2011-10-07 [colin] 3.7.10cvs21
[claws.git] / src / gtk / colorlabel.c
index ace677307017cd3c1629436ac823a5434df85c81..c5014bfe65fe29e3aedde1001fc6efaf252e8529 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2009 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 2001-2011 Hiroyuki Yamamoto & The Claws Mail Team
  *
  * 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
@@ -130,7 +130,9 @@ static struct
 #define LABEL_COLORS_ELEMS (sizeof label_colors[0] / sizeof label_colors[0][0])
 
 #define G_RETURN_VAL_IF_INVALID_COLOR(color, val) \
-       g_return_val_if_fail((color) >= 0 && (color) < LABEL_COLORS_ELEMS, (val))
+       do if ((color) < 0 || (color) >= LABEL_COLORS_ELEMS) {  \
+               return val;                                     \
+       } while(0)
 
 #define INTCOLOR_TO_GDKCOLOR(intcolor, gdkcolor) \
        gdkcolor.red   = ((intcolor >> 16UL) & 0xFFUL) << 8UL; \
@@ -187,28 +189,41 @@ gchar *colorlabel_get_color_default_text(gint color_index)
 }
 
 static gboolean colorlabel_drawing_area_expose_event_cb
+#if !GTK_CHECK_VERSION(3, 0, 0)
        (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
+#else
+       (GtkWidget *widget, cairo_t *cr, gpointer data)
+#endif
 {
-       GdkDrawable *drawable = widget->window;
+#if !GTK_CHECK_VERSION(3, 0, 0)
+       cairo_t *cr;
+       GdkWindow *drawable = gtk_widget_get_window(widget);
+#endif
+       GtkAllocation allocation;
        gulong c = (gulong) GPOINTER_TO_INT(data);
        GdkColor color;
-       GdkGC *gc;
 
        INTCOLOR_TO_GDKCOLOR(c, color)
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
        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, widget->style->black_gc,
-                          FALSE, 0, 0, widget->allocation.width - 1,
-                          widget->allocation.height - 1);
-       gdk_draw_rectangle(drawable, gc,
-                          TRUE, 1, 1, widget->allocation.width - 2,
-                          widget->allocation.height - 2);
-
-       g_object_unref(gc);                        
+       cr = gdk_cairo_create(drawable);
+#endif
+       gtk_widget_get_allocation(widget, &allocation);
+
+       cairo_set_source_rgb(cr, 0., 0., 0.);
+       cairo_rectangle(cr, 0, 0,
+           allocation.width - 1,
+           allocation.height - 1);
+       cairo_stroke(cr);
+       gdk_cairo_set_source_color(cr, &color);
+       cairo_rectangle(cr, 1, 1,
+           allocation.width - 2,
+           allocation.height - 2);
+       cairo_fill(cr);
+#if !GTK_CHECK_VERSION(3, 0, 0)
+       cairo_destroy(cr);
+#endif
        
        return FALSE;
 }
@@ -226,11 +241,19 @@ static GtkWidget *colorlabel_create_color_widget(GdkColor color)
                         (CL(g) << (gulong)  8) | \
                         (CL(b)))
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
        g_signal_connect(G_OBJECT(widget), "expose_event", 
                         G_CALLBACK
                                (colorlabel_drawing_area_expose_event_cb),
                         GINT_TO_POINTER
                                ((gint)CR(color.red, color.green, color.blue)));
+#else
+       g_signal_connect(G_OBJECT(widget), "draw", 
+                        G_CALLBACK
+                               (colorlabel_drawing_area_expose_event_cb),
+                        GINT_TO_POINTER
+                               ((gint)CR(color.red, color.green, color.blue)));
+#endif
 
        return widget;
 }
@@ -248,7 +271,7 @@ static void colorlabel_recreate_color(gint color)
                        continue;
 
                widget = colorlabel_create_color_widget(label_colors[i][color].color);
-               g_return_if_fail(widget);
+               cm_return_if_fail(widget);
 
                if (label_colors[i][color].widget) 
                        gtk_widget_destroy(label_colors[i][color].widget);
@@ -263,7 +286,7 @@ static void colorlabel_recreate_label(gint color)
        int i;
        
        for (i = 0; i < NUM_MENUS; i++) {
-               if (!label_colors[i][color].changed & LCCF_LABEL)
+               if (!(label_colors[i][color].changed & LCCF_LABEL))
                        continue;
 
                if (label_colors[i][color].label == NULL) 
@@ -379,6 +402,10 @@ GtkWidget *colorlabel_create_color_menu(void)
        g_object_set_data(G_OBJECT(item), "color", GUINT_TO_POINTER(0));
        gtk_widget_show(item);
 
+       item = gtk_separator_menu_item_new();
+       gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       gtk_widget_show(item);
+
        /* and the color items */
        for (i = 0; i < LABEL_COLORS_ELEMS; i++) {
                GtkWidget *hbox;