Re: Redoing colormap editor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sven Neumann wrote:
> I am not sure if merging colormaps and palettes is going to help to
> avoid the confusion that already exists between the two. And as far as I
> can see the Colormap editor has a very different use case than the
> Palette editor. So it seems to need a different user interface as well.
I really don't think the use case is that different even if I don't use
it something near to often. At least it would be easier to manage.

Anyway, to get some feedback a (big) patch is attached that reimplements
the colormap editor using a GimpViewPalette:

- It's not really cleaned up yet, but I'll do that as soon as possible,

- mostly a rewrite based on the implementation in gimppaletteeditor.c

- zooming like in the palette editor is not implemented (mainly because
  I think it should be common to both (and also other?) editors and I
	didn't have time for it yet; also it looks not that bad now),

- saving and loading of colormaps should be easy to add (but then, how
  should that be done? either truncating the palette if it's to big or
	simply resize the colormap? I'm not quite sure how it's supposed to
	behave),

- ...

So, I hope you can comment on it :)

Regards,
Olof

-- 
Please note that according to German law on data retention, information
on every electronic information exchange with me is retained for a period
of six months.
Index: app/actions/colormap-commands.c
===================================================================
--- app/actions/colormap-commands.c	(revision 25173)
+++ app/actions/colormap-commands.c	(working copy)
@@ -114,12 +114,17 @@
                                  gint       value,
                                  gpointer   data)
 {
-  GimpContext *context;
-  GimpImage   *image;
+  GimpColormapEditor *editor;
+  GimpContext        *context;
+  GimpImage          *image;
+  gint                size;
   return_if_no_context (context, data);
   return_if_no_image (image, data);
+  editor = GIMP_COLORMAP_EDITOR (data);
 
-  if (gimp_image_get_colormap_size (image) < 256)
+  size = gimp_image_get_colormap_size (image);
+
+  if (size < 256)
     {
       GimpRGB color;
 
@@ -129,6 +134,7 @@
         gimp_context_get_foreground (context, &color);
 
       gimp_image_add_colormap_entry (image, &color);
+      gimp_colormap_editor_set_index (editor, size, NULL);
       gimp_image_flush (image);
     }
 }
Index: app/widgets/gimpcolormapeditor.c
===================================================================
--- app/widgets/gimpcolormapeditor.c	(revision 25173)
+++ app/widgets/gimpcolormapeditor.c	(working copy)
@@ -1,35 +1,12 @@
-/* GIMP - The GNU Image Manipulation Program
- * Copyright (C) 1995 Spencer Kimball and Peter Mattis
- *
- * 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 2 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
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
 #include "config.h"
 
 #include <string.h>
 
-#ifdef __GNUC__
-#warning GTK_DISABLE_DEPRECATED
-#endif
-#undef GTK_DISABLE_DEPRECATED
-
 #include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
 
+#include "libgimpbase/gimpbase.h"
+#include "libgimpmath/gimpmath.h"
 #include "libgimpcolor/gimpcolor.h"
-#include "libgimpmath/gimpmath.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
 #include "widgets-types.h"
@@ -37,27 +14,25 @@
 #include "core/gimp.h"
 #include "core/gimpcontainer.h"
 #include "core/gimpcontext.h"
+#include "core/gimpdatafactory.h"
+#include "core/gimppalette.h"
+#include "core/gimpmarshal.h"
+#include "core/gimpimage-colormap.h"
 #include "core/gimpimage.h"
-#include "core/gimpimage-colormap.h"
-#include "core/gimpmarshal.h"
 
+#include "gimpdnd.h"
+#include "gimpdocked.h"
+#include "gimphelp-ids.h"
 #include "gimpcolormapeditor.h"
-#include "gimpdnd.h"
+#include "gimpsessioninfo-aux.h"
+#include "gimpuimanager.h"
+#include "gimpviewrendererpalette.h"
+#include "gimpwidgets-utils.h"
+#include "gimppaletteview.h"
 #include "gimpmenufactory.h"
-#include "gimpuimanager.h"
 
 #include "gimp-intl.h"
 

/*  Add these features:
 *
 *  load/save colormaps
 *  requantize
 *  add color--by clicking in the checked region
 *  all changes need to flush colormap lookup cache
 */


 enum
 {
   SELECTED,
@@ -71,73 +46,121 @@
          gimp_image_base_type (image) == GIMP_INDEXED && \
          gimp_image_get_colormap (image) != NULL)
 
+#define ENTRY_WIDTH  12
+#define ENTRY_HEIGHT 10
+#define SPACING       1
+#define COLUMNS      16
+#define ROWS         11
 
-static GObject * gimp_colormap_editor_constructor  (GType               type,
-                                                    guint               n_params,
-                                                    GObjectConstructParam *params);
+#define PREVIEW_WIDTH  ((ENTRY_WIDTH  + SPACING) * COLUMNS + 1)
+#define PREVIEW_HEIGHT ((ENTRY_HEIGHT + SPACING) * ROWS    + 1)
 
-static void   gimp_colormap_editor_finalize        (GObject            *object);
-static void   gimp_colormap_editor_destroy         (GtkObject          *object);
-static void   gimp_colormap_editor_unmap           (GtkWidget          *widget);
+/*  local function prototypes  */
 
-static void   gimp_colormap_editor_set_image       (GimpImageEditor    *editor,
-                                                    GimpImage          *image);
+static void   gimp_colormap_editor_docked_iface_init (GimpDockedInterface *iface);
 
+static GObject * gimp_colormap_editor_constructor (GType                  type,
+                                                   guint                  n_params,
+                                                   GObjectConstructParam *params);
+
+static void  gimp_colormap_editor_finalize    (GObject            *object);
+static void  gimp_colormap_editor_destroy     (GtkObject          *object);
+static void  gimp_colormap_editor_unmap       (GtkWidget          *widget);
+static void  gimp_colormap_editor_set_image   (GimpImageEditor    *editor,
+                                               GimpImage          *image);
+
+static void  gimp_colormap_editor_set_context (GimpDocked        *docked,
+                                               GimpContext       *context);
+
 static PangoLayout *
-              gimp_colormap_editor_create_layout   (GtkWidget          *widget);
+             gimp_colormap_editor_create_layout           (GtkWidget          *widget);
 
-static void   gimp_colormap_editor_draw            (GimpColormapEditor *editor);
-static void   gimp_colormap_editor_draw_cell       (GimpColormapEditor *editor,
-                                                    gint                col);
-static void   gimp_colormap_editor_clear           (GimpColormapEditor *editor,
-                                                    gint                start_row);
-static void   gimp_colormap_editor_update_entries  (GimpColormapEditor *editor);
+static GimpPalette *
+             gimp_colormap_editor_create_palette_from_colormap (GimpColormapEditor *editor);
 
