sync with 0.8.1cvs30
[claws.git] / src / alertpanel.c
index ca6f06d0e11c118cee0ace9ed1194414288d46a0..0c7d37058fbdb80b0a8218582e844e6d6172ae02 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@
 #include "manage_window.h"
 #include "utils.h"
 #include "gtkutils.h"
+#include "inc.h"
 
 #define TITLE_FONT     "-*-helvetica-medium-r-normal--17-*-*-*-*-*-*-*," \
                        "-*-*-medium-r-normal--16-*-*-*-*-*-*-*,*"
@@ -49,17 +50,19 @@ static void alertpanel_create               (const gchar    *title,
                                         const gchar    *button1_label,
                                         const gchar    *button2_label,
                                         const gchar    *button3_label,
-                                        gboolean        can_disable);
-static void alertpanel_button_toggled  (GtkToggleButton *button,
-                                        gpointer        data);
-static void alertpanel_button_clicked  (GtkWidget      *widget,
-                                        gpointer        data);
-static gint alertpanel_deleted         (GtkWidget      *widget,
-                                        GdkEventAny    *event,
-                                        gpointer        data);
-static void alertpanel_close           (GtkWidget      *widget,
-                                        GdkEventAny    *event,
-                                        gpointer        data);
+                                        gboolean        can_disable,
+                                        GtkWidget      *custom_widget);
+
+static void alertpanel_button_toggled  (GtkToggleButton        *button,
+                                        gpointer                data);
+static void alertpanel_button_clicked  (GtkWidget              *widget,
+                                        gpointer                data);
+static gint alertpanel_deleted         (GtkWidget              *widget,
+                                        GdkEventAny            *event,
+                                        gpointer                data);
+static void alertpanel_close           (GtkWidget              *widget,
+                                        GdkEventAny            *event,
+                                        gpointer                data);
 
 AlertValue alertpanel(const gchar *title,
                      const gchar *message,
@@ -73,13 +76,31 @@ AlertValue alertpanel(const gchar *title,
                alertpanel_is_open = TRUE;
 
        alertpanel_create(title, message, button1_label, button2_label,
-                         button3_label, FALSE);
+                         button3_label, FALSE, NULL);
        alertpanel_show();
 
        debug_print("return value = %d\n", value);
        return value;
 }
 
+AlertValue alertpanel_with_widget(const gchar *title,
+                                 const gchar *message,
+                                 const gchar *button1_label,
+                                 const gchar *button2_label,
+                                 const gchar *button3_label,
+                                 GtkWidget *widget)
+{
+       if (alertpanel_is_open)
+               return -1;
+       else
+               alertpanel_is_open = TRUE;
+       alertpanel_create(title, message, button1_label, button2_label, 
+                         button3_label, FALSE, widget);
+       alertpanel_show();
+
+       debug_print("return value = %d\n", value);
+       return value;
+}
 void alertpanel_message(const gchar *title, const gchar *message)
 {
        if (alertpanel_is_open)
@@ -87,20 +108,21 @@ void alertpanel_message(const gchar *title, const gchar *message)
        else
                alertpanel_is_open = TRUE;
 
-       alertpanel_create(title, message, NULL, NULL, NULL, FALSE);
+       alertpanel_create(title, message, NULL, NULL, NULL, FALSE, NULL);
        alertpanel_show();
 }
 
-AlertValue alertpanel_message_with_disable(const gchar *title,
-                                          const gchar  *message)
+AlertValue alertpanel_message_with_disable(const gchar *title,
+                                          const gchar *message)
 {
        if (alertpanel_is_open)
-               return;
+               return 0;
        else
                alertpanel_is_open = TRUE;
 
-       alertpanel_create(title, message, NULL, NULL, NULL, TRUE);
+       alertpanel_create(title, message, NULL, NULL, NULL, TRUE, NULL);
        alertpanel_show();
+
        return value;
 }
 
@@ -149,10 +171,9 @@ static void alertpanel_show(void)
        manage_window_set_transient(GTK_WINDOW(dialog));
        value = G_ALERTWAIT;
 
-       /* ungrab the mouse events ? */
        if (gdk_pointer_is_grabbed())
                gdk_pointer_ungrab(GDK_CURRENT_TIME);
-
+       inc_lock();
        while ((value & G_ALERT_VALUE_MASK) == G_ALERTWAIT)
                gtk_main_iteration();
 
@@ -160,6 +181,7 @@ static void alertpanel_show(void)
        GTK_EVENTS_FLUSH();
 
        alertpanel_is_open = FALSE;
