[maemo-commits] [maemo-commits] r10462 - in projects/haf/branches/hildon-libs/hildon-1: . examples src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Mar 8 13:20:59 EET 2007
Author: mdk
Date: 2007-03-08 13:20:57 +0200 (Thu, 08 Mar 2007)
New Revision: 10462

Added:
   projects/haf/branches/hildon-libs/hildon-1/examples/hildon-color-pop-example.c
Modified:
   projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2
   projects/haf/branches/hildon-libs/hildon-1/configure.ac
   projects/haf/branches/hildon-libs/hildon-1/examples/Makefile.am
   projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button-private.h
   projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.c
   projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.h
Log:
Adding a property 'is-popped' and some functions to pop-up the color selection dialog.
Adding an example that pops-up the dialog from another thread.


Modified: projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2	2007-03-08 09:16:50 UTC (rev 10461)
+++ projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2	2007-03-08 11:20:57 UTC (rev 10462)
@@ -1,3 +1,15 @@
+2007-03-08  Michael Dominic Kostrzewa  <michael.kostrzewa at nokia.com> 
+
+	* src/hildon-color-button-private.h:
+	* src/hildon-color-button.c:
+	* src/hildon-color-button.h: Adding a property 'is-popped' and some
+	functions to pop-up the color selection dialog. 
+
+	* configure.ac:
+	* examples/Makefile.am:
+	* examples/hildon-color-pop-example.c:  An example that pops-up the
+	dialog from another thread.
+
 2007-03-07  Michael Dominic Kostrzewa  <michael.kostrzewa at nokia.com> 
 
 	* src/hildon-caption.c:

Modified: projects/haf/branches/hildon-libs/hildon-1/configure.ac
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/configure.ac	2007-03-08 09:16:50 UTC (rev 10461)
+++ projects/haf/branches/hildon-libs/hildon-1/configure.ac	2007-03-08 11:20:57 UTC (rev 10462)
@@ -117,7 +117,7 @@
 # includes all the low-level flags
 # FIXME Add esd and gconf flags
 HILDON_OBJ_CFLAGS="\$(CFLAGS) \$(GTK_CFLAGS) \$(CHECK_CFLAGS) \$(GCONF_CFLAGS) -I\$(top_builddir)/src/"
-HILDON_OBJ_LIBS="\$(top_builddir)/src/libhildon_\$(PACKAGE_VERSION_MAJOR).la \$(GTK_LIBS) \$(GCONF_LIBS) \$(CHECK_LIBS)"
+HILDON_OBJ_LIBS="\$(top_builddir)/src/libhildon_\$(PACKAGE_VERSION_MAJOR).la \$(GTK_LIBS) \$(GCONF_LIBS) \$(CHECK_LIBS) `pkg-config --libs gthread-2.0`"
 AC_SUBST(HILDON_OBJ_CFLAGS)
 AC_SUBST(HILDON_OBJ_LIBS)
 

Modified: projects/haf/branches/hildon-libs/hildon-1/examples/Makefile.am
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/examples/Makefile.am	2007-03-08 09:16:50 UTC (rev 10461)
+++ projects/haf/branches/hildon-libs/hildon-1/examples/Makefile.am	2007-03-08 11:20:57 UTC (rev 10462)
@@ -25,7 +25,8 @@
 					  hildon-hvolumebar-example		\
 					  hildon-lookup-example			\
 					  hildon-number-editor-example		\
-					  hildon-scrolled-window-example
+					  hildon-scrolled-window-example	\
+					  hildon-color-pop-example
 
 # HIldon window
 hildon_window_example_LDADD		= $(HILDON_OBJ_LIBS)
@@ -82,6 +83,11 @@
 hildon_color_button_example_CFLAGS	= $(HILDON_OBJ_CFLAGS)
 hildon_color_button_example_SOURCES	= hildon-color-button-example.c
 
+# Hildon color pop example
+hildon_color_pop_example_LDADD		= $(HILDON_OBJ_LIBS)
+hildon_color_pop_example_CFLAGS		= $(HILDON_OBJ_CFLAGS)
+hildon_color_pop_example_SOURCES	= hildon-color-pop-example.c
+
 # Hildon color button example
 hildon_login_dialog_example_LDADD	= $(HILDON_OBJ_LIBS)
 hildon_login_dialog_example_CFLAGS	= $(HILDON_OBJ_CFLAGS)

