2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser Public License as published by
8 * the Free Software Foundation; version 2 of the license.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser Public License for more details.
17 #include "hildon-picker-button.h"
18 #include "hildon-picker-dialog.h"
20 G_DEFINE_TYPE (HildonPickerButton, hildon_picker_button, HILDON_TYPE_BUTTON)
22 #define GET_PRIVATE(o) \
23 (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_PICKER_BUTTON, HildonPickerButtonPrivate))
25 typedef struct _HildonPickerButtonPrivate HildonPickerButtonPrivate;
27 struct _HildonPickerButtonPrivate
45 static guint picker_button_signals[LAST_SIGNAL] = { 0 };
48 hildon_picker_button_get_property (GObject * object, guint property_id,
49 GValue * value, GParamSpec * pspec)
51 switch (property_id) {
53 g_value_set_object (value,
54 hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (object)));
57 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
62 hildon_picker_button_set_property (GObject * object, guint property_id,
63 const GValue * value, GParamSpec * pspec)
65 switch (property_id) {
67 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (object),
68 g_value_get_object (value));
71 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76 hildon_picker_button_clicked (GtkButton * button)
79 HildonPickerButtonPrivate *priv;
82 priv = GET_PRIVATE (HILDON_PICKER_BUTTON (button));
84 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (priv->selector));
86 /* Create the dialog if it doesn't exist already. */
88 parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
89 if (GTK_WIDGET_TOPLEVEL (parent)) {
90 priv->dialog = hildon_picker_dialog_new (GTK_WINDOW (parent));
92 priv->dialog = hildon_picker_dialog_new (NULL);
95 hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (priv->dialog),
96 HILDON_TOUCH_SELECTOR (priv->selector));
98 gtk_window_set_modal (GTK_WINDOW (priv->dialog),
99 gtk_window_get_modal (GTK_WINDOW (parent)));
100 gtk_window_set_title (GTK_WINDOW (priv->dialog),
101 hildon_button_get_title (HILDON_BUTTON (button)));
104 response = gtk_dialog_run (GTK_DIALOG (priv->dialog));
106 case GTK_RESPONSE_OK:
107 hildon_button_set_value (HILDON_BUTTON (button),
108 hildon_touch_selector_get_current_text
109 (HILDON_TOUCH_SELECTOR (priv->selector)));
110 g_signal_emit (HILDON_PICKER_BUTTON (button),
111 picker_button_signals[VALUE_CHANGED], 0);
114 gtk_widget_hide (priv->dialog);
118 hildon_picker_button_class_init (HildonPickerButtonClass * klass)
120 GObjectClass *object_class = G_OBJECT_CLASS (klass);
121 GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
123 g_type_class_add_private (klass, sizeof (HildonPickerButtonPrivate));
125 object_class->get_property = hildon_picker_button_get_property;
126 object_class->set_property = hildon_picker_button_set_property;
128 button_class->clicked = hildon_picker_button_clicked;
130 g_object_class_install_property (object_class,
132 g_param_spec_object ("touch-selector",
133 "HildonTouchSelector widget",
134 "HildonTouchSelector widget to be launched on button clicked",
135 HILDON_TYPE_TOUCH_SELECTOR,
138 picker_button_signals[VALUE_CHANGED] =
139 g_signal_new ("value-changed",
140 G_TYPE_FROM_CLASS (klass),
141 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
144 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
148 hildon_picker_button_init (HildonPickerButton * self)
150 HildonPickerButtonPrivate *priv;
152 priv = GET_PRIVATE (self);
155 priv->selector = NULL;
159 hildon_picker_button_new (HildonSizeType size,
160 HildonButtonArrangement arrangement)
164 button = g_object_new (HILDON_TYPE_PICKER_BUTTON,
165 "arrangement", arrangement, "size-flags", size, NULL);
171 hildon_picker_button_set_selector (HildonPickerButton * button,
172 HildonTouchSelector * selector)
174 HildonPickerButtonPrivate *priv;
176 g_return_if_fail (HILDON_IS_PICKER_BUTTON (button));
177 g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
179 priv = GET_PRIVATE (button);
181 priv->selector = g_object_ref (selector);
184 HildonTouchSelector *
185 hildon_picker_button_get_selector (HildonPickerButton * button)
187 HildonPickerButtonPrivate *priv;
189 g_return_val_if_fail (HILDON_IS_PICKER_BUTTON (button), NULL);
191 priv = GET_PRIVATE (button);
193 return HILDON_TOUCH_SELECTOR (priv->selector);