]> git.sur5r.net Git - glabels/commitdiff
alert module merged into hig module.
authorJim Evins <evins@snaught.com>
Sat, 5 Oct 2002 04:00:07 +0000 (04:00 +0000)
committerJim Evins <evins@snaught.com>
Sat, 5 Oct 2002 04:00:07 +0000 (04:00 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@145 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/po/POTFILES.in
glabels2/src/Makefile.am
glabels2/src/alert.c [deleted file]
glabels2/src/alert.h [deleted file]
glabels2/src/file.c
glabels2/src/hig.c
glabels2/src/hig.h

index 87bde91c911afec08f61867a29701267e21b62aa..9cfc05474dbd4e888617bc32591993bb6275a272 100644 (file)
@@ -24,8 +24,6 @@ src/prefs.c
 src/prefs.h
 src/prefs-dialog.c
 src/prefs-dialog.h
-src/alert.c
-src/alert.h
 src/hig.c
 src/hig.h
 src/view.c
index be37c9f75306202bcc594cf687303c841536d9f7..0b033b1b078c090558fc6b77741215f1d0f92e60 100644 (file)
@@ -64,8 +64,6 @@ glabels_SOURCES =                     \
        prefs.h                         \
        prefs-dialog.c                  \
        prefs-dialog.h                  \
-       alert.c                         \
-       alert.h                         \
        hig.c                           \
        hig.h                           \
        view.c                          \
diff --git a/glabels2/src/alert.c b/glabels2/src/alert.c
deleted file mode 100644 (file)
index 42e18d0..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  alert.c:  a HIG inspired alert dialog
- *
- *  Copyright (C) 2001  Jim Evins <evins@snaught.com>.
- *
- *  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 <config.h>
-
-#include <glib.h>
-
-#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);
-
-\f
-/****************************************************************************/
-/* 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.               */
-/****************************************************************************/
-GtkWidget* gl_alert_dialog_new      (GtkWindow      *parent,
-                                    GtkDialogFlags  flags,
-                                    GtkMessageType  type,
-                                    GtkButtonsType  buttons,
-                                    const gchar    *primary_text,
-                                    const gchar    *secondary_text)
-{
-       GtkWidget    *dialog, *hbox, *image, *label;
-       gchar        *label_text;
-       const gchar  *stock_id = NULL;
-       GtkStockItem  item;
-  
-       /* 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);
-       gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
-                           hbox, FALSE, FALSE, 0);
-
-       /* Create image */
-       switch (type) {
-       case GTK_MESSAGE_INFO:
-               stock_id = GTK_STOCK_DIALOG_INFO;
-               break;
-       case GTK_MESSAGE_QUESTION:
-               stock_id = GTK_STOCK_DIALOG_QUESTION;
-               break;
-       case GTK_MESSAGE_WARNING:
-               stock_id = GTK_STOCK_DIALOG_WARNING;
-               break;
-       case GTK_MESSAGE_ERROR:
-               stock_id = GTK_STOCK_DIALOG_ERROR;
-               break;
-       default:
-               stock_id = GTK_STOCK_DIALOG_INFO;
-               g_warning ("Unknown GtkMessageType %d", type);
-               break;
-       }
-       if (gtk_stock_lookup (stock_id, &item)) {
-               image = gtk_image_new_from_stock (stock_id,
-                                                 GTK_ICON_SIZE_DIALOG);
-       } else {
-               image = gtk_image_new_from_stock (NULL,
-                                                 GTK_ICON_SIZE_DIALOG);
-               g_warning ("Stock dialog ID doesn't exist?");
-       }
-       gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
-
-       /* Create label containing primary and secondary text */
-       label_text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
-                                     primary_text, secondary_text);
-       label = gtk_label_new (label_text);
-       g_free (label_text);
-       gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
-
-       /* Adjust dialog properties */
-       gtk_window_set_title (GTK_WINDOW(dialog), "");
-       gtk_container_set_border_width (GTK_CONTAINER(dialog),
-                                       HIG_ALERT_BORDER);
-       gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
-
-       /* Adjust VBOX properties */
-       gtk_box_set_spacing (GTK_BOX(GTK_DIALOG(dialog)->vbox),
-                            HIG_ALERT_SPACING);
-
-       /* Adjust HBOX properties */
-       gtk_box_set_spacing (GTK_BOX(hbox), HIG_ALERT_SPACING);
-       gtk_container_set_border_width (GTK_CONTAINER(hbox), HIG_ALERT_BORDER);
-
-       /* Adjust IMAGE properties */
-       gtk_misc_set_alignment (GTK_MISC(image), 0.5, 0.0);
-
-       /* Adjust LABEL properties */
-       gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
-       gtk_label_set_use_markup (GTK_LABEL(label), TRUE);
-       gtk_misc_set_alignment (GTK_MISC(image), 0.5, 0.0);
-
-       /* Add buttons */
-       switch (buttons) {
-       case GTK_BUTTONS_NONE:
-               /* nothing */
-               break;
-       case GTK_BUTTONS_OK:
-               gtk_dialog_add_button (GTK_DIALOG(dialog),
-                                      GTK_STOCK_OK, GTK_RESPONSE_OK);
-               break;
-       case GTK_BUTTONS_CLOSE:
-               gtk_dialog_add_button (GTK_DIALOG(dialog),
-                                      GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
-               break;
-       case GTK_BUTTONS_CANCEL:
-               gtk_dialog_add_button (GTK_DIALOG(dialog),
-                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
-               break;
-       case GTK_BUTTONS_YES_NO:
-               gtk_dialog_add_button (GTK_DIALOG(dialog),
-                                      GTK_STOCK_NO, GTK_RESPONSE_NO);
-               gtk_dialog_add_button (GTK_DIALOG(dialog),
-                                      GTK_STOCK_YES, GTK_RESPONSE_YES);
-               break;
-       case GTK_BUTTONS_OK_CANCEL:
-               gtk_dialog_add_button (GTK_DIALOG(dialog),
-                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
-               gtk_dialog_add_button (GTK_DIALOG(dialog),
-                                      GTK_STOCK_OK, GTK_RESPONSE_OK);
-               break;
-       default:
-               g_warning ("Unknown GtkButtonsType");
-               break;
-       }
-
-       /* Show dialog widgets */
-       gtk_widget_show_all (hbox);
-
-       return dialog;
-}
-
diff --git a/glabels2/src/alert.h b/glabels2/src/alert.h
deleted file mode 100644 (file)
index 5c5b70f..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  alert.h:  a HIG inspired alert dialog
- *
- *  Copyright (C) 2002  Jim Evins <evins@snaught.com>.
- *
- *  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 __ALERT_H__
-#define __ALERT_H__
-
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS
-
-#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
-
-#endif /* __ALERT_H__ */
index 36f6b1aa8da39c70f175817963ee7a45ac2c2e4a..d5b7e1b8ea77dcfe623d4ea7ee274ebed299ab65 100644 (file)
@@ -29,7 +29,6 @@
 #include "file.h"
 #include "recent.h"
 #include "hig.h"
-#include "alert.h"
 #include "util.h"
 #include "wdgt-media-select.h"
 #include "wdgt-rotate-label.h"
@@ -290,12 +289,12 @@ open_ok (GtkWidget        *widget,
 
        if (!filename || g_file_test (filename, G_FILE_TEST_IS_DIR)) {
 
-               dlg = gl_alert_dialog_new (GTK_WINDOW(fsel),
-                                          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                          GTK_MESSAGE_WARNING,
-                                          GTK_BUTTONS_CLOSE,
-                                          _("Empty file name selection"),
-                                          _("Please select a file or supply a valid file name"));
+               dlg = gl_hig_alert_new (GTK_WINDOW(fsel),
+                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                       GTK_MESSAGE_WARNING,
+                                       GTK_BUTTONS_CLOSE,
+                                       _("Empty file name selection"),
+                                       _("Please select a file or supply a valid file name"));
 
                gtk_dialog_run (GTK_DIALOG (dlg));
                gtk_widget_destroy (dlg);
@@ -304,12 +303,12 @@ open_ok (GtkWidget        *widget,
 
                if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
 
-                       dlg = gl_alert_dialog_new (GTK_WINDOW(fsel),
-                                                  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                  GTK_MESSAGE_WARNING,
-                                                  GTK_BUTTONS_CLOSE,
-                                                  _("File does not exist"),
-                                                  _("Please select a file or supply a valid file name"));
+                       dlg = gl_hig_alert_new (GTK_WINDOW(fsel),
+                                               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                               GTK_MESSAGE_WARNING,
+                                               GTK_BUTTONS_CLOSE,
+                                               _("File does not exist"),
+                                               _("Please select a file or supply a valid file name"));
 
                        gtk_dialog_run (GTK_DIALOG (dlg));
                        gtk_widget_destroy (dlg);
@@ -373,12 +372,12 @@ gl_file_open_real (const gchar     *filename,
                primary_msg = g_strdup_printf (_("Could not open file \"%s\""),
                                               filename);
 
-               dlg = gl_alert_dialog_new (window,
-                                          GTK_DIALOG_DESTROY_WITH_PARENT,
-                                          GTK_MESSAGE_ERROR,
-                                          GTK_BUTTONS_CLOSE,
-                                          primary_msg,
-                                          _("Not a supported file format"));
+               dlg = gl_hig_alert_new (window,
+                                       GTK_DIALOG_DESTROY_WITH_PARENT,
+                                       GTK_MESSAGE_ERROR,
+                                       GTK_BUTTONS_CLOSE,
+                                       primary_msg,
+                                       _("Not a supported file format"));
 
                g_free (primary_msg);
 
@@ -463,12 +462,12 @@ gl_file_save (glLabel   *label,
                primary_msg = g_strdup_printf (_("Could not save file \"%s\""),
                                               filename);
 
-               dialog = gl_alert_dialog_new (window,
-                                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                             GTK_MESSAGE_ERROR,
-                                             GTK_BUTTONS_CLOSE,
-                                             primary_msg,
-                                             _("Error encountered during save.  The file is still not saved."));
+               dialog = gl_hig_alert_new (window,
+                                          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                          GTK_MESSAGE_ERROR,
+                                          GTK_BUTTONS_CLOSE,
+                                          primary_msg,
+                                          _("Error encountered during save.  The file is still not saved."));
 
                g_free (primary_msg);
 
@@ -582,12 +581,12 @@ save_as_ok_cb (GtkWidget        *widget,
 
        if (!raw_filename || g_file_test (raw_filename, G_FILE_TEST_IS_DIR)) {
 
-               dlg = gl_alert_dialog_new (GTK_WINDOW(fsel),
-                                          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                          GTK_MESSAGE_WARNING,
-                                          GTK_BUTTONS_CLOSE,
-                                          _("Empty file name selection"),
-                                          _("Please supply a valid file name"));
+               dlg = gl_hig_alert_new (GTK_WINDOW(fsel),
+                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                       GTK_MESSAGE_WARNING,
+                                       GTK_BUTTONS_CLOSE,
+                                       _("Empty file name selection"),
+                                       _("Please supply a valid file name"));
 
                gtk_dialog_run (GTK_DIALOG (dlg));
                gtk_widget_destroy (dlg);
@@ -604,12 +603,12 @@ save_as_ok_cb (GtkWidget        *widget,
                        primary_msg = g_strdup_printf (_("Overwrite file \"%s\"?"),
                                                       filename);
 
-                       dlg = gl_alert_dialog_new (GTK_WINDOW(fsel),
-                                                  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                  GTK_MESSAGE_QUESTION,
-                                                  GTK_BUTTONS_YES_NO,
-                                                  primary_msg,
-                                                  _("File already exists."));
+                       dlg = gl_hig_alert_new (GTK_WINDOW(fsel),
+                                               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                               GTK_MESSAGE_QUESTION,
+                                               GTK_BUTTONS_YES_NO,
+                                               primary_msg,
+                                               _("File already exists."));
                        
                        g_free (primary_msg);
 
@@ -631,12 +630,12 @@ save_as_ok_cb (GtkWidget        *widget,
                                primary_msg = g_strdup_printf (_("Could not save file \"%s\""),
                                                               filename);
 
-                               dlg = gl_alert_dialog_new (GTK_WINDOW(fsel),
-                                                          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                          GTK_MESSAGE_ERROR,
-                                                          GTK_BUTTONS_CLOSE,
-                                                          primary_msg,
-                                                          _("Error encountered during save.  The file is still not saved."));
+                               dlg = gl_hig_alert_new (GTK_WINDOW(fsel),
+                                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                       GTK_MESSAGE_ERROR,
+                                                       GTK_BUTTONS_CLOSE,
+                                                       primary_msg,
+                                                       _("Error encountered during save.  The file is still not saved."));
 
                                g_free (primary_msg);
 
@@ -727,12 +726,12 @@ gl_file_close (glWindow *window)
                        msg = g_strdup_printf (_("Save changes to document \"%s\" before closing?"),
                                               fname);
                        
-                       msgbox = gl_alert_dialog_new (GTK_WINDOW(window),
-                                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                     GTK_MESSAGE_WARNING,
-                                                     GTK_BUTTONS_NONE,
-                                                     msg,
-                                                     _("Your changes will be lost if you don't save them."));
+                       msgbox = gl_hig_alert_new (GTK_WINDOW(window),
+                                                  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                  GTK_MESSAGE_WARNING,
+                                                  GTK_BUTTONS_NONE,
+                                                  msg,
+                                                  _("Your changes will be lost if you don't save them."));
 
                        gtk_dialog_add_button (GTK_DIALOG (msgbox),
                                               _("Close without saving"),
index 4f6f2569eebdac9d44854d2fc2e56e6a61e7ea88..bd2d20777009a6a1dfe06bc49fe8df83589dc88f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  (GLABELS) Label and Business Card Creation program for GNOME
  *
- *  hig.c:  HIG inspired dialog and layout tools
+ *  hig.c:  HIG inspired dialogs and layout tools
  *
  *  Copyright (C) 2001  Jim Evins <evins@snaught.com>.
  *
@@ -29,6 +29,9 @@
 /*========================================================*/
 /* Private macros and constants.                          */
 /*========================================================*/
+#define HIG_ALERT_BORDER               6
+#define HIG_ALERT_SPACING             12
+
 #define HIG_DIALOG_BORDER             12
 #define HIG_DIALOG_VBOX_SPACING       18
 #define HIG_DIALOG_OUTER_VBOX_SPACING 12
@@ -43,6 +46,7 @@
 /*===========================================*/
 /* Private globals                           */
 /*===========================================*/
+static GtkDialogClass *hig_alert_parent_class;
 static GtkDialogClass *hig_dialog_parent_class;
 static GtkVBoxClass   *hig_category_parent_class;
 static GtkVBoxClass   *hig_vbox_parent_class;
@@ -53,6 +57,10 @@ static GtkHBoxClass   *hig_hbox_parent_class;
 /* Local function prototypes                 */
 /*===========================================*/
 
+static void       gl_hig_alert_class_init    (glHigAlertClass *class);
+static void       gl_hig_alert_init          (glHigAlert *hig_alert);
+static void       gl_hig_alert_finalize      (GObject *object);
+
 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);
@@ -75,8 +83,204 @@ static void       gl_hig_hbox_finalize       (GObject *object);
 
 \f
 /****************************************************************************/
+/****************************************************************************/
+/* Boilerplate Alert Object stuff.                                          */
+/****************************************************************************/
+/****************************************************************************/
+guint
+gl_hig_alert_get_type (void)
+{
+       static guint hig_alert_type = 0;
+
+       if (!hig_alert_type) {
+               GTypeInfo hig_alert_info = {
+                       sizeof (glHigAlertClass),
+                       NULL,
+                       NULL,
+                       (GClassInitFunc) gl_hig_alert_class_init,
+                       NULL,
+                       NULL,
+                       sizeof (glHigAlert),
+                       0,
+                       (GInstanceInitFunc) gl_hig_alert_init,
+               };
+
+               hig_alert_type =
+                   g_type_register_static (gtk_dialog_get_type (),
+                                           "glHigAlert",
+                                           &hig_alert_info, 0);
+       }
+
+       return hig_alert_type;
+}
+
+static void
+gl_hig_alert_class_init (glHigAlertClass *class)
+{
+       GObjectClass *object_class = (GObjectClass *) class;
+
+       hig_alert_parent_class = g_type_class_peek_parent (class);
+
+       object_class->finalize = gl_hig_alert_finalize;
+}
+
+static void
+gl_hig_alert_init (glHigAlert *hig_alert)
+{
+}
+
+static void
+gl_hig_alert_finalize (GObject *object)
+{
+       glHigAlert *hig_alert;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GL_IS_HIG_ALERT (object));
+
+       hig_alert = GL_HIG_ALERT (object);
+
+       G_OBJECT_CLASS (hig_alert_parent_class)->finalize (object);
+}
+
+
+/****************************************************************************/
+/* Create a message dialog that attempts to be HIG compliant.               */
+/****************************************************************************/
+GtkWidget* gl_hig_alert_new      (GtkWindow      *parent,
+                                 GtkDialogFlags  flags,
+                                 GtkMessageType  type,
+                                 GtkButtonsType  buttons,
+                                 const gchar    *primary_text,
+                                 const gchar    *secondary_text)
+{
+       GtkWidget    *dialog, *hbox, *image, *label;
+       gchar        *label_text;
+       const gchar  *stock_id = NULL;
+       GtkStockItem  item;
+  
+       /* Bare dialog */
+       dialog = g_object_new (gl_hig_alert_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);
+       gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
+                           hbox, FALSE, FALSE, 0);
+
+       /* Create image */
+       switch (type) {
+       case GTK_MESSAGE_INFO:
+               stock_id = GTK_STOCK_DIALOG_INFO;
+               break;
+       case GTK_MESSAGE_QUESTION:
+               stock_id = GTK_STOCK_DIALOG_QUESTION;
+               break;
+       case GTK_MESSAGE_WARNING:
+               stock_id = GTK_STOCK_DIALOG_WARNING;
+               break;
+       case GTK_MESSAGE_ERROR:
+               stock_id = GTK_STOCK_DIALOG_ERROR;
+               break;
+       default:
+               stock_id = GTK_STOCK_DIALOG_INFO;
+               g_warning ("Unknown GtkMessageType %d", type);
+               break;
+       }
+       if (gtk_stock_lookup (stock_id, &item)) {
+               image = gtk_image_new_from_stock (stock_id,
+                                                 GTK_ICON_SIZE_DIALOG);
+       } else {
+               image = gtk_image_new_from_stock (NULL,
+                                                 GTK_ICON_SIZE_DIALOG);
+               g_warning ("Stock dialog ID doesn't exist?");
+       }
+       gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
+
+       /* Create label containing primary and secondary text */
+       label_text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
+                                     primary_text, secondary_text);
+       label = gtk_label_new (label_text);
+       g_free (label_text);
+       gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+       /* Adjust dialog properties */
+       gtk_window_set_title (GTK_WINDOW(dialog), "");
+       gtk_container_set_border_width (GTK_CONTAINER(dialog),
+                                       HIG_ALERT_BORDER);
+       gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
+
+       /* Adjust VBOX properties */
+       gtk_box_set_spacing (GTK_BOX(GTK_DIALOG(dialog)->vbox),
+                            HIG_ALERT_SPACING);
+
+       /* Adjust HBOX properties */
+       gtk_box_set_spacing (GTK_BOX(hbox), HIG_ALERT_SPACING);
+       gtk_container_set_border_width (GTK_CONTAINER(hbox), HIG_ALERT_BORDER);
+
+       /* Adjust IMAGE properties */
+       gtk_misc_set_alignment (GTK_MISC(image), 0.5, 0.0);
+
+       /* Adjust LABEL properties */
+       gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
+       gtk_label_set_use_markup (GTK_LABEL(label), TRUE);
+       gtk_misc_set_alignment (GTK_MISC(image), 0.5, 0.0);
+
+       /* Add buttons */
+       switch (buttons) {
+       case GTK_BUTTONS_NONE:
+               /* nothing */
+               break;
+       case GTK_BUTTONS_OK:
+               gtk_dialog_add_button (GTK_DIALOG(dialog),
+                                      GTK_STOCK_OK, GTK_RESPONSE_OK);
+               break;
+       case GTK_BUTTONS_CLOSE:
+               gtk_dialog_add_button (GTK_DIALOG(dialog),
+                                      GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
+               break;
+       case GTK_BUTTONS_CANCEL:
+               gtk_dialog_add_button (GTK_DIALOG(dialog),
+                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+               break;
+       case GTK_BUTTONS_YES_NO:
+               gtk_dialog_add_button (GTK_DIALOG(dialog),
+                                      GTK_STOCK_NO, GTK_RESPONSE_NO);
+               gtk_dialog_add_button (GTK_DIALOG(dialog),
+                                      GTK_STOCK_YES, GTK_RESPONSE_YES);
+               break;
+       case GTK_BUTTONS_OK_CANCEL:
+               gtk_dialog_add_button (GTK_DIALOG(dialog),
+                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+               gtk_dialog_add_button (GTK_DIALOG(dialog),
+                                      GTK_STOCK_OK, GTK_RESPONSE_OK);
+               break;
+       default:
+               g_warning ("Unknown GtkButtonsType");
+               break;
+       }
+
+       /* Show dialog widgets */
+       gtk_widget_show_all (hbox);
+
+       return dialog;
+}
+
+
+/****************************************************************************/
+/****************************************************************************/
 /* Boilerplate Dialog Object stuff.                                         */
 /****************************************************************************/
+/****************************************************************************/
 guint
 gl_hig_dialog_get_type (void)
 {
@@ -234,10 +438,12 @@ gl_hig_dialog_add_widget (glHigDialog   *dialog,
        gtk_box_pack_start (GTK_BOX (dialog->vbox), widget, FALSE, FALSE, 0);
 }
 
-\f
+
+/****************************************************************************/
 /****************************************************************************/
 /* Boilerplate Category Object stuff.                                       */
 /****************************************************************************/
+/****************************************************************************/
 guint
 gl_hig_category_get_type (void)
 {
@@ -350,10 +556,11 @@ gl_hig_category_add_widget (glHigCategory *cat,
 }
 
 
-\f
+/****************************************************************************/
 /****************************************************************************/
 /* Boilerplate VBox Object stuff.                                           */
 /****************************************************************************/
+/****************************************************************************/
 guint
 gl_hig_vbox_get_type (void)
 {
@@ -454,10 +661,12 @@ gl_hig_vbox_add_widget (glHigVBox     *hig_vbox,
        gtk_box_pack_start (GTK_BOX (hig_vbox), widget, FALSE, FALSE, 0);
 }
 
-\f
+
+/****************************************************************************/
 /****************************************************************************/
 /* Boilerplate HBox Object stuff.                                           */
 /****************************************************************************/
+/****************************************************************************/
 guint
 gl_hig_hbox_get_type (void)
 {
index 4f1f70113fb71fa70906a62e4275c36c9489a5a2..c74df276927c38b8995802964f06d4e5dfd83cf5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  (GLABELS) Label and Business Card Creation program for GNOME
  *
- *  hig.h:  HIG inspired dialog and layout tools
+ *  hig.h:  HIG inspired dialogs and layout tools
  *
  *  Copyright (C) 2002  Jim Evins <evins@snaught.com>.
  *
@@ -30,6 +30,42 @@ G_BEGIN_DECLS
 #define GL_HIG_PAD1   6
 #define GL_HIG_PAD2  12
 
+
+/*===========================================================================*/
+/* HIG inspired alert.                                                       */
+/*===========================================================================*/
+
+#define GL_TYPE_HIG_ALERT (gl_hig_alert_get_type ())
+#define GL_HIG_ALERT(obj) \
+        (GTK_CHECK_CAST((obj), GL_TYPE_HIG_ALERT, glHigAlert ))
+#define GL_HIG_ALERT_CLASS(klass) \
+        (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_HIG_ALERT, glHigAlertClass))
+#define GL_IS_HIG_ALERT(obj) \
+        (GTK_CHECK_TYPE ((obj), GL_TYPE_HIG_ALERT))
+#define GL_IS_HIG_ALERT_CLASS(klass) \
+        (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_HIG_ALERT))
+
+typedef struct _glHigAlert      glHigAlert;
+typedef struct _glHigAlertClass glHigAlertClass;
+
+struct _glHigAlert {
+       GtkDialog         parent_widget;
+};
+
+struct _glHigAlertClass {
+       GtkDialogClass    parent_class;
+};
+
+guint      gl_hig_alert_get_type    (void);
+
+GtkWidget *gl_hig_alert_new         (GtkWindow      *parent,
+                                    GtkDialogFlags  flags,
+                                    GtkMessageType  type,
+                                    GtkButtonsType  buttons,
+                                    const gchar    *primary_text,
+                                    const gchar    *secondary_text);
+
+
 /*===========================================================================*/
 /* HIG Dialog wrapper.                                                       */
 /*===========================================================================*/
@@ -106,7 +142,6 @@ GtkWidget *gl_hig_category_new              (const gchar *header);
 void       gl_hig_category_add_widget       (glHigCategory *cat,
                                             GtkWidget     *widget);
 
-G_END_DECLS
 
 /*===========================================================================*/
 /* HIG VBOX wrapper.                                                         */
@@ -145,6 +180,7 @@ GtkWidget *gl_hig_vbox_new              (glHigVBoxType  type);
 void       gl_hig_vbox_add_widget       (glHigVBox     *hig_vbox,
                                         GtkWidget     *widget);
 
+
 /*===========================================================================*/
 /* HIG HBOX wrapper.                                                         */
 /*===========================================================================*/
@@ -180,6 +216,7 @@ void       gl_hig_hbox_add_widget         (glHigHBox     *hig_hbox,
 void       gl_hig_hbox_add_widget_justify (glHigHBox     *hig_hbox,
                                           GtkWidget     *widget);
 
+
 G_END_DECLS
 
 #endif /* __HIG_H__ */