2009-03-24 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-color-chooser.c
index 436cd6b..acbf971 100644 (file)
@@ -4,12 +4,12 @@
  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
  *
  * Author: Kuisma Salonen <kuisma.salonen@nokia.com>
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
  * as published by the Free Software Foundation; version 2.1 of
- * the License.
+ * the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -25,7 +25,7 @@
 
 /**
  * SECTION:hildon-color-chooser
- * @short_description: A widget used to select a color from an HSV colorspace
+ * @short_description: A widget used to select a color from an HSV colorspace.
  * @see_also: #HildonColorChooserDialog
  *
  * HildonColorChooser is a widget that displays an HSV colorspace. 
@@ -37,7 +37,8 @@
  * 
  */
 
-#include                                        <gtk/gtk.h>
+#undef                                          HILDON_DISABLE_DEPRECATED
+
 #include                                        "hildon-color-chooser.h"
 #include                                        "hildon-color-chooser-private.h"
 
@@ -73,6 +74,9 @@ hildon_color_chooser_size_allocate              (GtkWidget *widget,
 static void
 hildon_color_chooser_realize                    (GtkWidget *widget);
 
+static void
+hildon_color_chooser_unrealize                  (GtkWidget *widget);
+
 static void 
 hildon_color_chooser_map                        (GtkWidget *widget);
 
@@ -262,6 +266,7 @@ hildon_color_chooser_class_init                 (HildonColorChooserClass *klass)
     widget_class->size_request          = hildon_color_chooser_size_request;
     widget_class->size_allocate         = hildon_color_chooser_size_allocate;
     widget_class->realize               = hildon_color_chooser_realize;
+    widget_class->unrealize             = hildon_color_chooser_unrealize;
     widget_class->map                   = hildon_color_chooser_map;
     widget_class->unmap                 = hildon_color_chooser_unmap;
     widget_class->expose_event          = hildon_color_chooser_expose;
@@ -270,18 +275,25 @@ hildon_color_chooser_class_init                 (HildonColorChooserClass *klass)
     widget_class->motion_notify_event   = hildon_color_chooser_pointer_motion;
 
     gtk_widget_class_install_style_property (widget_class,
-            g_param_spec_boxed ("inner_size",
-                "Inner sizes",
-                "Sizes of SV plane, H bar and spacing",
-                GTK_TYPE_BORDER,
-                G_PARAM_READABLE));
+                                             g_param_spec_boxed ("inner_size",
+                                                                 "Inner sizes",
+                                                                 "Sizes of SV plane, H bar and spacing",
+                                                                 GTK_TYPE_BORDER,
+                                                                 G_PARAM_READABLE));
 
     gtk_widget_class_install_style_property (widget_class,
-            g_param_spec_boxed ("graphic_border",
-                "Graphical borders",
-                "Size of graphical border",
-                GTK_TYPE_BORDER,
-                G_PARAM_READABLE));
+                                             g_param_spec_boxed ("outer_border",
+                                                                 "Outer border",
+                                                                 "The outer border for the chooser",
+                                                                 GTK_TYPE_BORDER,
+                                                                 G_PARAM_READABLE));
+
+    gtk_widget_class_install_style_property (widget_class,
+                                             g_param_spec_boxed ("graphic_border",
+                                                                 "Graphical borders",
+                                                                 "Size of graphical border",
+                                                                 GTK_TYPE_BORDER,
+                                                                 G_PARAM_READABLE));
 
     /**
      * HildonColorChooser:color:
@@ -371,7 +383,6 @@ hildon_color_chooser_size_allocate              (GtkWidget *widget,
     }
 }
 
-
 static void
 hildon_color_chooser_realize                    (GtkWidget *widget)
 {
@@ -404,11 +415,24 @@ hildon_color_chooser_realize                    (GtkWidget *widget)
 
 
     gdk_window_set_user_data (priv->event_window, widget);
-    widget->window = gtk_widget_get_parent_window (widget);
 
-    widget->style = gtk_style_attach (widget->style, widget->window);
+    GTK_WIDGET_CLASS (parent_class)->realize (widget);
+}
+
+static void
+hildon_color_chooser_unrealize                  (GtkWidget *widget)
+{
+    HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget);
+
+    g_assert (priv);
+
+    if (priv->event_window) {
+       gdk_window_set_user_data (priv->event_window, NULL);
+       gdk_window_destroy (priv->event_window);
+       priv->event_window = NULL;
+    }
 
-    GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+    GTK_WIDGET_CLASS(parent_class)->unrealize(widget);
 }
 
 static void 
@@ -752,7 +776,7 @@ init_borders                                    (GtkWidget *w,
 
     if (tb) {
         *inner = *tb;
-        g_free (tb);
+        gtk_border_free (tb);
     } else {
         inner->left = 64;
         inner->right = 64;
@@ -771,15 +795,16 @@ init_borders                                    (GtkWidget *w,
  * @color: a color to be set
  *
  * Sets the color selected in the widget.
+ * Will move the crosshair pointer to indicate the passed color.
  */
 void 
-hildon_color_chooser_set_color                  (HildonColorChooser *sel, 
+hildon_color_chooser_set_color                  (HildonColorChooser *chooser, 
                                                  GdkColor *color)
 {
     unsigned short hue, sat, val;
     unsigned long min, max;
     signed long tmp, diff;
-    HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel);
+    HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (chooser);
 
     g_assert (priv);
 
@@ -815,8 +840,8 @@ hildon_color_chooser_set_color                  (HildonColorChooser *sel,
     priv->currsat = sat;
     priv->currval = val;
 
-    inline_limited_expose (sel);
-    g_signal_emit (sel, color_chooser_signals[COLOR_CHANGED], 0);
+    inline_limited_expose (chooser);
+    g_signal_emit (chooser, color_chooser_signals[COLOR_CHANGED], 0);
 }
 
 inline void
@@ -1244,19 +1269,26 @@ hildon_color_chooser_expose_timer               (gpointer data)
     return FALSE;
 }
 
-/* FIXME Missing documentation */
+/**
+ * hildon_color_chooser_get_color:
+ * @chooser: a #HildonColorChooser
+ * @color: a color structure to fill with the currently selected color
+ *
+ * Retrives the currently selected color in the chooser.
+ *
+ */
 void
-hildon_color_chooser_get_color                  (HildonColorChooser *sel, 
+hildon_color_chooser_get_color                  (HildonColorChooser *chooser, 
                                                  GdkColor *color)
 {
     HildonColorChooserPrivate *priv;
     GdkVisual *system_visual = gdk_visual_get_system ();
     unsigned long rgb[3], rgb2[3];
 
-    g_return_if_fail (HILDON_IS_COLOR_CHOOSER (sel));
+    g_return_if_fail (HILDON_IS_COLOR_CHOOSER (chooser));
     g_return_if_fail (color != NULL);
 
-    priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel);
+    priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (chooser);
     g_assert (priv);
 
     inline_h2rgb (priv->currhue, rgb);
@@ -1314,9 +1346,9 @@ hildon_color_chooser_get_property               (GObject *object,
     {
 
         case PROP_COLOR: {
-            GdkColor *color = g_new (GdkColor, 1);
-            hildon_color_chooser_get_color ((HildonColorChooser *) object, color);
-            g_value_take_boxed (value, color);
+            GdkColor color;
+            hildon_color_chooser_get_color ((HildonColorChooser *) object, &color);
+            g_value_set_boxed (value, &color);
             } break;
 
         default: