2010-11-20 06:52:09 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimptoolpalette.c
|
|
|
|
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2010-11-20 06:52:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2010-11-20 06:52:09 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2019-07-31 16:16:21 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2010-11-20 06:52:09 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2016-01-07 12:09:01 +08:00
|
|
|
#include "config/gimpguiconfig.h"
|
|
|
|
|
2010-11-20 06:52:09 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
2011-08-08 01:49:37 +08:00
|
|
|
#include "gimptoolbox.h"
|
2010-11-20 06:52:09 +08:00
|
|
|
#include "gimptoolpalette.h"
|
|
|
|
#include "gimpuimanager.h"
|
|
|
|
#include "gimpwidgets-utils.h"
|
2012-01-31 06:52:59 +08:00
|
|
|
#include "gimpwindowstrategy.h"
|
2010-11-20 06:52:09 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_TOOL_ICON_SIZE GTK_ICON_SIZE_BUTTON
|
|
|
|
#define DEFAULT_BUTTON_RELIEF GTK_RELIEF_NONE
|
|
|
|
|
|
|
|
#define TOOL_BUTTON_DATA_KEY "gimp-tool-palette-item"
|
|
|
|
#define TOOL_INFO_DATA_KEY "gimp-tool-info"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _GimpToolPalettePrivate GimpToolPalettePrivate;
|
|
|
|
|
|
|
|
struct _GimpToolPalettePrivate
|
|
|
|
{
|
2011-08-08 01:49:37 +08:00
|
|
|
GimpToolbox *toolbox;
|
2010-11-20 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
#define GET_PRIVATE(p) ((GimpToolPalettePrivate *) gimp_tool_palette_get_instance_private ((GimpToolPalette *) (p)))
|
2010-11-20 06:52:09 +08:00
|
|
|
|
|
|
|
|
2010-11-22 18:17:15 +08:00
|
|
|
static GtkSizeRequestMode
|
|
|
|
gimp_tool_palette_get_request_mode (GtkWidget *widget);
|
|
|
|
static void gimp_tool_palette_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *min_width,
|
|
|
|
gint *pref_width);
|
|
|
|
static void gimp_tool_palette_get_preferred_height(GtkWidget *widget,
|
|
|
|
gint *min_width,
|
|
|
|
gint *pref_width);
|
|
|
|
static void gimp_tool_palette_height_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
2018-07-30 18:47:18 +08:00
|
|
|
gint *min_height,
|
|
|
|
gint *pref_height);
|
2011-01-10 03:38:01 +08:00
|
|
|
static void gimp_tool_palette_style_updated (GtkWidget *widget);
|
2016-09-10 05:28:37 +08:00
|
|
|
static void gimp_tool_palette_hierarchy_changed (GtkWidget *widget,
|
|
|
|
GtkWidget *previous_toplevel);
|
2010-11-20 06:52:09 +08:00
|
|
|
|
|
|
|
static void gimp_tool_palette_tool_changed (GimpContext *context,
|
|
|
|
GimpToolInfo *tool_info,
|
|
|
|
GimpToolPalette *palette);
|
|
|
|
static void gimp_tool_palette_tool_reorder (GimpContainer *container,
|
|
|
|
GimpToolInfo *tool_info,
|
|
|
|
gint index,
|
|
|
|
GimpToolPalette *palette);
|
2010-11-21 03:37:15 +08:00
|
|
|
static void gimp_tool_palette_tool_button_toggled (GtkWidget *widget,
|
2010-11-20 06:52:09 +08:00
|
|
|
GimpToolPalette *palette);
|
2010-11-21 03:37:15 +08:00
|
|
|
static gboolean gimp_tool_palette_tool_button_press (GtkWidget *widget,
|
2010-11-20 06:52:09 +08:00
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpToolPalette *palette);
|
|
|
|
|
2017-05-10 05:14:24 +08:00
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpToolPalette, gimp_tool_palette,
|
|
|
|
GTK_TYPE_TOOL_PALETTE)
|
2010-11-20 06:52:09 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_tool_palette_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_palette_class_init (GimpToolPaletteClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2010-11-22 18:17:15 +08:00
|
|
|
widget_class->get_request_mode = gimp_tool_palette_get_request_mode;
|
|
|
|
widget_class->get_preferred_width = gimp_tool_palette_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height = gimp_tool_palette_get_preferred_height;
|
|
|
|
widget_class->get_preferred_height_for_width = gimp_tool_palette_height_for_width;
|
2011-01-10 03:38:01 +08:00
|
|
|
widget_class->style_updated = gimp_tool_palette_style_updated;
|
2010-11-22 18:17:15 +08:00
|
|
|
widget_class->hierarchy_changed = gimp_tool_palette_hierarchy_changed;
|
2010-11-20 06:52:09 +08:00
|
|
|
|
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
|
|
|
g_param_spec_enum ("tool-icon-size",
|
|
|
|
NULL, NULL,
|
|
|
|
GTK_TYPE_ICON_SIZE,
|
|
|
|
DEFAULT_TOOL_ICON_SIZE,
|
|
|
|
GIMP_PARAM_READABLE));
|
|
|
|
|
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
|
|
|
g_param_spec_enum ("button-relief",
|
|
|
|
NULL, NULL,
|
|
|
|
GTK_TYPE_RELIEF_STYLE,
|
|
|
|
DEFAULT_BUTTON_RELIEF,
|
|
|
|
GIMP_PARAM_READABLE));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_palette_init (GimpToolPalette *palette)
|
|
|
|
{
|
2013-05-17 20:41:11 +08:00
|
|
|
gtk_tool_palette_set_style (GTK_TOOL_PALETTE (palette), GTK_TOOLBAR_ICONS);
|
2010-11-20 06:52:09 +08:00
|
|
|
}
|
|
|
|
|
2010-11-22 18:17:15 +08:00
|
|
|
static GtkSizeRequestMode
|
|
|
|
gimp_tool_palette_get_request_mode (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
|
|
|
}
|
|
|
|
|
2018-07-30 18:47:18 +08:00
|
|
|
static gint
|
|
|
|
gimp_tool_palette_get_n_tools (GimpToolPalette *palette,
|
|
|
|
gint *button_width,
|
|
|
|
gint *button_height,
|
|
|
|
gint *min_columns,
|
|
|
|
gint *min_rows)
|
|
|
|
{
|
|
|
|
GimpToolPalettePrivate *private = GET_PRIVATE (palette);
|
|
|
|
Gimp *gimp;
|
|
|
|
GList *list;
|
|
|
|
GdkMonitor *monitor;
|
|
|
|
GdkRectangle workarea;
|
|
|
|
gint n_tools;
|
|
|
|
gint max_rows;
|
|
|
|
gint max_columns;
|
|
|
|
|
|
|
|
if (! gimp_tool_palette_get_button_size (palette,
|
|
|
|
button_width, button_height))
|
|
|
|
{
|
|
|
|
/* arbitrary values, just to simplify our callers */
|
|
|
|
*button_width = 24;
|
|
|
|
*button_height = 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp = gimp_toolbox_get_context (private->toolbox)->gimp;
|
|
|
|
|
|
|
|
for (list = gimp_get_tool_info_iter (gimp), n_tools = 0;
|
|
|
|
list;
|
|
|
|
list = list->next)
|
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info = list->data;
|
|
|
|
|
|
|
|
if (tool_info->visible)
|
|
|
|
n_tools++;
|
|
|
|
}
|
|
|
|
|
|
|
|
monitor = gimp_widget_get_monitor (GTK_WIDGET (palette));
|
|
|
|
gdk_monitor_get_workarea (monitor, &workarea);
|
|
|
|
|
|
|
|
max_columns = (workarea.width * 0.9) / *button_width;
|
|
|
|
max_rows = (workarea.height * 0.7) / *button_height;
|
|
|
|
|
|
|
|
*min_columns = MAX (2, n_tools / max_rows);
|
|
|
|
*min_rows = MAX (1, n_tools / max_columns);
|
|
|
|
|
|
|
|
return n_tools;
|
|
|
|
}
|
|
|
|
|
2010-11-22 18:17:15 +08:00
|
|
|
static void
|
|
|
|
gimp_tool_palette_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *min_width,
|
|
|
|
gint *pref_width)
|
|
|
|
{
|
|
|
|
gint button_width;
|
|
|
|
gint button_height;
|
2018-07-30 18:47:18 +08:00
|
|
|
gint min_columns;
|
|
|
|
gint min_rows;
|
2010-11-22 18:17:15 +08:00
|
|
|
|
2018-07-30 18:47:18 +08:00
|
|
|
gimp_tool_palette_get_n_tools (GIMP_TOOL_PALETTE (widget),
|
|
|
|
&button_width, &button_height,
|
|
|
|
&min_columns, &min_rows);
|
|
|
|
|
|
|
|
*min_width = min_columns * button_width;
|
|
|
|
*pref_width = min_columns * button_width;
|
2010-11-22 18:17:15 +08:00
|
|
|
}
|
|
|
|
|
2010-11-20 06:52:09 +08:00
|
|
|
static void
|
2010-11-22 18:17:15 +08:00
|
|
|
gimp_tool_palette_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *min_height,
|
|
|
|
gint *pref_height)
|
|
|
|
{
|
|
|
|
gint button_width;
|
|
|
|
gint button_height;
|
2018-07-30 18:47:18 +08:00
|
|
|
gint min_columns;
|
|
|
|
gint min_rows;
|
2010-11-22 18:17:15 +08:00
|
|
|
|
2018-07-30 18:47:18 +08:00
|
|
|
gimp_tool_palette_get_n_tools (GIMP_TOOL_PALETTE (widget),
|
|
|
|
&button_width, &button_height,
|
|
|
|
&min_columns, &min_rows);
|
|
|
|
|
|
|
|
*min_height = min_rows * button_height;
|
|
|
|
*pref_height = min_rows * button_height;
|
2010-11-22 18:17:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_palette_height_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *min_height,
|
|
|
|
gint *pref_height)
|
2010-11-20 06:52:09 +08:00
|
|
|
{
|
2018-07-30 18:47:18 +08:00
|
|
|
gint n_tools;
|
|
|
|
gint button_width;
|
|
|
|
gint button_height;
|
|
|
|
gint min_columns;
|
|
|
|
gint min_rows;
|
|
|
|
gint tool_columns;
|
|
|
|
gint tool_rows;
|
2010-11-20 06:52:09 +08:00
|
|
|
|
2018-07-30 18:47:18 +08:00
|
|
|
n_tools = gimp_tool_palette_get_n_tools (GIMP_TOOL_PALETTE (widget),
|
|
|
|
&button_width, &button_height,
|
|
|
|
&min_columns, &min_rows);
|
2010-11-20 06:52:09 +08:00
|
|
|
|
2018-07-30 18:47:18 +08:00
|
|
|
tool_columns = MAX (min_columns, width / button_width);
|
|
|
|
tool_rows = n_tools / tool_columns;
|
2010-11-20 06:52:09 +08:00
|
|
|
|
2018-07-30 18:47:18 +08:00
|
|
|
if (n_tools % tool_columns)
|
|
|
|
tool_rows++;
|
2010-11-20 06:52:09 +08:00
|
|
|
|
2018-07-30 18:47:18 +08:00
|
|
|
*min_height = *pref_height = tool_rows * button_height;
|
2010-11-20 06:52:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-10 03:38:01 +08:00
|
|
|
gimp_tool_palette_style_updated (GtkWidget *widget)
|
2010-11-20 06:52:09 +08:00
|
|
|
{
|
|
|
|
GimpToolPalettePrivate *private = GET_PRIVATE (widget);
|
|
|
|
Gimp *gimp;
|
|
|
|
GtkReliefStyle relief;
|
|
|
|
GList *list;
|
2018-05-31 08:59:05 +08:00
|
|
|
GtkIconSize tool_icon_size;
|
2010-11-20 06:52:09 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
|
2010-11-20 06:52:09 +08:00
|
|
|
|
2011-08-08 01:49:37 +08:00
|
|
|
if (! gimp_toolbox_get_context (private->toolbox))
|
2010-11-20 06:52:09 +08:00
|
|
|
return;
|
|
|
|
|
2011-08-08 01:49:37 +08:00
|
|
|
gimp = gimp_toolbox_get_context (private->toolbox)->gimp;
|
2010-11-20 06:52:09 +08:00
|
|
|
|
|
|
|
gtk_widget_style_get (widget,
|
|
|
|
"button-relief", &relief,
|
2018-05-31 08:59:05 +08:00
|
|
|
"tool-icon-size", &tool_icon_size,
|
2010-11-20 06:52:09 +08:00
|
|
|
NULL);
|
|
|
|
|
2018-05-31 08:59:05 +08:00
|
|
|
gtk_tool_palette_set_icon_size (GTK_TOOL_PALETTE (widget),
|
|
|
|
tool_icon_size);
|
|
|
|
|
2010-11-20 06:52:09 +08:00
|
|
|
for (list = gimp_get_tool_info_iter (gimp);
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info = list->data;
|
|
|
|
GtkWidget *tool_button;
|
|
|
|
|
|
|
|
tool_button = g_object_get_data (G_OBJECT (tool_info),
|
|
|
|
TOOL_BUTTON_DATA_KEY);
|
|
|
|
|
|
|
|
if (tool_button)
|
|
|
|
{
|
|
|
|
GtkWidget *button = gtk_bin_get_child (GTK_BIN (tool_button));
|
|
|
|
|
|
|
|
gtk_button_set_relief (GTK_BUTTON (button), relief);
|
|
|
|
}
|
|
|
|
}
|
2013-01-18 02:37:03 +08:00
|
|
|
|
|
|
|
gimp_dock_invalidate_geometry (GIMP_DOCK (private->toolbox));
|
2010-11-20 06:52:09 +08:00
|
|
|
}
|
|
|
|
|
2016-09-10 05:28:37 +08:00
|
|
|
static void
|
|
|
|
gimp_tool_palette_hierarchy_changed (GtkWidget *widget,
|
2017-03-13 00:13:45 +08:00
|
|
|
GtkWidget *previous_toplevel)
|
2016-09-10 05:28:37 +08:00
|
|
|
{
|
|
|
|
GimpToolPalettePrivate *private = GET_PRIVATE (widget);
|
|
|
|
GimpUIManager *ui_manager;
|
|
|
|
|
|
|
|
ui_manager = gimp_dock_get_ui_manager (GIMP_DOCK (private->toolbox));
|
|
|
|
|
|
|
|
if (ui_manager)
|
|
|
|
{
|
|
|
|
GimpContext *context = gimp_toolbox_get_context (private->toolbox);
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = gimp_get_tool_info_iter (context->gimp);
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info = list->data;
|
|
|
|
GtkToolItem *item;
|
2019-07-02 09:54:38 +08:00
|
|
|
GimpAction *action;
|
2016-09-10 05:28:37 +08:00
|
|
|
const gchar *identifier;
|
|
|
|
gchar *tmp;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
item = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
|
|
|
|
|
|
|
|
identifier = gimp_object_get_name (tool_info);
|
|
|
|
|
|
|
|
tmp = g_strndup (identifier + strlen ("gimp-"),
|
|
|
|
strlen (identifier) - strlen ("gimp--tool"));
|
|
|
|
name = g_strdup_printf ("tools-%s", tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
action = gimp_ui_manager_find_action (ui_manager, "tools", name);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (action)
|
|
|
|
gimp_widget_set_accel_help (GTK_WIDGET (item), action);
|
|
|
|
else
|
|
|
|
gimp_help_set_help_data (GTK_WIDGET (item),
|
2017-07-05 03:58:11 +08:00
|
|
|
tool_info->tooltip, tool_info->help_id);
|
2016-11-28 22:52:42 +08:00
|
|
|
|
|
|
|
/* Make sure the toolbox buttons won't grab focus, which has
|
|
|
|
* nearly no practical use, and prevents various actions until
|
|
|
|
* you click back in canvas.
|
|
|
|
*/
|
|
|
|
gtk_widget_set_can_focus (gtk_bin_get_child (GTK_BIN (item)),
|
|
|
|
FALSE);
|
2016-09-10 05:28:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2010-11-20 06:52:09 +08:00
|
|
|
GtkWidget *
|
2011-08-08 01:49:37 +08:00
|
|
|
gimp_tool_palette_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_TOOL_PALETTE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_tool_palette_set_toolbox (GimpToolPalette *palette,
|
|
|
|
GimpToolbox *toolbox)
|
2010-11-20 06:52:09 +08:00
|
|
|
{
|
2011-08-08 01:49:37 +08:00
|
|
|
GimpToolPalettePrivate *private;
|
|
|
|
GimpContext *context;
|
2016-09-10 05:28:37 +08:00
|
|
|
GtkWidget *group;
|
|
|
|
GSList *item_group = NULL;
|
|
|
|
GList *list;
|
2011-08-08 01:49:37 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_TOOL_PALETTE (palette));
|
|
|
|
g_return_if_fail (GIMP_IS_TOOLBOX (toolbox));
|
|
|
|
|
|
|
|
private = GET_PRIVATE (palette);
|
|
|
|
|
|
|
|
private->toolbox = toolbox;
|
|
|
|
|
2016-09-10 05:28:37 +08:00
|
|
|
context = gimp_toolbox_get_context (toolbox);
|
|
|
|
|
|
|
|
group = gtk_tool_item_group_new (_("Tools"));
|
|
|
|
gtk_tool_item_group_set_label_widget (GTK_TOOL_ITEM_GROUP (group), NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (palette), group);
|
|
|
|
gtk_widget_show (group);
|
|
|
|
|
|
|
|
for (list = gimp_get_tool_info_iter (context->gimp);
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info = list->data;
|
|
|
|
GtkToolItem *item;
|
|
|
|
const gchar *icon_name;
|
|
|
|
|
|
|
|
icon_name = gimp_viewable_get_icon_name (GIMP_VIEWABLE (tool_info));
|
|
|
|
|
|
|
|
item = gtk_radio_tool_button_new (item_group);
|
|
|
|
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), icon_name);
|
|
|
|
item_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
|
|
|
|
gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (item));
|
|
|
|
|
|
|
|
g_object_bind_property (tool_info, "visible",
|
|
|
|
item, "visible-horizontal",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
|
|
|
g_object_bind_property (tool_info, "visible",
|
|
|
|
item, "visible-vertical",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY, item);
|
|
|
|
g_object_set_data (G_OBJECT (item) , TOOL_INFO_DATA_KEY, tool_info);
|
|
|
|
|
|
|
|
g_signal_connect (item, "toggled",
|
|
|
|
G_CALLBACK (gimp_tool_palette_tool_button_toggled),
|
|
|
|
palette);
|
|
|
|
|
|
|
|
g_signal_connect (gtk_bin_get_child (GTK_BIN (item)), "button-press-event",
|
|
|
|
G_CALLBACK (gimp_tool_palette_tool_button_press),
|
|
|
|
palette);
|
|
|
|
}
|
2011-08-21 23:43:39 +08:00
|
|
|
|
2011-08-08 01:49:37 +08:00
|
|
|
g_signal_connect_object (context->gimp->tool_info_list, "reorder",
|
|
|
|
G_CALLBACK (gimp_tool_palette_tool_reorder),
|
|
|
|
palette, 0);
|
|
|
|
|
|
|
|
g_signal_connect_object (context, "tool-changed",
|
|
|
|
G_CALLBACK (gimp_tool_palette_tool_changed),
|
|
|
|
palette,
|
|
|
|
0);
|
2016-09-10 05:28:37 +08:00
|
|
|
gimp_tool_palette_tool_changed (context,
|
|
|
|
gimp_context_get_tool (context),
|
|
|
|
palette);
|
2010-11-20 06:52:09 +08:00
|
|
|
}
|
|
|
|
|
2010-11-20 17:20:52 +08:00
|
|
|
gboolean
|
|
|
|
gimp_tool_palette_get_button_size (GimpToolPalette *palette,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
|
|
|
GimpToolPalettePrivate *private;
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
GtkWidget *tool_button;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TOOL_PALETTE (palette), FALSE);
|
|
|
|
g_return_val_if_fail (width != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (height != NULL, FALSE);
|
|
|
|
|
|
|
|
private = GET_PRIVATE (palette);
|
|
|
|
|
2011-08-08 01:49:37 +08:00
|
|
|
tool_info = gimp_get_tool_info (gimp_toolbox_get_context (private->toolbox)->gimp,
|
2010-11-20 17:20:52 +08:00
|
|
|
"gimp-rect-select-tool");
|
|
|
|
tool_button = g_object_get_data (G_OBJECT (tool_info), TOOL_BUTTON_DATA_KEY);
|
|
|
|
|
|
|
|
if (tool_button)
|
|
|
|
{
|
|
|
|
GtkRequisition button_requisition;
|
|
|
|
|
2010-11-22 18:17:15 +08:00
|
|
|
gtk_widget_get_preferred_size (tool_button, &button_requisition, NULL);
|
2010-11-20 17:20:52 +08:00
|
|
|
|
|
|
|
*width = button_requisition.width;
|
|
|
|
*height = button_requisition.height;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-20 06:52:09 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_palette_tool_changed (GimpContext *context,
|
|
|
|
GimpToolInfo *tool_info,
|
|
|
|
GimpToolPalette *palette)
|
|
|
|
{
|
|
|
|
if (tool_info)
|
|
|
|
{
|
|
|
|
GtkWidget *tool_button = g_object_get_data (G_OBJECT (tool_info),
|
|
|
|
TOOL_BUTTON_DATA_KEY);
|
|
|
|
|
|
|
|
if (tool_button &&
|
|
|
|
! gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (tool_button)))
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (tool_button,
|
2010-11-21 03:37:15 +08:00
|
|
|
gimp_tool_palette_tool_button_toggled,
|
2010-11-20 06:52:09 +08:00
|
|
|
palette);
|
|
|
|
|
|
|
|
gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (tool_button),
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (tool_button,
|
2010-11-21 03:37:15 +08:00
|
|
|
gimp_tool_palette_tool_button_toggled,
|
2010-11-20 06:52:09 +08:00
|
|
|
palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_palette_tool_reorder (GimpContainer *container,
|
|
|
|
GimpToolInfo *tool_info,
|
|
|
|
gint index,
|
|
|
|
GimpToolPalette *palette)
|
|
|
|
{
|
|
|
|
if (tool_info)
|
|
|
|
{
|
|
|
|
GtkWidget *button = g_object_get_data (G_OBJECT (tool_info),
|
|
|
|
TOOL_BUTTON_DATA_KEY);
|
|
|
|
GtkWidget *group = gtk_widget_get_parent (button);
|
|
|
|
|
|
|
|
gtk_tool_item_group_set_item_position (GTK_TOOL_ITEM_GROUP (group),
|
|
|
|
GTK_TOOL_ITEM (button), index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-21 03:37:15 +08:00
|
|
|
gimp_tool_palette_tool_button_toggled (GtkWidget *widget,
|
|
|
|
GimpToolPalette *palette)
|
2010-11-20 06:52:09 +08:00
|
|
|
{
|
|
|
|
GimpToolPalettePrivate *private = GET_PRIVATE (palette);
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
|
|
|
|
tool_info = g_object_get_data (G_OBJECT (widget), TOOL_INFO_DATA_KEY);
|
|
|
|
|
|
|
|
if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (widget)))
|
2011-08-08 01:49:37 +08:00
|
|
|
gimp_context_set_tool (gimp_toolbox_get_context (private->toolbox), tool_info);
|
2010-11-20 06:52:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-21 03:37:15 +08:00
|
|
|
gimp_tool_palette_tool_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
GimpToolPalette *palette)
|
2010-11-20 06:52:09 +08:00
|
|
|
{
|
|
|
|
GimpToolPalettePrivate *private = GET_PRIVATE (palette);
|
|
|
|
|
|
|
|
if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
|
|
|
|
{
|
2012-01-31 06:52:59 +08:00
|
|
|
GimpContext *context = gimp_toolbox_get_context (private->toolbox);
|
|
|
|
GimpDock *dock = GIMP_DOCK (private->toolbox);
|
|
|
|
|
|
|
|
gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (context->gimp)),
|
|
|
|
context->gimp,
|
|
|
|
gimp_dock_get_dialog_factory (dock),
|
2014-05-02 09:01:23 +08:00
|
|
|
gimp_widget_get_monitor (widget),
|
2012-01-31 06:52:59 +08:00
|
|
|
"gimp-tool-options");
|
2010-11-20 06:52:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|