-static void   gimp_colormap_preview_size_allocate  (GtkWidget          *widget,
-                                                    GtkAllocation      *allocation,
-                                                    GimpColormapEditor *editor);
-static void   gimp_colormap_preview_expose         (GtkWidget          *widget,
-                                                    GdkEventExpose     *event,
-                                                    GimpColormapEditor *editor);
+static void  gimp_colormap_editor_update_entries          (GimpColormapEditor *editor);
+static void  gimp_colormap_editor_image_colormap_changed  (GimpImage          *image,
+                                                           gint                ncol,
+                                                           GimpColormapEditor *editor);
+static PangoLayout *
+             gimp_colormap_editor_create_layout           (GtkWidget *widget);
+
 static gboolean
-              gimp_colormap_preview_button_press   (GtkWidget          *widget,
-                                                    GdkEventButton     *bevent,
-                                                    GimpColormapEditor *editor);
-static void   gimp_colormap_preview_drag_color     (GtkWidget          *widget,
-                                                    GimpRGB            *color,
-                                                    gpointer            data);
-static void   gimp_colormap_preview_drop_color     (GtkWidget          *widget,
-                                                    gint                x,
-                                                    gint                y,
-                                                    const GimpRGB      *color,
-                                                    gpointer            data);
+             gimp_colormap_editor_draw_hint               (GtkWidget          *widget,
+                                                           GdkEventExpose     *event,
+                                                           GimpColormapEditor *editor);
 
-static void   gimp_colormap_adjustment_changed     (GtkAdjustment      *adjustment,
-                                                    GimpColormapEditor *editor);
-static void   gimp_colormap_hex_entry_changed      (GimpColorHexEntry  *entry,
-                                                    GimpColormapEditor *editor);
+static void  gimp_colormap_editor_set_hint                (GimpColormapEditor *editor,
+                                                           gboolean            draw_hint);
 
