2011-03-01 19:31:17 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpiconpicker.c
|
|
|
|
* Copyright (C) 2011 Michael Natterer <mitch@gimp.org>
|
2012-12-12 12:50:45 +08:00
|
|
|
* 2012 Daniel Sabo
|
2011-03-01 19:31:17 +08:00
|
|
|
*
|
|
|
|
* 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/>.
|
2011-03-01 19:31:17 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2011-03-01 19:31:17 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2011-04-28 20:23:33 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2011-03-01 19:31:17 +08:00
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimplist.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimptemplate.h"
|
2012-12-12 12:50:45 +08:00
|
|
|
#include "core/gimpviewable.h"
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
#include "gimpcontainerpopup.h"
|
2011-03-01 19:31:17 +08:00
|
|
|
#include "gimpiconpicker.h"
|
2013-03-11 02:46:20 +08:00
|
|
|
#include "gimpview.h"
|
2011-03-01 19:31:17 +08:00
|
|
|
#include "gimpviewablebutton.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_GIMP,
|
2014-05-09 08:24:42 +08:00
|
|
|
PROP_ICON_NAME,
|
2012-12-12 12:50:45 +08:00
|
|
|
PROP_ICON_PIXBUF
|
2011-03-01 19:31:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _GimpIconPickerPrivate GimpIconPickerPrivate;
|
|
|
|
|
|
|
|
struct _GimpIconPickerPrivate
|
|
|
|
{
|
|
|
|
Gimp *gimp;
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
gchar *icon_name;
|
2012-12-12 12:50:45 +08:00
|
|
|
GdkPixbuf *icon_pixbuf;
|
|
|
|
|
|
|
|
GimpViewable *preview;
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
GimpContainer *icon_name_container;
|
|
|
|
GimpContext *icon_name_context;
|
2012-12-12 12:50:45 +08:00
|
|
|
GimpObject *null_template_object;
|
|
|
|
|
|
|
|
GtkWidget *right_click_menu;
|
|
|
|
GtkWidget *menu_item_file_icon;
|
2014-05-09 08:24:42 +08:00
|
|
|
GtkWidget *menu_item_name_icon;
|
2012-12-12 12:50:45 +08:00
|
|
|
GtkWidget *menu_item_copy;
|
|
|
|
GtkWidget *menu_item_paste;
|
2011-03-01 19:31:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GET_PRIVATE(picker) \
|
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
|
|
|
((GimpIconPickerPrivate *) gimp_icon_picker_get_instance_private ((GimpIconPicker *) (picker)))
|
2011-03-01 19:31:17 +08:00
|
|
|
|
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
static void gimp_icon_picker_constructed (GObject *object);
|
|
|
|
static void gimp_icon_picker_finalize (GObject *object);
|
|
|
|
static void gimp_icon_picker_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_icon_picker_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_icon_picker_icon_changed (GimpContext *context,
|
|
|
|
GimpTemplate *template,
|
|
|
|
GimpIconPicker *picker);
|
|
|
|
static void gimp_icon_picker_clicked (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void gimp_icon_picker_menu_from_file (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
2014-05-09 08:24:42 +08:00
|
|
|
static void gimp_icon_picker_menu_from_name (GtkWidget *widget,
|
2012-12-12 12:50:45 +08:00
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_icon_picker_menu_paste (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_icon_picker_menu_copy (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2013-03-11 02:46:20 +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 (GimpIconPicker, gimp_icon_picker, GTK_TYPE_BOX)
|
2011-03-01 19:31:17 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_icon_picker_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_class_init (GimpIconPickerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructed = gimp_icon_picker_constructed;
|
|
|
|
object_class->finalize = gimp_icon_picker_finalize;
|
|
|
|
object_class->set_property = gimp_icon_picker_set_property;
|
|
|
|
object_class->get_property = gimp_icon_picker_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_GIMP,
|
|
|
|
g_param_spec_object ("gimp", NULL, NULL,
|
|
|
|
GIMP_TYPE_GIMP,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_ICON_NAME,
|
|
|
|
g_param_spec_string ("icon-name", NULL, NULL,
|
2011-03-01 19:31:17 +08:00
|
|
|
"gimp-toilet-paper",
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_ICON_PIXBUF,
|
|
|
|
g_param_spec_object ("icon-pixbuf", NULL, NULL,
|
|
|
|
GDK_TYPE_PIXBUF,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2011-03-01 19:31:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_init (GimpIconPicker *picker)
|
|
|
|
{
|
2012-12-12 12:50:45 +08:00
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (picker);
|
|
|
|
|
2011-03-01 19:31:17 +08:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (picker),
|
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
|
|
|
private->preview = g_object_new (GIMP_TYPE_VIEWABLE,
|
2014-05-09 08:24:42 +08:00
|
|
|
"icon-name", private->icon_name,
|
2012-12-12 12:50:45 +08:00
|
|
|
"icon-pixbuf", private->icon_pixbuf,
|
|
|
|
NULL);
|
2011-03-01 19:31:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_constructed (GObject *object)
|
|
|
|
{
|
2012-12-12 12:50:45 +08:00
|
|
|
GimpIconPicker *picker = GIMP_ICON_PICKER (object);
|
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (object);
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *viewable_view;
|
2014-05-09 08:24:42 +08:00
|
|
|
GList *icon_list;
|
|
|
|
GList *list;
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2018-02-12 05:23:10 +08:00
|
|
|
gimp_assert (GIMP_IS_GIMP (private->gimp));
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
/* Set up the icon picker */
|
|
|
|
private->icon_name_container = gimp_list_new (GIMP_TYPE_TEMPLATE, FALSE);
|
|
|
|
private->icon_name_context = gimp_context_new (private->gimp, "foo", NULL);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
g_signal_connect (private->icon_name_context, "template-changed",
|
2011-03-01 19:31:17 +08:00
|
|
|
G_CALLBACK (gimp_icon_picker_icon_changed),
|
|
|
|
picker);
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
icon_list = gtk_icon_theme_list_icons (gtk_icon_theme_get_default (), NULL);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
icon_list = g_list_sort (icon_list, (GCompareFunc) g_strcmp0);
|
|
|
|
icon_list = g_list_reverse (icon_list);
|
|
|
|
|
|
|
|
for (list = icon_list; list; list = g_list_next (list))
|
2011-03-01 19:31:17 +08:00
|
|
|
{
|
|
|
|
GimpObject *object = g_object_new (GIMP_TYPE_TEMPLATE,
|
2014-05-09 08:24:42 +08:00
|
|
|
"name", list->data,
|
|
|
|
"icon-name", list->data,
|
2011-03-01 19:31:17 +08:00
|
|
|
NULL);
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_container_add (private->icon_name_container, object);
|
2011-03-01 19:31:17 +08:00
|
|
|
g_object_unref (object);
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
if (private->icon_name && strcmp (list->data, private->icon_name) == 0)
|
|
|
|
gimp_context_set_template (private->icon_name_context,
|
2011-03-01 19:31:17 +08:00
|
|
|
GIMP_TEMPLATE (object));
|
|
|
|
}
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
/* An extra template object, use to make all icons clickable when a
|
|
|
|
* pixbuf icon is set.
|
2012-12-12 12:50:45 +08:00
|
|
|
*/
|
|
|
|
private->null_template_object = g_object_new (GIMP_TYPE_TEMPLATE,
|
2014-05-09 08:24:42 +08:00
|
|
|
"name", "",
|
|
|
|
"icon-name", "",
|
2012-12-12 12:50:45 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (private->icon_pixbuf)
|
|
|
|
{
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_context_set_template (private->icon_name_context,
|
2012-12-12 12:50:45 +08:00
|
|
|
GIMP_TEMPLATE (private->null_template_object));
|
|
|
|
}
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
g_list_free_full (icon_list, (GDestroyNotify) g_free);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
|
|
|
|
/* Set up preview button */
|
2013-03-11 05:33:45 +08:00
|
|
|
button = gtk_button_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (picker), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect (button, "button-press-event",
|
|
|
|
G_CALLBACK (gimp_icon_picker_clicked),
|
|
|
|
object);
|
|
|
|
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
viewable_view = gimp_view_new (private->icon_name_context,
|
2012-12-12 12:50:45 +08:00
|
|
|
private->preview,
|
|
|
|
GIMP_VIEW_SIZE_SMALL,
|
|
|
|
0,
|
|
|
|
FALSE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (viewable_view));
|
|
|
|
gtk_widget_show (viewable_view);
|
|
|
|
|
2013-03-11 05:33:45 +08:00
|
|
|
/* Set up button menu */
|
2012-12-12 12:50:45 +08:00
|
|
|
private->right_click_menu = gtk_menu_new ();
|
|
|
|
gtk_menu_attach_to_widget (GTK_MENU (private->right_click_menu), button, NULL);
|
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
private->menu_item_file_icon =
|
|
|
|
gtk_menu_item_new_with_label (_("From File..."));
|
2012-12-12 12:50:45 +08:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (private->right_click_menu),
|
|
|
|
GTK_WIDGET (private->menu_item_file_icon));
|
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
g_signal_connect (private->menu_item_file_icon, "button-press-event",
|
|
|
|
G_CALLBACK (gimp_icon_picker_menu_from_file),
|
|
|
|
object);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
private->menu_item_name_icon =
|
|
|
|
gtk_menu_item_new_with_label (_("From Named Icons..."));
|
2012-12-12 12:50:45 +08:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (private->right_click_menu),
|
2014-05-09 08:24:42 +08:00
|
|
|
GTK_WIDGET (private->menu_item_name_icon));
|
2012-12-12 12:50:45 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
g_signal_connect (private->menu_item_name_icon, "button-press-event",
|
|
|
|
G_CALLBACK (gimp_icon_picker_menu_from_name),
|
2013-03-11 02:46:20 +08:00
|
|
|
object);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
private->menu_item_copy =
|
|
|
|
gtk_menu_item_new_with_label (_("Copy Icon to Clipboard"));
|
2012-12-12 12:50:45 +08:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (private->right_click_menu),
|
|
|
|
GTK_WIDGET (private->menu_item_copy));
|
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
g_signal_connect (private->menu_item_copy, "button-press-event",
|
|
|
|
G_CALLBACK (gimp_icon_picker_menu_copy),
|
|
|
|
object);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
private->menu_item_paste =
|
|
|
|
gtk_menu_item_new_with_label (_("Paste Icon from Clipboard"));
|
2012-12-12 12:50:45 +08:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (private->right_click_menu),
|
|
|
|
GTK_WIDGET (private->menu_item_paste));
|
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
g_signal_connect (private->menu_item_paste, "button-press-event",
|
|
|
|
G_CALLBACK (gimp_icon_picker_menu_paste),
|
|
|
|
object);
|
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
gtk_widget_show_all (GTK_WIDGET (private->right_click_menu));
|
2011-03-01 19:31:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (object);
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_pointer (&private->icon_name, g_free);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&private->icon_name_container);
|
|
|
|
g_clear_object (&private->icon_name_context);
|
|
|
|
g_clear_object (&private->icon_pixbuf);
|
|
|
|
g_clear_object (&private->preview);
|
|
|
|
g_clear_object (&private->null_template_object);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
2011-03-01 19:31:17 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_GIMP:
|
|
|
|
private->gimp = g_value_get_object (value); /* don't ref */
|
|
|
|
break;
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
case PROP_ICON_NAME:
|
|
|
|
gimp_icon_picker_set_icon_name (GIMP_ICON_PICKER (object),
|
|
|
|
g_value_get_string (value));
|
2011-03-01 19:31:17 +08:00
|
|
|
break;
|
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
case PROP_ICON_PIXBUF:
|
|
|
|
gimp_icon_picker_set_icon_pixbuf (GIMP_ICON_PICKER (object),
|
2013-03-11 02:46:20 +08:00
|
|
|
g_value_get_object (value));
|
2012-12-12 12:50:45 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-01 19:31:17 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-12 12:50:45 +08:00
|
|
|
gimp_icon_picker_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2011-03-01 19:31:17 +08:00
|
|
|
{
|
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_GIMP:
|
|
|
|
g_value_set_object (value, private->gimp);
|
|
|
|
break;
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
case PROP_ICON_NAME:
|
|
|
|
g_value_set_string (value, private->icon_name);
|
2011-03-01 19:31:17 +08:00
|
|
|
break;
|
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
case PROP_ICON_PIXBUF:
|
|
|
|
g_value_set_object (value, private->icon_pixbuf);
|
|
|
|
break;
|
|
|
|
|
2011-03-01 19:31:17 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_icon_picker_new (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_ICON_PICKER,
|
|
|
|
"gimp", gimp,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_icon_picker_get_icon_name (GimpIconPicker *picker)
|
2011-03-01 19:31:17 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_ICON_PICKER (picker), NULL);
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
return GET_PRIVATE (picker)->icon_name;
|
2011-03-01 19:31:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_icon_picker_set_icon_name (GimpIconPicker *picker,
|
|
|
|
const gchar *icon_name)
|
2011-03-01 19:31:17 +08:00
|
|
|
{
|
|
|
|
GimpIconPickerPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_ICON_PICKER (picker));
|
2014-05-09 08:24:42 +08:00
|
|
|
g_return_if_fail (icon_name != NULL);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
|
|
|
private = GET_PRIVATE (picker);
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
g_free (private->icon_name);
|
|
|
|
private->icon_name = g_strdup (icon_name);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
if (private->icon_name_container)
|
2011-03-01 19:31:17 +08:00
|
|
|
{
|
|
|
|
GimpObject *object;
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
object = gimp_container_get_child_by_name (private->icon_name_container,
|
|
|
|
icon_name);
|
2011-03-01 19:31:17 +08:00
|
|
|
|
|
|
|
if (object)
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_context_set_template (private->icon_name_context,
|
2011-03-01 19:31:17 +08:00
|
|
|
GIMP_TEMPLATE (object));
|
|
|
|
}
|
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
g_object_set (private->preview,
|
2014-05-09 08:24:42 +08:00
|
|
|
"icon-name", private->icon_name,
|
2013-03-11 02:46:20 +08:00
|
|
|
NULL);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
g_object_notify (G_OBJECT (picker), "icon-name");
|
2011-03-01 19:31:17 +08:00
|
|
|
}
|
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
GdkPixbuf *
|
|
|
|
gimp_icon_picker_get_icon_pixbuf (GimpIconPicker *picker)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_ICON_PICKER (picker), NULL);
|
|
|
|
|
|
|
|
return GET_PRIVATE (picker)->icon_pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_icon_picker_set_icon_pixbuf (GimpIconPicker *picker,
|
|
|
|
GdkPixbuf *value)
|
|
|
|
{
|
|
|
|
GimpIconPickerPrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_ICON_PICKER (picker));
|
|
|
|
g_return_if_fail (value == NULL || GDK_IS_PIXBUF (value));
|
|
|
|
|
|
|
|
private = GET_PRIVATE (picker);
|
|
|
|
|
|
|
|
if (private->icon_pixbuf)
|
|
|
|
g_object_unref (private->icon_pixbuf);
|
|
|
|
|
|
|
|
private->icon_pixbuf = value;
|
|
|
|
|
|
|
|
if (private->icon_pixbuf)
|
|
|
|
{
|
|
|
|
g_object_ref (private->icon_pixbuf);
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_context_set_template (private->icon_name_context,
|
2012-12-12 12:50:45 +08:00
|
|
|
GIMP_TEMPLATE (private->null_template_object));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpObject *object;
|
|
|
|
|
2014-05-09 08:24:42 +08:00
|
|
|
object = gimp_container_get_child_by_name (private->icon_name_container,
|
|
|
|
private->icon_name);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
|
|
|
if (object)
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_context_set_template (private->icon_name_context,
|
2012-12-12 12:50:45 +08:00
|
|
|
GIMP_TEMPLATE (object));
|
|
|
|
}
|
|
|
|
|
2013-03-11 02:46:20 +08:00
|
|
|
g_object_set (private->preview,
|
|
|
|
"icon-pixbuf", private->icon_pixbuf,
|
|
|
|
NULL);
|
2012-12-12 12:50:45 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (picker), "icon-pixbuf");
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:31:17 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_icon_changed (GimpContext *context,
|
|
|
|
GimpTemplate *template,
|
|
|
|
GimpIconPicker *picker)
|
|
|
|
{
|
2012-12-12 12:50:45 +08:00
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (picker);
|
|
|
|
|
|
|
|
if (GIMP_OBJECT (template) != private->null_template_object)
|
|
|
|
{
|
|
|
|
gimp_icon_picker_set_icon_pixbuf (picker, NULL);
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_icon_picker_set_icon_name (picker, gimp_object_get_name (template));
|
2012-12-12 12:50:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_menu_from_file (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer object)
|
|
|
|
{
|
|
|
|
GimpIconPicker *picker = GIMP_ICON_PICKER (object);
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkFileFilter *filter;
|
|
|
|
|
|
|
|
dialog = gtk_file_chooser_dialog_new (_("Load Icon Image"),
|
|
|
|
NULL,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
2017-02-12 23:06:34 +08:00
|
|
|
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Open"), GTK_RESPONSE_ACCEPT,
|
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
filter = gtk_file_filter_new ();
|
|
|
|
gtk_file_filter_add_pixbuf_formats (filter);
|
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
|
|
|
|
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
2013-03-11 02:46:20 +08:00
|
|
|
gchar *filename;
|
2012-12-12 12:50:45 +08:00
|
|
|
GdkPixbuf *icon_pixbuf = NULL;
|
|
|
|
|
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
|
|
|
|
|
|
|
icon_pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
|
|
|
|
|
|
|
|
if (icon_pixbuf)
|
|
|
|
{
|
|
|
|
gimp_icon_picker_set_icon_pixbuf (picker, icon_pixbuf);
|
|
|
|
g_object_unref (icon_pixbuf);
|
|
|
|
}
|
2017-02-12 23:06:34 +08:00
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
g_free (filename);
|
|
|
|
}
|
2017-02-12 23:06:34 +08:00
|
|
|
|
2012-12-12 12:50:45 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_menu_copy (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer object)
|
|
|
|
{
|
|
|
|
GimpIconPicker *picker = GIMP_ICON_PICKER (object);
|
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (picker);
|
|
|
|
GtkClipboard *clipboard = NULL;
|
|
|
|
|
|
|
|
clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
|
|
|
|
GDK_SELECTION_CLIPBOARD);
|
|
|
|
|
|
|
|
if (private->icon_pixbuf)
|
|
|
|
{
|
|
|
|
gtk_clipboard_set_image (clipboard, private->icon_pixbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_menu_paste (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer object)
|
|
|
|
{
|
|
|
|
GimpIconPicker *picker = GIMP_ICON_PICKER (object);
|
|
|
|
GtkClipboard *clipboard = NULL;
|
|
|
|
GdkPixbuf *clipboard_pixbuf = NULL;
|
|
|
|
|
|
|
|
clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
|
|
|
|
GDK_SELECTION_CLIPBOARD);
|
|
|
|
|
|
|
|
clipboard_pixbuf = gtk_clipboard_wait_for_image (clipboard);
|
|
|
|
|
|
|
|
if (clipboard_pixbuf)
|
|
|
|
{
|
|
|
|
gimp_icon_picker_set_icon_pixbuf (picker, clipboard_pixbuf);
|
|
|
|
g_object_unref (clipboard_pixbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_icon_picker_clicked (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer object)
|
|
|
|
{
|
|
|
|
GimpIconPicker *picker = GIMP_ICON_PICKER (object);
|
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (picker);
|
|
|
|
GtkClipboard *clipboard = NULL;
|
|
|
|
|
|
|
|
clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
|
|
|
|
GDK_SELECTION_CLIPBOARD);
|
|
|
|
|
|
|
|
if (gtk_clipboard_wait_is_image_available (clipboard))
|
|
|
|
gtk_widget_set_sensitive (private->menu_item_paste, TRUE);
|
|
|
|
else
|
|
|
|
gtk_widget_set_sensitive (private->menu_item_paste, FALSE);
|
|
|
|
|
|
|
|
if (private->icon_pixbuf)
|
|
|
|
gtk_widget_set_sensitive (private->menu_item_copy, TRUE);
|
|
|
|
else
|
|
|
|
gtk_widget_set_sensitive (private->menu_item_copy, FALSE);
|
|
|
|
|
2018-05-02 05:42:48 +08:00
|
|
|
gtk_menu_popup_at_widget (GTK_MENU (private->right_click_menu),
|
|
|
|
widget,
|
|
|
|
GDK_GRAVITY_EAST,
|
|
|
|
GDK_GRAVITY_NORTH_WEST,
|
|
|
|
(GdkEvent *) event);
|
2012-12-12 12:50:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-09 08:24:42 +08:00
|
|
|
gimp_icon_picker_menu_from_name (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer object)
|
2012-12-12 12:50:45 +08:00
|
|
|
{
|
|
|
|
GimpIconPicker *picker = GIMP_ICON_PICKER (object);
|
|
|
|
GimpIconPickerPrivate *private = GET_PRIVATE (picker);
|
|
|
|
GtkWidget *popup;
|
|
|
|
|
|
|
|
/* FIXME: Right clicking on this popup can cause a crash */
|
2014-05-09 08:24:42 +08:00
|
|
|
popup = gimp_container_popup_new (private->icon_name_container,
|
|
|
|
private->icon_name_context,
|
2012-12-12 12:50:45 +08:00
|
|
|
GIMP_VIEW_TYPE_LIST,
|
|
|
|
GIMP_VIEW_SIZE_SMALL,
|
|
|
|
GIMP_VIEW_SIZE_SMALL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_container_popup_set_view_type (GIMP_CONTAINER_POPUP (popup),
|
|
|
|
GIMP_VIEW_TYPE_GRID);
|
|
|
|
|
2014-06-06 06:57:20 +08:00
|
|
|
gimp_popup_show (GIMP_POPUP (popup), GTK_WIDGET (picker));
|
2011-03-01 19:31:17 +08:00
|
|
|
}
|