1 /* GtkToolPalette -- A tool palette with categories and DnD support
2 * Copyright (C) 2008 Openismus GmbH
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "gtktoolpaletteprivate.h"
29 #define P_(msgid) (msgid)
31 #define ANIMATION_TIMEOUT 50
32 #define ANIMATION_DURATION (ANIMATION_TIMEOUT * 4)
33 #define DEFAULT_ANIMATION_STATE TRUE
34 #define DEFAULT_EXPANDER_SIZE 16
35 #define DEFAULT_HEADER_SPACING 2
37 #define DEFAULT_LABEL NULL
38 #define DEFAULT_COLLAPSED FALSE
39 #define DEFAULT_ELLIPSIZE PANGO_ELLIPSIZE_NONE
42 * SECTION:GtkToolItemGroup
43 * @short_description: A sub container used in a tool palette
44 * @include: gtktoolitemgroup.h
46 * An #GtkToolItemGroup is used together with #GtkToolPalette to add #GtkToolItem<!-- -->s to a palette like container
47 * with different categories and drag and drop support.
65 CHILD_PROP_HOMOGENEOUS,
72 typedef struct _GtkToolItemGroupChild GtkToolItemGroupChild;
74 struct _GtkToolItemGroupPrivate
77 GtkWidget *label_widget;
82 gint64 animation_start;
83 GSource *animation_timeout;
84 GtkExpanderStyle expander_style;
87 PangoEllipsizeMode ellipsize;
92 GtkSettings *settings;
93 gulong settings_connection;
98 struct _GtkToolItemGroupChild
102 guint homogeneous : 1;
108 static void gtk_tool_item_group_tool_shell_init (GtkToolShellIface *iface);
110 G_DEFINE_TYPE_WITH_CODE (GtkToolItemGroup, gtk_tool_item_group, GTK_TYPE_CONTAINER,
111 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL, gtk_tool_item_group_tool_shell_init));
114 gtk_tool_item_group_get_alignment (GtkToolItemGroup *group)
116 return gtk_bin_get_child (GTK_BIN (group->priv->header));
119 static GtkOrientation
120 gtk_tool_item_group_get_orientation (GtkToolShell *shell)
122 GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
124 if (GTK_IS_TOOL_PALETTE (parent))
125 return gtk_orientable_get_orientation (GTK_ORIENTABLE (parent));
127 return GTK_ORIENTATION_VERTICAL;
130 static GtkToolbarStyle
131 gtk_tool_item_group_get_style (GtkToolShell *shell)
133 GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
135 if (GTK_IS_TOOL_PALETTE (parent))
136 return gtk_tool_palette_get_style (GTK_TOOL_PALETTE (parent));
138 return GTK_TOOLBAR_ICONS;
142 gtk_tool_item_group_get_icon_size (GtkToolShell *shell)
144 GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
146 if (GTK_IS_TOOL_PALETTE (parent))
147 return gtk_tool_palette_get_icon_size (GTK_TOOL_PALETTE (parent));
149 return GTK_ICON_SIZE_SMALL_TOOLBAR;
152 static PangoEllipsizeMode
153 gtk_tool_item_group_get_ellipsize_mode (GtkToolShell *shell)
155 return GTK_TOOL_ITEM_GROUP (shell)->priv->ellipsize;
159 gtk_tool_item_group_get_text_alignment (GtkToolShell *shell)
161 if (GTK_TOOLBAR_TEXT == gtk_tool_item_group_get_style (shell) ||
162 GTK_TOOLBAR_BOTH_HORIZ == gtk_tool_item_group_get_style (shell))
168 static GtkOrientation
169 gtk_tool_item_group_get_text_orientation (GtkToolShell *shell)
171 GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
173 if (GTK_IS_TOOL_PALETTE (parent))
175 GtkOrientation orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (parent));
176 if (GTK_ORIENTATION_HORIZONTAL == orientation &&
177 (GTK_TOOLBAR_TEXT == gtk_tool_item_group_get_style (shell)/* ||
178 GTK_TOOLBAR_BOTH_HORIZ == gtk_tool_item_group_get_style (shell)*/))
179 return GTK_ORIENTATION_VERTICAL;
182 return GTK_ORIENTATION_HORIZONTAL;
185 static GtkSizeGroup *
186 gtk_tool_item_group_get_text_size_group (GtkToolShell *shell)
188 GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (shell));
190 if (GTK_IS_TOOL_PALETTE (parent))
191 return _gtk_tool_palette_get_size_group (GTK_TOOL_PALETTE (parent));
197 animation_change_notify (GtkToolItemGroup *group)
199 GtkSettings *settings = group->priv->settings;
203 g_object_get (settings,
204 "gtk-enable-animations", &animation,
207 animation = DEFAULT_ANIMATION_STATE;
209 group->priv->animation = animation;
213 gtk_tool_item_group_settings_change_notify (GtkSettings *settings,
214 const GParamSpec *pspec,
215 GtkToolItemGroup *group)
217 if (! strcmp (pspec->name, "gtk-enable-animations"))
219 animation_change_notify (group);
224 gtk_tool_item_group_screen_changed (GtkWidget *widget,
225 GdkScreen *previous_screen)
227 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (widget);
228 GtkToolItemGroupPrivate* priv = group->priv;
229 GtkSettings *old_settings = priv->settings;
230 GtkSettings *settings;
232 if (gtk_widget_has_screen (GTK_WIDGET (group)))
233 settings = gtk_widget_get_settings (GTK_WIDGET (group));
237 if (settings == old_settings)
242 g_signal_handler_disconnect (old_settings, priv->settings_connection);
243 g_object_unref (old_settings);
248 priv->settings_connection =
249 g_signal_connect (settings, "notify",
250 G_CALLBACK (gtk_tool_item_group_settings_change_notify),
252 priv->settings = g_object_ref (settings);
255 priv->settings = NULL;
257 animation_change_notify (group);
261 gtk_tool_item_group_tool_shell_init (GtkToolShellIface *iface)
263 iface->get_icon_size = gtk_tool_item_group_get_icon_size;
264 iface->get_orientation = gtk_tool_item_group_get_orientation;
265 iface->get_style = gtk_tool_item_group_get_style;
266 iface->get_text_alignment = gtk_tool_item_group_get_text_alignment;
267 iface->get_text_orientation = gtk_tool_item_group_get_text_orientation;
268 iface->get_text_size_group = gtk_tool_item_group_get_text_size_group;
269 iface->get_ellipsize_mode = gtk_tool_item_group_get_ellipsize_mode;
273 gtk_tool_item_group_header_expose_event_cb (GtkWidget *widget,
274 GdkEventExpose *event,
277 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (data);
278 GtkToolItemGroupPrivate* priv = group->priv;
279 GtkExpanderStyle expander_style;
280 GtkOrientation orientation;
282 GtkTextDirection direction;
284 orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
285 expander_style = priv->expander_style;
286 direction = gtk_widget_get_direction (widget);
288 if (GTK_ORIENTATION_VERTICAL == orientation)
290 if (GTK_TEXT_DIR_RTL == direction)
291 x = widget->allocation.x + widget->allocation.width - priv->expander_size / 2;
293 x = widget->allocation.x + priv->expander_size / 2;
294 y = widget->allocation.y + widget->allocation.height / 2;
298 x = widget->allocation.x + widget->allocation.width / 2;
299 y = widget->allocation.y + priv->expander_size / 2;
301 /* Unfortunatly gtk_paint_expander() doesn't support rotated drawing
302 * modes. Luckily the following shady arithmetics produce the desired
304 expander_style = GTK_EXPANDER_EXPANDED - expander_style; /* XXX */
307 gtk_paint_expander (widget->style, widget->window,
309 &event->area, GTK_WIDGET (group),
310 "tool-palette-header", x, y,
317 gtk_tool_item_group_header_size_request_cb (GtkWidget *widget,
318 GtkRequisition *requisition,
321 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (data);
322 requisition->height = MAX (requisition->height, group->priv->expander_size);
326 gtk_tool_item_group_header_clicked_cb (GtkButton *button,
329 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (data);
330 GtkToolItemGroupPrivate* priv = group->priv;
331 GtkWidget *parent = gtk_widget_get_parent (data);
333 if (priv->collapsed ||
334 !GTK_IS_TOOL_PALETTE (parent) ||
335 !gtk_tool_palette_get_exclusive (GTK_TOOL_PALETTE (parent), data))
336 gtk_tool_item_group_set_collapsed (group, !priv->collapsed);
340 gtk_tool_item_group_header_adjust_style (GtkToolItemGroup *group)
342 GtkWidget *alignment = gtk_tool_item_group_get_alignment (group);
343 GtkWidget *label_widget = gtk_bin_get_child (GTK_BIN (alignment));
344 GtkWidget *widget = GTK_WIDGET (group);
345 GtkToolItemGroupPrivate* priv = group->priv;
347 GtkTextDirection direction = gtk_widget_get_direction (widget);
349 gtk_widget_style_get (widget,
350 "header-spacing", &(priv->header_spacing),
351 "expander-size", &(priv->expander_size),
354 switch (gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group)))
356 case GTK_ORIENTATION_HORIZONTAL:
357 dy = priv->header_spacing + priv->expander_size;
359 if (GTK_IS_LABEL (label_widget))
361 gtk_label_set_ellipsize (GTK_LABEL (label_widget), PANGO_ELLIPSIZE_NONE);
362 if (GTK_TEXT_DIR_RTL == direction)
363 gtk_label_set_angle (GTK_LABEL (label_widget), -90);
365 gtk_label_set_angle (GTK_LABEL (label_widget), 90);
369 case GTK_ORIENTATION_VERTICAL:
370 dx = priv->header_spacing + priv->expander_size;
372 if (GTK_IS_LABEL (label_widget))
374 gtk_label_set_ellipsize (GTK_LABEL (label_widget), priv->ellipsize);
375 gtk_label_set_angle (GTK_LABEL (label_widget), 0);
380 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), dy, 0, dx, 0);
384 gtk_tool_item_group_init (GtkToolItemGroup *group)
386 GtkWidget *alignment;
387 GtkToolItemGroupPrivate* priv;
389 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (group), FALSE);
391 group->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (group,
392 GTK_TYPE_TOOL_ITEM_GROUP,
393 GtkToolItemGroupPrivate);
395 priv->children = NULL;
396 priv->header_spacing = DEFAULT_HEADER_SPACING;
397 priv->expander_size = DEFAULT_EXPANDER_SIZE;
398 priv->expander_style = GTK_EXPANDER_EXPANDED;
400 priv->label_widget = gtk_label_new (NULL);
401 gtk_misc_set_alignment (GTK_MISC (priv->label_widget), 0.0, 0.5);
402 alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
403 gtk_container_add (GTK_CONTAINER (alignment), priv->label_widget);
404 gtk_widget_show_all (alignment);
406 gtk_widget_push_composite_child ();
407 priv->header = gtk_button_new ();
408 gtk_widget_set_composite_name (priv->header, "header");
409 gtk_widget_pop_composite_child ();
411 g_object_ref_sink (priv->header);
412 gtk_button_set_focus_on_click (GTK_BUTTON (priv->header), FALSE);
413 gtk_container_add (GTK_CONTAINER (priv->header), alignment);
414 gtk_widget_set_parent (priv->header, GTK_WIDGET (group));
416 gtk_tool_item_group_header_adjust_style (group);
418 g_signal_connect_after (alignment, "expose-event",
419 G_CALLBACK (gtk_tool_item_group_header_expose_event_cb),
421 g_signal_connect_after (alignment, "size-request",
422 G_CALLBACK (gtk_tool_item_group_header_size_request_cb),
425 g_signal_connect (priv->header, "clicked",
426 G_CALLBACK (gtk_tool_item_group_header_clicked_cb),
431 gtk_tool_item_group_set_property (GObject *object,
436 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (object);
441 gtk_tool_item_group_set_label (group, g_value_get_string (value));
444 case PROP_LABEL_WIDGET:
445 gtk_tool_item_group_set_label_widget (group, g_value_get_object (value));
448 gtk_tool_item_group_set_collapsed (group, g_value_get_boolean (value));
452 gtk_tool_item_group_set_ellipsize (group, g_value_get_enum (value));
455 gtk_tool_item_group_set_header_relief (group, g_value_get_enum(value));
458 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
464 gtk_tool_item_group_get_property (GObject *object,
469 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (object);
474 g_value_set_string (value, gtk_tool_item_group_get_label (group));
477 case PROP_LABEL_WIDGET:
478 g_value_set_object (value,
479 gtk_tool_item_group_get_label_widget (group));
483 g_value_set_boolean (value, gtk_tool_item_group_get_collapsed (group));
487 g_value_set_enum (value, gtk_tool_item_group_get_ellipsize (group));
491 g_value_set_enum (value, gtk_tool_item_group_get_header_relief (group));
495 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
501 gtk_tool_item_group_finalize (GObject *object)
503 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (object);
505 if (group->priv->children)
507 g_list_free (group->priv->children);
508 group->priv->children = NULL;
511 G_OBJECT_CLASS (gtk_tool_item_group_parent_class)->finalize (object);
515 gtk_tool_item_group_dispose (GObject *object)
517 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (object);
518 GtkToolItemGroupPrivate* priv = group->priv;
522 /* disconnect focus tracking handler */
523 g_signal_handler_disconnect (priv->toplevel,
526 priv->focus_set_id = 0;
527 priv->toplevel = NULL;
530 G_OBJECT_CLASS (gtk_tool_item_group_parent_class)->dispose (object);
534 gtk_tool_item_group_get_item_size (GtkToolItemGroup *group,
535 GtkRequisition *item_size,
536 gboolean homogeneous_only,
537 gint *requested_rows)
539 GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (group));
541 if (GTK_IS_TOOL_PALETTE (parent))
542 _gtk_tool_palette_get_item_size (GTK_TOOL_PALETTE (parent), item_size, homogeneous_only, requested_rows);
544 _gtk_tool_item_group_item_size_request (group, item_size, homogeneous_only, requested_rows);
548 gtk_tool_item_group_size_request (GtkWidget *widget,
549 GtkRequisition *requisition)
551 const gint border_width = GTK_CONTAINER (widget)->border_width;
552 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (widget);
553 GtkToolItemGroupPrivate* priv = group->priv;
554 GtkOrientation orientation;
555 GtkRequisition item_size;
558 if (priv->children && gtk_tool_item_group_get_label_widget (group))
560 gtk_widget_size_request (priv->header, requisition);
561 gtk_widget_show (priv->header);
565 requisition->width = requisition->height = 0;
566 gtk_widget_hide (priv->header);
569 gtk_tool_item_group_get_item_size (group, &item_size, FALSE, &requested_rows);
571 orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
573 if (GTK_ORIENTATION_VERTICAL == orientation)
574 requisition->width = MAX (requisition->width, item_size.width);
576 requisition->height = MAX (requisition->height, item_size.height * requested_rows);
578 requisition->width += border_width * 2;
579 requisition->height += border_width * 2;
583 gtk_tool_item_group_is_item_visible (GtkToolItemGroup *group,
584 GtkToolItemGroupChild *child)
586 GtkToolbarStyle style;
587 GtkOrientation orientation;
589 orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
590 style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
592 /* horizontal tool palettes with text style support only homogeneous items */
593 if (!child->homogeneous &&
594 GTK_ORIENTATION_HORIZONTAL == orientation &&
595 GTK_TOOLBAR_TEXT == style)
599 (GTK_WIDGET_VISIBLE (child->item)) &&
600 (GTK_ORIENTATION_VERTICAL == orientation ?
601 gtk_tool_item_get_visible_vertical (child->item) :
602 gtk_tool_item_get_visible_horizontal (child->item));
605 static inline unsigned
609 return (x + y - 1) / y;
613 gtk_tool_item_group_real_size_query (GtkWidget *widget,
614 GtkAllocation *allocation,
615 GtkRequisition *inquery)
617 const gint border_width = GTK_CONTAINER (widget)->border_width;
618 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (widget);
619 GtkToolItemGroupPrivate* priv = group->priv;
621 GtkRequisition item_size;
622 GtkAllocation item_area;
624 GtkOrientation orientation;
625 GtkToolbarStyle style;
629 orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
630 style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
632 /* figure out the size of homogeneous items */
633 gtk_tool_item_group_get_item_size (group, &item_size, TRUE, &min_rows);
635 if (GTK_ORIENTATION_VERTICAL == orientation)
636 item_size.width = MIN (item_size.width, allocation->width);
638 item_size.height = MIN (item_size.height, allocation->height);
641 item_area.height = 0;
643 /* figure out the required columns (n_columns) and rows (n_rows) to place all items */
644 if (!priv->collapsed || !priv->animation || priv->animation_timeout)
650 if (GTK_ORIENTATION_VERTICAL == orientation)
652 gboolean new_row = FALSE;
656 item_area.width = allocation->width - 2 * border_width;
657 n_columns = MAX (item_area.width / item_size.width, 1);
659 /* calculate required rows for n_columns columns */
660 for (it = priv->children; it != NULL; it = it->next)
662 GtkToolItemGroupChild *child = it->data;
664 if (!gtk_tool_item_group_is_item_visible (group, child))
667 if (new_row || child->new_row)
677 if (child->homogeneous)
680 if (col >= n_columns)
685 GtkRequisition req = {0, 0};
688 gtk_widget_size_request (GTK_WIDGET (child->item), &req);
690 width = udiv (req.width, item_size.width);
698 if (col >= n_columns)
706 guint *row_min_width;
708 gboolean new_row = TRUE;
709 guint col = 0, min_col, max_col = 0, all_items = 0;
712 item_area.height = allocation->height - 2 * border_width;
713 n_rows = MAX (item_area.height / item_size.height, min_rows);
715 row_min_width = g_new0 (guint, n_rows);
717 /* calculate minimal and maximal required cols and minimal required rows */
718 for (it = priv->children; it != NULL; it = it->next)
720 GtkToolItemGroupChild *child = it->data;
722 if (!gtk_tool_item_group_is_item_visible (group, child))
725 if (new_row || child->new_row)
730 row_min_width[row] = 1;
736 if (child->homogeneous)
743 GtkRequisition req = {0, 0};
746 gtk_widget_size_request (GTK_WIDGET (child->item), &req);
748 width = udiv (req.width, item_size.width);
753 row_min_width[row] = MAX (row_min_width[row], width);
756 max_col = MAX (max_col, col);
759 /* calculate minimal required cols */
760 min_col = udiv (all_items, n_rows);
762 for (i = 0; i <= row; i++)
764 min_col = MAX (min_col, row_min_width[i]);
767 /* simple linear search for minimal required columns for the given maximal number of rows (n_rows) */
768 for (n_columns = min_col; n_columns < max_col; n_columns ++)
772 /* calculate required rows for n_columns columns */
773 for (it = priv->children; it != NULL; it = it->next)
775 GtkToolItemGroupChild *child = it->data;
777 if (!gtk_tool_item_group_is_item_visible (group, child))
780 if (new_row || child->new_row)
790 if (child->homogeneous)
793 if (col >= n_columns)
798 GtkRequisition req = {0, 0};
801 gtk_widget_size_request (GTK_WIDGET (child->item), &req);
803 width = udiv (req.width, item_size.width);
811 if (col >= n_columns)
821 item_area.width = item_size.width * n_columns;
822 item_area.height = item_size.height * n_rows;
828 /* figure out header widget size */
829 if (GTK_WIDGET_VISIBLE (priv->header))
831 GtkRequisition child_requisition;
833 gtk_widget_size_request (priv->header, &child_requisition);
835 if (GTK_ORIENTATION_VERTICAL == orientation)
836 inquery->height += child_requisition.height;
838 inquery->width += child_requisition.width;
841 /* report effective widget size */
842 inquery->width += item_area.width + 2 * border_width;
843 inquery->height += item_area.height + 2 * border_width;
847 gtk_tool_item_group_real_size_allocate (GtkWidget *widget,
848 GtkAllocation *allocation)
850 const gint border_width = GTK_CONTAINER (widget)->border_width;
851 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (widget);
852 GtkToolItemGroupPrivate* priv = group->priv;
853 GtkRequisition child_requisition;
854 GtkAllocation child_allocation;
856 GtkRequisition item_size;
857 GtkAllocation item_area;
859 GtkOrientation orientation;
860 GtkToolbarStyle style;
864 gint n_columns, n_rows = 1;
867 GtkTextDirection direction = gtk_widget_get_direction (widget);
869 orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
870 style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
873 GTK_WIDGET_CLASS (gtk_tool_item_group_parent_class)->size_allocate (widget, allocation);
875 child_allocation.x = border_width;
876 child_allocation.y = border_width;
878 /* place the header widget */
879 if (GTK_WIDGET_VISIBLE (priv->header))
881 gtk_widget_size_request (priv->header, &child_requisition);
883 if (GTK_ORIENTATION_VERTICAL == orientation)
885 child_allocation.width = allocation->width;
886 child_allocation.height = child_requisition.height;
890 child_allocation.width = child_requisition.width;
891 child_allocation.height = allocation->height;
893 if (GTK_TEXT_DIR_RTL == direction)
894 child_allocation.x = allocation->width - border_width - child_allocation.width;
897 gtk_widget_size_allocate (priv->header, &child_allocation);
899 if (GTK_ORIENTATION_VERTICAL == orientation)
900 child_allocation.y += child_allocation.height;
901 else if (GTK_TEXT_DIR_RTL != direction)
902 child_allocation.x += child_allocation.width;
904 child_allocation.x = border_width;
907 child_requisition.width = child_requisition.height = 0;
909 /* figure out the size of homogeneous items */
910 gtk_tool_item_group_get_item_size (group, &item_size, TRUE, &min_rows);
912 /* figure out the available columns and size of item_area */
913 if (GTK_ORIENTATION_VERTICAL == orientation)
915 item_size.width = MIN (item_size.width, allocation->width);
917 item_area.width = allocation->width - 2 * border_width;
918 item_area.height = allocation->height - 2 * border_width - child_requisition.height;
920 n_columns = MAX (item_area.width / item_size.width, 1);
922 item_size.width = item_area.width / n_columns;
926 item_size.height = MIN (item_size.height, allocation->height);
928 item_area.width = allocation->width - 2 * border_width - child_requisition.width;
929 item_area.height = allocation->height - 2 * border_width;
931 n_columns = MAX (item_area.width / item_size.width, 1);
932 n_rows = MAX (item_area.height / item_size.height, min_rows);
934 item_size.height = item_area.height / n_rows;
937 item_area.x = child_allocation.x;
938 item_area.y = child_allocation.y;
940 /* when expanded or in transition, place the tool items in a grid like layout */
941 if (!priv->collapsed || !priv->animation || priv->animation_timeout)
943 gint col = 0, row = 0;
945 for (it = priv->children; it != NULL; it = it->next)
947 GtkToolItemGroupChild *child = it->data;
950 if (!gtk_tool_item_group_is_item_visible (group, child))
952 gtk_widget_set_child_visible (GTK_WIDGET (child->item), FALSE);
957 /* for non homogeneous widgets request the required size */
958 child_requisition.width = 0;
960 if (!child->homogeneous)
962 gtk_widget_size_request (GTK_WIDGET (child->item), &child_requisition);
963 child_requisition.width = MIN (child_requisition.width, item_area.width);
966 /* select next row if at end of row */
967 if (col > 0 && (child->new_row || (col * item_size.width) + MAX (child_requisition.width, item_size.width) > item_area.width))
971 child_allocation.y += child_allocation.height;
976 /* calculate the position and size of the item */
977 if (!child->homogeneous)
983 col_width = udiv (child_requisition.width, item_size.width);
985 col_width = n_columns - col;
987 width = col_width * item_size.width;
989 if (GTK_TEXT_DIR_RTL == direction)
990 col_child = (n_columns - col - col_width);
994 child_allocation.x = item_area.x + col_child * item_size.width;
995 child_allocation.width = width;
1000 (item_area.x + col_child * item_size.width +
1001 (width - child_requisition.width) / 2);
1002 child_allocation.width = child_requisition.width;
1009 if (GTK_TEXT_DIR_RTL == direction)
1010 col_child = (n_columns - col - 1);
1012 child_allocation.x = item_area.x + col_child * item_size.width;
1013 child_allocation.width = item_size.width;
1018 child_allocation.height = item_size.height;
1020 gtk_widget_size_allocate (GTK_WIDGET (child->item), &child_allocation);
1021 gtk_widget_set_child_visible (GTK_WIDGET (child->item), TRUE);
1024 child_allocation.y += item_size.height;
1027 /* or just hide all items, when collapsed */
1031 for (it = priv->children; it != NULL; it = it->next)
1033 GtkToolItemGroupChild *child = it->data;
1035 gtk_widget_set_child_visible (GTK_WIDGET (child->item), FALSE);
1041 gtk_tool_item_group_size_allocate (GtkWidget *widget,
1042 GtkAllocation *allocation)
1044 gtk_tool_item_group_real_size_allocate (widget, allocation);
1046 if (GTK_WIDGET_MAPPED (widget))
1047 gdk_window_invalidate_rect (widget->window, NULL, FALSE);
1051 gtk_tool_item_group_set_focus_cb (GtkWidget *window,
1055 GtkAdjustment *adjustment;
1058 /* Find this group's parent widget in the focused widget's anchestry. */
1059 for (p = widget; p; p = gtk_widget_get_parent (p))
1062 p = gtk_widget_get_parent (p);
1066 if (GTK_IS_TOOL_PALETTE (p))
1068 /* Check that the focused widgets is fully visible within
1069 * the group's parent widget and make it visible otherwise. */
1071 adjustment = gtk_tool_palette_get_hadjustment (GTK_TOOL_PALETTE (p));
1072 adjustment = gtk_tool_palette_get_vadjustment (GTK_TOOL_PALETTE (p));
1078 /* Handle vertical adjustment. */
1079 if (gtk_widget_translate_coordinates
1080 (widget, p, 0, 0, NULL, &y) && y < 0)
1082 y += adjustment->value;
1083 gtk_adjustment_clamp_page (adjustment, y, y + widget->allocation.height);
1085 else if (gtk_widget_translate_coordinates
1086 (widget, p, 0, widget->allocation.height, NULL, &y) &&
1087 y > p->allocation.height)
1089 y += adjustment->value;
1090 gtk_adjustment_clamp_page (adjustment, y - widget->allocation.height, y);
1094 adjustment = gtk_tool_palette_get_hadjustment (GTK_TOOL_PALETTE (p));
1100 /* Handle horizontal adjustment. */
1101 if (gtk_widget_translate_coordinates
1102 (widget, p, 0, 0, &x, NULL) && x < 0)
1104 x += adjustment->value;
1105 gtk_adjustment_clamp_page (adjustment, x, x + widget->allocation.width);
1107 else if (gtk_widget_translate_coordinates
1108 (widget, p, widget->allocation.width, 0, &x, NULL) &&
1109 x > p->allocation.width)
1111 x += adjustment->value;
1112 gtk_adjustment_clamp_page (adjustment, x - widget->allocation.width, x);
1121 gtk_tool_item_group_set_toplevel_window (GtkToolItemGroup *group,
1122 GtkWidget *toplevel)
1124 GtkToolItemGroupPrivate* priv = group->priv;
1126 if (toplevel != priv->toplevel)
1130 /* Disconnect focus tracking handler. */
1131 g_signal_handler_disconnect (priv->toplevel,
1132 priv->focus_set_id);
1134 priv->focus_set_id = 0;
1135 priv->toplevel = NULL;
1140 /* Install focus tracking handler. We connect to the window's
1141 * set-focus signal instead of connecting to the focus signal of
1144 * 1) Reduce the number of signal handlers used.
1145 * 2) Avoid special handling for group headers.
1146 * 3) Catch focus grabs not only for direct children,
1147 * but also for nested widgets.
1149 priv->focus_set_id =
1150 g_signal_connect (toplevel, "set-focus",
1151 G_CALLBACK (gtk_tool_item_group_set_focus_cb),
1154 priv->toplevel = toplevel;
1160 gtk_tool_item_group_realize (GtkWidget *widget)
1162 GtkWidget *toplevel_window;
1163 const gint border_width = GTK_CONTAINER (widget)->border_width;
1164 gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1165 GdkWindowAttr attributes;
1166 GdkDisplay *display;
1168 attributes.window_type = GDK_WINDOW_CHILD;
1169 attributes.x = widget->allocation.x + border_width;
1170 attributes.y = widget->allocation.y + border_width;
1171 attributes.width = widget->allocation.width - border_width * 2;
1172 attributes.height = widget->allocation.height - border_width * 2;
1173 attributes.wclass = GDK_INPUT_OUTPUT;
1174 attributes.visual = gtk_widget_get_visual (widget);
1175 attributes.colormap = gtk_widget_get_colormap (widget);
1176 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
1177 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
1178 | GDK_BUTTON_MOTION_MASK;
1180 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1181 &attributes, attributes_mask);
1183 display = gdk_drawable_get_display (widget->window);
1185 if (gdk_display_supports_composite (display))
1186 gdk_window_set_composited (widget->window, TRUE);
1188 gdk_window_set_user_data (widget->window, widget);
1189 widget->style = gtk_style_attach (widget->style, widget->window);
1190 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
1191 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1193 gtk_container_forall (GTK_CONTAINER (widget),
1194 (GtkCallback) gtk_widget_set_parent_window,
1197 gtk_widget_queue_resize_no_redraw (widget);
1199 toplevel_window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
1200 gtk_tool_item_group_set_toplevel_window (GTK_TOOL_ITEM_GROUP (widget),
1205 gtk_tool_item_group_unrealize (GtkWidget *widget)
1207 gtk_tool_item_group_set_toplevel_window (GTK_TOOL_ITEM_GROUP (widget), NULL);
1208 GTK_WIDGET_CLASS (gtk_tool_item_group_parent_class)->unrealize (widget);
1212 gtk_tool_item_group_style_set (GtkWidget *widget,
1213 GtkStyle *previous_style)
1215 gtk_tool_item_group_header_adjust_style (GTK_TOOL_ITEM_GROUP (widget));
1216 GTK_WIDGET_CLASS (gtk_tool_item_group_parent_class)->style_set (widget, previous_style);
1220 gtk_tool_item_group_add (GtkContainer *container,
1223 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (container));
1224 g_return_if_fail (GTK_IS_TOOL_ITEM (widget));
1226 gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (container),
1227 GTK_TOOL_ITEM (widget), -1);
1231 gtk_tool_item_group_remove (GtkContainer *container,
1234 GtkToolItemGroup *group;
1235 GtkToolItemGroupPrivate* priv;
1238 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (container));
1239 group = GTK_TOOL_ITEM_GROUP (container);
1242 for (it = priv->children; it != NULL; it = it->next)
1244 GtkToolItemGroupChild *child_info = it->data;
1246 if ((GtkWidget *)child_info->item == child)
1248 g_object_unref (child);
1249 gtk_widget_unparent (child);
1251 g_free (child_info);
1252 priv->children = g_list_delete_link (priv->children, it);
1254 gtk_widget_queue_resize (GTK_WIDGET (container));
1261 gtk_tool_item_group_forall (GtkContainer *container,
1263 GtkCallback callback,
1264 gpointer callback_data)
1266 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (container);
1267 GtkToolItemGroupPrivate* priv = group->priv;
1270 if (internals && priv->header)
1271 callback (priv->header, callback_data);
1273 children = priv->children;
1276 GtkToolItemGroupChild *child = children->data;
1277 children = children->next; /* store pointer before call to callback
1278 because the child pointer is invalid if the
1279 child->item is removed from the item group
1282 callback (GTK_WIDGET (child->item), callback_data);
1287 gtk_tool_item_group_child_type (GtkContainer *container)
1289 return GTK_TYPE_TOOL_ITEM;
1292 static GtkToolItemGroupChild *
1293 gtk_tool_item_group_get_child (GtkToolItemGroup *group,
1301 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), NULL);
1302 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), NULL);
1304 for (it = group->priv->children, i = 0; it != NULL; it = it->next, ++i)
1306 GtkToolItemGroupChild *child = it->data;
1308 if (child->item == item)
1324 gtk_tool_item_group_get_item_packing (GtkToolItemGroup *group,
1326 gboolean *homogeneous,
1331 GtkToolItemGroupChild *child;
1333 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1334 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
1336 child = gtk_tool_item_group_get_child (group, item, NULL, NULL);
1341 *expand = child->expand;
1344 *homogeneous = child->homogeneous;
1347 *fill = child->fill;
1350 *new_row = child->new_row;
1354 gtk_tool_item_group_set_item_packing (GtkToolItemGroup *group,
1356 gboolean homogeneous,
1361 GtkToolItemGroupChild *child;
1362 gboolean changed = FALSE;
1364 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1365 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
1367 child = gtk_tool_item_group_get_child (group, item, NULL, NULL);
1371 gtk_widget_freeze_child_notify (GTK_WIDGET (item));
1373 if (child->homogeneous != homogeneous)
1375 child->homogeneous = homogeneous;
1377 gtk_widget_child_notify (GTK_WIDGET (item), "homogeneous");
1379 if (child->expand != expand)
1381 child->expand = expand;
1383 gtk_widget_child_notify (GTK_WIDGET (item), "expand");
1385 if (child->fill != fill)
1389 gtk_widget_child_notify (GTK_WIDGET (item), "fill");
1391 if (child->new_row != new_row)
1393 child->new_row = new_row;
1395 gtk_widget_child_notify (GTK_WIDGET (item), "new-row");
1398 gtk_widget_thaw_child_notify (GTK_WIDGET (item));
1400 if (changed && GTK_WIDGET_VISIBLE (group) && GTK_WIDGET_VISIBLE (item))
1401 gtk_widget_queue_resize (GTK_WIDGET (group));
1405 gtk_tool_item_group_set_child_property (GtkContainer *container,
1408 const GValue *value,
1411 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (container);
1412 GtkToolItem *item = GTK_TOOL_ITEM (child);
1413 gboolean homogeneous, expand, fill, new_row;
1415 if (prop_id != CHILD_PROP_POSITION)
1416 gtk_tool_item_group_get_item_packing (group, item,
1424 case CHILD_PROP_HOMOGENEOUS:
1425 gtk_tool_item_group_set_item_packing (group, item,
1426 g_value_get_boolean (value),
1432 case CHILD_PROP_EXPAND:
1433 gtk_tool_item_group_set_item_packing (group, item,
1435 g_value_get_boolean (value),
1440 case CHILD_PROP_FILL:
1441 gtk_tool_item_group_set_item_packing (group, item,
1444 g_value_get_boolean (value),
1448 case CHILD_PROP_NEW_ROW:
1449 gtk_tool_item_group_set_item_packing (group, item,
1453 g_value_get_boolean (value));
1456 case CHILD_PROP_POSITION:
1457 gtk_tool_item_group_set_item_position (group, item, g_value_get_int (value));
1461 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
1467 gtk_tool_item_group_get_child_property (GtkContainer *container,
1473 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (container);
1474 GtkToolItem *item = GTK_TOOL_ITEM (child);
1475 gboolean homogeneous, expand, fill, new_row;
1477 if (prop_id != CHILD_PROP_POSITION)
1478 gtk_tool_item_group_get_item_packing (group, item,
1486 case CHILD_PROP_HOMOGENEOUS:
1487 g_value_set_boolean (value, homogeneous);
1490 case CHILD_PROP_EXPAND:
1491 g_value_set_boolean (value, expand);
1494 case CHILD_PROP_FILL:
1495 g_value_set_boolean (value, fill);
1498 case CHILD_PROP_NEW_ROW:
1499 g_value_set_boolean (value, new_row);
1502 case CHILD_PROP_POSITION:
1503 g_value_set_int (value, gtk_tool_item_group_get_item_position (group, item));
1507 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
1513 gtk_tool_item_group_class_init (GtkToolItemGroupClass *cls)
1515 GObjectClass *oclass = G_OBJECT_CLASS (cls);
1516 GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
1517 GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
1519 oclass->set_property = gtk_tool_item_group_set_property;
1520 oclass->get_property = gtk_tool_item_group_get_property;
1521 oclass->finalize = gtk_tool_item_group_finalize;
1522 oclass->dispose = gtk_tool_item_group_dispose;
1524 wclass->size_request = gtk_tool_item_group_size_request;
1525 wclass->size_allocate = gtk_tool_item_group_size_allocate;
1526 wclass->realize = gtk_tool_item_group_realize;
1527 wclass->unrealize = gtk_tool_item_group_unrealize;
1528 wclass->style_set = gtk_tool_item_group_style_set;
1529 wclass->screen_changed = gtk_tool_item_group_screen_changed;
1531 cclass->add = gtk_tool_item_group_add;
1532 cclass->remove = gtk_tool_item_group_remove;
1533 cclass->forall = gtk_tool_item_group_forall;
1534 cclass->child_type = gtk_tool_item_group_child_type;
1535 cclass->set_child_property = gtk_tool_item_group_set_child_property;
1536 cclass->get_child_property = gtk_tool_item_group_get_child_property;
1538 g_object_class_install_property (oclass, PROP_LABEL,
1539 g_param_spec_string ("label",
1541 P_("The human-readable title of this item group"),
1543 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1544 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1546 g_object_class_install_property (oclass, PROP_LABEL_WIDGET,
1547 g_param_spec_object ("label-widget",
1549 P_("A widget to display in place of the usual label"),
1551 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1552 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1554 g_object_class_install_property (oclass, PROP_COLLAPSED,
1555 g_param_spec_boolean ("collapsed",
1557 P_("Wether the group has been collapsed and items are hidden"),
1559 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1560 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1562 g_object_class_install_property (oclass, PROP_ELLIPSIZE,
1563 g_param_spec_enum ("ellipsize",
1565 P_("Ellipsize for item group headers"),
1566 PANGO_TYPE_ELLIPSIZE_MODE, DEFAULT_ELLIPSIZE,
1567 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1568 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1570 g_object_class_install_property (oclass, PROP_RELIEF,
1571 g_param_spec_enum ("header-relief",
1572 P_("Header Relief"),
1573 P_("Relief of the group header button"),
1574 GTK_TYPE_RELIEF_STYLE, GTK_RELIEF_NORMAL,
1575 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1576 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1578 gtk_widget_class_install_style_property (wclass,
1579 g_param_spec_int ("expander-size",
1580 P_("Expander Size"),
1581 P_("Size of the expander arrow"),
1584 DEFAULT_EXPANDER_SIZE,
1585 G_PARAM_READABLE | G_PARAM_STATIC_NAME |
1586 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1588 gtk_widget_class_install_style_property (wclass,
1589 g_param_spec_int ("header-spacing",
1590 P_("Header Spacing"),
1591 P_("Spacing between expander arrow and caption"),
1594 DEFAULT_HEADER_SPACING,
1595 G_PARAM_READABLE | G_PARAM_STATIC_NAME |
1596 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1598 gtk_container_class_install_child_property (cclass, CHILD_PROP_HOMOGENEOUS,
1599 g_param_spec_boolean ("homogeneous",
1601 P_("Whether the item should be the same size as other homogeneous items"),
1603 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1604 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1606 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1607 g_param_spec_boolean ("expand",
1609 P_("Whether the item should receive extra space when the toolbar grows"),
1611 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1612 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1614 gtk_container_class_install_child_property (cclass, CHILD_PROP_FILL,
1615 g_param_spec_boolean ("fill",
1617 P_("Whether the item should fill the avaiable space"),
1619 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1620 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1622 gtk_container_class_install_child_property (cclass, CHILD_PROP_NEW_ROW,
1623 g_param_spec_boolean ("new-row",
1625 P_("Whether the item should start a new row"),
1627 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1628 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1630 gtk_container_class_install_child_property (cclass, CHILD_PROP_POSITION,
1631 g_param_spec_int ("position",
1633 P_("Position of the item within this group"),
1637 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1638 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1640 g_type_class_add_private (cls, sizeof (GtkToolItemGroupPrivate));
1644 * gtk_tool_item_group_new:
1645 * @label: the label of the new group.
1647 * Creates a new tool item group with label @label.
1649 * Returns: a new #GtkToolItemGroup.
1654 gtk_tool_item_group_new (const gchar *label)
1656 return g_object_new (GTK_TYPE_TOOL_ITEM_GROUP, "label",
1661 * gtk_tool_item_group_set_label:
1662 * @group: an #GtkToolItemGroup.
1663 * @label: the new human-readable label of of the group.
1665 * Sets the label of the tool item group. The label is displayed in the header
1671 gtk_tool_item_group_set_label (GtkToolItemGroup *group,
1674 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1678 gtk_tool_item_group_set_label_widget (group, NULL);
1682 GtkWidget *child = gtk_label_new (label);
1684 gtk_label_set_use_underline (GTK_LABEL (child), group->priv->use_underline);
1685 gtk_label_set_use_markup (GTK_LABEL (child), group->priv->use_markup);
1687 gtk_widget_show (child);
1689 gtk_tool_item_group_set_label_widget (group, child);
1692 g_object_notify (G_OBJECT (group), "label");
1696 * gtk_tool_item_group_set_label_widget:
1697 * @group: an #GtkToolItemGroup.
1698 * @widget: the new human-readable label of of the group.
1700 * Sets the label of the tool item group. The label is displayed in the header
1706 gtk_tool_item_group_set_label_widget (GtkToolItemGroup *group,
1707 GtkWidget *label_widget)
1709 GtkToolItemGroupPrivate* priv;
1710 GtkWidget *alignment;
1712 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1713 g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
1714 g_return_if_fail (label_widget == NULL || label_widget->parent == NULL);
1718 if (priv->label_widget == label_widget)
1721 alignment = gtk_tool_item_group_get_alignment (group);
1723 if (priv->label_widget)
1725 gtk_widget_set_state (priv->label_widget, GTK_STATE_NORMAL);
1726 gtk_container_remove (GTK_CONTAINER (alignment), priv->label_widget);
1732 gtk_container_add (GTK_CONTAINER (alignment), label_widget);
1735 priv->label_widget = label_widget;
1737 if (GTK_WIDGET_VISIBLE (group))
1738 gtk_widget_queue_resize (GTK_WIDGET (group));
1740 /* Only show the header widget if the group has children: */
1741 if (label_widget && priv->children)
1742 gtk_widget_show (priv->header);
1744 gtk_widget_hide (priv->header);
1746 g_object_freeze_notify (G_OBJECT (group));
1747 g_object_notify (G_OBJECT (group), "label-widget");
1748 g_object_notify (G_OBJECT (group), "label");
1749 g_object_thaw_notify (G_OBJECT (group));
1753 * gtk_tool_item_group_header_relief:
1754 * @group: an #GtkToolItemGroup.
1755 * @style: The GtkReliefStyle
1757 * Set the button relief of the group header. See #gtk_button_set_relief for
1763 gtk_tool_item_group_set_header_relief (GtkToolItemGroup *group,
1764 GtkReliefStyle style)
1766 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1767 gtk_button_set_relief (GTK_BUTTON(group->priv->header), style);
1771 gtk_tool_item_group_get_animation_timestamp (GtkToolItemGroup *group)
1774 g_source_get_current_time (group->priv->animation_timeout, &now);
1775 return (now.tv_sec * G_USEC_PER_SEC + now.tv_usec - group->priv->animation_start) / 1000;
1779 gtk_tool_item_group_force_expose (GtkToolItemGroup *group)
1781 GtkToolItemGroupPrivate* priv = group->priv;
1783 if (GTK_WIDGET_REALIZED (priv->header))
1785 GtkWidget *alignment = gtk_tool_item_group_get_alignment (group);
1788 /* Find the header button's arrow area... */
1789 area.x = alignment->allocation.x;
1790 area.y = alignment->allocation.y + (alignment->allocation.height - priv->expander_size) / 2;
1791 area.height = priv->expander_size;
1792 area.width = priv->expander_size;
1794 /* ... and invalidated it to get it animated. */
1795 gdk_window_invalidate_rect (priv->header->window, &area, TRUE);
1798 if (GTK_WIDGET_REALIZED (group))
1800 GtkWidget *widget = GTK_WIDGET (group);
1801 GtkWidget *parent = gtk_widget_get_parent (widget);
1802 int x, y, width, height;
1804 /* Find the tool item area button's arrow area... */
1805 width = widget->allocation.width;
1806 height = widget->allocation.height;
1808 gtk_widget_translate_coordinates (widget, parent, 0, 0, &x, &y);
1810 if (GTK_WIDGET_VISIBLE (priv->header))
1812 height -= priv->header->allocation.height;
1813 y += priv->header->allocation.height;
1816 /* ... and invalidated it to get it animated. */
1817 gtk_widget_queue_draw_area (parent, x, y, width, height);
1822 gtk_tool_item_group_animation_cb (gpointer data)
1824 GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (data);
1825 GtkToolItemGroupPrivate* priv = group->priv;
1826 gint64 timestamp = gtk_tool_item_group_get_animation_timestamp (group);
1828 /* Enque this early to reduce number of expose events. */
1829 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (group));
1831 /* Figure out current style of the expander arrow. */
1832 if (priv->collapsed)
1834 if (priv->expander_style == GTK_EXPANDER_EXPANDED)
1835 priv->expander_style = GTK_EXPANDER_SEMI_COLLAPSED;
1837 priv->expander_style = GTK_EXPANDER_COLLAPSED;
1841 if (priv->expander_style == GTK_EXPANDER_COLLAPSED)
1842 priv->expander_style = GTK_EXPANDER_SEMI_EXPANDED;
1844 priv->expander_style = GTK_EXPANDER_EXPANDED;
1847 gtk_tool_item_group_force_expose (group);
1849 /* Finish animation when done. */
1850 if (timestamp >= ANIMATION_DURATION)
1851 priv->animation_timeout = NULL;
1853 /* Ensure that all composited windows and child windows are repainted, before
1854 * the parent widget gets its expose-event. This is needed to avoid heavy
1855 * rendering artifacts. GTK+ should take care about this issue by itself I
1856 * guess, but currently it doesn't. Also I don't understand the parameters
1857 * of this issue well enough yet, to file a bug report.
1859 gdk_window_process_updates (GTK_WIDGET (group)->window, TRUE);
1861 return (priv->animation_timeout != NULL);
1865 * gtk_tool_item_group_set_collapsed:
1866 * @group: an #GtkToolItemGroup.
1867 * @collapsed: whether the @group should be collapsed or expanded.
1869 * Sets whether the @group should be collapsed or expanded.
1874 gtk_tool_item_group_set_collapsed (GtkToolItemGroup *group,
1878 GtkToolItemGroupPrivate* priv;
1880 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1884 parent = gtk_widget_get_parent (GTK_WIDGET (group));
1885 if (GTK_IS_TOOL_PALETTE (parent) && !collapsed)
1886 _gtk_tool_palette_set_expanding_child (GTK_TOOL_PALETTE (parent),
1887 GTK_WIDGET (group));
1888 if (collapsed != priv->collapsed)
1890 if (priv->animation)
1894 g_get_current_time (&now);
1896 if (priv->animation_timeout)
1897 g_source_destroy (priv->animation_timeout);
1899 priv->animation_start = (now.tv_sec * G_USEC_PER_SEC + now.tv_usec);
1900 priv->animation_timeout = g_timeout_source_new (ANIMATION_TIMEOUT);
1902 g_source_set_callback (priv->animation_timeout,
1903 gtk_tool_item_group_animation_cb,
1906 g_source_attach (priv->animation_timeout, NULL);
1910 priv->expander_style = GTK_EXPANDER_COLLAPSED;
1911 gtk_tool_item_group_force_expose (group);
1914 priv->collapsed = collapsed;
1915 g_object_notify (G_OBJECT (group), "collapsed");
1920 * gtk_tool_item_group_set_ellipsize:
1921 * @group: an #GtkToolItemGroup.
1922 * @ellipsize: the #PangoEllipsizeMode labels in @group should use.
1924 * Sets the ellipsization mode which should be used by labels in @group.
1929 gtk_tool_item_group_set_ellipsize (GtkToolItemGroup *group,
1930 PangoEllipsizeMode ellipsize)
1932 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1934 if (ellipsize != group->priv->ellipsize)
1936 group->priv->ellipsize = ellipsize;
1937 gtk_tool_item_group_header_adjust_style (group);
1938 g_object_notify (G_OBJECT (group), "ellipsize");
1939 _gtk_tool_item_group_palette_reconfigured (group);
1944 * gtk_tool_item_group_get_label:
1945 * @group: an #GtkToolItemGroup.
1947 * Gets the label of @group.
1949 * Returns: the label of @group. The label is an internal string of @group and must not be modified.
1953 G_CONST_RETURN gchar*
1954 gtk_tool_item_group_get_label (GtkToolItemGroup *group)
1956 GtkToolItemGroupPrivate *priv;
1958 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), NULL);
1962 if (GTK_IS_LABEL (priv->label_widget))
1963 return gtk_label_get_label (GTK_LABEL (priv->label_widget));
1969 * gtk_tool_item_group_get_label_widget:
1970 * @group: an #GtkToolItemGroup.
1972 * Gets the label of @group.
1974 * Returns: the label of @group. The label is an internal string of @group and must not be modified.
1979 gtk_tool_item_group_get_label_widget (GtkToolItemGroup *group)
1981 GtkWidget *alignment = gtk_tool_item_group_get_alignment (group);
1982 return gtk_bin_get_child (GTK_BIN (alignment));
1986 * gtk_tool_item_group_get_collapsed:
1987 * @group: an GtkToolItemGroup.
1989 * Gets whether @group is collapsed or expanded.
1991 * Returns: %TRUE if @group is collapsed, %FALSE if it is expanded.
1996 gtk_tool_item_group_get_collapsed (GtkToolItemGroup *group)
1998 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_COLLAPSED);
1999 return group->priv->collapsed;
2003 * gtk_tool_item_group_get_ellipsize:
2004 * @group: an #GtkToolItemGroup.
2006 * Gets the ellipsization mode of @group.
2008 * Returns: the #PangoEllipsizeMode of @group.
2013 gtk_tool_item_group_get_ellipsize (GtkToolItemGroup *group)
2015 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_ELLIPSIZE);
2016 return group->priv->ellipsize;
2020 * gtk_tool_item_group_get_header_relief:
2021 * @group: an #GtkToolItemGroup.
2023 * Gets the relief mode of the header button of @group.
2025 * Returns: the #GtkReliefStyle
2030 gtk_tool_item_group_get_header_relief (GtkToolItemGroup *group)
2032 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), GTK_RELIEF_NORMAL);
2033 return gtk_button_get_relief (GTK_BUTTON (group->priv->header));
2037 * gtk_tool_item_group_insert:
2038 * @group: an #GtkToolItemGroup.
2039 * @item: the #GtkToolItem to insert into @group.
2040 * @position: the position of @item in @group, starting with 0. The position -1 means end of list.
2042 * Inserts @item at @position in the list of children of @group.
2047 gtk_tool_item_group_insert (GtkToolItemGroup *group,
2051 GtkWidget *parent, *child_widget;
2052 GtkToolItemGroupChild *child;
2054 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
2055 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2056 g_return_if_fail (position >= -1);
2058 parent = gtk_widget_get_parent (GTK_WIDGET (group));
2060 child = g_new (GtkToolItemGroupChild, 1);
2061 child->item = g_object_ref_sink (item);
2062 child->homogeneous = TRUE;
2063 child->expand = FALSE;
2065 child->new_row = FALSE;
2067 group->priv->children = g_list_insert (group->priv->children, child, position);
2069 if (GTK_IS_TOOL_PALETTE (parent))
2070 _gtk_tool_palette_child_set_drag_source (GTK_WIDGET (item), parent);
2072 child_widget = gtk_bin_get_child (GTK_BIN (item));
2074 if (GTK_IS_BUTTON (child_widget))
2075 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), TRUE);
2077 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (group));
2081 * gtk_tool_item_group_set_item_position:
2082 * @group: an #GtkToolItemGroup.
2083 * @item: the #GtkToolItem to move to a new position, should be a child of @group.
2084 * @position: the new position of @item in @group, starting with 0. The position -1 means end of list.
2086 * Sets the position of @item in the list of children of @group.
2091 gtk_tool_item_group_set_item_position (GtkToolItemGroup *group,
2097 GtkToolItemGroupChild *child;
2098 GtkToolItemGroupPrivate* priv;
2100 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
2101 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2103 g_return_if_fail (position >= -1);
2105 child = gtk_tool_item_group_get_child (group, item, &old_position, &link);
2108 g_return_if_fail (child != NULL);
2110 if (position == old_position)
2113 priv->children = g_list_delete_link (priv->children, link);
2114 priv->children = g_list_insert (priv->children, child, position);
2116 gtk_widget_child_notify (GTK_WIDGET (item), "position");
2117 if (GTK_WIDGET_VISIBLE (group) && GTK_WIDGET_VISIBLE (item))
2118 gtk_widget_queue_resize (GTK_WIDGET (group));
2122 * gtk_tool_item_group_get_item_position:
2123 * @group: an #GtkToolItemGroup.
2124 * @item: a #GtkToolItem.
2126 * Gets the position of @item in @group as index.
2128 * Returns: the index of @item in @group or -1 if @item is no child of @group.
2133 gtk_tool_item_group_get_item_position (GtkToolItemGroup *group,
2138 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
2139 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2141 if (gtk_tool_item_group_get_child (group, item, &position, NULL))
2148 * gtk_tool_item_group_get_n_items:
2149 * @group: an #GtkToolItemGroup.
2151 * Gets the number of tool items in group.
2153 * Returns: the number of tool items in group.
2158 gtk_tool_item_group_get_n_items (GtkToolItemGroup *group)
2160 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), 0);
2162 return g_list_length (group->priv->children);
2166 * gtk_tool_item_group_get_nth_item:
2167 * @group: an #GtkToolItemGroup.
2168 * @index: the index.
2170 * Gets the tool item at index in group.
2172 * Returns: the #GtkToolItem at index.
2177 gtk_tool_item_group_get_nth_item (GtkToolItemGroup *group,
2180 GtkToolItemGroupChild *child;
2182 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), NULL);
2184 child = g_list_nth_data (group->priv->children, index);
2186 return child != NULL ? child->item : NULL;
2190 * gtk_tool_item_group_get_drop_item:
2191 * @group: an #GtkToolItemGroup.
2192 * @x: the x position.
2193 * @y: the y position.
2195 * Gets the tool item at position (x, y).
2197 * Returns: the #GtkToolItem at position (x, y).
2202 gtk_tool_item_group_get_drop_item (GtkToolItemGroup *group,
2206 GtkAllocation *allocation;
2207 GtkOrientation orientation;
2210 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), NULL);
2212 allocation = >K_WIDGET (group)->allocation;
2213 orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
2215 g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
2216 g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
2218 for (it = group->priv->children; it != NULL; it = it->next)
2220 GtkToolItemGroupChild *child = it->data;
2221 GtkToolItem *item = child->item;
2224 if (!item || !gtk_tool_item_group_is_item_visible (group, child))
2227 allocation = >K_WIDGET (item)->allocation;
2229 x0 = x - allocation->x;
2230 y0 = y - allocation->y;
2232 if (x0 >= 0 && x0 < allocation->width &&
2233 y0 >= 0 && y0 < allocation->height)
2241 _gtk_tool_item_group_item_size_request (GtkToolItemGroup *group,
2242 GtkRequisition *item_size,
2243 gboolean homogeneous_only,
2244 gint *requested_rows)
2246 GtkRequisition child_requisition;
2249 gboolean new_row = TRUE;
2250 GtkOrientation orientation;
2251 GtkToolbarStyle style;
2253 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
2254 g_return_if_fail (NULL != item_size);
2256 orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
2257 style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
2259 item_size->width = item_size->height = 0;
2261 for (it = group->priv->children; it != NULL; it = it->next)
2263 GtkToolItemGroupChild *child = it->data;
2265 if (!gtk_tool_item_group_is_item_visible (group, child))
2268 if (child->new_row || new_row)
2274 if (!child->homogeneous && child->expand)
2277 gtk_widget_size_request (GTK_WIDGET (child->item), &child_requisition);
2279 if (!homogeneous_only || child->homogeneous)
2280 item_size->width = MAX (item_size->width, child_requisition.width);
2281 item_size->height = MAX (item_size->height, child_requisition.height);
2285 *requested_rows = rows;
2289 _gtk_tool_item_group_paint (GtkToolItemGroup *group,
2292 GtkWidget *widget = GTK_WIDGET (group);
2293 GtkToolItemGroupPrivate* priv = group->priv;
2295 gdk_cairo_set_source_pixmap (cr, widget->window,
2296 widget->allocation.x,
2297 widget->allocation.y);
2299 if (priv->animation_timeout)
2301 GtkOrientation orientation = gtk_tool_item_group_get_orientation (GTK_TOOL_SHELL (group));
2302 cairo_pattern_t *mask;
2305 if (GTK_ORIENTATION_VERTICAL == orientation)
2306 v1 = widget->allocation.height;
2308 v1 = widget->allocation.width;
2312 if (!GTK_WIDGET_VISIBLE (priv->header))
2314 else if (GTK_ORIENTATION_VERTICAL == orientation)
2315 v0 = MAX (v0, priv->header->allocation.height);
2317 v0 = MAX (v0, priv->header->allocation.width);
2319 v1 = MIN (v0 + 256, v1);
2321 if (GTK_ORIENTATION_VERTICAL == orientation)
2323 v0 += widget->allocation.y;
2324 v1 += widget->allocation.y;
2326 mask = cairo_pattern_create_linear (0.0, v0, 0.0, v1);
2330 v0 += widget->allocation.x;
2331 v1 += widget->allocation.x;
2333 mask = cairo_pattern_create_linear (v0, 0.0, v1, 0.0);
2336 cairo_pattern_add_color_stop_rgba (mask, 0.00, 0.0, 0.0, 0.0, 1.00);
2337 cairo_pattern_add_color_stop_rgba (mask, 0.25, 0.0, 0.0, 0.0, 0.25);
2338 cairo_pattern_add_color_stop_rgba (mask, 0.50, 0.0, 0.0, 0.0, 0.10);
2339 cairo_pattern_add_color_stop_rgba (mask, 0.75, 0.0, 0.0, 0.0, 0.01);
2340 cairo_pattern_add_color_stop_rgba (mask, 1.00, 0.0, 0.0, 0.0, 0.00);
2342 cairo_mask (cr, mask);
2343 cairo_pattern_destroy (mask);
2350 _gtk_tool_item_group_get_size_for_limit (GtkToolItemGroup *group,
2355 GtkRequisition requisition;
2356 GtkToolItemGroupPrivate* priv = group->priv;
2358 gtk_widget_size_request (GTK_WIDGET (group), &requisition);
2360 if (!priv->collapsed || priv->animation_timeout)
2362 GtkAllocation allocation = { 0, 0, requisition.width, requisition.height };
2363 GtkRequisition inquery;
2366 allocation.width = limit;
2368 allocation.height = limit;
2370 gtk_tool_item_group_real_size_query (GTK_WIDGET (group),
2371 &allocation, &inquery);
2374 inquery.height -= requisition.height;
2376 inquery.width -= requisition.width;
2378 if (priv->animation_timeout && animation)
2380 gint64 timestamp = gtk_tool_item_group_get_animation_timestamp (group);
2382 timestamp = MIN (timestamp, ANIMATION_DURATION);
2384 if (priv->collapsed)
2385 timestamp = ANIMATION_DURATION - timestamp;
2389 inquery.height *= timestamp;
2390 inquery.height /= ANIMATION_DURATION;
2394 inquery.width *= timestamp;
2395 inquery.width /= ANIMATION_DURATION;
2400 requisition.height += inquery.height;
2402 requisition.width += inquery.width;
2405 return (vertical ? requisition.height : requisition.width);
2409 _gtk_tool_item_group_get_height_for_width (GtkToolItemGroup *group,
2412 return _gtk_tool_item_group_get_size_for_limit (group, width, TRUE, group->priv->animation);
2416 _gtk_tool_item_group_get_width_for_height (GtkToolItemGroup *group,
2419 return _gtk_tool_item_group_get_size_for_limit (group, height, FALSE, TRUE);
2423 gtk_tool_palette_reconfigured_foreach_item (GtkWidget *child,
2426 if (GTK_IS_TOOL_ITEM (child))
2427 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (child));
2432 _gtk_tool_item_group_palette_reconfigured (GtkToolItemGroup *group)
2434 gtk_container_foreach (GTK_CONTAINER (group),
2435 gtk_tool_palette_reconfigured_foreach_item,
2438 gtk_tool_item_group_header_adjust_style (group);