-static void   gimp_colormap_image_mode_changed     (GimpImage          *image,
-                                                    GimpColormapEditor *editor);
-static void   gimp_colormap_image_colormap_changed (GimpImage          *image,
-                                                    gint                ncol,
-                                                    GimpColormapEditor *editor);
+static void  gimp_colormap_editor_index_changed           (GtkAdjustment      *adjustment,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_columns_changed         (GtkAdjustment      *adj,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_image_mode_changed      (GimpImage          *image,
+                                                           GimpColormapEditor *editor);
 
+static void  gimp_colormap_editor_entry_clicked           (GimpPaletteView    *view,
+                                                           GimpPaletteEntry   *entry,
+                                                           GdkModifierType     state,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_entry_selected          (GimpPaletteView    *view,
+                                                           GimpPaletteEntry   *entry,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_entry_activated         (GimpPaletteView    *view,
+                                                           GimpPaletteEntry   *entry,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_entry_context           (GimpPaletteView    *view,
+                                                           GimpPaletteEntry   *entry,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_color_dropped           (GimpPaletteView    *view,
+                                                           GimpPaletteEntry   *entry,
+                                                           const GimpRGB      *color,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_palette_dropped         (GimpPaletteView    *view,
+                                                           gint                x,
+                                                           gint                y,
+                                                           GimpViewable       *viewable,
+                                                           GimpColormapEditor *editor);
+static gboolean
+             gimp_colormap_editor_eventbox_button_press   (GtkWidget          *widget,
+                                                           GdkEventButton     *bevent,
+                                                           GimpPaletteEditor  *editor);
 
-G_DEFINE_TYPE (GimpColormapEditor, gimp_colormap_editor,
-               GIMP_TYPE_IMAGE_EDITOR)
+static void  gimp_colormap_editor_eventbox_drop_color     (GtkWidget          *widget,
+                                                           gint                x,
+                                                           gint                y,
+                                                           const GimpRGB      *color,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_eventbox_drop_palette   (GtkWidget          *widget,
+                                                           gint                x,
+                                                           gint                y,
+                                                           GimpViewable       *viewable,
+                                                           GimpColormapEditor *editor);
+static void  gimp_colormap_editor_scroll_top_left         (GimpColormapEditor *editor);
+static void  gimp_colormap_editor_viewport_size_allocate  (GtkWidget          *widget,
+                                                           GtkAllocation      *allocation,
+                                                           GimpColormapEditor *editor);
 
+G_DEFINE_TYPE_WITH_CODE (GimpColormapEditor, gimp_colormap_editor,
+                         GIMP_TYPE_IMAGE_EDITOR,
+                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
+                                                gimp_colormap_editor_docked_iface_init))
+
 #define parent_class gimp_colormap_editor_parent_class
 
+static GimpDockedInterface *parent_docked_iface = NULL;
+
 static guint editor_signals[LAST_SIGNAL] = { 0 };
 
 
 static void
-gimp_colormap_editor_class_init (GimpColormapEditorClass* klass)
+gimp_colormap_editor_class_init (GimpColormapEditorClass *klass)
 {
   GObjectClass         *object_class       = G_OBJECT_CLASS (klass);
   GtkObjectClass       *gtk_object_class   = GTK_OBJECT_CLASS (klass);
   GtkWidgetClass       *widget_class       = GTK_WIDGET_CLASS (klass);
+  GimpEditorClass      *editor_class       = GIMP_EDITOR_CLASS (klass);
   GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
 
   editor_signals[SELECTED] =
@@ -150,12 +173,12 @@
                   G_TYPE_NONE, 1,
                   GDK_TYPE_MODIFIER_TYPE);
 
-  object_class->constructor     = gimp_colormap_editor_constructor;
+  object_class->constructor = gimp_colormap_editor_constructor;
   object_class->finalize        = gimp_colormap_editor_finalize;
 
-  gtk_object_class->destroy     = gimp_colormap_editor_destroy;
+  gtk_object_class->destroy = gimp_colormap_editor_destroy;
 
-  widget_class->unmap           = gimp_colormap_editor_unmap;
+  widget_class->unmap       = gimp_colormap_editor_unmap;
 
   image_editor_class->set_image = gimp_colormap_editor_set_image;
 
@@ -163,81 +186,125 @@
 }
 
 static void
+gimp_colormap_editor_docked_iface_init (GimpDockedInterface *iface)
+{
+  parent_docked_iface = g_type_interface_peek_parent (iface);
+
+  if (!parent_docked_iface)
+    parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
+
+  iface->set_context  = gimp_colormap_editor_set_context;
+  //iface->set_aux_info = NULL;
+  //iface->get_aux_info = NULL;
+}
+
+static void
 gimp_colormap_editor_init (GimpColormapEditor *editor)
 {
-  GtkWidget      *frame;
-  GtkWidget      *table;
-  GtkObject      *adj;
-  gint            width;
-  gint            height;
+  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
+  GtkWidget       *alignment;
+  GtkWidget       *hbox;
+  GtkWidget       *label;
+  GtkObject       *adj;
 
+  gimp_editor_set_name (GIMP_EDITOR (editor), _("Colormap Editor"));
+
   editor->col_index     = 0;
-  editor->dnd_col_index = 0;
-  editor->xn            = 0;
-  editor->yn            = 0;
-  editor->cellsize      = 0;
+  editor->color_dialog  = NULL;
+  editor->palette       = NULL;
 
-  /*  The palette frame  */
-  frame = gtk_frame_new (NULL);
-  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-  gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
-  gtk_widget_show (frame);
 
-  editor->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
-  gtk_preview_set_expand (GTK_PREVIEW (editor->preview), TRUE);
-  gtk_widget_add_events (editor->preview, GDK_BUTTON_PRESS_MASK);
-  gtk_container_add (GTK_CONTAINER (frame), editor->preview);
-  gtk_widget_show (editor->preview);
+  editor->scrolled = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_set_size_request (editor->scrolled, -1, PREVIEW_HEIGHT);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (editor->scrolled),
+                                  GTK_POLICY_AUTOMATIC,
+                                  GTK_POLICY_AUTOMATIC);
+  gtk_box_pack_start (GTK_BOX (editor), editor->scrolled, TRUE, TRUE, 0);
+  gtk_widget_show (editor->scrolled);
 
-  editor->layout = gimp_colormap_editor_create_layout (editor->preview);
+  editor->layout = gimp_colormap_editor_create_layout (editor->scrolled);
 
-  pango_layout_set_width (editor->layout, 180 * PANGO_SCALE);
-  pango_layout_get_pixel_size (editor->layout, &width, &height);
-  gtk_widget_set_size_request (editor->preview, width, height);
+  editor->eventbox = gtk_event_box_new ();
+  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (editor->scrolled),
+                                         editor->eventbox);
+  g_signal_connect (editor->eventbox->parent, "size-allocate",
+                    G_CALLBACK (gimp_colormap_editor_viewport_size_allocate),
+                    editor);
+  gtk_widget_show (editor->eventbox);
 
-  g_signal_connect_after (editor->preview, "size-allocate",
-                          G_CALLBACK (gimp_colormap_preview_size_allocate),
-                          editor);
+  g_signal_connect (editor->eventbox, "button-press-event",
+                    G_CALLBACK (gimp_colormap_editor_eventbox_button_press),
+                    editor);
 
-  g_signal_connect_after (editor->preview, "expose-event",
-                          G_CALLBACK (gimp_colormap_preview_expose),
-                          editor);
+  gimp_dnd_color_dest_add (editor->eventbox, gimp_colormap_editor_eventbox_drop_color, editor);
+  gimp_dnd_viewable_dest_add (editor->eventbox, GIMP_TYPE_PALETTE,
+                              gimp_colormap_editor_eventbox_drop_palette,
+                              editor);
 
-  g_signal_connect (editor->preview, "button-press-event",
-                    G_CALLBACK (gimp_colormap_preview_button_press),
+  alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+  gtk_container_add (GTK_CONTAINER (editor->eventbox), alignment);
+  gtk_widget_show (alignment);
+
+  editor->view = gimp_view_new_full_by_types (NULL,
+                                              GIMP_TYPE_PALETTE_VIEW,
+                                              GIMP_TYPE_PALETTE,
+                                              PREVIEW_WIDTH, PREVIEW_HEIGHT, 0,
+                                              FALSE, TRUE, FALSE);
+  gimp_view_renderer_palette_set_cell_size
+    (GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (editor->view)->renderer), -1);
+  gimp_view_renderer_palette_set_draw_grid
+    (GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (editor->view)->renderer), TRUE);
+  gtk_container_add (GTK_CONTAINER (alignment), editor->view);
+  //gtk_widget_show (editor->view);
+
+  g_signal_connect (editor->view, "entry-clicked",
+                    G_CALLBACK (gimp_colormap_editor_entry_clicked),
                     editor);
+  g_signal_connect (editor->view, "entry-selected",
+                    G_CALLBACK (gimp_colormap_editor_entry_selected),
+                    editor);
+  g_signal_connect (editor->view, "entry-activated",
+                    G_CALLBACK (gimp_colormap_editor_entry_activated),
+                    editor);
+  g_signal_connect (editor->view, "entry-context",
+                    G_CALLBACK (gimp_colormap_editor_entry_context),
+                    editor);
+  g_signal_connect (editor->view, "color-dropped",
+                    G_CALLBACK (gimp_colormap_editor_color_dropped),
+                    editor);
 
-  gimp_dnd_color_source_add (editor->preview, gimp_colormap_preview_drag_color,
-                             editor);
-  gimp_dnd_color_dest_add (editor->preview, gimp_colormap_preview_drop_color,
-                           editor);
+  gimp_dnd_viewable_dest_add (editor->view, GIMP_TYPE_PALETTE,
+                              gimp_colormap_editor_palette_dropped,
+                              editor);
 
-  /*  Some helpful hints  */
-  table = gtk_table_new (2, 2, FALSE);
-  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
-  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
-  gtk_box_pack_end (GTK_BOX (editor), table, FALSE, FALSE, 0);
-  gtk_widget_show (table);
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_box_pack_start (GTK_BOX (editor), hbox, FALSE, FALSE, 0);
+  gtk_widget_show (hbox);
 
-  editor->index_spinbutton = gimp_spin_button_new (&adj,
-                                                   0, 0, 0, 1, 10, 10, 1.0, 0);
+  label = gtk_label_new (_("Index:"));
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+  gtk_widget_show (label);
+
+  editor->index_spinbutton = gimp_spin_button_new (&adj, 0, 0, 64, 1, 4, 4, 1, 0);
   editor->index_adjustment = GTK_ADJUSTMENT (adj);
-  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
-                             _("Color index:"), 0.0, 0.5,
-                             editor->index_spinbutton, 1, TRUE);
+  gtk_box_pack_start (GTK_BOX (hbox), editor->index_spinbutton, FALSE, FALSE, 0);
+  gtk_widget_show (editor->index_spinbutton);
 
   g_signal_connect (editor->index_adjustment, "value-changed",
-                    G_CALLBACK (gimp_colormap_adjustment_changed),
+                    G_CALLBACK (gimp_colormap_editor_index_changed),
                     editor);
 
-  editor->color_entry = gimp_color_hex_entry_new ();
-  gtk_entry_set_width_chars (GTK_ENTRY (editor->color_entry), 12);
-  gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
-                             _("HTML notation:"), 0.0, 0.5,
-                             editor->color_entry, 1, TRUE);
+  label = gtk_label_new (_("Columns:"));
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+  gtk_widget_show (label);
 
-  g_signal_connect (editor->color_entry, "color-changed",
-                    G_CALLBACK (gimp_colormap_hex_entry_changed),
+  editor->columns_spinbutton = gimp_spin_button_new (&adj, 0, 0, 64, 1, 4, 4, 1, 0);
+  editor->columns_adjustment = GTK_ADJUSTMENT (adj);
+  gtk_box_pack_start (GTK_BOX (hbox), editor->columns_spinbutton, FALSE, FALSE, 0);
+  gtk_widget_show (editor->columns_spinbutton);
+
+  g_signal_connect (editor->columns_adjustment, "value-changed",
+                    G_CALLBACK (gimp_colormap_editor_columns_changed),
                     editor);
 }
 
@@ -246,24 +313,21 @@
                                   guint                  n_params,
                                   GObjectConstructParam *params)
 {
-  GObject            *object;
+  GObject           *object;
   GimpColormapEditor *editor;
 
   object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
   editor = GIMP_COLORMAP_EDITOR (object);
 
-  editor->edit_button =
-    gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
-                                   "colormap-edit-color",
-                                   NULL);
+  gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
+                                 "colormap-edit-color", NULL);
 
