X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkmessagedialog.c;h=709fcfef0c86cf9710d6bf328bda3e0f398e24e0;hb=ce0675f1fb2582717793ec29b1787039dfbf8437;hp=d8fa79a28cb68980469a310871670a81a96a7269;hpb=e0aa12eb0ab8d20a2bc9de7d89c779d3566ee669;p=~andy%2Fgtk diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c index d8fa79a28..709fcfef0 100644 --- a/gtk/gtkmessagedialog.c +++ b/gtk/gtkmessagedialog.c @@ -13,9 +13,7 @@ * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ /* @@ -26,19 +24,20 @@ */ #include "config.h" + #include #include "gtkmessagedialog.h" #include "gtkaccessible.h" #include "gtkbuildable.h" #include "gtklabel.h" -#include "gtkhbox.h" -#include "gtkvbox.h" +#include "gtkbox.h" #include "gtkimage.h" #include "gtkstock.h" #include "gtkiconfactory.h" #include "gtkintl.h" #include "gtkprivate.h" +#include "gtktypebuiltins.h" /** * SECTION:gtkmessagedialog @@ -51,6 +50,10 @@ * convenience widget; you could construct the equivalent of #GtkMessageDialog * from #GtkDialog without too much effort, but #GtkMessageDialog saves typing. * + * One difference from #GtkDialog is that #GtkMessageDialog sets the + * #GtkWindow:skip-taskbar-hint property to %TRUE, so that the dialog is hidden + * from the taskbar by default. + * * The easiest way to do a modal message dialog is to use gtk_dialog_run(), though * you can also pass in the %GTK_DIALOG_MODAL flag, gtk_dialog_run() automatically * makes the dialog modal and waits for the user to respond to it. gtk_dialog_run() @@ -107,8 +110,7 @@ struct _GtkMessageDialogPrivate guint message_type : 3; }; -static void gtk_message_dialog_style_set (GtkWidget *widget, - GtkStyle *prev_style); +static void gtk_message_dialog_style_updated (GtkWidget *widget); static void gtk_message_dialog_set_property (GObject *object, guint prop_id, @@ -174,7 +176,9 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class) widget_class = GTK_WIDGET_CLASS (class); gobject_class = G_OBJECT_CLASS (class); - widget_class->style_set = gtk_message_dialog_style_set; + widget_class->style_updated = gtk_message_dialog_style_updated; + + gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ALERT); gobject_class->set_property = gtk_message_dialog_set_property; gobject_class->get_property = gtk_message_dialog_get_property; @@ -291,7 +295,7 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class) GTK_PARAM_READWRITE)); /** - * GtkMessageDialog:message-area + * GtkMessageDialog:message-area: * * The #GtkVBox that corresponds to the message area of this dialog. See * gtk_message_dialog_get_message_area() for a detailed description of this @@ -337,18 +341,25 @@ gtk_message_dialog_init (GtkMessageDialog *dialog) priv->label = gtk_label_new (NULL); priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (priv->image), 0.5, 0.0); - + g_object_set (priv->image, "use-fallback", TRUE, NULL); + gtk_widget_set_halign (priv->image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (priv->image, GTK_ALIGN_START); + gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE); gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE); - gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0); - + gtk_widget_set_halign (priv->label, GTK_ALIGN_START); + gtk_widget_set_valign (priv->label, GTK_ALIGN_START); + 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); + gtk_widget_set_halign (priv->secondary_label, GTK_ALIGN_START); + gtk_widget_set_valign (priv->secondary_label, GTK_ALIGN_START); + + gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0); + gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0); - hbox = gtk_hbox_new (FALSE, 12); - priv->message_area = gtk_vbox_new (FALSE, 12); + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label, FALSE, FALSE, 0); @@ -372,6 +383,8 @@ gtk_message_dialog_init (GtkMessageDialog *dialog) gtk_container_set_border_width (GTK_CONTAINER (action_area), 5); gtk_box_set_spacing (GTK_BOX (action_area), 6); + gtk_message_dialog_style_updated (GTK_WIDGET (dialog)); + gtk_widget_show_all (hbox); } @@ -379,20 +392,30 @@ static void setup_primary_label_font (GtkMessageDialog *dialog) { GtkMessageDialogPrivate *priv = dialog->priv; - gint size; - PangoFontDescription *font_desc; - /* unset the font settings */ - gtk_widget_modify_font (priv->label, NULL); + if (!priv->has_primary_markup) + { + PangoAttrList *attributes; + PangoAttribute *attr; + + attributes = pango_attr_list_new (); - if (priv->has_secondary_text && !priv->has_primary_markup) + attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); + pango_attr_list_insert (attributes, attr); + + if (priv->has_secondary_text) + { + attr = pango_attr_scale_new (PANGO_SCALE_LARGE); + pango_attr_list_insert (attributes, attr); + } + + gtk_label_set_attributes (GTK_LABEL (priv->label), attributes); + pango_attr_list_unref (attributes); + } + else { - size = pango_font_description_get_size (gtk_widget_get_style (priv->label)->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 (priv->label, font_desc); - pango_font_description_free (font_desc); + /* unset the font settings */ + gtk_label_set_attributes (GTK_LABEL (priv->label), NULL); } } @@ -403,25 +426,30 @@ setup_type (GtkMessageDialog *dialog, GtkMessageDialogPrivate *priv = dialog->priv; const gchar *stock_id = NULL; AtkObject *atk_obj; - + GIcon *gicon = NULL; + priv->message_type = type; switch (type) { case GTK_MESSAGE_INFO: stock_id = GTK_STOCK_DIALOG_INFO; + gicon = g_themed_icon_new_with_default_fallbacks ("dialog-information-symbolic"); break; case GTK_MESSAGE_QUESTION: stock_id = GTK_STOCK_DIALOG_QUESTION; + gicon = g_themed_icon_new_with_default_fallbacks ("dialog-question-symbolic"); break; case GTK_MESSAGE_WARNING: stock_id = GTK_STOCK_DIALOG_WARNING; + gicon = g_themed_icon_new_with_default_fallbacks ("dialog-warning-symbolic"); break; - + case GTK_MESSAGE_ERROR: stock_id = GTK_STOCK_DIALOG_ERROR; + gicon = g_themed_icon_new_with_default_fallbacks ("dialog-error-symbolic"); break; case GTK_MESSAGE_OTHER: @@ -432,10 +460,10 @@ setup_type (GtkMessageDialog *dialog, break; } - if (stock_id) - gtk_image_set_from_stock (GTK_IMAGE (priv->image), stock_id, - GTK_ICON_SIZE_DIALOG); - + gtk_image_set_from_gicon (GTK_IMAGE (priv->image), gicon, GTK_ICON_SIZE_DIALOG); + if (gicon) + g_object_unref (gicon); + atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dialog)); if (GTK_IS_ACCESSIBLE (atk_obj)) { @@ -570,7 +598,7 @@ gtk_message_dialog_get_property (GObject *object, * @type: type of message * @buttons: set of buttons to use * @message_format: (allow-none): printf()-style format string, or %NULL - * @Varargs: arguments for @message_format + * @...: arguments for @message_format * * Creates a new message dialog, which is a simple dialog with an icon * indicating the dialog type (error, warning, etc.) and some text the @@ -579,7 +607,7 @@ gtk_message_dialog_get_property (GObject *object, * #GtkDialog for more details. * * Return value: (transfer none): a new #GtkMessageDialog - **/ + */ GtkWidget* gtk_message_dialog_new (GtkWindow *parent, GtkDialogFlags flags, @@ -628,13 +656,13 @@ gtk_message_dialog_new (GtkWindow *parent, /** * gtk_message_dialog_new_with_markup: - * @parent: (allow-none): transient parent, or %NULL for none + * @parent: (allow-none): transient parent, or %NULL for none * @flags: flags * @type: type of message * @buttons: set of buttons to use * @message_format: (allow-none): printf()-style format string, or %NULL - * @Varargs: arguments for @message_format - * + * @...: arguments for @message_format + * * Creates a new message dialog, which is a simple dialog with an icon * indicating the dialog type (error, warning, etc.) and some text which * is marked up with the Pango text markup language. @@ -719,7 +747,8 @@ gtk_message_dialog_set_image (GtkMessageDialog *dialog, if (image == NULL) { image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); + gtk_widget_set_halign (image, GTK_ALIGN_CENTER); + gtk_widget_set_valign (image, GTK_ALIGN_START); } priv->message_type = GTK_MESSAGE_OTHER; @@ -781,16 +810,13 @@ gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog, * gtk_message_dialog_format_secondary_text: * @message_dialog: a #GtkMessageDialog * @message_format: (allow-none): 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). + * @...: arguments for @message_format * - * Note that setting a secondary text makes the primary text become - * bold, unless you have provided explicit markup. + * Sets the secondary text of the message dialog to be @message_format + * (with printf()-style). * * Since: 2.6 - **/ + */ void gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog, const gchar *message_format, @@ -829,32 +855,29 @@ gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog, /** * gtk_message_dialog_format_secondary_markup: * @message_dialog: a #GtkMessageDialog - * @message_format: printf()-style markup string (see + * @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. + * @...: arguments for @message_format * - * Note that setting a secondary text makes the primary text become - * bold, unless you have provided explicit markup. + * 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. * * Due to an oversight, this function does not escape special XML characters - * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments + * like gtk_message_dialog_new_with_markup() does. Thus, if the arguments * may contain special XML characters, you should use g_markup_printf_escaped() * to escape it. * * gchar *msg; - * + * * msg = g_markup_printf_escaped (message_format, ...); * gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg); * g_free (msg); * * * Since: 2.6 - **/ + */ void gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog, const gchar *message_format, @@ -979,8 +1002,7 @@ gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog, } static void -gtk_message_dialog_style_set (GtkWidget *widget, - GtkStyle *prev_style) +gtk_message_dialog_style_updated (GtkWidget *widget) { GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget); GtkWidget *parent; @@ -992,12 +1014,10 @@ gtk_message_dialog_style_set (GtkWidget *widget, { gtk_widget_style_get (widget, "message-border", &border_width, NULL); - + gtk_container_set_border_width (GTK_CONTAINER (parent), MAX (0, border_width - 7)); } - setup_primary_label_font (dialog); - - GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_set (widget, prev_style); + GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget); }