From d5ab45944d708756ac47476d4a0b538cb7728b06 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Parro Date: Tue, 26 Oct 2004 05:06:32 +0000 Subject: [PATCH] Fix for #118764, David Bordoley: 2004-10-25 Carlos Garnacho Parro Fix for #118764, David Bordoley: * gtk/gtkmessagedialog.[ch] (gtk_message_dialog_format_secondary_text), (gtk_message_dialog_format_secondary_format): API additions to create HIG-like dialogs * demos/gtk-demo/dialog.c: Use the new API in the example * docs/reference/gtk/gtk-sections.txt: * docs/reference/gtk/tmpl/gtkmessagedialog.sgml: documented API additions --- ChangeLog | 16 ++ ChangeLog.pre-2-10 | 16 ++ ChangeLog.pre-2-6 | 16 ++ ChangeLog.pre-2-8 | 16 ++ demos/gtk-demo/dialog.c | 5 +- docs/reference/gtk/gtk-sections.txt | 2 + docs/reference/gtk/tmpl/gtkmessagedialog.sgml | 20 ++ gtk/gtkmessagedialog.c | 202 ++++++++++++++++-- gtk/gtkmessagedialog.h | 13 +- 9 files changed, 287 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index eba389232b..0eb852d70c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-10-25 Carlos Garnacho Parro + + Fix for #118764, David Bordoley: + + * gtk/gtkmessagedialog.[ch] + (gtk_message_dialog_format_secondary_text), + (gtk_message_dialog_format_secondary_format): API additions to + create HIG-like dialogs + + * demos/gtk-demo/dialog.c: Use the new API in the example + + * docs/reference/gtk/gtk-sections.txt: + * docs/reference/gtk/tmpl/gtkmessagedialog.sgml: documented API + additions + 2004-10-25 James M. Cape Rework of GtkFileChooserButton, some cleanups. Fixes #154388, @@ -37,6 +52,7 @@ * gtk/.cvsignore: Ignore gtk-update-icon-cache. * tests/.cvsignore: Ignore testimage. +>>>>>>> 1.5960 2004-10-25 Matthias Clasen * gtk/gtkcellrenderercombo.c (find_text): Don't leak text. (#156325, diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index eba389232b..0eb852d70c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,18 @@ +2004-10-25 Carlos Garnacho Parro + + Fix for #118764, David Bordoley: + + * gtk/gtkmessagedialog.[ch] + (gtk_message_dialog_format_secondary_text), + (gtk_message_dialog_format_secondary_format): API additions to + create HIG-like dialogs + + * demos/gtk-demo/dialog.c: Use the new API in the example + + * docs/reference/gtk/gtk-sections.txt: + * docs/reference/gtk/tmpl/gtkmessagedialog.sgml: documented API + additions + 2004-10-25 James M. Cape Rework of GtkFileChooserButton, some cleanups. Fixes #154388, @@ -37,6 +52,7 @@ * gtk/.cvsignore: Ignore gtk-update-icon-cache. * tests/.cvsignore: Ignore testimage. +>>>>>>> 1.5960 2004-10-25 Matthias Clasen * gtk/gtkcellrenderercombo.c (find_text): Don't leak text. (#156325, diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index eba389232b..0eb852d70c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,18 @@ +2004-10-25 Carlos Garnacho Parro + + Fix for #118764, David Bordoley: + + * gtk/gtkmessagedialog.[ch] + (gtk_message_dialog_format_secondary_text), + (gtk_message_dialog_format_secondary_format): API additions to + create HIG-like dialogs + + * demos/gtk-demo/dialog.c: Use the new API in the example + + * docs/reference/gtk/gtk-sections.txt: + * docs/reference/gtk/tmpl/gtkmessagedialog.sgml: documented API + additions + 2004-10-25 James M. Cape Rework of GtkFileChooserButton, some cleanups. Fixes #154388, @@ -37,6 +52,7 @@ * gtk/.cvsignore: Ignore gtk-update-icon-cache. * tests/.cvsignore: Ignore testimage. +>>>>>>> 1.5960 2004-10-25 Matthias Clasen * gtk/gtkcellrenderercombo.c (find_text): Don't leak text. (#156325, diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index eba389232b..0eb852d70c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,18 @@ +2004-10-25 Carlos Garnacho Parro + + Fix for #118764, David Bordoley: + + * gtk/gtkmessagedialog.[ch] + (gtk_message_dialog_format_secondary_text), + (gtk_message_dialog_format_secondary_format): API additions to + create HIG-like dialogs + + * demos/gtk-demo/dialog.c: Use the new API in the example + + * docs/reference/gtk/gtk-sections.txt: + * docs/reference/gtk/tmpl/gtkmessagedialog.sgml: documented API + additions + 2004-10-25 James M. Cape Rework of GtkFileChooserButton, some cleanups. Fixes #154388, @@ -37,6 +52,7 @@ * gtk/.cvsignore: Ignore gtk-update-icon-cache. * tests/.cvsignore: Ignore testimage. +>>>>>>> 1.5960 2004-10-25 Matthias Clasen * gtk/gtkcellrenderercombo.c (find_text): Don't leak text. (#156325, diff --git a/demos/gtk-demo/dialog.c b/demos/gtk-demo/dialog.c index 0ba668c41f..bab1cd129c 100644 --- a/demos/gtk-demo/dialog.c +++ b/demos/gtk-demo/dialog.c @@ -22,8 +22,9 @@ message_dialog_clicked (GtkButton *button, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "This message box has been popped up the following\n" - "number of times:\n\n" - "%d", i); + "number of times:"); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + "%d", i); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); i++; diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index c8d165dca8..7820519c1f 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -2190,6 +2190,8 @@ GtkButtonsType gtk_message_dialog_new gtk_message_dialog_new_with_markup gtk_message_dialog_set_markup +gtk_message_dialog_format_secondary_text +gtk_message_dialog_format_secondary_markup GTK_MESSAGE_DIALOG GTK_IS_MESSAGE_DIALOG diff --git a/docs/reference/gtk/tmpl/gtkmessagedialog.sgml b/docs/reference/gtk/tmpl/gtkmessagedialog.sgml index f1bab03d0f..cb787b875d 100644 --- a/docs/reference/gtk/tmpl/gtkmessagedialog.sgml +++ b/docs/reference/gtk/tmpl/gtkmessagedialog.sgml @@ -144,3 +144,23 @@ then call gtk_dialog_add_buttons(). @str: + + + + + +@message_dialog: +@message_format: +@Varargs: + + + + + + + +@message_dialog: +@message_format: +@Varargs: + + diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c index 657453b1dd..7db998b90f 100644 --- a/gtk/gtkmessagedialog.c +++ b/gtk/gtkmessagedialog.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */ /* GTK - The GIMP Toolkit * Copyright (C) 2000 Red Hat, Inc. * @@ -35,6 +36,17 @@ #include "gtkintl.h" #include +#define GTK_MESSAGE_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_MESSAGE_DIALOG, GtkMessageDialogPrivate)) + +typedef struct _GtkMessageDialogPrivate GtkMessageDialogPrivate; + +struct _GtkMessageDialogPrivate +{ + GtkWidget *secondary_label; + gboolean has_primary_markup; + gboolean has_secondary_text; +}; + static void gtk_message_dialog_class_init (GtkMessageDialogClass *klass); static void gtk_message_dialog_init (GtkMessageDialog *dialog); static void gtk_message_dialog_style_set (GtkWidget *widget, @@ -51,6 +63,9 @@ static void gtk_message_dialog_get_property (GObject *object, static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog, GtkButtonsType buttons); +static void gtk_message_dialog_font_size_change (GtkWidget *widget, + GtkStyle *prev_style, + gpointer data); enum { PROP_0, @@ -109,7 +124,7 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class) P_("Width of border around the label and image in the message dialog"), 0, G_MAXINT, - 8, + 12, G_PARAM_READABLE)); /** * GtkMessageDialog::use_separator @@ -141,29 +156,49 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class) GTK_TYPE_BUTTONS_TYPE, GTK_BUTTONS_NONE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - + g_type_class_add_private (gobject_class, + sizeof (GtkMessageDialogPrivate)); } static void gtk_message_dialog_init (GtkMessageDialog *dialog) { - GtkWidget *hbox; + GtkWidget *hbox, *vbox; + GtkMessageDialogPrivate *priv; + + priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - + + priv->has_primary_markup = FALSE; + priv->has_secondary_text = FALSE; + priv->secondary_label = gtk_label_new (NULL); + dialog->label = gtk_label_new (NULL); dialog->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG); gtk_misc_set_alignment (GTK_MISC (dialog->image), 0.5, 0.0); - gtk_label_set_line_wrap (GTK_LABEL (dialog->label), TRUE); + gtk_label_set_line_wrap (GTK_LABEL (dialog->label), TRUE); gtk_label_set_selectable (GTK_LABEL (dialog->label), TRUE); + gtk_misc_set_alignment (GTK_MISC (dialog->label), 0.0, 0.0); - hbox = gtk_hbox_new (FALSE, 6); + gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE); + gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0); + + hbox = gtk_hbox_new (FALSE, 12); + vbox = gtk_vbox_new (FALSE, 12); + + gtk_box_pack_start (GTK_BOX (vbox), dialog->label, + FALSE, FALSE, 0); + + gtk_box_pack_start (GTK_BOX (vbox), priv->secondary_label, + TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), dialog->image, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), dialog->label, + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), @@ -173,6 +208,9 @@ gtk_message_dialog_init (GtkMessageDialog *dialog) gtk_widget_show_all (hbox); _gtk_dialog_set_ignore_separator (GTK_DIALOG (dialog), TRUE); + + g_signal_connect (G_OBJECT (dialog), "style-set", + G_CALLBACK (gtk_message_dialog_font_size_change), NULL); } static GtkMessageType @@ -204,6 +242,31 @@ gtk_message_dialog_get_message_type (GtkMessageDialog *dialog) } } +static void +setup_primary_label_font (GtkMessageDialog *dialog) +{ + gint size; + PangoFontDescription *font_desc; + GtkMessageDialogPrivate *priv; + + priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog); + + if (priv->has_primary_markup) + return; + + /* unset the font settings */ + gtk_widget_modify_font (dialog->label, NULL); + + if (priv->has_secondary_text) + { + size = pango_font_description_get_size (dialog->label->style->font_desc); + font_desc = pango_font_description_new (); + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE); + gtk_widget_modify_font (dialog->label, font_desc); + } +} + static void setup_type (GtkMessageDialog *dialog, GtkMessageType type) @@ -228,7 +291,7 @@ setup_type (GtkMessageDialog *dialog, case GTK_MESSAGE_ERROR: stock_id = GTK_STOCK_DIALOG_ERROR; break; - + default: g_warning ("Unknown GtkMessageType %d", type); break; @@ -293,6 +356,14 @@ gtk_message_dialog_get_property (GObject *object, } } +static void +gtk_message_dialog_font_size_change (GtkWidget *widget, + GtkStyle *prev_style, + gpointer data) +{ + setup_primary_label_font (GTK_MESSAGE_DIALOG (widget)); +} + /** * gtk_message_dialog_new: @@ -343,11 +414,10 @@ gtk_message_dialog_new (GtkWindow *parent, va_start (args, message_format); msg = g_strdup_vprintf (message_format, args); va_end (args); - - + gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->label), msg); - + g_free (msg); } @@ -416,8 +486,8 @@ gtk_message_dialog_new_with_markup (GtkWindow *parent, ...) { GtkWidget *widget; - gchar* msg = 0; va_list args; + gchar *msg = NULL; g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL); @@ -450,13 +520,117 @@ gtk_message_dialog_new_with_markup (GtkWindow *parent, **/ void gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog, - const gchar *str) + const gchar *str) { + GtkMessageDialogPrivate *priv; + g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog)); - + + priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog); + priv->has_primary_markup = TRUE; gtk_label_set_markup (GTK_LABEL (message_dialog->label), str); } +/** + * gtk_message_dialog_format_secondary_text: + * @message_dialog: a #GtkMessageDialog + * @message_format: printf()-style format string, or %NULL + * @Varargs: arguments for @message_format + * + * Sets the secondary text of the message dialog to be @message_format + * (with printf()-style). + * + * Note that setting a secondary text makes the primary text become + * bold, unless you have provided explicit markup. + * + * Since: 2.6 + **/ +void +gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog, + const gchar *message_format, + ...) +{ + va_list args; + gchar *msg = NULL; + GtkMessageDialogPrivate *priv; + + g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog)); + + priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog); + + if (message_format) + { + priv->has_secondary_text = TRUE; + + va_start (args, message_format); + msg = g_strdup_vprintf (message_format, args); + va_end (args); + + gtk_widget_show (priv->secondary_label); + gtk_label_set_text (GTK_LABEL (priv->secondary_label), msg); + + g_free (msg); + } + else + { + priv->has_secondary_text = FALSE; + gtk_widget_hide (priv->secondary_label); + } + + setup_primary_label_font (message_dialog); +} + +/** + * gtk_message_dialog_format_secondary_markup: + * @message_dialog: a #GtkMessageDialog + * @message_format: printf()-style markup string (see + Pango markup format), or %NULL + * @Varargs: arguments for @message_format + * + * Sets the secondary text of the message dialog to be @message_format (with + * printf()-style), which is marked up with the + * Pango text markup language. + * + * Note that setting a secondary text makes the primary text become + * bold, unless you have provided explicit markup. + * + * Since: 2.6 + **/ +void +gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog, + const gchar *message_format, + ...) +{ + va_list args; + gchar *msg = NULL; + GtkMessageDialogPrivate *priv; + + g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog)); + + priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (message_dialog); + + if (message_format) + { + priv->has_secondary_text = TRUE; + + va_start (args, message_format); + msg = g_strdup_vprintf (message_format, args); + va_end (args); + + gtk_widget_show (priv->secondary_label); + gtk_label_set_markup (GTK_LABEL (priv->secondary_label), msg); + + g_free (msg); + } + else + { + priv->has_secondary_text = FALSE; + gtk_widget_hide (priv->secondary_label); + } + + setup_primary_label_font (message_dialog); +} + static void gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog, GtkButtonsType buttons) diff --git a/gtk/gtkmessagedialog.h b/gtk/gtkmessagedialog.h index fe627c0c3e..479b91d714 100644 --- a/gtk/gtkmessagedialog.h +++ b/gtk/gtkmessagedialog.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */ /* GTK - The GIMP Toolkit * Copyright (C) 2000 Red Hat, Inc. * @@ -58,7 +59,6 @@ typedef enum #define GTK_IS_MESSAGE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MESSAGE_DIALOG)) #define GTK_MESSAGE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MESSAGE_DIALOG, GtkMessageDialogClass)) - typedef struct _GtkMessageDialog GtkMessageDialog; typedef struct _GtkMessageDialogClass GtkMessageDialogClass; @@ -99,9 +99,16 @@ GtkWidget* gtk_message_dialog_new_with_markup (GtkWindow *parent, const gchar *message_format, ...) G_GNUC_PRINTF (5, 6); - void gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog, - const gchar *str); + const gchar *str); + +void gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog, + const gchar *message_format, + ...) G_GNUC_PRINTF (2, 3); + +void gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog, + const gchar *message_format, + ...) G_GNUC_PRINTF (2, 3); #ifdef __cplusplus }