From 5157d53fef688ef5e766448854b8dbf4b6f8b45b Mon Sep 17 00:00:00 2001 From: Michael Dominic Kostrzewa Date: Thu, 8 Mar 2007 11:20:57 +0000 Subject: [PATCH] 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. --- ChangeLog.2 | 12 ++++++ configure.ac | 2 +- examples/Makefile.am | 8 +++- examples/hildon-color-pop-example.c | 79 +++++++++++++++++++++++++++++++++++ src/hildon-color-button-private.h | 1 + src/hildon-color-button.c | 67 ++++++++++++++++++++++++++++- src/hildon-color-button.h | 6 +++ 7 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 examples/hildon-color-pop-example.c diff --git a/ChangeLog.2 b/ChangeLog.2 index 1d3f064..4dd8493 100644 --- a/ChangeLog.2 +++ b/ChangeLog.2 @@ -1,3 +1,15 @@ +2007-03-08 Michael Dominic Kostrzewa + + * 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 * src/hildon-caption.c: diff --git a/configure.ac b/configure.ac index 9eb94ae..07f918b 100644 --- a/configure.ac +++ b/configure.ac @@ -117,7 +117,7 @@ CFLAGS="$CFLAGS -DMAEMO_CHANGES" # 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) diff --git a/examples/Makefile.am b/examples/Makefile.am index ade790e..fcaff4b 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -25,7 +25,8 @@ noinst_PROGRAMS = hildon-window-example \ 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_LDADD = $(HILDON_OBJ_LIBS) 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) diff --git a/examples/hildon-color-pop-example.c b/examples/hildon-color-pop-example.c new file mode 100644 index 0000000..ebe33a7 --- /dev/null +++ b/examples/hildon-color-pop-example.c @@ -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 + * + * 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 +#include +#include +#include +#include "hildon.h" +#include + +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; +} + + diff --git a/src/hildon-color-button-private.h b/src/hildon-color-button-private.h index 430ad59..31a0b38 100644 --- a/src/hildon-color-button-private.h +++ b/src/hildon-color-button-private.h @@ -34,6 +34,7 @@ typedef struct _HildonColorButtonPrivate Hildon struct _HildonColorButtonPrivate { GtkWidget *dialog; + gboolean popped; GdkColor color; GdkGC *gc; diff --git a/src/hildon-color-button.c b/src/hildon-color-button.c index 2c1b2a5..249dcc3 100644 --- a/src/hildon-color-button.c +++ b/src/hildon-color-button.c @@ -86,7 +86,8 @@ enum { PROP_0, - PROP_COLOR + PROP_COLOR, + PROP_IS_POPPED }; static void @@ -210,6 +211,18 @@ hildon_color_button_class_init (HildonColorButtonClass *klass) 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 @@ hildon_color_button_init (HildonColorButton *cb) priv->dialog = NULL; priv->gc = NULL; + priv->popped = FALSE; gtk_widget_push_composite_child (); @@ -350,7 +364,7 @@ hildon_color_button_finalize (GObject *object) if (priv->dialog) { - gtk_widget_destroy(priv->dialog); + gtk_widget_destroy (priv->dialog); priv->dialog = NULL; } @@ -419,6 +433,7 @@ hildon_color_button_clicked (GtkButton *button) 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 @@ hildon_color_button_clicked (GtkButton *button) } gtk_widget_hide (GTK_WIDGET(cs_dialog)); + priv->popped = FALSE; } /* Popup a color selector dialog on hardkey Select press. @@ -488,6 +504,9 @@ hildon_color_button_get_property (GObject *object, 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_set_color (HildonColorButton *button, } /** + * 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 diff --git a/src/hildon-color-button.h b/src/hildon-color-button.h index 6895f5e..7aa4dd3 100644 --- a/src/hildon-color-button.h +++ b/src/hildon-color-button.h @@ -82,6 +82,12 @@ void 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__ */ -- 1.7.9.5