2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-07-14 22:41:29 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimppaletteview.c
|
|
|
|
* Copyright (C) 2005 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2005-07-14 22:41:29 +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
|
2005-07-14 22:41:29 +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/>.
|
2005-07-14 22:41:29 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2005-08-04 08:09:33 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2005-07-15 02:37:33 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2007-12-16 19:15:36 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2005-07-15 02:37:33 +08:00
|
|
|
|
2005-07-14 22:41:29 +08:00
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimppalette.h"
|
|
|
|
#include "core/gimpmarshal.h"
|
|
|
|
|
2005-07-15 02:37:33 +08:00
|
|
|
#include "gimpdnd.h"
|
2005-07-14 22:41:29 +08:00
|
|
|
#include "gimppaletteview.h"
|
|
|
|
#include "gimpviewrendererpalette.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2005-07-15 02:37:33 +08:00
|
|
|
ENTRY_CLICKED,
|
2005-07-14 22:41:29 +08:00
|
|
|
ENTRY_SELECTED,
|
|
|
|
ENTRY_ACTIVATED,
|
|
|
|
ENTRY_CONTEXT,
|
2005-07-15 02:37:33 +08:00
|
|
|
COLOR_DROPPED,
|
2005-07-14 22:41:29 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean gimp_palette_view_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *eevent);
|
|
|
|
static gboolean gimp_palette_view_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
2005-08-04 08:09:33 +08:00
|
|
|
static gboolean gimp_palette_view_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent);
|
|
|
|
static gboolean gimp_palette_view_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction);
|
2005-07-14 22:41:29 +08:00
|
|
|
static void gimp_palette_view_set_viewable (GimpView *view,
|
|
|
|
GimpViewable *old_viewable,
|
|
|
|
GimpViewable *new_viewable);
|
2005-07-15 02:37:33 +08:00
|
|
|
static GimpPaletteEntry *
|
|
|
|
gimp_palette_view_find_entry (GimpPaletteView *view,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
2005-07-14 22:41:29 +08:00
|
|
|
static void gimp_palette_view_expose_entry (GimpPaletteView *view,
|
|
|
|
GimpPaletteEntry *entry);
|
|
|
|
static void gimp_palette_view_invalidate (GimpPalette *palette,
|
|
|
|
GimpPaletteView *view);
|
2005-07-15 02:37:33 +08:00
|
|
|
static void gimp_palette_view_drag_color (GtkWidget *widget,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_palette_view_drop_color (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpPaletteView, gimp_palette_view, GIMP_TYPE_VIEW)
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_palette_view_parent_class
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static guint view_signals[LAST_SIGNAL] = { 0 };
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_palette_view_class_init (GimpPaletteViewClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GimpViewClass *view_class = GIMP_VIEW_CLASS (klass);
|
|
|
|
|
2005-07-15 02:37:33 +08:00
|
|
|
view_signals[ENTRY_CLICKED] =
|
|
|
|
g_signal_new ("entry-clicked",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPaletteViewClass, entry_clicked),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__POINTER_ENUM,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_POINTER,
|
|
|
|
GDK_TYPE_MODIFIER_TYPE);
|
|
|
|
|
2005-07-14 22:41:29 +08:00
|
|
|
view_signals[ENTRY_SELECTED] =
|
|
|
|
g_signal_new ("entry-selected",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPaletteViewClass, entry_selected),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__POINTER,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
view_signals[ENTRY_ACTIVATED] =
|
|
|
|
g_signal_new ("entry-activated",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPaletteViewClass, entry_activated),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__POINTER,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
view_signals[ENTRY_CONTEXT] =
|
|
|
|
g_signal_new ("entry-context",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPaletteViewClass, entry_context),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__POINTER,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
2005-07-15 02:37:33 +08:00
|
|
|
view_signals[COLOR_DROPPED] =
|
|
|
|
g_signal_new ("color-dropped",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPaletteViewClass, color_dropped),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__POINTER_BOXED,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_POINTER,
|
|
|
|
GIMP_TYPE_RGB);
|
|
|
|
|
2005-07-14 22:41:29 +08:00
|
|
|
widget_class->expose_event = gimp_palette_view_expose;
|
|
|
|
widget_class->button_press_event = gimp_palette_view_button_press;
|
2005-08-04 08:09:33 +08:00
|
|
|
widget_class->key_press_event = gimp_palette_view_key_press;
|
|
|
|
widget_class->focus = gimp_palette_view_focus;
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
view_class->set_viewable = gimp_palette_view_set_viewable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_palette_view_init (GimpPaletteView *view)
|
|
|
|
{
|
2009-10-18 02:20:39 +08:00
|
|
|
gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
view->selected = NULL;
|
|
|
|
view->dnd_entry = NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-14 17:19:09 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_palette_view_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *eevent)
|
2005-07-14 22:41:29 +08:00
|
|
|
{
|
2007-11-14 17:19:09 +08:00
|
|
|
GimpPaletteView *pal_view = GIMP_PALETTE_VIEW (widget);
|
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2009-10-18 02:20:39 +08:00
|
|
|
if (! gtk_widget_is_drawable (widget))
|
2007-11-14 17:19:09 +08:00
|
|
|
return FALSE;
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2007-11-14 17:19:09 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2007-11-14 17:19:09 +08:00
|
|
|
if (view->renderer->viewable && pal_view->selected)
|
|
|
|
{
|
|
|
|
GimpViewRendererPalette *renderer;
|
2008-06-28 23:50:27 +08:00
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
2010-01-15 22:33:08 +08:00
|
|
|
GtkAllocation allocation;
|
2007-11-14 17:19:09 +08:00
|
|
|
cairo_t *cr;
|
|
|
|
gint row, col;
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2007-11-14 17:19:09 +08:00
|
|
|
renderer = GIMP_VIEW_RENDERER_PALETTE (view->renderer);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2010-01-15 22:33:08 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2007-11-14 17:19:09 +08:00
|
|
|
row = pal_view->selected->position / renderer->columns;
|
|
|
|
col = pal_view->selected->position % renderer->columns;
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
cr = gdk_cairo_create (gtk_widget_get_window (widget));
|
2007-11-14 17:19:09 +08:00
|
|
|
gdk_cairo_region (cr, eevent->region);
|
|
|
|
cairo_clip (cr);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2010-10-15 21:06:43 +08:00
|
|
|
cairo_translate (cr, allocation.x, allocation.y);
|
|
|
|
|
2007-11-14 17:19:09 +08:00
|
|
|
cairo_rectangle (cr,
|
2010-10-15 21:06:43 +08:00
|
|
|
col * renderer->cell_width + 0.5,
|
|
|
|
row * renderer->cell_height + 0.5,
|
2007-11-14 17:19:09 +08:00
|
|
|
renderer->cell_width,
|
|
|
|
renderer->cell_height);
|
|
|
|
|
2007-12-16 19:15:36 +08:00
|
|
|
cairo_set_line_width (cr, 1.0);
|
2008-06-28 23:50:27 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_SELECTED]);
|
2007-11-14 17:19:09 +08:00
|
|
|
cairo_stroke_preserve (cr);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2007-12-16 19:15:36 +08:00
|
|
|
if (gimp_cairo_set_focus_line_pattern (cr, widget))
|
2007-11-14 17:19:09 +08:00
|
|
|
{
|
2008-06-28 23:50:27 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
|
2007-11-14 22:42:05 +08:00
|
|
|
cairo_stroke (cr);
|
2007-11-14 17:19:09 +08:00
|
|
|
}
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2007-11-14 17:19:09 +08:00
|
|
|
cairo_destroy (cr);
|
2005-07-14 22:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_palette_view_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
|
|
|
{
|
2005-07-15 02:37:33 +08:00
|
|
|
GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);
|
|
|
|
GimpPaletteEntry *entry;
|
2005-07-14 22:41:29 +08:00
|
|
|
|
2009-10-18 02:20:39 +08:00
|
|
|
if (gtk_widget_get_can_focus (widget) && ! gtk_widget_has_focus (widget))
|
2005-08-04 08:09:33 +08:00
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
|
2005-07-15 02:37:33 +08:00
|
|
|
entry = gimp_palette_view_find_entry (view, bevent->x, bevent->y);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
view->dnd_entry = entry;
|
|
|
|
|
|
|
|
if (! entry || bevent->button == 2)
|
|
|
|
return FALSE;
|
|
|
|
|
2005-07-15 02:37:33 +08:00
|
|
|
if (bevent->type == GDK_BUTTON_PRESS)
|
|
|
|
g_signal_emit (view, view_signals[ENTRY_CLICKED], 0,
|
|
|
|
entry, bevent->state);
|
|
|
|
|
2005-07-14 22:41:29 +08:00
|
|
|
switch (bevent->button)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
if (bevent->type == GDK_BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
gimp_palette_view_select_entry (view, entry);
|
|
|
|
}
|
|
|
|
else if (bevent->type == GDK_2BUTTON_PRESS && entry == view->selected)
|
|
|
|
{
|
|
|
|
g_signal_emit (view, view_signals[ENTRY_ACTIVATED], 0, entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if (bevent->type == GDK_BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
if (entry != view->selected)
|
|
|
|
gimp_palette_view_select_entry (view, entry);
|
|
|
|
|
|
|
|
g_signal_emit (view, view_signals[ENTRY_CONTEXT], 0, entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-08-04 08:09:33 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_palette_view_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent)
|
|
|
|
{
|
|
|
|
GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);
|
|
|
|
|
|
|
|
if (view->selected &&
|
2008-02-17 01:51:02 +08:00
|
|
|
(kevent->keyval == GDK_space ||
|
|
|
|
kevent->keyval == GDK_KP_Space ||
|
|
|
|
kevent->keyval == GDK_Return ||
|
|
|
|
kevent->keyval == GDK_KP_Enter ||
|
|
|
|
kevent->keyval == GDK_ISO_Enter))
|
2005-08-04 08:09:33 +08:00
|
|
|
{
|
|
|
|
g_signal_emit (view, view_signals[ENTRY_CLICKED], 0,
|
|
|
|
view->selected, kevent->state);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_palette_view_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);
|
2005-08-17 09:25:20 +08:00
|
|
|
GimpPalette *palette;
|
|
|
|
|
|
|
|
palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);
|
2005-08-04 08:09:33 +08:00
|
|
|
|
2009-10-18 02:20:39 +08:00
|
|
|
if (gtk_widget_get_can_focus (widget) && ! gtk_widget_has_focus (widget))
|
2005-08-04 08:09:33 +08:00
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (widget);
|
2005-08-17 09:25:20 +08:00
|
|
|
|
2010-10-27 20:36:44 +08:00
|
|
|
if (! view->selected && gimp_palette_get_n_colors (palette) > 0)
|
|
|
|
{
|
|
|
|
GimpPaletteEntry *entry = gimp_palette_get_entry (palette, 0);
|
|
|
|
|
|
|
|
gimp_palette_view_select_entry (view, entry);
|
|
|
|
}
|
2005-08-17 09:25:20 +08:00
|
|
|
|
2005-08-04 08:09:33 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->selected)
|
|
|
|
{
|
|
|
|
GimpViewRendererPalette *renderer;
|
|
|
|
gint skip = 0;
|
|
|
|
|
|
|
|
renderer = GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (view)->renderer);
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case GTK_DIR_UP:
|
|
|
|
skip = -renderer->columns;
|
|
|
|
break;
|
|
|
|
case GTK_DIR_DOWN:
|
|
|
|
skip = renderer->columns;
|
|
|
|
break;
|
|
|
|
case GTK_DIR_LEFT:
|
|
|
|
skip = -1;
|
|
|
|
break;
|
|
|
|
case GTK_DIR_RIGHT:
|
|
|
|
skip = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DIR_TAB_FORWARD:
|
|
|
|
case GTK_DIR_TAB_BACKWARD:
|
2005-08-17 08:39:44 +08:00
|
|
|
return FALSE;
|
2005-08-04 08:09:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (skip != 0)
|
|
|
|
{
|
|
|
|
GimpPaletteEntry *entry;
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
position = view->selected->position + skip;
|
|
|
|
|
2010-10-27 20:36:44 +08:00
|
|
|
entry = gimp_palette_get_entry (palette, position);
|
2005-08-04 08:09:33 +08:00
|
|
|
|
|
|
|
if (entry)
|
|
|
|
gimp_palette_view_select_entry (view, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-07-14 22:41:29 +08:00
|
|
|
static void
|
|
|
|
gimp_palette_view_set_viewable (GimpView *view,
|
|
|
|
GimpViewable *old_viewable,
|
|
|
|
GimpViewable *new_viewable)
|
|
|
|
{
|
|
|
|
GimpPaletteView *pal_view = GIMP_PALETTE_VIEW (view);
|
|
|
|
|
|
|
|
pal_view->dnd_entry = NULL;
|
2005-07-15 02:37:33 +08:00
|
|
|
gimp_palette_view_select_entry (pal_view, NULL);
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
if (old_viewable)
|
2005-07-22 06:36:14 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (old_viewable,
|
|
|
|
gimp_palette_view_invalidate,
|
|
|
|
view);
|
|
|
|
|
|
|
|
if (! new_viewable)
|
|
|
|
{
|
|
|
|
gimp_dnd_color_source_remove (GTK_WIDGET (view));
|
|
|
|
gimp_dnd_color_dest_remove (GTK_WIDGET (view));
|
|
|
|
}
|
|
|
|
}
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
GIMP_VIEW_CLASS (parent_class)->set_viewable (view,
|
|
|
|
old_viewable, new_viewable);
|
|
|
|
|
|
|
|
if (new_viewable)
|
2005-07-22 06:36:14 +08:00
|
|
|
{
|
|
|
|
g_signal_connect (new_viewable, "invalidate-preview",
|
|
|
|
G_CALLBACK (gimp_palette_view_invalidate),
|
|
|
|
view);
|
|
|
|
|
|
|
|
/* unset the palette drag handler set by GimpView */
|
|
|
|
gimp_dnd_viewable_source_remove (GTK_WIDGET (view), GIMP_TYPE_PALETTE);
|
|
|
|
|
|
|
|
if (! old_viewable)
|
|
|
|
{
|
|
|
|
gimp_dnd_color_source_add (GTK_WIDGET (view),
|
|
|
|
gimp_palette_view_drag_color,
|
|
|
|
view);
|
|
|
|
gimp_dnd_color_dest_add (GTK_WIDGET (view),
|
|
|
|
gimp_palette_view_drop_color,
|
|
|
|
view);
|
|
|
|
}
|
|
|
|
}
|
2005-07-14 22:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_palette_view_select_entry (GimpPaletteView *view,
|
|
|
|
GimpPaletteEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PALETTE_VIEW (view));
|
|
|
|
|
|
|
|
if (entry == view->selected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (view->selected)
|
|
|
|
gimp_palette_view_expose_entry (view, view->selected);
|
|
|
|
|
|
|
|
view->selected = entry;
|
|
|
|
|
|
|
|
if (view->selected)
|
|
|
|
gimp_palette_view_expose_entry (view, view->selected);
|
|
|
|
|
|
|
|
g_signal_emit (view, view_signals[ENTRY_SELECTED], 0, view->selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private funcions */
|
|
|
|
|
2005-07-15 02:37:33 +08:00
|
|
|
static GimpPaletteEntry *
|
|
|
|
gimp_palette_view_find_entry (GimpPaletteView *view,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
GimpViewRendererPalette *renderer;
|
|
|
|
GimpPaletteEntry *entry = NULL;
|
|
|
|
gint col, row;
|
|
|
|
|
|
|
|
renderer = GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (view)->renderer);
|
|
|
|
|
|
|
|
col = x / renderer->cell_width;
|
|
|
|
row = y / renderer->cell_height;
|
|
|
|
|
|
|
|
if (col >= 0 && col < renderer->columns &&
|
|
|
|
row >= 0 && row < renderer->rows)
|
|
|
|
{
|
|
|
|
GimpPalette *palette;
|
|
|
|
|
|
|
|
palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);
|
|
|
|
|
2010-10-27 20:36:44 +08:00
|
|
|
entry = gimp_palette_get_entry (palette,
|
|
|
|
row * renderer->columns + col);
|
2005-07-15 02:37:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2005-07-14 22:41:29 +08:00
|
|
|
static void
|
|
|
|
gimp_palette_view_expose_entry (GimpPaletteView *view,
|
|
|
|
GimpPaletteEntry *entry)
|
|
|
|
{
|
|
|
|
GimpViewRendererPalette *renderer;
|
|
|
|
gint row, col;
|
2005-07-15 02:37:33 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (view);
|
2010-01-15 22:33:08 +08:00
|
|
|
GtkAllocation allocation;
|
2005-07-14 22:41:29 +08:00
|
|
|
|
|
|
|
renderer = GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (view)->renderer);
|
|
|
|
|
2010-01-15 22:33:08 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2005-07-14 22:41:29 +08:00
|
|
|
row = entry->position / renderer->columns;
|
|
|
|
col = entry->position % renderer->columns;
|
|
|
|
|
|
|
|
gtk_widget_queue_draw_area (GTK_WIDGET (view),
|
2010-01-15 22:33:08 +08:00
|
|
|
allocation.x + col * renderer->cell_width,
|
|
|
|
allocation.y + row * renderer->cell_height,
|
2005-07-14 22:41:29 +08:00
|
|
|
renderer->cell_width + 1,
|
|
|
|
renderer->cell_height + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_palette_view_invalidate (GimpPalette *palette,
|
|
|
|
GimpPaletteView *view)
|
|
|
|
{
|
|
|
|
view->dnd_entry = NULL;
|
|
|
|
|
2010-10-27 20:36:44 +08:00
|
|
|
if (view->selected &&
|
|
|
|
! g_list_find (gimp_palette_get_colors (palette), view->selected))
|
|
|
|
{
|
|
|
|
gimp_palette_view_select_entry (view, NULL);
|
|
|
|
}
|
2005-07-15 02:37:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_palette_view_drag_color (GtkWidget *widget,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpPaletteView *view = GIMP_PALETTE_VIEW (data);
|
|
|
|
|
|
|
|
if (view->dnd_entry)
|
|
|
|
*color = view->dnd_entry->color;
|
|
|
|
else
|
|
|
|
gimp_rgba_set (color, 0.0, 0.0, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_palette_view_drop_color (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpPaletteView *view = GIMP_PALETTE_VIEW (data);
|
|
|
|
GimpPaletteEntry *entry;
|
|
|
|
|
|
|
|
entry = gimp_palette_view_find_entry (view, x, y);
|
|
|
|
|
|
|
|
g_signal_emit (view, view_signals[COLOR_DROPPED], 0,
|
|
|
|
entry, color);
|
2005-07-14 22:41:29 +08:00
|
|
|
}
|