1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #include "gtkmessagedialog.h"
32 #include "gtkiconfactory.h"
35 static void gtk_message_dialog_class_init (GtkMessageDialogClass *klass);
36 static void gtk_message_dialog_init (GtkMessageDialog *dialog);
37 static void gtk_message_dialog_style_set (GtkWidget *widget,
38 GtkStyle *prev_style);
40 static gpointer parent_class;
43 gtk_message_dialog_get_type (void)
45 static GtkType dialog_type = 0;
49 static const GtkTypeInfo dialog_info =
52 sizeof (GtkMessageDialog),
53 sizeof (GtkMessageDialogClass),
54 (GtkClassInitFunc) gtk_message_dialog_class_init,
55 (GtkObjectInitFunc) gtk_message_dialog_init,
56 /* reserved_1 */ NULL,
57 /* reserved_2 */ NULL,
58 (GtkClassInitFunc) NULL,
61 dialog_type = gtk_type_unique (GTK_TYPE_DIALOG, &dialog_info);
68 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
70 GtkWidgetClass *widget_class;
72 widget_class = GTK_WIDGET_CLASS (class);
74 parent_class = g_type_class_peek_parent (class);
76 widget_class->style_set = gtk_message_dialog_style_set;
78 gtk_widget_class_install_style_property (widget_class,
79 g_param_spec_int ("message_border",
80 _("Image/label border"),
81 _("Width of border around the label and image in the message dialog"),
89 gtk_message_dialog_init (GtkMessageDialog *dialog)
93 dialog->label = gtk_label_new (NULL);
94 dialog->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
96 gtk_label_set_line_wrap (GTK_LABEL (dialog->label), TRUE);
97 gtk_label_set_selectable (GTK_LABEL (dialog->label), TRUE);
99 hbox = gtk_hbox_new (FALSE, 6);
101 gtk_box_pack_start (GTK_BOX (hbox), dialog->image,
104 gtk_box_pack_start (GTK_BOX (hbox), dialog->label,
107 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
111 gtk_widget_show_all (hbox);
115 setup_type(GtkMessageDialog *dialog, GtkMessageType type)
117 /* Note: this function can be called more than once,
118 * and after showing the dialog, due to object args
121 const gchar *stock_id = NULL;
126 case GTK_MESSAGE_INFO:
127 stock_id = GTK_STOCK_DIALOG_INFO;
130 case GTK_MESSAGE_QUESTION:
131 stock_id = GTK_STOCK_DIALOG_QUESTION;
134 case GTK_MESSAGE_WARNING:
135 stock_id = GTK_STOCK_DIALOG_WARNING;
138 case GTK_MESSAGE_ERROR:
139 stock_id = GTK_STOCK_DIALOG_ERROR;
143 g_warning ("Unknown GtkMessageType %d", type);
147 if (stock_id == NULL)
148 stock_id = GTK_STOCK_DIALOG_INFO;
150 if (gtk_stock_lookup (stock_id, &item))
152 gtk_image_set_from_stock (GTK_IMAGE (dialog->image), stock_id,
153 GTK_ICON_SIZE_DIALOG);
155 gtk_window_set_title (GTK_WINDOW (dialog), item.label);
158 g_warning ("Stock dialog ID doesn't exist?");
162 * gtk_message_dialog_new:
163 * @parent: transient parent, or NULL for none
165 * @type: type of message
166 * @buttons: set of buttons to use
167 * @message_format: printf()-style format string, or NULL
168 * @Varargs: arguments for @message_format
170 * Creates a new message dialog, which is a simple dialog with an icon
171 * indicating the dialog type (error, warning, etc.) and some text the
172 * user may want to see. When the user clicks a button a "response"
173 * signal is emitted with response IDs from #GtkResponseType. See
174 * #GtkDialog for more details.
176 * Return value: a new #GtkMessageDialog
179 gtk_message_dialog_new (GtkWindow *parent,
180 GtkDialogFlags flags,
182 GtkButtonsType buttons,
183 const gchar *message_format,
191 widget = GTK_WIDGET (gtk_type_new (GTK_TYPE_MESSAGE_DIALOG));
192 dialog = GTK_DIALOG (widget);
196 va_start (args, message_format);
197 msg = g_strdup_vprintf(message_format, args);
201 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->label),
208 gtk_window_set_transient_for (GTK_WINDOW (widget),
209 GTK_WINDOW (parent));
212 if (flags & GTK_DIALOG_MODAL)
213 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
215 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
216 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
218 if (flags & GTK_DIALOG_NO_SEPARATOR)
219 gtk_dialog_set_has_separator (dialog, FALSE);
221 setup_type (GTK_MESSAGE_DIALOG (dialog), type);
225 case GTK_BUTTONS_NONE:
230 gtk_dialog_add_button (dialog,
235 case GTK_BUTTONS_CLOSE:
236 gtk_dialog_add_button (dialog,
241 case GTK_BUTTONS_CANCEL:
242 gtk_dialog_add_button (dialog,
244 GTK_RESPONSE_CANCEL);
247 case GTK_BUTTONS_YES_NO:
248 gtk_dialog_add_button (dialog,
251 gtk_dialog_add_button (dialog,
256 case GTK_BUTTONS_OK_CANCEL:
257 gtk_dialog_add_button (dialog,
259 GTK_RESPONSE_CANCEL);
260 gtk_dialog_add_button (dialog,
266 g_warning ("Unknown GtkButtonsType");
274 gtk_message_dialog_style_set (GtkWidget *widget,
275 GtkStyle *prev_style)
278 gint border_width = 0;
280 parent = GTK_WIDGET (GTK_MESSAGE_DIALOG (widget)->image->parent);
284 gtk_widget_style_get (widget, "message_border",
285 &border_width, NULL);
287 gtk_container_set_border_width (GTK_CONTAINER (parent),
291 if (GTK_WIDGET_CLASS (parent_class)->style_set)
292 (GTK_WIDGET_CLASS (parent_class)->style_set) (widget, prev_style);