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>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpfilteredcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpviewable.h"
|
|
|
|
#include "core/gimptag.h"
|
|
|
|
#include "core/gimptagged.h"
|
|
|
|
|
|
|
|
#include "gimptagentry.h"
|
|
|
|
#include "gimptagpopup.h"
|
|
|
|
#include "gimpcombotagentry.h"
|
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
static GObject* gimp_combo_tag_entry_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
|
|
|
static void gimp_combo_tag_entry_dispose (GObject *object);
|
2009-11-16 03:28:39 +08:00
|
|
|
|
2009-11-16 04:34:16 +08:00
|
|
|
static gboolean gimp_combo_tag_entry_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
2008-12-20 22:46:54 +08:00
|
|
|
static void gimp_combo_tag_entry_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *previous_style);
|
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
static void gimp_combo_tag_entry_icon_press (GtkWidget *widget,
|
|
|
|
GtkEntryIconPosition icon_pos,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer user_data);
|
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
static void gimp_combo_tag_entry_popup_destroy (GtkObject *object,
|
2008-12-31 08:01:24 +08:00
|
|
|
GimpComboTagEntry *entry);
|
2008-12-20 22:46:54 +08:00
|
|
|
|
|
|
|
static void gimp_combo_tag_entry_tag_count_changed (GimpFilteredContainer *container,
|
|
|
|
gint tag_count,
|
2008-12-31 08:01:24 +08:00
|
|
|
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
|
|
|
|
2009-11-16 04:34:16 +08:00
|
|
|
object_class->constructor = gimp_combo_tag_entry_constructor;
|
|
|
|
object_class->dispose = gimp_combo_tag_entry_dispose;
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2009-11-16 04:34:16 +08:00
|
|
|
widget_class->expose_event = gimp_combo_tag_entry_expose;
|
|
|
|
widget_class->style_set = gimp_combo_tag_entry_style_set;
|
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
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
GTK_STOCK_GO_DOWN);
|
|
|
|
|
|
|
|
g_signal_connect (entry, "icon-press",
|
|
|
|
G_CALLBACK (gimp_combo_tag_entry_icon_press),
|
2008-12-20 22:46:54 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2009-01-05 03:45:07 +08:00
|
|
|
static GObject *
|
2008-12-20 22:46:54 +08:00
|
|
|
gimp_combo_tag_entry_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
2008-12-31 08:01:24 +08:00
|
|
|
GObject *object;
|
|
|
|
GimpComboTagEntry *entry;
|
2008-12-20 22:46:54 +08:00
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type,
|
|
|
|
n_params,
|
|
|
|
params);
|
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
entry = GIMP_COMBO_TAG_ENTRY (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
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-11-16 04:34:16 +08:00
|
|
|
if (combo_entry->arrow_pixbuf)
|
|
|
|
{
|
|
|
|
g_object_unref (combo_entry->arrow_pixbuf);
|
|
|
|
combo_entry->arrow_pixbuf = NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gimp_combo_tag_entry_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
GimpComboTagEntry *entry = GIMP_COMBO_TAG_ENTRY (widget);
|
|
|
|
|
|
|
|
if (! entry->arrow_pixbuf)
|
|
|
|
{
|
2010-09-10 19:47:04 +08:00
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
|
|
|
GdkPixmap *pixmap;
|
|
|
|
cairo_t *cr;
|
2009-11-16 04:34:16 +08:00
|
|
|
|
2010-09-10 19:47:04 +08:00
|
|
|
pixmap = gdk_pixmap_new (gtk_widget_get_window (widget), 8, 8, -1);
|
|
|
|
|
|
|
|
cr = gdk_cairo_create (pixmap);
|
|
|
|
gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
|
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_destroy (cr);
|
2009-11-16 04:34:16 +08:00
|
|
|
|
|
|
|
gtk_paint_arrow (style, pixmap,
|
|
|
|
GTK_STATE_NORMAL,
|
|
|
|
GTK_SHADOW_NONE, NULL, widget, NULL,
|
|
|
|
GTK_ARROW_DOWN, TRUE,
|
|
|
|
0, 0, 8, 8);
|
|
|
|
|
|
|
|
entry->arrow_pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL,
|
|
|
|
0, 0, 0, 0, 8, 8);
|
|
|
|
|
|
|
|
g_object_unref (pixmap);
|
|
|
|
|
|
|
|
gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry),
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
entry->arrow_pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
|
|
|
|
}
|
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
static void
|
2008-12-31 08:01:24 +08:00
|
|
|
gimp_combo_tag_entry_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *previous_style)
|
2008-12-20 22:46:54 +08:00
|
|
|
{
|
2008-12-31 08:01:24 +08:00
|
|
|
GimpComboTagEntry *entry = GIMP_COMBO_TAG_ENTRY (widget);
|
2009-03-23 07:04:37 +08:00
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
2008-12-31 08:01:24 +08:00
|
|
|
GdkColor color;
|
|
|
|
PangoAttribute *attribute;
|
2008-12-20 22:46:54 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->style_set)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
|
|
|
|
|
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
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
if (style->font_desc)
|
|
|
|
{
|
|
|
|
attribute = pango_attr_font_desc_new (style->font_desc);
|
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
|
|
|
}
|
|
|
|
color = style->text[GTK_STATE_NORMAL];
|
|
|
|
attribute = pango_attr_foreground_new (color.red, color.green, color.blue);
|
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
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
color = style->text[GTK_STATE_SELECTED];
|
|
|
|
attribute = pango_attr_foreground_new (color.red, color.green, color.blue);
|
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
|
|
|
color = style->base[GTK_STATE_SELECTED];
|
|
|
|
attribute = pango_attr_background_new (color.red, color.green, color.blue);
|
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
|
|
|
|
2008-12-20 22:46:54 +08:00
|
|
|
color = style->text[GTK_STATE_INSENSITIVE];
|
|
|
|
attribute = pango_attr_foreground_new (color.red, color.green, color.blue);
|
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
|
|
|
color = style->base[GTK_STATE_INSENSITIVE];
|
|
|
|
attribute = pango_attr_background_new (color.red, color.green, color.blue);
|
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
|
|
|
|
2008-12-31 08:01:24 +08:00
|
|
|
entry->selected_item_color = style->base[GTK_STATE_SELECTED];
|
2009-11-16 04:34:16 +08:00
|
|
|
|
|
|
|
if (entry->arrow_pixbuf)
|
|
|
|
{
|
|
|
|
g_object_unref (entry->arrow_pixbuf);
|
|
|
|
entry->arrow_pixbuf = NULL;
|
|
|
|
}
|
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:
|
|
|
|
* @container: a filtered container to be used.
|
|
|
|
* @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 *
|
|
|
|
gimp_combo_tag_entry_new (GimpFilteredContainer *container,
|
|
|
|
GimpTagEntryMode mode)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_FILTERED_CONTAINER (container), NULL);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GimpFilteredContainer *container = GIMP_TAG_ENTRY (entry)->container;
|
|
|
|
gint tag_count;
|
2009-10-18 02:20:39 +08:00
|
|
|
|
2009-11-16 03:28:39 +08:00
|
|
|
tag_count = gimp_filtered_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);
|
|
|
|
gimp_tag_popup_show (GIMP_TAG_POPUP (entry->popup));
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
gimp_combo_tag_entry_popup_destroy (GtkObject *object,
|
|
|
|
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
|
|
|
|
gimp_combo_tag_entry_tag_count_changed (GimpFilteredContainer *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
|
|
|
}
|