-  editor->add_button =
-    gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
-                                   "colormap-add-color-from-fg",
-                                   "colormap-add-color-from-bg",
-                                   GDK_CONTROL_MASK,
-                                   NULL);
+  gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
+                                 "colormap-add-color-from-fg",
+                                 "colormap-add-color-from-bg",
+                                 GDK_CONTROL_MASK,
+                                 NULL);
 
   return object;
 }
@@ -287,6 +351,12 @@
 {
   GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
 
+  if (editor->palette)
+    {
+      g_object_unref (editor->palette);
+      editor->palette = NULL;
+    }
+
   if (editor->color_dialog)
     {
       gtk_widget_destroy (editor->color_dialog);
@@ -308,62 +378,75 @@
 }
 
 static void
+gimp_colormap_editor_set_context (GimpDocked  *docked,
+                                  GimpContext *context)
+{
+  GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (docked);
+
+  parent_docked_iface->set_context (docked, context);
+
+  gimp_view_renderer_set_context (GIMP_VIEW (editor->view)->renderer,
+                                  context);
+}
+
+static void
 gimp_colormap_editor_set_image (GimpImageEditor *image_editor,
                                 GimpImage       *image)
 {
   GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (image_editor);
+  gint size;
 
   if (image_editor->image)
     {
       g_signal_handlers_disconnect_by_func (image_editor->image,
-                                            gimp_colormap_image_mode_changed,
+                                            gimp_colormap_editor_image_mode_changed,
                                             editor);
       g_signal_handlers_disconnect_by_func (image_editor->image,
-                                            gimp_colormap_image_colormap_changed,
+                                            gimp_colormap_editor_image_colormap_changed,
                                             editor);
 
       if (editor->color_dialog)
         gtk_widget_hide (editor->color_dialog);
-
-      if (! HAVE_COLORMAP (image))
-        {
-          editor->index_adjustment->upper = 0;
-          gtk_adjustment_changed (editor->index_adjustment);
-
-          if (GTK_WIDGET_MAPPED (GTK_WIDGET (editor)))
-            gimp_colormap_editor_clear (editor, -1);
-        }
     }
 
   GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
 
-  editor->col_index     = 0;
-  editor->dnd_col_index = 0;
-
   if (image)
     {
+      gtk_widget_show (editor->view);
       g_signal_connect (image, "mode-changed",
-                        G_CALLBACK (gimp_colormap_image_mode_changed),
+                        G_CALLBACK (gimp_colormap_editor_image_mode_changed),
                         editor);
       g_signal_connect (image, "colormap-changed",
-                        G_CALLBACK (gimp_colormap_image_colormap_changed),
+                        G_CALLBACK (gimp_colormap_editor_image_colormap_changed),
                         editor);
 
       if (HAVE_COLORMAP (image))
         {
-          gimp_colormap_editor_draw (editor);
+          size = gimp_image_get_colormap_size (image) - 1;
 
-          editor->index_adjustment->upper =
-            gimp_image_get_colormap_size (image) - 1;
+          editor->col_index     = CLAMP (editor->col_index, 0, size);
 
+          if (editor->palette)
+            g_object_unref (editor->palette);
+          editor->palette = gimp_colormap_editor_create_palette_from_colormap (editor);
+
+          GTK_ADJUSTMENT (editor->index_adjustment)->upper = size;
+
           gtk_adjustment_changed (editor->index_adjustment);
+          gimp_colormap_editor_set_hint (editor, FALSE);
+          gimp_colormap_editor_set_index (editor, editor->col_index, NULL);
+          gimp_colormap_editor_scroll_top_left (editor);
         }
+      else
+        gimp_colormap_editor_set_hint (editor, TRUE);
     }
+  else
+    gtk_widget_hide (editor->view);
 
   gimp_colormap_editor_update_entries (editor);
 }
 
-
 /*  public functions  */
 
 GtkWidget *
@@ -378,6 +461,45 @@
                        NULL);
 }
 
+gboolean
+gimp_colormap_editor_set_index (GimpColormapEditor *editor,
+                                gint                index,
+                                GimpRGB            *color)
+{
+  GimpImage   *image;
+  gint         size;
+
+  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), FALSE);
+
+  image = GIMP_IMAGE_EDITOR (editor)->image;
+
+  if (! HAVE_COLORMAP (image))
+    return FALSE;
+
+  size = gimp_image_get_colormap_size (image);
+
+  if (size < 1)
+    return FALSE;
+
+  index = CLAMP (index, 0, size - 1);
+
+  if (index != editor->col_index)
+    {
+      editor->col_index     = index;
+
+      gtk_adjustment_set_value (editor->index_adjustment, editor->col_index);
+      gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view),
+                                      g_list_nth_data (editor->palette->colors, index));
+      gimp_colormap_editor_update_entries (editor);
+    }
+
+  if (color)
+    gimp_image_get_colormap_entry (GIMP_IMAGE_EDITOR (editor)->image,
+                                   index, color);
+
+  return TRUE;
+}
+
 gint
 gimp_colormap_editor_get_index (GimpColormapEditor *editor,
                                 const GimpRGB      *search)
@@ -421,67 +543,110 @@
   return index;
 }
 
-gboolean
-gimp_colormap_editor_set_index (GimpColormapEditor *editor,
-                                gint                index,
-                                GimpRGB            *color)
+gint
+gimp_colormap_editor_max_index (GimpColormapEditor *editor)
 {
   GimpImage *image;
-  gint       size;
 
-  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), FALSE);
+  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), -1);
 
   image = GIMP_IMAGE_EDITOR (editor)->image;
 
   if (! HAVE_COLORMAP (image))
