2008-12-20 22:46:54 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpcombotagentry.c
|
|
|
|
* Copyright (C) 2008 Aurimas Juška <aurisj@svn.gnome.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2008-12-20 22:46:54 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-12-20 22:46:54 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-20 22:46:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2008-12-20 22:46:54 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2017-03-05 23:01:59 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimptag.h"
|
|
|
|
#include "core/gimptagged.h"
|
2011-03-23 06:11:46 +08:00
|
|
|
#include "core/gimptaggedcontainer.h"
|
|
|
|
#include "core/gimpviewable.h"
|
2008-12-20 22:46:54 +08:00
|
|
|
|
|
|
|
#include "gimptagentry.h"
|
|
|
|
#include "gimptagpopup.h"
|
|
|
|
#include "gimpcombotagentry.h"
|
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
|
2011-03-23 06:11:46 +08:00
|
|
|
static void gimp_combo_tag_entry_constructed (GObject *object);
|
|
|
|
static void gimp_combo_tag_entry_dispose (GObject *object);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2010-10-20 02:09:22 +08:00
|
|
|
static gboolean gimp_combo_tag_entry_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
2011-02-09 18:44:32 +08:00
|
|
|
static void gimp_combo_tag_entry_style_updated (GtkWidget *widget);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2011-03-23 06:11:46 +08:00
|
|
|
static void gimp_combo_tag_entry_icon_press (GtkWidget *widget,
|
|
|
|
GtkEntryIconPosition icon_pos,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer user_data);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2014-07-21 08:34:39 +08:00
|
|
|
static void gimp_combo_tag_entry_popup_destroy (GtkWidget *widget,
|
2011-03-23 06:11:46 +08:00
|
|
|
GimpComboTagEntry *entry);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2011-03-23 06:11:46 +08:00
|
|
|
static void gimp_combo_tag_entry_tag_count_changed (GimpTaggedContainer *container,
|
|
|
|
gint tag_count,
|
|
|
|
GimpComboTagEntry *entry);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpComboTagEntry, gimp_combo_tag_entry, GIMP_TYPE_TAG_ENTRY);
|
|
|
|
|
|
|
|
#define parent_class gimp_combo_tag_entry_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_combo_tag_entry_class_init (GimpComboTagEntryClass *klass)
|
|
|
|
{
|
2009-03-03 05:34:59 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
object_class->constructed = gimp_combo_tag_entry_constructed;
|
|
|
|
object_class->dispose = gimp_combo_tag_entry_dispose;
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
widget_class->draw = gimp_combo_tag_entry_draw;
|
|
|
|
widget_class->style_updated = gimp_combo_tag_entry_style_updated;
|
2008-12-20 22:46:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-31 08:01:24 +08:00
|
|
|
gimp_combo_tag_entry_init (GimpComboTagEntry *entry)
|
2008-12-20 22:46:54 +08:00
|
|
|
{
|
2009-11-16 03:28:39 +08:00
|
|
|
entry->popup = NULL;
|
|
|
|
entry->normal_item_attr = NULL;
|
|
|
|
entry->selected_item_attr = NULL;
|
2008-12-31 08:01:24 +08:00
|
|
|
entry->insensitive_item_attr = NULL;
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
gtk_widget_add_events (GTK_WIDGET (entry),
|
2009-11-16 03:28:39 +08:00
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2014-05-07 21:30:38 +08:00
|
|
|
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
2017-03-05 23:01:59 +08:00
|
|
|
GIMP_ICON_GO_DOWN);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
|
|
|
g_signal_connect (entry, "icon-press",
|
|
|
|
G_CALLBACK (gimp_combo_tag_entry_icon_press),
|
2008-12-20 22:46:54 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2011-01-14 16:38:11 +08:00
|
|
|
static void
|
|
|
|
gimp_combo_tag_entry_constructed (GObject *object)
|
2008-12-20 22:46:54 +08:00
|
|
|
{
|
2011-01-14 16:38:11 +08:00
|
|
|
GimpComboTagEntry *entry = GIMP_COMBO_TAG_ENTRY (object);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2009-01-05 03:45:07 +08:00
|
|
|
g_signal_connect_object (GIMP_TAG_ENTRY (entry)->container,
|
|
|
|
"tag-count-changed",
|
|
|
|
G_CALLBACK (gimp_combo_tag_entry_tag_count_changed),
|
|
|
|
entry, 0);
|
2008-12-20 22:46:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-31 08:01:24 +08:00
|
|
|
gimp_combo_tag_entry_dispose (GObject *object)
|
2008-12-20 22:46:54 +08:00
|
|
|
{
|
2008-12-31 08:01:24 +08:00
|
|
|
GimpComboTagEntry *combo_entry = GIMP_COMBO_TAG_ENTRY (object);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
|
|
|
if (combo_entry->normal_item_attr)
|
|
|
|
{
|
|
|
|
pango_attr_list_unref (combo_entry->normal_item_attr);
|
|
|
|
combo_entry->normal_item_attr = NULL;
|
|
|
|
}
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
if (combo_entry->selected_item_attr)
|
|
|
|
{
|
|
|
|
pango_attr_list_unref (combo_entry->selected_item_attr);
|
|
|
|
combo_entry->selected_item_attr = NULL;
|
|
|
|
}
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
if (combo_entry->insensitive_item_attr)
|
|
|
|
{
|
|
|
|
pango_attr_list_unref (combo_entry->insensitive_item_attr);
|
|
|
|
combo_entry->insensitive_item_attr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2009-11-16 04:34:16 +08:00
|
|
|
static gboolean
|
2010-10-20 02:09:22 +08:00
|
|
|
gimp_combo_tag_entry_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
2009-11-16 04:34:16 +08:00
|
|
|
{
|
2011-02-09 18:44:32 +08:00
|
|
|
GtkStyleContext *style = gtk_widget_get_style_context (widget);
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
gint x, y;
|
2010-10-21 01:38:20 +08:00
|
|
|
|
2010-10-22 22:45:36 +08:00
|
|
|
cairo_save (cr);
|
2010-10-21 01:38:20 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
|
2010-10-22 22:45:36 +08:00
|
|
|
cairo_restore (cr);
|
2009-11-16 04:34:16 +08:00
|
|
|
|
2010-10-22 22:45:36 +08:00
|
|
|
gtk_entry_get_icon_area (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
&icon_area);
|
2010-10-21 01:38:20 +08:00
|
|
|
|
2010-10-22 22:45:36 +08:00
|
|
|
x = icon_area.x + (icon_area.width - 8) / 2;
|
|
|
|
y = icon_area.y + (icon_area.height - 8) / 2;
|
2010-10-21 01:38:20 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
gtk_render_arrow (style, cr, G_PI, x, y, 8);
|
2009-11-16 04:34:16 +08:00
|
|
|
|
2010-10-21 01:38:20 +08:00
|
|
|
return FALSE;
|
2009-11-16 04:34:16 +08:00
|
|
|
}
|
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
static void
|
2011-02-09 18:44:32 +08:00
|
|
|
gimp_combo_tag_entry_style_updated (GtkWidget *widget)
|
2008-12-20 22:46:54 +08:00
|
|
|
{
|
2011-02-09 18:44:32 +08:00
|
|
|
GimpComboTagEntry *entry = GIMP_COMBO_TAG_ENTRY (widget);
|
|
|
|
GtkStyleContext *style = gtk_widget_get_style_context (widget);
|
|
|
|
GdkRGBA color;
|
|
|
|
const PangoFontDescription *font_desc;
|
|
|
|
PangoAttribute *attribute;
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
if (entry->normal_item_attr)
|
2009-11-16 03:28:39 +08:00
|
|
|
pango_attr_list_unref (entry->normal_item_attr);
|
2008-12-31 08:01:24 +08:00
|
|
|
entry->normal_item_attr = pango_attr_list_new ();
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
font_desc = gtk_style_context_get_font (style, 0);
|
|
|
|
attribute = pango_attr_font_desc_new (font_desc);
|
|
|
|
pango_attr_list_insert (entry->normal_item_attr, attribute);
|
|
|
|
|
|
|
|
gtk_style_context_get_color (style, 0, &color);
|
|
|
|
attribute = pango_attr_foreground_new (color.red * 65535.99,
|
|
|
|
color.green * 65535.99,
|
|
|
|
color.blue * 65535.99);
|
2008-12-31 08:01:24 +08:00
|
|
|
pango_attr_list_insert (entry->normal_item_attr, attribute);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
if (entry->selected_item_attr)
|
2009-11-16 03:28:39 +08:00
|
|
|
pango_attr_list_unref (entry->selected_item_attr);
|
2008-12-31 08:01:24 +08:00
|
|
|
entry->selected_item_attr = pango_attr_list_copy (entry->normal_item_attr);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color);
|
|
|
|
attribute = pango_attr_foreground_new (color.red * 65535.99,
|
|
|
|
color.green * 65535.99,
|
|
|
|
color.blue * 65535.99);
|
2008-12-31 08:01:24 +08:00
|
|
|
pango_attr_list_insert (entry->selected_item_attr, attribute);
|
2011-02-09 18:44:32 +08:00
|
|
|
gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color);
|
|
|
|
attribute = pango_attr_background_new (color.red * 65535.99,
|
|
|
|
color.green * 65535.99,
|
|
|
|
color.blue * 65535.99);
|
2008-12-31 08:01:24 +08:00
|
|
|
pango_attr_list_insert (entry->selected_item_attr, attribute);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
if (entry->insensitive_item_attr)
|
2009-11-16 03:28:39 +08:00
|
|
|
pango_attr_list_unref (entry->insensitive_item_attr);
|
2008-12-31 08:01:24 +08:00
|
|
|
entry->insensitive_item_attr = pango_attr_list_copy (entry->normal_item_attr);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
gtk_style_context_get_color (style, GTK_STATE_FLAG_INSENSITIVE, &color);
|
|
|
|
attribute = pango_attr_foreground_new (color.red * 65535.99,
|
|
|
|
color.green * 65535.99,
|
|
|
|
color.blue * 65535.99);
|
2008-12-31 08:01:24 +08:00
|
|
|
pango_attr_list_insert (entry->insensitive_item_attr, attribute);
|
2011-02-09 18:44:32 +08:00
|
|
|
gtk_style_context_get_background_color (style, GTK_STATE_FLAG_INSENSITIVE, &color);
|
|
|
|
attribute = pango_attr_background_new (color.red * 65535.99,
|
|
|
|
color.green * 65535.99,
|
|
|
|
color.blue * 65535.99);
|
2008-12-31 08:01:24 +08:00
|
|
|
pango_attr_list_insert (entry->insensitive_item_attr, attribute);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2011-02-09 18:44:32 +08:00
|
|
|
gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
|
|
|
|
&entry->selected_item_color);
|
2009-11-16 03:28:39 +08:00
|
|
|
}
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
/**
|
|
|
|
* gimp_combo_tag_entry_new:
|
2011-03-23 06:11:46 +08:00
|
|
|
* @container: a tagged container to be used.
|
2009-11-16 03:28:39 +08:00
|
|
|
* @mode: tag entry mode to work in.
|
|
|
|
*
|
|
|
|
* Creates a new #GimpComboTagEntry widget which extends #GimpTagEntry by
|
|
|
|
* adding ability to pick tags using popup window (similar to combo box).
|
|
|
|
*
|
|
|
|
* Return value: a new #GimpComboTagEntry widget.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2011-03-23 06:11:46 +08:00
|
|
|
gimp_combo_tag_entry_new (GimpTaggedContainer *container,
|
|
|
|
GimpTagEntryMode mode)
|
2009-11-16 03:28:39 +08:00
|
|
|
{
|
2011-03-23 06:11:46 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_TAGGED_CONTAINER (container), NULL);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_COMBO_TAG_ENTRY,
|
|
|
|
"container", container,
|
|
|
|
"mode", mode,
|
|
|
|
NULL);
|
2008-12-20 22:46:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-11-16 03:28:39 +08:00
|
|
|
gimp_combo_tag_entry_icon_press (GtkWidget *widget,
|
|
|
|
GtkEntryIconPosition icon_pos,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer user_data)
|
2008-12-20 22:46:54 +08:00
|
|
|
{
|
2009-11-16 03:28:39 +08:00
|
|
|
GimpComboTagEntry *entry = GIMP_COMBO_TAG_ENTRY (widget);
|
|
|
|
|
|
|
|
if (! entry->popup)
|
|
|
|
{
|
2011-03-23 06:11:46 +08:00
|
|
|
GimpTaggedContainer *container = GIMP_TAG_ENTRY (entry)->container;
|
|
|
|
gint tag_count;
|
2009-10-18 02:20:39 +08:00
|
|
|
|
2011-03-23 06:11:46 +08:00
|
|
|
tag_count = gimp_tagged_container_get_tag_count (container);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
if (tag_count > 0 && ! GIMP_TAG_ENTRY (entry)->has_invalid_tags)
|
|
|
|
{
|
|
|
|
entry->popup = gimp_tag_popup_new (entry);
|
|
|
|
g_signal_connect (entry->popup, "destroy",
|
|
|
|
G_CALLBACK (gimp_combo_tag_entry_popup_destroy),
|
|
|
|
entry);
|
2018-05-01 19:42:19 +08:00
|
|
|
gimp_tag_popup_show (GIMP_TAG_POPUP (entry->popup), event);
|
2009-11-16 03:28:39 +08:00
|
|
|
}
|
|
|
|
}
|
2008-12-20 22:46:54 +08:00
|
|
|
else
|
2009-11-16 03:28:39 +08:00
|
|
|
{
|
|
|
|
gtk_widget_destroy (entry->popup);
|
|
|
|
}
|
|
|
|
}
|
2008-12-31 08:01:24 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
static void
|
2014-07-21 08:34:39 +08:00
|
|
|
gimp_combo_tag_entry_popup_destroy (GtkWidget *widget,
|
2009-11-16 03:28:39 +08:00
|
|
|
GimpComboTagEntry *entry)
|
|
|
|
{
|
|
|
|
entry->popup = NULL;
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (entry));
|
2008-12-20 22:46:54 +08:00
|
|
|
}
|
2009-05-27 02:25:09 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
static void
|
2011-03-23 06:11:46 +08:00
|
|
|
gimp_combo_tag_entry_tag_count_changed (GimpTaggedContainer *container,
|
|
|
|
gint tag_count,
|
|
|
|
GimpComboTagEntry *entry)
|
2009-05-27 02:25:09 +08:00
|
|
|
{
|
2009-11-16 03:28:39 +08:00
|
|
|
gboolean sensitive;
|
2009-05-27 02:25:09 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
sensitive = tag_count > 0 && ! GIMP_TAG_ENTRY (entry)->has_invalid_tags;
|
2009-05-27 02:25:09 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
sensitive);
|
2009-05-27 02:25:09 +08:00
|
|
|
}
|