[gtk+/gtk-3-6] Ensure GtkColorButton has a dialog when adding a palette



commit 9a0b91461055b0e7bb997fb414819e8257ad620d
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Mon Dec 3 23:46:18 2012 +0100

    Ensure GtkColorButton has a dialog when adding a palette
    
    https://bugzilla.gnome.org/show_bug.cgi?id=132333

 gtk/gtkcolorbutton.c |   55 ++++++++++++++++++++++++++++---------------------
 1 files changed, 31 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c
index 63dd81c..52c1ec5 100644
--- a/gtk/gtkcolorbutton.c
+++ b/gtk/gtkcolorbutton.c
@@ -584,36 +584,42 @@ 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);
@@ -962,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);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]