2006-09-11 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / hildon-widgets / hildon-color-button.c
index 271ac57..bc9048a 100644 (file)
@@ -1,14 +1,14 @@
 /*
  * This file is part of hildon-libs
  *
- * Copyright (C) 2005 Nokia Corporation.
+ * Copyright (C) 2005, 2006 Nokia Corporation.
  *
- * Contact: Luc Pionchon <luc.pionchon@nokia.com>
+ * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@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; either version 2.1 of
- * the License, or (at your option) any later version.
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License.
  *
  * This library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 
 /**
  * SECTION:hildon-color-button
- * @short_description: A widget to open HildonColorSelector
- * @see_also: #HildonColorSelector, #HildonColorPopup
+ * @short_description: A widget to open HildonColorChooserDialog
+ * @see_also: #HildonColorChooserDialog, #HildonColorPopup
  *
- * HildonColorButton is a widget to open a HildonColorSelector.
+ * HildonColorButton is a widget to open a HildonColorChooserDialog.
  * The selected color is shown in the button.
  * The selected color is a property of the button.
  * The property name is "color" and its type is GtkColor.
 #include <gtk/gtkalignment.h>
 #include <gtk/gtkdrawingarea.h>
 #include <gtk/gtksignal.h>
+#include <gdk/gdkkeysyms.h>
+#include <hildon-widgets/hildon-defines.h>
 
 #include "hildon-color-button.h"
-#include "hildon-color-selector.h"
+#include "hildon-color-chooser-dialog.h"
 
 #define HILDON_COLOR_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE\
               ((obj), HILDON_TYPE_COLOR_BUTTON, HildonColorButtonPrivate))
 
 #define COLOR_FILLED_HEIGHT 22
-#define COLOR_FILLED_WIDTH 22
-#define COLOR_BUTTON_WIDTH 48
-#define COLOR_BUTTON_HEIGHT 40
+#define COLOR_FILLED_WIDTH  22
+
+#define COLOR_BUTTON_WIDTH  52
+#define COLOR_BUTTON_HEIGHT 48
 
 /* the outer border color */
 #define OUTER_BORDER_RED   0
@@ -60,7 +63,7 @@
 #define INNER_BORDER_RED   65535
 #define INNER_BORDER_BLUE  65535
 #define INNER_BORDER_GREEN 65535
-#define INNER_BORDER_THICKNESS 1
+#define INNER_BORDER_THICKNESS 2
 
 struct _HildonColorButtonPrivate 
 {
@@ -95,6 +98,10 @@ static void
 hildon_color_button_unrealize(GtkWidget *widget);
 static void
 hildon_color_button_clicked(GtkButton *button);
+static gboolean
+hildon_color_button_key_pressed(GtkWidget * button, 
+                                GdkEventKey * event,
+                                gpointer data);
 static gint
 hildon_color_field_expose_event(GtkWidget *widget, GdkEventExpose *event,
                                 HildonColorButton *cb);
@@ -219,8 +226,8 @@ hildon_color_field_expose_event(GtkWidget *widget, GdkEventExpose *event,
             TRUE,
             event->area.x + (INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS),
             event->area.y + (INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS),
-            event->area.height - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2),
-            event->area.width  - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2));
+            event->area.width  - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2),
+            event->area.height - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2));
 
     return FALSE;
 }
@@ -253,6 +260,10 @@ hildon_color_button_init(HildonColorButton *cb)
   g_signal_connect(drawing_area, "expose-event",
                    G_CALLBACK(hildon_color_field_expose_event), cb);
 
+  /* Connect to callback function for key press event */
+  g_signal_connect(G_OBJECT(cb), "key-press-event",
+                  G_CALLBACK(hildon_color_button_key_pressed), cb);
+  
   /* packing */
   gtk_container_add(GTK_CONTAINER(align), drawing_area);
   gtk_container_add(GTK_CONTAINER(cb), align);
@@ -313,33 +324,54 @@ static void
 hildon_color_button_clicked(GtkButton *button)
 {
   HildonColorButton *cb = HILDON_COLOR_BUTTON(button);
-  HildonColorSelector *cs_dialog = HILDON_COLOR_SELECTOR(cb->priv->dialog);
-
+  HildonColorChooserDialog *cs_dialog = HILDON_COLOR_CHOOSER_DIALOG(cb->priv->dialog);
+  
   /* Popup the color selector dialog */
   if (!cs_dialog)
   {
     /* The dialog hasn't been created yet, do it. */
     GtkWidget *parent = gtk_widget_get_toplevel(GTK_WIDGET(cb));
-    cb->priv->dialog = hildon_color_selector_new(GTK_WINDOW(parent));
-    cs_dialog = HILDON_COLOR_SELECTOR(cb->priv->dialog);
-    
+    cb->priv->dialog = hildon_color_chooser_dialog_new(GTK_WINDOW(parent));
+    cs_dialog = HILDON_COLOR_CHOOSER_DIALOG(cb->priv->dialog);
     if (parent)
       gtk_window_set_transient_for(GTK_WINDOW(cs_dialog), GTK_WINDOW(parent));
   }
-  
+
   /* Set the initial color for the color selector dialog */
-  hildon_color_selector_set_color(cs_dialog, &cb->priv->color);
-  
+  hildon_color_chooser_dialog_set_color(cs_dialog, &cb->priv->color);
   /* Update the color for color button if selection was made */
   if (gtk_dialog_run(GTK_DIALOG(cs_dialog)) == GTK_RESPONSE_OK)
   {
-    cb->priv->color = *hildon_color_selector_get_color(cs_dialog);
+    hildon_color_chooser_dialog_get_color(cs_dialog, &cb->priv->color);
     hildon_color_button_set_color( HILDON_COLOR_BUTTON( button ), 
             &(cb->priv->color) );
+  } else 
+  {
+          // FIXME: Fixes 39778, but I think the bug lies elsewhere
+          gtk_widget_queue_draw (GTK_WIDGET (button)); 
   }
+
   gtk_widget_hide(GTK_WIDGET(cs_dialog));
 }
 
+/* Popup a color selector dialog on hardkey Select press */
+static gboolean
+hildon_color_button_key_pressed(GtkWidget * button, 
+                                GdkEventKey * event,
+                                gpointer data)
+{
+  g_return_val_if_fail (HILDON_IS_COLOR_BUTTON(button), FALSE);
+
+  if (event->keyval == HILDON_HARDKEY_SELECT)
+  {
+    hildon_color_button_clicked(GTK_BUTTON(button));
+    return TRUE;
+  }
+  
+  return FALSE;
+}
+
 /* Set_property function for HildonColorButtonClass initialization */
 static void
 hildon_color_button_set_property(GObject *object, guint param_id,