-    return FALSE;
+    return -1;
 
-  size = gimp_image_get_colormap_size (image);
+  return MAX (0, gimp_image_get_colormap_size (image) - 1);
+}
 
-  if (size < 1)
-    return FALSE;
+static GimpPalette*
+gimp_colormap_editor_create_palette_from_colormap (GimpColormapEditor *editor)
+{
+  GimpPalette *result;
+  GimpRGB      tmp;
+  GimpImage   *image;
+  gint         i;
 
-  index = CLAMP (index, 0, size - 1);
+  result = (GimpPalette*) gimp_palette_new ("internal colormap");
+  image = GIMP_IMAGE_EDITOR (editor)->image;
 
-  if (index != editor->col_index)
+  for (i = 0; i < gimp_image_get_colormap_size (image); ++i)
     {
-      gint old = editor->col_index;
-
-      editor->col_index     = index;
-      editor->dnd_col_index = index;
-
-      gimp_colormap_editor_draw_cell (editor, old);
-      gimp_colormap_editor_draw_cell (editor, index);
-
-      gimp_colormap_editor_update_entries (editor);
+      gimp_image_get_colormap_entry (image, i, &tmp);
+      gimp_palette_add_entry (result, i, NULL, &tmp);
     }
 
-  if (color)
-    gimp_image_get_colormap_entry (GIMP_IMAGE_EDITOR (editor)->image,
-                                   index, color);
-
-  return TRUE;
+  return result;
 }
 
-gint
-gimp_colormap_editor_max_index (GimpColormapEditor *editor)
+static void
+gimp_colormap_editor_image_colormap_changed (GimpImage          *image,
+                                             gint                ncol,
+                                             GimpColormapEditor *editor)
 {
-  GimpImage *image;
+  GimpRGB           temp;
+  GimpPaletteEntry *entry;
 
-  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), -1);
+  if (HAVE_COLORMAP (image))
+    {
+      if (ncol < 0)
+        {
+          if (editor->palette)
+            g_object_unref (editor->palette);
+          editor->palette = gimp_colormap_editor_create_palette_from_colormap (editor);
+        }
+      else
+        {
+          gimp_image_get_colormap_entry (image, ncol, &temp);
+          entry = (GimpPaletteEntry *) (g_list_nth (editor->palette->colors, ncol)->data);
+          entry->color = temp;
+          gimp_data_dirty (GIMP_DATA (editor->palette));
+        }
 
-  image = GIMP_IMAGE_EDITOR (editor)->image;
+      if (editor->index_adjustment->upper !=
+          (gimp_image_get_colormap_size (image) - 1))
+        {
+          editor->index_adjustment->upper =
+            gimp_image_get_colormap_size (image) - 1;
 
-  if (! HAVE_COLORMAP (image))
-    return -1;
+          gtk_adjustment_changed (editor->index_adjustment);
+        }
 
-  return MAX (0, gimp_image_get_colormap_size (image) - 1);
+      gimp_colormap_editor_set_hint (editor, FALSE);
+    }
+  else
+    gimp_colormap_editor_set_hint (editor, TRUE);
+
+  if (ncol == editor->col_index || ncol == -1)
+    gimp_colormap_editor_update_entries (editor);
 }
 
+static void
+gimp_colormap_editor_update_entries (GimpColormapEditor *editor)
+{
+  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
 
-/*  private functions  */
+  if (! HAVE_COLORMAP (image) ||
+      ! gimp_image_get_colormap_size (image))
+    {
+      gtk_widget_set_sensitive (editor->index_spinbutton, FALSE);
+      gtk_adjustment_set_value (editor->index_adjustment, 0);
+      gtk_widget_set_sensitive (editor->columns_spinbutton, FALSE);
+      g_signal_handlers_disconnect_by_func (editor->eventbox,
+                                            gimp_colormap_editor_eventbox_button_press,
+                                            editor);
+    }
+  else
+    {
+      gtk_adjustment_set_value (editor->index_adjustment, editor->col_index);
+      gtk_widget_set_sensitive (editor->index_spinbutton, TRUE);
+      gtk_widget_set_sensitive (editor->columns_spinbutton, TRUE);
+      gimp_palette_set_columns (editor->palette, gtk_adjustment_get_value (editor->columns_adjustment));
+      g_signal_connect (editor->eventbox, "button-press-event",
+                        G_CALLBACK (gimp_colormap_editor_eventbox_button_press),
+                        editor);
+    }
+}
 
-
 static PangoLayout *
 gimp_colormap_editor_create_layout (GtkWidget *widget)
 {
@@ -490,8 +655,8 @@
   PangoAttribute *attr;
 
   layout = gtk_widget_create_pango_layout (widget,
-                                           _("Only indexed images have "
-                                             "a colormap."));
+                                           _("Only indexed images\n"
+                                             "have a colormap."));
   pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
 
   attrs = pango_attr_list_new ();
@@ -507,392 +672,227 @@
   return layout;
 }
 
-#define MIN_CELL_SIZE 4
-
 static void
-gimp_colormap_editor_draw (GimpColormapEditor *editor)
+gimp_colormap_editor_set_hint (GimpColormapEditor *editor,
+                               gboolean            draw_hint)
 {
-  GimpImage *image  = GIMP_IMAGE_EDITOR (editor)->image;
-  gint       i, j, k, b;
-  gint       col;
-  guchar    *row;
-  gint       cellsize, ncol, xn, yn;
-  gint       width  = editor->preview->allocation.width;
-  gint       height = editor->preview->allocation.height;
-
-  ncol = gimp_image_get_colormap_size (image);
-
-  if (! ncol)
+  if (draw_hint)
     {
-      gimp_colormap_editor_clear (editor, -1);
-      return;
+      gtk_widget_set_sensitive (editor->view, FALSE);
+      gimp_view_set_viewable (GIMP_VIEW (editor->view), NULL);
+      g_signal_connect (editor->view, "expose-event",
+        G_CALLBACK (gimp_colormap_editor_draw_hint),
+        editor);
     }
-
-  cellsize = sqrt (width * height / ncol);
-  while (cellsize >= MIN_CELL_SIZE
-         && (xn = width / cellsize) * (yn = height / cellsize) < ncol)
-    cellsize--;
-
-  if (cellsize < MIN_CELL_SIZE)
+  else
     {
-      cellsize = MIN_CELL_SIZE;
-      xn = yn = ceil (sqrt (ncol));
+      gtk_widget_set_sensitive (editor->view, TRUE);
+      gimp_view_set_viewable (GIMP_VIEW (editor->view), GIMP_VIEWABLE (editor->palette));
+      g_signal_handlers_disconnect_by_func (editor->view,
+        gimp_colormap_editor_draw_hint,
+        editor);
     }
+}
 