+       inc_unlock();
 }
 
 static void alertpanel_create(const gchar *title,
@@ -167,24 +189,25 @@ static void alertpanel_create(const gchar *title,
                              const gchar *button1_label,
                              const gchar *button2_label,
                              const gchar *button3_label,
-                             gboolean     can_disable)
+                             gboolean     can_disable,
+                             GtkWidget *custom_widget)
 {
        static GdkFont *titlefont;
        GtkStyle *style;
        GtkWidget *label;
        GtkWidget *hbox;
        GtkWidget *vbox;
+       GtkWidget *spc_vbox;
+       GtkWidget *msg_vbox;
+       GtkWidget *disable_chkbtn;
        GtkWidget *confirm_area;
        GtkWidget *button1;
        GtkWidget *button2;
        GtkWidget *button3;
        const gchar *label2;
        const gchar *label3;
-       GtkWidget *hbox2;
-       GtkWidget *disable_chkbtn;
-       GtkWidget *box_for_buttons;
 
-       debug_print(_("Creating alert panel dialog...\n"));
+       debug_print("Creating alert panel dialog...\n");
 
        dialog = gtk_dialog_new();
        gtk_window_set_title(GTK_WINDOW(dialog), title);
@@ -206,10 +229,11 @@ static void alertpanel_create(const gchar *title,
                           hbox, TRUE, TRUE, 16);
 
        /* title label */
-       //pixmapwid = create_pixmapwid(dialog, GNUstep_xpm);
-       //gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16);
+       /* pixmapwid = create_pixmapwid(dialog, GNUstep_xpm); */
+       /* gtk_box_pack_start(GTK_BOX(hbox), pixmapwid, FALSE, FALSE, 16); */
        label = gtk_label_new(title);
-       gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 16);
+       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 16);
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        style = gtk_style_copy(gtk_widget_get_style(label));
        if (!titlefont)
                titlefont = gdk_fontset_load(TITLE_FONT);
@@ -222,15 +246,50 @@ static void alertpanel_create(const gchar *title,
        gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
                          vbox);
 
+       spc_vbox = gtk_vbox_new(FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
+       gtk_widget_set_usize(spc_vbox, -1, 16);
+
+       msg_vbox = gtk_vbox_new(FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), msg_vbox, FALSE, FALSE, 0);
+
        /* for message label */
        hbox = gtk_hbox_new(FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 20);
+       gtk_box_pack_start(GTK_BOX(msg_vbox), hbox, FALSE, FALSE, 0);
 
        /* message label */
        label = gtk_label_new(message);
-       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 32);
+       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 24);
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
 
+       /* Claws: custom widget */
+       if (custom_widget) {
+               GtkWidget *custom_hbox = gtk_hbox_new(FALSE, 0);
+               gtk_box_pack_start(GTK_BOX(msg_vbox), custom_hbox, FALSE,
+                                  FALSE, 0);
+               gtk_box_pack_start(GTK_BOX(custom_hbox), custom_widget, FALSE,
+                                  FALSE, 24);
+       }
+       if (can_disable) {
+               hbox = gtk_hbox_new(FALSE, 0);
+               gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
+
+               disable_chkbtn = gtk_check_button_new_with_label
+                       (_("Show this message next time"));
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
+                                            TRUE);
+               gtk_box_pack_start(GTK_BOX(hbox), disable_chkbtn,
+                                  FALSE, FALSE, 0);
+               gtk_signal_connect(GTK_OBJECT(disable_chkbtn), "toggled",
+                                  GTK_SIGNAL_FUNC(alertpanel_button_toggled),
+                                  GUINT_TO_POINTER(G_ALERTDISABLE));
+       } else {
+               spc_vbox = gtk_vbox_new(FALSE, 0);
+               gtk_box_pack_start(GTK_BOX(vbox), spc_vbox, FALSE, FALSE, 0);
+               gtk_widget_set_usize(spc_vbox, -1, 20);
+       }
+
        /* for button(s) */
        if (!button1_label)
                button1_label = _("OK");
@@ -244,24 +303,7 @@ static void alertpanel_create(const gchar *title,
                                button2_label ? &button2 : NULL, label2,
                                button3_label ? &button3 : NULL, label3);
 
-       if (can_disable) {
-               hbox2 = gtk_hbox_new(FALSE, 8);
-               gtk_box_pack_end(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
-               disable_chkbtn = gtk_check_button_new_with_label
-                       (_("Show this message next time"));
-               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(disable_chkbtn),
-                                            TRUE);
-               gtk_signal_connect(GTK_OBJECT(disable_chkbtn), "toggled",
-                                  GTK_SIGNAL_FUNC(alertpanel_button_toggled),
-                                  GUINT_TO_POINTER(G_ALERTDISABLE));
-               gtk_box_pack_start(GTK_BOX(hbox2), disable_chkbtn,
-                                  TRUE, TRUE, 0);
-               box_for_buttons = hbox2;
-       } else
-               box_for_buttons = vbox;
-
-       gtk_box_pack_end(GTK_BOX(box_for_buttons), confirm_area,
-                        FALSE, FALSE, 0);
+       gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(button1);
        gtk_widget_grab_focus(button1);
        if (button2_label && *button2_label == '+') {
@@ -275,15 +317,15 @@ static void alertpanel_create(const gchar *title,
 
        gtk_signal_connect(GTK_OBJECT(button1), "clicked",
                           GTK_SIGNAL_FUNC(alertpanel_button_clicked),
-                          (gpointer)G_ALERTDEFAULT);
+                          GUINT_TO_POINTER(G_ALERTDEFAULT));
        if (button2_label)
                gtk_signal_connect(GTK_OBJECT(button2), "clicked",
                                   GTK_SIGNAL_FUNC(alertpanel_button_clicked),
-                                  (gpointer)G_ALERTALTERNATE);
+                                  GUINT_TO_POINTER(G_ALERTALTERNATE));
        if (button3_label)
                gtk_signal_connect(GTK_OBJECT(button3), "clicked",
                                   GTK_SIGNAL_FUNC(alertpanel_button_clicked),
-                                  (gpointer)G_ALERTOTHER);
+                                  GUINT_TO_POINTER(G_ALERTOTHER));
 
        gtk_widget_show_all(dialog);
 }