X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtktoolitem.c;h=90ba2fd744d1481462abc09729b3ffedc984ff9e;hb=e4c2ef108cc66210af015b679ce3542ca6decfec;hp=1916af938c911751d7edf8e1f0f3439b22fff912;hpb=8fb1dc24118bde3e7e46c219aac6a507da9e96e1;p=~andy%2Fgtk diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c index 1916af938..90ba2fd74 100644 --- a/gtk/gtktoolitem.c +++ b/gtk/gtktoolitem.c @@ -15,27 +15,67 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ -#include +#include "config.h" + #include "gtktoolitem.h" + +#include + #include "gtkmarshalers.h" -#include "gtktoolbar.h" +#include "gtktoolshell.h" #include "gtkseparatormenuitem.h" +#include "gtksizerequest.h" +#include "gtkactivatable.h" #include "gtkintl.h" -#include "gtkmain.h" #include "gtkprivate.h" -#include "gtkalias.h" -#include + +/** + * SECTION:gtktoolitem + * @short_description: The base class of widgets that can be added to GtkToolShell + * @Title: GtkToolItem + * @see_also: + * + * #GtkToolbar + * The toolbar widget + * + * + * #GtkToolButton + * A subclass of #GtkToolItem that displays buttons on + * the toolbar + * + * + * #GtkSeparatorToolItem + * A subclass of #GtkToolItem that separates groups of + * items on a toolbar + * + * + * + * #GtkToolItems are widgets that can appear on a toolbar. To + * create a toolbar item that contain something else than a button, use + * gtk_tool_item_new(). Use gtk_container_add() to add a child + * widget to the tool item. + * + * For toolbar items that contain buttons, see the #GtkToolButton, + * #GtkToggleToolButton and #GtkRadioToolButton classes. + * + * See the #GtkToolbar class for a description of the toolbar widget, and + * #GtkToolShell for a description of the tool shell interface. + */ + +/** + * GtkToolItem: + * + * The GtkToolItem struct contains only private data. + * It should only be accessed through the functions described below. + */ enum { CREATE_MENU_PROXY, TOOLBAR_RECONFIGURED, - SET_TOOLTIP, LAST_SIGNAL }; @@ -43,32 +83,38 @@ enum { PROP_0, PROP_VISIBLE_HORIZONTAL, PROP_VISIBLE_VERTICAL, - PROP_IS_IMPORTANT + PROP_IS_IMPORTANT, + + /* activatable properties */ + PROP_ACTIVATABLE_RELATED_ACTION, + PROP_ACTIVATABLE_USE_ACTION_APPEARANCE }; -#define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate)) struct _GtkToolItemPrivate { gchar *tip_text; gchar *tip_private; - guint visible_horizontal : 1; - guint visible_vertical : 1; - guint homogeneous : 1; - guint expand : 1; - guint use_drag_window : 1; - guint is_important : 1; + guint visible_horizontal : 1; + guint visible_vertical : 1; + guint homogeneous : 1; + guint expand : 1; + guint use_drag_window : 1; + guint is_important : 1; + guint use_action_appearance : 1; GdkWindow *drag_window; - gchar *menu_item_id; GtkWidget *menu_item; + + GtkAction *action; }; - -static void gtk_tool_item_finalize (GObject *object); -static void gtk_tool_item_parent_set (GtkWidget *toolitem, - GtkWidget *parent); + +static void gtk_tool_item_finalize (GObject *object); +static void gtk_tool_item_dispose (GObject *object); +static void gtk_tool_item_parent_set (GtkWidget *toolitem, + GtkWidget *parent); static void gtk_tool_item_set_property (GObject *object, guint prop_id, const GValue *value, @@ -83,21 +129,33 @@ static void gtk_tool_item_realize (GtkWidget *widget); static void gtk_tool_item_unrealize (GtkWidget *widget); static void gtk_tool_item_map (GtkWidget *widget); static void gtk_tool_item_unmap (GtkWidget *widget); -static void gtk_tool_item_size_request (GtkWidget *widget, - GtkRequisition *requisition); +static void gtk_tool_item_get_preferred_width + (GtkWidget *widget, + gint *minimum, + gint *natural); +static void gtk_tool_item_get_preferred_height + (GtkWidget *widget, + gint *minimum, + gint *natural); static void gtk_tool_item_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item, - GtkTooltips *tooltips, - const gchar *tip_text, - const gchar *tip_private); - -static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item); +static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface); +static void gtk_tool_item_update (GtkActivatable *activatable, + GtkAction *action, + const gchar *property_name); +static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable, + GtkAction *action); +static void gtk_tool_item_set_related_action (GtkToolItem *item, + GtkAction *action); +static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item, + gboolean use_appearance); static guint toolitem_signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN) +G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN, + G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE, + gtk_tool_item_activatable_interface_init)) static void gtk_tool_item_class_init (GtkToolItemClass *klass) @@ -107,22 +165,25 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) object_class = (GObjectClass *)klass; widget_class = (GtkWidgetClass *)klass; - + object_class->set_property = gtk_tool_item_set_property; object_class->get_property = gtk_tool_item_get_property; - object_class->finalize = gtk_tool_item_finalize; - object_class->notify = gtk_tool_item_property_notify; + object_class->finalize = gtk_tool_item_finalize; + object_class->dispose = gtk_tool_item_dispose; + object_class->notify = gtk_tool_item_property_notify; widget_class->realize = gtk_tool_item_realize; widget_class->unrealize = gtk_tool_item_unrealize; widget_class->map = gtk_tool_item_map; widget_class->unmap = gtk_tool_item_unmap; - widget_class->size_request = gtk_tool_item_size_request; + widget_class->get_preferred_width = gtk_tool_item_get_preferred_width; + widget_class->get_preferred_height = gtk_tool_item_get_preferred_height; widget_class->size_allocate = gtk_tool_item_size_allocate; widget_class->parent_set = gtk_tool_item_parent_set; - klass->create_menu_proxy = gtk_tool_item_create_menu_proxy; - klass->set_tooltip = gtk_tool_item_real_set_tooltip; + gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (klass)); + + klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy; g_object_class_install_property (object_class, PROP_VISIBLE_HORIZONTAL, @@ -146,6 +207,10 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) FALSE, GTK_PARAM_READWRITE)); + g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action"); + g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance"); + + /** * GtkToolItem::create-menu-proxy: * @tool_item: the object the signal was emitted on @@ -176,7 +241,7 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) * Return value: %TRUE if the signal was handled, %FALSE if not **/ toolitem_signals[CREATE_MENU_PROXY] = - g_signal_new (I_("create_menu_proxy"), + g_signal_new (I_("create-menu-proxy"), G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy), @@ -192,49 +257,22 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) * item is a child of changes. For custom subclasses of #GtkToolItem, * the default handler of this signal use the functions * - * gtk_toolbar_get_orientation() - * gtk_toolbar_get_style() - * gtk_toolbar_get_icon_size() - * gtk_toolbar_get_relief_style() + * gtk_tool_shell_get_orientation() + * gtk_tool_shell_get_style() + * gtk_tool_shell_get_icon_size() + * gtk_tool_shell_get_relief_style() * * to find out what the toolbar should look like and change * themselves accordingly. **/ toolitem_signals[TOOLBAR_RECONFIGURED] = - g_signal_new (I_("toolbar_reconfigured"), + g_signal_new (I_("toolbar-reconfigured"), G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured), NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); -/** - * GtkToolItem::set-tooltip: - * @tool_item: the object the signal was emitted on - * @tooltips: the #GtkTooltips - * @tip_text: the tooltip text - * @tip_private: the tooltip private text - * - * This signal is emitted when the toolitem's tooltip changes. - * Application developers can use gtk_tool_item_set_tooltip() to - * set the item's tooltip. - * - * Return value: %TRUE if the signal was handled, %FALSE if not - * - * Deprecated: 2.12: With the new tooltip API, there is no - * need to use this signal anymore. - **/ - toolitem_signals[SET_TOOLTIP] = - g_signal_new (I_("set_tooltip"), - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip), - _gtk_boolean_handled_accumulator, NULL, - _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING, - G_TYPE_BOOLEAN, 3, - GTK_TYPE_TOOLTIPS, - G_TYPE_STRING, - G_TYPE_STRING); g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate)); } @@ -242,14 +280,18 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) static void gtk_tool_item_init (GtkToolItem *toolitem) { - GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS); + gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE); - toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem); + toolitem->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolitem, + GTK_TYPE_TOOL_ITEM, + GtkToolItemPrivate); toolitem->priv->visible_horizontal = TRUE; toolitem->priv->visible_vertical = TRUE; toolitem->priv->homogeneous = FALSE; toolitem->priv->expand = FALSE; + + toolitem->priv->use_action_appearance = TRUE; } static void @@ -258,20 +300,33 @@ gtk_tool_item_finalize (GObject *object) GtkToolItem *item = GTK_TOOL_ITEM (object); g_free (item->priv->menu_item_id); - + if (item->priv->menu_item) g_object_unref (item->priv->menu_item); - - if (G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize) - G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object); + + G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object); } +static void +gtk_tool_item_dispose (GObject *object) +{ + GtkToolItem *item = GTK_TOOL_ITEM (object); + + if (item->priv->action) + { + gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL); + item->priv->action = NULL; + } + G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object); +} + + static void gtk_tool_item_parent_set (GtkWidget *toolitem, GtkWidget *prev_parent) { - if (GTK_WIDGET (toolitem)->parent != NULL) - _gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem)); + if (gtk_widget_get_parent (GTK_WIDGET (toolitem)) != NULL) + gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem)); } static void @@ -293,8 +348,15 @@ gtk_tool_item_set_property (GObject *object, case PROP_IS_IMPORTANT: gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value)); break; + case PROP_ACTIVATABLE_RELATED_ACTION: + gtk_tool_item_set_related_action (toolitem, g_value_get_object (value)); + break; + case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: + gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -317,8 +379,15 @@ gtk_tool_item_get_property (GObject *object, case PROP_IS_IMPORTANT: g_value_set_boolean (value, toolitem->priv->is_important); break; + case PROP_ACTIVATABLE_RELATED_ACTION: + g_value_set_object (value, toolitem->priv->action); + break; + case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: + g_value_set_boolean (value, toolitem->priv->use_action_appearance); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -330,26 +399,31 @@ gtk_tool_item_property_notify (GObject *object, if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0) gtk_widget_set_sensitive (tool_item->priv->menu_item, - GTK_WIDGET_SENSITIVE (tool_item)); + gtk_widget_get_sensitive (GTK_WIDGET (tool_item))); + + if (G_OBJECT_CLASS (gtk_tool_item_parent_class)->notify) + G_OBJECT_CLASS (gtk_tool_item_parent_class)->notify (object, pspec); } static void create_drag_window (GtkToolItem *toolitem) { + GtkAllocation allocation; GtkWidget *widget; GdkWindowAttr attributes; - gint attributes_mask, border_width; + gint attributes_mask; g_return_if_fail (toolitem->priv->use_drag_window == TRUE); widget = GTK_WIDGET (toolitem); - border_width = GTK_CONTAINER (toolitem)->border_width; + + gtk_widget_get_allocation (widget, &allocation); attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x + border_width; - attributes.y = widget->allocation.y + border_width; - attributes.width = widget->allocation.width - border_width * 2; - attributes.height = widget->allocation.height - border_width * 2; + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; attributes.wclass = GDK_INPUT_ONLY; attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); @@ -358,24 +432,24 @@ create_drag_window (GtkToolItem *toolitem) toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - gdk_window_set_user_data (toolitem->priv->drag_window, toolitem); + gtk_widget_register_window (widget, toolitem->priv->drag_window); } static void gtk_tool_item_realize (GtkWidget *widget) { GtkToolItem *toolitem; + GdkWindow *window; toolitem = GTK_TOOL_ITEM (widget); - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + gtk_widget_set_realized (widget, TRUE); - widget->window = gtk_widget_get_parent_window (widget); - g_object_ref (widget->window); + window = gtk_widget_get_parent_window (widget); + gtk_widget_set_window (widget, window); + g_object_ref (window); if (toolitem->priv->use_drag_window) create_drag_window(toolitem); - - widget->style = gtk_style_attach (widget->style, widget->window); } static void @@ -383,7 +457,7 @@ destroy_drag_window (GtkToolItem *toolitem) { if (toolitem->priv->drag_window) { - gdk_window_set_user_data (toolitem->priv->drag_window, NULL); + gtk_widget_unregister_window (GTK_WIDGET (toolitem), toolitem->priv->drag_window); gdk_window_destroy (toolitem->priv->drag_window); toolitem->priv->drag_window = NULL; } @@ -424,23 +498,31 @@ gtk_tool_item_unmap (GtkWidget *widget) } static void -gtk_tool_item_size_request (GtkWidget *widget, - GtkRequisition *requisition) +gtk_tool_item_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural) { - GtkWidget *child = GTK_BIN (widget)->child; + GtkWidget *child; - if (child && GTK_WIDGET_VISIBLE (child)) - { - gtk_widget_size_request (child, requisition); - } - else - { - requisition->height = 0; - requisition->width = 0; - } - - requisition->width += (GTK_CONTAINER (widget)->border_width) * 2; - requisition->height += (GTK_CONTAINER (widget)->border_width) * 2; + *minimum = *natural = 0; + + child = gtk_bin_get_child (GTK_BIN (widget)); + if (child && gtk_widget_get_visible (child)) + gtk_widget_get_preferred_width (child, minimum, natural); +} + +static void +gtk_tool_item_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + GtkWidget *child; + + *minimum = *natural = 0; + + child = gtk_bin_get_child (GTK_BIN (widget)); + if (child && gtk_widget_get_visible (child)) + gtk_widget_get_preferred_height (child, minimum, natural); } static void @@ -449,36 +531,145 @@ gtk_tool_item_size_allocate (GtkWidget *widget, { GtkToolItem *toolitem = GTK_TOOL_ITEM (widget); GtkAllocation child_allocation; - gint border_width; - GtkWidget *child = GTK_BIN (widget)->child; + GtkWidget *child; - widget->allocation = *allocation; - border_width = GTK_CONTAINER (widget)->border_width; + gtk_widget_set_allocation (widget, allocation); if (toolitem->priv->drag_window) gdk_window_move_resize (toolitem->priv->drag_window, - widget->allocation.x + border_width, - widget->allocation.y + border_width, - widget->allocation.width - border_width * 2, - widget->allocation.height - border_width * 2); - - if (child && GTK_WIDGET_VISIBLE (child)) + allocation->x, + allocation->y, + allocation->width, + allocation->height); + + child = gtk_bin_get_child (GTK_BIN (widget)); + if (child && gtk_widget_get_visible (child)) { - child_allocation.x = allocation->x + border_width; - child_allocation.y = allocation->y + border_width; - child_allocation.width = allocation->width - 2 * border_width; - child_allocation.height = allocation->height - 2 * border_width; + child_allocation.x = allocation->x; + child_allocation.y = allocation->y; + child_allocation.width = allocation->width; + child_allocation.height = allocation->height; gtk_widget_size_allocate (child, &child_allocation); } } -static gboolean -gtk_tool_item_create_menu_proxy (GtkToolItem *item) +gboolean +_gtk_tool_item_create_menu_proxy (GtkToolItem *item) { + GtkWidget *menu_item; + gboolean visible_overflown; + + if (item->priv->action) + { + g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL); + + if (visible_overflown) + { + menu_item = gtk_action_create_menu_item (item->priv->action); + + g_object_ref_sink (menu_item); + gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item); + g_object_unref (menu_item); + } + else + gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL); + + return TRUE; + } + return FALSE; } +static void +gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface) +{ + iface->update = gtk_tool_item_update; + iface->sync_action_properties = gtk_tool_item_sync_action_properties; +} + +static void +gtk_tool_item_update (GtkActivatable *activatable, + GtkAction *action, + const gchar *property_name) +{ + if (strcmp (property_name, "visible") == 0) + { + if (gtk_action_is_visible (action)) + gtk_widget_show (GTK_WIDGET (activatable)); + else + gtk_widget_hide (GTK_WIDGET (activatable)); + } + else if (strcmp (property_name, "sensitive") == 0) + gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action)); + else if (strcmp (property_name, "tooltip") == 0) + gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable), + gtk_action_get_tooltip (action)); + else if (strcmp (property_name, "visible-horizontal") == 0) + gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable), + gtk_action_get_visible_horizontal (action)); + else if (strcmp (property_name, "visible-vertical") == 0) + gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable), + gtk_action_get_visible_vertical (action)); + else if (strcmp (property_name, "is-important") == 0) + gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable), + gtk_action_get_is_important (action)); +} + +static void +gtk_tool_item_sync_action_properties (GtkActivatable *activatable, + GtkAction *action) +{ + if (!action) + return; + + if (gtk_action_is_visible (action)) + gtk_widget_show (GTK_WIDGET (activatable)); + else + gtk_widget_hide (GTK_WIDGET (activatable)); + + gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action)); + + gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable), + gtk_action_get_tooltip (action)); + gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable), + gtk_action_get_visible_horizontal (action)); + gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable), + gtk_action_get_visible_vertical (action)); + gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable), + gtk_action_get_is_important (action)); +} + +static void +gtk_tool_item_set_related_action (GtkToolItem *item, + GtkAction *action) +{ + if (item->priv->action == action) + return; + + gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action); + + item->priv->action = action; + + if (action) + { + gtk_tool_item_rebuild_menu (item); + } +} + +static void +gtk_tool_item_set_use_action_appearance (GtkToolItem *item, + gboolean use_appearance) +{ + if (item->priv->use_action_appearance != use_appearance) + { + item->priv->use_action_appearance = use_appearance; + + gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action); + } +} + + /** * gtk_tool_item_new: * @@ -498,15 +689,43 @@ gtk_tool_item_new (void) return item; } +/** + * gtk_tool_item_get_ellipsize_mode: + * @tool_item: a #GtkToolItem + * + * Returns the ellipsize mode used for @tool_item. Custom subclasses of + * #GtkToolItem should call this function to find out how text should + * be ellipsized. + * + * Return value: a #PangoEllipsizeMode indicating how text in @tool_item + * should be ellipsized. + * + * Since: 2.20 + **/ +PangoEllipsizeMode +gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item) +{ + GtkWidget *parent; + + g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL); + + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) + return PANGO_ELLIPSIZE_NONE; + + return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent)); +} + /** * gtk_tool_item_get_icon_size: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * * Returns the icon size used for @tool_item. Custom subclasses of * #GtkToolItem should call this function to find out what size icons * they should use. * - * Return value: a #GtkIconSize indicating the icon size used for @tool_item + * Return value: (type int): a #GtkIconSize indicating the icon size + * used for @tool_item * * Since: 2.4 **/ @@ -517,16 +736,16 @@ gtk_tool_item_get_icon_size (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR); - parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_ICON_SIZE_LARGE_TOOLBAR; - return gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent)); } /** * gtk_tool_item_get_orientation: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * * Returns the orientation used for @tool_item. Custom subclasses of * #GtkToolItem should call this function to find out what size icons @@ -544,16 +763,16 @@ gtk_tool_item_get_orientation (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL); - parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_ORIENTATION_HORIZONTAL; - return gtk_toolbar_get_orientation (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent)); } /** * gtk_tool_item_get_toolbar_style: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * * Returns the toolbar style used for @tool_item. Custom subclasses of * #GtkToolItem should call this function in the handler of the @@ -569,10 +788,7 @@ gtk_tool_item_get_orientation (GtkToolItem *tool_item) * GTK_TOOLBAR_TEXT, meaning the tool item should only * show text * GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show - * both an icon and a label, arranged horizontally (however, note the - * #GtkToolButton::has_text_horizontally that makes tool buttons not - * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ. - * + * both an icon and a label, arranged horizontally * * * Return value: A #GtkToolbarStyle indicating the toolbar style used @@ -587,18 +803,18 @@ gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS); - parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_TOOLBAR_ICONS; - return gtk_toolbar_get_style (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent)); } /** * gtk_tool_item_get_relief_style: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * - * Returns the relief style of @tool_item. See gtk_button_set_relief_style(). + * Returns the relief style of @tool_item. See gtk_button_set_relief(). * Custom subclasses of #GtkToolItem should call this function in the handler * of the #GtkToolItem::toolbar_reconfigured signal to find out the * relief style of buttons. @@ -615,25 +831,105 @@ gtk_tool_item_get_relief_style (GtkToolItem *tool_item) g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE); - parent = GTK_WIDGET (tool_item)->parent; - if (!parent || !GTK_IS_TOOLBAR (parent)) + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) return GTK_RELIEF_NONE; - return gtk_toolbar_get_relief_style (GTK_TOOLBAR (parent)); + return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent)); } /** - * gtk_tool_item_set_expand: + * gtk_tool_item_get_text_alignment: * @tool_item: a #GtkToolItem: - * @expand: Whether @tool_item is allocated extra space * + * Returns the text alignment used for @tool_item. Custom subclasses of + * #GtkToolItem should call this function to find out how text should + * be aligned. + * + * Return value: a #gfloat indicating the horizontal text alignment + * used for @tool_item + * + * Since: 2.20 + **/ +gfloat +gtk_tool_item_get_text_alignment (GtkToolItem *tool_item) +{ + GtkWidget *parent; + + g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL); + + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) + return 0.5; + + return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent)); +} + +/** + * gtk_tool_item_get_text_orientation: + * @tool_item: a #GtkToolItem + * + * Returns the text orientation used for @tool_item. Custom subclasses of + * #GtkToolItem should call this function to find out how text should + * be orientated. + * + * Return value: a #GtkOrientation indicating the text orientation + * used for @tool_item + * + * Since: 2.20 + */ +GtkOrientation +gtk_tool_item_get_text_orientation (GtkToolItem *tool_item) +{ + GtkWidget *parent; + + g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL); + + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) + return GTK_ORIENTATION_HORIZONTAL; + + return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent)); +} + +/** + * gtk_tool_item_get_text_size_group: + * @tool_item: a #GtkToolItem + * + * Returns the size group used for labels in @tool_item. + * Custom subclasses of #GtkToolItem should call this function + * and use the size group for labels. + * + * Return value: (transfer none): a #GtkSizeGroup + * + * Since: 2.20 + */ +GtkSizeGroup * +gtk_tool_item_get_text_size_group (GtkToolItem *tool_item) +{ + GtkWidget *parent; + + g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL); + + parent = gtk_widget_get_parent (GTK_WIDGET (tool_item)); + if (!parent || !GTK_IS_TOOL_SHELL (parent)) + return NULL; + + return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent)); +} + +/** + * gtk_tool_item_set_expand: + * @tool_item: a #GtkToolItem + * @expand: Whether @tool_item is allocated extra space + * * Sets whether @tool_item is allocated extra space when there * is more room on the toolbar then needed for the items. The * effect is that the item gets bigger when the toolbar gets bigger * and smaller when the toolbar gets smaller. - * + * * Since: 2.4 - **/ + */ void gtk_tool_item_set_expand (GtkToolItem *tool_item, gboolean expand) @@ -652,7 +948,7 @@ gtk_tool_item_set_expand (GtkToolItem *tool_item, /** * gtk_tool_item_get_expand: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * * Returns whether @tool_item is allocated extra space. * See gtk_tool_item_set_expand(). @@ -671,7 +967,7 @@ gtk_tool_item_get_expand (GtkToolItem *tool_item) /** * gtk_tool_item_set_homogeneous: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * @homogeneous: whether @tool_item is the same size as other homogeneous items * * Sets whether @tool_item is to be allocated the same size as other @@ -698,13 +994,13 @@ gtk_tool_item_set_homogeneous (GtkToolItem *tool_item, /** * gtk_tool_item_get_homogeneous: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * * Returns whether @tool_item is the same size as other homogeneous * items. See gtk_tool_item_set_homogeneous(). * * Return value: %TRUE if the item is the same size as other homogeneous - * item.s + * items. * * Since: 2.4 **/ @@ -765,54 +1061,9 @@ gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important) } } -static gboolean -gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item, - GtkTooltips *tooltips, - const gchar *tip_text, - const gchar *tip_private) -{ - GtkWidget *child = GTK_BIN (tool_item)->child; - - if (!child) - return FALSE; - - gtk_widget_set_tooltip_text (child, tip_text); - - return TRUE; -} - -/** - * gtk_tool_item_set_tooltip: - * @tool_item: a #GtkToolItem: - * @tooltips: The #GtkTooltips object to be used - * @tip_text: text to be used as tooltip text for @tool_item - * @tip_private: text to be used as private tooltip text - * - * Sets the #GtkTooltips object to be used for @tool_item, the - * text to be displayed as tooltip on the item and the private text - * to be used. See gtk_tooltips_set_tip(). - * - * Since: 2.4 - * - * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead. - **/ -void -gtk_tool_item_set_tooltip (GtkToolItem *tool_item, - GtkTooltips *tooltips, - const gchar *tip_text, - const gchar *tip_private) -{ - gboolean retval; - - g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item)); - - g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0, - tooltips, tip_text, tip_private, &retval); -} - /** * gtk_tool_item_set_tooltip_text: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * @text: text to be used as tooltip for @tool_item * * Sets the text to be displayed as tooltip on the item. @@ -828,15 +1079,14 @@ gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item, g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item)); - child = GTK_BIN (tool_item)->child; - + child = gtk_bin_get_child (GTK_BIN (tool_item)); if (child) gtk_widget_set_tooltip_text (child, text); } /** * gtk_tool_item_set_tooltip_markup: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * @markup: markup text to be used as tooltip for @tool_item * * Sets the markup text to be displayed as tooltip on the item. @@ -852,8 +1102,7 @@ gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item, g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item)); - child = GTK_BIN (tool_item)->child; - + child = gtk_bin_get_child (GTK_BIN (tool_item)); if (child) gtk_widget_set_tooltip_markup (child, markup); } @@ -884,10 +1133,11 @@ gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem, if (use_drag_window) { - if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem)) + if (!toolitem->priv->drag_window && + gtk_widget_get_realized (GTK_WIDGET (toolitem))) { create_drag_window(toolitem); - if (GTK_WIDGET_MAPPED (toolitem)) + if (gtk_widget_get_mapped (GTK_WIDGET (toolitem))) gdk_window_show (toolitem->priv->drag_window); } } @@ -1016,15 +1266,15 @@ gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem) /** * gtk_tool_item_retrieve_proxy_menu_item: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * * Returns the #GtkMenuItem that was last set by * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem * that is going to appear in the overflow menu. - * - * Return value: The #GtkMenuItem that is going to appear in the + * + * Return value: (transfer none): The #GtkMenuItem that is going to appear in the * overflow menu for @tool_item. - * + * * Since: 2.4 **/ GtkWidget * @@ -1042,20 +1292,21 @@ gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item) /** * gtk_tool_item_get_proxy_menu_item: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * @menu_item_id: a string used to identify the menu item - * + * * If @menu_item_id matches the string passed to * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem. * - * Custom subclasses of #GtkToolItem should use this function to update - * their menu item when the #GtkToolItem changes. That the - * @menu_item_ids must match ensures that a #GtkToolItem will not - * inadvertently change a menu item that they did not create. - * - * Return value: The #GtkMenuItem passed to - * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_ids match. - * + * Custom subclasses of #GtkToolItem should use this function to + * update their menu item when the #GtkToolItem changes. That the + * @menu_item_ids must match ensures that a #GtkToolItem + * will not inadvertently change a menu item that they did not create. + * + * Return value: (transfer none): The #GtkMenuItem passed to + * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_ids + * match. + * * Since: 2.4 **/ GtkWidget * @@ -1072,36 +1323,37 @@ gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item, } /** - * gtk_tool_item_rebuild_menu() + * gtk_tool_item_rebuild_menu: * @tool_item: a #GtkToolItem - * + * * Calling this function signals to the toolbar that the * overflow menu item for @tool_item has changed. If the * overflow menu is visible when this function it called, * the menu will be rebuilt. * - * The function must be called when the tool item - * changes what it will do in response to the "create_menu_proxy" - * signal. - * + * The function must be called when the tool item changes what it + * will do in response to the #GtkToolItem::create-menu-proxy signal. + * * Since: 2.6 - **/ + */ void gtk_tool_item_rebuild_menu (GtkToolItem *tool_item) { + GtkWidget *parent; GtkWidget *widget; - + g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item)); widget = GTK_WIDGET (tool_item); - - if (widget->parent && GTK_IS_TOOLBAR (widget->parent)) - _gtk_toolbar_rebuild_menu (GTK_TOOLBAR (widget->parent)); + + parent = gtk_widget_get_parent (widget); + if (GTK_IS_TOOL_SHELL (parent)) + gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent)); } /** * gtk_tool_item_set_proxy_menu_item: - * @tool_item: a #GtkToolItem: + * @tool_item: a #GtkToolItem * @menu_item_id: a string used to identify @menu_item * @menu_item: a #GtkMenuItem to be used in the overflow menu * @@ -1134,7 +1386,7 @@ gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item, g_object_ref_sink (menu_item); gtk_widget_set_sensitive (menu_item, - GTK_WIDGET_SENSITIVE (tool_item)); + gtk_widget_get_sensitive (GTK_WIDGET (tool_item))); } tool_item->priv->menu_item = menu_item; @@ -1142,18 +1394,25 @@ gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item, } /** - * _gtk_tool_item_toolbar_reconfigured: - * @tool_item: a #GtkToolItem: - * - * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. This - * internal function is called by #GtkToolbar when some aspect of its - * configuration changes. - * - * Since: 2.4 + * gtk_tool_item_toolbar_reconfigured: + * @tool_item: a #GtkToolItem + * + * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. + * #GtkToolbar and other #GtkToolShell implementations use this function + * to notify children, when some aspect of their configuration changes. + * + * Since: 2.14 **/ void -_gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item) +gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item) { + /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was + * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function + * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured". + * It's not possible to rename the signal, and emitting another name than + * indicated by the function name would be quite confusing. That's the + * price of providing stable APIs. + */ g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item)); g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0); @@ -1163,6 +1422,3 @@ _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item) gtk_widget_queue_resize (GTK_WIDGET (tool_item)); } - -#define __GTK_TOOL_ITEM_C__ -#include "gtkaliasdef.c"