1
/* Ekiga -- A VoIP and Video-Conferencing application
2
* Copyright (C) 2000-2007 Damien Sandras
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
* Ekiga is licensed under the GPL license and as a special exception,
20
* you have permission to link or otherwise combine this program with the
21
* programs OPAL, OpenH323 and PWLIB, and distribute the combination,
22
* without applying the requirements of the GNU GPL to the OPAL, OpenH323
23
* and PWLIB programs, as long as you do follow the requirements of the
24
* GNU GPL for all the rest of the software thus combined.
28
* dialpad.cpp - description
29
* ---------------------------
30
* begin : Thu Jan 3 2008
31
* copyright : (C) 2008 by Steve Frécinaux
32
* description : Dial pad widget.
37
#include <gdk/gdkkeysyms.h>
42
/* Make this flag available with GTK+ 2.10 */
43
#ifndef G_PARAM_SPEC_STATIC_STRINGS
44
#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
54
/* Translators: the following strings are letters that stand on mobile phone
57
static const struct const_key_info keys_info[] = {
58
{ "1", "", GDK_KP_1 },
59
{ "2", N_("abc"), GDK_KP_2 },
60
{ "3", N_("def"), GDK_KP_3 },
61
{ "4", N_("ghi"), GDK_KP_4 },
62
{ "5", N_("jkl"), GDK_KP_5 },
63
{ "6", N_("mno"), GDK_KP_6 },
64
{ "7", N_("pqrs"), GDK_KP_7 },
65
{ "8", N_("tuv"), GDK_KP_8 },
66
{ "9", N_("wxyz"), GDK_KP_9 },
67
{ "*", "", GDK_KP_Multiply },
68
{ "0", "", GDK_KP_0 },
69
{ "#", "", GDK_numbersign }
72
struct _EkigaDialpadPrivate
74
GtkAccelGroup *accel_group;
75
GtkWidget *buttons[G_N_ELEMENTS (keys_info)];
84
static guint ekiga_dialpad_signals[LAST_SIGNAL];
92
G_DEFINE_TYPE (EkigaDialpad, ekiga_dialpad, GTK_TYPE_TABLE);
95
ekiga_dialpad_get_property (GObject *object,
100
EkigaDialpad *dialpad = EKIGA_DIALPAD (object);
103
case PROP_ACCEL_GROUP:
104
g_value_set_object (value, dialpad->priv->accel_group);
107
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
113
ekiga_dialpad_set_property (GObject *object,
118
EkigaDialpad *dialpad = EKIGA_DIALPAD (object);
121
case PROP_ACCEL_GROUP:
122
dialpad->priv->accel_group = GTK_ACCEL_GROUP (g_value_get_object (value));
123
g_object_ref (dialpad->priv->accel_group);
126
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
132
on_dialpad_button_clicked (GtkButton *button,
133
EkigaDialpad *dialpad)
137
for (i = 0; i < G_N_ELEMENTS (keys_info); i++) {
138
if (GTK_WIDGET (button) == dialpad->priv->buttons[i]) {
139
g_signal_emit (dialpad, ekiga_dialpad_signals[BUTTON_CLICKED], 0,
140
keys_info[i].number);
145
g_return_if_reached ();
149
ekiga_dialpad_init (EkigaDialpad *dialpad)
153
dialpad->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialpad,
155
EkigaDialpadPrivate);
157
gtk_table_set_col_spacings (GTK_TABLE (dialpad), 2);
158
gtk_table_set_row_spacings (GTK_TABLE (dialpad), 2);
159
gtk_table_set_homogeneous (GTK_TABLE (dialpad), true);
161
/* Create the buttons */
162
for (i = 0; i < G_N_ELEMENTS (keys_info); i++) {
167
GtkWidget *alignment;
169
box = gtk_hbox_new (FALSE, 2);
171
label = gtk_label_new (keys_info[i].number);
172
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
173
gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
175
label = gtk_label_new (NULL);
176
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
178
if (strlen (keys_info [i].letters) > 0) {
179
text = g_strdup_printf ("<sub><span size=\"small\">%s</span></sub>",
180
_(keys_info [i].letters));
181
gtk_label_set_markup (GTK_LABEL (label), text);
184
gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0);
186
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
187
gtk_container_add (GTK_CONTAINER (alignment), box);
189
button = gtk_button_new ();
190
gtk_container_set_border_width (GTK_CONTAINER (button), 0);
191
gtk_container_add (GTK_CONTAINER (button), alignment);
193
dialpad->priv->buttons[i] = button;
195
gtk_table_attach (GTK_TABLE (dialpad), button,
198
(GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
199
(GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
202
g_signal_connect (button, "clicked",
203
G_CALLBACK (on_dialpad_button_clicked), dialpad);
208
ekiga_dialpad_constructor (GType type,
209
guint n_construct_properties,
210
GObjectConstructParam *construct_properties)
212
GObjectClass *parent_class;
213
EkigaDialpad *dialpad;
215
/* Invoke parent constructor. */
216
parent_class = G_OBJECT_CLASS (ekiga_dialpad_parent_class);
217
dialpad = EKIGA_DIALPAD (parent_class->constructor (type,
218
n_construct_properties,
219
construct_properties));
221
/* The construct properties have been set -> we can use them (similar to
222
* object_class->construcor which was not available in gtk 2.10) */
223
if (dialpad->priv->accel_group != NULL) {
225
for (i = 0; i < G_N_ELEMENTS (keys_info); i++) {
226
gtk_widget_add_accelerator (dialpad->priv->buttons[i],
228
dialpad->priv->accel_group,
230
(GdkModifierType) 0, (GtkAccelFlags) 0);
234
return G_OBJECT (dialpad);
238
ekiga_dialpad_finalize (GObject *object)
240
EkigaDialpad *dialpad = EKIGA_DIALPAD (object);
242
if (dialpad->priv->accel_group != NULL)
243
g_object_unref (dialpad->priv->accel_group);
245
G_OBJECT_CLASS (ekiga_dialpad_parent_class)->finalize (object);
249
ekiga_dialpad_class_init (EkigaDialpadClass *klass)
251
GType the_type = G_TYPE_FROM_CLASS (klass);
252
GObjectClass *object_class = G_OBJECT_CLASS (klass);
254
object_class->constructor = ekiga_dialpad_constructor;
255
object_class->finalize = ekiga_dialpad_finalize;
256
object_class->get_property = ekiga_dialpad_get_property;
257
object_class->set_property = ekiga_dialpad_set_property;
259
g_object_class_install_property (object_class,
261
g_param_spec_object ("accel-group",
264
GTK_TYPE_ACCEL_GROUP,
265
(GParamFlags) (G_PARAM_READWRITE |
266
G_PARAM_CONSTRUCT_ONLY |
267
G_PARAM_STATIC_STRINGS)));
269
ekiga_dialpad_signals[BUTTON_CLICKED] =
270
g_signal_new ("button-clicked", the_type,
272
G_STRUCT_OFFSET (EkigaDialpadClass, button_clicked),
274
g_cclosure_marshal_VOID__STRING,
277
G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
279
g_type_class_add_private (klass, sizeof (EkigaDialpadPrivate));
283
ekiga_dialpad_get_button_code (EkigaDialpad * /* dialpad */,
287
for (i = 0; i < G_N_ELEMENTS (keys_info); i++)
288
if (keys_info[i].number[0] == number)
289
return keys_info[i].code;
293
GtkWidget *ekiga_dialpad_new (GtkAccelGroup *accel_group)
297
if (accel_group == NULL)
298
obj = g_object_new (EKIGA_TYPE_DIALPAD, NULL);
300
obj = g_object_new (EKIGA_TYPE_DIALPAD, "accel-group", accel_group, NULL);
302
return GTK_WIDGET (obj);
305
/* ex:set ts=2 sw=2 et: */