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
22 #include "gtktoolpaletteprivate.h"
23 #include "gtkmarshalers.h"
28 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
29 #define DEFAULT_ORIENTATION GTK_ORIENTATION_VERTICAL
30 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_ICONS
32 #define DEFAULT_CHILD_EXCLUSIVE FALSE
33 #define DEFAULT_CHILD_EXPAND FALSE
35 #define P_(msgid) (msgid)
38 * SECTION:GtkToolPalette
39 * @short_description: A tool palette with categories
40 * @include: gtktoolpalette.h
42 * An #GtkToolPalette allows it to add #GtkToolItem<!-- -->s to a palette like container
43 * with different categories and drag and drop support.
45 * An #GtkToolPalette is created with a call to gtk_tool_palette_new().
47 * #GtkToolItem<!-- -->s cannot be added directly to an #GtkToolPalette, instead they
48 * are added to an #GtkToolItemGroup which can than be added to an #GtkToolPalette. To add
49 * an #GtkToolItemGroup to an #GtkToolPalette use gtk_container_add().
52 * GtkWidget *palette, *group;
55 * palette = gtk_tool_palette_new ();
56 * group = gtk_tool_item_group_new (_("Test Category"));
57 * gtk_container_add (GTK_CONTAINER (palette), group);
59 * item = gtk_tool_button_new_from_stock (GTK_STOCK_OK);
60 * gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
63 * The easiest way to use drag and drop with GtkToolPalette is to call gtk_tool_palette_add_drag_dest()
64 * with the desired drag source @palette and the desired drag target @widget. Than gtk_tool_palette_get_drag_item()
65 * can be used to get the dragged item in the #GtkWidget::drag-data-received signal handler of the drag target.
69 * passive_canvas_drag_data_received (GtkWidget *widget,
70 * GdkDragContext *context,
73 * GtkSelectionData *selection,
81 * /<!-- -->* Get the dragged item *<!-- -->/
82 * palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context), GTK_TYPE_TOOL_PALETTE);
83 * if (palette != NULL)
84 * item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette), selection);
86 * /<!-- -->* Do something with item *<!-- -->/
89 * GtkWidget *target, palette;
91 * palette = gtk_tool_palette_new ();
92 * target = gtk_drawing_area_new ();
94 * g_signal_connect (G_OBJECT (target), "drag-data-received",
95 * G_CALLBACK (passive_canvas_drag_data_received), NULL);
96 * gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target,
97 * GTK_DEST_DEFAULT_ALL,
98 * GTK_TOOL_PALETTE_DRAG_ITEMS,
105 typedef struct _GtkToolItemGroupInfo GtkToolItemGroupInfo;
106 typedef struct _GtkToolPaletteDragData GtkToolPaletteDragData;
120 CHILD_PROP_EXCLUSIVE,
124 struct _GtkToolItemGroupInfo
126 GtkToolItemGroup *widget;
128 guint notify_collapsed;
134 struct _GtkToolPalettePrivate
138 GtkAdjustment *hadjustment;
139 GtkAdjustment *vadjustment;
141 GtkIconSize icon_size;
142 gboolean icon_size_set;
143 GtkOrientation orientation;
144 GtkToolbarStyle style;
147 GtkWidget *expanding_child;
149 GtkSizeGroup *text_size_group;
151 GtkSettings *settings;
152 gulong settings_connection;
154 guint drag_source : 2;
157 struct _GtkToolPaletteDragData
159 GtkToolPalette *palette;
163 static GdkAtom dnd_target_atom_item = GDK_NONE;
164 static GdkAtom dnd_target_atom_group = GDK_NONE;
166 static const GtkTargetEntry dnd_targets[] =
168 { "application/x-gtk-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
169 { "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
172 G_DEFINE_TYPE_WITH_CODE (GtkToolPalette,
175 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
178 gtk_tool_palette_init (GtkToolPalette *palette)
180 palette->priv = G_TYPE_INSTANCE_GET_PRIVATE (palette,
181 GTK_TYPE_TOOL_PALETTE,
182 GtkToolPalettePrivate);
184 palette->priv->groups = g_ptr_array_sized_new(4);
185 g_ptr_array_set_free_func (palette->priv->groups, g_free);
187 palette->priv->icon_size = DEFAULT_ICON_SIZE;
188 palette->priv->icon_size_set = FALSE;
189 palette->priv->orientation = DEFAULT_ORIENTATION;
190 palette->priv->style = DEFAULT_TOOLBAR_STYLE;
191 palette->priv->style_set = FALSE;
193 palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
197 gtk_tool_palette_reconfigured (GtkToolPalette *palette)
201 for (i = 0; i < palette->priv->groups->len; ++i)
203 GtkToolItemGroupInfo *info = g_ptr_array_index(palette->priv->groups, i);
205 _gtk_tool_item_group_palette_reconfigured (info->widget);
208 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
212 gtk_tool_palette_set_property (GObject *object,
217 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
222 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
224 palette->priv->icon_size = g_value_get_enum (value);
225 gtk_tool_palette_reconfigured (palette);
229 case PROP_ICON_SIZE_SET:
230 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
232 palette->priv->icon_size_set = g_value_get_enum (value);
233 gtk_tool_palette_reconfigured (palette);
237 case PROP_ORIENTATION:
238 if ((guint) g_value_get_enum (value) != palette->priv->orientation)
240 palette->priv->orientation = g_value_get_enum (value);
241 gtk_tool_palette_reconfigured (palette);
245 case PROP_TOOLBAR_STYLE:
246 if ((guint) g_value_get_enum (value) != palette->priv->style)
248 palette->priv->style = g_value_get_enum (value);
249 gtk_tool_palette_reconfigured (palette);
254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
260 gtk_tool_palette_get_property (GObject *object,
265 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
270 g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
273 case PROP_ICON_SIZE_SET:
274 g_value_set_boolean (value, palette->priv->icon_size_set);
277 case PROP_ORIENTATION:
278 g_value_set_enum (value, palette->priv->orientation);
281 case PROP_TOOLBAR_STYLE:
282 g_value_set_enum (value, gtk_tool_palette_get_style (palette));
286 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
292 gtk_tool_palette_dispose (GObject *object)
294 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
297 if (palette->priv->hadjustment)
299 g_object_unref (palette->priv->hadjustment);
300 palette->priv->hadjustment = NULL;
303 if (palette->priv->vadjustment)
305 g_object_unref (palette->priv->vadjustment);
306 palette->priv->vadjustment = NULL;
309 for (i = 0; i < palette->priv->groups->len; ++i)
311 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
313 if (group->notify_collapsed)
315 g_signal_handler_disconnect (group->widget, group->notify_collapsed);
316 group->notify_collapsed = 0;
320 if (palette->priv->text_size_group)
322 g_object_unref (palette->priv->text_size_group);
323 palette->priv->text_size_group = NULL;
326 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
330 gtk_tool_palette_finalize (GObject *object)
332 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
334 g_ptr_array_free(palette->priv->groups, TRUE);
336 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
340 gtk_tool_palette_size_request (GtkWidget *widget,
341 GtkRequisition *requisition)
343 const gint border_width = GTK_CONTAINER (widget)->border_width;
344 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
345 GtkRequisition child_requisition;
348 requisition->width = 0;
349 requisition->height = 0;
351 for (i = 0; i < palette->priv->groups->len; ++i)
353 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
358 gtk_widget_size_request (GTK_WIDGET (group->widget), &child_requisition);
360 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
362 requisition->width = MAX (requisition->width, child_requisition.width);
363 requisition->height += child_requisition.height;
367 requisition->width += child_requisition.width;
368 requisition->height = MAX (requisition->height, child_requisition.height);
372 requisition->width += border_width * 2;
373 requisition->height += border_width * 2;
377 gtk_tool_palette_size_allocate (GtkWidget *widget,
378 GtkAllocation *allocation)
380 const gint border_width = GTK_CONTAINER (widget)->border_width;
381 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
382 GtkAdjustment *adjustment = NULL;
383 GtkAllocation child_allocation;
385 gint n_expand_groups = 0;
386 gint remaining_space = 0;
387 gint expand_space = 0;
389 gint page_start, page_size = 0;
393 gint min_offset = -1, max_offset = -1;
397 gint *group_sizes = g_newa(gint, palette->priv->groups->len);
399 GtkTextDirection direction = gtk_widget_get_direction (widget);
401 GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
403 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
405 adjustment = palette->priv->vadjustment;
406 page_size = allocation->height;
410 adjustment = palette->priv->hadjustment;
411 page_size = allocation->width;
415 offset = gtk_adjustment_get_value (adjustment);
416 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
417 GTK_TEXT_DIR_RTL == direction)
420 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
421 child_allocation.width = allocation->width - border_width * 2;
423 child_allocation.height = allocation->height - border_width * 2;
425 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
426 remaining_space = allocation->height;
428 remaining_space = allocation->width;
430 /* figure out the required size of all groups to be able to distribute the
431 * remaining space on allocation */
432 for (i = 0; i < palette->priv->groups->len; ++i)
434 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
440 widget = GTK_WIDGET (group->widget);
442 if (gtk_tool_item_group_get_n_items (group->widget))
444 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
445 size = _gtk_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
447 size = _gtk_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
449 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
450 n_expand_groups += 1;
455 remaining_space -= size;
456 group_sizes[i] = size;
458 /* if the widget is currently expanding an offset which allows to display as much of the
459 * widget as possible is calculated */
460 if (widget == palette->priv->expanding_child)
463 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
464 child_allocation.width : child_allocation.height;
471 for (j = 0; j < i; ++j)
472 min_offset += group_sizes[j];
474 max_offset = min_offset + group_sizes[i];
476 real_size = _gtk_tool_item_group_get_size_for_limit
477 (GTK_TOOL_ITEM_GROUP (widget), limit,
478 GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
481 if (size == real_size)
482 palette->priv->expanding_child = NULL;
486 if (n_expand_groups > 0)
488 remaining_space = MAX (0, remaining_space);
489 expand_space = remaining_space / n_expand_groups;
492 if (max_offset != -1)
495 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
496 allocation->height : allocation->width;
498 offset = MIN (MAX (offset, max_offset - limit), min_offset);
501 if (remaining_space > 0)
505 child_allocation.y = border_width;
507 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
508 child_allocation.y -= offset;
512 /* allocate all groups at the calculated positions */
513 for (i = 0; i < palette->priv->groups->len; ++i)
515 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
521 widget = GTK_WIDGET (group->widget);
523 if (gtk_tool_item_group_get_n_items (group->widget))
525 gint size = group_sizes[i];
527 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
529 size += MIN (expand_space, remaining_space);
530 remaining_space -= expand_space;
533 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
534 child_allocation.height = size;
536 child_allocation.width = size;
538 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
539 GTK_TEXT_DIR_RTL == direction)
540 child_allocation.x = allocation->width - x - child_allocation.width;
542 child_allocation.x = x;
544 gtk_widget_size_allocate (widget, &child_allocation);
545 gtk_widget_show (widget);
547 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
548 child_allocation.y += child_allocation.height;
550 x += child_allocation.width;
553 gtk_widget_hide (widget);
556 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
558 child_allocation.y += border_width;
559 child_allocation.y += offset;
561 page_start = child_allocation.y;
571 /* update the scrollbar to match the displayed adjustment */
576 adjustment->page_increment = page_size * 0.9;
577 adjustment->step_increment = page_size * 0.1;
578 adjustment->page_size = page_size;
580 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
581 GTK_TEXT_DIR_LTR == direction)
583 adjustment->lower = 0;
584 adjustment->upper = MAX (0, page_start);
586 value = MIN (offset, adjustment->upper - adjustment->page_size);
587 gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
591 adjustment->lower = page_size - MAX (0, page_start);
592 adjustment->upper = page_size;
596 value = MAX (offset, adjustment->lower);
597 gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
600 gtk_adjustment_changed (adjustment);
605 gtk_tool_palette_expose_event (GtkWidget *widget,
606 GdkEventExpose *event)
608 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
613 display = gdk_drawable_get_display (widget->window);
615 if (!gdk_display_supports_composite (display))
618 cr = gdk_cairo_create (widget->window);
619 gdk_cairo_region (cr, event->region);
622 cairo_push_group (cr);
624 for (i = 0; i < palette->priv->groups->len; ++i)
626 GtkToolItemGroupInfo *info = g_ptr_array_index(palette->priv->groups, i);
628 _gtk_tool_item_group_paint (info->widget, cr);
631 cairo_pop_group_to_source (cr);
640 gtk_tool_palette_realize (GtkWidget *widget)
642 const gint border_width = GTK_CONTAINER (widget)->border_width;
643 gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
644 GdkWindowAttr attributes;
646 attributes.window_type = GDK_WINDOW_CHILD;
647 attributes.x = widget->allocation.x + border_width;
648 attributes.y = widget->allocation.y + border_width;
649 attributes.width = widget->allocation.width - border_width * 2;
650 attributes.height = widget->allocation.height - border_width * 2;
651 attributes.wclass = GDK_INPUT_OUTPUT;
652 attributes.visual = gtk_widget_get_visual (widget);
653 attributes.colormap = gtk_widget_get_colormap (widget);
654 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
655 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
656 | GDK_BUTTON_MOTION_MASK;
658 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
659 &attributes, attributes_mask);
661 gdk_window_set_user_data (widget->window, widget);
662 widget->style = gtk_style_attach (widget->style, widget->window);
663 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
664 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
666 gtk_container_forall (GTK_CONTAINER (widget),
667 (GtkCallback) gtk_widget_set_parent_window,
670 gtk_widget_queue_resize_no_redraw (widget);
674 gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
677 GtkWidget *widget = GTK_WIDGET (data);
678 gtk_tool_palette_size_allocate (widget, &widget->allocation);
682 gtk_tool_palette_set_scroll_adjustments (GtkWidget *widget,
683 GtkAdjustment *hadjustment,
684 GtkAdjustment *vadjustment)
686 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
689 g_object_ref_sink (hadjustment);
691 g_object_ref_sink (vadjustment);
693 if (palette->priv->hadjustment)
694 g_object_unref (palette->priv->hadjustment);
695 if (palette->priv->vadjustment)
696 g_object_unref (palette->priv->vadjustment);
698 palette->priv->hadjustment = hadjustment;
699 palette->priv->vadjustment = vadjustment;
701 if (palette->priv->hadjustment)
702 g_signal_connect (palette->priv->hadjustment, "value-changed",
703 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
705 if (palette->priv->vadjustment)
706 g_signal_connect (palette->priv->vadjustment, "value-changed",
707 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
712 gtk_tool_palette_add (GtkContainer *container,
715 GtkToolPalette *palette;
716 GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
718 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
719 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
721 palette = GTK_TOOL_PALETTE (container);
723 g_ptr_array_add (palette->priv->groups, info);
724 info->pos = palette->priv->groups->len - 1;
725 info->widget = g_object_ref_sink (child);
727 gtk_widget_set_parent (child, GTK_WIDGET (palette));
731 gtk_tool_palette_remove (GtkContainer *container,
734 GtkToolPalette *palette;
737 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
738 palette = GTK_TOOL_PALETTE (container);
740 for (i = 0; i < palette->priv->groups->len; ++i)
742 GtkToolItemGroupInfo *info = g_ptr_array_index(palette->priv->groups, i);
743 if (GTK_WIDGET(info->widget) == child)
745 g_object_unref (child);
746 gtk_widget_unparent (child);
748 g_ptr_array_remove_index (palette->priv->groups, i);
754 gtk_tool_palette_forall (GtkContainer *container,
756 GtkCallback callback,
757 gpointer callback_data)
759 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
763 for (i = 0; i < palette->priv->groups->len; ++i)
765 GtkToolItemGroupInfo *info = g_ptr_array_index(palette->priv->groups, i);
767 callback (GTK_WIDGET (info->widget),
773 gtk_tool_palette_child_type (GtkContainer *container)
775 return GTK_TYPE_TOOL_ITEM_GROUP;
779 gtk_tool_palette_set_child_property (GtkContainer *container,
785 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
789 case CHILD_PROP_EXCLUSIVE:
790 gtk_tool_palette_set_exclusive (palette, child, g_value_get_boolean (value));
793 case CHILD_PROP_EXPAND:
794 gtk_tool_palette_set_expand (palette, child, g_value_get_boolean (value));
798 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
804 gtk_tool_palette_get_child_property (GtkContainer *container,
810 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
814 case CHILD_PROP_EXCLUSIVE:
815 g_value_set_boolean (value, gtk_tool_palette_get_exclusive (palette, child));
818 case CHILD_PROP_EXPAND:
819 g_value_set_boolean (value, gtk_tool_palette_get_expand (palette, child));
823 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
829 style_change_notify (GtkToolPalette *palette)
831 GtkToolPalettePrivate* priv = palette->priv;
833 if (!priv->style_set)
835 /* pretend it was set, then unset, thus reverting to new default */
836 priv->style_set = TRUE;
837 gtk_tool_palette_unset_style (palette);
842 icon_size_change_notify (GtkToolPalette *palette)
844 GtkToolPalettePrivate* priv = palette->priv;
846 if (!priv->icon_size_set)
848 /* pretend it was set, then unset, thus reverting to new default */
849 priv->icon_size_set = TRUE;
850 gtk_tool_palette_unset_icon_size (palette);
855 gtk_tool_palette_settings_change_notify (GtkSettings *settings,
856 const GParamSpec *pspec,
857 GtkToolPalette *palette)
859 if (! strcmp (pspec->name, "gtk-toolbar-style"))
860 style_change_notify (palette);
861 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
862 icon_size_change_notify (palette);
866 gtk_tool_palette_screen_changed (GtkWidget *widget,
867 GdkScreen *previous_screen)
869 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
870 GtkToolPalettePrivate* priv = palette->priv;
871 GtkSettings *old_settings = priv->settings;
872 GtkSettings *settings;
874 if (gtk_widget_has_screen (GTK_WIDGET (palette)))
875 settings = gtk_widget_get_settings (GTK_WIDGET (palette));
879 if (settings == old_settings)
884 g_signal_handler_disconnect (old_settings, priv->settings_connection);
885 g_object_unref (old_settings);
890 priv->settings_connection =
891 g_signal_connect (settings, "notify",
892 G_CALLBACK (gtk_tool_palette_settings_change_notify),
894 priv->settings = g_object_ref (settings);
897 priv->settings = NULL;
899 gtk_tool_palette_reconfigured (palette);
904 gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
906 GObjectClass *oclass = G_OBJECT_CLASS (cls);
907 GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
908 GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
910 oclass->set_property = gtk_tool_palette_set_property;
911 oclass->get_property = gtk_tool_palette_get_property;
912 oclass->dispose = gtk_tool_palette_dispose;
913 oclass->finalize = gtk_tool_palette_finalize;
915 wclass->size_request = gtk_tool_palette_size_request;
916 wclass->size_allocate = gtk_tool_palette_size_allocate;
917 wclass->expose_event = gtk_tool_palette_expose_event;
918 wclass->realize = gtk_tool_palette_realize;
920 cclass->add = gtk_tool_palette_add;
921 cclass->remove = gtk_tool_palette_remove;
922 cclass->forall = gtk_tool_palette_forall;
923 cclass->child_type = gtk_tool_palette_child_type;
924 cclass->set_child_property = gtk_tool_palette_set_child_property;
925 cclass->get_child_property = gtk_tool_palette_get_child_property;
927 cls->set_scroll_adjustments = gtk_tool_palette_set_scroll_adjustments;
929 /* Handle screen-changed so we can update our GtkSettings.
931 wclass->screen_changed = gtk_tool_palette_screen_changed;
934 * GtkToolPalette::set-scroll-adjustments:
935 * @widget: the GtkToolPalette that received the signal
936 * @hadjustment: The horizontal adjustment
937 * @vadjustment: The vertical adjustment
939 * Set the scroll adjustments for the viewport.
940 * Usually scrolled containers like GtkScrolledWindow will emit this signal to
941 * connect two instances of GtkScrollbar to the scroll directions of the GtkToolpalette.
945 wclass->set_scroll_adjustments_signal =
946 g_signal_new ("set-scroll-adjustments",
947 G_TYPE_FROM_CLASS (oclass),
948 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
949 G_STRUCT_OFFSET (GtkToolPaletteClass, set_scroll_adjustments),
951 _gtk_marshal_VOID__OBJECT_OBJECT,
954 GTK_TYPE_ADJUSTMENT);
956 g_object_class_override_property (oclass, PROP_ORIENTATION,
960 * GtkToolPalette:icon-size:
962 * The size of the icons in a tool palette is normally determined by
963 * the toolbar-icon-size setting. When this property is set, it
964 * overrides the setting.
966 * This should only be used for special-purpose toolbars, normal
967 * application toolbars should respect the user preferences for the
972 g_object_class_install_property (oclass,
974 g_param_spec_enum ("icon-size",
976 P_("Size of icons in this tool palette"),
979 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
980 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
983 * GtkToolbar:icon-size-set:
985 * Is %TRUE if the icon-size property has been set.
989 g_object_class_install_property (oclass,
991 g_param_spec_boolean ("icon-size-set",
993 P_("Whether the icon-size property has been set"),
995 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
996 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
998 g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
999 g_param_spec_enum ("toolbar-style",
1000 P_("Toolbar Style"),
1001 P_("Style of items in the tool palette"),
1002 GTK_TYPE_TOOLBAR_STYLE,
1003 DEFAULT_TOOLBAR_STYLE,
1004 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1005 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1008 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
1009 g_param_spec_boolean ("exclusive",
1011 P_("Whether the item group should be the only expanded at a given time"),
1012 DEFAULT_CHILD_EXCLUSIVE,
1013 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1014 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1016 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1017 g_param_spec_boolean ("expand",
1019 P_("Whether the item group should receive extra space when the palette grows"),
1020 DEFAULT_CHILD_EXPAND,
1021 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1022 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1024 g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
1026 dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
1027 dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
1031 * gtk_tool_palette_new:
1033 * Creates a new tool palette.
1035 * Returns: a new #GtkToolPalette.
1040 gtk_tool_palette_new (void)
1042 return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
1046 * gtk_tool_palette_set_icon_size:
1047 * @palette: an #GtkToolPalette.
1048 * @icon_size: the #GtkIconSize that icons in the tool palette shall have.
1050 * Sets the size of icons in the tool palette.
1055 gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
1056 GtkIconSize icon_size)
1058 GtkToolPalettePrivate *priv;
1060 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1061 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
1063 priv = palette->priv;
1065 if (!priv->icon_size_set)
1067 priv->icon_size_set = TRUE;
1068 g_object_notify (G_OBJECT (palette), "icon-size-set");
1071 if (priv->icon_size == icon_size)
1074 priv->icon_size = icon_size;
1075 g_object_notify (G_OBJECT (palette), "icon-size");
1077 gtk_tool_palette_reconfigured (palette);
1079 gtk_widget_queue_resize (GTK_WIDGET (palette));
1082 static GtkSettings *
1083 toolpalette_get_settings (GtkToolPalette *palette)
1085 GtkToolPalettePrivate *priv = palette->priv;
1086 return priv->settings;
1090 * gtk_tool_palette_unset_icon_size:
1091 * @palette: an #GtkToolPalette.
1093 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(), so that
1094 * user preferences will be used to determine the icon size.
1099 gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
1101 GtkToolPalettePrivate* priv = palette->priv;
1104 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1106 if (palette->priv->icon_size_set)
1108 GtkSettings *settings = toolpalette_get_settings (palette);
1112 g_object_get (settings,
1113 "gtk-toolbar-icon-size", &size,
1117 size = DEFAULT_ICON_SIZE;
1119 if (size != palette->priv->icon_size)
1121 gtk_tool_palette_set_icon_size (palette, size);
1122 g_object_notify (G_OBJECT (palette), "icon-size");
1125 priv->icon_size_set = FALSE;
1126 g_object_notify (G_OBJECT (palette), "icon-size-set");
1130 /* Set the "toolbar-style" property and do appropriate things.
1131 * GtkToolbar does this by emiting a signal instead of just calling a function,
1132 * but I don't see how that is useful. murrayc.
1135 gtk_tool_palette_change_style (GtkToolPalette *palette,
1136 GtkToolbarStyle style)
1138 GtkToolPalettePrivate* priv = palette->priv;
1140 if (priv->style != style)
1142 priv->style = style;
1144 gtk_tool_palette_reconfigured (palette);
1146 gtk_widget_queue_resize (GTK_WIDGET (palette));
1147 g_object_notify (G_OBJECT (palette), "toolbar-style");
1153 * gtk_tool_palette_set_style:
1154 * @palette: a #GtkToolPalette.
1155 * @style: the #GtkToolbarStyle that items in the tool palette shall have.
1157 * Sets the style (text, icons or both) of items in the tool palette.
1162 gtk_tool_palette_set_style (GtkToolPalette *palette,
1163 GtkToolbarStyle style)
1165 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1167 palette->priv->style_set = TRUE;
1168 gtk_tool_palette_change_style (palette, style);
1173 * gtk_tool_palette_unset_style:
1174 * @palette: a #GtkToolPalette.
1176 * Unsets a toolbar style set with gtk_tool_palette_set_style(), so that
1177 * user preferences will be used to determine the toolbar style.
1180 gtk_tool_palette_unset_style (GtkToolPalette *palette)
1182 GtkToolPalettePrivate* priv = palette->priv;
1183 GtkToolbarStyle style;
1185 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1187 if (priv->style_set)
1189 GtkSettings *settings = toolpalette_get_settings (palette);
1192 g_object_get (settings,
1193 "gtk-toolbar-style", &style,
1196 style = DEFAULT_TOOLBAR_STYLE;
1198 if (style != priv->style)
1199 gtk_tool_palette_change_style (palette, style);
1201 priv->style_set = FALSE;
1206 * gtk_tool_palette_get_icon_size:
1207 * @palette: an #GtkToolPalette.
1209 * Gets the size of icons in the tool palette. See gtk_tool_palette_set_icon_size().
1211 * Returns: the #GtkIconSize of icons in the tool palette.
1216 gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
1218 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
1219 return palette->priv->icon_size;
1223 * gtk_tool_palette_get_style:
1224 * @palette: an #GtkToolPalette.
1226 * Gets the style (icons, text or both) of items in the tool palette.
1228 * Returns: the #GtkToolbarStyle of items in the tool palette.
1233 gtk_tool_palette_get_style (GtkToolPalette *palette)
1235 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
1236 return palette->priv->style;
1240 _gtk_tool_palette_compare_groups (gconstpointer a,
1243 const GtkToolItemGroupInfo *group_a = a;
1244 const GtkToolItemGroupInfo *group_b = b;
1246 return group_a->pos - group_b->pos;
1251 * gtk_tool_palette_set_group_position:
1252 * @palette: an #GtkToolPalette.
1253 * @group: an #GtkToolItemGroup which is a child of palette.
1254 * @position: a new index for group.
1256 * Sets the position of the group as an index of the tool palette.
1257 * If position is 0 the group will become the first child, if position is
1258 * -1 it will become the last child.
1263 gtk_tool_palette_set_group_position (GtkToolPalette *palette,
1267 GtkToolItemGroupInfo *group_new;
1268 GtkToolItemGroupInfo *group_old;
1271 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1272 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1274 g_return_if_fail (position >= -1);
1277 position = palette->priv->groups->len - 1;
1279 g_return_if_fail ((guint) position < palette->priv->groups->len);
1281 group_new = g_ptr_array_index(palette->priv->groups, position);
1283 if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
1286 old_position = gtk_tool_palette_get_group_position (palette, group);
1287 g_return_if_fail (old_position >= 0);
1289 group_old = g_ptr_array_index(palette->priv->groups, old_position);
1291 group_new->pos = position;
1292 group_old->pos = old_position;
1294 g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups);
1296 gtk_widget_queue_resize (GTK_WIDGET (palette));
1300 gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
1304 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1307 if (gtk_tool_item_group_get_collapsed (group))
1310 for (i = 0; i < palette->priv->groups->len; ++i)
1312 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1313 GtkToolItemGroup *current_group = info->widget;
1315 if (current_group && current_group != group)
1316 gtk_tool_item_group_set_collapsed (current_group, TRUE);
1321 * gtk_tool_palette_set_exclusive:
1322 * @palette: an #GtkToolPalette.
1323 * @group: an #GtkToolItemGroup which is a child of palette.
1324 * @exclusive: whether the group should be exclusive or not.
1326 * Sets whether the group should be exclusive or not. If an exclusive group is expanded
1327 * all other groups are collapsed.
1332 gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
1336 GtkToolItemGroupInfo *group_info;
1339 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1340 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1342 position = gtk_tool_palette_get_group_position (palette, group);
1343 g_return_if_fail (position >= 0);
1345 group_info = g_ptr_array_index (palette->priv->groups, position);
1347 if (exclusive == group_info->exclusive)
1350 group_info->exclusive = exclusive;
1352 if (group_info->exclusive != (0 != group_info->notify_collapsed))
1354 if (group_info->exclusive)
1356 group_info->notify_collapsed =
1357 g_signal_connect (group, "notify::collapsed",
1358 G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
1363 g_signal_handler_disconnect (group, group_info->notify_collapsed);
1364 group_info->notify_collapsed = 0;
1368 gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
1369 gtk_widget_child_notify (group, "exclusive");
1373 * gtk_tool_palette_set_expand:
1374 * @palette: an #GtkToolPalette.
1375 * @group: an #GtkToolItemGroup which is a child of palette.
1376 * @expand: whether the group should be given extra space.
1378 * Sets whether the group should be given extra space.
1383 gtk_tool_palette_set_expand (GtkToolPalette *palette,
1387 GtkToolItemGroupInfo *group_info;
1390 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1391 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1393 position = gtk_tool_palette_get_group_position (palette, group);
1394 g_return_if_fail (position >= 0);
1396 group_info = g_ptr_array_index (palette->priv->groups, position);
1398 if (expand != group_info->expand)
1400 group_info->expand = expand;
1401 gtk_widget_queue_resize (GTK_WIDGET (palette));
1402 gtk_widget_child_notify (group, "expand");
1407 * gtk_tool_palette_get_group_position:
1408 * @palette: an #GtkToolPalette.
1409 * @group: an #GtkToolItemGroup.
1411 * Gets the position of @group in @palette as index. see gtk_tool_palette_set_group_position().
1413 * Returns: the index of group or -1 if @group is not a child of @palette.
1418 gtk_tool_palette_get_group_position (GtkToolPalette *palette,
1423 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
1424 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
1426 for (i = 0; i < palette->priv->groups->len; ++i)
1428 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1429 if ((gpointer) group == info->widget)
1437 * gtk_tool_palette_get_exclusive:
1438 * @palette: an #GtkToolPalette.
1439 * @group: an #GtkToolItemGroup which is a child of palette.
1441 * Gets whether group is exclusive or not. See gtk_tool_palette_set_exclusive().
1443 * Returns: %TRUE if group is exclusive.
1448 gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
1452 GtkToolItemGroupInfo *info;
1454 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
1455 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
1457 position = gtk_tool_palette_get_group_position (palette, group);
1458 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
1460 info = g_ptr_array_index (palette->priv->groups, position);
1462 return info->exclusive;
1466 * gtk_tool_palette_get_expand:
1467 * @palette: an #GtkToolPalette.
1468 * @group: an #GtkToolItemGroup which is a child of palette.
1470 * Gets whether group should be given extra space. See gtk_tool_palette_set_expand().
1472 * Returns: %TRUE if group should be given extra space, %FALSE otherwise.
1477 gtk_tool_palette_get_expand (GtkToolPalette *palette,
1481 GtkToolItemGroupInfo *info;
1483 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
1484 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
1486 position = gtk_tool_palette_get_group_position (palette, group);
1487 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
1489 info = g_ptr_array_index (palette->priv->groups, position);
1491 return info->expand;
1495 * gtk_tool_palette_get_drop_item:
1496 * @palette: an #GtkToolPalette.
1497 * @x: the x position.
1498 * @y: the y position.
1500 * Gets the item at position (x, y). See gtk_tool_palette_get_drop_group().
1502 * Returns: the #GtkToolItem at position or %NULL if there is no such item.
1507 gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
1511 GtkWidget *group = gtk_tool_palette_get_drop_group (palette, x, y);
1514 return gtk_tool_item_group_get_drop_item (GTK_TOOL_ITEM_GROUP (group),
1515 x - group->allocation.x,
1516 y - group->allocation.y);
1522 * gtk_tool_palette_get_drop_group:
1523 * @palette: an #GtkToolPalette.
1524 * @x: the x position.
1525 * @y: the y position.
1527 * Gets the group at position (x, y).
1529 * Returns: the #GtkToolItemGroup at position or %NULL if there is no such group.
1534 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
1538 GtkAllocation *allocation;
1541 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1543 allocation = >K_WIDGET (palette)->allocation;
1545 g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
1546 g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
1548 for (i = 0; i < palette->priv->groups->len; ++i)
1550 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
1557 widget = GTK_WIDGET (group->widget);
1559 x0 = x - widget->allocation.x;
1560 y0 = y - widget->allocation.y;
1562 if (x0 >= 0 && x0 < widget->allocation.width &&
1563 y0 >= 0 && y0 < widget->allocation.height)
1571 * gtk_tool_palette_get_drag_item:
1572 * @palette: an #GtkToolPalette.
1573 * @selection: a #GtkSelectionData.
1575 * Get the dragged item from the selection. This could be a #GtkToolItem or
1576 * an #GtkToolItemGroup.
1578 * Returns: the dragged item in selection.
1583 gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
1584 const GtkSelectionData *selection)
1586 GtkToolPaletteDragData *data;
1588 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1589 g_return_val_if_fail (NULL != selection, NULL);
1591 g_return_val_if_fail (selection->format == 8, NULL);
1592 g_return_val_if_fail (selection->length == sizeof (GtkToolPaletteDragData), NULL);
1593 g_return_val_if_fail (selection->target == dnd_target_atom_item ||
1594 selection->target == dnd_target_atom_group,
1597 data = (GtkToolPaletteDragData*) selection->data;
1599 g_return_val_if_fail (data->palette == palette, NULL);
1601 if (dnd_target_atom_item == selection->target)
1602 g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
1603 else if (dnd_target_atom_group == selection->target)
1604 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
1610 * gtk_tool_palette_set_drag_source:
1611 * @palette: an #GtkToolPalette.
1612 * @targets: the #GtkToolPaletteDragTargets which the widget should support.
1614 * Sets the tool palette as a drag source. Enables all groups and items in
1615 * the tool palette as drag sources on button 1 and button 3 press with copy
1618 * See gtk_drag_source_set().
1624 gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
1625 GtkToolPaletteDragTargets targets)
1629 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1631 if ((palette->priv->drag_source & targets) == targets)
1634 palette->priv->drag_source |= targets;
1636 for (i = 0; i < palette->priv->groups->len; ++i)
1638 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1640 gtk_container_forall (GTK_CONTAINER (info->widget),
1641 _gtk_tool_palette_child_set_drag_source,
1647 * gtk_tool_palette_add_drag_dest:
1648 * @palette: an #GtkToolPalette.
1649 * @widget: a #GtkWidget which should be a drag destination for palette.
1650 * @flags: the flags that specify what actions GTK+ should take for drops on that widget.
1651 * @targets: the #GtkToolPaletteDragTargets which the widget should support.
1652 * @actions: the #GdkDragAction<!-- -->s which the widget should suppport.
1654 * Sets the tool palette as drag source (see gtk_tool_palette_set_drag_source()) and
1655 * sets widget as a drag destination for drags from palette. With flags the actions
1656 * (like highlighting and target checking) which should be performed by GTK+ for
1657 * drops on widget can be specified. With targets the supported drag targets
1658 * (groups and/or items) can be specified. With actions the supported drag actions
1659 * (copy and move) can be specified.
1661 * See gtk_drag_dest_set().
1666 gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
1668 GtkDestDefaults flags,
1669 GtkToolPaletteDragTargets targets,
1670 GdkDragAction actions)
1672 GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
1675 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1676 g_return_if_fail (GTK_IS_WIDGET (widget));
1678 gtk_tool_palette_set_drag_source (palette,
1681 if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
1682 entries[n_entries++] = dnd_targets[0];
1683 if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
1684 entries[n_entries++] = dnd_targets[1];
1686 gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
1690 _gtk_tool_palette_get_item_size (GtkToolPalette *palette,
1691 GtkRequisition *item_size,
1692 gboolean homogeneous_only,
1693 gint *requested_rows)
1695 GtkRequisition max_requisition;
1699 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1700 g_return_if_fail (NULL != item_size);
1702 max_requisition.width = 0;
1703 max_requisition.height = 0;
1706 /* iterate over all groups and calculate the max item_size and max row request */
1707 for (i = 0; i < palette->priv->groups->len; ++i)
1709 GtkRequisition requisition;
1711 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
1716 _gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
1718 max_requisition.width = MAX (max_requisition.width, requisition.width);
1719 max_requisition.height = MAX (max_requisition.height, requisition.height);
1720 max_rows = MAX (max_rows, rows);
1723 *item_size = max_requisition;
1725 *requested_rows = max_rows;
1729 gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
1730 GdkDragContext *context,
1731 GtkSelectionData *selection,
1736 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1738 if (selection->target == dnd_target_atom_item)
1739 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
1742 gtk_selection_data_set (selection, selection->target, 8,
1743 (guchar*) &drag_data, sizeof (drag_data));
1747 gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
1748 GdkDragContext *context,
1749 GtkSelectionData *selection,
1754 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1756 if (selection->target == dnd_target_atom_group)
1757 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
1760 gtk_selection_data_set (selection, selection->target, 8,
1761 (guchar*) &drag_data, sizeof (drag_data));
1765 _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
1768 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1770 /* Check drag_source,
1771 * to work properly when called from gtk_tool_item_group_insert().
1773 if (!palette->priv->drag_source)
1776 if (GTK_IS_TOOL_ITEM (child) &&
1777 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
1779 /* Connect to child instead of the item itself,
1780 * to work arround bug 510377.
1782 if (GTK_IS_TOOL_BUTTON (child))
1783 child = gtk_bin_get_child (GTK_BIN (child));
1788 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1789 &dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1791 g_signal_connect (child, "drag-data-get",
1792 G_CALLBACK (gtk_tool_palette_item_drag_data_get),
1795 else if (GTK_IS_BUTTON (child) &&
1796 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
1798 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1799 &dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1801 g_signal_connect (child, "drag-data-get",
1802 G_CALLBACK (gtk_tool_palette_child_drag_data_get),
1808 * gtk_tool_palette_get_drag_target_item:
1810 * Get the target entry for a dragged #GtkToolItem.
1812 * Returns: the #GtkTargetEntry for a dragged item.
1816 G_CONST_RETURN GtkTargetEntry*
1817 gtk_tool_palette_get_drag_target_item (void)
1819 return &dnd_targets[0];
1823 * gtk_tool_palette_get_drag_target_group:
1825 * Get the target entry for a dragged #GtkToolItemGroup.
1827 * Returns: the #GtkTargetEntry for a dragged group.
1831 G_CONST_RETURN GtkTargetEntry*
1832 gtk_tool_palette_get_drag_target_group (void)
1834 return &dnd_targets[1];
1838 _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
1841 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1842 palette->priv->expanding_child = widget;
1846 gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
1848 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1849 return palette->priv->hadjustment;
1853 gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
1855 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1856 return palette->priv->vadjustment;
1860 _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
1862 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1864 return palette->priv->text_size_group;