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.
25 #include <gdk/gdkkeysyms.h>
28 #include "mainwindow.h"
29 #include "alertpanel.h"
30 #include "manage_window.h"
34 #include "logwindow.h"
36 #define TITLE_FONT "-*-helvetica-medium-r-normal--17-*-*-*-*-*-*-*," \
37 "-*-*-medium-r-normal--16-*-*-*-*-*-*-*,*"
38 #define MESSAGE_FONT "-*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*," \
39 "-*-*-medium-r-normal--14-*-*-*-*-*-*-*,*"
40 #define ALERT_PANEL_WIDTH 380
41 #define TITLE_HEIGHT 72
42 #define MESSAGE_HEIGHT 62
44 static gboolean alertpanel_is_open = FALSE;
45 static AlertValue value;
47 static GtkWidget *dialog;
49 static void alertpanel_show (void);
50 static void alertpanel_create (const gchar *title,
52 const gchar *button1_label,
53 const gchar *button2_label,
54 const gchar *button3_label,
56 GtkWidget *custom_widget);
58 static void alertpanel_button_toggled (GtkToggleButton *button,
60 static void alertpanel_button_clicked (GtkWidget *widget,
62 static gint alertpanel_deleted (GtkWidget *widget,
65 static void alertpanel_close (GtkWidget *widget,
69 AlertValue alertpanel(const gchar *title,
71 const gchar *button1_label,
72 const gchar *button2_label,
73 const gchar *button3_label)
75 if (alertpanel_is_open)
78 alertpanel_is_open = TRUE;
80 alertpanel_create(title, message, button1_label, button2_label,
81 button3_label, FALSE, NULL);
84 debug_print("return value = %d\n", value);
88 AlertValue alertpanel_with_widget(const gchar *title,
90 const gchar *button1_label,
91 const gchar *button2_label,
92 const gchar *button3_label,
95 if (alertpanel_is_open)
98 alertpanel_is_open = TRUE;
99 alertpanel_create(title, message, button1_label, button2_label,
100 button3_label, FALSE, widget);
103 debug_print("return value = %d\n", value);
106 void alertpanel_message(const gchar *title, const gchar *message)
108 if (alertpanel_is_open)
111 alertpanel_is_open = TRUE;
113 alertpanel_create(title, message, NULL, NULL, NULL, FALSE, NULL);
117 AlertValue alertpanel_message_with_disable(const gchar *title,
118 const gchar *message)
120 if (alertpanel_is_open)
123 alertpanel_is_open = TRUE;
125 alertpanel_create(title, message, NULL, NULL, NULL, TRUE, NULL);
131 void alertpanel_notice(const gchar *format, ...)
136 va_start(args, format);
137 g_vsnprintf(buf, sizeof(buf), format, args);
141 alertpanel_message(_("Notice"), buf);
144 void alertpanel_warning(const gchar *format, ...)
149 va_start(args, format);
150 g_vsnprintf(buf, sizeof(buf), format, args);
154 alertpanel_message(_("Warning"), buf);
157 void alertpanel_error(const gchar *format, ...)
162 va_start(args, format);
163 g_vsnprintf(buf, sizeof(buf), format, args);
167 alertpanel_message(_("Error"), buf);
171 *\brief display an error with a View Log button
174 void alertpanel_error_log(const gchar *format, ...)
181 va_start(args, format);
182 g_vsnprintf(buf, sizeof(buf), format, args);
186 mainwin = mainwindow_get_mainwindow();
188 if (mainwin && mainwin->logwin) {
189 val = alertpanel(_("Error"), buf, _("OK"), _("View log"), NULL);
190 if (val == G_ALERTALTERNATE)
191 log_window_show(mainwin->logwin);
193 alertpanel_error(buf);
196 static void alertpanel_show(void)
198 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
199 manage_window_set_transient(GTK_WINDOW(dialog));
202 if (gdk_pointer_is_grabbed())
203 gdk_pointer_ungrab(GDK_CURRENT_TIME);
205 while ((value & G_ALERT_VALUE_MASK) == G_ALERTWAIT)
206 gtk_main_iteration();
208 gtk_widget_destroy(dialog);
211 alertpanel_is_open = FALSE;
215 static void alertpanel_create(const gchar *title,
216 const gchar *message,
217 const gchar *button1_label,
218 const gchar *button2_label,
219 const gchar *button3_label,
220 gboolean can_disable,
221 GtkWidget *custom_widget)
223 static GdkFont *titlefont;
230 GtkWidget *disable_chkbtn;
231 GtkWidget *confirm_area;
238 debug_print("Creating alert panel dialog...\n");
240 dialog = gtk_dialog_new();
241 gtk_window_set_title(GTK_WINDOW(dialog), title);
242 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
243 gtk_container_set_border_width
244 (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
245 gtk_window_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
246 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
247 GTK_SIGNAL_FUNC(alertpanel_deleted),
248 (gpointer)G_ALERTOTHER);
249 gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
250 GTK_SIGNAL_FUNC(alertpanel_close),
251 (gpointer)G_ALERTOTHER);
252 gtk_widget_realize(dialog);
254 /* for title label */
255 hbox = gtk_hbox_new(FALSE, 0);
256 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
257 hbox, TRUE, TRUE, 16);
260 /* pixmapwid = create_pixmapwid(dialog, GNUstep_xpm); */
261 /* gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16); */
262 label = gtk_label_new(title);
263 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 16);
264 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
265 style = gtk_style_copy(gtk_widget_get_style(label));
267 titlefont = gtkut_font_load(TITLE_FONT);
269 style->font = titlefont;
270 gtk_widget_set_style(label, style);
272 /* for message and button(s) */
273 vbox = gtk_vbox_new(FALSE, 0);
274 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
277 spc_vbox = gtk_vbox_new(FALSE, 0);
278 gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
279 gtk_widget_set_usize(spc_vbox, -1, 16);
281 msg_vbox = gtk_vbox_new(FALSE, 0);
282 gtk_box_pack_start(GTK_BOX(vbox), msg_vbox, FALSE, FALSE, 0);
284 /* for message label */
285 hbox = gtk_hbox_new(FALSE, 0);
286 gtk_box_pack_start(GTK_BOX(msg_vbox), hbox, FALSE, FALSE, 0);
289 label = gtk_label_new(message);
290 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 24);
291 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
293 /* Claws: custom widget */
295 GtkWidget *custom_hbox = gtk_hbox_new(FALSE, 0);
296 gtk_box_pack_start(GTK_BOX(msg_vbox), custom_hbox, FALSE,
298 gtk_box_pack_start(GTK_BOX(custom_hbox), custom_widget, FALSE,
302 hbox = gtk_hbox_new(FALSE, 0);
303 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
304 gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
306 disable_chkbtn = gtk_check_button_new_with_label
307 (_("Show this message next time"));
308 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
310 gtk_box_pack_start(GTK_BOX(hbox), disable_chkbtn,
312 gtk_signal_connect(GTK_OBJECT(disable_chkbtn), "toggled",
313 GTK_SIGNAL_FUNC(alertpanel_button_toggled),
314 GUINT_TO_POINTER(G_ALERTDISABLE));
316 spc_vbox = gtk_vbox_new(FALSE, 0);
317 gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
318 gtk_widget_set_usize(spc_vbox, -1, 20);
323 button1_label = _("OK");
324 label2 = button2_label;
325 label3 = button3_label;
326 if (label2 && *label2 == '+') label2++;
327 if (label3 && *label3 == '+') label3++;
329 gtkut_button_set_create(&confirm_area,
330 &button1, button1_label,
331 button2_label ? &button2 : NULL, label2,
332 button3_label ? &button3 : NULL, label3);
334 gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
335 gtk_widget_grab_default(button1);
336 gtk_widget_grab_focus(button1);
337 if (button2_label && *button2_label == '+') {
338 gtk_widget_grab_default(button2);
339 gtk_widget_grab_focus(button2);
341 if (button3_label && *button3_label == '+') {
342 gtk_widget_grab_default(button3);
343 gtk_widget_grab_focus(button3);
346 gtk_signal_connect(GTK_OBJECT(button1), "clicked",
347 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
348 GUINT_TO_POINTER(G_ALERTDEFAULT));
350 gtk_signal_connect(GTK_OBJECT(button2), "clicked",
351 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
352 GUINT_TO_POINTER(G_ALERTALTERNATE));
354 gtk_signal_connect(GTK_OBJECT(button3), "clicked",
355 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
356 GUINT_TO_POINTER(G_ALERTOTHER));
358 gtk_widget_show_all(dialog);
361 static void alertpanel_button_toggled(GtkToggleButton *button,
364 if (gtk_toggle_button_get_active(button))
365 value &= ~GPOINTER_TO_UINT(data);
367 value |= GPOINTER_TO_UINT(data);
370 static void alertpanel_button_clicked(GtkWidget *widget, gpointer data)
372 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
375 static gint alertpanel_deleted(GtkWidget *widget, GdkEventAny *event,
378 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
382 static void alertpanel_close(GtkWidget *widget, GdkEventAny *event,
385 if (event->type == GDK_KEY_PRESS)
386 if (((GdkEventKey *)event)->keyval != GDK_Escape)
389 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;