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"
33 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
34 #define DEFAULT_ORIENTATION GTK_ORIENTATION_VERTICAL
35 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_ICONS
37 #define DEFAULT_CHILD_EXCLUSIVE FALSE
38 #define DEFAULT_CHILD_EXPAND FALSE
41 * SECTION:gtktoolpalette
42 * @Short_description: A tool palette with categories
43 * @Title: GtkToolPalette
45 * A #GtkToolPalette allows you to add #GtkToolItem<!-- -->s to a palette-like
46 * container with different categories and drag and drop support.
48 * A #GtkToolPalette is created with a call to gtk_tool_palette_new().
50 * #GtkToolItem<!-- -->s cannot be added directly to a #GtkToolPalette -
51 * instead they are added to a #GtkToolItemGroup which can than be added
52 * to a #GtkToolPalette. To add a #GtkToolItemGroup to a #GtkToolPalette,
53 * use gtk_container_add().
56 * GtkWidget *palette, *group;
59 * palette = gtk_tool_palette_new ();
60 * group = gtk_tool_item_group_new (_("Test Category"));
61 * gtk_container_add (GTK_CONTAINER (palette), group);
63 * item = gtk_tool_button_new_from_stock (GTK_STOCK_OK);
64 * gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
67 * The easiest way to use drag and drop with #GtkToolPalette is to call
68 * gtk_tool_palette_add_drag_dest() with the desired drag source @palette
69 * and the desired drag target @widget. Then gtk_tool_palette_get_drag_item()
70 * can be used to get the dragged item in the #GtkWidget::drag-data-received
71 * signal handler of the drag target.
75 * passive_canvas_drag_data_received (GtkWidget *widget,
76 * GdkDragContext *context,
79 * GtkSelectionData *selection,
87 * /<!-- -->* Get the dragged item *<!-- -->/
88 * palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context),
89 * GTK_TYPE_TOOL_PALETTE);
90 * if (palette != NULL)
91 * item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
94 * /<!-- -->* Do something with item *<!-- -->/
97 * GtkWidget *target, palette;
99 * palette = gtk_tool_palette_new ();
100 * target = gtk_drawing_area_new ();
102 * g_signal_connect (G_OBJECT (target), "drag-data-received",
103 * G_CALLBACK (passive_canvas_drag_data_received), NULL);
104 * gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target,
105 * GTK_DEST_DEFAULT_ALL,
106 * GTK_TOOL_PALETTE_DRAG_ITEMS,
113 typedef struct _GtkToolItemGroupInfo GtkToolItemGroupInfo;
114 typedef struct _GtkToolPaletteDragData GtkToolPaletteDragData;
128 CHILD_PROP_EXCLUSIVE,
132 struct _GtkToolItemGroupInfo
134 GtkToolItemGroup *widget;
136 guint notify_collapsed;
142 struct _GtkToolPalettePrivate
146 GtkAdjustment *hadjustment;
147 GtkAdjustment *vadjustment;
149 GtkIconSize icon_size;
150 gboolean icon_size_set;
151 GtkOrientation orientation;
152 GtkToolbarStyle style;
155 GtkWidget *expanding_child;
157 GtkSizeGroup *text_size_group;
159 GtkSettings *settings;
160 gulong settings_connection;
162 guint drag_source : 2;
165 struct _GtkToolPaletteDragData
167 GtkToolPalette *palette;
171 static GdkAtom dnd_target_atom_item = GDK_NONE;
172 static GdkAtom dnd_target_atom_group = GDK_NONE;
174 static const GtkTargetEntry dnd_targets[] =
176 { "application/x-gtk-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
177 { "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
180 G_DEFINE_TYPE_WITH_CODE (GtkToolPalette,
183 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
186 gtk_tool_palette_init (GtkToolPalette *palette)
188 palette->priv = G_TYPE_INSTANCE_GET_PRIVATE (palette,
189 GTK_TYPE_TOOL_PALETTE,
190 GtkToolPalettePrivate);
192 palette->priv->groups = g_ptr_array_sized_new (4);
193 g_ptr_array_set_free_func (palette->priv->groups, g_free);
195 palette->priv->icon_size = DEFAULT_ICON_SIZE;
196 palette->priv->icon_size_set = FALSE;
197 palette->priv->orientation = DEFAULT_ORIENTATION;
198 palette->priv->style = DEFAULT_TOOLBAR_STYLE;
199 palette->priv->style_set = FALSE;
201 palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
205 gtk_tool_palette_reconfigured (GtkToolPalette *palette)
209 for (i = 0; i < palette->priv->groups->len; ++i)
211 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
213 _gtk_tool_item_group_palette_reconfigured (info->widget);
216 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
220 gtk_tool_palette_set_property (GObject *object,
225 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
230 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
232 palette->priv->icon_size = g_value_get_enum (value);
233 gtk_tool_palette_reconfigured (palette);
237 case PROP_ICON_SIZE_SET:
238 if ((guint) g_value_get_enum (value) != palette->priv->icon_size)
240 palette->priv->icon_size_set = g_value_get_enum (value);
241 gtk_tool_palette_reconfigured (palette);
245 case PROP_ORIENTATION:
246 if ((guint) g_value_get_enum (value) != palette->priv->orientation)
248 palette->priv->orientation = g_value_get_enum (value);
249 gtk_tool_palette_reconfigured (palette);
253 case PROP_TOOLBAR_STYLE:
254 if ((guint) g_value_get_enum (value) != palette->priv->style)
256 palette->priv->style = g_value_get_enum (value);
257 gtk_tool_palette_reconfigured (palette);
262 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
268 gtk_tool_palette_get_property (GObject *object,
273 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
278 g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
281 case PROP_ICON_SIZE_SET:
282 g_value_set_boolean (value, palette->priv->icon_size_set);
285 case PROP_ORIENTATION:
286 g_value_set_enum (value, palette->priv->orientation);
289 case PROP_TOOLBAR_STYLE:
290 g_value_set_enum (value, gtk_tool_palette_get_style (palette));
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
300 gtk_tool_palette_dispose (GObject *object)
302 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
305 if (palette->priv->hadjustment)
307 g_object_unref (palette->priv->hadjustment);
308 palette->priv->hadjustment = NULL;
311 if (palette->priv->vadjustment)
313 g_object_unref (palette->priv->vadjustment);
314 palette->priv->vadjustment = NULL;
317 for (i = 0; i < palette->priv->groups->len; ++i)
319 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
321 if (group->notify_collapsed)
323 g_signal_handler_disconnect (group->widget, group->notify_collapsed);
324 group->notify_collapsed = 0;
328 if (palette->priv->text_size_group)
330 g_object_unref (palette->priv->text_size_group);
331 palette->priv->text_size_group = NULL;
334 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
338 gtk_tool_palette_finalize (GObject *object)
340 GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
342 g_ptr_array_free (palette->priv->groups, TRUE);
344 G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
348 gtk_tool_palette_size_request (GtkWidget *widget,
349 GtkRequisition *requisition)
351 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
352 GtkRequisition child_requisition;
356 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
358 requisition->width = 0;
359 requisition->height = 0;
361 for (i = 0; i < palette->priv->groups->len; ++i)
363 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
368 gtk_widget_size_request (GTK_WIDGET (group->widget), &child_requisition);
370 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
372 requisition->width = MAX (requisition->width, child_requisition.width);
373 requisition->height += child_requisition.height;
377 requisition->width += child_requisition.width;
378 requisition->height = MAX (requisition->height, child_requisition.height);
382 requisition->width += border_width * 2;
383 requisition->height += border_width * 2;
387 gtk_tool_palette_size_allocate (GtkWidget *widget,
388 GtkAllocation *allocation)
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;
403 gint min_offset = -1, max_offset = -1;
407 gint *group_sizes = g_newa (gint, palette->priv->groups->len);
409 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
410 GtkTextDirection direction = gtk_widget_get_direction (widget);
412 GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
414 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
416 adjustment = palette->priv->vadjustment;
417 page_size = allocation->height;
421 adjustment = palette->priv->hadjustment;
422 page_size = allocation->width;
426 offset = gtk_adjustment_get_value (adjustment);
427 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
428 GTK_TEXT_DIR_RTL == direction)
431 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
432 child_allocation.width = allocation->width - border_width * 2;
434 child_allocation.height = allocation->height - border_width * 2;
436 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
437 remaining_space = allocation->height;
439 remaining_space = allocation->width;
441 /* figure out the required size of all groups to be able to distribute the
442 * remaining space on allocation
444 for (i = 0; i < palette->priv->groups->len; ++i)
446 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
452 widget = GTK_WIDGET (group->widget);
454 if (gtk_tool_item_group_get_n_items (group->widget))
456 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
457 size = _gtk_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
459 size = _gtk_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
461 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
462 n_expand_groups += 1;
467 remaining_space -= size;
468 group_sizes[i] = size;
470 /* if the widget is currently expanding an offset which allows to
471 * display as much of the widget as possible is calculated
473 if (widget == palette->priv->expanding_child)
476 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
477 child_allocation.width : child_allocation.height;
484 for (j = 0; j < i; ++j)
485 min_offset += group_sizes[j];
487 max_offset = min_offset + group_sizes[i];
489 real_size = _gtk_tool_item_group_get_size_for_limit
490 (GTK_TOOL_ITEM_GROUP (widget), limit,
491 GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
494 if (size == real_size)
495 palette->priv->expanding_child = NULL;
499 if (n_expand_groups > 0)
501 remaining_space = MAX (0, remaining_space);
502 expand_space = remaining_space / n_expand_groups;
505 if (max_offset != -1)
508 GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
509 allocation->height : allocation->width;
511 offset = MIN (MAX (offset, max_offset - limit), min_offset);
514 if (remaining_space > 0)
518 child_allocation.y = border_width;
520 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
521 child_allocation.y -= offset;
525 /* allocate all groups at the calculated positions */
526 for (i = 0; i < palette->priv->groups->len; ++i)
528 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
534 widget = GTK_WIDGET (group->widget);
536 if (gtk_tool_item_group_get_n_items (group->widget))
538 gint size = group_sizes[i];
540 if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
542 size += MIN (expand_space, remaining_space);
543 remaining_space -= expand_space;
546 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
547 child_allocation.height = size;
549 child_allocation.width = size;
551 if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
552 GTK_TEXT_DIR_RTL == direction)
553 child_allocation.x = allocation->width - x - child_allocation.width;
555 child_allocation.x = x;
557 gtk_widget_size_allocate (widget, &child_allocation);
558 gtk_widget_show (widget);
560 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
561 child_allocation.y += child_allocation.height;
563 x += child_allocation.width;
566 gtk_widget_hide (widget);
569 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
571 child_allocation.y += border_width;
572 child_allocation.y += offset;
574 page_start = child_allocation.y;
584 /* update the scrollbar to match the displayed adjustment */
589 adjustment->page_increment = page_size * 0.9;
590 adjustment->step_increment = page_size * 0.1;
591 adjustment->page_size = page_size;
593 if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
594 GTK_TEXT_DIR_LTR == direction)
596 adjustment->lower = 0;
597 adjustment->upper = MAX (0, page_start);
599 value = MIN (offset, adjustment->upper - adjustment->page_size);
600 gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
604 adjustment->lower = page_size - MAX (0, page_start);
605 adjustment->upper = page_size;
609 value = MAX (offset, adjustment->lower);
610 gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
613 gtk_adjustment_changed (adjustment);
618 gtk_tool_palette_expose_event (GtkWidget *widget,
619 GdkEventExpose *event)
621 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
626 display = gdk_drawable_get_display (widget->window);
628 if (!gdk_display_supports_composite (display))
631 cr = gdk_cairo_create (widget->window);
632 gdk_cairo_region (cr, event->region);
635 cairo_push_group (cr);
637 for (i = 0; i < palette->priv->groups->len; ++i)
639 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
641 _gtk_tool_item_group_paint (info->widget, cr);
644 cairo_pop_group_to_source (cr);
653 gtk_tool_palette_realize (GtkWidget *widget)
655 GdkWindowAttr attributes;
656 gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
659 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
661 attributes.window_type = GDK_WINDOW_CHILD;
662 attributes.x = widget->allocation.x + border_width;
663 attributes.y = widget->allocation.y + border_width;
664 attributes.width = widget->allocation.width - border_width * 2;
665 attributes.height = widget->allocation.height - border_width * 2;
666 attributes.wclass = GDK_INPUT_OUTPUT;
667 attributes.visual = gtk_widget_get_visual (widget);
668 attributes.colormap = gtk_widget_get_colormap (widget);
669 attributes.event_mask = gtk_widget_get_events (widget)
670 | GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
671 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
672 | GDK_BUTTON_MOTION_MASK;
674 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
675 &attributes, attributes_mask);
677 gdk_window_set_user_data (widget->window, widget);
678 widget->style = gtk_style_attach (widget->style, widget->window);
679 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
680 gtk_widget_set_realized (widget, TRUE);
682 gtk_container_forall (GTK_CONTAINER (widget),
683 (GtkCallback) gtk_widget_set_parent_window,
686 gtk_widget_queue_resize_no_redraw (widget);
690 gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
693 GtkWidget *widget = GTK_WIDGET (data);
694 gtk_tool_palette_size_allocate (widget, &widget->allocation);
698 gtk_tool_palette_set_scroll_adjustments (GtkWidget *widget,
699 GtkAdjustment *hadjustment,
700 GtkAdjustment *vadjustment)
702 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
705 g_object_ref_sink (hadjustment);
707 g_object_ref_sink (vadjustment);
709 if (palette->priv->hadjustment)
710 g_object_unref (palette->priv->hadjustment);
711 if (palette->priv->vadjustment)
712 g_object_unref (palette->priv->vadjustment);
714 palette->priv->hadjustment = hadjustment;
715 palette->priv->vadjustment = vadjustment;
717 if (palette->priv->hadjustment)
718 g_signal_connect (palette->priv->hadjustment, "value-changed",
719 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
721 if (palette->priv->vadjustment)
722 g_signal_connect (palette->priv->vadjustment, "value-changed",
723 G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
728 gtk_tool_palette_add (GtkContainer *container,
731 GtkToolPalette *palette;
732 GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
734 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
735 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
737 palette = GTK_TOOL_PALETTE (container);
739 g_ptr_array_add (palette->priv->groups, info);
740 info->pos = palette->priv->groups->len - 1;
741 info->widget = g_object_ref_sink (child);
743 gtk_widget_set_parent (child, GTK_WIDGET (palette));
747 gtk_tool_palette_remove (GtkContainer *container,
750 GtkToolPalette *palette;
753 g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
754 palette = GTK_TOOL_PALETTE (container);
756 for (i = 0; i < palette->priv->groups->len; ++i)
758 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
759 if (GTK_WIDGET(info->widget) == child)
761 g_object_unref (child);
762 gtk_widget_unparent (child);
764 g_ptr_array_remove_index (palette->priv->groups, i);
770 gtk_tool_palette_forall (GtkContainer *container,
772 GtkCallback callback,
773 gpointer callback_data)
775 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
779 for (i = 0; i < palette->priv->groups->len; ++i)
781 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
783 callback (GTK_WIDGET (info->widget),
789 gtk_tool_palette_child_type (GtkContainer *container)
791 return GTK_TYPE_TOOL_ITEM_GROUP;
795 gtk_tool_palette_set_child_property (GtkContainer *container,
801 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
805 case CHILD_PROP_EXCLUSIVE:
806 gtk_tool_palette_set_exclusive (palette, GTK_TOOL_ITEM_GROUP (child),
807 g_value_get_boolean (value));
810 case CHILD_PROP_EXPAND:
811 gtk_tool_palette_set_expand (palette, GTK_TOOL_ITEM_GROUP (child),
812 g_value_get_boolean (value));
816 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
822 gtk_tool_palette_get_child_property (GtkContainer *container,
828 GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
832 case CHILD_PROP_EXCLUSIVE:
833 g_value_set_boolean (value,
834 gtk_tool_palette_get_exclusive (palette, GTK_TOOL_ITEM_GROUP (child)));
837 case CHILD_PROP_EXPAND:
838 g_value_set_boolean (value,
839 gtk_tool_palette_get_expand (palette, GTK_TOOL_ITEM_GROUP (child)));
843 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
849 style_change_notify (GtkToolPalette *palette)
851 GtkToolPalettePrivate* priv = palette->priv;
853 if (!priv->style_set)
855 /* pretend it was set, then unset, thus reverting to new default */
856 priv->style_set = TRUE;
857 gtk_tool_palette_unset_style (palette);
862 icon_size_change_notify (GtkToolPalette *palette)
864 GtkToolPalettePrivate* priv = palette->priv;
866 if (!priv->icon_size_set)
868 /* pretend it was set, then unset, thus reverting to new default */
869 priv->icon_size_set = TRUE;
870 gtk_tool_palette_unset_icon_size (palette);
875 gtk_tool_palette_settings_change_notify (GtkSettings *settings,
876 const GParamSpec *pspec,
877 GtkToolPalette *palette)
879 if (strcmp (pspec->name, "gtk-toolbar-style") == 0)
880 style_change_notify (palette);
881 else if (strcmp (pspec->name, "gtk-toolbar-icon-size") == 0)
882 icon_size_change_notify (palette);
886 gtk_tool_palette_screen_changed (GtkWidget *widget,
887 GdkScreen *previous_screen)
889 GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
890 GtkToolPalettePrivate* priv = palette->priv;
891 GtkSettings *old_settings = priv->settings;
892 GtkSettings *settings;
894 if (gtk_widget_has_screen (GTK_WIDGET (palette)))
895 settings = gtk_widget_get_settings (GTK_WIDGET (palette));
899 if (settings == old_settings)
904 g_signal_handler_disconnect (old_settings, priv->settings_connection);
905 g_object_unref (old_settings);
910 priv->settings_connection =
911 g_signal_connect (settings, "notify",
912 G_CALLBACK (gtk_tool_palette_settings_change_notify),
914 priv->settings = g_object_ref (settings);
917 priv->settings = NULL;
919 gtk_tool_palette_reconfigured (palette);
924 gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
926 GObjectClass *oclass = G_OBJECT_CLASS (cls);
927 GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
928 GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
930 oclass->set_property = gtk_tool_palette_set_property;
931 oclass->get_property = gtk_tool_palette_get_property;
932 oclass->dispose = gtk_tool_palette_dispose;
933 oclass->finalize = gtk_tool_palette_finalize;
935 wclass->size_request = gtk_tool_palette_size_request;
936 wclass->size_allocate = gtk_tool_palette_size_allocate;
937 wclass->expose_event = gtk_tool_palette_expose_event;
938 wclass->realize = gtk_tool_palette_realize;
940 cclass->add = gtk_tool_palette_add;
941 cclass->remove = gtk_tool_palette_remove;
942 cclass->forall = gtk_tool_palette_forall;
943 cclass->child_type = gtk_tool_palette_child_type;
944 cclass->set_child_property = gtk_tool_palette_set_child_property;
945 cclass->get_child_property = gtk_tool_palette_get_child_property;
947 cls->set_scroll_adjustments = gtk_tool_palette_set_scroll_adjustments;
949 /* Handle screen-changed so we can update our GtkSettings.
951 wclass->screen_changed = gtk_tool_palette_screen_changed;
954 * GtkToolPalette::set-scroll-adjustments:
955 * @widget: the GtkToolPalette that received the signal
956 * @hadjustment: The horizontal adjustment
957 * @vadjustment: The vertical adjustment
959 * Set the scroll adjustments for the viewport.
960 * Usually scrolled containers like GtkScrolledWindow will emit this
961 * signal to connect two instances of GtkScrollbar to the scroll
962 * directions of the GtkToolpalette.
966 wclass->set_scroll_adjustments_signal =
967 g_signal_new ("set-scroll-adjustments",
968 G_TYPE_FROM_CLASS (oclass),
969 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
970 G_STRUCT_OFFSET (GtkToolPaletteClass, set_scroll_adjustments),
972 _gtk_marshal_VOID__OBJECT_OBJECT,
975 GTK_TYPE_ADJUSTMENT);
977 g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
980 * GtkToolPalette:icon-size:
982 * The size of the icons in a tool palette is normally determined by
983 * the #GtkSettings:toolbar-icon-size setting. When this property is set,
984 * it overrides the setting.
986 * This should only be used for special-purpose tool palettes, normal
987 * application tool palettes should respect the user preferences for the
992 g_object_class_install_property (oclass,
994 g_param_spec_enum ("icon-size",
996 P_("Size of icons in this tool palette"),
999 GTK_PARAM_READWRITE));
1002 * GtkToolPalette:icon-size-set:
1004 * Is %TRUE if the #GtkToolPalette:icon-size property has been set.
1008 g_object_class_install_property (oclass,
1010 g_param_spec_boolean ("icon-size-set",
1011 P_("Icon size set"),
1012 P_("Whether the icon-size property has been set"),
1014 GTK_PARAM_READWRITE));
1017 * GtkToolPalette:toolbar-style:
1019 * The style of items in the tool palette.
1023 g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
1024 g_param_spec_enum ("toolbar-style",
1025 P_("Toolbar Style"),
1026 P_("Style of items in the tool palette"),
1027 GTK_TYPE_TOOLBAR_STYLE,
1028 DEFAULT_TOOLBAR_STYLE,
1029 GTK_PARAM_READWRITE));
1033 * GtkToolPalette:exclusive:
1035 * Whether the item group should be the only one that is expanded
1040 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
1041 g_param_spec_boolean ("exclusive",
1043 P_("Whether the item group should be the only expanded at a given time"),
1044 DEFAULT_CHILD_EXCLUSIVE,
1045 GTK_PARAM_READWRITE));
1048 * GtkToolPalette:expand:
1050 * Whether the item group should receive extra space when the palette grows.
1055 gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
1056 g_param_spec_boolean ("expand",
1058 P_("Whether the item group should receive extra space when the palette grows"),
1059 DEFAULT_CHILD_EXPAND,
1060 GTK_PARAM_READWRITE));
1062 g_type_class_add_private (cls, sizeof (GtkToolPalettePrivate));
1064 dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
1065 dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
1069 * gtk_tool_palette_new:
1071 * Creates a new tool palette.
1073 * Returns: a new #GtkToolPalette
1078 gtk_tool_palette_new (void)
1080 return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
1084 * gtk_tool_palette_set_icon_size:
1085 * @palette: a #GtkToolPalette
1086 * @icon_size: (type int): the #GtkIconSize that icons in the tool
1087 * palette shall have
1089 * Sets the size of icons in the tool palette.
1094 gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
1095 GtkIconSize icon_size)
1097 GtkToolPalettePrivate *priv;
1099 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1100 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
1102 priv = palette->priv;
1104 if (!priv->icon_size_set)
1106 priv->icon_size_set = TRUE;
1107 g_object_notify (G_OBJECT (palette), "icon-size-set");
1110 if (priv->icon_size == icon_size)
1113 priv->icon_size = icon_size;
1114 g_object_notify (G_OBJECT (palette), "icon-size");
1116 gtk_tool_palette_reconfigured (palette);
1118 gtk_widget_queue_resize (GTK_WIDGET (palette));
1121 static GtkSettings *
1122 toolpalette_get_settings (GtkToolPalette *palette)
1124 GtkToolPalettePrivate *priv = palette->priv;
1125 return priv->settings;
1129 * gtk_tool_palette_unset_icon_size:
1130 * @palette: a #GtkToolPalette
1132 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(),
1133 * so that user preferences will be used to determine the icon size.
1138 gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
1140 GtkToolPalettePrivate* priv = palette->priv;
1143 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1145 if (palette->priv->icon_size_set)
1147 GtkSettings *settings = toolpalette_get_settings (palette);
1151 g_object_get (settings,
1152 "gtk-toolbar-icon-size", &size,
1156 size = DEFAULT_ICON_SIZE;
1158 if (size != palette->priv->icon_size)
1160 gtk_tool_palette_set_icon_size (palette, size);
1161 g_object_notify (G_OBJECT (palette), "icon-size");
1164 priv->icon_size_set = FALSE;
1165 g_object_notify (G_OBJECT (palette), "icon-size-set");
1169 /* Set the "toolbar-style" property and do appropriate things.
1170 * GtkToolbar does this by emitting a signal instead of just
1171 * calling a function...
1174 gtk_tool_palette_change_style (GtkToolPalette *palette,
1175 GtkToolbarStyle style)
1177 GtkToolPalettePrivate* priv = palette->priv;
1179 if (priv->style != style)
1181 priv->style = style;
1183 gtk_tool_palette_reconfigured (palette);
1185 gtk_widget_queue_resize (GTK_WIDGET (palette));
1186 g_object_notify (G_OBJECT (palette), "toolbar-style");
1192 * gtk_tool_palette_set_style:
1193 * @palette: a #GtkToolPalette
1194 * @style: the #GtkToolbarStyle that items in the tool palette shall have
1196 * Sets the style (text, icons or both) of items in the tool palette.
1201 gtk_tool_palette_set_style (GtkToolPalette *palette,
1202 GtkToolbarStyle style)
1204 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1206 palette->priv->style_set = TRUE;
1207 gtk_tool_palette_change_style (palette, style);
1212 * gtk_tool_palette_unset_style:
1213 * @palette: a #GtkToolPalette
1215 * Unsets a toolbar style set with gtk_tool_palette_set_style(),
1216 * so that user preferences will be used to determine the toolbar style.
1221 gtk_tool_palette_unset_style (GtkToolPalette *palette)
1223 GtkToolPalettePrivate* priv = palette->priv;
1224 GtkToolbarStyle style;
1226 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1228 if (priv->style_set)
1230 GtkSettings *settings = toolpalette_get_settings (palette);
1233 g_object_get (settings,
1234 "gtk-toolbar-style", &style,
1237 style = DEFAULT_TOOLBAR_STYLE;
1239 if (style != priv->style)
1240 gtk_tool_palette_change_style (palette, style);
1242 priv->style_set = FALSE;
1247 * gtk_tool_palette_get_icon_size:
1248 * @palette: a #GtkToolPalette
1250 * Gets the size of icons in the tool palette.
1251 * See gtk_tool_palette_set_icon_size().
1253 * Returns: (type int): the #GtkIconSize of icons in the tool palette
1258 gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
1260 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
1262 return palette->priv->icon_size;
1266 * gtk_tool_palette_get_style:
1267 * @palette: a #GtkToolPalette
1269 * Gets the style (icons, text or both) of items in the tool palette.
1271 * Returns: the #GtkToolbarStyle of items in the tool palette.
1276 gtk_tool_palette_get_style (GtkToolPalette *palette)
1278 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
1280 return palette->priv->style;
1284 _gtk_tool_palette_compare_groups (gconstpointer a,
1287 const GtkToolItemGroupInfo *group_a = a;
1288 const GtkToolItemGroupInfo *group_b = b;
1290 return group_a->pos - group_b->pos;
1294 * gtk_tool_palette_set_group_position:
1295 * @palette: a #GtkToolPalette
1296 * @group: a #GtkToolItemGroup which is a child of palette
1297 * @position: a new index for group
1299 * Sets the position of the group as an index of the tool palette.
1300 * If position is 0 the group will become the first child, if position is
1301 * -1 it will become the last child.
1306 gtk_tool_palette_set_group_position (GtkToolPalette *palette,
1307 GtkToolItemGroup *group,
1310 GtkToolItemGroupInfo *group_new;
1311 GtkToolItemGroupInfo *group_old;
1314 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1315 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1316 g_return_if_fail (position >= -1);
1319 position = palette->priv->groups->len - 1;
1321 g_return_if_fail ((guint) position < palette->priv->groups->len);
1323 group_new = g_ptr_array_index (palette->priv->groups, position);
1325 if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
1328 old_position = gtk_tool_palette_get_group_position (palette, group);
1329 g_return_if_fail (old_position >= 0);
1331 group_old = g_ptr_array_index (palette->priv->groups, old_position);
1333 group_new->pos = position;
1334 group_old->pos = old_position;
1336 g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups);
1338 gtk_widget_queue_resize (GTK_WIDGET (palette));
1342 gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
1346 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1349 if (gtk_tool_item_group_get_collapsed (group))
1352 for (i = 0; i < palette->priv->groups->len; ++i)
1354 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1355 GtkToolItemGroup *current_group = info->widget;
1357 if (current_group && current_group != group)
1358 gtk_tool_item_group_set_collapsed (current_group, TRUE);
1363 * gtk_tool_palette_set_exclusive:
1364 * @palette: a #GtkToolPalette
1365 * @group: a #GtkToolItemGroup which is a child of palette
1366 * @exclusive: whether the group should be exclusive or not
1368 * Sets whether the group should be exclusive or not.
1369 * If an exclusive group is expanded all other groups are collapsed.
1374 gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
1375 GtkToolItemGroup *group,
1378 GtkToolItemGroupInfo *group_info;
1381 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1382 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1384 position = gtk_tool_palette_get_group_position (palette, group);
1385 g_return_if_fail (position >= 0);
1387 group_info = g_ptr_array_index (palette->priv->groups, position);
1389 if (exclusive == group_info->exclusive)
1392 group_info->exclusive = exclusive;
1394 if (group_info->exclusive != (0 != group_info->notify_collapsed))
1396 if (group_info->exclusive)
1398 group_info->notify_collapsed =
1399 g_signal_connect (group, "notify::collapsed",
1400 G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
1405 g_signal_handler_disconnect (group, group_info->notify_collapsed);
1406 group_info->notify_collapsed = 0;
1410 gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
1411 gtk_widget_child_notify (GTK_WIDGET (group), "exclusive");
1415 * gtk_tool_palette_set_expand:
1416 * @palette: a #GtkToolPalette
1417 * @group: a #GtkToolItemGroup which is a child of palette
1418 * @expand: whether the group should be given extra space
1420 * Sets whether the group should be given extra space.
1425 gtk_tool_palette_set_expand (GtkToolPalette *palette,
1426 GtkToolItemGroup *group,
1429 GtkToolItemGroupInfo *group_info;
1432 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1433 g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
1435 position = gtk_tool_palette_get_group_position (palette, group);
1436 g_return_if_fail (position >= 0);
1438 group_info = g_ptr_array_index (palette->priv->groups, position);
1440 if (expand != group_info->expand)
1442 group_info->expand = expand;
1443 gtk_widget_queue_resize (GTK_WIDGET (palette));
1444 gtk_widget_child_notify (GTK_WIDGET (group), "expand");
1449 * gtk_tool_palette_get_group_position:
1450 * @palette: a #GtkToolPalette
1451 * @group: a #GtkToolItemGroup
1453 * Gets the position of @group in @palette as index.
1454 * See gtk_tool_palette_set_group_position().
1456 * Returns: the index of group or -1 if @group is not a child of @palette
1461 gtk_tool_palette_get_group_position (GtkToolPalette *palette,
1462 GtkToolItemGroup *group)
1466 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
1467 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
1469 for (i = 0; i < palette->priv->groups->len; ++i)
1471 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1472 if ((gpointer) group == info->widget)
1480 * gtk_tool_palette_get_exclusive:
1481 * @palette: a #GtkToolPalette
1482 * @group: a #GtkToolItemGroup which is a child of palette
1484 * Gets whether @group is exclusive or not.
1485 * See gtk_tool_palette_set_exclusive().
1487 * Returns: %TRUE if @group is exclusive
1492 gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
1493 GtkToolItemGroup *group)
1496 GtkToolItemGroupInfo *info;
1498 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
1499 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
1501 position = gtk_tool_palette_get_group_position (palette, group);
1502 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
1504 info = g_ptr_array_index (palette->priv->groups, position);
1506 return info->exclusive;
1510 * gtk_tool_palette_get_expand:
1511 * @palette: a #GtkToolPalette
1512 * @group: a #GtkToolItemGroup which is a child of palette
1514 * Gets whether group should be given extra space.
1515 * See gtk_tool_palette_set_expand().
1517 * Returns: %TRUE if group should be given extra space, %FALSE otherwise
1522 gtk_tool_palette_get_expand (GtkToolPalette *palette,
1523 GtkToolItemGroup *group)
1526 GtkToolItemGroupInfo *info;
1528 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
1529 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
1531 position = gtk_tool_palette_get_group_position (palette, group);
1532 g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
1534 info = g_ptr_array_index (palette->priv->groups, position);
1536 return info->expand;
1540 * gtk_tool_palette_get_drop_item:
1541 * @palette: a #GtkToolPalette
1542 * @x: the x position
1543 * @y: the y position
1545 * Gets the item at position (x, y).
1546 * See gtk_tool_palette_get_drop_group().
1548 * Returns: the #GtkToolItem at position or %NULL if there is no such item
1553 gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
1557 GtkToolItemGroup *group = gtk_tool_palette_get_drop_group (palette, x, y);
1558 GtkWidget *widget = GTK_WIDGET (group);
1561 return gtk_tool_item_group_get_drop_item (group,
1562 x - widget->allocation.x,
1563 y - widget->allocation.y);
1569 * gtk_tool_palette_get_drop_group:
1570 * @palette: a #GtkToolPalette
1571 * @x: the x position
1572 * @y: the y position
1574 * Gets the group at position (x, y).
1576 * Returns: the #GtkToolItemGroup at position or %NULL
1577 * if there is no such group
1582 gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
1586 GtkAllocation *allocation;
1589 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1591 allocation = >K_WIDGET (palette)->allocation;
1593 g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
1594 g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
1596 for (i = 0; i < palette->priv->groups->len; ++i)
1598 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1605 widget = GTK_WIDGET (group->widget);
1607 x0 = x - widget->allocation.x;
1608 y0 = y - widget->allocation.y;
1610 if (x0 >= 0 && x0 < widget->allocation.width &&
1611 y0 >= 0 && y0 < widget->allocation.height)
1612 return GTK_TOOL_ITEM_GROUP (widget);
1619 * gtk_tool_palette_get_drag_item:
1620 * @palette: a #GtkToolPalette
1621 * @selection: a #GtkSelectionData
1623 * Get the dragged item from the selection.
1624 * This could be a #GtkToolItem or a #GtkToolItemGroup.
1626 * Returns: the dragged item in selection
1631 gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
1632 const GtkSelectionData *selection)
1634 GtkToolPaletteDragData *data;
1636 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1637 g_return_val_if_fail (NULL != selection, NULL);
1639 g_return_val_if_fail (selection->format == 8, NULL);
1640 g_return_val_if_fail (selection->length == sizeof (GtkToolPaletteDragData), NULL);
1641 g_return_val_if_fail (selection->target == dnd_target_atom_item ||
1642 selection->target == dnd_target_atom_group,
1645 data = (GtkToolPaletteDragData*) selection->data;
1647 g_return_val_if_fail (data->palette == palette, NULL);
1649 if (dnd_target_atom_item == selection->target)
1650 g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
1651 else if (dnd_target_atom_group == selection->target)
1652 g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
1658 * gtk_tool_palette_set_drag_source:
1659 * @palette: a #GtkToolPalette
1660 * @targets: the #GtkToolPaletteDragTarget<!-- -->s
1661 * which the widget should support
1663 * Sets the tool palette as a drag source.
1664 * Enables all groups and items in the tool palette as drag sources
1665 * on button 1 and button 3 press with copy and move actions.
1666 * See gtk_drag_source_set().
1671 gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
1672 GtkToolPaletteDragTargets targets)
1676 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1678 if ((palette->priv->drag_source & targets) == targets)
1681 palette->priv->drag_source |= targets;
1683 for (i = 0; i < palette->priv->groups->len; ++i)
1685 GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
1687 gtk_container_forall (GTK_CONTAINER (info->widget),
1688 _gtk_tool_palette_child_set_drag_source,
1694 * gtk_tool_palette_add_drag_dest:
1695 * @palette: a #GtkToolPalette
1696 * @widget: a #GtkWidget which should be a drag destination for @palette
1697 * @flags: the flags that specify what actions GTK+ should take for drops
1699 * @targets: the #GtkToolPaletteDragTarget<!-- -->s which the widget
1701 * @actions: the #GdkDragAction<!-- -->s which the widget should suppport
1703 * Sets @palette as drag source (see gtk_tool_palette_set_drag_source())
1704 * and sets @widget as a drag destination for drags from @palette.
1705 * See gtk_drag_dest_set().
1710 gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
1712 GtkDestDefaults flags,
1713 GtkToolPaletteDragTargets targets,
1714 GdkDragAction actions)
1716 GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
1719 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1720 g_return_if_fail (GTK_IS_WIDGET (widget));
1722 gtk_tool_palette_set_drag_source (palette,
1725 if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
1726 entries[n_entries++] = dnd_targets[0];
1727 if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
1728 entries[n_entries++] = dnd_targets[1];
1730 gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
1734 _gtk_tool_palette_get_item_size (GtkToolPalette *palette,
1735 GtkRequisition *item_size,
1736 gboolean homogeneous_only,
1737 gint *requested_rows)
1739 GtkRequisition max_requisition;
1743 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1744 g_return_if_fail (NULL != item_size);
1746 max_requisition.width = 0;
1747 max_requisition.height = 0;
1750 /* iterate over all groups and calculate the max item_size and max row request */
1751 for (i = 0; i < palette->priv->groups->len; ++i)
1753 GtkRequisition requisition;
1755 GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
1760 _gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
1762 max_requisition.width = MAX (max_requisition.width, requisition.width);
1763 max_requisition.height = MAX (max_requisition.height, requisition.height);
1764 max_rows = MAX (max_rows, rows);
1767 *item_size = max_requisition;
1769 *requested_rows = max_rows;
1773 gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
1774 GdkDragContext *context,
1775 GtkSelectionData *selection,
1780 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1782 if (selection->target == dnd_target_atom_item)
1783 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
1786 gtk_selection_data_set (selection, selection->target, 8,
1787 (guchar*) &drag_data, sizeof (drag_data));
1791 gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
1792 GdkDragContext *context,
1793 GtkSelectionData *selection,
1798 GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
1800 if (selection->target == dnd_target_atom_group)
1801 drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
1804 gtk_selection_data_set (selection, selection->target, 8,
1805 (guchar*) &drag_data, sizeof (drag_data));
1809 _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
1812 GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
1814 /* Check drag_source,
1815 * to work properly when called from gtk_tool_item_group_insert().
1817 if (!palette->priv->drag_source)
1820 if (GTK_IS_TOOL_ITEM (child) &&
1821 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
1823 /* Connect to child instead of the item itself,
1824 * to work arround bug 510377.
1826 if (GTK_IS_TOOL_BUTTON (child))
1827 child = gtk_bin_get_child (GTK_BIN (child));
1832 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1833 &dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1835 g_signal_connect (child, "drag-data-get",
1836 G_CALLBACK (gtk_tool_palette_item_drag_data_get),
1839 else if (GTK_IS_BUTTON (child) &&
1840 (palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
1842 gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
1843 &dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
1845 g_signal_connect (child, "drag-data-get",
1846 G_CALLBACK (gtk_tool_palette_child_drag_data_get),
1852 * gtk_tool_palette_get_drag_target_item:
1854 * Gets the target entry for a dragged #GtkToolItem.
1856 * Returns: the #GtkTargetEntry for a dragged item.
1860 G_CONST_RETURN GtkTargetEntry*
1861 gtk_tool_palette_get_drag_target_item (void)
1863 return &dnd_targets[0];
1867 * gtk_tool_palette_get_drag_target_group:
1869 * Get the target entry for a dragged #GtkToolItemGroup.
1871 * Returns: the #GtkTargetEntry for a dragged group
1875 G_CONST_RETURN GtkTargetEntry*
1876 gtk_tool_palette_get_drag_target_group (void)
1878 return &dnd_targets[1];
1882 _gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
1885 g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
1886 palette->priv->expanding_child = widget;
1890 * gtk_tool_palette_get_hadjustment:
1891 * @palette: a #GtkToolPalette
1893 * Gets the horizontal adjustment of the tool palette.
1895 * Returns: the horizontal adjustment of @palette
1900 gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
1902 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1904 return palette->priv->hadjustment;
1908 * gtk_tool_palette_get_vadjustment:
1909 * @palette: a #GtkToolPalette
1911 * Gets the vertical adjustment of the tool palette.
1913 * Returns: the vertical adjustment of @palette
1918 gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
1920 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1922 return palette->priv->vadjustment;
1926 _gtk_tool_palette_get_size_group (GtkToolPalette *palette)
1928 g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
1930 return palette->priv->text_size_group;