From a5323663beeb29d04dd85c1a3c0cb17bb12ce8ac Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 18 Sep 2002 04:28:38 +0000 Subject: [PATCH] Added HIG module (hig.[ch]) to provide HIG inspired dialog and layout tools. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@123 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/po/POTFILES.in | 2 + glabels2/src/Makefile.am | 2 + glabels2/src/alert.c | 91 ++++++++++- glabels2/src/alert.h | 35 ++++- glabels2/src/file.c | 39 +++-- glabels2/src/hig.c | 323 +++++++++++++++++++++++++++++++++++++++ glabels2/src/hig.h | 102 +++++++++++++ 7 files changed, 564 insertions(+), 30 deletions(-) create mode 100644 glabels2/src/hig.c create mode 100644 glabels2/src/hig.h diff --git a/glabels2/po/POTFILES.in b/glabels2/po/POTFILES.in index 0dd680ee..b517e35b 100644 --- a/glabels2/po/POTFILES.in +++ b/glabels2/po/POTFILES.in @@ -28,6 +28,8 @@ src/prefs-dialog.c src/prefs-dialog.h src/alert.c src/alert.h +src/hig.c +src/hig.h src/view.c src/view.h src/view-object.c diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index 29d1a1b2..a50c6a1a 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -69,6 +69,8 @@ glabels_SOURCES = \ prefs-dialog.h \ alert.c \ alert.h \ + hig.c \ + hig.h \ view.c \ view.h \ view-object.c \ diff --git a/glabels2/src/alert.c b/glabels2/src/alert.c index 33dbfcac..42e18d05 100644 --- a/glabels2/src/alert.c +++ b/glabels2/src/alert.c @@ -26,10 +26,86 @@ #include "alert.h" +/*========================================================*/ +/* Private macros and constants. */ +/*========================================================*/ #define HIG_ALERT_BORDER 6 #define HIG_ALERT_SPACING 12 +/*===========================================*/ +/* Private globals */ +/*===========================================*/ +static GtkDialogClass *parent_class; + + +/*===========================================*/ +/* Local function prototypes */ +/*===========================================*/ + +static void gl_alert_dialog_class_init (glAlertDialogClass *class); +static void gl_alert_dialog_init (glAlertDialog *alert_dialog); +static void gl_alert_dialog_finalize (GObject *object); + +/****************************************************************************/ +/* Boilerplate Object stuff. */ +/****************************************************************************/ +guint +gl_alert_dialog_get_type (void) +{ + static guint alert_dialog_type = 0; + + if (!alert_dialog_type) { + GTypeInfo alert_dialog_info = { + sizeof (glAlertDialogClass), + NULL, + NULL, + (GClassInitFunc) gl_alert_dialog_class_init, + NULL, + NULL, + sizeof (glAlertDialog), + 0, + (GInstanceInitFunc) gl_alert_dialog_init, + }; + + alert_dialog_type = + g_type_register_static (gtk_dialog_get_type (), + "glAlertDialog", + &alert_dialog_info, 0); + } + + return alert_dialog_type; +} + +static void +gl_alert_dialog_class_init (glAlertDialogClass *class) +{ + GObjectClass *object_class = (GObjectClass *) class; + + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = gl_alert_dialog_finalize; +} + +static void +gl_alert_dialog_init (glAlertDialog *alert_dialog) +{ +} + +static void +gl_alert_dialog_finalize (GObject *object) +{ + glAlertDialog *alert_dialog; + + g_return_if_fail (object != NULL); + g_return_if_fail (GL_IS_ALERT_DIALOG (object)); + + alert_dialog = GL_ALERT_DIALOG (object); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + + /****************************************************************************/ /* Create a message dialog that attempts to be HIG compliant. */ /****************************************************************************/ @@ -45,8 +121,19 @@ GtkWidget* gl_alert_dialog_new (GtkWindow *parent, const gchar *stock_id = NULL; GtkStockItem item; - /* Create bare dialog */ - dialog = gtk_dialog_new_with_buttons ("", parent, flags, NULL); + /* Bare dialog */ + dialog = g_object_new (gl_alert_dialog_get_type (), NULL); + + /* Parent */ + gtk_window_set_transient_for (GTK_WINDOW(dialog), parent); + + /* Flags */ + if ( flags & GTK_DIALOG_MODAL ) { + gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); + } + if ( flags & GTK_DIALOG_DESTROY_WITH_PARENT ) { + gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE); + } /* Create HBOX */ hbox = gtk_hbox_new (FALSE, HIG_ALERT_SPACING); diff --git a/glabels2/src/alert.h b/glabels2/src/alert.h index 6877943c..5c5b70f6 100644 --- a/glabels2/src/alert.h +++ b/glabels2/src/alert.h @@ -27,12 +27,35 @@ G_BEGIN_DECLS -GtkWidget* gl_alert_dialog_new (GtkWindow *parent, - GtkDialogFlags flags, - GtkMessageType type, - GtkButtonsType buttons, - const gchar *primary_text, - const gchar *secondary_text); +#define GL_TYPE_ALERT_DIALOG (gl_alert_dialog_get_type ()) +#define GL_ALERT_DIALOG(obj) \ + (GTK_CHECK_CAST((obj), GL_TYPE_ALERT_DIALOG, glAlertDialog )) +#define GL_ALERT_DIALOG_CLASS(klass) \ + (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_ALERT_DIALOG, glAlertDialogClass)) +#define GL_IS_ALERT_DIALOG(obj) \ + (GTK_CHECK_TYPE ((obj), GL_TYPE_ALERT_DIALOG)) +#define GL_IS_ALERT_DIALOG_CLASS(klass) \ + (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_ALERT_DIALOG)) + +typedef struct _glAlertDialog glAlertDialog; +typedef struct _glAlertDialogClass glAlertDialogClass; + +struct _glAlertDialog { + GtkDialog parent_widget; +}; + +struct _glAlertDialogClass { + GtkDialogClass parent_class; +}; + +guint gl_alert_dialog_get_type (void); + +GtkWidget *gl_alert_dialog_new (GtkWindow *parent, + GtkDialogFlags flags, + GtkMessageType type, + GtkButtonsType buttons, + const gchar *primary_text, + const gchar *secondary_text); G_END_DECLS diff --git a/glabels2/src/file.c b/glabels2/src/file.c index cb6900f6..0b3b1cf3 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -30,6 +30,7 @@ #include "file.h" #include "mdi.h" #include "recent.h" +#include "hig.h" #include "alert.h" #include "util.h" #include "wdgt-media-select.h" @@ -52,7 +53,7 @@ static gchar *save_path = NULL; /*===========================================*/ /* Local function prototypes. */ /*===========================================*/ -static void create_new_dialog_widgets (GtkDialog *dlg); +static void create_new_dialog_widgets (glHigDialog *dlg); static void new_template_changed (glWdgtMediaSelect *select, gpointer data); static void new_response (GtkDialog *dlg, @@ -83,14 +84,14 @@ gl_file_new (void) g_return_if_fail (glabels_mdi != NULL); g_return_if_fail (win != NULL); - dlg = gtk_dialog_new_with_buttons (_("New Label or Card"), - GTK_WINDOW (win), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_OK, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - NULL); + dlg = gl_hig_dialog_new_with_buttons (_("New Label or Card"), + GTK_WINDOW (win), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_OK, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + NULL); - create_new_dialog_widgets (GTK_DIALOG (dlg)); + create_new_dialog_widgets (GL_HIG_DIALOG (dlg)); g_signal_connect (G_OBJECT(dlg), "response", G_CALLBACK (new_response), dlg); @@ -104,31 +105,25 @@ gl_file_new (void) /* PRIVATE. Create widgets. */ /*---------------------------------------------------------------------------*/ static void -create_new_dialog_widgets (GtkDialog *dlg) +create_new_dialog_widgets (glHigDialog *dlg) { - GtkWidget *wframe, *wvbox, *template_entry, *rotate_sel; + GtkWidget *wframe, *template_entry, *rotate_sel; gl_debug (DEBUG_FILE, "START"); - wframe = gtk_frame_new (_("Media Type")); + wframe = gl_hig_category_new (_("Media Type")); gtk_box_pack_start (GTK_BOX (dlg->vbox), wframe, FALSE, FALSE, 0); - wvbox = gtk_vbox_new (FALSE, GNOME_PAD); - gtk_container_set_border_width (GTK_CONTAINER (wvbox), 10); - gtk_container_add (GTK_CONTAINER (wframe), wvbox); - template_entry = gl_wdgt_media_select_new (); - gtk_container_add (GTK_CONTAINER (wvbox), template_entry); + gtk_box_pack_start (GTK_BOX (GL_HIG_CATEGORY(wframe)->vbox), + template_entry, FALSE, FALSE, 0); - wframe = gtk_frame_new (_("Label orientation")); + wframe = gl_hig_category_new (_("Label orientation")); gtk_box_pack_start (GTK_BOX (dlg->vbox), wframe, FALSE, FALSE, 0); - wvbox = gtk_vbox_new (FALSE, GNOME_PAD); - gtk_container_set_border_width (GTK_CONTAINER (wvbox), 10); - gtk_container_add (GTK_CONTAINER (wframe), wvbox); - rotate_sel = gl_wdgt_rotate_label_new (); - gtk_box_pack_start (GTK_BOX (wvbox), rotate_sel, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (GL_HIG_CATEGORY(wframe)->vbox), + rotate_sel, FALSE, FALSE, 0); g_object_set_data (G_OBJECT (dlg), "template_entry", template_entry); diff --git a/glabels2/src/hig.c b/glabels2/src/hig.c new file mode 100644 index 00000000..93baaf49 --- /dev/null +++ b/glabels2/src/hig.c @@ -0,0 +1,323 @@ +/* + * (GLABELS) Label and Business Card Creation program for GNOME + * + * hig.c: HIG inspired dialog and layout tools + * + * Copyright (C) 2001 Jim Evins . + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include + +#include "hig.h" + +/*========================================================*/ +/* Private macros and constants. */ +/*========================================================*/ +#define HIG_DIALOG_BORDER 12 +#define HIG_DIALOG_VBOX_SPACING 18 +#define HIG_DIALOG_ACTION_BORDER 0 + +#define HIG_GENERAL_SPACING 6 + +/*===========================================*/ +/* Private globals */ +/*===========================================*/ +static GtkDialogClass *hig_dialog_parent_class; +static GtkVBoxClass *hig_category_parent_class; + + +/*===========================================*/ +/* Local function prototypes */ +/*===========================================*/ + +static void gl_hig_dialog_class_init (glHigDialogClass *class); +static void gl_hig_dialog_init (glHigDialog *hig_dialog); +static void gl_hig_dialog_finalize (GObject *object); + +static void add_buttons_valist (glHigDialog *dialog, + const gchar *first_button_text, + va_list args); + +static void gl_hig_category_class_init (glHigCategoryClass *class); +static void gl_hig_category_init (glHigCategory *hig_category); +static void gl_hig_category_finalize (GObject *object); + + +/****************************************************************************/ +/* Boilerplate Dialog Object stuff. */ +/****************************************************************************/ +guint +gl_hig_dialog_get_type (void) +{ + static guint hig_dialog_type = 0; + + if (!hig_dialog_type) { + GTypeInfo hig_dialog_info = { + sizeof (glHigDialogClass), + NULL, + NULL, + (GClassInitFunc) gl_hig_dialog_class_init, + NULL, + NULL, + sizeof (glHigDialog), + 0, + (GInstanceInitFunc) gl_hig_dialog_init, + }; + + hig_dialog_type = + g_type_register_static (gtk_dialog_get_type (), + "glHigDialog", + &hig_dialog_info, 0); + } + + return hig_dialog_type; +} + +static void +gl_hig_dialog_class_init (glHigDialogClass *class) +{ + GObjectClass *object_class = (GObjectClass *) class; + + hig_dialog_parent_class = g_type_class_peek_parent (class); + + object_class->finalize = gl_hig_dialog_finalize; +} + +static void +gl_hig_dialog_init (glHigDialog *hig_dialog) +{ + gtk_container_set_border_width (GTK_CONTAINER(hig_dialog), + HIG_DIALOG_BORDER); + +#if 0 + hig_dialog->vbox = gtk_vbox_new (FALSE, HIG_DIALOG_VBOX_SPACING); + gtk_box_pack_start (GTK_BOX(GTK_DIALOG(hig_dialog)->vbox), + hig_dialog->vbox, FALSE, FALSE, 0); +#else + hig_dialog->vbox = GTK_DIALOG(hig_dialog)->vbox; + gtk_box_set_spacing (GTK_BOX(GTK_DIALOG(hig_dialog)->vbox), + HIG_DIALOG_VBOX_SPACING); +#endif + + /* FIXME: Doesn't seem to accomplish anything. */ + gtk_container_set_border_width (GTK_CONTAINER(GTK_DIALOG(hig_dialog)->action_area), + HIG_DIALOG_ACTION_BORDER); +} + +static void +gl_hig_dialog_finalize (GObject *object) +{ + glHigDialog *hig_dialog; + + g_return_if_fail (object != NULL); + g_return_if_fail (GL_IS_HIG_DIALOG (object)); + + hig_dialog = GL_HIG_DIALOG (object); + + G_OBJECT_CLASS (hig_dialog_parent_class)->finalize (object); +} + + +/****************************************************************************/ +/* Create a dialog that attempts to be HIG compliant. */ +/****************************************************************************/ +GtkWidget* gl_hig_dialog_new (void) +{ + GtkWidget *dialog; + + dialog = g_object_new (gl_hig_dialog_get_type (), NULL); + + return dialog; +} + + + +/****************************************************************************/ +/* Create a dialog that attempts to be HIG compliant with buttons. */ +/****************************************************************************/ +GtkWidget *gl_hig_dialog_new_with_buttons (const gchar *title, + GtkWindow *parent, + GtkDialogFlags flags, + const gchar *first_button_text, + ...) +{ + GtkWidget *dialog; + va_list args; + + /* Create bare dialog */ + dialog = g_object_new (gl_hig_dialog_get_type (), NULL); + + /* Title */ + gtk_window_set_title (GTK_WINDOW(dialog), title); + + /* Parent */ + gtk_window_set_transient_for (GTK_WINDOW(dialog), parent); + + /* Flags */ + if ( flags & GTK_DIALOG_MODAL ) { + gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); + } + if ( flags & GTK_DIALOG_DESTROY_WITH_PARENT ) { + gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE); + } + + /* Buttons */ + va_start (args, first_button_text); + add_buttons_valist (GL_HIG_DIALOG(dialog), first_button_text, args); + va_end (args); + + + return dialog; +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Add buttons to dialog from va_list. */ +/*---------------------------------------------------------------------------*/ +static void +add_buttons_valist(glHigDialog *dialog, + const gchar *first_button_text, + va_list args) +{ + const gchar* text; + gint response_id; + + g_return_if_fail (GL_IS_HIG_DIALOG (dialog)); + + if (first_button_text == NULL) + return; + + text = first_button_text; + response_id = va_arg (args, gint); + + while (text != NULL) + { + gtk_dialog_add_button (GTK_DIALOG(dialog), text, response_id); + + text = va_arg (args, gchar*); + if (text == NULL) + break; + response_id = va_arg (args, int); + } +} + + +/****************************************************************************/ +/* Boilerplate Category Object stuff. */ +/****************************************************************************/ +guint +gl_hig_category_get_type (void) +{ + static guint hig_category_type = 0; + + if (!hig_category_type) { + GTypeInfo hig_category_info = { + sizeof (glHigCategoryClass), + NULL, + NULL, + (GClassInitFunc) gl_hig_category_class_init, + NULL, + NULL, + sizeof (glHigCategory), + 0, + (GInstanceInitFunc) gl_hig_category_init, + }; + + hig_category_type = + g_type_register_static (gtk_vbox_get_type (), + "glHigCategory", + &hig_category_info, 0); + } + + return hig_category_type; +} + +static void +gl_hig_category_class_init (glHigCategoryClass *class) +{ + GObjectClass *object_class = (GObjectClass *) class; + + hig_category_parent_class = g_type_class_peek_parent (class); + + object_class->finalize = gl_hig_category_finalize; +} + +static void +gl_hig_category_init (glHigCategory *hig_category) +{ + GtkWidget *hbox; + + gtk_box_set_spacing (GTK_BOX(hig_category), HIG_GENERAL_SPACING); + + /* 1st row: Label */ + hig_category->label = gtk_label_new (""); + gtk_label_set_use_markup (GTK_LABEL(hig_category->label), TRUE); + gtk_misc_set_alignment (GTK_MISC(hig_category->label), 0.0, 0.0); + gtk_box_pack_start (GTK_BOX(hig_category), + hig_category->label, FALSE, FALSE, 0); + + /* 2nd row: HBOX */ + hbox = gtk_hbox_new (FALSE, HIG_GENERAL_SPACING); + gtk_box_pack_start (GTK_BOX(hig_category), hbox, FALSE, FALSE, 0); + + /* 2nd row, Column 1: Indentation spacing */ + gtk_box_pack_start (GTK_BOX(hbox), + gtk_label_new (" "), FALSE, FALSE, 0); + + /* 2nd row, Column 2: User area (inner vbox) */ + hig_category->vbox = gtk_vbox_new (FALSE, HIG_GENERAL_SPACING); + gtk_box_pack_start (GTK_BOX(hbox), + hig_category->vbox, FALSE, FALSE, 0); +} + +static void +gl_hig_category_finalize (GObject *object) +{ + glHigCategory *hig_category; + + g_return_if_fail (object != NULL); + g_return_if_fail (GL_IS_HIG_CATEGORY (object)); + + hig_category = GL_HIG_CATEGORY (object); + + G_OBJECT_CLASS (hig_category_parent_class)->finalize (object); +} + + +/****************************************************************************/ +/* Create a category layout container that attempts to be HIG compliant. */ +/****************************************************************************/ +GtkWidget* gl_hig_category_new (const gchar *header) +{ + GtkWidget *category; + gchar *marked_up_header; + + category = g_object_new (gl_hig_category_get_type (), NULL); + + marked_up_header = g_strdup_printf ("%s", + header); + gtk_label_set_text (GTK_LABEL(GL_HIG_CATEGORY(category)->label), + marked_up_header); + g_free (marked_up_header); + + gtk_label_set_use_markup (GTK_LABEL(GL_HIG_CATEGORY(category)->label), + TRUE); + + return category; +} + diff --git a/glabels2/src/hig.h b/glabels2/src/hig.h new file mode 100644 index 00000000..c1d1359d --- /dev/null +++ b/glabels2/src/hig.h @@ -0,0 +1,102 @@ +/* + * (GLABELS) Label and Business Card Creation program for GNOME + * + * hig.h: HIG inspired dialog and layout tools + * + * Copyright (C) 2002 Jim Evins . + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __HIG_H__ +#define __HIG_H__ + +#include + +G_BEGIN_DECLS + +/*===========================================================================*/ +/* HIG Dialog. */ +/*===========================================================================*/ + +#define GL_TYPE_HIG_DIALOG (gl_hig_dialog_get_type ()) +#define GL_HIG_DIALOG(obj) \ + (GTK_CHECK_CAST((obj), GL_TYPE_HIG_DIALOG, glHigDialog )) +#define GL_HIG_DIALOG_CLASS(klass) \ + (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_HIG_DIALOG, glHigDialogClass)) +#define GL_IS_HIG_DIALOG(obj) \ + (GTK_CHECK_TYPE ((obj), GL_TYPE_HIG_DIALOG)) +#define GL_IS_HIG_DIALOG_CLASS(klass) \ + (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_HIG_DIALOG)) + +typedef struct _glHigDialog glHigDialog; +typedef struct _glHigDialogClass glHigDialogClass; + +struct _glHigDialog { + GtkDialog parent_widget; + + GtkWidget *vbox; +}; + +struct _glHigDialogClass { + GtkDialogClass parent_class; +}; + +guint gl_hig_dialog_get_type (void); + +GtkWidget *gl_hig_dialog_new (void); + +GtkWidget *gl_hig_dialog_new_with_buttons (const gchar *title, + GtkWindow *parent, + GtkDialogFlags flags, + const gchar *first_button_text, + ...); + + +/*===========================================================================*/ +/* HIG Category. */ +/*===========================================================================*/ + +#define GL_TYPE_HIG_CATEGORY (gl_hig_category_get_type ()) +#define GL_HIG_CATEGORY(obj) \ + (GTK_CHECK_CAST((obj), GL_TYPE_HIG_CATEGORY, glHigCategory )) +#define GL_HIG_CATEGORY_CLASS(klass) \ + (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_HIG_CATEGORY, glHigCategoryClass)) +#define GL_IS_HIG_CATEGORY(obj) \ + (GTK_CHECK_TYPE ((obj), GL_TYPE_HIG_CATEGORY)) +#define GL_IS_HIG_CATEGORY_CLASS(klass) \ + (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_HIG_CATEGORY)) + +typedef struct _glHigCategory glHigCategory; +typedef struct _glHigCategoryClass glHigCategoryClass; + +struct _glHigCategory { + GtkVBox parent_widget; + + GtkWidget *label; + GtkWidget *vbox; +}; + +struct _glHigCategoryClass { + GtkVBoxClass parent_class; +}; + +guint gl_hig_category_get_type (void); + +GtkWidget *gl_hig_category_new (const gchar *header); + +G_END_DECLS + +#endif /* __HIG_H__ */ -- 2.39.5