]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorsel.c
Do nothing on empty string, quietly.
[~andy/gtk] / gtk / gtkcolorsel.c
index c8822743a9bfcf6efc22d1977a4e167c11ccec5a..eb660b9d4746f9936d9d796c9a6f4b468aa84192 100644 (file)
@@ -21,6 +21,7 @@
 #include <math.h>
 #include <gdk/gdk.h>
 #include "gtkcolorsel.h"
+#include "gtkwindow.h"
 #include "gtkhbbox.h"
 #include "gtkdnd.h"
 #include "gtkselection.h"
@@ -195,7 +196,7 @@ static const gchar  *value_index_key = "gtk-value-index";
 #define SF GtkSignalFunc
 
 
-scale_val_type scale_vals[NUM_CHANNELS] =
+static const scale_val_type scale_vals[NUM_CHANNELS] =
 {
   {"Hue:",        0.0, 360.0, 1.00, 10.00, (SF) gtk_color_selection_hsv_updater},
   {"Saturation:", 0.0,   1.0, 0.01,  0.01, (SF) gtk_color_selection_hsv_updater},
@@ -213,7 +214,7 @@ gtk_color_selection_get_type (void)
 
   if (!color_selection_type)
     {
-      GtkTypeInfo colorsel_info =
+      static const GtkTypeInfo colorsel_info =
       {
        "GtkColorSelection",
        sizeof (GtkColorSelection),
@@ -287,7 +288,7 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
   colorsel->policy = GTK_UPDATE_CONTINUOUS;
 
   hbox = gtk_hbox_new (FALSE, 5);
-  gtk_container_border_width (GTK_CONTAINER (hbox), 5);
+  gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
   gtk_container_add (GTK_CONTAINER (colorsel), hbox);
 
   vbox = gtk_vbox_new (FALSE, 5);
@@ -323,7 +324,7 @@ gtk_color_selection_init (GtkColorSelection *colorsel)
 
   frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-  gtk_container_border_width (GTK_CONTAINER (frame), 0);
+  gtk_container_set_border_width (GTK_CONTAINER (frame), 0);
   gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, TRUE, 0);
   gtk_widget_show (frame);
 
@@ -516,7 +517,7 @@ gtk_color_selection_realize (GtkWidget         *widget)
 {
   GtkColorSelection *colorsel;
 
-  GtkTargetEntry targets[] = {
+  static const GtkTargetEntry targets[] = {
     { "application/x-color", 0 }
   };
 
@@ -862,6 +863,7 @@ gtk_color_selection_drag_begin (GtkWidget      *widget,
   GdkColor bg;
 
   window = gtk_window_new(GTK_WINDOW_POPUP);
+  gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
   gtk_widget_set_usize (window, 48, 32);
   gtk_widget_realize (window);
 
@@ -1024,11 +1026,15 @@ static gint
 gtk_color_selection_value_timeout (GtkColorSelection *colorsel)
 {
   gint x, y;
-
+  
+  GDK_THREADS_ENTER ();
+  
   gdk_window_get_pointer (colorsel->value_area->window, &x, &y, NULL);
   gtk_color_selection_update_value (colorsel, y);
   gtk_color_selection_color_changed (colorsel);
 
+  GDK_THREADS_LEAVE ();
+
   return (TRUE);
 }
 
@@ -1041,14 +1047,15 @@ gtk_color_selection_value_events (GtkWidget *area,
 
   colorsel = (GtkColorSelection*) gtk_object_get_data (GTK_OBJECT (area), "_GtkColorSelection");
 
+  if (colorsel->value_gc == NULL)
+    colorsel->value_gc = gdk_gc_new (colorsel->value_area->window);
+
   switch (event->type)
     {
     case GDK_MAP:
       gtk_color_selection_draw_value_marker (colorsel);
       break;
     case GDK_EXPOSE:
-      if (colorsel->value_gc == NULL)
-       colorsel->value_gc = gdk_gc_new (colorsel->value_area->window);
       gtk_color_selection_draw_value_marker (colorsel);
       break;
     case GDK_BUTTON_PRESS:
@@ -1128,7 +1135,14 @@ gtk_color_selection_wheel_events (GtkWidget *area,
   gint x, y;
 
   colorsel = (GtkColorSelection*) gtk_object_get_data (GTK_OBJECT (area), "_GtkColorSelection");
-
+  
+  if (colorsel->wheel_gc == NULL)
+    colorsel->wheel_gc = gdk_gc_new (colorsel->wheel_area->window);
+  if (colorsel->sample_gc == NULL)
+    colorsel->sample_gc = gdk_gc_new (colorsel->sample_area->window);
+  if (colorsel->value_gc == NULL)
+    colorsel->value_gc = gdk_gc_new (colorsel->value_area->window);
+  
   switch (event->type)
     {
     case GDK_MAP:
@@ -1137,12 +1151,6 @@ gtk_color_selection_wheel_events (GtkWidget *area,
       gtk_color_selection_draw_sample (colorsel, TRUE);
       break;
     case GDK_EXPOSE:
-      if (colorsel->wheel_gc == NULL)
-       colorsel->wheel_gc = gdk_gc_new (colorsel->wheel_area->window);
-      if (colorsel->sample_gc == NULL)
-       colorsel->sample_gc = gdk_gc_new (colorsel->sample_area->window);
-      if (colorsel->value_gc == NULL)
-       colorsel->value_gc = gdk_gc_new (colorsel->value_area->window);
       gtk_color_selection_draw_wheel_marker (colorsel);
       gtk_color_selection_draw_wheel_frame (colorsel);
       break;
@@ -1247,7 +1255,7 @@ gtk_color_selection_draw_value_bar (GtkColorSelection *colorsel,
       v -= sv;
     }
 
-  gtk_widget_draw (colorsel->value_area, NULL);
+  gtk_widget_queue_draw (colorsel->value_area);
 }
 
 static void
@@ -1320,7 +1328,39 @@ gtk_color_selection_draw_wheel (GtkColorSelection *colorsel,
       gtk_preview_draw_row (GTK_PREVIEW (colorsel->wheel_area), colorsel->wheel_buf, 0, y, wid);
     }
 
-  gtk_widget_draw (colorsel->wheel_area, NULL);
+  if (colorsel->wheel_area->window)
+     {
+       GdkPixmap *pm = NULL;
+       GdkGC     *pmgc = NULL;
+       GdkColor   col;
+       gint w, h;
+       
+       pm = gdk_pixmap_new (colorsel->wheel_area->window, wid, heig, 1);
+       pmgc = gdk_gc_new (pm);
+       
+       col.pixel = 0;
+       gdk_gc_set_foreground(pmgc, &col);
+       gdk_draw_rectangle(pm, pmgc, TRUE, 0, 0, wid, heig);
+       col.pixel = 1;
+       
+       gdk_gc_set_foreground(pmgc, &col);
+       gdk_draw_arc (pm, pmgc, TRUE, 0, 0, wid, heig, 0, 360*64);
+
+       w = colorsel->wheel_area->allocation.width;
+       h = colorsel->wheel_area->allocation.height;
+       
+       gdk_draw_arc (pm, pmgc,
+                     FALSE, 1, 1, w - 1, h - 1, 30 * 64, 180 * 64);
+       gdk_draw_arc (pm, pmgc,
+                     FALSE, 0, 0, w, h, 30 * 64, 180 * 64);
+       gdk_draw_arc (pm, pmgc,
+                     FALSE, 1, 1, w - 1, h - 1, 210 * 64, 180 * 64);
+       gdk_draw_arc (pm, pmgc,
+                     FALSE, 0, 0, w, h, 210 * 64, 180 * 64);
+       gdk_window_shape_combine_mask(colorsel->wheel_area->window, pm, 0, 0);
+       gdk_pixmap_unref(pm);
+       gdk_gc_destroy(pmgc);
+     }
 }
 
 static void
@@ -1385,7 +1425,7 @@ gtk_color_selection_draw_sample (GtkColorSelection *colorsel,
       gtk_preview_draw_row (GTK_PREVIEW (colorsel->sample_area), colorsel->sample_buf, 0, y, wid);
     }
 
-  gtk_widget_draw (colorsel->sample_area, NULL);
+  gtk_widget_queue_draw (colorsel->sample_area);
 }
 
 static gint
@@ -1574,7 +1614,7 @@ gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
   GtkWidget *action_area, *frame;
 
   colorseldiag->main_vbox = gtk_vbox_new (FALSE, 10);
-  gtk_container_border_width (GTK_CONTAINER (colorseldiag), 10);
+  gtk_container_set_border_width (GTK_CONTAINER (colorseldiag), 10);
   gtk_container_add (GTK_CONTAINER (colorseldiag), colorseldiag->main_vbox);
   gtk_widget_show (colorseldiag->main_vbox);