* src/colorlabel.c
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 11 Feb 2003 20:49:05 +0000 (20:49 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 11 Feb 2003 20:49:05 +0000 (20:49 +0000)
don't use pixmaps for label color rect but draw rectangles
so we can respect the color map of palette based visuals
(fixes the long time crashes on Suns - thanks to Andreas
Engel and Steve O'Hara-Smith for testing)

ChangeLog.claws
configure.ac
src/colorlabel.c

index 13f9b27..060281f 100644 (file)
@@ -1,3 +1,11 @@
+2003-02-11 [alfons]    0.8.9claws55
+
+       * src/colorlabel.c
+               don't use pixmaps for label color rect but draw rectangles
+               so we can respect the color map of palette based visuals
+               (fixes the long time crashes on Suns - thanks to Andreas
+               Engel and Steve O'Hara-Smith for testing)
+
 2003-02-11 [christoph] 0.8.9claws54
 
        * src/matcher_parser_parse.y
 2003-02-11 [christoph] 0.8.9claws54
 
        * src/matcher_parser_parse.y
index 607d63a..9fb8080 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=9
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=9
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws54
+EXTRA_VERSION=claws55
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 42a447e..11dc581 100644 (file)
@@ -35,6 +35,7 @@
 #include <gtk/gtkalignment.h>
 #include <gtk/gtkhbox.h>
 #include <gtk/gtkwindow.h>
 #include <gtk/gtkalignment.h>
 #include <gtk/gtkhbox.h>
 #include <gtk/gtkwindow.h>
+#include <gtk/gtkdrawingarea.h>
 
 #include "intl.h"
 #include "colorlabel.h"
 
 #include "intl.h"
 #include "colorlabel.h"
@@ -66,7 +67,7 @@ static struct
        /* XXX: note that the label member is supposed to be dynamically 
         * allocated and fffreed */
        gchar                   *label;
        /* XXX: note that the label member is supposed to be dynamically 
         * allocated and fffreed */
        gchar                   *label;
-       GtkPixmap               *pixmap;
+       GtkWidget               *widget;
 } label_colors[] = {
        { LCCF_ALL, { 0, 0xffff, (0x99 << 8), 0x0 },            NULL, NULL },
        { LCCF_ALL, { 0, 0xffff, 0, 0 },                        NULL, NULL },
 } label_colors[] = {
        { LCCF_ALL, { 0, 0xffff, (0x99 << 8), 0x0 },            NULL, NULL },
        { LCCF_ALL, { 0, 0xffff, 0, 0 },                        NULL, NULL },
@@ -107,56 +108,52 @@ gchar *colorlabel_get_color_text(gint color_index)
        return label_colors[color_index].label;
 }
 
        return label_colors[color_index].label;
 }
 
-GtkPixmap *colorlabel_create_color_pixmap(GdkColor color)
+static gboolean colorlabel_drawing_area_expose_event_cb
+       (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
 {
 {
-       const gchar *FMT = "+      c #%2.2X%2.2X%2.2X";
-       gchar buf[40];
-
-       /* black frame of 1 pixel */
-       gchar *dummy_xpm[] = {
-               "16 16 3 1",
-               "       c None",
-               ".      c #000000",
-               "+      c #000000",
-               "................",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               "................"
-       };
-
-       GdkBitmap *xpmmask;
-       GdkPixmap *xpm;
-       GtkPixmap *pixmap;
-
-       /* put correct color in xpm data */
-       sprintf(buf, FMT, color.red >> 8, color.green >> 8, color.blue >> 8);
-       dummy_xpm[3] = buf;                             
-
-       /* XXX: passing NULL as GdkWindow* seems to be possible */
-       xpm = gdk_pixmap_create_from_xpm_d
-               (GDK_ROOT_PARENT(), &xpmmask, NULL, (gchar **) &dummy_xpm);
-       if (xpm == NULL)
-               debug_print("*** NO XPM\n");
-       pixmap = GTK_PIXMAP(gtk_pixmap_new(xpm, xpmmask)); 
-
-       g_return_val_if_fail(pixmap, NULL);
-
-       gdk_pixmap_unref(xpm);
-       gdk_bitmap_unref(xpmmask);
-
-       return pixmap;
+       GdkDrawable *drawable = widget->window;
+       gulong c = (gulong) GPOINTER_TO_INT(data);
+       GdkColor color;
+       GdkGC *gc;
+
+       color.red   = ((c >> 16UL) & 0xFFUL) << 8UL;
+       color.green = ((c >>  8UL) & 0xFFUL) << 8UL;
+       color.blue  = ((c)         & 0xFFUL) << 8UL;
+
+       gdk_colormap_alloc_color(gtk_widget_get_colormap(widget), &color, FALSE, TRUE);
+
+       gc = gdk_gc_new(drawable);
+
+       gdk_gc_set_foreground(gc, &color);
+       gdk_draw_rectangle(drawable, gc,
+                          TRUE, 0, 0, widget->allocation.width,
+                          widget->allocation.height);
+       gdk_draw_rectangle(drawable, widget->style->black_gc,
+                          FALSE, 0, 0, widget->allocation.width,
+                          widget->allocation.height);
+
+       gdk_gc_unref(gc);                          
+       
+       return FALSE;
+}
+
+static GtkWidget *colorlabel_create_color_widget(GdkColor color)
+{
+       GtkWidget *widget;
+
+       widget = gtk_drawing_area_new();
+       gtk_drawing_area_size(GTK_DRAWING_AREA(widget), 16, 16);
+
+#define CL(x)          (((gulong) (x) >> (gulong) 8) & 0xFFUL) 
+#define CR(r, g, b)    ((CL(r) << (gulong) 16) | \
+                        (CL(g) << (gulong)  8) | \
+                        (CL(b)))
+
+       gtk_signal_connect(GTK_OBJECT(widget), "expose_event", 
+                          colorlabel_drawing_area_expose_event_cb,
+                          GINT_TO_POINTER( (gint) CR(color.red, color.green, color.blue )));
+
+       return widget;
 }
 
 /* XXX: this function to check if menus with colors and labels should
 }
 
 /* XXX: this function to check if menus with colors and labels should
@@ -178,18 +175,18 @@ gboolean colorlabel_changed(void)
  * function */
 static void colorlabel_recreate_color(gint color)
 {
  * function */
 static void colorlabel_recreate_color(gint color)
 {
-       GtkPixmap *pixmap;
+       GtkWidget *widget;
 
        if (!(label_colors[color].changed & LCCF_COLOR))
                return;
 
 
        if (!(label_colors[color].changed & LCCF_COLOR))
                return;
 
-       pixmap = GTK_PIXMAP(colorlabel_create_color_pixmap(label_colors[color].color));
-       g_return_if_fail(pixmap);
+       widget = colorlabel_create_color_widget(label_colors[color].color);
+       g_return_if_fail(widget);
 
 
-       if (label_colors[color].pixmap)
-               gtk_widget_destroy(GTK_WIDGET(label_colors[color].pixmap));
+       if (label_colors[color].widget) 
+               gtk_widget_destroy(label_colors[color].widget);
 
 
-       label_colors[color].pixmap = pixmap;            
+       label_colors[color].widget = widget;            
        label_colors[color].changed &= ~LCCF_COLOR;
 }
 
        label_colors[color].changed &= ~LCCF_COLOR;
 }
 
@@ -249,9 +246,8 @@ GtkWidget *colorlabel_create_check_color_menu_item(gint color_index)
        gtk_widget_show(align);
        gtk_container_set_border_width(GTK_CONTAINER(align), 1);
 
        gtk_widget_show(align);
        gtk_container_set_border_width(GTK_CONTAINER(align), 1);
 
-       gtk_container_add(GTK_CONTAINER(align),
-                         GTK_WIDGET(label_colors[color_index].pixmap));
-       gtk_widget_show(GTK_WIDGET(label_colors[color_index].pixmap));
+       gtk_container_add(GTK_CONTAINER(align), label_colors[color_index].widget);
+       gtk_widget_show(label_colors[color_index].widget);
        gtk_widget_set_usize(align, 16, 16);
 
        gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0);
        gtk_widget_set_usize(align, 16, 16);
 
        gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0);
