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"
34 static void gtk_message_dialog_class_init (GtkMessageDialogClass *klass);
35 static void gtk_message_dialog_init (GtkMessageDialog *dialog);
39 gtk_message_dialog_get_type (void)
41 static GtkType dialog_type = 0;
45 static const GtkTypeInfo dialog_info =
48 sizeof (GtkMessageDialog),
49 sizeof (GtkMessageDialogClass),
50 (GtkClassInitFunc) gtk_message_dialog_class_init,
51 (GtkObjectInitFunc) gtk_message_dialog_init,
52 /* reserved_1 */ NULL,
53 /* reserved_2 */ NULL,
54 (GtkClassInitFunc) NULL,
57 dialog_type = gtk_type_unique (GTK_TYPE_DIALOG, &dialog_info);
64 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
69 gtk_message_dialog_init (GtkMessageDialog *dialog)
73 dialog->label = gtk_label_new (NULL);
74 dialog->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
76 gtk_label_set_line_wrap (GTK_LABEL (dialog->label), TRUE);
78 hbox = gtk_hbox_new (FALSE, 10);
80 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
82 gtk_box_pack_start (GTK_BOX (hbox), dialog->image,
85 gtk_box_pack_start (GTK_BOX (hbox), dialog->label,
88 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
92 gtk_widget_show_all (hbox);
96 setup_type(GtkMessageDialog *dialog, GtkMessageType type)
98 /* Note: this function can be called more than once,
99 * and after showing the dialog, due to object args
102 const gchar *stock_id = NULL;
107 case GTK_MESSAGE_INFO:
108 stock_id = GTK_STOCK_DIALOG_INFO;
111 case GTK_MESSAGE_QUESTION:
112 stock_id = GTK_STOCK_DIALOG_QUESTION;
115 case GTK_MESSAGE_WARNING:
116 stock_id = GTK_STOCK_DIALOG_WARNING;
119 case GTK_MESSAGE_ERROR:
120 stock_id = GTK_STOCK_DIALOG_ERROR;
124 g_warning ("Unknown GtkMessageType %d", type);
128 if (stock_id == NULL)
129 stock_id = GTK_STOCK_DIALOG_INFO;
131 if (gtk_stock_lookup (stock_id, &item))
133 gtk_image_set_from_stock (GTK_IMAGE (dialog->image), stock_id,
134 GTK_ICON_SIZE_DIALOG);
136 gtk_window_set_title (GTK_WINDOW (dialog), item.label);
139 g_warning ("Stock dialog ID doesn't exist?");
143 * gtk_message_dialog_new:
144 * @parent: transient parent, or NULL for none
146 * @type: type of message
147 * @buttons: set of buttons to use
148 * @message_format: printf()-style format string, or NULL
149 * @Varargs: arguments for @message_format
151 * Creates a new message dialog, which is a simple dialog with an icon
152 * indicating the dialog type (error, warning, etc.) and some text the
153 * user may want to see. If the button set you select with the @buttons
154 * argument has positive buttons (OK, Yes) they will result in a response ID
155 * of GTK_RESPONSE_ACCEPT. If it has negative buttons (Cancel, No) they will
156 * result in a response ID of GTK_RESPONSE_REJECT. See #GtkDialog for more
159 * Return value: a new #GtkMessageDialog
162 gtk_message_dialog_new (GtkWindow *parent,
163 GtkDialogFlags flags,
165 GtkButtonsType buttons,
166 const gchar *message_format,
174 widget = GTK_WIDGET (gtk_type_new (GTK_TYPE_MESSAGE_DIALOG));
175 dialog = GTK_DIALOG (widget);
179 va_start (args, message_format);
180 msg = g_strdup_vprintf(message_format, args);
184 gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->label),
191 gtk_window_set_transient_for (GTK_WINDOW (widget),
192 GTK_WINDOW (parent));
195 if (flags & GTK_DIALOG_MODAL)
196 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
198 if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
199 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
201 setup_type (GTK_MESSAGE_DIALOG (dialog), type);
205 case GTK_BUTTONS_NONE:
210 gtk_dialog_add_button (dialog,
212 GTK_RESPONSE_ACCEPT);
215 case GTK_BUTTONS_CLOSE:
216 gtk_dialog_add_button (dialog,
217 GTK_STOCK_BUTTON_CLOSE,
218 GTK_RESPONSE_ACCEPT);
221 case GTK_BUTTONS_CANCEL:
222 gtk_dialog_add_button (dialog,
223 GTK_STOCK_BUTTON_CANCEL,
224 GTK_RESPONSE_REJECT);
227 case GTK_BUTTONS_YES_NO:
228 gtk_dialog_add_button (dialog,
229 GTK_STOCK_BUTTON_YES,
230 GTK_RESPONSE_ACCEPT);
231 gtk_dialog_add_button (dialog,
233 GTK_RESPONSE_REJECT);
236 case GTK_BUTTONS_OK_CANCEL:
237 gtk_dialog_add_button (dialog,
239 GTK_RESPONSE_ACCEPT);
240 gtk_dialog_add_button (dialog,
241 GTK_STOCK_BUTTON_CANCEL,
242 GTK_RESPONSE_REJECT);
246 g_warning ("Unknown GtkButtonsType");