* 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()
* </refsect2>
*/
-struct _GtkMessageDialogPriv
+struct _GtkMessageDialogPrivate
{
GtkWidget *image;
GtkWidget *label;
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,
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;
G_MAXINT,
12,
GTK_PARAM_READABLE));
- /**
- * GtkMessageDialog:use-separator:
- *
- * Whether to draw a separator line between the message label and the buttons
- * in the dialog.
- *
- * Since: 2.4
- */
- gtk_widget_class_install_style_property (widget_class,
- g_param_spec_boolean ("use-separator",
- P_("Use separator"),
- P_("Whether to put a separator between the message dialog's text and the buttons"),
- FALSE,
- GTK_PARAM_READABLE));
+
/**
* GtkMessageDialog:message-type:
*
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
GTK_TYPE_WIDGET,
GTK_PARAM_READABLE));
- g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPriv));
+ g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
}
static void
GtkWidget *hbox;
GtkDialog *message_dialog = GTK_DIALOG (dialog);
GtkWidget *action_area, *content_area;
- GtkMessageDialogPriv *priv;
+ GtkMessageDialogPrivate *priv;
dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
GTK_TYPE_MESSAGE_DIALOG,
- GtkMessageDialogPriv);
+ GtkMessageDialogPrivate);
priv = dialog->priv;
content_area = gtk_dialog_get_content_area (message_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);
gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
gtk_box_set_spacing (GTK_BOX (action_area), 6);
- gtk_widget_show_all (hbox);
+ gtk_message_dialog_style_updated (GTK_WIDGET (dialog));
- _gtk_dialog_set_ignore_separator (GTK_DIALOG (dialog), TRUE);
+ gtk_widget_show_all (hbox);
}
static void
setup_primary_label_font (GtkMessageDialog *dialog)
{
- GtkMessageDialogPriv *priv = dialog->priv;
- gint size;
- PangoFontDescription *font_desc;
+ GtkMessageDialogPrivate *priv = dialog->priv;
+
+ if (!priv->has_primary_markup)
+ {
+ PangoAttrList *attributes;
+ PangoAttribute *attr;
- /* unset the font settings */
- gtk_widget_modify_font (priv->label, NULL);
+ attributes = pango_attr_list_new ();
+
+ 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);
+ }
- if (priv->has_secondary_text && !priv->has_primary_markup)
+ gtk_label_set_attributes (GTK_LABEL (priv->label), attributes);
+ pango_attr_list_unref (attributes);
+ }
+ else
{
- size = pango_font_description_get_size (priv->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 (priv->label, font_desc);
- pango_font_description_free (font_desc);
+ /* unset the font settings */
+ gtk_label_set_attributes (GTK_LABEL (priv->label), NULL);
}
}
setup_type (GtkMessageDialog *dialog,
GtkMessageType type)
{
- GtkMessageDialogPriv *priv = dialog->priv;
+ 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:
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))
{
GParamSpec *pspec)
{
GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
- GtkMessageDialogPriv *priv = dialog->priv;
+ GtkMessageDialogPrivate *priv = dialog->priv;
switch (prop_id)
{
GParamSpec *pspec)
{
GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (object);
- GtkMessageDialogPriv *priv = dialog->priv;
+ GtkMessageDialogPrivate *priv = dialog->priv;
switch (prop_id)
{
* @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
* #GtkDialog for more details.
*
* Return value: (transfer none): a new #GtkMessageDialog
- **/
+ */
GtkWidget*
gtk_message_dialog_new (GtkWindow *parent,
GtkDialogFlags flags,
NULL);
dialog = GTK_DIALOG (widget);
- if (flags & GTK_DIALOG_NO_SEPARATOR)
- {
- g_warning ("The GTK_DIALOG_NO_SEPARATOR flag cannot be used for GtkMessageDialog");
- flags &= ~GTK_DIALOG_NO_SEPARATOR;
- }
-
if (message_format)
{
va_start (args, message_format);
/**
* 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>.
gtk_message_dialog_set_image (GtkMessageDialog *dialog,
GtkWidget *image)
{
- GtkMessageDialogPriv *priv;
+ GtkMessageDialogPrivate *priv;
GtkWidget *parent;
g_return_if_fail (GTK_IS_MESSAGE_DIALOG (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;
- parent = priv->image->parent;
+ parent = gtk_widget_get_parent (priv->image);
gtk_container_add (GTK_CONTAINER (parent), image);
gtk_container_remove (GTK_CONTAINER (parent), priv->image);
gtk_box_reorder_child (GTK_BOX (parent), image, 0);
*
* Gets the dialog's image.
*
- * Return value: the dialog's image
+ * Return value: (transfer none): the dialog's image
*
* Since: 2.14
**/
gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
const gchar *str)
{
- GtkMessageDialogPriv *priv;
+ GtkMessageDialogPrivate *priv;
g_return_if_fail (GTK_IS_MESSAGE_DIALOG (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,
{
va_list args;
gchar *msg = NULL;
- GtkMessageDialogPriv *priv;
+ GtkMessageDialogPrivate *priv;
g_return_if_fail (GTK_IS_MESSAGE_DIALOG (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, "%s", msg);
* g_free (msg);
* </programlisting></informalexample>
*
* Since: 2.6
- **/
+ */
void
gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
const gchar *message_format,
{
va_list args;
gchar *msg = NULL;
- GtkMessageDialogPriv *priv;
+ GtkMessageDialogPrivate *priv;
g_return_if_fail (GTK_IS_MESSAGE_DIALOG (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
**/
}
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);
- gboolean use_separator;
GtkWidget *parent;
gint border_width;
- parent = gtk_message_dialog_get_image (GTK_MESSAGE_DIALOG (widget))->parent;
+ parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
if (parent)
{
gtk_widget_style_get (widget, "message-border",
&border_width, NULL);
-
+
gtk_container_set_border_width (GTK_CONTAINER (parent),
MAX (0, border_width - 7));
}
- gtk_widget_style_get (widget,
- "use-separator", &use_separator,
- NULL);
-
- _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), FALSE);
- gtk_dialog_set_has_separator (GTK_DIALOG (widget), use_separator);
- _gtk_dialog_set_ignore_separator (GTK_DIALOG (widget), TRUE);
-
- 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);
}