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
27 #include "gtktoolpaletteprivate.h"
28 #include "gtkmarshalers.h"
29 #include "gtktypebuiltins.h"
30 #include "gtkprivate.h"
31 #include "gtkscrollable.h"
32 #include "gtkorientableprivate.h"
35 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
36 #define DEFAULT_ORIENTATION GTK_ORIENTATION_VERTICAL
37 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_ICONS
39 #define DEFAULT_CHILD_EXCLUSIVE FALSE
40 #define DEFAULT_CHILD_EXPAND FALSE
43 * SECTION:gtktoolpalette
44 * @Short_description: A tool palette with categories
45 * @Title: GtkToolPalette
47 * A #GtkToolPalette allows you to add #GtkToolItem<!-- -->s to a palette-like
48 * container with different categories and drag and drop support.
50 * A #GtkToolPalette is created with a call to gtk_tool_palette_new().
52 * #GtkToolItem<!-- -->s cannot be added directly to a #GtkToolPalette -
53 * instead they are added to a #GtkToolItemGroup which can than be added
54 * to a #GtkToolPalette. To add a #GtkToolItemGroup to a #GtkToolPalette,
55 * use gtk_container_add().
58 * GtkWidget *palette, *group;
61 * palette = gtk_tool_palette_new ();
62 * group = gtk_tool_item_group_new (_("Test Category"));
63 * gtk_container_add (GTK_CONTAINER (palette), group);
65 * item = gtk_tool_button_new_from_stock (GTK_STOCK_OK);
66 * gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
69 * The easiest way to use drag and drop with #GtkToolPalette is to call
70 * gtk_tool_palette_add_drag_dest() with the desired drag source @palette
71 * and the desired drag target @widget. Then gtk_tool_palette_get_drag_item()
72 * can be used to get the dragged item in the #GtkWidget::drag-data-received
73 * signal handler of the drag target.
77 * passive_canvas_drag_data_received (GtkWidget *widget,
78 * GdkDragContext *context,
81 * GtkSelectionData *selection,
89 * /<!-- -->* Get the dragged item *<!-- -->/
90 * palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context),
91 * GTK_TYPE_TOOL_PALETTE);
92 * if (palette != NULL)
93 * item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
96 * /<!-- -->* Do something with item *<!-- -->/
99 * GtkWidget *target, palette;
101 * palette = gtk_tool_palette_new ();
102 * target = gtk_drawing_area_new ();
104 * g_signal_connect (G_OBJECT (target), "drag-data-received",
105 * G_CALLBACK (passive_canvas_drag_data_received), NULL);
106 * gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target,
107 * GTK_DEST_DEFAULT_ALL,
108 * GTK_TOOL_PALETTE_DRAG_ITEMS,
115 typedef struct _GtkToolItemGroupInfo GtkToolItemGroupInfo;
116 typedef struct _GtkToolPaletteDragData GtkToolPaletteDragData;
134 CHILD_PROP_EXCLUSIVE,
138 struct _GtkToolItemGroupInfo
140 GtkToolItemGroup *widget;
142 gulong notify_collapsed;
148 struct _GtkToolPalettePrivate
152 GtkAdjustment *hadjustment;
153 GtkAdjustment *vadjustment;
155 GtkIconSize icon_size;
156 gboolean icon_size_set;
157 GtkOrientation orientation;
158 GtkToolbarStyle style;
161 GtkWidget *expanding_child;
163 GtkSizeGroup *text_size_group;
165 GtkSettings *settings;
166 gulong settings_connection;
168 guint drag_source : 2;
170 /* GtkScrollablePolicy needs to be checked when
171 * driving the scrollable adjustment values */
172 guint hscroll_policy : 1;
173 guint vscroll_policy : 1;
176 struct _GtkToolPaletteDragData
178 GtkToolPalette *palette;
182 static GdkAtom dnd_target_atom_item = GDK_NONE;
183 static GdkAtom dnd_target_atom_group = GDK_NONE;
185 static const GtkTargetEntry dnd_targets[] =
187 { "application/x-gtk-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
188 { "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
191 static void gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
192 GtkAdjustment *adjustment);
193 static void gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
194 GtkAdjustment *adjustment);
197 G_DEFINE_TYPE_WITH_CODE (GtkToolPalette,
200 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
201 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
204 gtk_tool_palette_init (GtkToolPalette *palette)
206 palette->priv = G_TYPE_INSTANCE_GET_PRIVATE (palette,
207 GTK_TYPE_TOOL_PALETTE,
208 GtkToolPalettePrivate);
210 palette->priv->groups = g_ptr_array_sized_new (4);
211 g_ptr_array_set_free_func (palette->priv->groups, g_free);
213 palette->priv->icon_size = DEFAULT_ICON_SIZE;
214 palette->priv->icon_size_set = FALSE;
215 palette->priv->orientation = DEFAULT_ORIENTATION;
216 palette->priv->style = DEFAULT_TOOLBAR_STYLE;
217 palette->priv->style_set = FALSE;
219 palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
223 gtk_tool_palette_reconfigured (GtkToolPalette *palette)
227 for (i = 0; i < palette->priv->groups->len; ++i)
229 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
231 _gtk_tool_item_group_palette_reconfigured (info->widget);
234 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
238 gtk_tool_palette_set_property (GObject *object,
243 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
248 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
250 palette->priv->icon_size = g_value_get_enum (value);
251 gtk_tool_palette_reconfigured (palette);
255 case PROP_ICON_SIZE_SET:
256 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
258 palette->priv->icon_size_set = g_value_get_enum (value);
259 gtk_tool_palette_reconfigured (palette);
263 case PROP_ORIENTATION:
264 if ((guint) g_value_get_enum (value) != palette->priv->orientation)
266 palette->priv->orientation = g_value_get_enum (value);
267 _gtk_orientable_set_style_classes (GTK_ORIENTABLE (palette));
268 gtk_tool_palette_reconfigured (palette);
272 case PROP_TOOLBAR_STYLE:
273 if ((guint) g_value_get_enum (value) != palette->priv->style)
275 palette->priv->style = g_value_get_enum (value);
276 gtk_tool_palette_reconfigured (palette);
280 case PROP_HADJUSTMENT:
281 gtk_tool_palette_set_hadjustment (palette, g_value_get_object (value));
284 case PROP_VADJUSTMENT:
285 gtk_tool_palette_set_vadjustment (palette, g_value_get_object (value));
288 case PROP_HSCROLL_POLICY:
289 palette->priv->hscroll_policy = g_value_get_enum (value);
290 gtk_widget_queue_resize (GTK_WIDGET (palette));
293 case PROP_VSCROLL_POLICY:
294 palette->priv->vscroll_policy = g_value_get_enum (value);
295 gtk_widget_queue_resize (GTK_WIDGET (palette));
299 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
305 gtk_tool_palette_get_property (GObject *object,
310 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
315 g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
318 case PROP_ICON_SIZE_SET:
319 g_value_set_boolean (value, palette->priv->icon_size_set);
322 case PROP_ORIENTATION:
323 g_value_set_enum (value, palette->priv->orientation);
326 case PROP_TOOLBAR_STYLE:
327 g_value_set_enum (value, gtk_tool_palette_get_style (palette));
330 case PROP_HADJUSTMENT:
331 g_value_set_object (value, palette->priv->hadjustment);
334 case PROP_VADJUSTMENT:
335 g_value_set_object (value, palette->priv->vadjustment);
338 case PROP_HSCROLL_POLICY:
339 g_value_set_enum (value, palette->priv->hscroll_policy);
342 case PROP_VSCROLL_POLICY:
343 g_value_set_enum (value, palette->priv->vscroll_policy);
347 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
353 gtk_tool_palette_dispose (GObject *object)
355 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
358 if (palette->priv->hadjustment)
360 g_object_unref (palette->priv->hadjustment);
361 palette->priv->hadjustment = NULL;
364 if (palette->priv->vadjustment)
366 g_object_unref (palette->priv->vadjustment);
367 palette->priv->vadjustment = NULL;
370 for (i = 0; i < palette->priv->groups->len; ++i)
372 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
374 if (group->notify_collapsed)
376 g_signal_handler_disconnect (group->widget, group->notify_collapsed);
377 group->notify_collapsed = 0;
381 if (palette->priv->text_size_group)
383 g_object_unref (palette->priv->text_size_group);
384 palette->priv->text_size_group = NULL;
387 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
391 gtk_tool_palette_finalize (GObject *object)
393 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
395 g_ptr_array_free (palette->priv->groups, TRUE);
397 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
401 gtk_tool_palette_size_request (GtkWidget *widget,
402 GtkRequisition *requisition)
404 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
405 GtkRequisition child_requisition;
409 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
411 requisition->width = 0;
412 requisition->height = 0;
414 for (i = 0; i < palette->priv->groups->len; ++i)
416 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
421 gtk_widget_get_preferred_size (GTK_WIDGET (group->widget),
422 &child_requisition, NULL);
424 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
426 requisition->width = MAX (requisition->width, child_requisition.width);
427 requisition->height += child_requisition.height;
431 requisition->width += child_requisition.width;
432 requisition->height = MAX (requisition->height, child_requisition.height);
436 requisition->width += border_width * 2;
437 requisition->height += border_width * 2;
441 gtk_tool_palette_get_preferred_width (GtkWidget *widget,
445 GtkRequisition requisition;
447 gtk_tool_palette_size_request (widget, &requisition);
449 *minimum = *natural = requisition.width;
453 gtk_tool_palette_get_preferred_height (GtkWidget *widget,
457 GtkRequisition requisition;
459 gtk_tool_palette_size_request (widget, &requisition);
461 *minimum = *natural = requisition.height;
466 gtk_tool_palette_size_allocate (GtkWidget *widget,
467 GtkAllocation *allocation)
469 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
470 GtkAdjustment *adjustment = NULL;
471 GtkAllocation child_allocation;
473 gint n_expand_groups = 0;
474 gint remaining_space = 0;
475 gint expand_space = 0;
477 gint page_start, page_size = 0;
482 gint min_offset = -1, max_offset = -1;
486 gint *group_sizes = g_newa (gint, palette->priv->groups->len);
487 GtkTextDirection direction;
489 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
490 direction = gtk_widget_get_direction (widget);
492 GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
494 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
496 adjustment = palette->priv->vadjustment;
497 page_size = allocation->height;
501 adjustment = palette->priv->hadjustment;
502 page_size = allocation->width;
506 offset = gtk_adjustment_get_value (adjustment);
507 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
508 GTK_TEXT_DIR_RTL == direction)
511 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
512 child_allocation.width = allocation->width - border_width * 2;
514 child_allocation.height = allocation->height - border_width * 2;
516 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
517 remaining_space = allocation->height;
519 remaining_space = allocation->width;
521 /* figure out the required size of all groups to be able to distribute the
522 * remaining space on allocation
524 for (i = 0; i < palette->priv->groups->len; ++i)
526 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
534 widget = GTK_WIDGET (group->widget);
536 if (gtk_tool_item_group_get_n_items (group->widget))
538 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
539 size = _gtk_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
541 size = _gtk_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
543 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
544 n_expand_groups += 1;
549 remaining_space -= size;
550 group_sizes[i] = size;
552 /* if the widget is currently expanding an offset which allows to
553 * display as much of the widget as possible is calculated
555 if (widget == palette->priv->expanding_child)
558 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
559 child_allocation.width : child_allocation.height;
566 for (j = 0; j < i; ++j)
567 min_offset += group_sizes[j];
569 max_offset = min_offset + group_sizes[i];
571 real_size = _gtk_tool_item_group_get_size_for_limit
572 (GTK_TOOL_ITEM_GROUP (widget), limit,
573 GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
576 if (size == real_size)
577 palette->priv->expanding_child = NULL;
581 if (n_expand_groups > 0)
583 remaining_space = MAX (0, remaining_space);
584 expand_space = remaining_space / n_expand_groups;
587 if (max_offset != -1)
590 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
591 allocation->height : allocation->width;
593 offset = MIN (MAX (offset, max_offset - limit), min_offset);
596 if (remaining_space > 0)
600 child_allocation.y = border_width;
602 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
603 child_allocation.y -= offset;
607 /* allocate all groups at the calculated positions */
608 for (i = 0; i < palette->priv->groups->len; ++i)
610 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
616 widget = GTK_WIDGET (group->widget);
618 if (gtk_tool_item_group_get_n_items (group->widget))
620 gint size = group_sizes[i];
622 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
624 size += MIN (expand_space, remaining_space);
625 remaining_space -= expand_space;
628 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
629 child_allocation.height = size;
631 child_allocation.width = size;
633 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
634 GTK_TEXT_DIR_RTL == direction)
635 child_allocation.x = allocation->width - x - child_allocation.width;
637 child_allocation.x = x;
639 gtk_widget_size_allocate (widget, &child_allocation);
640 gtk_widget_show (widget);
642 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
643 child_allocation.y += child_allocation.height;
645 x += child_allocation.width;
648 gtk_widget_hide (widget);
651 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
653 child_allocation.y += border_width;
654 child_allocation.y += offset;
656 page_start = child_allocation.y;
666 /* update the scrollbar to match the displayed adjustment */
669 gdouble value, lower, upper;
671 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
672 GTK_TEXT_DIR_LTR == direction)
675 upper = MAX (0, page_start);
677 value = MIN (offset, upper - page_size);
678 gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
682 lower = page_size - MAX (0, page_start);
687 value = MAX (offset, lower);
688 gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
691 gtk_adjustment_configure (adjustment,
702 gtk_tool_palette_realize (GtkWidget *widget)
704 GtkAllocation allocation;
706 GdkWindowAttr attributes;
707 gint attributes_mask;
710 gtk_widget_set_realized (widget, TRUE);
712 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
714 gtk_widget_get_allocation (widget, &allocation);
716 attributes.window_type = GDK_WINDOW_CHILD;
717 attributes.x = allocation.x + border_width;
718 attributes.y = allocation.y + border_width;
719 attributes.width = allocation.width - border_width * 2;
720 attributes.height = allocation.height - border_width * 2;
721 attributes.wclass = GDK_INPUT_OUTPUT;
722 attributes.visual = gtk_widget_get_visual (widget);
723 attributes.event_mask = gtk_widget_get_events (widget)
724 | GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
725 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
726 | GDK_BUTTON_MOTION_MASK;
727 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
729 window = gdk_window_new (gtk_widget_get_parent_window (widget),
730 &attributes, attributes_mask);
731 gtk_widget_set_window (widget, window);
732 gdk_window_set_user_data (window, widget);
734 gtk_style_context_set_background (gtk_widget_get_style_context (widget),
737 gtk_container_forall (GTK_CONTAINER (widget),
738 (GtkCallback) gtk_widget_set_parent_window,
741 gtk_widget_queue_resize_no_redraw (widget);
745 gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
748 GtkAllocation allocation;
749 GtkWidget *widget = GTK_WIDGET (data);
751 gtk_widget_get_allocation (widget, &allocation);
752 gtk_tool_palette_size_allocate (widget, &allocation);
756 gtk_tool_palette_add (GtkContainer *container,
759 GtkToolPalette *palette;
760 GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
762 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
763 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
765 palette = GTK_TOOL_PALETTE (container);
767 g_ptr_array_add (palette->priv->groups, info);
768 info->pos = palette->priv->groups->len - 1;
769 info->widget = g_object_ref_sink (child);
771 gtk_widget_set_parent (child, GTK_WIDGET (palette));
775 gtk_tool_palette_remove (GtkContainer *container,
778 GtkToolPalette *palette;
781 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
782 palette = GTK_TOOL_PALETTE (container);
784 for (i = 0; i < palette->priv->groups->len; ++i)
786 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
787 if (GTK_WIDGET(info->widget) == child)
789 g_object_unref (child);
790 gtk_widget_unparent (child);
792 g_ptr_array_remove_index (palette->priv->groups, i);
798 gtk_tool_palette_forall (GtkContainer *container,
800 GtkCallback callback,
801 gpointer callback_data)
803 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
806 for (i = 0; i < palette->priv->groups->len; ++i)
808 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
810 len = palette->priv->groups->len;
813 callback (GTK_WIDGET (info->widget),
816 /* At destroy time, 'callback' results in removing a widget,
817 * here we just reset the current index to account for the removed widget. */
818 i -= (len - palette->priv->groups->len);
823 gtk_tool_palette_child_type (GtkContainer *container)
825 return GTK_TYPE_TOOL_ITEM_GROUP;
829 gtk_tool_palette_set_child_property (GtkContainer *container,
835 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
839 case CHILD_PROP_EXCLUSIVE:
840 gtk_tool_palette_set_exclusive (palette, GTK_TOOL_ITEM_GROUP (child),
841 g_value_get_boolean (value));
844 case CHILD_PROP_EXPAND:
845 gtk_tool_palette_set_expand (palette, GTK_TOOL_ITEM_GROUP (child),
846 g_value_get_boolean (value));
850 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
856 gtk_tool_palette_get_child_property (GtkContainer *container,
862 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
866 case CHILD_PROP_EXCLUSIVE:
867 g_value_set_boolean (value,
868 gtk_tool_palette_get_exclusive (palette, GTK_TOOL_ITEM_GROUP (child)));
871 case CHILD_PROP_EXPAND:
872 g_value_set_boolean (value,
873 gtk_tool_palette_get_expand (palette, GTK_TOOL_ITEM_GROUP (child)));
877 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
883 style_change_notify (GtkToolPalette *palette)
885 GtkToolPalettePrivate* priv = palette->priv;
887 if (!priv->style_set)
889 /* pretend it was set, then unset, thus reverting to new default */
890 priv->style_set = TRUE;
891 gtk_tool_palette_unset_style (palette);
896 icon_size_change_notify (GtkToolPalette *palette)
898 GtkToolPalettePrivate* priv = palette->priv;
900 if (!priv->icon_size_set)
902 /* pretend it was set, then unset, thus reverting to new default */
903 priv->icon_size_set = TRUE;
904 gtk_tool_palette_unset_icon_size (palette);
909 gtk_tool_palette_settings_change_notify (GtkSettings *settings,
910 const GParamSpec *pspec,
911 GtkToolPalette *palette)
913 if (strcmp (pspec->name, "gtk-toolbar-style") == 0)
914 style_change_notify (palette);
915 else if (strcmp (pspec->name, "gtk-toolbar-icon-size") == 0)
916 icon_size_change_notify (palette);
920 gtk_tool_palette_screen_changed (GtkWidget *widget,
921 GdkScreen *previous_screen)
923 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
924 GtkToolPalettePrivate* priv = palette->priv;
925 GtkSettings *old_settings = priv->settings;
926 GtkSettings *settings;
928 if (gtk_widget_has_screen (GTK_WIDGET (palette)))
929 settings = gtk_widget_get_settings (GTK_WIDGET (palette));
933 if (settings == old_settings)
938 g_signal_handler_disconnect (old_settings, priv->settings_connection);
939 g_object_unref (old_settings);
944 priv->settings_connection =
945 g_signal_connect (settings, "notify",
946 G_CALLBACK (gtk_tool_palette_settings_change_notify),
948 priv->settings = g_object_ref (settings);
951 priv->settings = NULL;
953 gtk_tool_palette_reconfigured (palette);
958 gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
960 GObjectClass *oclass = G_OBJECT_CLASS (cls);
961 GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
962 GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
964 oclass->set_property = gtk_tool_palette_set_property;
965 oclass->get_property = gtk_tool_palette_get_property;
966 oclass->dispose = gtk_tool_palette_dispose;
967 oclass->finalize = gtk_tool_palette_finalize;
969 wclass->get_preferred_width = gtk_tool_palette_get_preferred_width;
970 wclass->get_preferred_height= gtk_tool_palette_get_preferred_height;
971 wclass->size_allocate = gtk_tool_palette_size_allocate;
972 wclass->realize = gtk_tool_palette_realize;
974 cclass->add = gtk_tool_palette_add;
975 cclass->remove = gtk_tool_palette_remove;
976 cclass->forall = gtk_tool_palette_forall;
977 cclass->child_type = gtk_tool_palette_child_type;
978 cclass->set_child_property = gtk_tool_palette_set_child_property;
979 cclass->get_child_property = gtk_tool_palette_get_child_property;
981 /* Handle screen-changed so we can update our GtkSettings.
983 wclass->screen_changed = gtk_tool_palette_screen_changed;
985 g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
987 g_object_class_override_property (oclass, PROP_HADJUSTMENT, "hadjustment");
988 g_object_class_override_property (oclass, PROP_VADJUSTMENT, "vadjustment");
989 g_object_class_override_property (oclass, PROP_HSCROLL_POLICY, "hscroll-policy");
990 g_object_class_override_property (oclass, PROP_VSCROLL_POLICY, "vscroll-policy");
993 * GtkToolPalette:icon-size:
995 * The size of the icons in a tool palette is normally determined by
996 * the #GtkSettings:toolbar-icon-size setting. When this property is set,
997 * it overrides the setting.
999 * This should only be used for special-purpose tool palettes, normal
1000 * application tool palettes should respect the user preferences for the
1005 g_object_class_install_property (oclass,
1007 g_param_spec_enum ("icon-size",
1009 P_("Size of icons in this tool palette"),
1012 GTK_PARAM_READWRITE));
1015 * GtkToolPalette:icon-size-set:
1017 * Is %TRUE if the #GtkToolPalette:icon-size property has been set.
1021 g_object_class_install_property (oclass,
1023 g_param_spec_boolean ("icon-size-set",
1024 P_("Icon size set"),
1025 P_("Whether the icon-size property has been set"),
1027 GTK_PARAM_READWRITE));
1030 * GtkToolPalette:toolbar-style:
1032 * The style of items in the tool palette.
1036 g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
1037 g_param_spec_enum ("toolbar-style",
1038 P_("Toolbar Style"),
1039 P_("Style of items in the tool palette"),
1040 GTK_TYPE_TOOLBAR_STYLE,
1041 DEFAULT_TOOLBAR_STYLE,
1042 GTK_PARAM_READWRITE));
1046 * GtkToolPalette:exclusive:
1048 * Whether the item group should be the only one that is expanded
1053 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
1054 g_param_spec_boolean ("exclusive",
1056 P_("Whether the item group should be the only expanded at a given time"),
1057 DEFAULT_CHILD_EXCLUSIVE,
1058 GTK_PARAM_READWRITE));
1061 * GtkToolPalette:expand:
1063 * Whether the item group should receive extra space when the palette grows.
1068 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1069 g_param_spec_boolean ("expand",
1071 P_("Whether the item group should receive extra space when the palette grows"),
1072 DEFAULT_CHILD_EXPAND,
1073 GTK_PARAM_READWRITE));
1075 g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
1077 dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
1078 dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
1082 * gtk_tool_palette_new:
1084 * Creates a new tool palette.
1086 * Returns: a new #GtkToolPalette
1091 gtk_tool_palette_new (void)
1093 return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
1097 * gtk_tool_palette_set_icon_size:
1098 * @palette: a #GtkToolPalette
1099 * @icon_size: (type int): the #GtkIconSize that icons in the tool
1100 * palette shall have
1102 * Sets the size of icons in the tool palette.
1107 gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
1108 GtkIconSize icon_size)
1110 GtkToolPalettePrivate *priv;
1112 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1113 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
1115 priv = palette->priv;
1117 if (!priv->icon_size_set)
1119 priv->icon_size_set = TRUE;
1120 g_object_notify (G_OBJECT (palette), "icon-size-set");
1123 if (priv->icon_size == icon_size)
1126 priv->icon_size = icon_size;
1127 g_object_notify (G_OBJECT (palette), "icon-size");
1129 gtk_tool_palette_reconfigured (palette);
1131 gtk_widget_queue_resize (GTK_WIDGET (palette));
1134 static GtkSettings *
1135 toolpalette_get_settings (GtkToolPalette *palette)
1137 GtkToolPalettePrivate *priv = palette->priv;
1138 return priv->settings;
1142 * gtk_tool_palette_unset_icon_size:
1143 * @palette: a #GtkToolPalette
1145 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(),
1146 * so that user preferences will be used to determine the icon size.
1151 gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
1153 GtkToolPalettePrivate* priv = palette->priv;
1156 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1158 if (palette->priv->icon_size_set)
1160 GtkSettings *settings = toolpalette_get_settings (palette);
1164 g_object_get (settings,
1165 "gtk-toolbar-icon-size", &size,
1169 size = DEFAULT_ICON_SIZE;
1171 if (size != palette->priv->icon_size)
1173 gtk_tool_palette_set_icon_size (palette, size);
1174 g_object_notify (G_OBJECT (palette), "icon-size");
1177 priv->icon_size_set = FALSE;
1178 g_object_notify (G_OBJECT (palette), "icon-size-set");
1182 /* Set the "toolbar-style" property and do appropriate things.
1183 * GtkToolbar does this by emitting a signal instead of just
1184 * calling a function...
1187 gtk_tool_palette_change_style (GtkToolPalette *palette,
1188 GtkToolbarStyle style)
1190 GtkToolPalettePrivate* priv = palette->priv;
1192 if (priv->style != style)
1194 priv->style = style;
1196 gtk_tool_palette_reconfigured (palette);
1198 gtk_widget_queue_resize (GTK_WIDGET (palette));
1199 g_object_notify (G_OBJECT (palette), "toolbar-style");
1205 * gtk_tool_palette_set_style:
1206 * @palette: a #GtkToolPalette
1207 * @style: the #GtkToolbarStyle that items in the tool palette shall have
1209 * Sets the style (text, icons or both) of items in the tool palette.
1214 gtk_tool_palette_set_style (GtkToolPalette *palette,
1215 GtkToolbarStyle style)
1217 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1219 palette->priv->style_set = TRUE;
1220 gtk_tool_palette_change_style (palette, style);
1225 * gtk_tool_palette_unset_style:
1226 * @palette: a #GtkToolPalette
1228 * Unsets a toolbar style set with gtk_tool_palette_set_style(),
1229 * so that user preferences will be used to determine the toolbar style.
1234 gtk_tool_palette_unset_style (GtkToolPalette *palette)
1236 GtkToolPalettePrivate* priv = palette->priv;
1237 GtkToolbarStyle style;
1239 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1241 if (priv->style_set)
1243 GtkSettings *settings = toolpalette_get_settings (palette);
1246 g_object_get (settings,
1247 "gtk-toolbar-style", &style,
1250 style = DEFAULT_TOOLBAR_STYLE;
1252 if (style != priv->style)
1253 gtk_tool_palette_change_style (palette, style);
1255 priv->style_set = FALSE;
1260 * gtk_tool_palette_get_icon_size:
1261 * @palette: a #GtkToolPalette
1263 * Gets the size of icons in the tool palette.
1264 * See gtk_tool_palette_set_icon_size().
1266 * Returns: (type int): the #GtkIconSize of icons in the tool palette
1271 gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
1273 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
1275 return palette->priv->icon_size;
1279 * gtk_tool_palette_get_style:
1280 * @palette: a #GtkToolPalette
1282 * Gets the style (icons, text or both) of items in the tool palette.
1284 * Returns: the #GtkToolbarStyle of items in the tool palette.
1289 gtk_tool_palette_get_style (GtkToolPalette *palette)
1291 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
1293 return palette->priv->style;
1297 _gtk_tool_palette_compare_groups (gconstpointer a,
1300 const GtkToolItemGroupInfo *group_a = a;
1301 const GtkToolItemGroupInfo *group_b = b;
1303 return group_a->pos - group_b->pos;
1307 * gtk_tool_palette_set_group_position:
1308 * @palette: a #GtkToolPalette
1309 * @group: a #GtkToolItemGroup which is a child of palette
1310 * @position: a new index for group
1312 * Sets the position of the group as an index of the tool palette.
1313 * If position is 0 the group will become the first child, if position is
1314 * -1 it will become the last child.
1319 gtk_tool_palette_set_group_position (GtkToolPalette *palette,
1320 GtkToolItemGroup *group,
1323 GtkToolItemGroupInfo *group_new;
1324 GtkToolItemGroupInfo *group_old;
1327 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1328 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1329 g_return_if_fail (position >= -1);
1332 position = palette->priv->groups->len - 1;
1334 g_return_if_fail ((guint) position < palette->priv->groups->len);
1336 group_new = g_ptr_array_index (palette->priv->groups, position);
1338 if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
1341 old_position = gtk_tool_palette_get_group_position (palette, group);
1342 g_return_if_fail (old_position >= 0);
1344 group_old = g_ptr_array_index (palette->priv->groups, old_position);
1346 group_new->pos = position;
1347 group_old->pos = old_position;
1349 g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups);
1351 gtk_widget_queue_resize (GTK_WIDGET (palette));
1355 gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
1359 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1362 if (gtk_tool_item_group_get_collapsed (group))
1365 for (i = 0; i < palette->priv->groups->len; ++i)
1367 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1368 GtkToolItemGroup *current_group = info->widget;
1370 if (current_group && current_group != group)
1371 gtk_tool_item_group_set_collapsed (current_group, TRUE);
1376 * gtk_tool_palette_set_exclusive:
1377 * @palette: a #GtkToolPalette
1378 * @group: a #GtkToolItemGroup which is a child of palette
1379 * @exclusive: whether the group should be exclusive or not
1381 * Sets whether the group should be exclusive or not.
1382 * If an exclusive group is expanded all other groups are collapsed.
1387 gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
1388 GtkToolItemGroup *group,
1391 GtkToolItemGroupInfo *group_info;
1394 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1395 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1397 position = gtk_tool_palette_get_group_position (palette, group);
1398 g_return_if_fail (position >= 0);
1400 group_info = g_ptr_array_index (palette->priv->groups, position);
1402 if (exclusive == group_info->exclusive)
1405 group_info->exclusive = exclusive;
1407 if (group_info->exclusive != (0 != group_info->notify_collapsed))
1409 if (group_info->exclusive)
1411 group_info->notify_collapsed =
1412 g_signal_connect (group, "notify::collapsed",
1413 G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
1418 g_signal_handler_disconnect (group, group_info->notify_collapsed);
1419 group_info->notify_collapsed = 0;
1423 gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
1424 gtk_widget_child_notify (GTK_WIDGET (group), "exclusive");
1428 * gtk_tool_palette_set_expand:
1429 * @palette: a #GtkToolPalette
1430 * @group: a #GtkToolItemGroup which is a child of palette
1431 * @expand: whether the group should be given extra space
1433 * Sets whether the group should be given extra space.
1438 gtk_tool_palette_set_expand (GtkToolPalette *palette,
1439 GtkToolItemGroup *group,
1442 GtkToolItemGroupInfo *group_info;
1445 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1446 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1448 position = gtk_tool_palette_get_group_position (palette, group);
1449 g_return_if_fail (position >= 0);
1451 group_info = g_ptr_array_index (palette->priv->groups, position);
1453 if (expand != group_info->expand)
1455 group_info->expand = expand;
1456 gtk_widget_queue_resize (GTK_WIDGET (palette));
1457 gtk_widget_child_notify (GTK_WIDGET (group), "expand");
1462 * gtk_tool_palette_get_group_position:
1463 * @palette: a #GtkToolPalette
1464 * @group: a #GtkToolItemGroup
1466 * Gets the position of @group in @palette as index.
1467 * See gtk_tool_palette_set_group_position().
1469 * Returns: the index of group or -1 if @group is not a child of @palette
1474 gtk_tool_palette_get_group_position (GtkToolPalette *palette,
1475 GtkToolItemGroup *group)
1479 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
1480 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
1482 for (i = 0; i < palette->priv->groups->len; ++i)
1484 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1485 if ((gpointer) group == info->widget)
1493 * gtk_tool_palette_get_exclusive:
1494 * @palette: a #GtkToolPalette
1495 * @group: a #GtkToolItemGroup which is a child of palette
1497 * Gets whether @group is exclusive or not.
1498 * See gtk_tool_palette_set_exclusive().
1500 * Returns: %TRUE if @group is exclusive
1505 gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
1506 GtkToolItemGroup *group)
1509 GtkToolItemGroupInfo *info;
1511 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
1512 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
1514 position = gtk_tool_palette_get_group_position (palette, group);
1515 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
1517 info = g_ptr_array_index (palette->priv->groups, position);
1519 return info->exclusive;
1523 * gtk_tool_palette_get_expand:
1524 * @palette: a #GtkToolPalette
1525 * @group: a #GtkToolItemGroup which is a child of palette
1527 * Gets whether group should be given extra space.
1528 * See gtk_tool_palette_set_expand().
1530 * Returns: %TRUE if group should be given extra space, %FALSE otherwise
1535 gtk_tool_palette_get_expand (GtkToolPalette *palette,
1536 GtkToolItemGroup *group)
1539 GtkToolItemGroupInfo *info;
1541 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
1542 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
1544 position = gtk_tool_palette_get_group_position (palette, group);
1545 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
1547 info = g_ptr_array_index (palette->priv->groups, position);
1549 return info->expand;
1553 * gtk_tool_palette_get_drop_item:
1554 * @palette: a #GtkToolPalette
1555 * @x: the x position
1556 * @y: the y position
1558 * Gets the item at position (x, y).
1559 * See gtk_tool_palette_get_drop_group().
1561 * Returns: (transfer none): the #GtkToolItem at position or %NULL if there is no such item
1566 gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
1570 GtkAllocation allocation;
1571 GtkToolItemGroup *group = gtk_tool_palette_get_drop_group (palette, x, y);
1572 GtkWidget *widget = GTK_WIDGET (group);
1576 gtk_widget_get_allocation (widget, &allocation);
1577 return gtk_tool_item_group_get_drop_item (group,
1586 * gtk_tool_palette_get_drop_group:
1587 * @palette: a #GtkToolPalette
1588 * @x: the x position
1589 * @y: the y position
1591 * Gets the group at position (x, y).
1593 * Returns: (transfer none): the #GtkToolItemGroup at position or %NULL
1594 * if there is no such group
1599 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
1603 GtkAllocation allocation;
1606 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1608 gtk_widget_get_allocation (GTK_WIDGET (palette), &allocation);
1610 g_return_val_if_fail (x >= 0 && x < allocation.width, NULL);
1611 g_return_val_if_fail (y >= 0 && y < allocation.height, NULL);
1613 for (i = 0; i < palette->priv->groups->len; ++i)
1615 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1622 widget = GTK_WIDGET (group->widget);
1623 gtk_widget_get_allocation (widget, &allocation);
1625 x0 = x - allocation.x;
1626 y0 = y - allocation.y;
1628 if (x0 >= 0 && x0 < allocation.width &&
1629 y0 >= 0 && y0 < allocation.height)
1630 return GTK_TOOL_ITEM_GROUP (widget);
1637 * gtk_tool_palette_get_drag_item:
1638 * @palette: a #GtkToolPalette
1639 * @selection: a #GtkSelectionData
1641 * Get the dragged item from the selection.
1642 * This could be a #GtkToolItem or a #GtkToolItemGroup.
1644 * Returns: (transfer none): the dragged item in selection
1649 gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
1650 const GtkSelectionData *selection)
1652 GtkToolPaletteDragData *data;
1655 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1656 g_return_val_if_fail (NULL != selection, NULL);
1658 g_return_val_if_fail (gtk_selection_data_get_format (selection) == 8, NULL);
1659 g_return_val_if_fail (gtk_selection_data_get_length (selection) == sizeof (GtkToolPaletteDragData), NULL);
1660 target = gtk_selection_data_get_target (selection);
1661 g_return_val_if_fail (target == dnd_target_atom_item ||
1662 target == dnd_target_atom_group,
1665 data = (GtkToolPaletteDragData*) gtk_selection_data_get_data (selection);
1667 g_return_val_if_fail (data->palette == palette, NULL);
1669 if (dnd_target_atom_item == target)
1670 g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
1671 else if (dnd_target_atom_group == target)
1672 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
1678 * gtk_tool_palette_set_drag_source:
1679 * @palette: a #GtkToolPalette
1680 * @targets: the #GtkToolPaletteDragTarget<!-- -->s
1681 * which the widget should support
1683 * Sets the tool palette as a drag source.
1684 * Enables all groups and items in the tool palette as drag sources
1685 * on button 1 and button 3 press with copy and move actions.
1686 * See gtk_drag_source_set().
1691 gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
1692 GtkToolPaletteDragTargets targets)
1696 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1698 if ((palette->priv->drag_source & targets) == targets)
1701 palette->priv->drag_source |= targets;
1703 for (i = 0; i < palette->priv->groups->len; ++i)
1705 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1707 gtk_container_forall (GTK_CONTAINER (info->widget),
1708 _gtk_tool_palette_child_set_drag_source,
1714 * gtk_tool_palette_add_drag_dest:
1715 * @palette: a #GtkToolPalette
1716 * @widget: a #GtkWidget which should be a drag destination for @palette
1717 * @flags: the flags that specify what actions GTK+ should take for drops
1719 * @targets: the #GtkToolPaletteDragTarget<!-- -->s which the widget
1721 * @actions: the #GdkDragAction<!-- -->s which the widget should suppport
1723 * Sets @palette as drag source (see gtk_tool_palette_set_drag_source())
1724 * and sets @widget as a drag destination for drags from @palette.
1725 * See gtk_drag_dest_set().
1730 gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
1732 GtkDestDefaults flags,
1733 GtkToolPaletteDragTargets targets,
1734 GdkDragAction actions)
1736 GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
1739 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1740 g_return_if_fail (GTK_IS_WIDGET (widget));
1742 gtk_tool_palette_set_drag_source (palette,
1745 if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
1746 entries[n_entries++] = dnd_targets[0];
1747 if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
1748 entries[n_entries++] = dnd_targets[1];
1750 gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
1754 _gtk_tool_palette_get_item_size (GtkToolPalette *palette,
1755 GtkRequisition *item_size,
1756 gboolean homogeneous_only,
1757 gint *requested_rows)
1759 GtkRequisition max_requisition;
1763 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1764 g_return_if_fail (NULL != item_size);
1766 max_requisition.width = 0;
1767 max_requisition.height = 0;
1770 /* iterate over all groups and calculate the max item_size and max row request */
1771 for (i = 0; i < palette->priv->groups->len; ++i)
1773 GtkRequisition requisition;
1775 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1780 _gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
1782 max_requisition.width = MAX (max_requisition.width, requisition.width);
1783 max_requisition.height = MAX (max_requisition.height, requisition.height);
1784 max_rows = MAX (max_rows, rows);
1787 *item_size = max_requisition;
1789 *requested_rows = max_rows;
1793 gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
1794 GdkDragContext *context,
1795 GtkSelectionData *selection,
1800 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1803 target = gtk_selection_data_get_target (selection);
1805 if (target == dnd_target_atom_item)
1806 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
1809 gtk_selection_data_set (selection, target, 8,
1810 (guchar*) &drag_data, sizeof (drag_data));
1814 gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
1815 GdkDragContext *context,
1816 GtkSelectionData *selection,
1821 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1824 target = gtk_selection_data_get_target (selection);
1826 if (target == dnd_target_atom_group)
1827 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
1830 gtk_selection_data_set (selection, target, 8,
1831 (guchar*) &drag_data, sizeof (drag_data));
1835 _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
1838 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1840 /* Check drag_source,
1841 * to work properly when called from gtk_tool_item_group_insert().
1843 if (!palette->priv->drag_source)
1846 if (GTK_IS_TOOL_ITEM (child) &&
1847 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
1849 /* Connect to child instead of the item itself,
1850 * to work arround bug 510377.
1852 if (GTK_IS_TOOL_BUTTON (child))
1853 child = gtk_bin_get_child (GTK_BIN (child));
1858 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1859 &dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1861 g_signal_connect (child, "drag-data-get",
1862 G_CALLBACK (gtk_tool_palette_item_drag_data_get),
1865 else if (GTK_IS_BUTTON (child) &&
1866 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
1868 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1869 &dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1871 g_signal_connect (child, "drag-data-get",
1872 G_CALLBACK (gtk_tool_palette_child_drag_data_get),
1878 * gtk_tool_palette_get_drag_target_item:
1880 * Gets the target entry for a dragged #GtkToolItem.
1882 * Returns: (transfer none): the #GtkTargetEntry for a dragged item.
1886 const GtkTargetEntry*
1887 gtk_tool_palette_get_drag_target_item (void)
1889 return &dnd_targets[0];
1893 * gtk_tool_palette_get_drag_target_group:
1895 * Get the target entry for a dragged #GtkToolItemGroup.
1897 * Returns: (transfer none): the #GtkTargetEntry for a dragged group
1901 const GtkTargetEntry*
1902 gtk_tool_palette_get_drag_target_group (void)
1904 return &dnd_targets[1];
1908 _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
1911 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1912 palette->priv->expanding_child = widget;
1916 * gtk_tool_palette_get_hadjustment:
1917 * @palette: a #GtkToolPalette
1919 * Gets the horizontal adjustment of the tool palette.
1921 * Returns: (transfer none): the horizontal adjustment of @palette
1925 * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
1928 gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
1930 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1932 return palette->priv->hadjustment;
1936 gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
1937 GtkAdjustment *adjustment)
1939 GtkToolPalettePrivate *priv = palette->priv;
1941 if (adjustment && priv->hadjustment == adjustment)
1944 if (priv->hadjustment != NULL)
1946 g_signal_handlers_disconnect_by_func (priv->hadjustment,
1947 gtk_tool_palette_adjustment_value_changed,
1949 g_object_unref (priv->hadjustment);
1952 if (adjustment == NULL)
1953 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
1956 g_signal_connect (adjustment, "value-changed",
1957 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
1959 priv->hadjustment = g_object_ref_sink (adjustment);
1960 /* FIXME: Adjustment should probably have its values updated now */
1961 g_object_notify (G_OBJECT (palette), "hadjustment");
1965 * gtk_tool_palette_get_vadjustment:
1966 * @palette: a #GtkToolPalette
1968 * Gets the vertical adjustment of the tool palette.
1970 * Returns: (transfer none): the vertical adjustment of @palette
1974 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
1977 gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
1979 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1981 return palette->priv->vadjustment;
1985 gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
1986 GtkAdjustment *adjustment)
1988 GtkToolPalettePrivate *priv = palette->priv;
1990 if (adjustment && priv->vadjustment == adjustment)
1993 if (priv->vadjustment != NULL)
1995 g_signal_handlers_disconnect_by_func (priv->vadjustment,
1996 gtk_tool_palette_adjustment_value_changed,
1998 g_object_unref (priv->vadjustment);
2001 if (adjustment == NULL)
2002 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2005 g_signal_connect (adjustment, "value-changed",
2006 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
2008 priv->vadjustment = g_object_ref_sink (adjustment);
2009 /* FIXME: Adjustment should probably have its values updated now */
2010 g_object_notify (G_OBJECT (palette), "vadjustment");
2014 _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
2016 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
2018 return palette->priv->text_size_group;