Added: projects/haf/branches/hildon-libs/hildon-1/examples/hildon-color-pop-example.c
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/examples/hildon-color-pop-example.c	2007-03-08 09:16:50 UTC (rev 10461)
+++ projects/haf/branches/hildon-libs/hildon-1/examples/hildon-color-pop-example.c	2007-03-08 11:20:57 UTC (rev 10462)
@@ -0,0 +1,79 @@
+/*
+ * This file is a part of hildon examples
+ *
+ * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
+ *
+ * Author: Michael Dominic Kostrzewa <michael.kostrzewa at 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.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include                                        <stdio.h>
+#include                                        <stdlib.h>
+#include                                        <glib.h>
+#include                                        <gtk/gtk.h>
+#include                                        "hildon.h"
+#include                                        <unistd.h>
+
+gpointer
+new_thread_func                                 (gpointer data);
+
+gpointer
+new_thread_func                                 (gpointer data)
+{
+        HildonColorButton *button = (HildonColorButton *) data;
+
+        sleep (3);
+
+
+        if (hildon_color_button_get_is_popped (button)) {
+                g_debug ("Dialog popped, trying to close it!");
+                hildon_color_button_pop_up (button);
+        } else {
+                g_debug ("Dialog not popped, doing nothing");
+        }
+
+        return NULL;
+}
+
+int
+main                                            (int argc, 
+                                                 char **args)
+{
+    g_thread_init (NULL);
+    gtk_init (&argc, &args);
+   
+    HildonProgram *program = hildon_program_get_instance ();
+
+    GtkWidget *window = hildon_window_new ();
+    hildon_program_add_window (program, HILDON_WINDOW (window));    
+
+    GtkWidget *button = hildon_color_button_new ();
+
+    gtk_container_set_border_width (GTK_CONTAINER (window), 6);
+    
+    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+    gtk_container_add (GTK_CONTAINER (window), button);
+    gtk_widget_show_all (GTK_WIDGET (window));
+
+    g_thread_create (new_thread_func, button, TRUE, NULL);
+    
+    gtk_main ();
+    return 0;
+}
+
+

Modified: projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button-private.h
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button-private.h	2007-03-08 09:16:50 UTC (rev 10461)
+++ projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button-private.h	2007-03-08 11:20:57 UTC (rev 10462)
@@ -34,6 +34,7 @@
 struct                                          _HildonColorButtonPrivate
 {
     GtkWidget *dialog;
+    gboolean popped;
 
     GdkColor color;
     GdkGC *gc;

Modified: projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.c
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.c	2007-03-08 09:16:50 UTC (rev 10461)
+++ projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.c	2007-03-08 11:20:57 UTC (rev 10462)
@@ -86,7 +86,8 @@
 enum 
 {
     PROP_0,
-    PROP_COLOR
+    PROP_COLOR,
+    PROP_IS_POPPED
 };
 
 static void
@@ -210,6 +211,18 @@
                 GDK_TYPE_COLOR,
                 G_PARAM_READWRITE));
 
+    /**
+     * HildonColorButton:is-popped:
+     *
+     * If the color selection dialog is currently popped-down (visible)
+     */
+    g_object_class_install_property (gobject_class, PROP_IS_POPPED,
+            g_param_spec_boolean ("is-popped",
+                "IsPopped",
+                "If the color selection dialog is popped down",
+                FALSE,
+                G_PARAM_READABLE));
+
     g_type_class_add_private (gobject_class, sizeof (HildonColorButtonPrivate));
 }
 
@@ -309,6 +322,7 @@
 
     priv->dialog = NULL;
     priv->gc = NULL;
+    priv->popped = FALSE;
 
     gtk_widget_push_composite_child ();
 
@@ -350,7 +364,7 @@
 
     if (priv->dialog)
     {
-        gtk_widget_destroy(priv->dialog);
+        gtk_widget_destroy (priv->dialog);
         priv->dialog = NULL;
     }
 
@@ -419,6 +433,7 @@
     hildon_color_chooser_dialog_set_color (cs_dialog, &priv->color);
 
     /* Update the color for color button if selection was made */
+    priv->popped = TRUE;
     if (gtk_dialog_run (GTK_DIALOG (cs_dialog)) == GTK_RESPONSE_OK)
     {
         hildon_color_chooser_dialog_get_color (cs_dialog, &priv->color);
@@ -427,6 +442,7 @@
     } 
 
     gtk_widget_hide (GTK_WIDGET(cs_dialog));
+    priv->popped = FALSE;
 }
 
 /* Popup a color selector dialog on hardkey Select press.
@@ -488,6 +504,9 @@
             g_value_set_boxed (value, &priv->color);
             break;
 
+        case PROP_IS_POPPED:
+            g_value_set_boolean (value, priv->popped);
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
             break;
@@ -542,6 +561,50 @@
 }
 
 /**
+ * hildon_color_button_get_is_popped
+ * @button: a #HildonColorButton
+ *
+ * This function checks if the color button has the color 
+ * selection dialog currently popped-down. 
+ * 
+ * Returns: TRUE if the dialog is popped-down (visible to user).
+ *
+ */
+gboolean
+hildon_color_button_get_is_popped               (HildonColorButton *button)
+{
+    HildonColorButtonPrivate *priv = NULL; 
+    g_return_val_if_fail (HILDON_IS_COLOR_BUTTON (button), FALSE);
+
+    priv = HILDON_COLOR_BUTTON_GET_PRIVATE (button);
+    g_assert (priv);
+
+    return priv->popped;
+}
+
+/**
+ * hildon_color_button_pop_up
+ * @button: a #HildonColorButton
+ *
+ * If the color selection dialog is currently popped-down (visible)
+ * it will be popped-up (hidden).
+ *
+ */
+void
+hildon_color_button_pop_up                      (HildonColorButton *button)
+{
+    HildonColorButtonPrivate *priv = NULL; 
+    g_return_if_fail (HILDON_IS_COLOR_BUTTON (button));
+
+    priv = HILDON_COLOR_BUTTON_GET_PRIVATE (button);
+    g_assert (priv);
+
+    if (priv->popped && priv->dialog) {
+        gtk_dialog_response (GTK_DIALOG (priv->dialog), GTK_RESPONSE_CANCEL);
+    }
+}
+
+/**
  * hildon_color_button_get_color:
  * @button: a #HildonColorButton
  * @color: a color #GdkColor to be fillled with the current color

Modified: projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.h
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.h	2007-03-08 09:16:50 UTC (rev 10461)
+++ projects/haf/branches/hildon-libs/hildon-1/src/hildon-color-button.h	2007-03-08 11:20:57 UTC (rev 10462)
@@ -82,6 +82,12 @@
 hildon_color_button_set_color                   (HildonColorButton *button,         
                                                  GdkColor *color);
 
+gboolean
+hildon_color_button_get_is_popped               (HildonColorButton *button);
+
+void
+hildon_color_button_pop_up                      (HildonColorButton *button);
+
 G_END_DECLS
 
 #endif                                          /* __HILDON_COLOR_BUTTON_H__ */


More information about the maemo-commits mailing list