2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999,2000 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
28 #include "alertpanel.h"
29 #include "manage_window.h"
33 #define TITLE_FONT "-*-helvetica-medium-r-normal--17-*-*-*-*-*-*-*," \
34 "-*-*-medium-r-normal--16-*-*-*-*-*-*-*,*"
35 #define MESSAGE_FONT "-*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*," \
36 "-*-*-medium-r-normal--14-*-*-*-*-*-*-*,*"
37 #define ALERT_PANEL_WIDTH 380
38 #define TITLE_HEIGHT 72
39 #define MESSAGE_HEIGHT 62
41 static gboolean alertpanel_is_open = FALSE;
42 static AlertValue value;
44 static GtkWidget *dialog;
46 static void alertpanel_show (void);
47 static void alertpanel_create (const gchar *title,
49 const gchar *button1_label,
50 const gchar *button2_label,
51 const gchar *button3_label);
52 static void alertpanel_button_clicked (GtkWidget *widget,
54 static void alertpanel_close (GtkWidget *widget,
58 AlertValue alertpanel(const gchar *title,
60 const gchar *button1_label,
61 const gchar *button2_label,
62 const gchar *button3_label)
64 if (alertpanel_is_open)
67 alertpanel_is_open = TRUE;
69 alertpanel_create(title, message, button1_label, button2_label,
73 debug_print("return value = %d\n", value);
77 void alertpanel_message(const gchar *title, const gchar *message)
79 if (alertpanel_is_open)
82 alertpanel_is_open = TRUE;
84 alertpanel_create(title, message, NULL, NULL, NULL);
88 void alertpanel_notice(const gchar *format, ...)
93 va_start(args, format);
94 g_vsnprintf(buf, sizeof(buf), format, args);
98 alertpanel_message(_("Notice"), buf);
101 void alertpanel_warning(const gchar *format, ...)
106 va_start(args, format);
107 g_vsnprintf(buf, sizeof(buf), format, args);
111 alertpanel_message(_("Warning"), buf);
114 void alertpanel_error(const gchar *format, ...)
119 va_start(args, format);
120 g_vsnprintf(buf, sizeof(buf), format, args);
124 alertpanel_message(_("Error"), buf);
127 static void alertpanel_show(void)
129 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
130 manage_window_set_transient(GTK_WINDOW(dialog));
133 while (value == G_ALERTWAIT)
134 gtk_main_iteration();
136 gtk_widget_destroy(dialog);
139 alertpanel_is_open = FALSE;
142 static void alertpanel_create(const gchar *title,
143 const gchar *message,
144 const gchar *button1_label,
145 const gchar *button2_label,
146 const gchar *button3_label)
148 static GdkFont *titlefont;
153 GtkWidget *confirm_area;
160 debug_print(_("Creating alert panel dialog...\n"));
162 dialog = gtk_dialog_new();
163 gtk_window_set_title(GTK_WINDOW(dialog), title);
164 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
165 gtk_container_set_border_width
166 (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
167 gtk_window_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
168 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
169 GTK_SIGNAL_FUNC(alertpanel_close),
170 (gpointer)G_ALERTOTHER);
171 gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
172 GTK_SIGNAL_FUNC(alertpanel_close),
173 (gpointer)G_ALERTOTHER);
174 gtk_widget_realize(dialog);
176 /* for title label */
177 hbox = gtk_hbox_new(FALSE, 0);
178 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
179 hbox, TRUE, TRUE, 16);
182 //pixmapwid = create_pixmapwid(dialog, GNUstep_xpm);
183 //gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16);
184 label = gtk_label_new(title);
185 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 16);
186 style = gtk_style_copy(gtk_widget_get_style(label));
188 titlefont = gdk_fontset_load(TITLE_FONT);
190 style->font = titlefont;
191 gtk_widget_set_style(label, style);
193 /* for message and button(s) */
194 vbox = gtk_vbox_new(FALSE, 0);
195 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
198 /* for message label */
199 hbox = gtk_hbox_new(FALSE, 0);
200 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 20);
203 label = gtk_label_new(message);
204 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 32);
205 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
209 button1_label = _("OK");
210 label2 = button2_label;
211 label3 = button3_label;
212 if (label2 && *label2 == '+') label2++;
213 if (label3 && *label3 == '+') label3++;
215 gtkut_button_set_create(&confirm_area,
216 &button1, button1_label,
217 button2_label ? &button2 : NULL, label2,
218 button3_label ? &button3 : NULL, label3);
220 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
221 gtk_widget_grab_default(button1);
222 gtk_widget_grab_focus(button1);
223 if (button2_label && *button2_label == '+') {
224 gtk_widget_grab_default(button2);
225 gtk_widget_grab_focus(button2);
227 if (button3_label && *button3_label == '+') {
228 gtk_widget_grab_default(button3);
229 gtk_widget_grab_focus(button3);
232 gtk_signal_connect(GTK_OBJECT(button1), "clicked",
233 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
234 (gpointer)G_ALERTDEFAULT);
236 gtk_signal_connect(GTK_OBJECT(button2), "clicked",
237 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
238 (gpointer)G_ALERTALTERNATE);
240 gtk_signal_connect(GTK_OBJECT(button3), "clicked",
241 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
242 (gpointer)G_ALERTOTHER);
244 gtk_widget_show_all(dialog);
247 static void alertpanel_button_clicked(GtkWidget *widget, gpointer data)
249 value = (AlertValue)data;
252 static void alertpanel_close(GtkWidget *widget, GdkEventAny *event,
255 if (event->type == GDK_KEY_PRESS)
256 if (((GdkEventKey *)event)->keyval != GDK_Escape)
259 value = (AlertValue)data;