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 "alertpanel.h"
29 #include "manage_window.h"
34 #define TITLE_FONT "-*-helvetica-medium-r-normal--17-*-*-*-*-*-*-*," \
35 "-*-*-medium-r-normal--16-*-*-*-*-*-*-*,*"
36 #define MESSAGE_FONT "-*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*," \
37 "-*-*-medium-r-normal--14-*-*-*-*-*-*-*,*"
38 #define ALERT_PANEL_WIDTH 380
39 #define TITLE_HEIGHT 72
40 #define MESSAGE_HEIGHT 62
42 static gboolean alertpanel_is_open
= FALSE
;
43 static AlertValue value
;
45 static GtkWidget
*dialog
;
47 static void alertpanel_show (void);
48 static void alertpanel_create (const gchar
*title
,
50 const gchar
*button1_label
,
51 const gchar
*button2_label
,
52 const gchar
*button3_label
,
54 GtkWidget
*custom_widget
);
56 static void alertpanel_button_toggled (GtkToggleButton
*button
,
58 static void alertpanel_button_clicked (GtkWidget
*widget
,
60 static gint
alertpanel_deleted (GtkWidget
*widget
,
63 static void alertpanel_close (GtkWidget
*widget
,
67 AlertValue
alertpanel(const gchar
*title
,
69 const gchar
*button1_label
,
70 const gchar
*button2_label
,
71 const gchar
*button3_label
)
73 if (alertpanel_is_open
)
76 alertpanel_is_open
= TRUE
;
78 alertpanel_create(title
, message
, button1_label
, button2_label
,
79 button3_label
, FALSE
, NULL
);
82 debug_print("return value = %d\n", value
);
86 AlertValue
alertpanel_with_widget(const gchar
*title
,
88 const gchar
*button1_label
,
89 const gchar
*button2_label
,
90 const gchar
*button3_label
,
93 if (alertpanel_is_open
)
96 alertpanel_is_open
= TRUE
;
97 alertpanel_create(title
, message
, button1_label
, button2_label
,
98 button3_label
, FALSE
, widget
);
101 debug_print("return value = %d\n", value
);
104 void alertpanel_message(const gchar
*title
, const gchar
*message
)
106 if (alertpanel_is_open
)
109 alertpanel_is_open
= TRUE
;
111 alertpanel_create(title
, message
, NULL
, NULL
, NULL
, FALSE
, NULL
);
115 AlertValue
alertpanel_message_with_disable(const gchar
*title
,
116 const gchar
*message
)
118 if (alertpanel_is_open
)
121 alertpanel_is_open
= TRUE
;
123 alertpanel_create(title
, message
, NULL
, NULL
, NULL
, TRUE
, NULL
);
129 void alertpanel_notice(const gchar
*format
, ...)
134 va_start(args
, format
);
135 g_vsnprintf(buf
, sizeof(buf
), format
, args
);
139 alertpanel_message(_("Notice"), buf
);
142 void alertpanel_warning(const gchar
*format
, ...)
147 va_start(args
, format
);
148 g_vsnprintf(buf
, sizeof(buf
), format
, args
);
152 alertpanel_message(_("Warning"), buf
);
155 void alertpanel_error(const gchar
*format
, ...)
160 va_start(args
, format
);
161 g_vsnprintf(buf
, sizeof(buf
), format
, args
);
165 alertpanel_message(_("Error"), buf
);
168 static void alertpanel_show(void)
170 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
171 manage_window_set_transient(GTK_WINDOW(dialog
));
174 if (gdk_pointer_is_grabbed())
175 gdk_pointer_ungrab(GDK_CURRENT_TIME
);
177 while ((value
& G_ALERT_VALUE_MASK
) == G_ALERTWAIT
)
178 gtk_main_iteration();
180 gtk_widget_destroy(dialog
);
183 alertpanel_is_open
= FALSE
;
187 static void alertpanel_create(const gchar
*title
,
188 const gchar
*message
,
189 const gchar
*button1_label
,
190 const gchar
*button2_label
,
191 const gchar
*button3_label
,
192 gboolean can_disable
,
193 GtkWidget
*custom_widget
)
195 static GdkFont
*titlefont
;
202 GtkWidget
*disable_chkbtn
;
203 GtkWidget
*confirm_area
;
210 debug_print("Creating alert panel dialog...\n");
212 dialog
= gtk_dialog_new();
213 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
214 gtk_window_set_policy(GTK_WINDOW(dialog
), FALSE
, FALSE
, FALSE
);
215 gtk_container_set_border_width
216 (GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), 5);
217 gtk_window_position(GTK_WINDOW(dialog
), GTK_WIN_POS_CENTER
);
218 gtk_signal_connect(GTK_OBJECT(dialog
), "delete_event",
219 GTK_SIGNAL_FUNC(alertpanel_deleted
),
220 (gpointer
)G_ALERTOTHER
);
221 gtk_signal_connect(GTK_OBJECT(dialog
), "key_press_event",
222 GTK_SIGNAL_FUNC(alertpanel_close
),
223 (gpointer
)G_ALERTOTHER
);
224 gtk_widget_realize(dialog
);
226 /* for title label */
227 hbox
= gtk_hbox_new(FALSE
, 0);
228 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog
)->vbox
),
229 hbox
, TRUE
, TRUE
, 16);
232 /* pixmapwid = create_pixmapwid(dialog, GNUstep_xpm); */
233 /* gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16); */
234 label
= gtk_label_new(title
);
235 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 16);
236 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
237 style
= gtk_style_copy(gtk_widget_get_style(label
));
239 titlefont
= gtkut_font_load(TITLE_FONT
);
241 style
->font
= titlefont
;
242 gtk_widget_set_style(label
, style
);
244 /* for message and button(s) */
245 vbox
= gtk_vbox_new(FALSE
, 0);
246 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
),
249 spc_vbox
= gtk_vbox_new(FALSE
, 0);
250 gtk_box_pack_start(GTK_BOX(vbox
), spc_vbox
, FALSE
, FALSE
, 0);
251 gtk_widget_set_usize(spc_vbox
, -1, 16);
253 msg_vbox
= gtk_vbox_new(FALSE
, 0);
254 gtk_box_pack_start(GTK_BOX(vbox
), msg_vbox
, FALSE
, FALSE
, 0);
256 /* for message label */
257 hbox
= gtk_hbox_new(FALSE
, 0);
258 gtk_box_pack_start(GTK_BOX(msg_vbox
), hbox
, FALSE
, FALSE
, 0);
261 label
= gtk_label_new(message
);
262 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 24);
263 gtk_label_set_justify(GTK_LABEL(label
), GTK_JUSTIFY_LEFT
);
265 /* Claws: custom widget */
267 GtkWidget
*custom_hbox
= gtk_hbox_new(FALSE
, 0);
268 gtk_box_pack_start(GTK_BOX(msg_vbox
), custom_hbox
, FALSE
,
270 gtk_box_pack_start(GTK_BOX(custom_hbox
), custom_widget
, FALSE
,
274 hbox
= gtk_hbox_new(FALSE
, 0);
275 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
276 gtk_container_set_border_width(GTK_CONTAINER(hbox
), 8);
278 disable_chkbtn
= gtk_check_button_new_with_label
279 (_("Show this message next time"));
280 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn
),
282 gtk_box_pack_start(GTK_BOX(hbox
), disable_chkbtn
,
284 gtk_signal_connect(GTK_OBJECT(disable_chkbtn
), "toggled",
285 GTK_SIGNAL_FUNC(alertpanel_button_toggled
),
286 GUINT_TO_POINTER(G_ALERTDISABLE
));
288 spc_vbox
= gtk_vbox_new(FALSE
, 0);
289 gtk_box_pack_start(GTK_BOX(vbox
), spc_vbox
, FALSE
, FALSE
, 0);
290 gtk_widget_set_usize(spc_vbox
, -1, 20);
295 button1_label
= _("OK");
296 label2
= button2_label
;
297 label3
= button3_label
;
298 if (label2
&& *label2
== '+') label2
++;
299 if (label3
&& *label3
== '+') label3
++;
301 gtkut_button_set_create(&confirm_area
,
302 &button1
, button1_label
,
303 button2_label
? &button2
: NULL
, label2
,
304 button3_label
? &button3
: NULL
, label3
);
306 gtk_box_pack_end(GTK_BOX(vbox
), confirm_area
, FALSE
, FALSE
, 0);
307 gtk_widget_grab_default(button1
);
308 gtk_widget_grab_focus(button1
);
309 if (button2_label
&& *button2_label
== '+') {
310 gtk_widget_grab_default(button2
);
311 gtk_widget_grab_focus(button2
);
313 if (button3_label
&& *button3_label
== '+') {
314 gtk_widget_grab_default(button3
);
315 gtk_widget_grab_focus(button3
);
318 gtk_signal_connect(GTK_OBJECT(button1
), "clicked",
319 GTK_SIGNAL_FUNC(alertpanel_button_clicked
),
320 GUINT_TO_POINTER(G_ALERTDEFAULT
));
322 gtk_signal_connect(GTK_OBJECT(button2
), "clicked",
323 GTK_SIGNAL_FUNC(alertpanel_button_clicked
),
324 GUINT_TO_POINTER(G_ALERTALTERNATE
));
326 gtk_signal_connect(GTK_OBJECT(button3
), "clicked",
327 GTK_SIGNAL_FUNC(alertpanel_button_clicked
),
328 GUINT_TO_POINTER(G_ALERTOTHER
));
330 gtk_widget_show_all(dialog
);
333 static void alertpanel_button_toggled(GtkToggleButton
*button
,
336 if (gtk_toggle_button_get_active(button
))
337 value
&= ~GPOINTER_TO_UINT(data
);
339 value
|= GPOINTER_TO_UINT(data
);
342 static void alertpanel_button_clicked(GtkWidget
*widget
, gpointer data
)
344 value
= (value
& ~G_ALERT_VALUE_MASK
) | (AlertValue
)data
;
347 static gint
alertpanel_deleted(GtkWidget
*widget
, GdkEventAny
*event
,
350 value
= (value
& ~G_ALERT_VALUE_MASK
) | (AlertValue
)data
;
354 static void alertpanel_close(GtkWidget
*widget
, GdkEventAny
*event
,
357 if (event
->type
== GDK_KEY_PRESS
)
358 if (((GdkEventKey
*)event
)->keyval
!= GDK_Escape
)
361 value
= (value
& ~G_ALERT_VALUE_MASK
) | (AlertValue
)data
;