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"
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_tool_palette_reconfigured (palette);
270 case PROP_TOOLBAR_STYLE:
271 if ((guint) g_value_get_enum (value) != palette->priv->style)
273 palette->priv->style = g_value_get_enum (value);
274 gtk_tool_palette_reconfigured (palette);
278 case PROP_HADJUSTMENT:
279 gtk_tool_palette_set_hadjustment (palette, g_value_get_object (value));
282 case PROP_VADJUSTMENT:
283 gtk_tool_palette_set_vadjustment (palette, g_value_get_object (value));
286 case PROP_HSCROLL_POLICY:
287 palette->priv->hscroll_policy = g_value_get_enum (value);
288 gtk_widget_queue_resize (GTK_WIDGET (palette));
291 case PROP_VSCROLL_POLICY:
292 palette->priv->vscroll_policy = g_value_get_enum (value);
293 gtk_widget_queue_resize (GTK_WIDGET (palette));
297 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
303 gtk_tool_palette_get_property (GObject *object,
308 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
313 g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
316 case PROP_ICON_SIZE_SET:
317 g_value_set_boolean (value, palette->priv->icon_size_set);
320 case PROP_ORIENTATION:
321 g_value_set_enum (value, palette->priv->orientation);
324 case PROP_TOOLBAR_STYLE:
325 g_value_set_enum (value, gtk_tool_palette_get_style (palette));
328 case PROP_HADJUSTMENT:
329 g_value_set_object (value, palette->priv->hadjustment);
332 case PROP_VADJUSTMENT:
333 g_value_set_object (value, palette->priv->vadjustment);
336 case PROP_HSCROLL_POLICY:
337 g_value_set_enum (value, palette->priv->hscroll_policy);
340 case PROP_VSCROLL_POLICY:
341 g_value_set_enum (value, palette->priv->vscroll_policy);
345 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
351 gtk_tool_palette_dispose (GObject *object)
353 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
356 if (palette->priv->hadjustment)
358 g_object_unref (palette->priv->hadjustment);
359 palette->priv->hadjustment = NULL;
362 if (palette->priv->vadjustment)
364 g_object_unref (palette->priv->vadjustment);
365 palette->priv->vadjustment = NULL;
368 for (i = 0; i < palette->priv->groups->len; ++i)
370 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
372 if (group->notify_collapsed)
374 g_signal_handler_disconnect (group->widget, group->notify_collapsed);
375 group->notify_collapsed = 0;
379 if (palette->priv->text_size_group)
381 g_object_unref (palette->priv->text_size_group);
382 palette->priv->text_size_group = NULL;
385 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
389 gtk_tool_palette_finalize (GObject *object)
391 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
393 g_ptr_array_free (palette->priv->groups, TRUE);
395 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
399 gtk_tool_palette_size_request (GtkWidget *widget,
400 GtkRequisition *requisition)
402 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
403 GtkRequisition child_requisition;
407 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
409 requisition->width = 0;
410 requisition->height = 0;
412 for (i = 0; i < palette->priv->groups->len; ++i)
414 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
419 gtk_widget_get_preferred_size (GTK_WIDGET (group->widget),
420 &child_requisition, NULL);
422 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
424 requisition->width = MAX (requisition->width, child_requisition.width);
425 requisition->height += child_requisition.height;
429 requisition->width += child_requisition.width;
430 requisition->height = MAX (requisition->height, child_requisition.height);
434 requisition->width += border_width * 2;
435 requisition->height += border_width * 2;
439 gtk_tool_palette_get_preferred_width (GtkWidget *widget,
443 GtkRequisition requisition;
445 gtk_tool_palette_size_request (widget, &requisition);
447 *minimum = *natural = requisition.width;
451 gtk_tool_palette_get_preferred_height (GtkWidget *widget,
455 GtkRequisition requisition;
457 gtk_tool_palette_size_request (widget, &requisition);
459 *minimum = *natural = requisition.height;
464 gtk_tool_palette_size_allocate (GtkWidget *widget,
465 GtkAllocation *allocation)
467 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
468 GtkAdjustment *adjustment = NULL;
469 GtkAllocation child_allocation;
471 gint n_expand_groups = 0;
472 gint remaining_space = 0;
473 gint expand_space = 0;
475 gint page_start, page_size = 0;
480 gint min_offset = -1, max_offset = -1;
484 gint *group_sizes = g_newa (gint, palette->priv->groups->len);
485 GtkTextDirection direction;
487 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
488 direction = gtk_widget_get_direction (widget);
490 GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
492 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
494 adjustment = palette->priv->vadjustment;
495 page_size = allocation->height;
499 adjustment = palette->priv->hadjustment;
500 page_size = allocation->width;
504 offset = gtk_adjustment_get_value (adjustment);
505 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
506 GTK_TEXT_DIR_RTL == direction)
509 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
510 child_allocation.width = allocation->width - border_width * 2;
512 child_allocation.height = allocation->height - border_width * 2;
514 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
515 remaining_space = allocation->height;
517 remaining_space = allocation->width;
519 /* figure out the required size of all groups to be able to distribute the
520 * remaining space on allocation
522 for (i = 0; i < palette->priv->groups->len; ++i)
524 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
530 widget = GTK_WIDGET (group->widget);
532 if (gtk_tool_item_group_get_n_items (group->widget))
534 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
535 size = _gtk_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
537 size = _gtk_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
539 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
540 n_expand_groups += 1;
545 remaining_space -= size;
546 group_sizes[i] = size;
548 /* if the widget is currently expanding an offset which allows to
549 * display as much of the widget as possible is calculated
551 if (widget == palette->priv->expanding_child)
554 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
555 child_allocation.width : child_allocation.height;
562 for (j = 0; j < i; ++j)
563 min_offset += group_sizes[j];
565 max_offset = min_offset + group_sizes[i];
567 real_size = _gtk_tool_item_group_get_size_for_limit
568 (GTK_TOOL_ITEM_GROUP (widget), limit,
569 GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
572 if (size == real_size)
573 palette->priv->expanding_child = NULL;
577 if (n_expand_groups > 0)
579 remaining_space = MAX (0, remaining_space);
580 expand_space = remaining_space / n_expand_groups;
583 if (max_offset != -1)
586 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
587 allocation->height : allocation->width;
589 offset = MIN (MAX (offset, max_offset - limit), min_offset);
592 if (remaining_space > 0)
596 child_allocation.y = border_width;
598 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
599 child_allocation.y -= offset;
603 /* allocate all groups at the calculated positions */
604 for (i = 0; i < palette->priv->groups->len; ++i)
606 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
612 widget = GTK_WIDGET (group->widget);
614 if (gtk_tool_item_group_get_n_items (group->widget))
616 gint size = group_sizes[i];
618 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
620 size += MIN (expand_space, remaining_space);
621 remaining_space -= expand_space;
624 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
625 child_allocation.height = size;
627 child_allocation.width = size;
629 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
630 GTK_TEXT_DIR_RTL == direction)
631 child_allocation.x = allocation->width - x - child_allocation.width;
633 child_allocation.x = x;
635 gtk_widget_size_allocate (widget, &child_allocation);
636 gtk_widget_show (widget);
638 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
639 child_allocation.y += child_allocation.height;
641 x += child_allocation.width;
644 gtk_widget_hide (widget);
647 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
649 child_allocation.y += border_width;
650 child_allocation.y += offset;
652 page_start = child_allocation.y;
662 /* update the scrollbar to match the displayed adjustment */
667 adjustment->page_increment = page_size * 0.9;
668 adjustment->step_increment = page_size * 0.1;
669 adjustment->page_size = page_size;
671 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
672 GTK_TEXT_DIR_LTR == direction)
674 adjustment->lower = 0;
675 adjustment->upper = MAX (0, page_start);
677 value = MIN (offset, adjustment->upper - adjustment->page_size);
678 gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
682 adjustment->lower = page_size - MAX (0, page_start);
683 adjustment->upper = page_size;
687 value = MAX (offset, adjustment->lower);
688 gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
691 gtk_adjustment_changed (adjustment);
696 gtk_tool_palette_draw (GtkWidget *widget,
699 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
704 window = gtk_widget_get_window (widget);
706 display = gdk_window_get_display (window);
708 if (!gdk_display_supports_composite (display))
711 cairo_push_group (cr);
713 for (i = 0; i < palette->priv->groups->len; ++i)
715 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
717 _gtk_tool_item_group_paint (info->widget, cr);
720 cairo_pop_group_to_source (cr);
728 gtk_tool_palette_realize (GtkWidget *widget)
730 GtkAllocation allocation;
732 GdkWindowAttr attributes;
733 gint attributes_mask;
736 gtk_widget_set_realized (widget, TRUE);
738 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
740 gtk_widget_get_allocation (widget, &allocation);
742 attributes.window_type = GDK_WINDOW_CHILD;
743 attributes.x = allocation.x + border_width;
744 attributes.y = allocation.y + border_width;
745 attributes.width = allocation.width - border_width * 2;
746 attributes.height = allocation.height - border_width * 2;
747 attributes.wclass = GDK_INPUT_OUTPUT;
748 attributes.visual = gtk_widget_get_visual (widget);
749 attributes.event_mask = gtk_widget_get_events (widget)
750 | GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
751 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
752 | GDK_BUTTON_MOTION_MASK;
753 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
755 window = gdk_window_new (gtk_widget_get_parent_window (widget),
756 &attributes, attributes_mask);
757 gtk_widget_set_window (widget, window);
758 gdk_window_set_user_data (window, widget);
760 gtk_style_context_set_background (gtk_widget_get_style_context (widget),
763 gtk_container_forall (GTK_CONTAINER (widget),
764 (GtkCallback) gtk_widget_set_parent_window,
767 gtk_widget_queue_resize_no_redraw (widget);
771 gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
774 GtkAllocation allocation;
775 GtkWidget *widget = GTK_WIDGET (data);
777 gtk_widget_get_allocation (widget, &allocation);
778 gtk_tool_palette_size_allocate (widget, &allocation);
782 gtk_tool_palette_add (GtkContainer *container,
785 GtkToolPalette *palette;
786 GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
788 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
789 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
791 palette = GTK_TOOL_PALETTE (container);
793 g_ptr_array_add (palette->priv->groups, info);
794 info->pos = palette->priv->groups->len - 1;
795 info->widget = g_object_ref_sink (child);
797 gtk_widget_set_parent (child, GTK_WIDGET (palette));
801 gtk_tool_palette_remove (GtkContainer *container,
804 GtkToolPalette *palette;
807 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
808 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);
813 if (GTK_WIDGET(info->widget) == child)
815 g_object_unref (child);
816 gtk_widget_unparent (child);
818 g_ptr_array_remove_index (palette->priv->groups, i);
824 gtk_tool_palette_forall (GtkContainer *container,
826 GtkCallback callback,
827 gpointer callback_data)
829 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
833 for (i = 0; i < palette->priv->groups->len; ++i)
835 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
837 callback (GTK_WIDGET (info->widget),
843 gtk_tool_palette_child_type (GtkContainer *container)
845 return GTK_TYPE_TOOL_ITEM_GROUP;
849 gtk_tool_palette_set_child_property (GtkContainer *container,
855 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
859 case CHILD_PROP_EXCLUSIVE:
860 gtk_tool_palette_set_exclusive (palette, GTK_TOOL_ITEM_GROUP (child),
861 g_value_get_boolean (value));
864 case CHILD_PROP_EXPAND:
865 gtk_tool_palette_set_expand (palette, GTK_TOOL_ITEM_GROUP (child),
866 g_value_get_boolean (value));
870 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
876 gtk_tool_palette_get_child_property (GtkContainer *container,
882 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
886 case CHILD_PROP_EXCLUSIVE:
887 g_value_set_boolean (value,
888 gtk_tool_palette_get_exclusive (palette, GTK_TOOL_ITEM_GROUP (child)));
891 case CHILD_PROP_EXPAND:
892 g_value_set_boolean (value,
893 gtk_tool_palette_get_expand (palette, GTK_TOOL_ITEM_GROUP (child)));
897 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
903 style_change_notify (GtkToolPalette *palette)
905 GtkToolPalettePrivate* priv = palette->priv;
907 if (!priv->style_set)
909 /* pretend it was set, then unset, thus reverting to new default */
910 priv->style_set = TRUE;
911 gtk_tool_palette_unset_style (palette);
916 icon_size_change_notify (GtkToolPalette *palette)
918 GtkToolPalettePrivate* priv = palette->priv;
920 if (!priv->icon_size_set)
922 /* pretend it was set, then unset, thus reverting to new default */
923 priv->icon_size_set = TRUE;
924 gtk_tool_palette_unset_icon_size (palette);
929 gtk_tool_palette_settings_change_notify (GtkSettings *settings,
930 const GParamSpec *pspec,
931 GtkToolPalette *palette)
933 if (strcmp (pspec->name, "gtk-toolbar-style") == 0)
934 style_change_notify (palette);
935 else if (strcmp (pspec->name, "gtk-toolbar-icon-size") == 0)
936 icon_size_change_notify (palette);
940 gtk_tool_palette_screen_changed (GtkWidget *widget,
941 GdkScreen *previous_screen)
943 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
944 GtkToolPalettePrivate* priv = palette->priv;
945 GtkSettings *old_settings = priv->settings;
946 GtkSettings *settings;
948 if (gtk_widget_has_screen (GTK_WIDGET (palette)))
949 settings = gtk_widget_get_settings (GTK_WIDGET (palette));
953 if (settings == old_settings)
958 g_signal_handler_disconnect (old_settings, priv->settings_connection);
959 g_object_unref (old_settings);
964 priv->settings_connection =
965 g_signal_connect (settings, "notify",
966 G_CALLBACK (gtk_tool_palette_settings_change_notify),
968 priv->settings = g_object_ref (settings);
971 priv->settings = NULL;
973 gtk_tool_palette_reconfigured (palette);
978 gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
980 GObjectClass *oclass = G_OBJECT_CLASS (cls);
981 GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
982 GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
984 oclass->set_property = gtk_tool_palette_set_property;
985 oclass->get_property = gtk_tool_palette_get_property;
986 oclass->dispose = gtk_tool_palette_dispose;
987 oclass->finalize = gtk_tool_palette_finalize;
989 wclass->get_preferred_width = gtk_tool_palette_get_preferred_width;
990 wclass->get_preferred_height= gtk_tool_palette_get_preferred_height;
991 wclass->size_allocate = gtk_tool_palette_size_allocate;
992 wclass->draw = gtk_tool_palette_draw;
993 wclass->realize = gtk_tool_palette_realize;
995 cclass->add = gtk_tool_palette_add;
996 cclass->remove = gtk_tool_palette_remove;
997 cclass->forall = gtk_tool_palette_forall;
998 cclass->child_type = gtk_tool_palette_child_type;
999 cclass->set_child_property = gtk_tool_palette_set_child_property;
1000 cclass->get_child_property = gtk_tool_palette_get_child_property;
1002 /* Handle screen-changed so we can update our GtkSettings.
1004 wclass->screen_changed = gtk_tool_palette_screen_changed;
1006 g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
1008 g_object_class_override_property (oclass, PROP_HADJUSTMENT, "hadjustment");
1009 g_object_class_override_property (oclass, PROP_VADJUSTMENT, "vadjustment");
1010 g_object_class_override_property (oclass, PROP_HSCROLL_POLICY, "hscroll-policy");
1011 g_object_class_override_property (oclass, PROP_VSCROLL_POLICY, "vscroll-policy");
1014 * GtkToolPalette:icon-size:
1016 * The size of the icons in a tool palette is normally determined by
1017 * the #GtkSettings:toolbar-icon-size setting. When this property is set,
1018 * it overrides the setting.
1020 * This should only be used for special-purpose tool palettes, normal
1021 * application tool palettes should respect the user preferences for the
1026 g_object_class_install_property (oclass,
1028 g_param_spec_enum ("icon-size",
1030 P_("Size of icons in this tool palette"),
1033 GTK_PARAM_READWRITE));
1036 * GtkToolPalette:icon-size-set:
1038 * Is %TRUE if the #GtkToolPalette:icon-size property has been set.
1042 g_object_class_install_property (oclass,
1044 g_param_spec_boolean ("icon-size-set",
1045 P_("Icon size set"),
1046 P_("Whether the icon-size property has been set"),
1048 GTK_PARAM_READWRITE));
1051 * GtkToolPalette:toolbar-style:
1053 * The style of items in the tool palette.
1057 g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
1058 g_param_spec_enum ("toolbar-style",
1059 P_("Toolbar Style"),
1060 P_("Style of items in the tool palette"),
1061 GTK_TYPE_TOOLBAR_STYLE,
1062 DEFAULT_TOOLBAR_STYLE,
1063 GTK_PARAM_READWRITE));
1067 * GtkToolPalette:exclusive:
1069 * Whether the item group should be the only one that is expanded
1074 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
1075 g_param_spec_boolean ("exclusive",
1077 P_("Whether the item group should be the only expanded at a given time"),
1078 DEFAULT_CHILD_EXCLUSIVE,
1079 GTK_PARAM_READWRITE));
1082 * GtkToolPalette:expand:
1084 * Whether the item group should receive extra space when the palette grows.
1089 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1090 g_param_spec_boolean ("expand",
1092 P_("Whether the item group should receive extra space when the palette grows"),
1093 DEFAULT_CHILD_EXPAND,
1094 GTK_PARAM_READWRITE));
1096 g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
1098 dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
1099 dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
1103 * gtk_tool_palette_new:
1105 * Creates a new tool palette.
1107 * Returns: a new #GtkToolPalette
1112 gtk_tool_palette_new (void)
1114 return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
1118 * gtk_tool_palette_set_icon_size:
1119 * @palette: a #GtkToolPalette
1120 * @icon_size: (type int): the #GtkIconSize that icons in the tool
1121 * palette shall have
1123 * Sets the size of icons in the tool palette.
1128 gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
1129 GtkIconSize icon_size)
1131 GtkToolPalettePrivate *priv;
1133 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1134 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
1136 priv = palette->priv;
1138 if (!priv->icon_size_set)
1140 priv->icon_size_set = TRUE;
1141 g_object_notify (G_OBJECT (palette), "icon-size-set");
1144 if (priv->icon_size == icon_size)
1147 priv->icon_size = icon_size;
1148 g_object_notify (G_OBJECT (palette), "icon-size");
1150 gtk_tool_palette_reconfigured (palette);
1152 gtk_widget_queue_resize (GTK_WIDGET (palette));
1155 static GtkSettings *
1156 toolpalette_get_settings (GtkToolPalette *palette)
1158 GtkToolPalettePrivate *priv = palette->priv;
1159 return priv->settings;
1163 * gtk_tool_palette_unset_icon_size:
1164 * @palette: a #GtkToolPalette
1166 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(),
1167 * so that user preferences will be used to determine the icon size.
1172 gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
1174 GtkToolPalettePrivate* priv = palette->priv;
1177 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1179 if (palette->priv->icon_size_set)
1181 GtkSettings *settings = toolpalette_get_settings (palette);
1185 g_object_get (settings,
1186 "gtk-toolbar-icon-size", &size,
1190 size = DEFAULT_ICON_SIZE;
1192 if (size != palette->priv->icon_size)
1194 gtk_tool_palette_set_icon_size (palette, size);
1195 g_object_notify (G_OBJECT (palette), "icon-size");
1198 priv->icon_size_set = FALSE;
1199 g_object_notify (G_OBJECT (palette), "icon-size-set");
1203 /* Set the "toolbar-style" property and do appropriate things.
1204 * GtkToolbar does this by emitting a signal instead of just
1205 * calling a function...
1208 gtk_tool_palette_change_style (GtkToolPalette *palette,
1209 GtkToolbarStyle style)
1211 GtkToolPalettePrivate* priv = palette->priv;
1213 if (priv->style != style)
1215 priv->style = style;
1217 gtk_tool_palette_reconfigured (palette);
1219 gtk_widget_queue_resize (GTK_WIDGET (palette));
1220 g_object_notify (G_OBJECT (palette), "toolbar-style");
1226 * gtk_tool_palette_set_style:
1227 * @palette: a #GtkToolPalette
1228 * @style: the #GtkToolbarStyle that items in the tool palette shall have
1230 * Sets the style (text, icons or both) of items in the tool palette.
1235 gtk_tool_palette_set_style (GtkToolPalette *palette,
1236 GtkToolbarStyle style)
1238 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1240 palette->priv->style_set = TRUE;
1241 gtk_tool_palette_change_style (palette, style);
1246 * gtk_tool_palette_unset_style:
1247 * @palette: a #GtkToolPalette
1249 * Unsets a toolbar style set with gtk_tool_palette_set_style(),
1250 * so that user preferences will be used to determine the toolbar style.
1255 gtk_tool_palette_unset_style (GtkToolPalette *palette)
1257 GtkToolPalettePrivate* priv = palette->priv;
1258 GtkToolbarStyle style;
1260 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1262 if (priv->style_set)
1264 GtkSettings *settings = toolpalette_get_settings (palette);
1267 g_object_get (settings,
1268 "gtk-toolbar-style", &style,
1271 style = DEFAULT_TOOLBAR_STYLE;
1273 if (style != priv->style)
1274 gtk_tool_palette_change_style (palette, style);
1276 priv->style_set = FALSE;
1281 * gtk_tool_palette_get_icon_size:
1282 * @palette: a #GtkToolPalette
1284 * Gets the size of icons in the tool palette.
1285 * See gtk_tool_palette_set_icon_size().
1287 * Returns: (type int): the #GtkIconSize of icons in the tool palette
1292 gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
1294 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
1296 return palette->priv->icon_size;
1300 * gtk_tool_palette_get_style:
1301 * @palette: a #GtkToolPalette
1303 * Gets the style (icons, text or both) of items in the tool palette.
1305 * Returns: the #GtkToolbarStyle of items in the tool palette.
1310 gtk_tool_palette_get_style (GtkToolPalette *palette)
1312 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
1314 return palette->priv->style;
1318 _gtk_tool_palette_compare_groups (gconstpointer a,
1321 const GtkToolItemGroupInfo *group_a = a;
1322 const GtkToolItemGroupInfo *group_b = b;
1324 return group_a->pos - group_b->pos;
1328 * gtk_tool_palette_set_group_position:
1329 * @palette: a #GtkToolPalette
1330 * @group: a #GtkToolItemGroup which is a child of palette
1331 * @position: a new index for group
1333 * Sets the position of the group as an index of the tool palette.
1334 * If position is 0 the group will become the first child, if position is
1335 * -1 it will become the last child.
1340 gtk_tool_palette_set_group_position (GtkToolPalette *palette,
1341 GtkToolItemGroup *group,
1344 GtkToolItemGroupInfo *group_new;
1345 GtkToolItemGroupInfo *group_old;
1348 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1349 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1350 g_return_if_fail (position >= -1);
1353 position = palette->priv->groups->len - 1;
1355 g_return_if_fail ((guint) position < palette->priv->groups->len);
1357 group_new = g_ptr_array_index (palette->priv->groups, position);
1359 if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
1362 old_position = gtk_tool_palette_get_group_position (palette, group);
1363 g_return_if_fail (old_position >= 0);
1365 group_old = g_ptr_array_index (palette->priv->groups, old_position);
1367 group_new->pos = position;
1368 group_old->pos = old_position;
1370 g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups);
1372 gtk_widget_queue_resize (GTK_WIDGET (palette));
1376 gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
1380 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1383 if (gtk_tool_item_group_get_collapsed (group))
1386 for (i = 0; i < palette->priv->groups->len; ++i)
1388 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1389 GtkToolItemGroup *current_group = info->widget;
1391 if (current_group && current_group != group)
1392 gtk_tool_item_group_set_collapsed (current_group, TRUE);
1397 * gtk_tool_palette_set_exclusive:
1398 * @palette: a #GtkToolPalette
1399 * @group: a #GtkToolItemGroup which is a child of palette
1400 * @exclusive: whether the group should be exclusive or not
1402 * Sets whether the group should be exclusive or not.
1403 * If an exclusive group is expanded all other groups are collapsed.
1408 gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
1409 GtkToolItemGroup *group,
1412 GtkToolItemGroupInfo *group_info;
1415 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1416 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1418 position = gtk_tool_palette_get_group_position (palette, group);
1419 g_return_if_fail (position >= 0);
1421 group_info = g_ptr_array_index (palette->priv->groups, position);
1423 if (exclusive == group_info->exclusive)
1426 group_info->exclusive = exclusive;
1428 if (group_info->exclusive != (0 != group_info->notify_collapsed))
1430 if (group_info->exclusive)
1432 group_info->notify_collapsed =
1433 g_signal_connect (group, "notify::collapsed",
1434 G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
1439 g_signal_handler_disconnect (group, group_info->notify_collapsed);
1440 group_info->notify_collapsed = 0;
1444 gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
1445 gtk_widget_child_notify (GTK_WIDGET (group), "exclusive");
1449 * gtk_tool_palette_set_expand:
1450 * @palette: a #GtkToolPalette
1451 * @group: a #GtkToolItemGroup which is a child of palette
1452 * @expand: whether the group should be given extra space
1454 * Sets whether the group should be given extra space.
1459 gtk_tool_palette_set_expand (GtkToolPalette *palette,
1460 GtkToolItemGroup *group,
1463 GtkToolItemGroupInfo *group_info;
1466 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1467 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1469 position = gtk_tool_palette_get_group_position (palette, group);
1470 g_return_if_fail (position >= 0);
1472 group_info = g_ptr_array_index (palette->priv->groups, position);
1474 if (expand != group_info->expand)
1476 group_info->expand = expand;
1477 gtk_widget_queue_resize (GTK_WIDGET (palette));
1478 gtk_widget_child_notify (GTK_WIDGET (group), "expand");
1483 * gtk_tool_palette_get_group_position:
1484 * @palette: a #GtkToolPalette
1485 * @group: a #GtkToolItemGroup
1487 * Gets the position of @group in @palette as index.
1488 * See gtk_tool_palette_set_group_position().
1490 * Returns: the index of group or -1 if @group is not a child of @palette
1495 gtk_tool_palette_get_group_position (GtkToolPalette *palette,
1496 GtkToolItemGroup *group)
1500 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
1501 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
1503 for (i = 0; i < palette->priv->groups->len; ++i)
1505 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1506 if ((gpointer) group == info->widget)
1514 * gtk_tool_palette_get_exclusive:
1515 * @palette: a #GtkToolPalette
1516 * @group: a #GtkToolItemGroup which is a child of palette
1518 * Gets whether @group is exclusive or not.
1519 * See gtk_tool_palette_set_exclusive().
1521 * Returns: %TRUE if @group is exclusive
1526 gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
1527 GtkToolItemGroup *group)
1530 GtkToolItemGroupInfo *info;
1532 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
1533 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
1535 position = gtk_tool_palette_get_group_position (palette, group);
1536 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
1538 info = g_ptr_array_index (palette->priv->groups, position);
1540 return info->exclusive;
1544 * gtk_tool_palette_get_expand:
1545 * @palette: a #GtkToolPalette
1546 * @group: a #GtkToolItemGroup which is a child of palette
1548 * Gets whether group should be given extra space.
1549 * See gtk_tool_palette_set_expand().
1551 * Returns: %TRUE if group should be given extra space, %FALSE otherwise
1556 gtk_tool_palette_get_expand (GtkToolPalette *palette,
1557 GtkToolItemGroup *group)
1560 GtkToolItemGroupInfo *info;
1562 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
1563 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
1565 position = gtk_tool_palette_get_group_position (palette, group);
1566 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
1568 info = g_ptr_array_index (palette->priv->groups, position);
1570 return info->expand;
1574 * gtk_tool_palette_get_drop_item:
1575 * @palette: a #GtkToolPalette
1576 * @x: the x position
1577 * @y: the y position
1579 * Gets the item at position (x, y).
1580 * See gtk_tool_palette_get_drop_group().
1582 * Returns: (transfer none): the #GtkToolItem at position or %NULL if there is no such item
1587 gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
1591 GtkAllocation allocation;
1592 GtkToolItemGroup *group = gtk_tool_palette_get_drop_group (palette, x, y);
1593 GtkWidget *widget = GTK_WIDGET (group);
1597 gtk_widget_get_allocation (widget, &allocation);
1598 return gtk_tool_item_group_get_drop_item (group,
1607 * gtk_tool_palette_get_drop_group:
1608 * @palette: a #GtkToolPalette
1609 * @x: the x position
1610 * @y: the y position
1612 * Gets the group at position (x, y).
1614 * Returns: (transfer none): the #GtkToolItemGroup at position or %NULL
1615 * if there is no such group
1620 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
1624 GtkAllocation allocation;
1627 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1629 gtk_widget_get_allocation (GTK_WIDGET (palette), &allocation);
1631 g_return_val_if_fail (x >= 0 && x < allocation.width, NULL);
1632 g_return_val_if_fail (y >= 0 && y < allocation.height, NULL);
1634 for (i = 0; i < palette->priv->groups->len; ++i)
1636 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1643 widget = GTK_WIDGET (group->widget);
1644 gtk_widget_get_allocation (widget, &allocation);
1646 x0 = x - allocation.x;
1647 y0 = y - allocation.y;
1649 if (x0 >= 0 && x0 < allocation.width &&
1650 y0 >= 0 && y0 < allocation.height)
1651 return GTK_TOOL_ITEM_GROUP (widget);
1658 * gtk_tool_palette_get_drag_item:
1659 * @palette: a #GtkToolPalette
1660 * @selection: a #GtkSelectionData
1662 * Get the dragged item from the selection.
1663 * This could be a #GtkToolItem or a #GtkToolItemGroup.
1665 * Returns: (transfer none): the dragged item in selection
1670 gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
1671 const GtkSelectionData *selection)
1673 GtkToolPaletteDragData *data;
1676 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1677 g_return_val_if_fail (NULL != selection, NULL);
1679 g_return_val_if_fail (gtk_selection_data_get_format (selection) == 8, NULL);
1680 g_return_val_if_fail (gtk_selection_data_get_length (selection) == sizeof (GtkToolPaletteDragData), NULL);
1681 target = gtk_selection_data_get_target (selection);
1682 g_return_val_if_fail (target == dnd_target_atom_item ||
1683 target == dnd_target_atom_group,
1686 data = (GtkToolPaletteDragData*) gtk_selection_data_get_data (selection);
1688 g_return_val_if_fail (data->palette == palette, NULL);
1690 if (dnd_target_atom_item == target)
1691 g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
1692 else if (dnd_target_atom_group == target)
1693 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
1699 * gtk_tool_palette_set_drag_source:
1700 * @palette: a #GtkToolPalette
1701 * @targets: the #GtkToolPaletteDragTarget<!-- -->s
1702 * which the widget should support
1704 * Sets the tool palette as a drag source.
1705 * Enables all groups and items in the tool palette as drag sources
1706 * on button 1 and button 3 press with copy and move actions.
1707 * See gtk_drag_source_set().
1712 gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
1713 GtkToolPaletteDragTargets targets)
1717 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1719 if ((palette->priv->drag_source & targets) == targets)
1722 palette->priv->drag_source |= targets;
1724 for (i = 0; i < palette->priv->groups->len; ++i)
1726 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1728 gtk_container_forall (GTK_CONTAINER (info->widget),
1729 _gtk_tool_palette_child_set_drag_source,
1735 * gtk_tool_palette_add_drag_dest:
1736 * @palette: a #GtkToolPalette
1737 * @widget: a #GtkWidget which should be a drag destination for @palette
1738 * @flags: the flags that specify what actions GTK+ should take for drops
1740 * @targets: the #GtkToolPaletteDragTarget<!-- -->s which the widget
1742 * @actions: the #GdkDragAction<!-- -->s which the widget should suppport
1744 * Sets @palette as drag source (see gtk_tool_palette_set_drag_source())
1745 * and sets @widget as a drag destination for drags from @palette.
1746 * See gtk_drag_dest_set().
1751 gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
1753 GtkDestDefaults flags,
1754 GtkToolPaletteDragTargets targets,
1755 GdkDragAction actions)
1757 GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
1760 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1761 g_return_if_fail (GTK_IS_WIDGET (widget));
1763 gtk_tool_palette_set_drag_source (palette,
1766 if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
1767 entries[n_entries++] = dnd_targets[0];
1768 if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
1769 entries[n_entries++] = dnd_targets[1];
1771 gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
1775 _gtk_tool_palette_get_item_size (GtkToolPalette *palette,
1776 GtkRequisition *item_size,
1777 gboolean homogeneous_only,
1778 gint *requested_rows)
1780 GtkRequisition max_requisition;
1784 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1785 g_return_if_fail (NULL != item_size);
1787 max_requisition.width = 0;
1788 max_requisition.height = 0;
1791 /* iterate over all groups and calculate the max item_size and max row request */
1792 for (i = 0; i < palette->priv->groups->len; ++i)
1794 GtkRequisition requisition;
1796 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1801 _gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
1803 max_requisition.width = MAX (max_requisition.width, requisition.width);
1804 max_requisition.height = MAX (max_requisition.height, requisition.height);
1805 max_rows = MAX (max_rows, rows);
1808 *item_size = max_requisition;
1810 *requested_rows = max_rows;
1814 gtk_tool_palette_item_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_item)
1827 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
1830 gtk_selection_data_set (selection, target, 8,
1831 (guchar*) &drag_data, sizeof (drag_data));
1835 gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
1836 GdkDragContext *context,
1837 GtkSelectionData *selection,
1842 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1845 target = gtk_selection_data_get_target (selection);
1847 if (target == dnd_target_atom_group)
1848 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
1851 gtk_selection_data_set (selection, target, 8,
1852 (guchar*) &drag_data, sizeof (drag_data));
1856 _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
1859 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1861 /* Check drag_source,
1862 * to work properly when called from gtk_tool_item_group_insert().
1864 if (!palette->priv->drag_source)
1867 if (GTK_IS_TOOL_ITEM (child) &&
1868 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
1870 /* Connect to child instead of the item itself,
1871 * to work arround bug 510377.
1873 if (GTK_IS_TOOL_BUTTON (child))
1874 child = gtk_bin_get_child (GTK_BIN (child));
1879 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1880 &dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1882 g_signal_connect (child, "drag-data-get",
1883 G_CALLBACK (gtk_tool_palette_item_drag_data_get),
1886 else if (GTK_IS_BUTTON (child) &&
1887 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
1889 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1890 &dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1892 g_signal_connect (child, "drag-data-get",
1893 G_CALLBACK (gtk_tool_palette_child_drag_data_get),
1899 * gtk_tool_palette_get_drag_target_item:
1901 * Gets the target entry for a dragged #GtkToolItem.
1903 * Returns: (transfer none): the #GtkTargetEntry for a dragged item.
1907 G_CONST_RETURN GtkTargetEntry*
1908 gtk_tool_palette_get_drag_target_item (void)
1910 return &dnd_targets[0];
1914 * gtk_tool_palette_get_drag_target_group:
1916 * Get the target entry for a dragged #GtkToolItemGroup.
1918 * Returns: (transfer none): the #GtkTargetEntry for a dragged group
1922 G_CONST_RETURN GtkTargetEntry*
1923 gtk_tool_palette_get_drag_target_group (void)
1925 return &dnd_targets[1];
1929 _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
1932 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1933 palette->priv->expanding_child = widget;
1937 * gtk_tool_palette_get_hadjustment:
1938 * @palette: a #GtkToolPalette
1940 * Gets the horizontal adjustment of the tool palette.
1942 * Returns: (transfer none): the horizontal adjustment of @palette
1946 * Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
1949 gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
1951 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1953 return palette->priv->hadjustment;
1957 gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
1958 GtkAdjustment *adjustment)
1960 GtkToolPalettePrivate *priv = palette->priv;
1962 if (adjustment && priv->hadjustment == adjustment)
1965 if (priv->hadjustment != NULL)
1967 g_signal_handlers_disconnect_by_func (priv->hadjustment,
1968 gtk_tool_palette_adjustment_value_changed,
1970 g_object_unref (priv->hadjustment);
1973 if (adjustment == NULL)
1974 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
1977 g_signal_connect (adjustment, "value-changed",
1978 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
1980 priv->hadjustment = g_object_ref_sink (adjustment);
1981 /* FIXME: Adjustment should probably have it's values updated now */
1982 g_object_notify (G_OBJECT (palette), "hadjustment");
1986 * gtk_tool_palette_get_vadjustment:
1987 * @palette: a #GtkToolPalette
1989 * Gets the vertical adjustment of the tool palette.
1991 * Returns: (transfer none): the vertical adjustment of @palette
1995 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
1998 gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
2000 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
2002 return palette->priv->vadjustment;
2006 gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
2007 GtkAdjustment *adjustment)
2009 GtkToolPalettePrivate *priv = palette->priv;
2011 if (adjustment && priv->vadjustment == adjustment)
2014 if (priv->vadjustment != NULL)
2016 g_signal_handlers_disconnect_by_func (priv->vadjustment,
2017 gtk_tool_palette_adjustment_value_changed,
2019 g_object_unref (priv->vadjustment);
2022 if (adjustment == NULL)
2023 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2026 g_signal_connect (adjustment, "value-changed",
2027 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
2029 priv->vadjustment = g_object_ref_sink (adjustment);
2030 /* FIXME: Adjustment should probably have it's values updated now */
2031 g_object_notify (G_OBJECT (palette), "vadjustment");
2035 _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
2037 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
2039 return palette->priv->text_size_group;