]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmessagedialog.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkmessagedialog.c
index 14552874b9819042b303c9e6ffefa383b747b48f..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/>.
  */
 
 /*
@@ -33,8 +31,7 @@
 #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"
  * 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()
@@ -177,6 +178,8 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
   
   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;
   
@@ -292,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
@@ -338,15 +341,22 @@ 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_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
   priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
@@ -373,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);
 }
 
@@ -380,25 +392,30 @@ static void
 setup_primary_label_font (GtkMessageDialog *dialog)
 {
   GtkMessageDialogPrivate *priv = dialog->priv;
-  gint size;
-  PangoFontDescription *font_desc;
-  GtkStyleContext *context;
-  GtkStateFlags state;
 
-  /* 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
     {
-      context = gtk_widget_get_style_context (priv->label);
-      state = gtk_widget_get_state_flags (priv->label);
-
-      size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
-      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);
     }
 }
 
@@ -409,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:
@@ -438,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))
     {
@@ -576,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
@@ -585,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,
@@ -634,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>.
@@ -725,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;
@@ -787,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,
@@ -835,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,
@@ -1002,7 +1019,5 @@ gtk_message_dialog_style_updated (GtkWidget *widget)
                                       MAX (0, border_width - 7));
     }
 
-  setup_primary_label_font (dialog);
-
   GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);
 }