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"
30 #include "gtkprivate.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;
129 CHILD_PROP_EXCLUSIVE,
133 struct _GtkToolItemGroupInfo
135 GtkToolItemGroup *widget;
137 guint notify_collapsed;
143 struct _GtkToolPalettePrivate
147 GtkAdjustment *hadjustment;
148 GtkAdjustment *vadjustment;
150 GtkIconSize icon_size;
151 gboolean icon_size_set;
152 GtkOrientation orientation;
153 GtkToolbarStyle style;
156 GtkWidget *expanding_child;
158 GtkSizeGroup *text_size_group;
160 GtkSettings *settings;
161 gulong settings_connection;
163 guint drag_source : 2;
166 struct _GtkToolPaletteDragData
168 GtkToolPalette *palette;
172 static GdkAtom dnd_target_atom_item = GDK_NONE;
173 static GdkAtom dnd_target_atom_group = GDK_NONE;
175 static const GtkTargetEntry dnd_targets[] =
177 { "application/x-gtk-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
178 { "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
181 G_DEFINE_TYPE_WITH_CODE (GtkToolPalette,
184 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
187 gtk_tool_palette_init (GtkToolPalette *palette)
189 palette->priv = G_TYPE_INSTANCE_GET_PRIVATE (palette,
190 GTK_TYPE_TOOL_PALETTE,
191 GtkToolPalettePrivate);
193 palette->priv->groups = g_ptr_array_sized_new (4);
194 g_ptr_array_set_free_func (palette->priv->groups, g_free);
196 palette->priv->icon_size = DEFAULT_ICON_SIZE;
197 palette->priv->icon_size_set = FALSE;
198 palette->priv->orientation = DEFAULT_ORIENTATION;
199 palette->priv->style = DEFAULT_TOOLBAR_STYLE;
200 palette->priv->style_set = FALSE;
202 palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
206 gtk_tool_palette_reconfigured (GtkToolPalette *palette)
210 for (i = 0; i < palette->priv->groups->len; ++i)
212 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
214 _gtk_tool_item_group_palette_reconfigured (info->widget);
217 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
221 gtk_tool_palette_set_property (GObject *object,
226 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
231 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
233 palette->priv->icon_size = g_value_get_enum (value);
234 gtk_tool_palette_reconfigured (palette);
238 case PROP_ICON_SIZE_SET:
239 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
241 palette->priv->icon_size_set = g_value_get_enum (value);
242 gtk_tool_palette_reconfigured (palette);
246 case PROP_ORIENTATION:
247 if ((guint) g_value_get_enum (value) != palette->priv->orientation)
249 palette->priv->orientation = g_value_get_enum (value);
250 gtk_tool_palette_reconfigured (palette);
254 case PROP_TOOLBAR_STYLE:
255 if ((guint) g_value_get_enum (value) != palette->priv->style)
257 palette->priv->style = g_value_get_enum (value);
258 gtk_tool_palette_reconfigured (palette);
263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
269 gtk_tool_palette_get_property (GObject *object,
274 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
279 g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
282 case PROP_ICON_SIZE_SET:
283 g_value_set_boolean (value, palette->priv->icon_size_set);
286 case PROP_ORIENTATION:
287 g_value_set_enum (value, palette->priv->orientation);
290 case PROP_TOOLBAR_STYLE:
291 g_value_set_enum (value, gtk_tool_palette_get_style (palette));
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
301 gtk_tool_palette_dispose (GObject *object)
303 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
306 if (palette->priv->hadjustment)
308 g_object_unref (palette->priv->hadjustment);
309 palette->priv->hadjustment = NULL;
312 if (palette->priv->vadjustment)
314 g_object_unref (palette->priv->vadjustment);
315 palette->priv->vadjustment = NULL;
318 for (i = 0; i < palette->priv->groups->len; ++i)
320 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
322 if (group->notify_collapsed)
324 g_signal_handler_disconnect (group->widget, group->notify_collapsed);
325 group->notify_collapsed = 0;
329 if (palette->priv->text_size_group)
331 g_object_unref (palette->priv->text_size_group);
332 palette->priv->text_size_group = NULL;
335 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
339 gtk_tool_palette_finalize (GObject *object)
341 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
343 g_ptr_array_free (palette->priv->groups, TRUE);
345 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
349 gtk_tool_palette_size_request (GtkWidget *widget,
350 GtkRequisition *requisition)
352 const gint border_width = GTK_CONTAINER (widget)->border_width;
353 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
354 GtkRequisition child_requisition;
357 requisition->width = 0;
358 requisition->height = 0;
360 for (i = 0; i < palette->priv->groups->len; ++i)
362 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
367 gtk_widget_size_request (GTK_WIDGET (group->widget), &child_requisition);
369 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
371 requisition->width = MAX (requisition->width, child_requisition.width);
372 requisition->height += child_requisition.height;
376 requisition->width += child_requisition.width;
377 requisition->height = MAX (requisition->height, child_requisition.height);
381 requisition->width += border_width * 2;
382 requisition->height += border_width * 2;
386 gtk_tool_palette_size_allocate (GtkWidget *widget,
387 GtkAllocation *allocation)
389 const gint border_width = GTK_CONTAINER (widget)->border_width;
390 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
391 GtkAdjustment *adjustment = NULL;
392 GtkAllocation child_allocation;
394 gint n_expand_groups = 0;
395 gint remaining_space = 0;
396 gint expand_space = 0;
398 gint page_start, page_size = 0;
402 gint min_offset = -1, max_offset = -1;
406 gint *group_sizes = g_newa (gint, palette->priv->groups->len);
408 GtkTextDirection direction = gtk_widget_get_direction (widget);
410 GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
412 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
414 adjustment = palette->priv->vadjustment;
415 page_size = allocation->height;
419 adjustment = palette->priv->hadjustment;
420 page_size = allocation->width;
424 offset = gtk_adjustment_get_value (adjustment);
425 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
426 GTK_TEXT_DIR_RTL == direction)
429 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
430 child_allocation.width = allocation->width - border_width * 2;
432 child_allocation.height = allocation->height - border_width * 2;
434 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
435 remaining_space = allocation->height;
437 remaining_space = allocation->width;
439 /* figure out the required size of all groups to be able to distribute the
440 * remaining space on allocation
442 for (i = 0; i < palette->priv->groups->len; ++i)
444 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
450 widget = GTK_WIDGET (group->widget);
452 if (gtk_tool_item_group_get_n_items (group->widget))
454 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
455 size = _gtk_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
457 size = _gtk_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
459 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
460 n_expand_groups += 1;
465 remaining_space -= size;
466 group_sizes[i] = size;
468 /* if the widget is currently expanding an offset which allows to
469 * display as much of the widget as possible is calculated
471 if (widget == palette->priv->expanding_child)
474 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
475 child_allocation.width : child_allocation.height;
482 for (j = 0; j < i; ++j)
483 min_offset += group_sizes[j];
485 max_offset = min_offset + group_sizes[i];
487 real_size = _gtk_tool_item_group_get_size_for_limit
488 (GTK_TOOL_ITEM_GROUP (widget), limit,
489 GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
492 if (size == real_size)
493 palette->priv->expanding_child = NULL;
497 if (n_expand_groups > 0)
499 remaining_space = MAX (0, remaining_space);
500 expand_space = remaining_space / n_expand_groups;
503 if (max_offset != -1)
506 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
507 allocation->height : allocation->width;
509 offset = MIN (MAX (offset, max_offset - limit), min_offset);
512 if (remaining_space > 0)
516 child_allocation.y = border_width;
518 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
519 child_allocation.y -= offset;
523 /* allocate all groups at the calculated positions */
524 for (i = 0; i < palette->priv->groups->len; ++i)
526 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
532 widget = GTK_WIDGET (group->widget);
534 if (gtk_tool_item_group_get_n_items (group->widget))
536 gint size = group_sizes[i];
538 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
540 size += MIN (expand_space, remaining_space);
541 remaining_space -= expand_space;
544 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
545 child_allocation.height = size;
547 child_allocation.width = size;
549 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
550 GTK_TEXT_DIR_RTL == direction)
551 child_allocation.x = allocation->width - x - child_allocation.width;
553 child_allocation.x = x;
555 gtk_widget_size_allocate (widget, &child_allocation);
556 gtk_widget_show (widget);
558 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
559 child_allocation.y += child_allocation.height;
561 x += child_allocation.width;
564 gtk_widget_hide (widget);
567 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
569 child_allocation.y += border_width;
570 child_allocation.y += offset;
572 page_start = child_allocation.y;
582 /* update the scrollbar to match the displayed adjustment */
587 adjustment->page_increment = page_size * 0.9;
588 adjustment->step_increment = page_size * 0.1;
589 adjustment->page_size = page_size;
591 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
592 GTK_TEXT_DIR_LTR == direction)
594 adjustment->lower = 0;
595 adjustment->upper = MAX (0, page_start);
597 value = MIN (offset, adjustment->upper - adjustment->page_size);
598 gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
602 adjustment->lower = page_size - MAX (0, page_start);
603 adjustment->upper = page_size;
607 value = MAX (offset, adjustment->lower);
608 gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
611 gtk_adjustment_changed (adjustment);
616 gtk_tool_palette_expose_event (GtkWidget *widget,
617 GdkEventExpose *event)
619 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
624 display = gdk_drawable_get_display (widget->window);
626 if (!gdk_display_supports_composite (display))
629 cr = gdk_cairo_create (widget->window);
630 gdk_cairo_region (cr, event->region);
633 cairo_push_group (cr);
635 for (i = 0; i < palette->priv->groups->len; ++i)
637 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
639 _gtk_tool_item_group_paint (info->widget, cr);
642 cairo_pop_group_to_source (cr);
651 gtk_tool_palette_realize (GtkWidget *widget)
653 const gint border_width = GTK_CONTAINER (widget)->border_width;
654 gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
655 GdkWindowAttr attributes;
657 attributes.window_type = GDK_WINDOW_CHILD;
658 attributes.x = widget->allocation.x + border_width;
659 attributes.y = widget->allocation.y + border_width;
660 attributes.width = widget->allocation.width - border_width * 2;
661 attributes.height = widget->allocation.height - border_width * 2;
662 attributes.wclass = GDK_INPUT_OUTPUT;
663 attributes.visual = gtk_widget_get_visual (widget);
664 attributes.colormap = gtk_widget_get_colormap (widget);
665 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
666 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
667 | GDK_BUTTON_MOTION_MASK;
669 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
670 &attributes, attributes_mask);
672 gdk_window_set_user_data (widget->window, widget);
673 widget->style = gtk_style_attach (widget->style, widget->window);
674 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
675 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
677 gtk_container_forall (GTK_CONTAINER (widget),
678 (GtkCallback) gtk_widget_set_parent_window,
681 gtk_widget_queue_resize_no_redraw (widget);
685 gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
688 GtkWidget *widget = GTK_WIDGET (data);
689 gtk_tool_palette_size_allocate (widget, &widget->allocation);
693 gtk_tool_palette_set_scroll_adjustments (GtkWidget *widget,
694 GtkAdjustment *hadjustment,
695 GtkAdjustment *vadjustment)
697 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
700 g_object_ref_sink (hadjustment);
702 g_object_ref_sink (vadjustment);
704 if (palette->priv->hadjustment)
705 g_object_unref (palette->priv->hadjustment);
706 if (palette->priv->vadjustment)
707 g_object_unref (palette->priv->vadjustment);
709 palette->priv->hadjustment = hadjustment;
710 palette->priv->vadjustment = vadjustment;
712 if (palette->priv->hadjustment)
713 g_signal_connect (palette->priv->hadjustment, "value-changed",
714 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
716 if (palette->priv->vadjustment)
717 g_signal_connect (palette->priv->vadjustment, "value-changed",
718 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
723 gtk_tool_palette_add (GtkContainer *container,
726 GtkToolPalette *palette;
727 GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
729 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
730 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
732 palette = GTK_TOOL_PALETTE (container);
734 g_ptr_array_add (palette->priv->groups, info);
735 info->pos = palette->priv->groups->len - 1;
736 info->widget = g_object_ref_sink (child);
738 gtk_widget_set_parent (child, GTK_WIDGET (palette));
742 gtk_tool_palette_remove (GtkContainer *container,
745 GtkToolPalette *palette;
748 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
749 palette = GTK_TOOL_PALETTE (container);
751 for (i = 0; i < palette->priv->groups->len; ++i)
753 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
754 if (GTK_WIDGET(info->widget) == child)
756 g_object_unref (child);
757 gtk_widget_unparent (child);
759 g_ptr_array_remove_index (palette->priv->groups, i);
765 gtk_tool_palette_forall (GtkContainer *container,
767 GtkCallback callback,
768 gpointer callback_data)
770 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
774 for (i = 0; i < palette->priv->groups->len; ++i)
776 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
778 callback (GTK_WIDGET (info->widget),
784 gtk_tool_palette_child_type (GtkContainer *container)
786 return GTK_TYPE_TOOL_ITEM_GROUP;
790 gtk_tool_palette_set_child_property (GtkContainer *container,
796 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
800 case CHILD_PROP_EXCLUSIVE:
801 gtk_tool_palette_set_exclusive (palette, child, g_value_get_boolean (value));
804 case CHILD_PROP_EXPAND:
805 gtk_tool_palette_set_expand (palette, child, g_value_get_boolean (value));
809 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
815 gtk_tool_palette_get_child_property (GtkContainer *container,
821 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
825 case CHILD_PROP_EXCLUSIVE:
826 g_value_set_boolean (value, gtk_tool_palette_get_exclusive (palette, child));
829 case CHILD_PROP_EXPAND:
830 g_value_set_boolean (value, gtk_tool_palette_get_expand (palette, child));
834 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
840 style_change_notify (GtkToolPalette *palette)
842 GtkToolPalettePrivate* priv = palette->priv;
844 if (!priv->style_set)
846 /* pretend it was set, then unset, thus reverting to new default */
847 priv->style_set = TRUE;
848 gtk_tool_palette_unset_style (palette);
853 icon_size_change_notify (GtkToolPalette *palette)
855 GtkToolPalettePrivate* priv = palette->priv;
857 if (!priv->icon_size_set)
859 /* pretend it was set, then unset, thus reverting to new default */
860 priv->icon_size_set = TRUE;
861 gtk_tool_palette_unset_icon_size (palette);
866 gtk_tool_palette_settings_change_notify (GtkSettings *settings,
867 const GParamSpec *pspec,
868 GtkToolPalette *palette)
870 if (strcmp (pspec->name, "gtk-toolbar-style") == 0)
871 style_change_notify (palette);
872 else if (strcmp (pspec->name, "gtk-toolbar-icon-size") == 0)
873 icon_size_change_notify (palette);
877 gtk_tool_palette_screen_changed (GtkWidget *widget,
878 GdkScreen *previous_screen)
880 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
881 GtkToolPalettePrivate* priv = palette->priv;
882 GtkSettings *old_settings = priv->settings;
883 GtkSettings *settings;
885 if (gtk_widget_has_screen (GTK_WIDGET (palette)))
886 settings = gtk_widget_get_settings (GTK_WIDGET (palette));
890 if (settings == old_settings)
895 g_signal_handler_disconnect (old_settings, priv->settings_connection);
896 g_object_unref (old_settings);
901 priv->settings_connection =
902 g_signal_connect (settings, "notify",
903 G_CALLBACK (gtk_tool_palette_settings_change_notify),
905 priv->settings = g_object_ref (settings);
908 priv->settings = NULL;
910 gtk_tool_palette_reconfigured (palette);
915 gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
917 GObjectClass *oclass = G_OBJECT_CLASS (cls);
918 GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
919 GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
921 oclass->set_property = gtk_tool_palette_set_property;
922 oclass->get_property = gtk_tool_palette_get_property;
923 oclass->dispose = gtk_tool_palette_dispose;
924 oclass->finalize = gtk_tool_palette_finalize;
926 wclass->size_request = gtk_tool_palette_size_request;
927 wclass->size_allocate = gtk_tool_palette_size_allocate;
928 wclass->expose_event = gtk_tool_palette_expose_event;
929 wclass->realize = gtk_tool_palette_realize;
931 cclass->add = gtk_tool_palette_add;
932 cclass->remove = gtk_tool_palette_remove;
933 cclass->forall = gtk_tool_palette_forall;
934 cclass->child_type = gtk_tool_palette_child_type;
935 cclass->set_child_property = gtk_tool_palette_set_child_property;
936 cclass->get_child_property = gtk_tool_palette_get_child_property;
938 cls->set_scroll_adjustments = gtk_tool_palette_set_scroll_adjustments;
940 /* Handle screen-changed so we can update our GtkSettings.
942 wclass->screen_changed = gtk_tool_palette_screen_changed;
945 * GtkToolPalette::set-scroll-adjustments:
946 * @widget: the GtkToolPalette that received the signal
947 * @hadjustment: The horizontal adjustment
948 * @vadjustment: The vertical adjustment
950 * Set the scroll adjustments for the viewport.
951 * Usually scrolled containers like GtkScrolledWindow will emit this
952 * signal to connect two instances of GtkScrollbar to the scroll
953 * directions of the GtkToolpalette.
957 wclass->set_scroll_adjustments_signal =
958 g_signal_new ("set-scroll-adjustments",
959 G_TYPE_FROM_CLASS (oclass),
960 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
961 G_STRUCT_OFFSET (GtkToolPaletteClass, set_scroll_adjustments),
963 _gtk_marshal_VOID__OBJECT_OBJECT,
966 GTK_TYPE_ADJUSTMENT);
968 g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
971 * GtkToolPalette:icon-size:
973 * The size of the icons in a tool palette is normally determined by
974 * the #GtkSettings:toolbar-icon-size setting. When this property is set,
975 * it overrides the setting.
977 * This should only be used for special-purpose tool palettes, normal
978 * application tool palettes should respect the user preferences for the
983 g_object_class_install_property (oclass,
985 g_param_spec_enum ("icon-size",
987 P_("Size of icons in this tool palette"),
990 GTK_PARAM_READWRITE));
993 * GtkToolPalette:icon-size-set:
995 * Is %TRUE if the #GtkToolPalette:icon-size property has been set.
999 g_object_class_install_property (oclass,
1001 g_param_spec_boolean ("icon-size-set",
1002 P_("Icon size set"),
1003 P_("Whether the icon-size property has been set"),
1005 GTK_PARAM_READWRITE));
1008 * GtkToolPalette:toolbar-style:
1010 * The style of items in the tool palette.
1014 g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
1015 g_param_spec_enum ("toolbar-style",
1016 P_("Toolbar Style"),
1017 P_("Style of items in the tool palette"),
1018 GTK_TYPE_TOOLBAR_STYLE,
1019 DEFAULT_TOOLBAR_STYLE,
1020 GTK_PARAM_READWRITE));
1024 * GtkToolPalette:exclusive:
1026 * Whether the item group should be the only one that is expanded
1031 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
1032 g_param_spec_boolean ("exclusive",
1034 P_("Whether the item group should be the only expanded at a given time"),
1035 DEFAULT_CHILD_EXCLUSIVE,
1036 GTK_PARAM_READWRITE));
1039 * GtkToolPalette:expand:
1041 * Whether the item group should receive extra space when the palette grows.
1046 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1047 g_param_spec_boolean ("expand",
1049 P_("Whether the item group should receive extra space when the palette grows"),
1050 DEFAULT_CHILD_EXPAND,
1051 GTK_PARAM_READWRITE));
1053 g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
1055 dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
1056 dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
1060 * gtk_tool_palette_new:
1062 * Creates a new tool palette.
1064 * Returns: a new #GtkToolPalette
1069 gtk_tool_palette_new (void)
1071 return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
1075 * gtk_tool_palette_set_icon_size:
1076 * @palette: a #GtkToolPalette
1077 * @icon_size: (type int): the #GtkIconSize that icons in the tool
1078 * palette shall have
1080 * Sets the size of icons in the tool palette.
1085 gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
1086 GtkIconSize icon_size)
1088 GtkToolPalettePrivate *priv;
1090 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1091 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
1093 priv = palette->priv;
1095 if (!priv->icon_size_set)
1097 priv->icon_size_set = TRUE;
1098 g_object_notify (G_OBJECT (palette), "icon-size-set");
1101 if (priv->icon_size == icon_size)
1104 priv->icon_size = icon_size;
1105 g_object_notify (G_OBJECT (palette), "icon-size");
1107 gtk_tool_palette_reconfigured (palette);
1109 gtk_widget_queue_resize (GTK_WIDGET (palette));
1112 static GtkSettings *
1113 toolpalette_get_settings (GtkToolPalette *palette)
1115 GtkToolPalettePrivate *priv = palette->priv;
1116 return priv->settings;
1120 * gtk_tool_palette_unset_icon_size:
1121 * @palette: a #GtkToolPalette
1123 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(),
1124 * so that user preferences will be used to determine the icon size.
1129 gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
1131 GtkToolPalettePrivate* priv = palette->priv;
1134 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1136 if (palette->priv->icon_size_set)
1138 GtkSettings *settings = toolpalette_get_settings (palette);
1142 g_object_get (settings,
1143 "gtk-toolbar-icon-size", &size,
1147 size = DEFAULT_ICON_SIZE;
1149 if (size != palette->priv->icon_size)
1151 gtk_tool_palette_set_icon_size (palette, size);
1152 g_object_notify (G_OBJECT (palette), "icon-size");
1155 priv->icon_size_set = FALSE;
1156 g_object_notify (G_OBJECT (palette), "icon-size-set");
1160 /* Set the "toolbar-style" property and do appropriate things.
1161 * GtkToolbar does this by emitting a signal instead of just
1162 * calling a function...
1165 gtk_tool_palette_change_style (GtkToolPalette *palette,
1166 GtkToolbarStyle style)
1168 GtkToolPalettePrivate* priv = palette->priv;
1170 if (priv->style != style)
1172 priv->style = style;
1174 gtk_tool_palette_reconfigured (palette);
1176 gtk_widget_queue_resize (GTK_WIDGET (palette));
1177 g_object_notify (G_OBJECT (palette), "toolbar-style");
1183 * gtk_tool_palette_set_style:
1184 * @palette: a #GtkToolPalette
1185 * @style: the #GtkToolbarStyle that items in the tool palette shall have
1187 * Sets the style (text, icons or both) of items in the tool palette.
1192 gtk_tool_palette_set_style (GtkToolPalette *palette,
1193 GtkToolbarStyle style)
1195 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1197 palette->priv->style_set = TRUE;
1198 gtk_tool_palette_change_style (palette, style);
1203 * gtk_tool_palette_unset_style:
1204 * @palette: a #GtkToolPalette
1206 * Unsets a toolbar style set with gtk_tool_palette_set_style(),
1207 * so that user preferences will be used to determine the toolbar style.
1212 gtk_tool_palette_unset_style (GtkToolPalette *palette)
1214 GtkToolPalettePrivate* priv = palette->priv;
1215 GtkToolbarStyle style;
1217 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1219 if (priv->style_set)
1221 GtkSettings *settings = toolpalette_get_settings (palette);
1224 g_object_get (settings,
1225 "gtk-toolbar-style", &style,
1228 style = DEFAULT_TOOLBAR_STYLE;
1230 if (style != priv->style)
1231 gtk_tool_palette_change_style (palette, style);
1233 priv->style_set = FALSE;
1238 * gtk_tool_palette_get_icon_size:
1239 * @palette: a #GtkToolPalette
1241 * Gets the size of icons in the tool palette.
1242 * See gtk_tool_palette_set_icon_size().
1244 * Returns: (type int): the #GtkIconSize of icons in the tool palette
1249 gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
1251 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
1253 return palette->priv->icon_size;
1257 * gtk_tool_palette_get_style:
1258 * @palette: a #GtkToolPalette
1260 * Gets the style (icons, text or both) of items in the tool palette.
1262 * Returns: the #GtkToolbarStyle of items in the tool palette.
1267 gtk_tool_palette_get_style (GtkToolPalette *palette)
1269 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
1271 return palette->priv->style;
1275 _gtk_tool_palette_compare_groups (gconstpointer a,
1278 const GtkToolItemGroupInfo *group_a = a;
1279 const GtkToolItemGroupInfo *group_b = b;
1281 return group_a->pos - group_b->pos;
1285 * gtk_tool_palette_set_group_position:
1286 * @palette: a #GtkToolPalette
1287 * @group: a #GtkToolItemGroup which is a child of palette
1288 * @position: a new index for group
1290 * Sets the position of the group as an index of the tool palette.
1291 * If position is 0 the group will become the first child, if position is
1292 * -1 it will become the last child.
1297 gtk_tool_palette_set_group_position (GtkToolPalette *palette,
1301 GtkToolItemGroupInfo *group_new;
1302 GtkToolItemGroupInfo *group_old;
1305 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1306 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1307 g_return_if_fail (position >= -1);
1310 position = palette->priv->groups->len - 1;
1312 g_return_if_fail ((guint) position < palette->priv->groups->len);
1314 group_new = g_ptr_array_index (palette->priv->groups, position);
1316 if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
1319 old_position = gtk_tool_palette_get_group_position (palette, group);
1320 g_return_if_fail (old_position >= 0);
1322 group_old = g_ptr_array_index (palette->priv->groups, old_position);
1324 group_new->pos = position;
1325 group_old->pos = old_position;
1327 g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups);
1329 gtk_widget_queue_resize (GTK_WIDGET (palette));
1333 gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
1337 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1340 if (gtk_tool_item_group_get_collapsed (group))
1343 for (i = 0; i < palette->priv->groups->len; ++i)
1345 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1346 GtkToolItemGroup *current_group = info->widget;
1348 if (current_group && current_group != group)
1349 gtk_tool_item_group_set_collapsed (current_group, TRUE);
1354 * gtk_tool_palette_set_exclusive:
1355 * @palette: a #GtkToolPalette
1356 * @group: a #GtkToolItemGroup which is a child of palette
1357 * @exclusive: whether the group should be exclusive or not
1359 * Sets whether the group should be exclusive or not.
1360 * If an exclusive group is expanded all other groups are collapsed.
1365 gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
1369 GtkToolItemGroupInfo *group_info;
1372 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1373 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1375 position = gtk_tool_palette_get_group_position (palette, group);
1376 g_return_if_fail (position >= 0);
1378 group_info = g_ptr_array_index (palette->priv->groups, position);
1380 if (exclusive == group_info->exclusive)
1383 group_info->exclusive = exclusive;
1385 if (group_info->exclusive != (0 != group_info->notify_collapsed))
1387 if (group_info->exclusive)
1389 group_info->notify_collapsed =
1390 g_signal_connect (group, "notify::collapsed",
1391 G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
1396 g_signal_handler_disconnect (group, group_info->notify_collapsed);
1397 group_info->notify_collapsed = 0;
1401 gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
1402 gtk_widget_child_notify (group, "exclusive");
1406 * gtk_tool_palette_set_expand:
1407 * @palette: a #GtkToolPalette
1408 * @group: a #GtkToolItemGroup which is a child of palette
1409 * @expand: whether the group should be given extra space
1411 * Sets whether the group should be given extra space.
1416 gtk_tool_palette_set_expand (GtkToolPalette *palette,
1420 GtkToolItemGroupInfo *group_info;
1423 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1424 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1426 position = gtk_tool_palette_get_group_position (palette, group);
1427 g_return_if_fail (position >= 0);
1429 group_info = g_ptr_array_index (palette->priv->groups, position);
1431 if (expand != group_info->expand)
1433 group_info->expand = expand;
1434 gtk_widget_queue_resize (GTK_WIDGET (palette));
1435 gtk_widget_child_notify (group, "expand");
1440 * gtk_tool_palette_get_group_position:
1441 * @palette: a #GtkToolPalette
1442 * @group: a #GtkToolItemGroup
1444 * Gets the position of @group in @palette as index.
1445 * See gtk_tool_palette_set_group_position().
1447 * Returns: the index of group or -1 if @group is not a child of @palette
1452 gtk_tool_palette_get_group_position (GtkToolPalette *palette,
1457 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
1458 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
1460 for (i = 0; i < palette->priv->groups->len; ++i)
1462 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1463 if ((gpointer) group == info->widget)
1471 * gtk_tool_palette_get_exclusive:
1472 * @palette: a #GtkToolPalette
1473 * @group: a #GtkToolItemGroup which is a child of palette
1475 * Gets whether @group is exclusive or not.
1476 * See gtk_tool_palette_set_exclusive().
1478 * Returns: %TRUE if @group is exclusive
1483 gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
1487 GtkToolItemGroupInfo *info;
1489 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
1490 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
1492 position = gtk_tool_palette_get_group_position (palette, group);
1493 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
1495 info = g_ptr_array_index (palette->priv->groups, position);
1497 return info->exclusive;
1501 * gtk_tool_palette_get_expand:
1502 * @palette: a #GtkToolPalette
1503 * @group: a #GtkToolItemGroup which is a child of palette
1505 * Gets whether group should be given extra space.
1506 * See gtk_tool_palette_set_expand().
1508 * Returns: %TRUE if group should be given extra space, %FALSE otherwise
1513 gtk_tool_palette_get_expand (GtkToolPalette *palette,
1517 GtkToolItemGroupInfo *info;
1519 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
1520 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
1522 position = gtk_tool_palette_get_group_position (palette, group);
1523 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
1525 info = g_ptr_array_index (palette->priv->groups, position);
1527 return info->expand;
1531 * gtk_tool_palette_get_drop_item:
1532 * @palette: a #GtkToolPalette
1533 * @x: the x position
1534 * @y: the y position
1536 * Gets the item at position (x, y).
1537 * See gtk_tool_palette_get_drop_group().
1539 * Returns: the #GtkToolItem at position or %NULL if there is no such item
1544 gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
1548 GtkWidget *group = gtk_tool_palette_get_drop_group (palette, x, y);
1551 return gtk_tool_item_group_get_drop_item (GTK_TOOL_ITEM_GROUP (group),
1552 x - group->allocation.x,
1553 y - group->allocation.y);
1559 * gtk_tool_palette_get_drop_group:
1560 * @palette: a #GtkToolPalette
1561 * @x: the x position
1562 * @y: the y position
1564 * Gets the group at position (x, y).
1566 * Returns: the #GtkToolItemGroup at position or %NULL
1567 * if there is no such group
1572 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
1576 GtkAllocation *allocation;
1579 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1581 allocation = >K_WIDGET (palette)->allocation;
1583 g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
1584 g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
1586 for (i = 0; i < palette->priv->groups->len; ++i)
1588 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1595 widget = GTK_WIDGET (group->widget);
1597 x0 = x - widget->allocation.x;
1598 y0 = y - widget->allocation.y;
1600 if (x0 >= 0 && x0 < widget->allocation.width &&
1601 y0 >= 0 && y0 < widget->allocation.height)
1609 * gtk_tool_palette_get_drag_item:
1610 * @palette: a #GtkToolPalette
1611 * @selection: a #GtkSelectionData
1613 * Get the dragged item from the selection.
1614 * This could be a #GtkToolItem or a #GtkToolItemGroup.
1616 * Returns: the dragged item in selection
1621 gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
1622 const GtkSelectionData *selection)
1624 GtkToolPaletteDragData *data;
1626 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1627 g_return_val_if_fail (NULL != selection, NULL);
1629 g_return_val_if_fail (selection->format == 8, NULL);
1630 g_return_val_if_fail (selection->length == sizeof (GtkToolPaletteDragData), NULL);
1631 g_return_val_if_fail (selection->target == dnd_target_atom_item ||
1632 selection->target == dnd_target_atom_group,
1635 data = (GtkToolPaletteDragData*) selection->data;
1637 g_return_val_if_fail (data->palette == palette, NULL);
1639 if (dnd_target_atom_item == selection->target)
1640 g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
1641 else if (dnd_target_atom_group == selection->target)
1642 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
1648 * gtk_tool_palette_set_drag_source:
1649 * @palette: a #GtkToolPalette
1650 * @targets: the #GtkToolPaletteDragTarget<!-- -->s
1651 * which the widget should support
1653 * Sets the tool palette as a drag source.
1654 * Enables all groups and items in the tool palette as drag sources
1655 * on button 1 and button 3 press with copy and move actions.
1656 * See gtk_drag_source_set().
1661 gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
1662 GtkToolPaletteDragTargets targets)
1666 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1668 if ((palette->priv->drag_source & targets) == targets)
1671 palette->priv->drag_source |= targets;
1673 for (i = 0; i < palette->priv->groups->len; ++i)
1675 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1677 gtk_container_forall (GTK_CONTAINER (info->widget),
1678 _gtk_tool_palette_child_set_drag_source,
1684 * gtk_tool_palette_add_drag_dest:
1685 * @palette: a #GtkToolPalette
1686 * @widget: a #GtkWidget which should be a drag destination for @palette
1687 * @flags: the flags that specify what actions GTK+ should take for drops
1689 * @targets: the #GtkToolPaletteDragTarget<!-- -->s which the widget
1691 * @actions: the #GdkDragAction<!-- -->s which the widget should suppport
1693 * Sets @palette as drag source (see gtk_tool_palette_set_drag_source())
1694 * and sets @widget as a drag destination for drags from @palette.
1695 * See gtk_drag_dest_set().
1700 gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
1702 GtkDestDefaults flags,
1703 GtkToolPaletteDragTargets targets,
1704 GdkDragAction actions)
1706 GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
1709 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1710 g_return_if_fail (GTK_IS_WIDGET (widget));
1712 gtk_tool_palette_set_drag_source (palette,
1715 if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
1716 entries[n_entries++] = dnd_targets[0];
1717 if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
1718 entries[n_entries++] = dnd_targets[1];
1720 gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
1724 _gtk_tool_palette_get_item_size (GtkToolPalette *palette,
1725 GtkRequisition *item_size,
1726 gboolean homogeneous_only,
1727 gint *requested_rows)
1729 GtkRequisition max_requisition;
1733 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1734 g_return_if_fail (NULL != item_size);
1736 max_requisition.width = 0;
1737 max_requisition.height = 0;
1740 /* iterate over all groups and calculate the max item_size and max row request */
1741 for (i = 0; i < palette->priv->groups->len; ++i)
1743 GtkRequisition requisition;
1745 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1750 _gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
1752 max_requisition.width = MAX (max_requisition.width, requisition.width);
1753 max_requisition.height = MAX (max_requisition.height, requisition.height);
1754 max_rows = MAX (max_rows, rows);
1757 *item_size = max_requisition;
1759 *requested_rows = max_rows;
1763 gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
1764 GdkDragContext *context,
1765 GtkSelectionData *selection,
1770 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1772 if (selection->target == dnd_target_atom_item)
1773 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
1776 gtk_selection_data_set (selection, selection->target, 8,
1777 (guchar*) &drag_data, sizeof (drag_data));
1781 gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
1782 GdkDragContext *context,
1783 GtkSelectionData *selection,
1788 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1790 if (selection->target == dnd_target_atom_group)
1791 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
1794 gtk_selection_data_set (selection, selection->target, 8,
1795 (guchar*) &drag_data, sizeof (drag_data));
1799 _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
1802 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1804 /* Check drag_source,
1805 * to work properly when called from gtk_tool_item_group_insert().
1807 if (!palette->priv->drag_source)
1810 if (GTK_IS_TOOL_ITEM (child) &&
1811 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
1813 /* Connect to child instead of the item itself,
1814 * to work arround bug 510377.
1816 if (GTK_IS_TOOL_BUTTON (child))
1817 child = gtk_bin_get_child (GTK_BIN (child));
1822 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1823 &dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1825 g_signal_connect (child, "drag-data-get",
1826 G_CALLBACK (gtk_tool_palette_item_drag_data_get),
1829 else if (GTK_IS_BUTTON (child) &&
1830 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
1832 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1833 &dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1835 g_signal_connect (child, "drag-data-get",
1836 G_CALLBACK (gtk_tool_palette_child_drag_data_get),
1842 * gtk_tool_palette_get_drag_target_item:
1844 * Gets the target entry for a dragged #GtkToolItem.
1846 * Returns: the #GtkTargetEntry for a dragged item.
1850 G_CONST_RETURN GtkTargetEntry*
1851 gtk_tool_palette_get_drag_target_item (void)
1853 return &dnd_targets[0];
1857 * gtk_tool_palette_get_drag_target_group:
1859 * Get the target entry for a dragged #GtkToolItemGroup.
1861 * Returns: the #GtkTargetEntry for a dragged group
1865 G_CONST_RETURN GtkTargetEntry*
1866 gtk_tool_palette_get_drag_target_group (void)
1868 return &dnd_targets[1];
1872 _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
1875 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1876 palette->priv->expanding_child = widget;
1880 * gtk_tool_palette_get_hadjustment:
1881 * @palette: a #GtkToolPalette
1883 * Gets the horizontal adjustment of the tool palette.
1885 * Returns: the horizontal adjustment of @palette
1890 gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
1892 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1894 return palette->priv->hadjustment;
1898 * gtk_tool_palette_get_vadjustment:
1899 * @palette: a #GtkToolPalette
1901 * Gets the vertical adjustment of the tool palette.
1903 * Returns: the vertical adjustment of @palette
1908 gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
1910 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1912 return palette->priv->vadjustment;
1916 _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
1918 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1920 return palette->priv->text_size_group;
1924 #define __GTK_TOOL_PALETTE_C__
1925 #include "gtkaliasdef.c"