6c3ff3d0028477bff4ecca9f27142a76384e5399
[hildon] / src / hildon-dialog.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Karl Lattimer <karl.lattimer@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 /**
26  * SECTION:hildon-dialog
27  * @short_description: Widget representing a popup window in the Hildon framework.
28  * @see_also: #HildonCodeDialog, #HildonColorChooserDialog, #HildonFontSelectionDialog, #HildonGetPasswordDialog, #HildonLoginDialog, #HildonSetPasswordDialog, #HildonSortDialog, #HildonWizardDialog
29  *
30  * #HildonDialog is a GTK widget which represent a popup window in the
31  * Hildon framework. It is derived from #GtkDialog and provides additional
32  * commodities specific to the Hildon framework.
33  *
34  * As of hildon 2.2, #HildonDialog has been deprecated in favor of #GtkDialog.
35  *
36  * <example>
37  * <title>Simple <structname>HildonDialog</structname> usage</title>
38  * <programlisting>
39  * void quick_message (gchar *message)
40  * {
41  * <!-- -->
42  *     GtkWidget *dialog, *label;
43  * <!-- -->
44  *     dialog = hildon_dialog_new ();
45  *     label = gtk_label_new (message);
46  * <!-- -->
47  *     g_signal_connect_swapped (dialog,
48  *                               "response",
49  *                               G_CALLBACK (gtk_widget_destroy),
50  *                               dialog);
51  * <!-- -->
52  *     gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
53  *                        label);
54  *     gtk_widget_show_all (dialog);
55  * <!-- -->
56  * }
57  * </programlisting>
58  * </example>
59  */
60
61 #undef                                          HILDON_DISABLE_DEPRECATED
62
63 #include                                        "hildon-dialog.h"
64 #include                                        "hildon-gtk.h"
65
66 G_DEFINE_TYPE (HildonDialog, hildon_dialog, GTK_TYPE_DIALOG);
67
68 static void
69 hildon_dialog_class_init                        (HildonDialogClass *dialog_class)
70 {
71 }
72
73 static void
74 hildon_dialog_init                              (HildonDialog *self)
75 {
76 }
77
78 /**
79  * hildon_dialog_new:
80  *
81  * Creates a new #HildonDialog widget
82  *
83  * Returns: the newly created #HildonDialog
84  */
85 GtkWidget*
86 hildon_dialog_new                               (void)
87 {
88     GtkWidget *self = g_object_new (HILDON_TYPE_DIALOG, NULL);
89
90     return self;
91 }
92
93 /**
94  * hildon_dialog_new_with_buttons:
95  * @title: Title of the dialog, or %NULL
96  * @parent: Transient parent of the dialog, or %NULL
97  * @flags: from #GtkDialogFlags
98  * @first_button_text: stock ID or text to go in first button, or %NULL
99  * @Varargs: response ID for first button, then additional buttons, ending with %NULL
100  *
101  * Creates a new #HildonDialog. See gtk_dialog_new_with_buttons() for
102  * more information.
103  *
104  * Return value: a new #HildonDialog
105  */
106 GtkWidget*
107 hildon_dialog_new_with_buttons                  (const gchar *title,
108                                                  GtkWindow *parent,
109                                                  GtkDialogFlags flags,
110                                                  const gchar *first_button_text,
111                                                  ...)
112 {
113     GtkWidget *dialog;
114
115     dialog = g_object_new (HILDON_TYPE_DIALOG, NULL);
116
117     /* This code is copied from gtk_dialog_new_empty(), as it's a
118      * private function that we cannot use here */
119     if (title)
120         gtk_window_set_title (GTK_WINDOW (dialog), title);
121
122     if (parent)
123         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
124
125     if (flags & GTK_DIALOG_MODAL)
126         gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
127
128     if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
129         gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
130
131     if (flags & GTK_DIALOG_NO_SEPARATOR)
132         gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
133
134     /* This is almost copied from gtk_dialog_add_buttons_valist() */
135     if (first_button_text != NULL) {
136         va_list args;
137         const gchar *text;
138         gint response_id;
139
140         va_start (args, first_button_text);
141         text = first_button_text;
142         response_id = va_arg (args, gint);
143
144         while (text != NULL) {
145             hildon_dialog_add_button (HILDON_DIALOG (dialog), text, response_id);
146
147             text = va_arg (args, gchar*);
148             if (text == NULL)
149                 break;
150             response_id = va_arg (args, int);
151         }
152         va_end (args);
153     }
154
155     return dialog;
156 }
157
158 /**
159  * hildon_dialog_add_button:
160  * @dialog: a #HildonDialog
161  * @button_text: text of the button, or stock ID
162  * @response_id: response ID for the button.
163  *
164  * Adds a button to the dialog. Works exactly like
165  * gtk_dialog_add_button(), the only difference being that the button
166  * has finger size.
167  *
168  * Returns: the button widget that was added
169  */
170 GtkWidget *
171 hildon_dialog_add_button                        (HildonDialog *dialog,
172                                                  const gchar  *button_text,
173                                                  gint          response_id)
174 {
175     GtkWidget *button;
176     button = gtk_dialog_add_button (GTK_DIALOG (dialog), button_text, response_id);
177     return button;
178 }
179
180 /**
181  * hildon_dialog_add_buttons:
182  * @dialog: a #HildonDialog
183  * @first_button_text: text of the button, or stock ID
184  * @Varargs: response ID for first button, then more text-response_id pairs
185  *
186  * Adds several buttons to the dialog. Works exactly like
187  * gtk_dialog_add_buttons(), the only difference being that the
188  * buttons have finger size.
189  */
190 void
191 hildon_dialog_add_buttons                       (HildonDialog *dialog,
192                                                  const gchar  *first_button_text,
193                                                  ...)
194 {
195     va_list args;
196     const gchar *text;
197     gint response_id;
198
199     va_start (args, first_button_text);
200     text = first_button_text;
201     response_id = va_arg (args, gint);
202
203     while (text != NULL) {
204         hildon_dialog_add_button (HILDON_DIALOG (dialog), text, response_id);
205
206         text = va_arg (args, gchar*);
207         if (text == NULL)
208             break;
209         response_id = va_arg (args, int);
210     }
211
212     va_end (args);
213 }
214