@@ -284,7 +280,7 @@ GtkWidget *colorlabel_create_color_menu(void)
        
        /* and the color items */
        for (i = 0; i < LABEL_COLORS_ELEMS; i++) {
        
        /* and the color items */
        for (i = 0; i < LABEL_COLORS_ELEMS; i++) {
-               GtkPixmap *pixmap = colorlabel_create_color_pixmap(label_colors[i].color);
+               GtkWidget *widget = colorlabel_create_color_widget(label_colors[i].color);
 
                item  = gtk_menu_item_new();
                gtk_object_set_data(GTK_OBJECT(item), "color", GUINT_TO_POINTER(i + 1));
 
                item  = gtk_menu_item_new();
                gtk_object_set_data(GTK_OBJECT(item), "color", GUINT_TO_POINTER(i + 1));
@@ -301,8 +297,8 @@ GtkWidget *colorlabel_create_color_menu(void)
                gtk_widget_show(align);
                gtk_container_set_border_width(GTK_CONTAINER(align), 1);
 
                gtk_widget_show(align);
                gtk_container_set_border_width(GTK_CONTAINER(align), 1);
 
-               gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(pixmap));
-               gtk_widget_show(GTK_WIDGET(pixmap));
+               gtk_container_add(GTK_CONTAINER(align), widget);
+               gtk_widget_show(widget);
                gtk_widget_set_usize(align, 16, 16);
 
                gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0);
                gtk_widget_set_usize(align, 16, 16);
 
                gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0);