X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtktoolitem.c;h=90ba2fd744d1481462abc09729b3ffedc984ff9e;hb=67f5e595a796a8321d6dc7737c58476564998c07;hp=20ad6d821fdaaee29ea2f5060c528336c73e33d1;hpb=5e2c9437429f12cab3476e7b76deda5888224b61;p=~andy%2Fgtk diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c index 20ad6d821..90ba2fd74 100644 --- a/gtk/gtktoolitem.c +++ b/gtk/gtktoolitem.c @@ -15,22 +15,21 @@ * 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 "config.h" +#include "gtktoolitem.h" + #include -#include "gtktoolitem.h" #include "gtkmarshalers.h" #include "gtktoolshell.h" #include "gtkseparatormenuitem.h" +#include "gtksizerequest.h" #include "gtkactivatable.h" #include "gtkintl.h" -#include "gtkmain.h" #include "gtkprivate.h" @@ -97,22 +96,21 @@ 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; - gboolean use_action_appearance; }; - + 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, @@ -131,8 +129,14 @@ 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); @@ -161,7 +165,7 @@ 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; @@ -172,10 +176,13 @@ gtk_tool_item_class_init (GtkToolItemClass *klass) 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; + 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, @@ -393,6 +400,9 @@ 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_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 @@ -401,20 +411,19 @@ 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_get_border_width (GTK_CONTAINER (widget)); gtk_widget_get_allocation (widget, &allocation); attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = allocation.x + border_width; - attributes.y = allocation.y + border_width; - attributes.width = allocation.width - border_width * 2; - attributes.height = 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); @@ -423,7 +432,7 @@ 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 @@ -441,8 +450,6 @@ gtk_tool_item_realize (GtkWidget *widget) if (toolitem->priv->use_drag_window) create_drag_window(toolitem); - - gtk_widget_style_attach (widget); } static void @@ -450,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; } @@ -491,26 +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; - guint border_width; + + *minimum = *natural = 0; child = gtk_bin_get_child (GTK_BIN (widget)); if (child && gtk_widget_get_visible (child)) - { - gtk_widget_size_request (child, requisition); - } - else - { - requisition->height = 0; - requisition->width = 0; - } + gtk_widget_get_preferred_width (child, minimum, natural); +} - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - requisition->width += border_width * 2; - requisition->height += border_width * 2; +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 @@ -519,27 +531,24 @@ gtk_tool_item_size_allocate (GtkWidget *widget, { GtkToolItem *toolitem = GTK_TOOL_ITEM (widget); GtkAllocation child_allocation; - gint border_width; GtkWidget *child; gtk_widget_set_allocation (widget, allocation); - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - if (toolitem->priv->drag_window) gdk_window_move_resize (toolitem->priv->drag_window, - allocation->x + border_width, - allocation->y + border_width, - allocation->width - border_width * 2, - allocation->height - border_width * 2); + 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); } @@ -779,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 @@ -808,7 +814,7 @@ gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item) * gtk_tool_item_get_relief_style: * @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. @@ -890,10 +896,11 @@ gtk_tool_item_get_text_orientation (GtkToolItem *tool_item) * 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. + * 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: a #GtkSizeGroup + * Return value: (transfer none): a #GtkSizeGroup * * Since: 2.20 */ @@ -1285,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 * @@ -1401,7 +1409,7 @@ 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". - * Its not possible to rename the signal, and emitting another name than + * 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. */