-  yn = ((ncol + xn - 1) / xn);
+static gboolean
+gimp_colormap_editor_draw_hint (GtkWidget          *widget,
+                                GdkEventExpose     *event,
+                                GimpColormapEditor *editor)
+{
+  gint x, y, w, h, lw, lh;
 
-  /* We used to render just multiples of "cellsize" here, but the
-   *  colormap as dockable looks better if it always fills the
-   *  available allocation->width (which should always be larger than
-   *  "xn * cellsize"). Defensively, we use MAX (width, xn * cellsize)
-   *  below   --Mitch
-   */
+  pango_layout_get_pixel_size (editor->layout, &lw, &lh);
+  gdk_drawable_get_size (GDK_DRAWABLE (widget->window), &w, &h);
 
-  editor->xn       = xn;
-  editor->yn       = yn;
-  editor->cellsize = cellsize;
+  x = (w - lw) / 2;
+  y = (h - lh) / 2;
 
-  row = g_new (guchar, MAX (width, xn * cellsize) * 3);
-  col = 0;
-  for (i = 0; i < yn; i++)
-    {
-      for (j = 0; j < xn && col < ncol; j++, col++)
-        {
-          for (k = 0; k < cellsize; k++)
-            for (b = 0; b < 3; b++)
-              row[(j * cellsize + k) * 3 + b] = image->colormap[col * 3 + b];
-        }
+  gdk_draw_layout (widget->window,
+                   widget->style->fg_gc[widget->state],
+                   MAX (x, 0), MAX (y, 0),
+                   editor->layout);
 
-      if (j * cellsize > width)
-        memset (row + j * cellsize * 3, 255, 3 * (width - j * cellsize));
-
-      for (k = 0; k < cellsize; k++)
-        {
-          gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, 0,
-                                i * cellsize + k,
-                                width);
-        }
-    }
-
-  gimp_colormap_editor_clear (editor, yn * cellsize);
-
-  gimp_colormap_editor_draw_cell (editor, editor->col_index);
-
-  g_free (row);
-  gtk_widget_queue_draw (editor->preview);
+  return TRUE;
 }
 
 static void
-gimp_colormap_editor_draw_cell (GimpColormapEditor *editor,
-                                gint                col)
+gimp_colormap_editor_index_changed (GtkAdjustment      *adjustment,
+                                    GimpColormapEditor *editor)
 {
-  GimpImage *image    = GIMP_IMAGE_EDITOR (editor)->image;
-  gint       cellsize = editor->cellsize;
-  guchar    *row      = g_alloca (cellsize * 3);
-  gint       x, y, k;
+  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
 
-  if (! editor->xn)
-    return;
-
-  x = (col % editor->xn) * cellsize;
-  y = (col / editor->xn) * cellsize;
-
-  if (col == editor->col_index)
-    {
-      for (k = 0; k < cellsize; k++)
-        row[k*3] = row[k*3+1] = row[k*3+2] = (k & 1) * 255;
-
-      gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, x, y, cellsize);
-
-      if (!(cellsize & 1))
-        for (k = 0; k < cellsize; k++)
-          row[k*3] = row[k*3+1] = row[k*3+2] = ((x+y+1) & 1) * 255;
-
-      gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
-                            x, y+cellsize-1, cellsize);
-
-      row[0] = row[1] = row[2] = 255;
-      row[cellsize*3-3] = row[cellsize*3-2] = row[cellsize*3-1] = 255 * (cellsize & 1);
-
-      for (k = 1; k < cellsize - 1; k++)
-        {
-          row[k*3]   = image->colormap[col * 3];
-          row[k*3+1] = image->colormap[col * 3 + 1];
-          row[k*3+2] = image->colormap[col * 3 + 2];
-        }
-      for (k = 1; k < cellsize - 1; k+=2)
-        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
-                              x, y+k, cellsize);
-
-      row[0] = row[1] = row[2] = 0;
-      row[cellsize*3-3] = row[cellsize*3-2] = row[cellsize*3-1]
-        = 255 * ((cellsize+1) & 1);
-      for (k = 2; k < cellsize - 1; k += 2)
-        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
-                              x, y+k, cellsize);
-    }
-  else
-    {
-      for (k = 0; k < cellsize; k++)
-        {
-          row[k*3]   = image->colormap[col * 3];
-          row[k*3+1] = image->colormap[col * 3 + 1];
-          row[k*3+2] = image->colormap[col * 3 + 2];
-        }
-
-      for (k = 0; k < cellsize; k++)
-        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
-                              x, y+k, cellsize);
-    }
-
-  gtk_widget_queue_draw_area (editor->preview,
-                              x, y,
-                              cellsize, cellsize);
+  if (HAVE_COLORMAP (image))
+    gimp_colormap_editor_set_index (editor, adjustment->value + 0.5, NULL);
 }
 
 static void
-gimp_colormap_preview_expose (GtkWidget          *widget,
-                              GdkEventExpose     *event,
-                              GimpColormapEditor *editor)
+gimp_colormap_editor_columns_changed (GtkAdjustment      *adj,
+                                      GimpColormapEditor *editor)
 {
-  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
-  gint             x, y;
-  gint             width, height;
-
-  if (image_editor->image == NULL ||
-      gimp_image_base_type (image_editor->image) == GIMP_INDEXED)
-    return;
-
-  pango_layout_get_pixel_size (editor->layout, &width, &height);
-
-  x = (widget->allocation.width - width) / 2;
-  y = (widget->allocation.height - height) / 2;
-
-  gdk_draw_layout (editor->preview->window,
-                   editor->preview->style->fg_gc[widget->state],
-                   MAX (x, 0), MAX (y, 0),
-                   editor->layout);
+  gimp_palette_set_columns (editor->palette, ROUND (adj->value));
 }
 
 static void
-gimp_colormap_editor_clear (GimpColormapEditor *editor,
-                            gint                start_row)
+gimp_colormap_editor_image_mode_changed (GimpImage          *image,
+                                         GimpColormapEditor *editor)
 {
-  guchar *row;
-  gint    width  = editor->preview->allocation.width;
-  gint    height = editor->preview->allocation.height;
-  gint    y;
+  if (editor->color_dialog)
+    gtk_widget_hide (editor->color_dialog);
 
-  if (start_row < 0)
-    start_row = 0;
-
-  if (start_row >= height)
-    return;
-
-  row = g_alloca (width * 3);
-
-  memset (row, 255, 3 * width);
-
-  for (y = start_row; y < height; y++)
-    gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, 0, y, width);
-
-  gtk_widget_queue_draw (editor->preview);
+  gimp_colormap_editor_image_colormap_changed (image, -1, editor);
 }
 
 static void
