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 gboolean can_disable);
53 static void alertpanel_button_toggled (GtkToggleButton *button,
55 static void alertpanel_button_clicked (GtkWidget *widget,
57 static gint alertpanel_deleted (GtkWidget *widget,
60 static void alertpanel_close (GtkWidget *widget,
64 AlertValue alertpanel(const gchar *title,
66 const gchar *button1_label,
67 const gchar *button2_label,
68 const gchar *button3_label)
70 if (alertpanel_is_open)
73 alertpanel_is_open = TRUE;
75 alertpanel_create(title, message, button1_label, button2_label,
76 button3_label, FALSE);
79 debug_print("return value = %d\n", value);
83 void alertpanel_message(const gchar *title, const gchar *message)
85 if (alertpanel_is_open)
88 alertpanel_is_open = TRUE;
90 alertpanel_create(title, message, NULL, NULL, NULL, FALSE);
94 AlertValue alertpanel_message_with_disable(const gchar *title,
97 if (alertpanel_is_open)
100 alertpanel_is_open = TRUE;
102 alertpanel_create(title, message, NULL, NULL, NULL, TRUE);
107 void alertpanel_notice(const gchar *format, ...)
112 va_start(args, format);
113 g_vsnprintf(buf, sizeof(buf), format, args);
117 alertpanel_message(_("Notice"), buf);
120 void alertpanel_warning(const gchar *format, ...)
125 va_start(args, format);
126 g_vsnprintf(buf, sizeof(buf), format, args);
130 alertpanel_message(_("Warning"), buf);
133 void alertpanel_error(const gchar *format, ...)
138 va_start(args, format);
139 g_vsnprintf(buf, sizeof(buf), format, args);
143 alertpanel_message(_("Error"), buf);
146 static void alertpanel_show(void)
148 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
149 manage_window_set_transient(GTK_WINDOW(dialog));
152 /* ungrab the mouse events ? */
153 if (gdk_pointer_is_grabbed())
154 gdk_pointer_ungrab(GDK_CURRENT_TIME);
156 while ((value & G_ALERT_VALUE_MASK) == G_ALERTWAIT)
157 gtk_main_iteration();
159 gtk_widget_destroy(dialog);
162 alertpanel_is_open = FALSE;
165 static void alertpanel_create(const gchar *title,
166 const gchar *message,
167 const gchar *button1_label,
168 const gchar *button2_label,
169 const gchar *button3_label,
170 gboolean can_disable)
172 static GdkFont *titlefont;
177 GtkWidget *confirm_area;
184 GtkWidget *disable_chkbtn;
185 GtkWidget *box_for_buttons;
187 debug_print(_("Creating alert panel dialog...\n"));
189 dialog = gtk_dialog_new();
190 gtk_window_set_title(GTK_WINDOW(dialog), title);
191 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE);
192 gtk_container_set_border_width
193 (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 5);
194 gtk_window_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
195 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
196 GTK_SIGNAL_FUNC(alertpanel_deleted),
197 (gpointer)G_ALERTOTHER);
198 gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
199 GTK_SIGNAL_FUNC(alertpanel_close),
200 (gpointer)G_ALERTOTHER);
201 gtk_widget_realize(dialog);
203 /* for title label */
204 hbox = gtk_hbox_new(FALSE, 0);
205 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
206 hbox, TRUE, TRUE, 16);
209 //pixmapwid = create_pixmapwid(dialog, GNUstep_xpm);
210 //gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16);
211 label = gtk_label_new(title);
212 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 16);
213 style = gtk_style_copy(gtk_widget_get_style(label));
215 titlefont = gdk_fontset_load(TITLE_FONT);
217 style->font = titlefont;
218 gtk_widget_set_style(label, style);
220 /* for message and button(s) */
221 vbox = gtk_vbox_new(FALSE, 0);
222 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
225 /* for message label */
226 hbox = gtk_hbox_new(FALSE, 0);
227 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 20);
230 label = gtk_label_new(message);
231 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 32);
232 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
236 button1_label = _("OK");
237 label2 = button2_label;
238 label3 = button3_label;
239 if (label2 && *label2 == '+') label2++;
240 if (label3 && *label3 == '+') label3++;
242 gtkut_button_set_create(&confirm_area,
243 &button1, button1_label,
244 button2_label ? &button2 : NULL, label2,
245 button3_label ? &button3 : NULL, label3);
248 hbox2 = gtk_hbox_new(FALSE, 8);
249 gtk_box_pack_end(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
250 disable_chkbtn = gtk_check_button_new_with_label
251 (_("Show this message next time"));
252 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
254 gtk_signal_connect(GTK_OBJECT(disable_chkbtn), "toggled",
255 GTK_SIGNAL_FUNC(alertpanel_button_toggled),
256 GUINT_TO_POINTER(G_ALERTDISABLE));
257 gtk_box_pack_start(GTK_BOX(hbox2), disable_chkbtn,
259 box_for_buttons = hbox2;
261 box_for_buttons = vbox;
263 gtk_box_pack_end(GTK_BOX(box_for_buttons), confirm_area,
265 gtk_widget_grab_default(button1);
266 gtk_widget_grab_focus(button1);
267 if (button2_label && *button2_label == '+') {
268 gtk_widget_grab_default(button2);
269 gtk_widget_grab_focus(button2);
271 if (button3_label && *button3_label == '+') {
272 gtk_widget_grab_default(button3);
273 gtk_widget_grab_focus(button3);
276 gtk_signal_connect(GTK_OBJECT(button1), "clicked",
277 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
278 (gpointer)G_ALERTDEFAULT);
280 gtk_signal_connect(GTK_OBJECT(button2), "clicked",
281 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
282 (gpointer)G_ALERTALTERNATE);
284 gtk_signal_connect(GTK_OBJECT(button3), "clicked",
285 GTK_SIGNAL_FUNC(alertpanel_button_clicked),
286 (gpointer)G_ALERTOTHER);
288 gtk_widget_show_all(dialog);
291 static void alertpanel_button_toggled(GtkToggleButton *button,
294 if (gtk_toggle_button_get_active(button))
295 value &= ~GPOINTER_TO_UINT(data);
297 value |= GPOINTER_TO_UINT(data);
300 static void alertpanel_button_clicked(GtkWidget *widget, gpointer data)
302 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
305 static gint alertpanel_deleted(GtkWidget *widget, GdkEventAny *event,
308 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;
312 static void alertpanel_close(GtkWidget *widget, GdkEventAny *event,
315 if (event->type == GDK_KEY_PRESS)
316 if (((GdkEventKey *)event)->keyval != GDK_Escape)
319 value = (value & ~G_ALERT_VALUE_MASK) | (AlertValue)data;