]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorbutton.c
a11y: Emit active-descendants-changed when focus changes
[~andy/gtk] / gtk / gtkcolorbutton.c
index ab2821fa41a4ea3cf79b97adcf2cf7727089330a..52c1ec52516f12f5dc1f973394ccd630c7ebb355 100644 (file)
@@ -60,8 +60,6 @@
 #define CHECK_DARK  (1.0 / 3.0)
 #define CHECK_LIGHT (2.0 / 3.0)
 
-#define COLOR_SAMPLE_MARGIN 1
-
 struct _GtkColorButtonPrivate
 {
   GtkWidget *draw_area; /* Widget where we draw the color sample */
@@ -243,8 +241,7 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
    * @widget: the object which received the signal.
    *
    * The ::color-set signal is emitted when the user selects a color.
-   * When handling this signal, use gtk_color_button_get_color() and
-   * gtk_color_button_get_alpha() (or gtk_color_button_get_rgba()) to
+   * When handling this signal, use gtk_color_button_get_rgba() to
    * find out which color was just selected.
    *
    * Note that this signal is only emitted when the <emphasis>user</emphasis>
@@ -437,19 +434,12 @@ gtk_color_button_init (GtkColorButton *button)
   gtk_widget_push_composite_child ();
 
   button->priv->draw_area = gtk_drawing_area_new ();
-  g_object_set (button->priv->draw_area, 
-                "margin-top", COLOR_SAMPLE_MARGIN,
-                "margin-bottom", COLOR_SAMPLE_MARGIN,
-                "margin-left", 16,
-                "margin-right", 16,
-                NULL);
-
   layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black");
   pango_layout_get_pixel_extents (layout, NULL, &rect);
   g_object_unref (layout);
 
   gtk_widget_set_size_request (button->priv->draw_area, 
-                               rect.width, rect.height - 2 * COLOR_SAMPLE_MARGIN);
+                               rect.width, rect.height);
 
   g_signal_connect (button->priv->draw_area, "draw",
                     G_CALLBACK (gtk_color_button_draw_cb), button);
@@ -594,40 +584,49 @@ dialog_response (GtkDialog *dialog,
     }
 }
 
+/* Create the dialog and connects its buttons */
 static void
-gtk_color_button_clicked (GtkButton *b)
+ensure_dialog (GtkColorButton *button)
 {
-  GtkColorButton *button = GTK_COLOR_BUTTON (b);
-  GtkWidget *dialog;
+  GtkWidget *parent, *dialog;
 
-  /* if dialog already exists, make sure it's shown and raised */
-  if (!button->priv->cs_dialog)
-    {
-      /* Create the dialog and connects its buttons */
-      GtkWidget *parent;
+  if (button->priv->cs_dialog != NULL)
+    return;
 
-      parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+  parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
 
-      button->priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
+  button->priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
 
-      if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
-        {
-          if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
-            gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
+  if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+  {
+    if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
+      gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
 
-          gtk_window_set_modal (GTK_WINDOW (dialog),
-                                gtk_window_get_modal (GTK_WINDOW (parent)));
-        }
+    gtk_window_set_modal (GTK_WINDOW (dialog),
+                            gtk_window_get_modal (GTK_WINDOW (parent)));
+  }
+
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (dialog_response), button);
+  g_signal_connect (dialog, "destroy",
+                    G_CALLBACK (dialog_destroy), button);
+}
 
-      g_signal_connect (dialog, "response",
-                        G_CALLBACK (dialog_response), button);
-      g_signal_connect (dialog, "destroy",
-                        G_CALLBACK (dialog_destroy), button);
-    }
+
+static void
+gtk_color_button_clicked (GtkButton *b)
+{
+  GtkColorButton *button = GTK_COLOR_BUTTON (b);
+
+  /* if dialog already exists, make sure it's shown and raised */
+  ensure_dialog (button);
 
   gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
                                    button->priv->use_alpha);
 
+  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
+                              &button->priv->rgba);
+
   gtk_window_present (GTK_WINDOW (button->priv->cs_dialog));
 }
 
@@ -728,7 +727,7 @@ gtk_color_button_get_alpha (GtkColorButton *button)
 }
 
 /**
- * gtk_color_button_set_rgba:
+ * gtk_color_button_set_rgba: (skip)
  * @button: a #GtkColorButton
  * @rgba: a #GdkRGBA to set the current color with
  *
@@ -754,7 +753,7 @@ gtk_color_button_set_rgba (GtkColorButton *button,
 }
 
 /**
- * gtk_color_button_get_rgba:
+ * gtk_color_button_get_rgba: (skip)
  * @button: a #GtkColorButton
  * @rgba: (out): a #GdkRGBA to fill in with the current color
  *
@@ -969,8 +968,9 @@ gtk_color_button_add_palette (GtkColorChooser *chooser,
 {
   GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
 
-  if (button->priv->cs_dialog)
-    gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
+  ensure_dialog (button);
+
+  gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
                                    orientation, colors_per_line, n_colors, colors);
 }