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, see <http://www.gnu.org/licenses/>.
26 #include "gtktoolpaletteprivate.h"
27 #include "gtkmarshalers.h"
28 #include "gtktypebuiltins.h"
29 #include "gtkprivate.h"
30 #include "gtkscrollable.h"
31 #include "gtkorientableprivate.h"
34 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
35 #define DEFAULT_ORIENTATION GTK_ORIENTATION_VERTICAL
36 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_ICONS
38 #define DEFAULT_CHILD_EXCLUSIVE FALSE
39 #define DEFAULT_CHILD_EXPAND FALSE
42 * SECTION:gtktoolpalette
43 * @Short_description: A tool palette with categories
44 * @Title: GtkToolPalette
46 * A #GtkToolPalette allows you to add #GtkToolItem<!-- -->s to a palette-like
47 * container with different categories and drag and drop support.
49 * A #GtkToolPalette is created with a call to gtk_tool_palette_new().
51 * #GtkToolItem<!-- -->s cannot be added directly to a #GtkToolPalette -
52 * instead they are added to a #GtkToolItemGroup which can than be added
53 * to a #GtkToolPalette. To add a #GtkToolItemGroup to a #GtkToolPalette,
54 * use gtk_container_add().
57 * GtkWidget *palette, *group;
60 * palette = gtk_tool_palette_new ();
61 * group = gtk_tool_item_group_new (_("Test Category"));
62 * gtk_container_add (GTK_CONTAINER (palette), group);
64 * item = gtk_tool_button_new_from_stock (GTK_STOCK_OK);
65 * gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
68 * The easiest way to use drag and drop with #GtkToolPalette is to call
69 * gtk_tool_palette_add_drag_dest() with the desired drag source @palette
70 * and the desired drag target @widget. Then gtk_tool_palette_get_drag_item()
71 * can be used to get the dragged item in the #GtkWidget::drag-data-received
72 * signal handler of the drag target.
76 * passive_canvas_drag_data_received (GtkWidget *widget,
77 * GdkDragContext *context,
80 * GtkSelectionData *selection,
88 * /<!-- -->* Get the dragged item *<!-- -->/
89 * palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context),
90 * GTK_TYPE_TOOL_PALETTE);
91 * if (palette != NULL)
92 * item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
95 * /<!-- -->* Do something with item *<!-- -->/
98 * GtkWidget *target, palette;
100 * palette = gtk_tool_palette_new ();
101 * target = gtk_drawing_area_new ();
103 * g_signal_connect (G_OBJECT (target), "drag-data-received",
104 * G_CALLBACK (passive_canvas_drag_data_received), NULL);
105 * gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target,
106 * GTK_DEST_DEFAULT_ALL,
107 * GTK_TOOL_PALETTE_DRAG_ITEMS,
114 typedef struct _GtkToolItemGroupInfo GtkToolItemGroupInfo;
115 typedef struct _GtkToolPaletteDragData GtkToolPaletteDragData;
133 CHILD_PROP_EXCLUSIVE,
137 struct _GtkToolItemGroupInfo
139 GtkToolItemGroup *widget;
141 gulong notify_collapsed;
147 struct _GtkToolPalettePrivate
151 GtkAdjustment *hadjustment;
152 GtkAdjustment *vadjustment;
154 GtkIconSize icon_size;
155 gboolean icon_size_set;
156 GtkOrientation orientation;
157 GtkToolbarStyle style;
160 GtkWidget *expanding_child;
162 GtkSizeGroup *text_size_group;
164 GtkSettings *settings;
165 gulong settings_connection;
167 guint drag_source : 2;
169 /* GtkScrollablePolicy needs to be checked when
170 * driving the scrollable adjustment values */
171 guint hscroll_policy : 1;
172 guint vscroll_policy : 1;
175 struct _GtkToolPaletteDragData
177 GtkToolPalette *palette;
181 static GdkAtom dnd_target_atom_item = GDK_NONE;
182 static GdkAtom dnd_target_atom_group = GDK_NONE;
184 static const GtkTargetEntry dnd_targets[] =
186 { "application/x-gtk-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
187 { "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
190 static void gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
191 GtkAdjustment *adjustment);
192 static void gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
193 GtkAdjustment *adjustment);
196 G_DEFINE_TYPE_WITH_CODE (GtkToolPalette,
199 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
200 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
203 gtk_tool_palette_init (GtkToolPalette *palette)
205 palette->priv = G_TYPE_INSTANCE_GET_PRIVATE (palette,
206 GTK_TYPE_TOOL_PALETTE,
207 GtkToolPalettePrivate);
209 palette->priv->groups = g_ptr_array_sized_new (4);
210 g_ptr_array_set_free_func (palette->priv->groups, g_free);
212 palette->priv->icon_size = DEFAULT_ICON_SIZE;
213 palette->priv->icon_size_set = FALSE;
214 palette->priv->orientation = DEFAULT_ORIENTATION;
215 palette->priv->style = DEFAULT_TOOLBAR_STYLE;
216 palette->priv->style_set = FALSE;
218 palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
222 gtk_tool_palette_reconfigured (GtkToolPalette *palette)
226 for (i = 0; i < palette->priv->groups->len; ++i)
228 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
230 _gtk_tool_item_group_palette_reconfigured (info->widget);
233 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
237 gtk_tool_palette_set_property (GObject *object,
242 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
247 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
249 palette->priv->icon_size = g_value_get_enum (value);
250 gtk_tool_palette_reconfigured (palette);
254 case PROP_ICON_SIZE_SET:
255 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
257 palette->priv->icon_size_set = g_value_get_enum (value);
258 gtk_tool_palette_reconfigured (palette);
262 case PROP_ORIENTATION:
263 if ((guint) g_value_get_enum (value) != palette->priv->orientation)
265 palette->priv->orientation = g_value_get_enum (value);
266 _gtk_orientable_set_style_classes (GTK_ORIENTABLE (palette));
267 gtk_tool_palette_reconfigured (palette);
271 case PROP_TOOLBAR_STYLE:
272 if ((guint) g_value_get_enum (value) != palette->priv->style)
274 palette->priv->style = g_value_get_enum (value);
275 gtk_tool_palette_reconfigured (palette);
279 case PROP_HADJUSTMENT:
280 gtk_tool_palette_set_hadjustment (palette, g_value_get_object (value));
283 case PROP_VADJUSTMENT:
284 gtk_tool_palette_set_vadjustment (palette, g_value_get_object (value));
287 case PROP_HSCROLL_POLICY:
288 palette->priv->hscroll_policy = g_value_get_enum (value);
289 gtk_widget_queue_resize (GTK_WIDGET (palette));
292 case PROP_VSCROLL_POLICY:
293 palette->priv->vscroll_policy = g_value_get_enum (value);
294 gtk_widget_queue_resize (GTK_WIDGET (palette));
298 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
304 gtk_tool_palette_get_property (GObject *object,
309 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
314 g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
317 case PROP_ICON_SIZE_SET:
318 g_value_set_boolean (value, palette->priv->icon_size_set);
321 case PROP_ORIENTATION:
322 g_value_set_enum (value, palette->priv->orientation);
325 case PROP_TOOLBAR_STYLE:
326 g_value_set_enum (value, gtk_tool_palette_get_style (palette));
329 case PROP_HADJUSTMENT:
330 g_value_set_object (value, palette->priv->hadjustment);
333 case PROP_VADJUSTMENT:
334 g_value_set_object (value, palette->priv->vadjustment);
337 case PROP_HSCROLL_POLICY:
338 g_value_set_enum (value, palette->priv->hscroll_policy);
341 case PROP_VSCROLL_POLICY:
342 g_value_set_enum (value, palette->priv->vscroll_policy);
346 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
352 gtk_tool_palette_dispose (GObject *object)
354 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
357 if (palette->priv->hadjustment)
359 g_object_unref (palette->priv->hadjustment);
360 palette->priv->hadjustment = NULL;
363 if (palette->priv->vadjustment)
365 g_object_unref (palette->priv->vadjustment);
366 palette->priv->vadjustment = NULL;
369 for (i = 0; i < palette->priv->groups->len; ++i)
371 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
373 if (group->notify_collapsed)
375 g_signal_handler_disconnect (group->widget, group->notify_collapsed);
376 group->notify_collapsed = 0;
380 if (palette->priv->text_size_group)
382 g_object_unref (palette->priv->text_size_group);
383 palette->priv->text_size_group = NULL;
386 if (palette->priv->settings_connection > 0)
388 g_signal_handler_disconnect (palette->priv->settings, palette->priv->settings_connection);
389 palette->priv->settings_connection = 0;
392 g_clear_object (&palette->priv->settings);
394 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
398 gtk_tool_palette_finalize (GObject *object)
400 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
402 g_ptr_array_free (palette->priv->groups, TRUE);
404 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
408 gtk_tool_palette_size_request (GtkWidget *widget,
409 GtkRequisition *requisition)
411 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
412 GtkRequisition child_requisition;
416 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
418 requisition->width = 0;
419 requisition->height = 0;
421 for (i = 0; i < palette->priv->groups->len; ++i)
423 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
428 gtk_widget_get_preferred_size (GTK_WIDGET (group->widget),
429 &child_requisition, NULL);
431 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
433 requisition->width = MAX (requisition->width, child_requisition.width);
434 requisition->height += child_requisition.height;
438 requisition->width += child_requisition.width;
439 requisition->height = MAX (requisition->height, child_requisition.height);
443 requisition->width += border_width * 2;
444 requisition->height += border_width * 2;
448 gtk_tool_palette_get_preferred_width (GtkWidget *widget,
452 GtkRequisition requisition;
454 gtk_tool_palette_size_request (widget, &requisition);
456 *minimum = *natural = requisition.width;
460 gtk_tool_palette_get_preferred_height (GtkWidget *widget,
464 GtkRequisition requisition;
466 gtk_tool_palette_size_request (widget, &requisition);
468 *minimum = *natural = requisition.height;
473 gtk_tool_palette_size_allocate (GtkWidget *widget,
474 GtkAllocation *allocation)
476 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
477 GtkAdjustment *adjustment = NULL;
478 GtkAllocation child_allocation;
480 gint n_expand_groups = 0;
481 gint remaining_space = 0;
482 gint expand_space = 0;
484 gint total_size, page_size;
489 gint min_offset = -1, max_offset = -1;
493 gint *group_sizes = g_newa (gint, palette->priv->groups->len);
494 GtkTextDirection direction;
496 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
497 direction = gtk_widget_get_direction (widget);
499 GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
501 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
503 adjustment = palette->priv->vadjustment;
504 page_size = allocation->height;
508 adjustment = palette->priv->hadjustment;
509 page_size = allocation->width;
513 offset = gtk_adjustment_get_value (adjustment);
514 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
515 GTK_TEXT_DIR_RTL == direction)
518 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
519 child_allocation.width = allocation->width - border_width * 2;
521 child_allocation.height = allocation->height - border_width * 2;
523 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
524 remaining_space = allocation->height;
526 remaining_space = allocation->width;
528 /* figure out the required size of all groups to be able to distribute the
529 * remaining space on allocation
531 for (i = 0; i < palette->priv->groups->len; ++i)
533 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
541 widget = GTK_WIDGET (group->widget);
543 if (gtk_tool_item_group_get_n_items (group->widget))
545 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
546 size = _gtk_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
548 size = _gtk_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
550 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
551 n_expand_groups += 1;
556 remaining_space -= size;
557 group_sizes[i] = size;
559 /* if the widget is currently expanding an offset which allows to
560 * display as much of the widget as possible is calculated
562 if (widget == palette->priv->expanding_child)
565 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
566 child_allocation.width : child_allocation.height;
573 for (j = 0; j < i; ++j)
574 min_offset += group_sizes[j];
576 max_offset = min_offset + group_sizes[i];
578 real_size = _gtk_tool_item_group_get_size_for_limit
579 (GTK_TOOL_ITEM_GROUP (widget), limit,
580 GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
583 if (size == real_size)
584 palette->priv->expanding_child = NULL;
588 if (n_expand_groups > 0)
590 remaining_space = MAX (0, remaining_space);
591 expand_space = remaining_space / n_expand_groups;
594 if (max_offset != -1)
597 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
598 allocation->height : allocation->width;
600 offset = MIN (MAX (offset, max_offset - limit), min_offset);
603 if (remaining_space > 0)
607 child_allocation.y = border_width;
609 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
610 child_allocation.y -= offset;
614 /* allocate all groups at the calculated positions */
615 for (i = 0; i < palette->priv->groups->len; ++i)
617 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
623 widget = GTK_WIDGET (group->widget);
625 if (gtk_tool_item_group_get_n_items (group->widget))
627 gint size = group_sizes[i];
629 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
631 size += MIN (expand_space, remaining_space);
632 remaining_space -= expand_space;
635 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
636 child_allocation.height = size;
638 child_allocation.width = size;
640 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
641 GTK_TEXT_DIR_RTL == direction)
642 child_allocation.x = allocation->width - x - child_allocation.width;
644 child_allocation.x = x;
646 gtk_widget_size_allocate (widget, &child_allocation);
647 gtk_widget_show (widget);
649 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
650 child_allocation.y += child_allocation.height;
652 x += child_allocation.width;
655 gtk_widget_hide (widget);
658 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
660 child_allocation.y += border_width;
661 child_allocation.y += offset;
663 total_size = child_allocation.y;
673 /* update the scrollbar to match the displayed adjustment */
676 gdouble lower, upper;
678 total_size = MAX (0, total_size);
679 page_size = MIN (total_size, page_size);
681 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
682 GTK_TEXT_DIR_LTR == direction)
689 lower = page_size - total_size;
695 gtk_adjustment_configure (adjustment,
706 gtk_tool_palette_realize (GtkWidget *widget)
708 GtkAllocation allocation;
710 GdkWindowAttr attributes;
711 gint attributes_mask;
714 gtk_widget_set_realized (widget, TRUE);
716 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
718 gtk_widget_get_allocation (widget, &allocation);
720 attributes.window_type = GDK_WINDOW_CHILD;
721 attributes.x = allocation.x + border_width;
722 attributes.y = allocation.y + border_width;
723 attributes.width = allocation.width - border_width * 2;
724 attributes.height = allocation.height - border_width * 2;
725 attributes.wclass = GDK_INPUT_OUTPUT;
726 attributes.visual = gtk_widget_get_visual (widget);
727 attributes.event_mask = gtk_widget_get_events (widget)
728 | GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
729 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
730 | GDK_BUTTON_MOTION_MASK;
731 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
733 window = gdk_window_new (gtk_widget_get_parent_window (widget),
734 &attributes, attributes_mask);
735 gtk_widget_set_window (widget, window);
736 gdk_window_set_user_data (window, widget);
738 gtk_style_context_set_background (gtk_widget_get_style_context (widget),
741 gtk_container_forall (GTK_CONTAINER (widget),
742 (GtkCallback) gtk_widget_set_parent_window,
745 gtk_widget_queue_resize_no_redraw (widget);
749 gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
752 GtkAllocation allocation;
753 GtkWidget *widget = GTK_WIDGET (data);
755 gtk_widget_get_allocation (widget, &allocation);
756 gtk_tool_palette_size_allocate (widget, &allocation);
760 gtk_tool_palette_add (GtkContainer *container,
763 GtkToolPalette *palette;
764 GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
766 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
767 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
769 palette = GTK_TOOL_PALETTE (container);
771 g_ptr_array_add (palette->priv->groups, info);
772 info->pos = palette->priv->groups->len - 1;
773 info->widget = g_object_ref_sink (child);
775 gtk_widget_set_parent (child, GTK_WIDGET (palette));
779 gtk_tool_palette_remove (GtkContainer *container,
782 GtkToolPalette *palette;
785 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
786 palette = GTK_TOOL_PALETTE (container);
788 for (i = 0; i < palette->priv->groups->len; ++i)
790 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
791 if (GTK_WIDGET(info->widget) == child)
793 g_object_unref (child);
794 gtk_widget_unparent (child);
796 g_ptr_array_remove_index (palette->priv->groups, i);
802 gtk_tool_palette_forall (GtkContainer *container,
804 GtkCallback callback,
805 gpointer callback_data)
807 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
810 for (i = 0; i < palette->priv->groups->len; ++i)
812 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
814 len = palette->priv->groups->len;
817 callback (GTK_WIDGET (info->widget),
820 /* At destroy time, 'callback' results in removing a widget,
821 * here we just reset the current index to account for the removed widget. */
822 i -= (len - palette->priv->groups->len);
827 gtk_tool_palette_child_type (GtkContainer *container)
829 return GTK_TYPE_TOOL_ITEM_GROUP;
833 gtk_tool_palette_set_child_property (GtkContainer *container,
839 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
843 case CHILD_PROP_EXCLUSIVE:
844 gtk_tool_palette_set_exclusive (palette, GTK_TOOL_ITEM_GROUP (child),
845 g_value_get_boolean (value));
848 case CHILD_PROP_EXPAND:
849 gtk_tool_palette_set_expand (palette, GTK_TOOL_ITEM_GROUP (child),
850 g_value_get_boolean (value));
854 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
860 gtk_tool_palette_get_child_property (GtkContainer *container,
866 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
870 case CHILD_PROP_EXCLUSIVE:
871 g_value_set_boolean (value,
872 gtk_tool_palette_get_exclusive (palette, GTK_TOOL_ITEM_GROUP (child)));
875 case CHILD_PROP_EXPAND:
876 g_value_set_boolean (value,
877 gtk_tool_palette_get_expand (palette, GTK_TOOL_ITEM_GROUP (child)));
881 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
887 style_change_notify (GtkToolPalette *palette)
889 GtkToolPalettePrivate* priv = palette->priv;
891 if (!priv->style_set)
893 /* pretend it was set, then unset, thus reverting to new default */
894 priv->style_set = TRUE;
895 gtk_tool_palette_unset_style (palette);
900 icon_size_change_notify (GtkToolPalette *palette)
902 GtkToolPalettePrivate* priv = palette->priv;
904 if (!priv->icon_size_set)
906 /* pretend it was set, then unset, thus reverting to new default */
907 priv->icon_size_set = TRUE;
908 gtk_tool_palette_unset_icon_size (palette);
913 gtk_tool_palette_settings_change_notify (GtkSettings *settings,
914 const GParamSpec *pspec,
915 GtkToolPalette *palette)
917 if (strcmp (pspec->name, "gtk-toolbar-style") == 0)
918 style_change_notify (palette);
919 else if (strcmp (pspec->name, "gtk-toolbar-icon-size") == 0)
920 icon_size_change_notify (palette);
924 gtk_tool_palette_screen_changed (GtkWidget *widget,
925 GdkScreen *previous_screen)
927 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
928 GtkToolPalettePrivate* priv = palette->priv;
929 GtkSettings *old_settings = priv->settings;
930 GtkSettings *settings;
932 if (gtk_widget_has_screen (GTK_WIDGET (palette)))
933 settings = gtk_widget_get_settings (GTK_WIDGET (palette));
937 if (settings == old_settings)
942 g_signal_handler_disconnect (old_settings, priv->settings_connection);
943 priv->settings_connection = 0;
944 g_object_unref (old_settings);
949 priv->settings_connection =
950 g_signal_connect (settings, "notify",
951 G_CALLBACK (gtk_tool_palette_settings_change_notify),
953 priv->settings = g_object_ref (settings);
956 priv->settings = NULL;
958 gtk_tool_palette_reconfigured (palette);
963 gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
965 GObjectClass *oclass = G_OBJECT_CLASS (cls);
966 GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
967 GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
969 oclass->set_property = gtk_tool_palette_set_property;
970 oclass->get_property = gtk_tool_palette_get_property;
971 oclass->dispose = gtk_tool_palette_dispose;
972 oclass->finalize = gtk_tool_palette_finalize;
974 wclass->get_preferred_width = gtk_tool_palette_get_preferred_width;
975 wclass->get_preferred_height= gtk_tool_palette_get_preferred_height;
976 wclass->size_allocate = gtk_tool_palette_size_allocate;
977 wclass->realize = gtk_tool_palette_realize;
979 cclass->add = gtk_tool_palette_add;
980 cclass->remove = gtk_tool_palette_remove;
981 cclass->forall = gtk_tool_palette_forall;
982 cclass->child_type = gtk_tool_palette_child_type;
983 cclass->set_child_property = gtk_tool_palette_set_child_property;
984 cclass->get_child_property = gtk_tool_palette_get_child_property;
986 /* Handle screen-changed so we can update our GtkSettings.
988 wclass->screen_changed = gtk_tool_palette_screen_changed;
990 g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
992 g_object_class_override_property (oclass, PROP_HADJUSTMENT, "hadjustment");
993 g_object_class_override_property (oclass, PROP_VADJUSTMENT, "vadjustment");
994 g_object_class_override_property (oclass, PROP_HSCROLL_POLICY, "hscroll-policy");
995 g_object_class_override_property (oclass, PROP_VSCROLL_POLICY, "vscroll-policy");
998 * GtkToolPalette:icon-size:
1000 * The size of the icons in a tool palette is normally determined by
1001 * the #GtkSettings:gtk-toolbar-icon-size setting. When this property is set,
1002 * it overrides the setting.
1004 * This should only be used for special-purpose tool palettes, normal
1005 * application tool palettes should respect the user preferences for the
1010 g_object_class_install_property (oclass,
1012 g_param_spec_enum ("icon-size",
1014 P_("Size of icons in this tool palette"),
1017 GTK_PARAM_READWRITE));
1020 * GtkToolPalette:icon-size-set:
1022 * Is %TRUE if the #GtkToolPalette:icon-size property has been set.
1026 g_object_class_install_property (oclass,
1028 g_param_spec_boolean ("icon-size-set",
1029 P_("Icon size set"),
1030 P_("Whether the icon-size property has been set"),
1032 GTK_PARAM_READWRITE));
1035 * GtkToolPalette:toolbar-style:
1037 * The style of items in the tool palette.
1041 g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
1042 g_param_spec_enum ("toolbar-style",
1043 P_("Toolbar Style"),
1044 P_("Style of items in the tool palette"),
1045 GTK_TYPE_TOOLBAR_STYLE,
1046 DEFAULT_TOOLBAR_STYLE,
1047 GTK_PARAM_READWRITE));
1051 * GtkToolPalette:exclusive:
1053 * Whether the item group should be the only one that is expanded
1058 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
1059 g_param_spec_boolean ("exclusive",
1061 P_("Whether the item group should be the only expanded at a given time"),
1062 DEFAULT_CHILD_EXCLUSIVE,
1063 GTK_PARAM_READWRITE));
1066 * GtkToolPalette:expand:
1068 * Whether the item group should receive extra space when the palette grows.
1073 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1074 g_param_spec_boolean ("expand",
1076 P_("Whether the item group should receive extra space when the palette grows"),
1077 DEFAULT_CHILD_EXPAND,
1078 GTK_PARAM_READWRITE));
1080 g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
1082 dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
1083 dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
1087 * gtk_tool_palette_new:
1089 * Creates a new tool palette.
1091 * Returns: a new #GtkToolPalette
1096 gtk_tool_palette_new (void)
1098 return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
1102 * gtk_tool_palette_set_icon_size:
1103 * @palette: a #GtkToolPalette
1104 * @icon_size: (type int): the #GtkIconSize that icons in the tool
1105 * palette shall have
1107 * Sets the size of icons in the tool palette.
1112 gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
1113 GtkIconSize icon_size)
1115 GtkToolPalettePrivate *priv;
1117 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1118 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
1120 priv = palette->priv;
1122 if (!priv->icon_size_set)
1124 priv->icon_size_set = TRUE;
1125 g_object_notify (G_OBJECT (palette), "icon-size-set");
1128 if (priv->icon_size == icon_size)
1131 priv->icon_size = icon_size;
1132 g_object_notify (G_OBJECT (palette), "icon-size");
1134 gtk_tool_palette_reconfigured (palette);
1136 gtk_widget_queue_resize (GTK_WIDGET (palette));
1139 static GtkSettings *
1140 toolpalette_get_settings (GtkToolPalette *palette)
1142 GtkToolPalettePrivate *priv = palette->priv;
1143 return priv->settings;
1147 * gtk_tool_palette_unset_icon_size:
1148 * @palette: a #GtkToolPalette
1150 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(),
1151 * so that user preferences will be used to determine the icon size.
1156 gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
1158 GtkToolPalettePrivate* priv = palette->priv;
1161 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1163 if (palette->priv->icon_size_set)
1165 GtkSettings *settings = toolpalette_get_settings (palette);
1169 g_object_get (settings,
1170 "gtk-toolbar-icon-size", &size,
1174 size = DEFAULT_ICON_SIZE;
1176 if (size != palette->priv->icon_size)
1178 gtk_tool_palette_set_icon_size (palette, size);
1179 g_object_notify (G_OBJECT (palette), "icon-size");
1182 priv->icon_size_set = FALSE;
1183 g_object_notify (G_OBJECT (palette), "icon-size-set");
1187 /* Set the "toolbar-style" property and do appropriate things.
1188 * GtkToolbar does this by emitting a signal instead of just
1189 * calling a function...
1192 gtk_tool_palette_change_style (GtkToolPalette *palette,
1193 GtkToolbarStyle style)
1195 GtkToolPalettePrivate* priv = palette->priv;
1197 if (priv->style != style)
1199 priv->style = style;
1201 gtk_tool_palette_reconfigured (palette);
1203 gtk_widget_queue_resize (GTK_WIDGET (palette));
1204 g_object_notify (G_OBJECT (palette), "toolbar-style");
1210 * gtk_tool_palette_set_style:
1211 * @palette: a #GtkToolPalette
1212 * @style: the #GtkToolbarStyle that items in the tool palette shall have
1214 * Sets the style (text, icons or both) of items in the tool palette.
1219 gtk_tool_palette_set_style (GtkToolPalette *palette,
1220 GtkToolbarStyle style)
1222 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1224 palette->priv->style_set = TRUE;
1225 gtk_tool_palette_change_style (palette, style);
1230 * gtk_tool_palette_unset_style:
1231 * @palette: a #GtkToolPalette
1233 * Unsets a toolbar style set with gtk_tool_palette_set_style(),
1234 * so that user preferences will be used to determine the toolbar style.
1239 gtk_tool_palette_unset_style (GtkToolPalette *palette)
1241 GtkToolPalettePrivate* priv = palette->priv;
1242 GtkToolbarStyle style;
1244 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1246 if (priv->style_set)
1248 GtkSettings *settings = toolpalette_get_settings (palette);
1251 g_object_get (settings,
1252 "gtk-toolbar-style", &style,
1255 style = DEFAULT_TOOLBAR_STYLE;
1257 if (style != priv->style)
1258 gtk_tool_palette_change_style (palette, style);
1260 priv->style_set = FALSE;
1265 * gtk_tool_palette_get_icon_size:
1266 * @palette: a #GtkToolPalette
1268 * Gets the size of icons in the tool palette.
1269 * See gtk_tool_palette_set_icon_size().
1271 * Returns: (type int): the #GtkIconSize of icons in the tool palette
1276 gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
1278 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
1280 return palette->priv->icon_size;
1284 * gtk_tool_palette_get_style:
1285 * @palette: a #GtkToolPalette
1287 * Gets the style (icons, text or both) of items in the tool palette.
1289 * Returns: the #GtkToolbarStyle of items in the tool palette.
1294 gtk_tool_palette_get_style (GtkToolPalette *palette)
1296 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
1298 return palette->priv->style;
1302 gtk_tool_palette_compare_groups (gconstpointer a,
1305 const GtkToolItemGroupInfo *group_a = a;
1306 const GtkToolItemGroupInfo *group_b = b;
1308 return group_a->pos - group_b->pos;
1312 * gtk_tool_palette_set_group_position:
1313 * @palette: a #GtkToolPalette
1314 * @group: a #GtkToolItemGroup which is a child of palette
1315 * @position: a new index for group
1317 * Sets the position of the group as an index of the tool palette.
1318 * If position is 0 the group will become the first child, if position is
1319 * -1 it will become the last child.
1324 gtk_tool_palette_set_group_position (GtkToolPalette *palette,
1325 GtkToolItemGroup *group,
1328 GtkToolItemGroupInfo *group_new;
1329 GtkToolItemGroupInfo *group_old;
1332 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1333 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1334 g_return_if_fail (position >= -1);
1337 position = palette->priv->groups->len - 1;
1339 g_return_if_fail ((guint) position < palette->priv->groups->len);
1341 group_new = g_ptr_array_index (palette->priv->groups, position);
1343 if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
1346 old_position = gtk_tool_palette_get_group_position (palette, group);
1347 g_return_if_fail (old_position >= 0);
1349 group_old = g_ptr_array_index (palette->priv->groups, old_position);
1351 group_new->pos = position;
1352 group_old->pos = old_position;
1354 g_ptr_array_sort (palette->priv->groups, gtk_tool_palette_compare_groups);
1356 gtk_widget_queue_resize (GTK_WIDGET (palette));
1360 gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
1364 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1367 if (gtk_tool_item_group_get_collapsed (group))
1370 for (i = 0; i < palette->priv->groups->len; ++i)
1372 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1373 GtkToolItemGroup *current_group = info->widget;
1375 if (current_group && current_group != group)
1376 gtk_tool_item_group_set_collapsed (current_group, TRUE);
1381 * gtk_tool_palette_set_exclusive:
1382 * @palette: a #GtkToolPalette
1383 * @group: a #GtkToolItemGroup which is a child of palette
1384 * @exclusive: whether the group should be exclusive or not
1386 * Sets whether the group should be exclusive or not.
1387 * If an exclusive group is expanded all other groups are collapsed.
1392 gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
1393 GtkToolItemGroup *group,
1396 GtkToolItemGroupInfo *group_info;
1399 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1400 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1402 position = gtk_tool_palette_get_group_position (palette, group);
1403 g_return_if_fail (position >= 0);
1405 group_info = g_ptr_array_index (palette->priv->groups, position);
1407 if (exclusive == group_info->exclusive)
1410 group_info->exclusive = exclusive;
1412 if (group_info->exclusive != (0 != group_info->notify_collapsed))
1414 if (group_info->exclusive)
1416 group_info->notify_collapsed =
1417 g_signal_connect (group, "notify::collapsed",
1418 G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
1423 g_signal_handler_disconnect (group, group_info->notify_collapsed);
1424 group_info->notify_collapsed = 0;
1428 gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
1429 gtk_widget_child_notify (GTK_WIDGET (group), "exclusive");
1433 * gtk_tool_palette_set_expand:
1434 * @palette: a #GtkToolPalette
1435 * @group: a #GtkToolItemGroup which is a child of palette
1436 * @expand: whether the group should be given extra space
1438 * Sets whether the group should be given extra space.
1443 gtk_tool_palette_set_expand (GtkToolPalette *palette,
1444 GtkToolItemGroup *group,
1447 GtkToolItemGroupInfo *group_info;
1450 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1451 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1453 position = gtk_tool_palette_get_group_position (palette, group);
1454 g_return_if_fail (position >= 0);
1456 group_info = g_ptr_array_index (palette->priv->groups, position);
1458 if (expand != group_info->expand)
1460 group_info->expand = expand;
1461 gtk_widget_queue_resize (GTK_WIDGET (palette));
1462 gtk_widget_child_notify (GTK_WIDGET (group), "expand");
1467 * gtk_tool_palette_get_group_position:
1468 * @palette: a #GtkToolPalette
1469 * @group: a #GtkToolItemGroup
1471 * Gets the position of @group in @palette as index.
1472 * See gtk_tool_palette_set_group_position().
1474 * Returns: the index of group or -1 if @group is not a child of @palette
1479 gtk_tool_palette_get_group_position (GtkToolPalette *palette,
1480 GtkToolItemGroup *group)
1484 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
1485 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
1487 for (i = 0; i < palette->priv->groups->len; ++i)
1489 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1490 if ((gpointer) group == info->widget)
1498 * gtk_tool_palette_get_exclusive:
1499 * @palette: a #GtkToolPalette
1500 * @group: a #GtkToolItemGroup which is a child of palette
1502 * Gets whether @group is exclusive or not.
1503 * See gtk_tool_palette_set_exclusive().
1505 * Returns: %TRUE if @group is exclusive
1510 gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
1511 GtkToolItemGroup *group)
1514 GtkToolItemGroupInfo *info;
1516 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
1517 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
1519 position = gtk_tool_palette_get_group_position (palette, group);
1520 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
1522 info = g_ptr_array_index (palette->priv->groups, position);
1524 return info->exclusive;
1528 * gtk_tool_palette_get_expand:
1529 * @palette: a #GtkToolPalette
1530 * @group: a #GtkToolItemGroup which is a child of palette
1532 * Gets whether group should be given extra space.
1533 * See gtk_tool_palette_set_expand().
1535 * Returns: %TRUE if group should be given extra space, %FALSE otherwise
1540 gtk_tool_palette_get_expand (GtkToolPalette *palette,
1541 GtkToolItemGroup *group)
1544 GtkToolItemGroupInfo *info;
1546 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
1547 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
1549 position = gtk_tool_palette_get_group_position (palette, group);
1550 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
1552 info = g_ptr_array_index (palette->priv->groups, position);
1554 return info->expand;
1558 * gtk_tool_palette_get_drop_item:
1559 * @palette: a #GtkToolPalette
1560 * @x: the x position
1561 * @y: the y position
1563 * Gets the item at position (x, y).
1564 * See gtk_tool_palette_get_drop_group().
1566 * Returns: (transfer none): the #GtkToolItem at position or %NULL if there is no such item
1571 gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
1575 GtkAllocation allocation;
1576 GtkToolItemGroup *group = gtk_tool_palette_get_drop_group (palette, x, y);
1577 GtkWidget *widget = GTK_WIDGET (group);
1581 gtk_widget_get_allocation (widget, &allocation);
1582 return gtk_tool_item_group_get_drop_item (group,
1591 * gtk_tool_palette_get_drop_group:
1592 * @palette: a #GtkToolPalette
1593 * @x: the x position
1594 * @y: the y position
1596 * Gets the group at position (x, y).
1598 * Returns: (transfer none): the #GtkToolItemGroup at position or %NULL
1599 * if there is no such group
1604 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
1608 GtkAllocation allocation;
1611 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1613 gtk_widget_get_allocation (GTK_WIDGET (palette), &allocation);
1615 g_return_val_if_fail (x >= 0 && x < allocation.width, NULL);
1616 g_return_val_if_fail (y >= 0 && y < allocation.height, NULL);
1618 for (i = 0; i < palette->priv->groups->len; ++i)
1620 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1627 widget = GTK_WIDGET (group->widget);
1628 gtk_widget_get_allocation (widget, &allocation);
1630 x0 = x - allocation.x;
1631 y0 = y - allocation.y;
1633 if (x0 >= 0 && x0 < allocation.width &&
1634 y0 >= 0 && y0 < allocation.height)
1635 return GTK_TOOL_ITEM_GROUP (widget);
1642 * gtk_tool_palette_get_drag_item:
1643 * @palette: a #GtkToolPalette
1644 * @selection: a #GtkSelectionData
1646 * Get the dragged item from the selection.
1647 * This could be a #GtkToolItem or a #GtkToolItemGroup.
1649 * Returns: (transfer none): the dragged item in selection
1654 gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
1655 const GtkSelectionData *selection)
1657 GtkToolPaletteDragData *data;
1660 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1661 g_return_val_if_fail (NULL != selection, NULL);
1663 g_return_val_if_fail (gtk_selection_data_get_format (selection) == 8, NULL);
1664 g_return_val_if_fail (gtk_selection_data_get_length (selection) == sizeof (GtkToolPaletteDragData), NULL);
1665 target = gtk_selection_data_get_target (selection);
1666 g_return_val_if_fail (target == dnd_target_atom_item ||
1667 target == dnd_target_atom_group,
1670 data = (GtkToolPaletteDragData*) gtk_selection_data_get_data (selection);
1672 g_return_val_if_fail (data->palette == palette, NULL);
1674 if (dnd_target_atom_item == target)
1675 g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
1676 else if (dnd_target_atom_group == target)
1677 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
1683 * gtk_tool_palette_set_drag_source:
1684 * @palette: a #GtkToolPalette
1685 * @targets: the #GtkToolPaletteDragTargets
1686 * which the widget should support
1688 * Sets the tool palette as a drag source.
1689 * Enables all groups and items in the tool palette as drag sources
1690 * on button 1 and button 3 press with copy and move actions.
1691 * See gtk_drag_source_set().
1696 gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
1697 GtkToolPaletteDragTargets targets)
1701 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1703 if ((palette->priv->drag_source & targets) == targets)
1706 palette->priv->drag_source |= targets;
1708 for (i = 0; i < palette->priv->groups->len; ++i)
1710 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1712 gtk_container_forall (GTK_CONTAINER (info->widget),
1713 _gtk_tool_palette_child_set_drag_source,
1719 * gtk_tool_palette_add_drag_dest:
1720 * @palette: a #GtkToolPalette
1721 * @widget: a #GtkWidget which should be a drag destination for @palette
1722 * @flags: the flags that specify what actions GTK+ should take for drops
1724 * @targets: the #GtkToolPaletteDragTargets which the widget
1726 * @actions: the #GdkDragAction<!-- -->s which the widget should suppport
1728 * Sets @palette as drag source (see gtk_tool_palette_set_drag_source())
1729 * and sets @widget as a drag destination for drags from @palette.
1730 * See gtk_drag_dest_set().
1735 gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
1737 GtkDestDefaults flags,
1738 GtkToolPaletteDragTargets targets,
1739 GdkDragAction actions)
1741 GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
1744 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1745 g_return_if_fail (GTK_IS_WIDGET (widget));
1747 gtk_tool_palette_set_drag_source (palette,
1750 if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
1751 entries[n_entries++] = dnd_targets[0];
1752 if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
1753 entries[n_entries++] = dnd_targets[1];
1755 gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
1759 _gtk_tool_palette_get_item_size (GtkToolPalette *palette,
1760 GtkRequisition *item_size,
1761 gboolean homogeneous_only,
1762 gint *requested_rows)
1764 GtkRequisition max_requisition;
1768 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1769 g_return_if_fail (NULL != item_size);
1771 max_requisition.width = 0;
1772 max_requisition.height = 0;
1775 /* iterate over all groups and calculate the max item_size and max row request */
1776 for (i = 0; i < palette->priv->groups->len; ++i)
1778 GtkRequisition requisition;
1780 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1785 _gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
1787 max_requisition.width = MAX (max_requisition.width, requisition.width);
1788 max_requisition.height = MAX (max_requisition.height, requisition.height);
1789 max_rows = MAX (max_rows, rows);
1792 *item_size = max_requisition;
1794 *requested_rows = max_rows;
1798 gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
1799 GdkDragContext *context,
1800 GtkSelectionData *selection,
1805 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1808 target = gtk_selection_data_get_target (selection);
1810 if (target == dnd_target_atom_item)
1811 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
1814 gtk_selection_data_set (selection, target, 8,
1815 (guchar*) &drag_data, sizeof (drag_data));
1819 gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
1820 GdkDragContext *context,
1821 GtkSelectionData *selection,
1826 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1829 target = gtk_selection_data_get_target (selection);
1831 if (target == dnd_target_atom_group)
1832 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
1835 gtk_selection_data_set (selection, target, 8,
1836 (guchar*) &drag_data, sizeof (drag_data));
1840 _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
1843 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1845 /* Check drag_source,
1846 * to work properly when called from gtk_tool_item_group_insert().
1848 if (!palette->priv->drag_source)
1851 if (GTK_IS_TOOL_ITEM (child) &&
1852 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
1854 /* Connect to child instead of the item itself,
1855 * to work arround bug 510377.
1857 if (GTK_IS_TOOL_BUTTON (child))
1858 child = gtk_bin_get_child (GTK_BIN (child));
1863 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1864 &dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1866 g_signal_connect (child, "drag-data-get",
1867 G_CALLBACK (gtk_tool_palette_item_drag_data_get),
1870 else if (GTK_IS_BUTTON (child) &&
1871 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
1873 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1874 &dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1876 g_signal_connect (child, "drag-data-get",
1877 G_CALLBACK (gtk_tool_palette_child_drag_data_get),
1883 * gtk_tool_palette_get_drag_target_item:
1885 * Gets the target entry for a dragged #GtkToolItem.
1887 * Returns: (transfer none): the #GtkTargetEntry for a dragged item.
1891 const GtkTargetEntry*
1892 gtk_tool_palette_get_drag_target_item (void)
1894 return &dnd_targets[0];
1898 * gtk_tool_palette_get_drag_target_group:
1900 * Get the target entry for a dragged #GtkToolItemGroup.
1902 * Returns: (transfer none): the #GtkTargetEntry for a dragged group
1906 const GtkTargetEntry*
1907 gtk_tool_palette_get_drag_target_group (void)
1909 return &dnd_targets[1];
1913 _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
1916 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1917 palette->priv->expanding_child = widget;
1921 * gtk_tool_palette_get_hadjustment:
1922 * @palette: a #GtkToolPalette
1924 * Gets the horizontal adjustment of the tool palette.
1926 * Returns: (transfer none): the horizontal adjustment of @palette
1930 * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
1933 gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
1935 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1937 return palette->priv->hadjustment;
1941 gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
1942 GtkAdjustment *adjustment)
1944 GtkToolPalettePrivate *priv = palette->priv;
1946 if (adjustment && priv->hadjustment == adjustment)
1949 if (priv->hadjustment != NULL)
1951 g_signal_handlers_disconnect_by_func (priv->hadjustment,
1952 gtk_tool_palette_adjustment_value_changed,
1954 g_object_unref (priv->hadjustment);
1957 if (adjustment == NULL)
1958 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
1961 g_signal_connect (adjustment, "value-changed",
1962 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
1964 priv->hadjustment = g_object_ref_sink (adjustment);
1965 /* FIXME: Adjustment should probably have its values updated now */
1966 g_object_notify (G_OBJECT (palette), "hadjustment");
1970 * gtk_tool_palette_get_vadjustment:
1971 * @palette: a #GtkToolPalette
1973 * Gets the vertical adjustment of the tool palette.
1975 * Returns: (transfer none): the vertical adjustment of @palette
1979 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
1982 gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
1984 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1986 return palette->priv->vadjustment;
1990 gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
1991 GtkAdjustment *adjustment)
1993 GtkToolPalettePrivate *priv = palette->priv;
1995 if (adjustment && priv->vadjustment == adjustment)
1998 if (priv->vadjustment != NULL)
2000 g_signal_handlers_disconnect_by_func (priv->vadjustment,
2001 gtk_tool_palette_adjustment_value_changed,
2003 g_object_unref (priv->vadjustment);
2006 if (adjustment == NULL)
2007 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2010 g_signal_connect (adjustment, "value-changed",
2011 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
2013 priv->vadjustment = g_object_ref_sink (adjustment);
2014 /* FIXME: Adjustment should probably have its values updated now */
2015 g_object_notify (G_OBJECT (palette), "vadjustment");
2019 _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
2021 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
2023 return palette->priv->text_size_group;