2009-07-13 15:38:34 +00:00
|
|
|
/* GtkToolPalette -- A tool palette with categories and DnD support
|
|
|
|
* Copyright (C) 2008 Openismus GmbH
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Mathias Hasselmann
|
|
|
|
*/
|
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
#include "gtktoolpaletteprivate.h"
|
|
|
|
#include "gtkmarshalers.h"
|
2011-01-04 19:51:19 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2009-11-27 04:52:20 +00:00
|
|
|
#include "gtkprivate.h"
|
2010-10-18 04:21:39 +00:00
|
|
|
#include "gtkscrollable.h"
|
2011-01-30 08:12:49 +00:00
|
|
|
#include "gtkorientableprivate.h"
|
2009-11-27 04:52:20 +00:00
|
|
|
#include "gtkintl.h"
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
|
|
|
|
#define DEFAULT_ORIENTATION GTK_ORIENTATION_VERTICAL
|
|
|
|
#define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_ICONS
|
|
|
|
|
|
|
|
#define DEFAULT_CHILD_EXCLUSIVE FALSE
|
|
|
|
#define DEFAULT_CHILD_EXPAND FALSE
|
|
|
|
|
|
|
|
/**
|
2009-11-27 04:52:20 +00:00
|
|
|
* SECTION:gtktoolpalette
|
|
|
|
* @Short_description: A tool palette with categories
|
|
|
|
* @Title: GtkToolPalette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2014-02-09 22:24:06 +00:00
|
|
|
* A #GtkToolPalette allows you to add #GtkToolItems to a palette-like
|
2009-11-27 04:52:20 +00:00
|
|
|
* container with different categories and drag and drop support.
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* A #GtkToolPalette is created with a call to gtk_tool_palette_new().
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2014-02-09 22:24:06 +00:00
|
|
|
* #GtkToolItems cannot be added directly to a #GtkToolPalette -
|
2009-11-27 04:52:20 +00:00
|
|
|
* instead they are added to a #GtkToolItemGroup which can than be added
|
|
|
|
* to a #GtkToolPalette. To add a #GtkToolItemGroup to a #GtkToolPalette,
|
|
|
|
* use gtk_container_add().
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
* |[<!-- language="C" -->
|
2009-07-13 15:38:34 +00:00
|
|
|
* GtkWidget *palette, *group;
|
|
|
|
* GtkToolItem *item;
|
|
|
|
*
|
|
|
|
* palette = gtk_tool_palette_new ();
|
|
|
|
* group = gtk_tool_item_group_new (_("Test Category"));
|
|
|
|
* gtk_container_add (GTK_CONTAINER (palette), group);
|
|
|
|
*
|
2013-06-24 23:28:53 +00:00
|
|
|
* item = gtk_tool_button_new_new (NULL, _("_Open"));
|
|
|
|
* gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-open");
|
2009-07-13 15:38:34 +00:00
|
|
|
* gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
|
|
|
|
* ]|
|
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* The easiest way to use drag and drop with #GtkToolPalette is to call
|
|
|
|
* gtk_tool_palette_add_drag_dest() with the desired drag source @palette
|
|
|
|
* and the desired drag target @widget. Then gtk_tool_palette_get_drag_item()
|
|
|
|
* can be used to get the dragged item in the #GtkWidget::drag-data-received
|
|
|
|
* signal handler of the drag target.
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
* |[<!-- language="C" -->
|
2009-07-13 15:38:34 +00:00
|
|
|
* static void
|
|
|
|
* passive_canvas_drag_data_received (GtkWidget *widget,
|
|
|
|
* GdkDragContext *context,
|
|
|
|
* gint x,
|
|
|
|
* gint y,
|
|
|
|
* GtkSelectionData *selection,
|
|
|
|
* guint info,
|
|
|
|
* guint time,
|
|
|
|
* gpointer data)
|
|
|
|
* {
|
|
|
|
* GtkWidget *palette;
|
|
|
|
* GtkWidget *item;
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
* // Get the dragged item
|
2009-11-27 04:52:20 +00:00
|
|
|
* palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context),
|
|
|
|
* GTK_TYPE_TOOL_PALETTE);
|
2009-07-13 15:38:34 +00:00
|
|
|
* if (palette != NULL)
|
2009-11-27 04:52:20 +00:00
|
|
|
* item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette),
|
|
|
|
* selection);
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
* // Do something with item
|
2009-07-13 15:38:34 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* GtkWidget *target, palette;
|
|
|
|
*
|
|
|
|
* palette = gtk_tool_palette_new ();
|
|
|
|
* target = gtk_drawing_area_new ();
|
|
|
|
*
|
|
|
|
* g_signal_connect (G_OBJECT (target), "drag-data-received",
|
2009-11-11 08:42:49 +00:00
|
|
|
* G_CALLBACK (passive_canvas_drag_data_received), NULL);
|
2009-07-13 15:38:34 +00:00
|
|
|
* gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target,
|
|
|
|
* GTK_DEST_DEFAULT_ALL,
|
|
|
|
* GTK_TOOL_PALETTE_DRAG_ITEMS,
|
|
|
|
* GDK_ACTION_COPY);
|
|
|
|
* ]|
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _GtkToolItemGroupInfo GtkToolItemGroupInfo;
|
|
|
|
typedef struct _GtkToolPaletteDragData GtkToolPaletteDragData;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_NONE,
|
|
|
|
PROP_ICON_SIZE,
|
2009-07-16 15:51:55 +00:00
|
|
|
PROP_ICON_SIZE_SET,
|
2009-07-13 15:38:34 +00:00
|
|
|
PROP_ORIENTATION,
|
|
|
|
PROP_TOOLBAR_STYLE,
|
2010-10-18 04:21:39 +00:00
|
|
|
PROP_HADJUSTMENT,
|
2010-10-26 00:59:02 +00:00
|
|
|
PROP_VADJUSTMENT,
|
|
|
|
PROP_HSCROLL_POLICY,
|
|
|
|
PROP_VSCROLL_POLICY
|
2009-07-13 15:38:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHILD_PROP_NONE,
|
|
|
|
CHILD_PROP_EXCLUSIVE,
|
|
|
|
CHILD_PROP_EXPAND,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkToolItemGroupInfo
|
|
|
|
{
|
|
|
|
GtkToolItemGroup *widget;
|
|
|
|
|
2010-10-08 00:37:23 +00:00
|
|
|
gulong notify_collapsed;
|
2009-11-09 21:16:15 +00:00
|
|
|
guint pos;
|
2009-07-13 15:38:34 +00:00
|
|
|
guint exclusive : 1;
|
|
|
|
guint expand : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkToolPalettePrivate
|
|
|
|
{
|
2009-11-09 21:16:15 +00:00
|
|
|
GPtrArray* groups;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
GtkAdjustment *hadjustment;
|
|
|
|
GtkAdjustment *vadjustment;
|
|
|
|
|
|
|
|
GtkIconSize icon_size;
|
2009-07-16 15:51:55 +00:00
|
|
|
gboolean icon_size_set;
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkOrientation orientation;
|
|
|
|
GtkToolbarStyle style;
|
2009-07-16 15:51:55 +00:00
|
|
|
gboolean style_set;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
GtkWidget *expanding_child;
|
|
|
|
|
|
|
|
GtkSizeGroup *text_size_group;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
guint drag_source : 2;
|
2010-10-26 00:59:02 +00:00
|
|
|
|
|
|
|
/* GtkScrollablePolicy needs to be checked when
|
|
|
|
* driving the scrollable adjustment values */
|
|
|
|
guint hscroll_policy : 1;
|
|
|
|
guint vscroll_policy : 1;
|
2009-07-13 15:38:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkToolPaletteDragData
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette;
|
|
|
|
GtkWidget *item;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GdkAtom dnd_target_atom_item = GDK_NONE;
|
|
|
|
static GdkAtom dnd_target_atom_group = GDK_NONE;
|
|
|
|
|
|
|
|
static const GtkTargetEntry dnd_targets[] =
|
|
|
|
{
|
2009-11-09 21:16:15 +00:00
|
|
|
{ "application/x-gtk-tool-palette-item", GTK_TARGET_SAME_APP, 0 },
|
|
|
|
{ "application/x-gtk-tool-palette-group", GTK_TARGET_SAME_APP, 0 },
|
2009-07-13 15:38:34 +00:00
|
|
|
};
|
|
|
|
|
2010-10-18 04:21:39 +00:00
|
|
|
static void gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
|
|
|
|
GtkAdjustment *adjustment);
|
|
|
|
static void gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
|
|
|
|
GtkAdjustment *adjustment);
|
|
|
|
|
|
|
|
|
2009-07-14 17:11:20 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkToolPalette,
|
2013-06-27 19:02:52 +00:00
|
|
|
gtk_tool_palette,
|
|
|
|
GTK_TYPE_CONTAINER,
|
|
|
|
G_ADD_PRIVATE (GtkToolPalette)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_init (GtkToolPalette *palette)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
palette->priv = gtk_tool_palette_get_instance_private (palette);
|
2009-11-27 04:52:20 +00:00
|
|
|
palette->priv->groups = g_ptr_array_sized_new (4);
|
2009-11-09 21:16:15 +00:00
|
|
|
g_ptr_array_set_free_func (palette->priv->groups, g_free);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
palette->priv->icon_size = DEFAULT_ICON_SIZE;
|
2009-07-16 15:51:55 +00:00
|
|
|
palette->priv->icon_size_set = FALSE;
|
2009-07-13 15:38:34 +00:00
|
|
|
palette->priv->orientation = DEFAULT_ORIENTATION;
|
|
|
|
palette->priv->style = DEFAULT_TOOLBAR_STYLE;
|
2009-07-16 15:51:55 +00:00
|
|
|
palette->priv->style_set = FALSE;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
palette->priv->text_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
|
2013-03-23 18:09:20 +00:00
|
|
|
|
|
|
|
if (dnd_target_atom_item == GDK_NONE)
|
|
|
|
{
|
|
|
|
dnd_target_atom_item = gdk_atom_intern_static_string (dnd_targets[0].target);
|
|
|
|
dnd_target_atom_group = gdk_atom_intern_static_string (dnd_targets[1].target);
|
|
|
|
}
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_reconfigured (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
|
2009-11-09 21:16:15 +00:00
|
|
|
if (info->widget)
|
|
|
|
_gtk_tool_item_group_palette_reconfigured (info->widget);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_resize_no_redraw (GTK_WIDGET (palette));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ICON_SIZE:
|
2014-06-09 15:49:22 +00:00
|
|
|
if (palette->priv->icon_size != g_value_get_enum (value))
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
palette->priv->icon_size = g_value_get_enum (value);
|
|
|
|
gtk_tool_palette_reconfigured (palette);
|
2014-06-09 15:49:22 +00:00
|
|
|
g_object_notify_by_pspec (object, pspec);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
case PROP_ICON_SIZE_SET:
|
2014-06-09 15:49:22 +00:00
|
|
|
if (palette->priv->icon_size_set != g_value_get_boolean (value))
|
2009-07-16 15:51:55 +00:00
|
|
|
{
|
2014-06-09 15:49:22 +00:00
|
|
|
palette->priv->icon_size_set = g_value_get_boolean (value);
|
2009-07-16 15:51:55 +00:00
|
|
|
gtk_tool_palette_reconfigured (palette);
|
2014-06-09 15:49:22 +00:00
|
|
|
g_object_notify_by_pspec (object, pspec);
|
2009-07-16 15:51:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
case PROP_ORIENTATION:
|
2014-06-09 15:49:22 +00:00
|
|
|
if (palette->priv->orientation != g_value_get_enum (value))
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
palette->priv->orientation = g_value_get_enum (value);
|
2011-01-12 21:55:55 +00:00
|
|
|
_gtk_orientable_set_style_classes (GTK_ORIENTABLE (palette));
|
2009-07-13 15:38:34 +00:00
|
|
|
gtk_tool_palette_reconfigured (palette);
|
2014-06-09 15:49:22 +00:00
|
|
|
g_object_notify_by_pspec (object, pspec);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TOOLBAR_STYLE:
|
2014-06-09 15:49:22 +00:00
|
|
|
if (palette->priv->style != g_value_get_enum (value))
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
palette->priv->style = g_value_get_enum (value);
|
|
|
|
gtk_tool_palette_reconfigured (palette);
|
2014-06-09 15:49:22 +00:00
|
|
|
g_object_notify_by_pspec (object, pspec);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-10-18 04:21:39 +00:00
|
|
|
case PROP_HADJUSTMENT:
|
|
|
|
gtk_tool_palette_set_hadjustment (palette, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VADJUSTMENT:
|
|
|
|
gtk_tool_palette_set_vadjustment (palette, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2010-10-26 00:59:02 +00:00
|
|
|
case PROP_HSCROLL_POLICY:
|
2014-06-09 15:49:22 +00:00
|
|
|
if (palette->priv->hscroll_policy != g_value_get_enum (value))
|
|
|
|
{
|
|
|
|
palette->priv->hscroll_policy = g_value_get_enum (value);
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (palette));
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
}
|
2010-10-26 00:59:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VSCROLL_POLICY:
|
2014-06-09 15:49:22 +00:00
|
|
|
if (palette->priv->vscroll_policy != g_value_get_enum (value))
|
|
|
|
{
|
|
|
|
palette->priv->vscroll_policy = g_value_get_enum (value);
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (palette));
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
}
|
2010-10-26 00:59:02 +00:00
|
|
|
break;
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ICON_SIZE:
|
|
|
|
g_value_set_enum (value, gtk_tool_palette_get_icon_size (palette));
|
|
|
|
break;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
case PROP_ICON_SIZE_SET:
|
|
|
|
g_value_set_boolean (value, palette->priv->icon_size_set);
|
|
|
|
break;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
case PROP_ORIENTATION:
|
2009-07-14 17:11:20 +00:00
|
|
|
g_value_set_enum (value, palette->priv->orientation);
|
2009-07-13 15:38:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TOOLBAR_STYLE:
|
|
|
|
g_value_set_enum (value, gtk_tool_palette_get_style (palette));
|
|
|
|
break;
|
|
|
|
|
2010-10-18 04:21:39 +00:00
|
|
|
case PROP_HADJUSTMENT:
|
|
|
|
g_value_set_object (value, palette->priv->hadjustment);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VADJUSTMENT:
|
|
|
|
g_value_set_object (value, palette->priv->vadjustment);
|
|
|
|
break;
|
|
|
|
|
2010-10-26 00:59:02 +00:00
|
|
|
case PROP_HSCROLL_POLICY:
|
|
|
|
g_value_set_enum (value, palette->priv->hscroll_policy);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VSCROLL_POLICY:
|
|
|
|
g_value_set_enum (value, palette->priv->vscroll_policy);
|
|
|
|
break;
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (palette->priv->hadjustment)
|
|
|
|
{
|
|
|
|
g_object_unref (palette->priv->hadjustment);
|
|
|
|
palette->priv->hadjustment = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (palette->priv->vadjustment)
|
|
|
|
{
|
|
|
|
g_object_unref (palette->priv->vadjustment);
|
|
|
|
palette->priv->vadjustment = NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (group->notify_collapsed)
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (group->widget, group->notify_collapsed);
|
|
|
|
group->notify_collapsed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (palette->priv->text_size_group)
|
|
|
|
{
|
|
|
|
g_object_unref (palette->priv->text_size_group);
|
|
|
|
palette->priv->text_size_group = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (object);
|
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
g_ptr_array_free (palette->priv->groups, TRUE);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_tool_palette_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
|
|
|
|
GtkRequisition child_requisition;
|
2010-06-02 04:28:22 +00:00
|
|
|
guint border_width;
|
2009-07-13 15:38:34 +00:00
|
|
|
guint i;
|
|
|
|
|
2010-06-02 04:28:22 +00:00
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
requisition->width = 0;
|
|
|
|
requisition->height = 0;
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (!group->widget)
|
|
|
|
continue;
|
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (GTK_WIDGET (group->widget),
|
|
|
|
&child_requisition, NULL);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
{
|
|
|
|
requisition->width = MAX (requisition->width, child_requisition.width);
|
|
|
|
requisition->height += child_requisition.height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
requisition->width += child_requisition.width;
|
|
|
|
requisition->height = MAX (requisition->height, child_requisition.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
requisition->width += border_width * 2;
|
|
|
|
requisition->height += border_width * 2;
|
|
|
|
}
|
|
|
|
|
2010-10-27 13:50:24 +00:00
|
|
|
static void
|
|
|
|
gtk_tool_palette_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
GtkRequisition requisition;
|
|
|
|
|
|
|
|
gtk_tool_palette_size_request (widget, &requisition);
|
|
|
|
|
|
|
|
*minimum = *natural = requisition.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
GtkRequisition requisition;
|
|
|
|
|
|
|
|
gtk_tool_palette_size_request (widget, &requisition);
|
|
|
|
|
|
|
|
*minimum = *natural = requisition.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
static void
|
|
|
|
gtk_tool_palette_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
|
|
|
|
GtkAdjustment *adjustment = NULL;
|
|
|
|
GtkAllocation child_allocation;
|
|
|
|
|
|
|
|
gint n_expand_groups = 0;
|
|
|
|
gint remaining_space = 0;
|
|
|
|
gint expand_space = 0;
|
|
|
|
|
2012-04-27 01:28:22 +00:00
|
|
|
gint total_size, page_size;
|
2009-07-13 15:38:34 +00:00
|
|
|
gint offset = 0;
|
|
|
|
guint i;
|
2010-06-02 04:28:22 +00:00
|
|
|
guint border_width;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
gint min_offset = -1, max_offset = -1;
|
|
|
|
|
|
|
|
gint x;
|
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
gint *group_sizes = g_newa (gint, palette->priv->groups->len);
|
2010-11-10 02:08:14 +00:00
|
|
|
GtkTextDirection direction;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-06-02 04:28:22 +00:00
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
2010-11-10 02:08:14 +00:00
|
|
|
direction = gtk_widget_get_direction (widget);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->size_allocate (widget, allocation);
|
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
{
|
|
|
|
adjustment = palette->priv->vadjustment;
|
|
|
|
page_size = allocation->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
adjustment = palette->priv->hadjustment;
|
|
|
|
page_size = allocation->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adjustment)
|
|
|
|
offset = gtk_adjustment_get_value (adjustment);
|
|
|
|
if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
|
|
|
|
GTK_TEXT_DIR_RTL == direction)
|
|
|
|
offset = -offset;
|
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
child_allocation.width = allocation->width - border_width * 2;
|
|
|
|
else
|
|
|
|
child_allocation.height = allocation->height - border_width * 2;
|
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
remaining_space = allocation->height;
|
|
|
|
else
|
|
|
|
remaining_space = allocation->width;
|
|
|
|
|
|
|
|
/* figure out the required size of all groups to be able to distribute the
|
2009-11-27 04:52:20 +00:00
|
|
|
* remaining space on allocation
|
|
|
|
*/
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
|
2009-07-13 15:38:34 +00:00
|
|
|
gint size;
|
|
|
|
|
2011-06-27 20:46:33 +00:00
|
|
|
group_sizes[i] = 0;
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
if (!group->widget)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (group->widget);
|
|
|
|
|
|
|
|
if (gtk_tool_item_group_get_n_items (group->widget))
|
|
|
|
{
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
size = _gtk_tool_item_group_get_height_for_width (group->widget, child_allocation.width);
|
|
|
|
else
|
|
|
|
size = _gtk_tool_item_group_get_width_for_height (group->widget, child_allocation.height);
|
|
|
|
|
|
|
|
if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
|
|
|
|
n_expand_groups += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
|
|
|
|
remaining_space -= size;
|
|
|
|
group_sizes[i] = size;
|
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
/* if the widget is currently expanding an offset which allows to
|
|
|
|
* display as much of the widget as possible is calculated
|
|
|
|
*/
|
2009-07-13 15:38:34 +00:00
|
|
|
if (widget == palette->priv->expanding_child)
|
|
|
|
{
|
|
|
|
gint limit =
|
|
|
|
GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
|
|
|
|
child_allocation.width : child_allocation.height;
|
|
|
|
|
|
|
|
gint real_size;
|
|
|
|
guint j;
|
|
|
|
|
|
|
|
min_offset = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < i; ++j)
|
|
|
|
min_offset += group_sizes[j];
|
|
|
|
|
|
|
|
max_offset = min_offset + group_sizes[i];
|
|
|
|
|
|
|
|
real_size = _gtk_tool_item_group_get_size_for_limit
|
|
|
|
(GTK_TOOL_ITEM_GROUP (widget), limit,
|
|
|
|
GTK_ORIENTATION_VERTICAL == palette->priv->orientation,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
if (size == real_size)
|
|
|
|
palette->priv->expanding_child = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_expand_groups > 0)
|
|
|
|
{
|
|
|
|
remaining_space = MAX (0, remaining_space);
|
|
|
|
expand_space = remaining_space / n_expand_groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_offset != -1)
|
|
|
|
{
|
|
|
|
gint limit =
|
|
|
|
GTK_ORIENTATION_VERTICAL == palette->priv->orientation ?
|
|
|
|
allocation->height : allocation->width;
|
|
|
|
|
|
|
|
offset = MIN (MAX (offset, max_offset - limit), min_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remaining_space > 0)
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
x = border_width;
|
|
|
|
child_allocation.y = border_width;
|
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
child_allocation.y -= offset;
|
|
|
|
else
|
|
|
|
x -= offset;
|
|
|
|
|
|
|
|
/* allocate all groups at the calculated positions */
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (!group->widget)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (gtk_tool_item_group_get_n_items (group->widget))
|
|
|
|
{
|
|
|
|
gint size = group_sizes[i];
|
|
|
|
|
|
|
|
if (group->expand && !gtk_tool_item_group_get_collapsed (group->widget))
|
|
|
|
{
|
|
|
|
size += MIN (expand_space, remaining_space);
|
|
|
|
remaining_space -= expand_space;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
child_allocation.height = size;
|
|
|
|
else
|
|
|
|
child_allocation.width = size;
|
|
|
|
|
|
|
|
if (GTK_ORIENTATION_HORIZONTAL == palette->priv->orientation &&
|
|
|
|
GTK_TEXT_DIR_RTL == direction)
|
|
|
|
child_allocation.x = allocation->width - x - child_allocation.width;
|
|
|
|
else
|
|
|
|
child_allocation.x = x;
|
|
|
|
|
2015-05-31 01:28:44 +00:00
|
|
|
gtk_widget_size_allocate (GTK_WIDGET (group->widget), &child_allocation);
|
|
|
|
gtk_widget_show (GTK_WIDGET (group->widget));
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
child_allocation.y += child_allocation.height;
|
|
|
|
else
|
|
|
|
x += child_allocation.width;
|
|
|
|
}
|
|
|
|
else
|
2015-05-31 01:28:44 +00:00
|
|
|
gtk_widget_hide (GTK_WIDGET (group->widget));
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation)
|
|
|
|
{
|
|
|
|
child_allocation.y += border_width;
|
|
|
|
child_allocation.y += offset;
|
|
|
|
|
2012-04-27 01:28:22 +00:00
|
|
|
total_size = child_allocation.y;
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x += border_width;
|
|
|
|
x += offset;
|
|
|
|
|
2012-04-27 01:28:22 +00:00
|
|
|
total_size = x;
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update the scrollbar to match the displayed adjustment */
|
|
|
|
if (adjustment)
|
|
|
|
{
|
2012-04-27 01:33:57 +00:00
|
|
|
gdouble lower, upper;
|
|
|
|
|
|
|
|
total_size = MAX (0, total_size);
|
|
|
|
page_size = MIN (total_size, page_size);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
|
|
|
|
GTK_TEXT_DIR_LTR == direction)
|
|
|
|
{
|
2011-01-05 12:12:17 +00:00
|
|
|
lower = 0;
|
2012-04-27 01:33:57 +00:00
|
|
|
upper = total_size;
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-27 01:33:57 +00:00
|
|
|
lower = page_size - total_size;
|
2011-01-05 12:12:17 +00:00
|
|
|
upper = page_size;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
offset = -offset;
|
|
|
|
}
|
|
|
|
|
2011-01-05 12:12:17 +00:00
|
|
|
gtk_adjustment_configure (adjustment,
|
2012-04-27 01:33:57 +00:00
|
|
|
offset,
|
2011-01-05 12:12:17 +00:00
|
|
|
lower,
|
|
|
|
upper,
|
|
|
|
page_size * 0.1,
|
|
|
|
page_size * 0.9,
|
|
|
|
page_size);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_realize (GtkWidget *widget)
|
|
|
|
{
|
2010-08-11 20:51:16 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkWindow *window;
|
2009-07-13 15:38:34 +00:00
|
|
|
GdkWindowAttr attributes;
|
2010-08-11 20:51:16 +00:00
|
|
|
gint attributes_mask;
|
2010-06-02 04:28:22 +00:00
|
|
|
guint border_width;
|
|
|
|
|
2010-08-11 20:51:16 +00:00
|
|
|
gtk_widget_set_realized (widget, TRUE);
|
|
|
|
|
2010-06-02 04:28:22 +00:00
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-08-11 20:51:16 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
2010-08-11 20:51:16 +00:00
|
|
|
attributes.x = allocation.x + border_width;
|
|
|
|
attributes.y = allocation.y + border_width;
|
|
|
|
attributes.width = allocation.width - border_width * 2;
|
|
|
|
attributes.height = allocation.height - border_width * 2;
|
2009-07-13 15:38:34 +00:00
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
2010-03-29 17:22:18 +00:00
|
|
|
attributes.event_mask = gtk_widget_get_events (widget)
|
|
|
|
| GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
|
|
|
|
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
|
2013-02-11 20:52:35 +00:00
|
|
|
| GDK_BUTTON_MOTION_MASK
|
|
|
|
| GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK
|
|
|
|
| GDK_TOUCH_MASK;
|
2010-08-28 16:04:08 +00:00
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-08-11 20:51:16 +00:00
|
|
|
window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
|
|
|
&attributes, attributes_mask);
|
2010-08-30 09:25:14 +00:00
|
|
|
gtk_widget_set_window (widget, window);
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_register_window (widget, window);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2011-01-03 22:21:46 +00:00
|
|
|
gtk_style_context_set_background (gtk_widget_get_style_context (widget),
|
|
|
|
window);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
gtk_container_forall (GTK_CONTAINER (widget),
|
|
|
|
(GtkCallback) gtk_widget_set_parent_window,
|
2010-08-11 20:51:16 +00:00
|
|
|
window);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_resize_no_redraw (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-11-07 09:55:37 +00:00
|
|
|
gtk_tool_palette_adjustment_value_changed (GtkAdjustment *adjustment,
|
2009-07-13 15:38:34 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2010-08-11 20:51:16 +00:00
|
|
|
GtkAllocation allocation;
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (data);
|
2010-08-11 20:51:16 +00:00
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
gtk_tool_palette_size_allocate (widget, &allocation);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_add (GtkContainer *container,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette;
|
2009-11-09 21:16:15 +00:00
|
|
|
GtkToolItemGroupInfo *info = g_new0(GtkToolItemGroupInfo, 1);
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
|
|
|
|
|
|
|
|
palette = GTK_TOOL_PALETTE (container);
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
g_ptr_array_add (palette->priv->groups, info);
|
|
|
|
info->pos = palette->priv->groups->len - 1;
|
|
|
|
info->widget = g_object_ref_sink (child);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
gtk_widget_set_parent (child, GTK_WIDGET (palette));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_remove (GtkContainer *container,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
|
|
|
|
palette = GTK_TOOL_PALETTE (container);
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
|
2009-11-09 21:16:15 +00:00
|
|
|
if (GTK_WIDGET(info->widget) == child)
|
|
|
|
{
|
|
|
|
g_object_unref (child);
|
|
|
|
gtk_widget_unparent (child);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
g_ptr_array_remove_index (palette->priv->groups, i);
|
|
|
|
}
|
|
|
|
}
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_forall (GtkContainer *container,
|
2009-11-07 09:55:37 +00:00
|
|
|
gboolean internals,
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
|
2011-01-31 19:57:05 +00:00
|
|
|
guint i, len;
|
2009-11-09 21:16:15 +00:00
|
|
|
|
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
|
2011-01-31 19:57:05 +00:00
|
|
|
|
|
|
|
len = palette->priv->groups->len;
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
if (info->widget)
|
|
|
|
callback (GTK_WIDGET (info->widget),
|
|
|
|
callback_data);
|
2011-01-31 19:57:05 +00:00
|
|
|
|
|
|
|
/* At destroy time, 'callback' results in removing a widget,
|
|
|
|
* here we just reset the current index to account for the removed widget. */
|
|
|
|
i -= (len - palette->priv->groups->len);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
2009-11-07 09:55:37 +00:00
|
|
|
gtk_tool_palette_child_type (GtkContainer *container)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
return GTK_TYPE_TOOL_ITEM_GROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_set_child_property (GtkContainer *container,
|
|
|
|
GtkWidget *child,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case CHILD_PROP_EXCLUSIVE:
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_set_exclusive (palette, GTK_TOOL_ITEM_GROUP (child),
|
|
|
|
g_value_get_boolean (value));
|
2009-07-13 15:38:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHILD_PROP_EXPAND:
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_set_expand (palette, GTK_TOOL_ITEM_GROUP (child),
|
|
|
|
g_value_get_boolean (value));
|
2009-07-13 15:38:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_get_child_property (GtkContainer *container,
|
|
|
|
GtkWidget *child,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case CHILD_PROP_EXCLUSIVE:
|
2010-01-14 09:26:49 +00:00
|
|
|
g_value_set_boolean (value,
|
|
|
|
gtk_tool_palette_get_exclusive (palette, GTK_TOOL_ITEM_GROUP (child)));
|
2009-07-13 15:38:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHILD_PROP_EXPAND:
|
2010-01-14 09:26:49 +00:00
|
|
|
g_value_set_boolean (value,
|
|
|
|
gtk_tool_palette_get_expand (palette, GTK_TOOL_ITEM_GROUP (child)));
|
2009-07-13 15:38:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
static void
|
|
|
|
gtk_tool_palette_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *previous_screen)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
|
|
|
|
|
|
|
|
gtk_tool_palette_reconfigured (palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
static void
|
|
|
|
gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
|
|
|
|
{
|
|
|
|
GObjectClass *oclass = G_OBJECT_CLASS (cls);
|
|
|
|
GtkWidgetClass *wclass = GTK_WIDGET_CLASS (cls);
|
|
|
|
GtkContainerClass *cclass = GTK_CONTAINER_CLASS (cls);
|
|
|
|
|
|
|
|
oclass->set_property = gtk_tool_palette_set_property;
|
|
|
|
oclass->get_property = gtk_tool_palette_get_property;
|
|
|
|
oclass->dispose = gtk_tool_palette_dispose;
|
|
|
|
oclass->finalize = gtk_tool_palette_finalize;
|
|
|
|
|
2010-10-27 13:50:24 +00:00
|
|
|
wclass->get_preferred_width = gtk_tool_palette_get_preferred_width;
|
|
|
|
wclass->get_preferred_height= gtk_tool_palette_get_preferred_height;
|
2009-07-13 15:38:34 +00:00
|
|
|
wclass->size_allocate = gtk_tool_palette_size_allocate;
|
|
|
|
wclass->realize = gtk_tool_palette_realize;
|
|
|
|
|
|
|
|
cclass->add = gtk_tool_palette_add;
|
|
|
|
cclass->remove = gtk_tool_palette_remove;
|
|
|
|
cclass->forall = gtk_tool_palette_forall;
|
|
|
|
cclass->child_type = gtk_tool_palette_child_type;
|
|
|
|
cclass->set_child_property = gtk_tool_palette_set_child_property;
|
|
|
|
cclass->get_child_property = gtk_tool_palette_get_child_property;
|
|
|
|
|
2013-07-08 17:45:01 +00:00
|
|
|
/* Handle screen-changed so we can update our configuration.
|
2009-07-16 15:51:55 +00:00
|
|
|
*/
|
|
|
|
wclass->screen_changed = gtk_tool_palette_screen_changed;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2010-10-26 00:59:02 +00:00
|
|
|
g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2010-10-26 00:59:02 +00:00
|
|
|
g_object_class_override_property (oclass, PROP_HADJUSTMENT, "hadjustment");
|
|
|
|
g_object_class_override_property (oclass, PROP_VADJUSTMENT, "vadjustment");
|
|
|
|
g_object_class_override_property (oclass, PROP_HSCROLL_POLICY, "hscroll-policy");
|
|
|
|
g_object_class_override_property (oclass, PROP_VSCROLL_POLICY, "vscroll-policy");
|
2010-10-18 04:21:39 +00:00
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
/**
|
2009-07-16 15:51:55 +00:00
|
|
|
* GtkToolPalette:icon-size:
|
|
|
|
*
|
2013-07-08 17:45:01 +00:00
|
|
|
* The size of the icons in a tool palette. When this property is set,
|
|
|
|
* it overrides the default setting.
|
2009-11-11 08:42:49 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* This should only be used for special-purpose tool palettes, normal
|
|
|
|
* application tool palettes should respect the user preferences for the
|
2009-07-16 15:51:55 +00:00
|
|
|
* size of icons.
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-16 15:51:55 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (oclass,
|
|
|
|
PROP_ICON_SIZE,
|
2009-07-13 15:38:34 +00:00
|
|
|
g_param_spec_enum ("icon-size",
|
2009-07-16 15:51:55 +00:00
|
|
|
P_("Icon size"),
|
|
|
|
P_("Size of icons in this tool palette"),
|
2009-07-13 15:38:34 +00:00
|
|
|
GTK_TYPE_ICON_SIZE,
|
|
|
|
DEFAULT_ICON_SIZE,
|
2014-06-09 15:49:22 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
/**
|
2009-11-26 23:56:25 +00:00
|
|
|
* GtkToolPalette:icon-size-set:
|
2009-07-16 15:51:55 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Is %TRUE if the #GtkToolPalette:icon-size property has been set.
|
2009-07-16 15:51:55 +00:00
|
|
|
*
|
2009-11-11 08:37:55 +00:00
|
|
|
* Since: 2.20
|
2009-07-16 15:51:55 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (oclass,
|
|
|
|
PROP_ICON_SIZE_SET,
|
|
|
|
g_param_spec_boolean ("icon-size-set",
|
2014-06-09 15:49:22 +00:00
|
|
|
P_("Icon size set"),
|
|
|
|
P_("Whether the icon-size property has been set"),
|
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
/**
|
|
|
|
* GtkToolPalette:toolbar-style:
|
|
|
|
*
|
|
|
|
* The style of items in the tool palette.
|
|
|
|
*
|
|
|
|
* Since: 2.20
|
|
|
|
*/
|
2009-07-13 15:38:34 +00:00
|
|
|
g_object_class_install_property (oclass, PROP_TOOLBAR_STYLE,
|
|
|
|
g_param_spec_enum ("toolbar-style",
|
|
|
|
P_("Toolbar Style"),
|
|
|
|
P_("Style of items in the tool palette"),
|
|
|
|
GTK_TYPE_TOOLBAR_STYLE,
|
|
|
|
DEFAULT_TOOLBAR_STYLE,
|
2014-06-09 15:49:22 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
/**
|
|
|
|
* GtkToolPalette:exclusive:
|
|
|
|
*
|
|
|
|
* Whether the item group should be the only one that is expanded
|
|
|
|
* at a given time.
|
|
|
|
*
|
|
|
|
* Since: 2.20
|
|
|
|
*/
|
2009-07-13 15:38:34 +00:00
|
|
|
gtk_container_class_install_child_property (cclass, CHILD_PROP_EXCLUSIVE,
|
|
|
|
g_param_spec_boolean ("exclusive",
|
|
|
|
P_("Exclusive"),
|
|
|
|
P_("Whether the item group should be the only expanded at a given time"),
|
|
|
|
DEFAULT_CHILD_EXCLUSIVE,
|
2009-11-27 04:52:20 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
/**
|
|
|
|
* GtkToolPalette:expand:
|
|
|
|
*
|
|
|
|
* Whether the item group should receive extra space when the palette grows.
|
|
|
|
* at a given time.
|
|
|
|
*
|
|
|
|
* Since: 2.20
|
|
|
|
*/
|
2009-07-13 15:38:34 +00:00
|
|
|
gtk_container_class_install_child_property (cclass, CHILD_PROP_EXPAND,
|
|
|
|
g_param_spec_boolean ("expand",
|
|
|
|
P_("Expand"),
|
|
|
|
P_("Whether the item group should receive extra space when the palette grows"),
|
|
|
|
DEFAULT_CHILD_EXPAND,
|
2009-11-27 04:52:20 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_new:
|
|
|
|
*
|
|
|
|
* Creates a new tool palette.
|
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Returns: a new #GtkToolPalette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
GtkWidget*
|
|
|
|
gtk_tool_palette_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_TOOL_PALETTE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_set_icon_size:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
2009-12-18 10:58:36 +00:00
|
|
|
* @icon_size: (type int): the #GtkIconSize that icons in the tool
|
|
|
|
* palette shall have
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
|
|
|
* Sets the size of icons in the tool palette.
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_tool_palette_set_icon_size (GtkToolPalette *palette,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
2009-07-16 15:51:55 +00:00
|
|
|
GtkToolPalettePrivate *priv;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
2009-07-16 15:51:55 +00:00
|
|
|
g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
|
|
|
|
|
|
|
|
priv = palette->priv;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
if (!priv->icon_size_set)
|
|
|
|
{
|
2009-11-11 08:42:49 +00:00
|
|
|
priv->icon_size_set = TRUE;
|
2009-07-16 15:51:55 +00:00
|
|
|
g_object_notify (G_OBJECT (palette), "icon-size-set");
|
|
|
|
}
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
if (priv->icon_size == icon_size)
|
|
|
|
return;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
priv->icon_size = icon_size;
|
|
|
|
g_object_notify (G_OBJECT (palette), "icon-size");
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
gtk_tool_palette_reconfigured (palette);
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (palette));
|
|
|
|
}
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
/**
|
2009-07-16 15:51:55 +00:00
|
|
|
* gtk_tool_palette_unset_icon_size:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
2009-07-16 15:51:55 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(),
|
|
|
|
* so that user preferences will be used to determine the icon size.
|
2009-07-16 15:51:55 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-16 15:51:55 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_tool_palette_unset_icon_size (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
GtkToolPalettePrivate* priv = palette->priv;
|
|
|
|
GtkIconSize size;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
if (palette->priv->icon_size_set)
|
|
|
|
{
|
2013-07-08 17:45:01 +00:00
|
|
|
size = DEFAULT_ICON_SIZE;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
if (size != palette->priv->icon_size)
|
|
|
|
{
|
|
|
|
gtk_tool_palette_set_icon_size (palette, size);
|
2009-11-11 08:42:49 +00:00
|
|
|
g_object_notify (G_OBJECT (palette), "icon-size");
|
2013-07-08 17:45:01 +00:00
|
|
|
}
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
priv->icon_size_set = FALSE;
|
2009-11-11 08:42:49 +00:00
|
|
|
g_object_notify (G_OBJECT (palette), "icon-size-set");
|
2009-07-16 15:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the "toolbar-style" property and do appropriate things.
|
2009-11-27 04:52:20 +00:00
|
|
|
* GtkToolbar does this by emitting a signal instead of just
|
|
|
|
* calling a function...
|
2009-07-16 15:51:55 +00:00
|
|
|
*/
|
|
|
|
static void
|
2009-11-27 04:52:20 +00:00
|
|
|
gtk_tool_palette_change_style (GtkToolPalette *palette,
|
|
|
|
GtkToolbarStyle style)
|
2009-07-16 15:51:55 +00:00
|
|
|
{
|
|
|
|
GtkToolPalettePrivate* priv = palette->priv;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
if (priv->style != style)
|
|
|
|
{
|
|
|
|
priv->style = style;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
gtk_tool_palette_reconfigured (palette);
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (palette));
|
|
|
|
g_object_notify (G_OBJECT (palette), "toolbar-style");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_set_style:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @style: the #GtkToolbarStyle that items in the tool palette shall have
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
|
|
|
* Sets the style (text, icons or both) of items in the tool palette.
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_tool_palette_set_style (GtkToolPalette *palette,
|
|
|
|
GtkToolbarStyle style)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
|
2009-11-11 08:42:49 +00:00
|
|
|
palette->priv->style_set = TRUE;
|
2009-07-16 15:51:55 +00:00
|
|
|
gtk_tool_palette_change_style (palette, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_unset_style:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
*
|
|
|
|
* Unsets a toolbar style set with gtk_tool_palette_set_style(),
|
|
|
|
* so that user preferences will be used to determine the toolbar style.
|
2009-11-11 08:42:49 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Since: 2.20
|
|
|
|
*/
|
2009-07-16 15:51:55 +00:00
|
|
|
void
|
|
|
|
gtk_tool_palette_unset_style (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
GtkToolPalettePrivate* priv = palette->priv;
|
|
|
|
GtkToolbarStyle style;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
if (priv->style_set)
|
|
|
|
{
|
2013-07-08 17:28:48 +00:00
|
|
|
style = DEFAULT_TOOLBAR_STYLE;
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
if (style != priv->style)
|
|
|
|
gtk_tool_palette_change_style (palette, style);
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-07-16 15:51:55 +00:00
|
|
|
priv->style_set = FALSE;
|
|
|
|
}
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_icon_size:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Gets the size of icons in the tool palette.
|
|
|
|
* See gtk_tool_palette_set_icon_size().
|
2009-11-11 08:42:49 +00:00
|
|
|
*
|
2009-12-18 10:58:36 +00:00
|
|
|
* Returns: (type int): the #GtkIconSize of icons in the tool palette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
GtkIconSize
|
|
|
|
gtk_tool_palette_get_icon_size (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_ICON_SIZE);
|
2009-11-27 04:52:20 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
return palette->priv->icon_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_style:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
|
|
|
* Gets the style (icons, text or both) of items in the tool palette.
|
|
|
|
*
|
|
|
|
* Returns: the #GtkToolbarStyle of items in the tool palette.
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
GtkToolbarStyle
|
|
|
|
gtk_tool_palette_get_style (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_TOOLBAR_STYLE);
|
2009-11-27 04:52:20 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
return palette->priv->style;
|
|
|
|
}
|
|
|
|
|
2012-10-02 17:23:29 +00:00
|
|
|
static gint
|
|
|
|
gtk_tool_palette_compare_groups (gconstpointer a,
|
|
|
|
gconstpointer b)
|
2009-11-09 21:16:15 +00:00
|
|
|
{
|
|
|
|
const GtkToolItemGroupInfo *group_a = a;
|
|
|
|
const GtkToolItemGroupInfo *group_b = b;
|
|
|
|
|
|
|
|
return group_a->pos - group_b->pos;
|
|
|
|
}
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
/**
|
|
|
|
* gtk_tool_palette_set_group_position:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @group: a #GtkToolItemGroup which is a child of palette
|
|
|
|
* @position: a new index for group
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
|
|
|
* Sets the position of the group as an index of the tool palette.
|
|
|
|
* If position is 0 the group will become the first child, if position is
|
|
|
|
* -1 it will become the last child.
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_set_group_position (GtkToolPalette *palette,
|
|
|
|
GtkToolItemGroup *group,
|
|
|
|
gint position)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-09 21:16:15 +00:00
|
|
|
GtkToolItemGroupInfo *group_new;
|
2009-11-11 08:42:49 +00:00
|
|
|
GtkToolItemGroupInfo *group_old;
|
2009-07-13 15:38:34 +00:00
|
|
|
gint old_position;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
|
|
|
|
g_return_if_fail (position >= -1);
|
|
|
|
|
|
|
|
if (-1 == position)
|
2009-11-09 21:16:15 +00:00
|
|
|
position = palette->priv->groups->len - 1;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
g_return_if_fail ((guint) position < palette->priv->groups->len);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
group_new = g_ptr_array_index (palette->priv->groups, position);
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
if (GTK_TOOL_ITEM_GROUP (group) == group_new->widget)
|
2009-07-13 15:38:34 +00:00
|
|
|
return;
|
|
|
|
|
2009-11-11 08:42:49 +00:00
|
|
|
old_position = gtk_tool_palette_get_group_position (palette, group);
|
2009-07-13 15:38:34 +00:00
|
|
|
g_return_if_fail (old_position >= 0);
|
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
group_old = g_ptr_array_index (palette->priv->groups, old_position);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
group_new->pos = position;
|
|
|
|
group_old->pos = old_position;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2012-10-02 17:23:29 +00:00
|
|
|
g_ptr_array_sort (palette->priv->groups, gtk_tool_palette_compare_groups);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (palette));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_group_notify_collapsed (GtkToolItemGroup *group,
|
2009-11-07 09:55:37 +00:00
|
|
|
GParamSpec *pspec,
|
2009-07-13 15:38:34 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (gtk_tool_item_group_get_collapsed (group))
|
|
|
|
return;
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-09 21:16:15 +00:00
|
|
|
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
|
|
|
|
GtkToolItemGroup *current_group = info->widget;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (current_group && current_group != group)
|
2009-11-09 21:16:15 +00:00
|
|
|
gtk_tool_item_group_set_collapsed (current_group, TRUE);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_set_exclusive:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @group: a #GtkToolItemGroup which is a child of palette
|
|
|
|
* @exclusive: whether the group should be exclusive or not
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Sets whether the group should be exclusive or not.
|
|
|
|
* If an exclusive group is expanded all other groups are collapsed.
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_set_exclusive (GtkToolPalette *palette,
|
|
|
|
GtkToolItemGroup *group,
|
|
|
|
gboolean exclusive)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
GtkToolItemGroupInfo *group_info;
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
|
|
|
|
|
|
|
|
position = gtk_tool_palette_get_group_position (palette, group);
|
|
|
|
g_return_if_fail (position >= 0);
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
group_info = g_ptr_array_index (palette->priv->groups, position);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (exclusive == group_info->exclusive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
group_info->exclusive = exclusive;
|
|
|
|
|
|
|
|
if (group_info->exclusive != (0 != group_info->notify_collapsed))
|
|
|
|
{
|
|
|
|
if (group_info->exclusive)
|
|
|
|
{
|
|
|
|
group_info->notify_collapsed =
|
|
|
|
g_signal_connect (group, "notify::collapsed",
|
|
|
|
G_CALLBACK (gtk_tool_palette_group_notify_collapsed),
|
|
|
|
palette);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (group, group_info->notify_collapsed);
|
|
|
|
group_info->notify_collapsed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tool_palette_group_notify_collapsed (group_info->widget, NULL, palette);
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_widget_child_notify (GTK_WIDGET (group), "exclusive");
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_set_expand:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @group: a #GtkToolItemGroup which is a child of palette
|
|
|
|
* @expand: whether the group should be given extra space
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
|
|
|
* Sets whether the group should be given extra space.
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_set_expand (GtkToolPalette *palette,
|
|
|
|
GtkToolItemGroup *group,
|
2009-07-13 15:38:34 +00:00
|
|
|
gboolean expand)
|
|
|
|
{
|
|
|
|
GtkToolItemGroupInfo *group_info;
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
|
|
|
|
|
|
|
|
position = gtk_tool_palette_get_group_position (palette, group);
|
|
|
|
g_return_if_fail (position >= 0);
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
group_info = g_ptr_array_index (palette->priv->groups, position);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (expand != group_info->expand)
|
|
|
|
{
|
|
|
|
group_info->expand = expand;
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (palette));
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_widget_child_notify (GTK_WIDGET (group), "expand");
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_group_position:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @group: a #GtkToolItemGroup
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Gets the position of @group in @palette as index.
|
|
|
|
* See gtk_tool_palette_set_group_position().
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Returns: the index of group or -1 if @group is not a child of @palette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
gint
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_get_group_position (GtkToolPalette *palette,
|
|
|
|
GtkToolItemGroup *group)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), -1);
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), -1);
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
|
|
|
{
|
|
|
|
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
|
|
|
|
if ((gpointer) group == info->widget)
|
|
|
|
return i;
|
|
|
|
}
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_exclusive:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @group: a #GtkToolItemGroup which is a child of palette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Gets whether @group is exclusive or not.
|
|
|
|
* See gtk_tool_palette_set_exclusive().
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Returns: %TRUE if @group is exclusive
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_get_exclusive (GtkToolPalette *palette,
|
|
|
|
GtkToolItemGroup *group)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
gint position;
|
2009-11-09 21:16:15 +00:00
|
|
|
GtkToolItemGroupInfo *info;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXCLUSIVE);
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXCLUSIVE);
|
|
|
|
|
|
|
|
position = gtk_tool_palette_get_group_position (palette, group);
|
|
|
|
g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXCLUSIVE);
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
info = g_ptr_array_index (palette->priv->groups, position);
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
return info->exclusive;
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_expand:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @group: a #GtkToolItemGroup which is a child of palette
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Gets whether group should be given extra space.
|
|
|
|
* See gtk_tool_palette_set_expand().
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Returns: %TRUE if group should be given extra space, %FALSE otherwise
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2010-01-14 09:26:49 +00:00
|
|
|
gtk_tool_palette_get_expand (GtkToolPalette *palette,
|
|
|
|
GtkToolItemGroup *group)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
gint position;
|
2009-11-09 21:16:15 +00:00
|
|
|
GtkToolItemGroupInfo *info;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), DEFAULT_CHILD_EXPAND);
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), DEFAULT_CHILD_EXPAND);
|
|
|
|
|
|
|
|
position = gtk_tool_palette_get_group_position (palette, group);
|
|
|
|
g_return_val_if_fail (position >= 0, DEFAULT_CHILD_EXPAND);
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
info = g_ptr_array_index (palette->priv->groups, position);
|
2009-11-11 08:42:49 +00:00
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
return info->expand;
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_drop_item:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @x: the x position
|
|
|
|
* @y: the y position
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Gets the item at position (x, y).
|
|
|
|
* See gtk_tool_palette_get_drop_group().
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2010-09-18 16:42:15 +00:00
|
|
|
* Returns: (transfer none): the #GtkToolItem at position or %NULL if there is no such item
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
GtkToolItem*
|
|
|
|
gtk_tool_palette_get_drop_item (GtkToolPalette *palette,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
2010-08-11 20:51:16 +00:00
|
|
|
GtkAllocation allocation;
|
2010-01-19 08:04:15 +00:00
|
|
|
GtkToolItemGroup *group = gtk_tool_palette_get_drop_group (palette, x, y);
|
|
|
|
GtkWidget *widget = GTK_WIDGET (group);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (group)
|
2010-08-11 20:51:16 +00:00
|
|
|
{
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
return gtk_tool_item_group_get_drop_item (group,
|
|
|
|
x - allocation.x,
|
|
|
|
y - allocation.y);
|
|
|
|
}
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_drop_group:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @x: the x position
|
|
|
|
* @y: the y position
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
|
|
|
* Gets the group at position (x, y).
|
|
|
|
*
|
2010-09-18 16:42:15 +00:00
|
|
|
* Returns: (transfer none): the #GtkToolItemGroup at position or %NULL
|
2009-11-27 04:52:20 +00:00
|
|
|
* if there is no such group
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
2010-01-18 08:37:14 +00:00
|
|
|
GtkToolItemGroup*
|
2009-07-13 15:38:34 +00:00
|
|
|
gtk_tool_palette_get_drop_group (GtkToolPalette *palette,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
2010-08-11 20:51:16 +00:00
|
|
|
GtkAllocation allocation;
|
2009-07-13 15:38:34 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
|
|
|
|
|
2010-08-11 20:51:16 +00:00
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (palette), &allocation);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-08-11 20:51:16 +00:00
|
|
|
g_return_val_if_fail (x >= 0 && x < allocation.width, NULL);
|
|
|
|
g_return_val_if_fail (y >= 0 && y < allocation.height, NULL);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
gint x0, y0;
|
|
|
|
|
|
|
|
if (!group->widget)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (group->widget);
|
2010-08-11 20:51:16 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-08-11 20:51:16 +00:00
|
|
|
x0 = x - allocation.x;
|
|
|
|
y0 = y - allocation.y;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-08-11 20:51:16 +00:00
|
|
|
if (x0 >= 0 && x0 < allocation.width &&
|
|
|
|
y0 >= 0 && y0 < allocation.height)
|
2010-01-18 08:37:14 +00:00
|
|
|
return GTK_TOOL_ITEM_GROUP (widget);
|
2009-07-13 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_drag_item:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @selection: a #GtkSelectionData
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Get the dragged item from the selection.
|
|
|
|
* This could be a #GtkToolItem or a #GtkToolItemGroup.
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2010-09-18 16:42:15 +00:00
|
|
|
* Returns: (transfer none): the dragged item in selection
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
GtkWidget*
|
|
|
|
gtk_tool_palette_get_drag_item (GtkToolPalette *palette,
|
|
|
|
const GtkSelectionData *selection)
|
|
|
|
{
|
|
|
|
GtkToolPaletteDragData *data;
|
2010-12-15 23:52:26 +00:00
|
|
|
GdkAtom target;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
|
|
|
|
g_return_val_if_fail (NULL != selection, NULL);
|
|
|
|
|
2010-12-15 23:52:26 +00:00
|
|
|
g_return_val_if_fail (gtk_selection_data_get_format (selection) == 8, NULL);
|
|
|
|
g_return_val_if_fail (gtk_selection_data_get_length (selection) == sizeof (GtkToolPaletteDragData), NULL);
|
|
|
|
target = gtk_selection_data_get_target (selection);
|
|
|
|
g_return_val_if_fail (target == dnd_target_atom_item ||
|
|
|
|
target == dnd_target_atom_group,
|
2009-07-13 15:38:34 +00:00
|
|
|
NULL);
|
|
|
|
|
2010-12-15 23:52:26 +00:00
|
|
|
data = (GtkToolPaletteDragData*) gtk_selection_data_get_data (selection);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (data->palette == palette, NULL);
|
|
|
|
|
2010-12-15 23:52:26 +00:00
|
|
|
if (dnd_target_atom_item == target)
|
2009-07-13 15:38:34 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
|
2010-12-15 23:52:26 +00:00
|
|
|
else if (dnd_target_atom_group == target)
|
2009-07-13 15:38:34 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
|
|
|
|
|
|
|
|
return data->item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_set_drag_source:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
2012-07-02 06:19:06 +00:00
|
|
|
* @targets: the #GtkToolPaletteDragTargets
|
2009-11-27 04:52:20 +00:00
|
|
|
* which the widget should support
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Sets the tool palette as a drag source.
|
|
|
|
* Enables all groups and items in the tool palette as drag sources
|
|
|
|
* on button 1 and button 3 press with copy and move actions.
|
2009-07-13 15:38:34 +00:00
|
|
|
* See gtk_drag_source_set().
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_tool_palette_set_drag_source (GtkToolPalette *palette,
|
|
|
|
GtkToolPaletteDragTargets targets)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
|
|
|
|
if ((palette->priv->drag_source & targets) == targets)
|
|
|
|
return;
|
|
|
|
|
|
|
|
palette->priv->drag_source |= targets;
|
|
|
|
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
2009-11-09 21:16:15 +00:00
|
|
|
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
|
|
|
|
if (info->widget)
|
|
|
|
gtk_container_forall (GTK_CONTAINER (info->widget),
|
2009-07-13 15:38:34 +00:00
|
|
|
_gtk_tool_palette_child_set_drag_source,
|
|
|
|
palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_add_drag_dest:
|
2009-11-27 04:52:20 +00:00
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
* @widget: a #GtkWidget which should be a drag destination for @palette
|
|
|
|
* @flags: the flags that specify what actions GTK+ should take for drops
|
|
|
|
* on that widget
|
2012-07-02 06:19:06 +00:00
|
|
|
* @targets: the #GtkToolPaletteDragTargets which the widget
|
2009-11-27 04:52:20 +00:00
|
|
|
* should support
|
2014-02-09 22:24:06 +00:00
|
|
|
* @actions: the #GdkDragActions which the widget should suppport
|
2009-11-27 04:52:20 +00:00
|
|
|
*
|
|
|
|
* Sets @palette as drag source (see gtk_tool_palette_set_drag_source())
|
|
|
|
* and sets @widget as a drag destination for drags from @palette.
|
2009-07-13 15:38:34 +00:00
|
|
|
* See gtk_drag_dest_set().
|
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_tool_palette_add_drag_dest (GtkToolPalette *palette,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GtkDestDefaults flags,
|
|
|
|
GtkToolPaletteDragTargets targets,
|
|
|
|
GdkDragAction actions)
|
|
|
|
{
|
|
|
|
GtkTargetEntry entries[G_N_ELEMENTS (dnd_targets)];
|
|
|
|
gint n_entries = 0;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
|
|
gtk_tool_palette_set_drag_source (palette,
|
|
|
|
targets);
|
|
|
|
|
|
|
|
if (targets & GTK_TOOL_PALETTE_DRAG_ITEMS)
|
|
|
|
entries[n_entries++] = dnd_targets[0];
|
|
|
|
if (targets & GTK_TOOL_PALETTE_DRAG_GROUPS)
|
|
|
|
entries[n_entries++] = dnd_targets[1];
|
|
|
|
|
|
|
|
gtk_drag_dest_set (widget, flags, entries, n_entries, actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_tool_palette_get_item_size (GtkToolPalette *palette,
|
|
|
|
GtkRequisition *item_size,
|
|
|
|
gboolean homogeneous_only,
|
|
|
|
gint *requested_rows)
|
|
|
|
{
|
|
|
|
GtkRequisition max_requisition;
|
|
|
|
gint max_rows;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
g_return_if_fail (NULL != item_size);
|
|
|
|
|
|
|
|
max_requisition.width = 0;
|
|
|
|
max_requisition.height = 0;
|
|
|
|
max_rows = 0;
|
|
|
|
|
|
|
|
/* iterate over all groups and calculate the max item_size and max row request */
|
2009-11-09 21:16:15 +00:00
|
|
|
for (i = 0; i < palette->priv->groups->len; ++i)
|
2009-07-13 15:38:34 +00:00
|
|
|
{
|
|
|
|
GtkRequisition requisition;
|
|
|
|
gint rows;
|
2009-11-27 04:52:20 +00:00
|
|
|
GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
|
|
|
if (!group->widget)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_gtk_tool_item_group_item_size_request (group->widget, &requisition, homogeneous_only, &rows);
|
|
|
|
|
|
|
|
max_requisition.width = MAX (max_requisition.width, requisition.width);
|
|
|
|
max_requisition.height = MAX (max_requisition.height, requisition.height);
|
|
|
|
max_rows = MAX (max_rows, rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
*item_size = max_requisition;
|
|
|
|
if (requested_rows)
|
|
|
|
*requested_rows = max_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_item_drag_data_get (GtkWidget *widget,
|
2009-11-07 09:55:37 +00:00
|
|
|
GdkDragContext *context,
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkSelectionData *selection,
|
2009-11-07 09:55:37 +00:00
|
|
|
guint info,
|
|
|
|
guint time,
|
2009-07-13 15:38:34 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
|
2010-12-15 23:52:26 +00:00
|
|
|
GdkAtom target;
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-12-15 23:52:26 +00:00
|
|
|
target = gtk_selection_data_get_target (selection);
|
|
|
|
|
|
|
|
if (target == dnd_target_atom_item)
|
2009-07-13 15:38:34 +00:00
|
|
|
drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
|
|
|
|
|
|
|
|
if (drag_data.item)
|
2010-12-15 23:52:26 +00:00
|
|
|
gtk_selection_data_set (selection, target, 8,
|
2009-07-13 15:38:34 +00:00
|
|
|
(guchar*) &drag_data, sizeof (drag_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tool_palette_child_drag_data_get (GtkWidget *widget,
|
2009-11-07 09:55:37 +00:00
|
|
|
GdkDragContext *context,
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkSelectionData *selection,
|
2009-11-07 09:55:37 +00:00
|
|
|
guint info,
|
|
|
|
guint time,
|
2009-07-13 15:38:34 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
|
2010-12-15 23:52:26 +00:00
|
|
|
GdkAtom target;
|
|
|
|
|
|
|
|
target = gtk_selection_data_get_target (selection);
|
2009-07-13 15:38:34 +00:00
|
|
|
|
2010-12-15 23:52:26 +00:00
|
|
|
if (target == dnd_target_atom_group)
|
2009-07-13 15:38:34 +00:00
|
|
|
drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
|
|
|
|
|
|
|
|
if (drag_data.item)
|
2010-12-15 23:52:26 +00:00
|
|
|
gtk_selection_data_set (selection, target, 8,
|
2009-07-13 15:38:34 +00:00
|
|
|
(guchar*) &drag_data, sizeof (drag_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_tool_palette_child_set_drag_source (GtkWidget *child,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkToolPalette *palette = GTK_TOOL_PALETTE (data);
|
|
|
|
|
|
|
|
/* Check drag_source,
|
|
|
|
* to work properly when called from gtk_tool_item_group_insert().
|
|
|
|
*/
|
|
|
|
if (!palette->priv->drag_source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GTK_IS_TOOL_ITEM (child) &&
|
|
|
|
(palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_ITEMS))
|
|
|
|
{
|
|
|
|
/* Connect to child instead of the item itself,
|
|
|
|
* to work arround bug 510377.
|
|
|
|
*/
|
|
|
|
if (GTK_IS_TOOL_BUTTON (child))
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (child));
|
|
|
|
|
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
|
|
|
|
&dnd_targets[0], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
|
|
|
|
g_signal_connect (child, "drag-data-get",
|
|
|
|
G_CALLBACK (gtk_tool_palette_item_drag_data_get),
|
|
|
|
palette);
|
|
|
|
}
|
2009-11-11 08:42:49 +00:00
|
|
|
else if (GTK_IS_BUTTON (child) &&
|
2009-07-13 15:38:34 +00:00
|
|
|
(palette->priv->drag_source & GTK_TOOL_PALETTE_DRAG_GROUPS))
|
|
|
|
{
|
|
|
|
gtk_drag_source_set (child, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
|
|
|
|
&dnd_targets[1], 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
|
|
|
|
g_signal_connect (child, "drag-data-get",
|
|
|
|
G_CALLBACK (gtk_tool_palette_child_drag_data_get),
|
|
|
|
palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_drag_target_item:
|
|
|
|
*
|
2009-11-27 04:52:20 +00:00
|
|
|
* Gets the target entry for a dragged #GtkToolItem.
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2010-09-18 16:42:15 +00:00
|
|
|
* Returns: (transfer none): the #GtkTargetEntry for a dragged item.
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
2011-06-06 18:13:44 +00:00
|
|
|
const GtkTargetEntry*
|
2009-07-13 15:38:34 +00:00
|
|
|
gtk_tool_palette_get_drag_target_item (void)
|
|
|
|
{
|
|
|
|
return &dnd_targets[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_drag_target_group:
|
|
|
|
*
|
|
|
|
* Get the target entry for a dragged #GtkToolItemGroup.
|
|
|
|
*
|
2010-09-18 16:42:15 +00:00
|
|
|
* Returns: (transfer none): the #GtkTargetEntry for a dragged group
|
2009-07-13 15:38:34 +00:00
|
|
|
*
|
2009-10-28 12:17:13 +00:00
|
|
|
* Since: 2.20
|
2009-07-13 15:38:34 +00:00
|
|
|
*/
|
2011-06-06 18:13:44 +00:00
|
|
|
const GtkTargetEntry*
|
2009-07-13 15:38:34 +00:00
|
|
|
gtk_tool_palette_get_drag_target_group (void)
|
|
|
|
{
|
|
|
|
return &dnd_targets[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_tool_palette_set_expanding_child (GtkToolPalette *palette,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TOOL_PALETTE (palette));
|
|
|
|
palette->priv->expanding_child = widget;
|
|
|
|
}
|
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_hadjustment:
|
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
*
|
|
|
|
* Gets the horizontal adjustment of the tool palette.
|
|
|
|
*
|
2010-09-18 16:42:15 +00:00
|
|
|
* Returns: (transfer none): the horizontal adjustment of @palette
|
2009-11-27 04:52:20 +00:00
|
|
|
*
|
|
|
|
* Since: 2.20
|
2010-10-18 04:21:39 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.0: Use gtk_scrollable_get_hadjustment()
|
2009-11-27 04:52:20 +00:00
|
|
|
*/
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkAdjustment*
|
|
|
|
gtk_tool_palette_get_hadjustment (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
|
2009-11-27 04:52:20 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
return palette->priv->hadjustment;
|
|
|
|
}
|
|
|
|
|
2010-10-18 04:21:39 +00:00
|
|
|
static void
|
|
|
|
gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
|
|
|
|
GtkAdjustment *adjustment)
|
|
|
|
{
|
|
|
|
GtkToolPalettePrivate *priv = palette->priv;
|
|
|
|
|
|
|
|
if (adjustment && priv->hadjustment == adjustment)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->hadjustment != NULL)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->hadjustment,
|
|
|
|
gtk_tool_palette_adjustment_value_changed,
|
|
|
|
palette);
|
|
|
|
g_object_unref (priv->hadjustment);
|
|
|
|
}
|
|
|
|
|
2010-10-22 15:01:58 +00:00
|
|
|
if (adjustment == NULL)
|
2010-10-18 04:21:39 +00:00
|
|
|
adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
g_signal_connect (adjustment, "value-changed",
|
|
|
|
G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
|
|
|
|
palette);
|
|
|
|
priv->hadjustment = g_object_ref_sink (adjustment);
|
2011-02-23 09:26:21 +00:00
|
|
|
/* FIXME: Adjustment should probably have its values updated now */
|
2010-10-18 04:21:39 +00:00
|
|
|
g_object_notify (G_OBJECT (palette), "hadjustment");
|
|
|
|
}
|
|
|
|
|
2009-11-27 04:52:20 +00:00
|
|
|
/**
|
|
|
|
* gtk_tool_palette_get_vadjustment:
|
|
|
|
* @palette: a #GtkToolPalette
|
|
|
|
*
|
|
|
|
* Gets the vertical adjustment of the tool palette.
|
|
|
|
*
|
2010-09-18 16:42:15 +00:00
|
|
|
* Returns: (transfer none): the vertical adjustment of @palette
|
2009-11-27 04:52:20 +00:00
|
|
|
*
|
|
|
|
* Since: 2.20
|
2010-10-18 04:21:39 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
|
2009-11-27 04:52:20 +00:00
|
|
|
*/
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkAdjustment*
|
|
|
|
gtk_tool_palette_get_vadjustment (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
|
2009-11-27 04:52:20 +00:00
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
return palette->priv->vadjustment;
|
|
|
|
}
|
|
|
|
|
2010-10-18 04:21:39 +00:00
|
|
|
static void
|
|
|
|
gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
|
|
|
|
GtkAdjustment *adjustment)
|
|
|
|
{
|
|
|
|
GtkToolPalettePrivate *priv = palette->priv;
|
|
|
|
|
|
|
|
if (adjustment && priv->vadjustment == adjustment)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->vadjustment != NULL)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->vadjustment,
|
|
|
|
gtk_tool_palette_adjustment_value_changed,
|
|
|
|
palette);
|
|
|
|
g_object_unref (priv->vadjustment);
|
|
|
|
}
|
|
|
|
|
2010-10-22 15:01:58 +00:00
|
|
|
if (adjustment == NULL)
|
2010-10-18 04:21:39 +00:00
|
|
|
adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
g_signal_connect (adjustment, "value-changed",
|
|
|
|
G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
|
|
|
|
palette);
|
|
|
|
priv->vadjustment = g_object_ref_sink (adjustment);
|
2011-02-23 09:26:21 +00:00
|
|
|
/* FIXME: Adjustment should probably have its values updated now */
|
2010-10-18 04:21:39 +00:00
|
|
|
g_object_notify (G_OBJECT (palette), "vadjustment");
|
|
|
|
}
|
|
|
|
|
2009-07-13 15:38:34 +00:00
|
|
|
GtkSizeGroup *
|
|
|
|
_gtk_tool_palette_get_size_group (GtkToolPalette *palette)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
|
|
|
|
|
|
|
|
return palette->priv->text_size_group;
|
|
|
|
}
|