Add HildonAppMenu::changed signal
[hildon] / hildon / 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: Rodrigo Novo <rodrigo.novo@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: A popup window in the Hildon framework.
28  * @see_also: #HildonCodeDialog, #HildonColorChooserDialog, #HildonFontSelectionDialog, #HildonGetPasswordDialog, #HildonLoginDialog, #HildonSetPasswordDialog, #HildonSortDialog, #HildonWizardDialog
29  *
30  * #HildonDialog is 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  * <note>
37  *   <para>
38  * #HildonDialog has been deprecated since Hildon 2.2 and should not
39  * be used in newly written code. See
40  * <link linkend="hildon-migrating-hildon-dialogs">Migrating Hildon Dialogs</link>
41  * section to know how to migrate this deprecated widget.
42  *   </para>
43  * </note>
44  *
45  * <example>
46  * <title>Simple <structname>HildonDialog</structname> usage</title>
47  * <programlisting>
48  * void quick_message (gchar *message)
49  * {
50  * <!-- -->
51  *     GtkWidget *dialog, *label;
52  * <!-- -->
53  *     dialog = hildon_dialog_new ();
54  *     label = gtk_label_new (message);
55  * <!-- -->
56  *     g_signal_connect_swapped (dialog,
57  *                               "response",
58  *                               G_CALLBACK (gtk_widget_destroy),
59  *                               dialog);
60  * <!-- -->
61  *     gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
62  *                        label);
63  *     gtk_widget_show_all (dialog);
64  * <!-- -->
65  * }
66  * </programlisting>
67  * </example>
68  */
69
70 #undef                                          HILDON_DISABLE_DEPRECATED
71
72 #include                                        "hildon-dialog.h"
73 #include                                        "hildon-gtk.h"
74
75 G_DEFINE_TYPE (HildonDialog, hildon_dialog, GTK_TYPE_DIALOG);
76
77 static void
78 hildon_dialog_class_init                        (HildonDialogClass *dialog_class)
79 {
80 }
81
82 static void
83 hildon_dialog_init                              (HildonDialog *self)
84 {
85 }
86
87 /**
88  * hildon_dialog_new:
89  *
90  * Creates a new #HildonDialog widget
91  *
92  * Returns: the newly created #HildonDialog
93  *
94  * Since: 2.2
95  */
96 GtkWidget*
97 hildon_dialog_new                               (void)
98 {
99     GtkWidget *self = g_object_new (HILDON_TYPE_DIALOG, NULL);
100
101     return self;
102 }
103
104 /**
105  * hildon_dialog_new_with_buttons:
106  * @title: Title of the dialog, or %NULL
107  * @parent: Transient parent of the dialog, or %NULL
108  * @flags: from #GtkDialogFlags
109  * @first_button_text: stock ID or text to go in first button, or %NULL
110  * @Varargs: response ID for first button, then additional buttons, ending with %NULL
111  *
112  * Creates a new #HildonDialog. See gtk_dialog_new_with_buttons() for
113  * more information.
114  *
115  * Return value: a new #HildonDialog
116  *
117  * Since: 2.2
118  */
119 GtkWidget*
120 hildon_dialog_new_with_buttons                  (const gchar *title,
121                                                  GtkWindow *parent,
122                                                  GtkDialogFlags flags,
123                                                  const gchar *first_button_text,
124                                                  ...)
125 {
126     GtkWidget *dialog;
127
128     dialog = g_object_new (HILDON_TYPE_DIALOG, NULL);
129
130     /* This code is copied from gtk_dialog_new_empty(), as it's a
131      * private function that we cannot use here */
132     if (title)
133         gtk_window_set_title (GTK_WINDOW (dialog), title);
134
135     if (parent)
136         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
137
138     if (flags & GTK_DIALOG_MODAL)
139         gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
140
141     if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
142         gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
143
144     if (flags & GTK_DIALOG_NO_SEPARATOR)
145         gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
146
147     /* This is almost copied from gtk_dialog_add_buttons_valist() */
148     if (first_button_text != NULL) {
149         va_list args;
150         const gchar *text;
151         gint response_id;
152
153         va_start (args, first_button_text);
154         text = first_button_text;
155         response_id = va_arg (args, gint);
156
157         while (text != NULL) {
158             hildon_dialog_add_button (HILDON_DIALOG (dialog), text, response_id);
159
160             text = va_arg (args, gchar*);
161             if (text == NULL)
162                 break;
163             response_id = va_arg (args, int);
164         }
165         va_end (args);
166     }
167
168     return dialog;
169 }
170
171 /**
172  * hildon_dialog_add_button:
173  * @dialog: a #HildonDialog
174  * @button_text: text of the button, or stock ID
175  * @response_id: response ID for the button.
176  *
177  * Adds a button to the dialog. Works exactly like
178  * gtk_dialog_add_button(), the only difference being that the button
179  * has finger size.
180  *
181  * Returns: the button widget that was added
182  *
183  * Since: 2.2
184  */
185 GtkWidget *
186 hildon_dialog_add_button                        (HildonDialog *dialog,
187                                                  const gchar  *button_text,
188                                                  gint          response_id)
189 {
190     GtkWidget *button;
191     button = gtk_dialog_add_button (GTK_DIALOG (dialog), button_text, response_id);
192     return button;
193 }
194
195 /**
196  * hildon_dialog_add_buttons:
197  * @dialog: a #HildonDialog
198  * @first_button_text: text of the button, or stock ID
199  * @Varargs: response ID for first button, then more text-response_id pairs
200  *
201  * Adds several buttons to the dialog. Works exactly like
202  * gtk_dialog_add_buttons(), the only difference being that the
203  * buttons have finger size.
204  *
205  * Since: 2.2
206  */
207 void
208 hildon_dialog_add_buttons                       (HildonDialog *dialog,
209                                                  const gchar  *first_button_text,
210                                                  ...)
211 {
212     va_list args;
213     const gchar *text;
214     gint response_id;
215
216     va_start (args, first_button_text);
217     text = first_button_text;
218     response_id = va_arg (args, gint);
219
220     while (text != NULL) {
221         hildon_dialog_add_button (HILDON_DIALOG (dialog), text, response_id);
222
223         text = va_arg (args, gchar*);
224         if (text == NULL)
225             break;
226         response_id = va_arg (args, int);
227     }
228
229     va_end (args);
230 }
231