2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * hig.c: HIG inspired dialog and layout tools
6 * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /*========================================================*/
30 /* Private macros and constants. */
31 /*========================================================*/
32 #define HIG_DIALOG_BORDER 12
33 #define HIG_DIALOG_VBOX_SPACING 18
34 #define HIG_DIALOG_ACTION_BORDER 0
36 #define HIG_GENERAL_SPACING 6
38 /*===========================================*/
40 /*===========================================*/
41 static GtkDialogClass *hig_dialog_parent_class;
42 static GtkVBoxClass *hig_category_parent_class;
45 /*===========================================*/
46 /* Local function prototypes */
47 /*===========================================*/
49 static void gl_hig_dialog_class_init (glHigDialogClass *class);
50 static void gl_hig_dialog_init (glHigDialog *hig_dialog);
51 static void gl_hig_dialog_finalize (GObject *object);
53 static void add_buttons_valist (glHigDialog *dialog,
54 const gchar *first_button_text,
57 static void gl_hig_category_class_init (glHigCategoryClass *class);
58 static void gl_hig_category_init (glHigCategory *hig_category);
59 static void gl_hig_category_finalize (GObject *object);
62 /****************************************************************************/
63 /* Boilerplate Dialog Object stuff. */
64 /****************************************************************************/
66 gl_hig_dialog_get_type (void)
68 static guint hig_dialog_type = 0;
70 if (!hig_dialog_type) {
71 GTypeInfo hig_dialog_info = {
72 sizeof (glHigDialogClass),
75 (GClassInitFunc) gl_hig_dialog_class_init,
80 (GInstanceInitFunc) gl_hig_dialog_init,
84 g_type_register_static (gtk_dialog_get_type (),
89 return hig_dialog_type;
93 gl_hig_dialog_class_init (glHigDialogClass *class)
95 GObjectClass *object_class = (GObjectClass *) class;
97 hig_dialog_parent_class = g_type_class_peek_parent (class);
99 object_class->finalize = gl_hig_dialog_finalize;
103 gl_hig_dialog_init (glHigDialog *hig_dialog)
105 gtk_container_set_border_width (GTK_CONTAINER(hig_dialog),
108 hig_dialog->vbox = gtk_vbox_new (FALSE, HIG_DIALOG_VBOX_SPACING);
109 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(hig_dialog)->vbox),
110 hig_dialog->vbox, FALSE, FALSE, 0);
111 gtk_box_set_spacing (GTK_BOX(GTK_DIALOG(hig_dialog)->vbox),
112 HIG_DIALOG_VBOX_SPACING);
116 gl_hig_dialog_finalize (GObject *object)
118 glHigDialog *hig_dialog;
120 g_return_if_fail (object != NULL);
121 g_return_if_fail (GL_IS_HIG_DIALOG (object));
123 hig_dialog = GL_HIG_DIALOG (object);
125 G_OBJECT_CLASS (hig_dialog_parent_class)->finalize (object);
129 /****************************************************************************/
130 /* Create a dialog that attempts to be HIG compliant. */
131 /****************************************************************************/
132 GtkWidget* gl_hig_dialog_new (void)
136 dialog = g_object_new (gl_hig_dialog_get_type (), NULL);
143 /****************************************************************************/
144 /* Create a dialog that attempts to be HIG compliant with buttons. */
145 /****************************************************************************/
146 GtkWidget *gl_hig_dialog_new_with_buttons (const gchar *title,
148 GtkDialogFlags flags,
149 const gchar *first_button_text,
155 /* Create bare dialog */
156 dialog = g_object_new (gl_hig_dialog_get_type (), NULL);
159 gtk_window_set_title (GTK_WINDOW(dialog), title);
162 gtk_window_set_transient_for (GTK_WINDOW(dialog), parent);
165 if ( flags & GTK_DIALOG_MODAL ) {
166 gtk_window_set_modal (GTK_WINDOW(dialog), TRUE);
168 if ( flags & GTK_DIALOG_DESTROY_WITH_PARENT ) {
169 gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE);
173 va_start (args, first_button_text);
174 add_buttons_valist (GL_HIG_DIALOG(dialog), first_button_text, args);
181 /*---------------------------------------------------------------------------*/
182 /* PRIVATE. Add buttons to dialog from va_list. */
183 /*---------------------------------------------------------------------------*/
185 add_buttons_valist(glHigDialog *dialog,
186 const gchar *first_button_text,
192 g_return_if_fail (GL_IS_HIG_DIALOG (dialog));
194 if (first_button_text == NULL)
197 text = first_button_text;
198 response_id = va_arg (args, gint);
202 gtk_dialog_add_button (GTK_DIALOG(dialog), text, response_id);
204 text = va_arg (args, gchar*);
207 response_id = va_arg (args, int);
212 /****************************************************************************/
213 /* Boilerplate Category Object stuff. */
214 /****************************************************************************/
216 gl_hig_category_get_type (void)
218 static guint hig_category_type = 0;
220 if (!hig_category_type) {
221 GTypeInfo hig_category_info = {
222 sizeof (glHigCategoryClass),
225 (GClassInitFunc) gl_hig_category_class_init,
228 sizeof (glHigCategory),
230 (GInstanceInitFunc) gl_hig_category_init,
234 g_type_register_static (gtk_vbox_get_type (),
236 &hig_category_info, 0);
239 return hig_category_type;
243 gl_hig_category_class_init (glHigCategoryClass *class)
245 GObjectClass *object_class = (GObjectClass *) class;
247 hig_category_parent_class = g_type_class_peek_parent (class);
249 object_class->finalize = gl_hig_category_finalize;
253 gl_hig_category_init (glHigCategory *hig_category)
257 gtk_box_set_spacing (GTK_BOX(hig_category), HIG_GENERAL_SPACING);
260 hig_category->label = gtk_label_new ("");
261 gtk_label_set_use_markup (GTK_LABEL(hig_category->label), TRUE);
262 gtk_misc_set_alignment (GTK_MISC(hig_category->label), 0.0, 0.0);
263 gtk_box_pack_start (GTK_BOX(hig_category),
264 hig_category->label, FALSE, FALSE, 0);
267 hbox = gtk_hbox_new (FALSE, HIG_GENERAL_SPACING);
268 gtk_box_pack_start (GTK_BOX(hig_category), hbox, FALSE, FALSE, 0);
270 /* 2nd row, Column 1: Indentation spacing */
271 gtk_box_pack_start (GTK_BOX(hbox),
272 gtk_label_new (" "), FALSE, FALSE, 0);
274 /* 2nd row, Column 2: User area (inner vbox) */
275 hig_category->vbox = gtk_vbox_new (FALSE, HIG_GENERAL_SPACING);
276 gtk_box_pack_start (GTK_BOX(hbox),
277 hig_category->vbox, FALSE, FALSE, 0);
281 gl_hig_category_finalize (GObject *object)
283 glHigCategory *hig_category;
285 g_return_if_fail (object != NULL);
286 g_return_if_fail (GL_IS_HIG_CATEGORY (object));
288 hig_category = GL_HIG_CATEGORY (object);
290 G_OBJECT_CLASS (hig_category_parent_class)->finalize (object);
294 /****************************************************************************/
295 /* Create a category layout container that attempts to be HIG compliant. */
296 /****************************************************************************/
297 GtkWidget* gl_hig_category_new (const gchar *header)
300 gchar *marked_up_header;
302 category = g_object_new (gl_hig_category_get_type (), NULL);
304 marked_up_header = g_strdup_printf ("<span weight=\"bold\">%s</span>",
306 gtk_label_set_text (GTK_LABEL(GL_HIG_CATEGORY(category)->label),
308 g_free (marked_up_header);
310 gtk_label_set_use_markup (GTK_LABEL(GL_HIG_CATEGORY(category)->label),