thread safety
[hildon] / hildon-widgets / hildon-color-popup.c
index fbecfcc..3cc8e4c 100644 (file)
  *
  */
 
-/*
- * @file hildon-color-popup.c
+/**
+ * SECTION:hildon-color-popup
+ * @short_description: A popup dialog for editing a color and showing the 
+ * edited result
+ * @see_also: #HildonColorButton, #HildonColorSelector
  *
- * This file contains the implementation of Hildon Color Selector Popup
- * widget containing the custom color palette selector popup for selecting 
- * different colors based on RGB values.
+ * #HildonColorPopup is only used inside #HildonColorButton. It is a
+ * popup dialog for editing a color. The color can be changed using
+ * three control bars that are used to adjust the red, green and blue
+ * color channels. The display is updated in real time when the bars are
+ * moved.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -53,6 +58,7 @@
 #define HILDON_COLOR_LABELS_LEFT_PAD      35
 #define HILDON_COLOR_PALETTE_POS_PAD      45
 #define HILDON_COLOR_BAR_WIDTH           449
+#define HILDON_COLOR_COL_SPACING          18
 
 /* 
  * Private function prototype definitions 
@@ -64,9 +70,9 @@ hildon_popup_palette_expose (GtkWidget * widget,
                              gpointer data);
 /**
  * hildon_color_popup_new:
- * @parent: the parent window of the dialog.
- * @initial_color: a #GdkColor with the initial values to be used.
- * @popup_data: a #HildonColorPopup.
+ * @parent: the parent window of the dialog
+ * @initial_color: a #GdkColor with the initial values to be used
+ * @popup_data: a #HildonColorPopup
  *
  * This function creates a new popup dialog with three controlbars
  * (red, green, blue) and a drawing area with the current color.
@@ -74,20 +80,17 @@ hildon_popup_palette_expose (GtkWidget * widget,
  * Used as normal GtkDialog (run with gtk_dialog_run() and read 
  * stardard responses (GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL). 
  *
- * Returns: the newly created popup dialog. 
+ * Returns: the newly created popup dialog 
  */
 
 GtkWidget *
-hildon_color_popup_new(GtkWindow *parent, GdkColor *initial_color, 
+hildon_color_popup_new(GtkWindow *parent, const GdkColor *initial_color, 
                HildonColorPopup *popup_data)
 {
   GtkWidget *popup;
   GtkTable *layout;
   GtkWidget *area;
   GtkWidget *l_red, *l_green, *l_blue;
-  GdkColor  *current_color;
-
-  current_color = initial_color;
 
   /* Create control bars for HildonColorPopup */
   popup_data->ctrlbar_red   = hildon_controlbar_new (); 
@@ -108,9 +111,9 @@ hildon_color_popup_new(GtkWindow *parent, GdkColor *initial_color,
                                HILDON_COLOR_BAR_WIDTH, -1); 
 
   /* Create labels for three kinds of color */
-  l_red = gtk_label_new( _("Ecdg_fi_5bit_colour_selector_red"));
-  l_green = gtk_label_new(_("Ecdg_fi_5bit_colour_selector_green"));
-  l_blue = gtk_label_new(_("Ecdg_fi_5bit_colour_selector_blue"));
+  l_red   = gtk_label_new(_("ecdg_fi_5bit_colour_selector_red"));
+  l_green = gtk_label_new(_("ecdg_fi_5bit_colour_selector_green"));
+  l_blue  = gtk_label_new(_("ecdg_fi_5bit_colour_selector_blue"));
   
   /* Position the labels to start about the same label as the controlbars */
   gtk_misc_set_alignment(GTK_MISC(l_red), 0.08f, 0.5f);
@@ -118,6 +121,7 @@ hildon_color_popup_new(GtkWindow *parent, GdkColor *initial_color,
   gtk_misc_set_alignment(GTK_MISC(l_blue), 0.08f, 0.5f);
 
   /* Add labels and control bars to the layout table */
+  gtk_table_set_col_spacing(layout, 0, HILDON_COLOR_COL_SPACING);
   gtk_table_attach_defaults(layout, l_red, 0, 1, 0, 2);
   gtk_table_attach_defaults(layout, popup_data->ctrlbar_red, 0, 1, 2, 4);
   gtk_table_attach_defaults(layout, l_green, 0, 1, 4, 6);
@@ -139,11 +143,11 @@ hildon_color_popup_new(GtkWindow *parent, GdkColor *initial_color,
 
   /* Give the initial values for each control bar */
   hildon_controlbar_set_value (HILDON_CONTROLBAR(popup_data->ctrlbar_red),   
-                                 (current_color->red >> 11)&0x1F);
+                                 (initial_color->red >> 11)&0x1F);
   hildon_controlbar_set_value (HILDON_CONTROLBAR(popup_data->ctrlbar_green),
-                                 (current_color->green >> 11)&0x1F);
+                                 (initial_color->green >> 11)&0x1F);
   hildon_controlbar_set_value (HILDON_CONTROLBAR(popup_data->ctrlbar_blue),
-                                 (current_color->blue >> 11)&0x1F);
+                                 (initial_color->blue >> 11)&0x1F);
 
   /* Register controlbar callbacks */
   g_signal_connect_swapped(popup_data->ctrlbar_red, "value-changed",
@@ -164,11 +168,12 @@ hildon_color_popup_new(GtkWindow *parent, GdkColor *initial_color,
                                        GTK_DIALOG_DESTROY_WITH_PARENT |
                                        GTK_DIALOG_NO_SEPARATOR,
                                        _("ecdg_bd_5bit_colour_selector_ok"), GTK_RESPONSE_OK,
-                                       _("Ecdg_bd_5bit_colour_selector_cancel"),
+                                       _("ecdg_bd_5bit_colour_selector_cancel"),
                                        GTK_RESPONSE_CANCEL,
                                        NULL);
 
-  gtk_dialog_set_default_response(GTK_DIALOG(popup), GTK_RESPONSE_OK);
+  /* Select-key shouldn't do anything unless dialog's button is focused */
+  gtk_dialog_set_default_response(GTK_DIALOG(popup), GTK_RESPONSE_NONE);
 
   /* Add layout table to the Vbox of the popup dialog */
   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(popup)->vbox), 
@@ -182,13 +187,11 @@ hildon_color_popup_new(GtkWindow *parent, GdkColor *initial_color,
 
 /**
  * hildon_color_popup_set_color_from_sliders:
- * @color: a pointer to #GdkColor to which the new values will be put.
- * @popup_data: a #HildonColorPopup.
+ * @color: a pointer to #GdkColor to which the new values will be put
+ * @popup_data: a #HildonColorPopup
  *
- * This function sets the values of the given #GdkColor to the values
- * in the sliders of controlbars.
- * 
- * Returns: void. 
+ * Sets the values in the given #GdkColor to the values of the
+ * controlbars.
  */
 
 void