* Jim Evins <evins@snaught.com>
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU General Public
* License, version 2, as published by the Free Software Foundation.
*
* This library 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
- * Library General Public License for more details.
+ * General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
#include <gtk/gtkentry.h>
#include <gtk/gtksignal.h>
-#include <libgnomecanvas/gnome-canvas.h>
-#include <libgnomecanvas/gnome-canvas-pixbuf.h>
-#include <libgnomecanvas/gnome-canvas-rect-ellipse.h>
+#include <gtk/gtkimage.h>
#include "e-util.h"
#include "e-colors.h"
#include "widget-color-combo.h"
static guint color_combo_signals [LAST_SIGNAL] = { 0, };
-#define PARENT_TYPE GTK_COMBO_BOX_TYPE
+#define PARENT_TYPE MYGAL_COMBO_BOX_TYPE
static GObjectClass *color_combo_parent_class;
#define make_color(CC,COL) (((COL) != NULL) ? (COL) : ((CC) ? ((CC)->default_color) : NULL))
+#define RGBA_TO_UINT(r,g,b,a) ((((guint)(r))<<24)|(((guint)(g))<<16)|(((guint)(b))<<8)|(guint)(a))
+#define GDK_TO_UINT(c) RGBA_TO_UINT(((c).red>>8), ((c).green>>8), ((c).blue>>8), 0xff)
+
+#define PREVIEW_SIZE 20
static void
color_combo_set_color_internal (ColorCombo *cc, GdkColor *color)
{
+ guint color_y, color_height;
+ guint height, width;
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *color_pixbuf;
GdkColor *new_color;
GdkColor *outline_color;
/* If the new and the default are NULL draw an outline */
outline_color = (new_color) ? new_color : &e_dark_gray;
- gnome_canvas_item_set (cc->preview_color_item,
- "fill_color_gdk", new_color,
- "outline_color_gdk", outline_color,
- NULL);
+ pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (cc->preview_image));
+
+ if (!pixbuf)
+ return;
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+
+ if (cc->preview_is_icon) {
+ color_y = height - 4;
+ color_height = 4;
+ }
+ else {
+ color_y = 0;
+ color_height = height;
+ }
+
+ color_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+ TRUE, 8,
+ width,
+ color_height);
+ gdk_pixbuf_fill (color_pixbuf, GDK_TO_UINT (*outline_color));
+ gdk_pixbuf_copy_area (color_pixbuf, 0, 0, width, color_height,
+ pixbuf, 0, color_y);
+
+ if (new_color != NULL)
+ gdk_pixbuf_fill (color_pixbuf, GDK_TO_UINT (*new_color));
+ else
+ gdk_pixbuf_fill (color_pixbuf, 0xffffff00);
+ gdk_pixbuf_copy_area (color_pixbuf, 0, 0, width - 2, color_height -2,
+ pixbuf, 1, color_y + 1);
+
+ g_object_unref (color_pixbuf);
+
+ gtk_widget_queue_draw (GTK_WIDGET (cc));
}
static void
g_signal_emit (cc,
color_combo_signals [CHANGED], 0,
color, is_custom, by_user, is_default);
- gtk_combo_box_popup_hide (GTK_COMBO_BOX (cc));
+ mygal_combo_box_popup_hide (MYGAL_COMBO_BOX (cc));
}
static void
static void
cb_cust_color_clicked (GtkWidget *widget, ColorCombo *cc)
{
- gtk_combo_box_popup_hide (GTK_COMBO_BOX (cc));
+ mygal_combo_box_popup_hide (MYGAL_COMBO_BOX (cc));
}
/*
ColorGroup *color_group)
{
GdkColor *color;
+ GdkPixbuf *pixbuf = NULL;
+
g_return_if_fail (cc != NULL);
g_return_if_fail (IS_COLOR_COMBO (cc));
/*
- * Our button with the canvas preview
+ * Our button with the gtk_image preview
*/
cc->preview_button = gtk_button_new ();
- gtk_button_set_relief (GTK_BUTTON (cc->preview_button), GTK_RELIEF_NONE);
+ cc->preview_is_icon = FALSE;
+
+ if (icon)
+ /* use icon only if size > 4*4 */
+ if ((gdk_pixbuf_get_width (icon) > 4) &&
+ (gdk_pixbuf_get_height (icon) > 4))
+ {
+ cc->preview_is_icon = TRUE;
+ pixbuf = gdk_pixbuf_copy (icon);
+ }
+
+ if (pixbuf == NULL)
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+ TRUE, 8,
+ PREVIEW_SIZE,
+ PREVIEW_SIZE);
+
+ cc->preview_image = gtk_image_new_from_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
- cc->preview_canvas = GNOME_CANVAS (gnome_canvas_new ());
-
- gnome_canvas_set_scroll_region (cc->preview_canvas, 0, 0, 24, 24);
- if (icon) {
- gnome_canvas_item_new (
- GNOME_CANVAS_GROUP (gnome_canvas_root (cc->preview_canvas)),
- GNOME_TYPE_CANVAS_PIXBUF,
- "pixbuf", icon,
- "x", 0.0,
- "y", 0.0,
- "anchor", GTK_ANCHOR_NW,
- NULL);
- gdk_pixbuf_unref (icon);
-
- cc->preview_color_item = gnome_canvas_item_new (
- GNOME_CANVAS_GROUP (gnome_canvas_root (cc->preview_canvas)),
- gnome_canvas_rect_get_type (),
- "x1", 3.0,
- "y1", 19.0,
- "x2", 20.0,
- "y2", 22.0,
- "fill_color", "black",
- "width_pixels", 1,
- NULL);
- } else
- cc->preview_color_item = gnome_canvas_item_new (
- GNOME_CANVAS_GROUP (gnome_canvas_root (cc->preview_canvas)),
- gnome_canvas_rect_get_type (),
- "x1", 2.0,
- "y1", 1.0,
- "x2", 21.0,
- "y2", 22.0,
- "fill_color", "black",
- "width_pixels", 1,
- NULL);
-
- gtk_container_add (GTK_CONTAINER (cc->preview_button), GTK_WIDGET (cc->preview_canvas));
- gtk_widget_set_usize (GTK_WIDGET (cc->preview_canvas), 24, 22);
+ gtk_button_set_relief (GTK_BUTTON (cc->preview_button), GTK_RELIEF_NONE);
+ gtk_widget_show (cc->preview_image);
+
+ gtk_container_add (GTK_CONTAINER (cc->preview_button), cc->preview_image);
g_signal_connect (cc->preview_button, "clicked",
G_CALLBACK (preview_clicked), cc);
gtk_widget_show_all (cc->preview_button);
- gtk_combo_box_construct (GTK_COMBO_BOX (cc),
- cc->preview_button,
- GTK_WIDGET (cc->palette));
+ mygal_combo_box_construct (MYGAL_COMBO_BOX (cc),
+ cc->preview_button,
+ GTK_WIDGET (cc->palette));
- gtk_combo_box_set_tearable (GTK_COMBO_BOX (cc), FALSE);
+ mygal_combo_box_set_tearable (MYGAL_COMBO_BOX (cc), FALSE);
color = color_palette_get_current_color (cc->palette, NULL);
color_combo_set_color_internal (cc, color);