]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmessagedialog.c
filechooserbutton: New test for opening the Other item in the combo box and then...
[~andy/gtk] / gtk / gtkmessagedialog.c
index 62bbe070cb57dbc39915bcff4b59babecf5e4bff..709fcfef0c86cf9710d6bf328bda3e0f398e24e0 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 
 /*
  */
 
 #include "config.h"
+
 #include <string.h>
 
 #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
  * 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 <link linkend="PangoMarkupFormat">Pango text markup language</link>.
@@ -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;
@@ -740,7 +769,7 @@ gtk_message_dialog_set_image (GtkMessageDialog *dialog,
  *
  * Gets the dialog's image.
  *
- * Return value: the dialog's image
+ * Return value: (transfer none): the dialog's image
  *
  * Since: 2.14
  **/
@@ -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
      <link linkend="PangoMarkupFormat">Pango markup format</link>), 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 
- * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
+ * @...: 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
+ * <link linkend="PangoMarkupFormat">Pango text markup language</link>.
  *
  * 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.
 
  * <informalexample><programlisting>
  * gchar *msg;
- *  
+ *
  * msg = g_markup_printf_escaped (message_format, ...);
  * gtk_message_dialog_format_secondary_markup (message_dialog, "&percnt;s", msg);
  * g_free (msg);
  * </programlisting></informalexample>
  *
  * Since: 2.6
- **/
+ */
 void
 gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
                                             const gchar      *message_format,
@@ -894,12 +917,15 @@ gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
  * gtk_message_dialog_get_message_area:
  * @message_dialog: a #GtkMessageDialog
  *
- * Return value: A #GtkVBox corresponding to the "message area" in the
- * @message_dialog.  This is the box where the dialog's primary and secondary
- * labels are packed.  You can add your own extra content to that box and it
- * will appear below those labels, on the right side of the dialog's image (or
- * on the left for right-to-left languages).  See gtk_dialog_get_content_area()
- * for the corresponding function in the parent #GtkDialog.
+ * Returns the message area of the dialog. This is the box where the
+ * dialog's primary and secondary labels are packed. You can add your
+ * own extra content to that box and it will appear below those labels,
+ * on the right side of the dialog's image (or on the left for right-to-left
+ * languages).  See gtk_dialog_get_content_area() for the corresponding
+ * function in the parent #GtkDialog.
+ *
+ * Return value: (transfer none): A #GtkVBox corresponding to the
+ *     "message area" in the @message_dialog.
  *
  * Since: 2.22
  **/
@@ -976,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;
@@ -989,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);
 }