-gimp_colormap_editor_update_entries (GimpColormapEditor *editor)
+gimp_colormap_editor_entry_clicked (GimpPaletteView    *view,
+                                    GimpPaletteEntry   *entry,
+                                    GdkModifierType     state,
+                                    GimpColormapEditor *editor)
 {
-  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
-
-  if (! HAVE_COLORMAP (image) ||
-      ! gimp_image_get_colormap_size (image))
+  if (entry)
     {
-      gtk_widget_set_sensitive (editor->index_spinbutton, FALSE);
-      gtk_widget_set_sensitive (editor->color_entry, FALSE);
+      GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
 
-      gtk_adjustment_set_value (editor->index_adjustment, 0);
-      gtk_entry_set_text (GTK_ENTRY (editor->color_entry), "");
+      if (state & GDK_CONTROL_MASK)
+        gimp_context_set_background (image_editor->context, &entry->color);
+      else
+        gimp_context_set_foreground (image_editor->context, &entry->color);
     }
-  else
-    {
-      gchar  *string;
-      guchar *col;
-
-      gtk_adjustment_set_value (editor->index_adjustment, editor->col_index);
-
-      col = image->colormap + editor->col_index * 3;
-
-      string = g_strdup_printf ("%02x%02x%02x", col[0], col[1], col[2]);
-      gtk_entry_set_text (GTK_ENTRY (editor->color_entry), string);
-      g_free (string);
-
-      gtk_widget_set_sensitive (editor->index_spinbutton, TRUE);
-      gtk_widget_set_sensitive (editor->color_entry, TRUE);
-    }
 }
 
 static void
-gimp_colormap_preview_size_allocate (GtkWidget          *widget,
-                                     GtkAllocation      *alloc,
+gimp_colormap_editor_entry_selected (GimpPaletteView    *view,
+                                     GimpPaletteEntry   *entry,
                                      GimpColormapEditor *editor)
 {
-  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
+  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
+  GimpPalette     *palette = editor->palette;
 
-  if (HAVE_COLORMAP (image))
-    gimp_colormap_editor_draw (editor);
+  if (entry)
+    gimp_colormap_editor_set_index (editor, g_list_index (editor->palette->colors, entry), NULL);
   else
-    gimp_colormap_editor_clear (editor, -1);
+    gimp_colormap_editor_set_index (editor, 0, NULL);
 }
 
+static void
+gimp_colormap_editor_entry_activated (GimpPaletteView   *view,
+                                      GimpPaletteEntry  *entry,
+                                      GimpColormapEditor *editor)
+{
+  gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
+                                   "colormap",
+                                   "colormap-edit-color");
+}
 
-static gboolean
-gimp_colormap_preview_button_press (GtkWidget          *widget,
-                                    GdkEventButton     *bevent,
+static void
+gimp_colormap_editor_entry_context (GimpPaletteView   *view,
+                                    GimpPaletteEntry  *entry,
                                     GimpColormapEditor *editor)
 {
-  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
-  guint      col;
+  gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
+}
 
-  if (! HAVE_COLORMAP (image))
-    return TRUE;
+static void
+gimp_colormap_editor_color_dropped (GimpPaletteView    *view,
+                                    GimpPaletteEntry   *entry,
+                                    const GimpRGB      *color,
+                                    GimpColormapEditor *editor)
+{
+  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
+  GimpRGB          temp;
+  gint             index;
 
-  if (!(bevent->y < editor->cellsize * editor->yn
-        && bevent->x < editor->cellsize * editor->xn))
-    return TRUE;
-
-  col = (editor->xn * ((gint) bevent->y / editor->cellsize) +
-         ((gint) bevent->x / editor->cellsize));
-
-  if (col >= gimp_image_get_colormap_size (image))
-    return TRUE;
-
-  switch (bevent->button)
+  if (entry)
     {
-    case 1:
-      gimp_colormap_editor_set_index (editor, col, NULL);
-      g_signal_emit (editor, editor_signals[SELECTED], 0, bevent->state);
+      index = g_list_index (editor->palette->colors, entry);
+      gimp_image_get_colormap_entry (image_editor->image, index, &temp);
 
-      if (bevent->type == GDK_2BUTTON_PRESS)
-        gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
-                                         "colormap",
-                                         "colormap-edit-color");
-      return TRUE;
-
-    case 2:
-      editor->dnd_col_index = col;
-      break;
-
-    case 3:
-      gimp_colormap_editor_set_index (editor, col, NULL);
-      gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
-      return TRUE;
-
-    default:
-      break;
+      if (gimp_rgb_distance (&temp, color) > EPSILON)
+        {
+          gimp_image_set_colormap_entry (image_editor->image, index, color, TRUE);
+          gimp_image_flush (image_editor->image);
+        }
     }
-
-  return FALSE;
+  else
+    {
+      gimp_image_add_colormap_entry (image_editor->image, color);
+      gimp_image_flush (image_editor->image);
+    }
 }
 
 static void
-gimp_colormap_preview_drag_color (GtkWidget *widget,
-                                  GimpRGB   *color,
-                                  gpointer   data)
+gimp_colormap_editor_palette_dropped  (GimpPaletteView    *view,
+                                       gint                x,
+                                       gint                y,
+                                       GimpViewable       *viewable,
+                                       GimpColormapEditor *editor)
 {
-  GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
-  GimpImage          *image  = GIMP_IMAGE_EDITOR (editor)->image;
-
-  if (HAVE_COLORMAP (image))
-    gimp_image_get_colormap_entry (image, editor->dnd_col_index, color);
+  g_printf ("dropped palette at %d %d\n", x, y);
 }
 
 static void
-gimp_colormap_preview_drop_color (GtkWidget     *widget,
-                                  gint           x,
-                                  gint           y,
-                                  const GimpRGB *color,
-                                  gpointer       data)
+gimp_colormap_editor_eventbox_drop_color (GtkWidget          *widget,
+                                          gint                x,
+                                          gint                y,
+                                          const GimpRGB      *color,
+                                          GimpColormapEditor *editor)
 {
-  GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
-  GimpImage          *image  = GIMP_IMAGE_EDITOR (editor)->image;
+  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
 
-  if (HAVE_COLORMAP (image) && gimp_image_get_colormap_size (image) < 256)
+  if (HAVE_COLORMAP (image_editor->image))
     {
-      gimp_image_add_colormap_entry (image, color);
+      gimp_image_add_colormap_entry (image_editor->image, color);
+      gimp_image_flush (image_editor->image);
     }
 }
 
 static void
