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);
688 if (palette->priv->hadjustment)
689 g_object_unref (palette->priv->hadjustment);
690 if (palette->priv->vadjustment)
691 g_object_unref (palette->priv->vadjustment);
694 g_object_ref_sink (hadjustment);
696 g_object_ref_sink (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 * The ::set-scroll-adjustments when FIXME
943 wclass->set_scroll_adjustments_signal =
944 g_signal_new ("set-scroll-adjustments",
945 G_TYPE_FROM_CLASS (oclass),
946 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
947 G_STRUCT_OFFSET (GtkToolPaletteClass, set_scroll_adjustments),
949 _gtk_marshal_VOID__OBJECT_OBJECT,
952 GTK_TYPE_ADJUSTMENT);
954 g_object_class_override_property (oclass, PROP_ORIENTATION,
958 * GtkToolPalette:icon-size:
960 * The size of the icons in a tool palette is normally determined by
961 * the toolbar-icon-size setting. When this property is set, it
962 * overrides the setting.
964 * This should only be used for special-purpose toolbars, normal
965 * application toolbars should respect the user preferences for the
970 g_object_class_install_property (oclass,
972 g_param_spec_enum ("icon-size",
974 P_("Size of icons in this tool palette"),
977 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
978 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
981 * GtkToolbar:icon-size-set:
983 * Is %TRUE if the icon-size property has been set.
987 g_object_class_install_property (oclass,
989 g_param_spec_boolean ("icon-size-set",
991 P_("Whether the icon-size property has been set"),
993 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
994 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
996 g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
997 g_param_spec_enum ("toolbar-style",
999 P_("Style of items in the tool palette"),
1000 GTK_TYPE_TOOLBAR_STYLE,
1001 DEFAULT_TOOLBAR_STYLE,
1002 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1003 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1006 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
1007 g_param_spec_boolean ("exclusive",
1009 P_("Whether the item group should be the only expanded at a given time"),
1010 DEFAULT_CHILD_EXCLUSIVE,
1011 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1012 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1014 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1015 g_param_spec_boolean ("expand",
1017 P_("Whether the item group should receive extra space when the palette grows"),
1018 DEFAULT_CHILD_EXPAND,
1019 G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
1020 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1022 g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
1024 dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
1025 dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
1029 * gtk_tool_palette_new:
1031 * Creates a new tool palette.
1033 * Returns: a new #GtkToolPalette.
1038 gtk_tool_palette_new (void)
1040 return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
1044 * gtk_tool_palette_set_icon_size:
1045 * @palette: an #GtkToolPalette.
1046 * @icon_size: the #GtkIconSize that icons in the tool palette shall have.
1048 * Sets the size of icons in the tool palette.
1053 gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
1054 GtkIconSize icon_size)
1056 GtkToolPalettePrivate *priv;
1058 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1059 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
1061 priv = palette->priv;
1063 if (!priv->icon_size_set)
1065 priv->icon_size_set = TRUE;
1066 g_object_notify (G_OBJECT (palette), "icon-size-set");
1069 if (priv->icon_size == icon_size)
1072 priv->icon_size = icon_size;
1073 g_object_notify (G_OBJECT (palette), "icon-size");
1075 gtk_tool_palette_reconfigured (palette);
1077 gtk_widget_queue_resize (GTK_WIDGET (palette));
1080 static GtkSettings *
1081 toolpalette_get_settings (GtkToolPalette *palette)
1083 GtkToolPalettePrivate *priv = palette->priv;
1084 return priv->settings;
1088 * gtk_tool_palette_unset_icon_size:
1089 * @palette: an #GtkToolPalette.
1091 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(), so that
1092 * user preferences will be used to determine the icon size.
1097 gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
1099 GtkToolPalettePrivate* priv = palette->priv;
1102 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1104 if (palette->priv->icon_size_set)
1106 GtkSettings *settings = toolpalette_get_settings (palette);
1110 g_object_get (settings,
1111 "gtk-toolbar-icon-size", &size,
1115 size = DEFAULT_ICON_SIZE;
1117 if (size != palette->priv->icon_size)
1119 gtk_tool_palette_set_icon_size (palette, size);
1120 g_object_notify (G_OBJECT (palette), "icon-size");
1123 priv->icon_size_set = FALSE;
1124 g_object_notify (G_OBJECT (palette), "icon-size-set");
1128 /* Set the "toolbar-style" property and do appropriate things.
1129 * GtkToolbar does this by emiting a signal instead of just calling a function,
1130 * but I don't see how that is useful. murrayc.
1133 gtk_tool_palette_change_style (GtkToolPalette *palette,
1134 GtkToolbarStyle style)
1136 GtkToolPalettePrivate* priv = palette->priv;
1138 if (priv->style != style)
1140 priv->style = style;
1142 gtk_tool_palette_reconfigured (palette);
1144 gtk_widget_queue_resize (GTK_WIDGET (palette));
1145 g_object_notify (G_OBJECT (palette), "toolbar-style");
1151 * gtk_tool_palette_set_style:
1152 * @palette: a #GtkToolPalette.
1153 * @style: the #GtkToolbarStyle that items in the tool palette shall have.
1155 * Sets the style (text, icons or both) of items in the tool palette.
1160 gtk_tool_palette_set_style (GtkToolPalette *palette,
1161 GtkToolbarStyle style)
1163 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1165 palette->priv->style_set = TRUE;
1166 gtk_tool_palette_change_style (palette, style);
1171 * gtk_tool_palette_unset_style:
1172 * @palette: a #GtkToolPalette.
1174 * Unsets a toolbar style set with gtk_tool_palette_set_style(), so that
1175 * user preferences will be used to determine the toolbar style.
1178 gtk_tool_palette_unset_style (GtkToolPalette *palette)
1180 GtkToolPalettePrivate* priv = palette->priv;
1181 GtkToolbarStyle style;
1183 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1185 if (priv->style_set)
1187 GtkSettings *settings = toolpalette_get_settings (palette);
1190 g_object_get (settings,
1191 "gtk-toolbar-style", &style,
1194 style = DEFAULT_TOOLBAR_STYLE;
1196 if (style != priv->style)
1197 gtk_tool_palette_change_style (palette, style);
1199 priv->style_set = FALSE;
1204 * gtk_tool_palette_get_icon_size:
1205 * @palette: an #GtkToolPalette.
1207 * Gets the size of icons in the tool palette. See gtk_tool_palette_set_icon_size().
1209 * Returns: the #GtkIconSize of icons in the tool palette.
1214 gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
1216 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
1217 return palette->priv->icon_size;
1221 * gtk_tool_palette_get_style:
1222 * @palette: an #GtkToolPalette.
1224 * Gets the style (icons, text or both) of items in the tool palette.
1226 * Returns: the #GtkToolbarStyle of items in the tool palette.
1231 gtk_tool_palette_get_style (GtkToolPalette *palette)
1233 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
1234 return palette->priv->style;
1238 _gtk_tool_palette_compare_groups (gconstpointer a,
1241 const GtkToolItemGroupInfo *group_a = a;
1242 const GtkToolItemGroupInfo *group_b = b;
1244 return group_a->pos - group_b->pos;
1249 * gtk_tool_palette_set_group_position:
1250 * @palette: an #GtkToolPalette.
1251 * @group: an #GtkToolItemGroup which is a child of palette.
1252 * @position: a new index for group.
1254 * Sets the position of the group as an index of the tool palette.
1255 * If position is 0 the group will become the first child, if position is
1256 * -1 it will become the last child.
1261 gtk_tool_palette_set_group_position (GtkToolPalette *palette,
1265 GtkToolItemGroupInfo *group_new;
1266 GtkToolItemGroupInfo *group_old;
1269 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1270 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1272 g_return_if_fail (position >= -1);
1275 position = palette->priv->groups->len - 1;
1277 g_return_if_fail ((guint) position < palette->priv->groups->len);
1279 group_new = g_ptr_array_index(palette->priv->groups, position);
1281 if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
1284 old_position = gtk_tool_palette_get_group_position (palette, group);
1285 g_return_if_fail (old_position >= 0);
1287 group_old = g_ptr_array_index(palette->priv->groups, old_position);
1289 group_new->pos = position;
1290 group_old->pos = old_position;
1292 g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups);
1294 gtk_widget_queue_resize (GTK_WIDGET (palette));
1298 gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
1302 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1305 if (gtk_tool_item_group_get_collapsed (group))
1308 for (i = 0; i < palette->priv->groups->len; ++i)
1310 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1311 GtkToolItemGroup *current_group = info->widget;
1313 if (current_group && current_group != group)
1314 gtk_tool_item_group_set_collapsed (current_group, TRUE);
1319 * gtk_tool_palette_set_exclusive:
1320 * @palette: an #GtkToolPalette.
1321 * @group: an #GtkToolItemGroup which is a child of palette.
1322 * @exclusive: whether the group should be exclusive or not.
1324 * Sets whether the group should be exclusive or not. If an exclusive group is expanded
1325 * all other groups are collapsed.
1330 gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
1334 GtkToolItemGroupInfo *group_info;
1337 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1338 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1340 position = gtk_tool_palette_get_group_position (palette, group);
1341 g_return_if_fail (position >= 0);
1343 group_info = g_ptr_array_index (palette->priv->groups, position);
1345 if (exclusive == group_info->exclusive)
1348 group_info->exclusive = exclusive;
1350 if (group_info->exclusive != (0 != group_info->notify_collapsed))
1352 if (group_info->exclusive)
1354 group_info->notify_collapsed =
1355 g_signal_connect (group, "notify::collapsed",
1356 G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
1361 g_signal_handler_disconnect (group, group_info->notify_collapsed);
1362 group_info->notify_collapsed = 0;
1366 gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
1367 gtk_widget_child_notify (group, "exclusive");
1371 * gtk_tool_palette_set_expand:
1372 * @palette: an #GtkToolPalette.
1373 * @group: an #GtkToolItemGroup which is a child of palette.
1374 * @expand: whether the group should be given extra space.
1376 * Sets whether the group should be given extra space.
1381 gtk_tool_palette_set_expand (GtkToolPalette *palette,
1385 GtkToolItemGroupInfo *group_info;
1388 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1389 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1391 position = gtk_tool_palette_get_group_position (palette, group);
1392 g_return_if_fail (position >= 0);
1394 group_info = g_ptr_array_index (palette->priv->groups, position);
1396 if (expand != group_info->expand)
1398 group_info->expand = expand;
1399 gtk_widget_queue_resize (GTK_WIDGET (palette));
1400 gtk_widget_child_notify (group, "expand");
1405 * gtk_tool_palette_get_group_position:
1406 * @palette: an #GtkToolPalette.
1407 * @group: an #GtkToolItemGroup.
1409 * Gets the position of @group in @palette as index. see gtk_tool_palette_set_group_position().
1411 * Returns: the index of group or -1 if @group is not a child of @palette.
1416 gtk_tool_palette_get_group_position (GtkToolPalette *palette,
1421 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
1422 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
1424 for (i = 0; i < palette->priv->groups->len; ++i)
1426 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1427 if ((gpointer) group == info->widget)
1435 * gtk_tool_palette_get_exclusive:
1436 * @palette: an #GtkToolPalette.
1437 * @group: an #GtkToolItemGroup which is a child of palette.
1439 * Gets whether group is exclusive or not. See gtk_tool_palette_set_exclusive().
1441 * Returns: %TRUE if group is exclusive.
1446 gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
1450 GtkToolItemGroupInfo *info;
1452 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
1453 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
1455 position = gtk_tool_palette_get_group_position (palette, group);
1456 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
1458 info = g_ptr_array_index (palette->priv->groups, position);
1460 return info->exclusive;
1464 * gtk_tool_palette_get_expand:
1465 * @palette: an #GtkToolPalette.
1466 * @group: an #GtkToolItemGroup which is a child of palette.
1468 * Gets whether group should be given extra space. See gtk_tool_palette_set_expand().
1470 * Returns: %TRUE if group should be given extra space, %FALSE otherwise.
1475 gtk_tool_palette_get_expand (GtkToolPalette *palette,
1479 GtkToolItemGroupInfo *info;
1481 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
1482 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
1484 position = gtk_tool_palette_get_group_position (palette, group);
1485 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
1487 info = g_ptr_array_index (palette->priv->groups, position);
1489 return info->expand;
1493 * gtk_tool_palette_get_drop_item:
1494 * @palette: an #GtkToolPalette.
1495 * @x: the x position.
1496 * @y: the y position.
1498 * Gets the item at position (x, y). See gtk_tool_palette_get_drop_group().
1500 * Returns: the #GtkToolItem at position or %NULL if there is no such item.
1505 gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
1509 GtkWidget *group = gtk_tool_palette_get_drop_group (palette, x, y);
1512 return gtk_tool_item_group_get_drop_item (GTK_TOOL_ITEM_GROUP (group),
1513 x - group->allocation.x,
1514 y - group->allocation.y);
1520 * gtk_tool_palette_get_drop_group:
1521 * @palette: an #GtkToolPalette.
1522 * @x: the x position.
1523 * @y: the y position.
1525 * Gets the group at position (x, y).
1527 * Returns: the #GtkToolItemGroup at position or %NULL if there is no such group.
1532 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
1536 GtkAllocation *allocation;
1539 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1541 allocation = >K_WIDGET (palette)->allocation;
1543 g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
1544 g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
1546 for (i = 0; i < palette->priv->groups->len; ++i)
1548 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
1555 widget = GTK_WIDGET (group->widget);
1557 x0 = x - widget->allocation.x;
1558 y0 = y - widget->allocation.y;
1560 if (x0 >= 0 && x0 < widget->allocation.width &&
1561 y0 >= 0 && y0 < widget->allocation.height)
1569 * gtk_tool_palette_get_drag_item:
1570 * @palette: an #GtkToolPalette.
1571 * @selection: a #GtkSelectionData.
1573 * Get the dragged item from the selection. This could be a #GtkToolItem or
1574 * an #GtkToolItemGroup.
1576 * Returns: the dragged item in selection.
1581 gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
1582 const GtkSelectionData *selection)
1584 GtkToolPaletteDragData *data;
1586 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1587 g_return_val_if_fail (NULL != selection, NULL);
1589 g_return_val_if_fail (selection->format == 8, NULL);
1590 g_return_val_if_fail (selection->length == sizeof (GtkToolPaletteDragData), NULL);
1591 g_return_val_if_fail (selection->target == dnd_target_atom_item ||
1592 selection->target == dnd_target_atom_group,
1595 data = (GtkToolPaletteDragData*) selection->data;
1597 g_return_val_if_fail (data->palette == palette, NULL);
1599 if (dnd_target_atom_item == selection->target)
1600 g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
1601 else if (dnd_target_atom_group == selection->target)
1602 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
1608 * gtk_tool_palette_set_drag_source:
1609 * @palette: an #GtkToolPalette.
1610 * @targets: the #GtkToolPaletteDragTargets which the widget should support.
1612 * Sets the tool palette as a drag source. Enables all groups and items in
1613 * the tool palette as drag sources on button 1 and button 3 press with copy
1616 * See gtk_drag_source_set().
1622 gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
1623 GtkToolPaletteDragTargets targets)
1627 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1629 if ((palette->priv->drag_source & targets) == targets)
1632 palette->priv->drag_source |= targets;
1634 for (i = 0; i < palette->priv->groups->len; ++i)
1636 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1638 gtk_container_forall (GTK_CONTAINER (info->widget),
1639 _gtk_tool_palette_child_set_drag_source,
1645 * gtk_tool_palette_add_drag_dest:
1646 * @palette: an #GtkToolPalette.
1647 * @widget: a #GtkWidget which should be a drag destination for palette.
1648 * @flags: the flags that specify what actions GTK+ should take for drops on that widget.
1649 * @targets: the #GtkToolPaletteDragTargets which the widget should support.
1650 * @actions: the #GdkDragAction<!-- -->s which the widget should suppport.
1652 * Sets the tool palette as drag source (see gtk_tool_palette_set_drag_source) and
1653 * sets widget as a drag destination for drags from palette. With flags the actions
1654 * (like highlighting and target checking) which should be performed by GTK+ for
1655 * drops on widget can be specified. With targets the supported drag targets
1656 * (groups and/or items) can be specified. With actions the supported drag actions
1657 * (copy and move) can be specified.
1659 * See gtk_drag_dest_set().
1664 gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
1666 GtkDestDefaults flags,
1667 GtkToolPaletteDragTargets targets,
1668 GdkDragAction actions)
1670 GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
1673 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1674 g_return_if_fail (GTK_IS_WIDGET (widget));
1676 gtk_tool_palette_set_drag_source (palette,
1679 if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
1680 entries[n_entries++] = dnd_targets[0];
1681 if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
1682 entries[n_entries++] = dnd_targets[1];
1684 gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
1688 _gtk_tool_palette_get_item_size (GtkToolPalette *palette,
1689 GtkRequisition *item_size,
1690 gboolean homogeneous_only,
1691 gint *requested_rows)
1693 GtkRequisition max_requisition;
1697 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1698 g_return_if_fail (NULL != item_size);
1700 max_requisition.width = 0;
1701 max_requisition.height = 0;
1704 /* iterate over all groups and calculate the max item_size and max row request */
1705 for (i = 0; i < palette->priv->groups->len; ++i)
1707 GtkRequisition requisition;
1709 GtkToolItemGroupInfo *group = g_ptr_array_index(palette->priv->groups, i);
1714 _gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
1716 max_requisition.width = MAX (max_requisition.width, requisition.width);
1717 max_requisition.height = MAX (max_requisition.height, requisition.height);
1718 max_rows = MAX (max_rows, rows);
1721 *item_size = max_requisition;
1723 *requested_rows = max_rows;
1727 gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
1728 GdkDragContext *context,
1729 GtkSelectionData *selection,
1734 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1736 if (selection->target == dnd_target_atom_item)
1737 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
1740 gtk_selection_data_set (selection, selection->target, 8,
1741 (guchar*) &drag_data, sizeof (drag_data));
1745 gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
1746 GdkDragContext *context,
1747 GtkSelectionData *selection,
1752 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1754 if (selection->target == dnd_target_atom_group)
1755 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
1758 gtk_selection_data_set (selection, selection->target, 8,
1759 (guchar*) &drag_data, sizeof (drag_data));
1763 _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
1766 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1768 /* Check drag_source,
1769 * to work properly when called from gtk_tool_item_group_insert().
1771 if (!palette->priv->drag_source)
1774 if (GTK_IS_TOOL_ITEM (child) &&
1775 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
1777 /* Connect to child instead of the item itself,
1778 * to work arround bug 510377.
1780 if (GTK_IS_TOOL_BUTTON (child))
1781 child = gtk_bin_get_child (GTK_BIN (child));
1786 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1787 &dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1789 g_signal_connect (child, "drag-data-get",
1790 G_CALLBACK (gtk_tool_palette_item_drag_data_get),
1793 else if (GTK_IS_BUTTON (child) &&
1794 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
1796 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1797 &dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1799 g_signal_connect (child, "drag-data-get",
1800 G_CALLBACK (gtk_tool_palette_child_drag_data_get),
1806 * gtk_tool_palette_get_drag_target_item:
1808 * Get the target entry for a dragged #GtkToolItem.
1810 * Returns: the #GtkTargetEntry for a dragged item.
1814 G_CONST_RETURN GtkTargetEntry*
1815 gtk_tool_palette_get_drag_target_item (void)
1817 return &dnd_targets[0];
1821 * gtk_tool_palette_get_drag_target_group:
1823 * Get the target entry for a dragged #GtkToolItemGroup.
1825 * Returns: the #GtkTargetEntry for a dragged group.
1829 G_CONST_RETURN GtkTargetEntry*
1830 gtk_tool_palette_get_drag_target_group (void)
1832 return &dnd_targets[1];
1836 _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
1839 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1840 palette->priv->expanding_child = widget;
1844 gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
1846 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1847 return palette->priv->hadjustment;
1851 gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
1853 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1854 return palette->priv->vadjustment;
1858 _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
1860 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1862 return palette->priv->text_size_group;