2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 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.
26 #include <gdk/gdkkeysyms.h>
29 #include "mainwindow.h"
30 #include "alertpanel.h"
31 #include "manage_window.h"
35 #include "logwindow.h"
37 #define TITLE_FONT "-*-helvetica-medium-r-normal--17-*-*-*-*-*-*-*," \
38 "-*-*-medium-r-normal--16-*-*-*-*-*-*-*,*"
39 #define MESSAGE_FONT "-*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*," \
40 "-*-*-medium-r-normal--14-*-*-*-*-*-*-*,*"
41 #define ALERT_PANEL_WIDTH 380
42 #define TITLE_HEIGHT 72
43 #define MESSAGE_HEIGHT 62
45 static gboolean alertpanel_is_open = FALSE;
46 static AlertValue value;
48 static GtkWidget *dialog;
50 static void alertpanel_show (void);
51 static void alertpanel_create (const gchar *title,
53 const gchar *button1_label,
54 const gchar *button2_label,
55 const gchar *button3_label,
57 GtkWidget *custom_widget);
59 static void alertpanel_button_toggled (GtkToggleButton *button,
61 static void alertpanel_button_clicked (GtkWidget *widget,
63 static gint alertpanel_deleted (GtkWidget *widget,
66 static void alertpanel_close (GtkWidget *widget,
70 AlertValue alertpanel(const gchar *title,
72 const gchar *button1_label,
73 const gchar *button2_label,
74 const gchar *button3_label)
76 if (alertpanel_is_open)
79 alertpanel_is_open = TRUE;
81 alertpanel_create(title, message, button1_label, button2_label,
82 button3_label, FALSE, NULL);
85 debug_print("return value = %d\n", value);
89 AlertValue alertpanel_with_widget(const gchar *title,
91 const gchar *button1_label,
92 const gchar *button2_label,
93 const gchar *button3_label,
96 if (alertpanel_is_open)
99 alertpanel_is_open = TRUE;
100 alertpanel_create(title, message, button1_label, button2_label,
101 button3_label, FALSE, widget);
104 debug_print("return value = %d\n", value);
107 void alertpanel_message(const gchar *title, const gchar *message)
109 if (alertpanel_is_open)
112 alertpanel_is_open = TRUE;
114 alertpanel_create(title, message, NULL, NULL, NULL, FALSE, NULL);
118 AlertValue alertpanel_message_with_disable(const gchar *title,
119 const gchar *message)
121 if (alertpanel_is_open)
124 alertpanel_is_open = TRUE;
126 alertpanel_create(title, message, NULL, NULL, NULL, TRUE, NULL);
132 void alertpanel_notice(const gchar *format, ...)
137 va_start(args, format);
138 g_vsnprintf(buf, sizeof(buf), format, args);
142 alertpanel_message(_("Notice"), buf);
145 void alertpanel_warning(const gchar *format, ...)
150 va_start(args, format);
151 g_vsnprintf(buf, sizeof(buf), format, args);
155 alertpanel_message(_("Warning"), buf);
158 void alertpanel_error(const gchar *format, ...)
163 va_start(args, format);
164 g_vsnprintf(buf, sizeof(buf), format, args);
168 alertpanel_message(_("Error"), buf);
172 *\brief display an error with a View Log button
175 void alertpanel_error_log(const gchar *format, ...)
182 va_start(args, format);
183 g_vsnprintf(buf, sizeof(buf), format, args);
187 mainwin = mainwindow_get_mainwindow();
189 if (mainwin && mainwin->logwin) {
190 val = alertpanel(_("Error"), buf, _("OK"), _("View log"), NULL);
191 if (val == G_ALERTALTERNATE)
192 log_window_show(mainwin->logwin);
194 alertpanel_error(buf);
197 static void alertpanel_show(void)
199 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
200 manage_window_set_transient(GTK_WINDOW(dialog));
203 if (gdk_pointer_is_grabbed())
204 gdk_pointer_ungrab(GDK_CURRENT_TIME);
206 while ((value & G_ALERT_VALUE_MASK) == G_ALERTWAIT)
207 gtk_main_iteration();
209 gtk_widget_destroy(dialog);
212 alertpanel_is_open = FALSE;
216 static void alertpanel_create(const gchar *title,
217 const gchar *message,
218 const gchar *button1_label,
219 const gchar *button2_label,
220 const gchar *button3_label,
221 gboolean can_disable,
222 GtkWidget *custom_widget)
224 static GdkFont *titlefont;
231 GtkWidget *disable_chkbtn;
232 GtkWidget *confirm_area;
239 debug_print("Creating alert panel dialog...\n");
241 dialog = gtk_dialog_new();
242 gtk_window_set_title(GTK_WINDOW(dialog), title);
243 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
244 gtk_container_set_border_width
245 (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
246 gtk_window_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
247 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
248 GTK_SIGNAL_FUNC(alertpanel_deleted),
249 (gpointer)G_ALERTOTHER);
250 gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
251 GTK_SIGNAL_FUNC(alertpanel_close),
252 (gpointer)G_ALERTOTHER);
253 gtk_widget_realize(dialog);
255 /* for title label */
256 hbox = gtk_hbox_new(FALSE, 0);
257 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
258 hbox, TRUE, TRUE, 16);
261 /* pixmapwid = create_pixmapwid(dialog, GNUstep_xpm); */
262 /* gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16); */
263 label = gtk_label_new(title);
264 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 16);
265 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
266 style = gtk_style_copy(gtk_widget_get_style(label));
268 titlefont = gtkut_font_load(TITLE_FONT);
270 style->font = titlefont;
271 gtk_widget_set_style(label, style);
273 /* for message and button(s) */
274 vbox = gtk_vbox_new(FALSE, 0);
275 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
278 spc_vbox = gtk_vbox_new(FALSE, 0);
279 gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
280 gtk_widget_set_usize(spc_vbox, -1, 16);
282 msg_vbox = gtk_vbox_new(FALSE, 0);
283 gtk_box_pack_start(GTK_BOX(vbox), msg_vbox, FALSE, FALSE, 0);
285 /* for message label */
286 hbox = gtk_hbox_new(FALSE, 0);
287 gtk_box_pack_start(GTK_BOX(msg_vbox), hbox, FALSE, FALSE, 0);
290 label = gtk_label_new(message);
291 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 24);
292 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
294 /* Claws: custom widget */
296 GtkWidget *custom_hbox = gtk_hbox_new(FALSE, 0);
297 gtk_box_pack_start(GTK_BOX(msg_vbox), custom_hbox, FALSE,
299 gtk_box_pack_start(GTK_BOX(custom_hbox), custom_widget, FALSE,
303 hbox = gtk_hbox_new(FALSE, 0);
304 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
305 gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
307 disable_chkbtn = gtk_check_button_new_with_label
308 (_("Show this message next time"));
309 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
311 gtk_box_pack_start(GTK_BOX(hbox), disable_chkbtn,
313 gtk_signal_connect(GTK_OBJECT(disable_chkbtn), "toggled",
314 GTK_SIGNAL_FUNC(alertpanel_button_toggled),
315 GUINT_TO_POINTER(G_ALERTDISABLE));
317 spc_vbox = gtk_vbox_new(FALSE, 0);
318 gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
319 gtk_widget_set_usize(spc_vbox, -1, 20);
324 button1_label = _("OK");
325 label2 = button2_label;
326 label3 = button3_label;
327 if (label2 && *label2 == '+') label2++;
328 if (label3 && *label3 == '+') label3++;
330 gtkut_button_set_create(&confirm_area,
331 &button1, button1_label,
332 button2_label ? &button2 : NULL, label2,
333 button3_label ? &button3 : NULL, label3);
335 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
336 gtk_widget_grab_default(button1);
337 gtk_widget_grab_focus(button1);
338 if (button2_label && *button2_label == '+') {
339 gtk_widget_grab_default(button2);
340 gtk_widget_grab_focus(button2);
342 if (button3_label && *button3_label == '+') {
343 gtk_widget_grab_default(button3);
344 gtk_widget_grab_focus(button3);
347 gtk_signal_connect(GTK_OBJECT(button1), "clicked",
348 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
349 GUINT_TO_POINTER(G_ALERTDEFAULT));
351 gtk_signal_connect(GTK_OBJECT(button2), "clicked",
352 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
353 GUINT_TO_POINTER(G_ALERTALTERNATE));
355 gtk_signal_connect(GTK_OBJECT(button3), "clicked",
356 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
357 GUINT_TO_POINTER(G_ALERTOTHER));
359 gtk_widget_show_all(dialog);
362 static void alertpanel_button_toggled(GtkToggleButton *button,
365 if (gtk_toggle_button_get_active(button))
366 value &= ~GPOINTER_TO_UINT(data);
368 value |= GPOINTER_TO_UINT(data);
371 static void alertpanel_button_clicked(GtkWidget *widget, gpointer data)
373 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
376 static gint alertpanel_deleted(GtkWidget *widget, GdkEventAny *event,
379 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
383 static void alertpanel_close(GtkWidget *widget, GdkEventAny *event,
386 if (event->type == GDK_KEY_PRESS)
387 if (((GdkEventKey *)event)->keyval != GDK_Escape)
390 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;