-gimp_colormap_adjustment_changed (GtkAdjustment      *adjustment,
-                                  GimpColormapEditor *editor)
+gimp_colormap_editor_eventbox_drop_palette  (GtkWidget          *widget,
+                                             gint                x,
+                                             gint                y,
+                                             GimpViewable       *viewable,
+                                             GimpColormapEditor *editor)
 {
-  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
+  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
 
-  if (HAVE_COLORMAP (image))
+  if (HAVE_COLORMAP (image_editor->image))
     {
-      gimp_colormap_editor_set_index (editor, adjustment->value + 0.5, NULL);
-
-      gimp_colormap_editor_update_entries (editor);
     }
 }
 
-static void
-gimp_colormap_hex_entry_changed (GimpColorHexEntry  *entry,
-                                 GimpColormapEditor *editor)
+static gboolean
+gimp_colormap_editor_eventbox_button_press (GtkWidget          *widget,
+                                            GdkEventButton     *bevent,
+                                            GimpPaletteEditor  *editor)
 {
-  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
-
-  if (image)
+  if (bevent->button == 3 && bevent->type == GDK_BUTTON_PRESS)
     {
-      GimpRGB color;
+      return gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
+    }
 
-      gimp_color_hex_entry_get_color (entry, &color);
-
-      gimp_image_set_colormap_entry (image, editor->col_index, &color, TRUE);
-      gimp_image_flush (image);
-    }
+  return TRUE;
 }
 
 static void
-gimp_colormap_image_mode_changed (GimpImage          *image,
-                                  GimpColormapEditor *editor)
+gimp_colormap_editor_scroll_top_left (GimpColormapEditor *editor)
 {
-  if (editor->color_dialog)
-    gtk_widget_hide (editor->color_dialog);
+  GtkAdjustment  *hadj;
+  GtkAdjustment  *vadj;
 
-  gimp_colormap_image_colormap_changed (image, -1, editor);
+  hadj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (editor->scrolled));
+  vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (editor->scrolled));
+
+  if (hadj)
+    gtk_adjustment_set_value (hadj, 0.0);
+  if (vadj)
+    gtk_adjustment_set_value (vadj, 0.0);
 }
 
 static void
-gimp_colormap_image_colormap_changed (GimpImage          *image,
-                                      gint                ncol,
-                                      GimpColormapEditor *editor)
+gimp_colormap_editor_viewport_size_allocate (GtkWidget          *widget,
+                                             GtkAllocation      *allocation,
+                                             GimpColormapEditor *editor)
 {
-  if (HAVE_COLORMAP (image))
-    {
-      if (ncol < 0)
-        {
-          gimp_colormap_editor_draw (editor);
-        }
-      else
-        {
-          gimp_colormap_editor_draw_cell (editor, ncol);
-        }
-
-      if (editor->index_adjustment->upper !=
-          (gimp_image_get_colormap_size (image) - 1))
-        {
-          editor->index_adjustment->upper =
-            gimp_image_get_colormap_size (image) - 1;
-
-          gtk_adjustment_changed (editor->index_adjustment);
-        }
-    }
-  else
-    {
-      gimp_colormap_editor_clear (editor, -1);
-    }
-
-  if (ncol == editor->col_index || ncol == -1)
-    gimp_colormap_editor_update_entries (editor);
+  /*gimp_view_renderer_set_size_full (GIMP_VIEW (editor->view)->renderer,
+                                    widget->allocation.width,
+                                    widget->allocation.height, 0);*/
 }
Index: app/widgets/gimpcolormapeditor.h
===================================================================
--- app/widgets/gimpcolormapeditor.h	(revision 25173)
+++ app/widgets/gimpcolormapeditor.h	(working copy)
@@ -1,21 +1,3 @@
-/* GIMP - The GNU Image Manipulation Program
- * Copyright (C) 1995 Spencer Kimball and Peter Mattis
- *
- * 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 2 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
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
 #ifndef __GIMP_COLORMAP_EDITOR_H__
 #define __GIMP_COLORMAP_EDITOR_H__
 
@@ -37,45 +19,49 @@
 {
   GimpImageEditor  parent_instance;
 
-  GtkWidget       *preview;
-  gint             col_index;
-  gint             dnd_col_index;
-  gint             xn;
-  gint             yn;
-  gint             cellsize;
+	GtkWidget       *scrolled;
+  GtkWidget       *view;
+	GtkWidget       *eventbox;
 
-  PangoLayout     *layout;
+	PangoLayout     *layout;
 
-  GtkWidget       *edit_button;
-  GtkWidget       *add_button;
+	GtkWidget       *index_spinbutton;
+	GtkAdjustment   *index_adjustment;
 
-  GtkAdjustment   *index_adjustment;
-  GtkWidget       *index_spinbutton;
-  GtkWidget       *color_entry;
+	GtkWidget       *columns_spinbutton;
+  GtkAdjustment   *columns_adjustment;
 
   GtkWidget       *color_dialog;
+
+  GimpPalette     *palette;
+
+	gint             col_index;
 };
 
 struct _GimpColormapEditorClass
 {
   GimpImageEditorClass  parent_class;
 
-  void (* selected) (GimpColormapEditor *editor,
-                     GdkModifierType     state);
+  /* signals */
+	void (* selected) (GimpColormapEditor *editor,
+										 GdkModifierType     state);
 };
 
 
-GType       gimp_colormap_editor_get_type  (void) G_GNUC_CONST;
+GType       gimp_colormap_editor_get_type   (void) G_GNUC_CONST;
 
-GtkWidget * gimp_colormap_editor_new       (GimpMenuFactory    *menu_factory);
+GtkWidget * gimp_colormap_editor_new        (GimpMenuFactory    *menu_factory);
 
-gint        gimp_colormap_editor_get_index (GimpColormapEditor *editor,
-                                            const GimpRGB      *search);
-gboolean    gimp_colormap_editor_set_index (GimpColormapEditor *editor,
-                                            gint                index,
-                                            GimpRGB            *color);
+void        gimp_colormap_editor_zoom       (GimpColormapEditor  *editor,
+                                             GimpZoomType        zoom_type);
 
-gint        gimp_colormap_editor_max_index (GimpColormapEditor *editor);
+gint        gimp_colormap_editor_get_index  (GimpColormapEditor *editor,
+                                             const GimpRGB     *search);
+gboolean    gimp_colormap_editor_set_index  (GimpColormapEditor *editor,
+                                             gint               index,
+                                             GimpRGB           *color);
 
+gint        gimp_colormap_editor_max_index  (GimpColormapEditor *editor);
 
+
 #endif /* __GIMP_COLORMAP_EDITOR_H__ */

Attachment: pgpeiB1nqQQTs.pgp
Description: PGP signature

_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux