Fix inputdialog modality and focus issue.
[claws.git] / src / gtk / inputdialog.c
index 59cd02b90d442a9b4135b38ee92749a73a97a063..c131c0abf951e98bc50689d420836867efc1e3ea 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
  *
  * 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
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include <glib.h>
@@ -85,7 +86,7 @@ static void combo_activated   (GtkEditable    *editable);
 gchar *input_dialog(const gchar *title, const gchar *message,
                    const gchar *default_string)
 {
-       if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
+       if (dialog && gtk_widget_get_visible(dialog)) return NULL;
 
        if (!dialog)
                input_dialog_create(FALSE);
@@ -100,10 +101,6 @@ gchar *input_dialog(const gchar *title, const gchar *message,
        gtk_widget_hide(icon_p);
        is_pass = FALSE;
        gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE);
-#ifdef MAEMO
-       hildon_gtk_entry_set_input_mode(GTK_ENTRY(entry), 
-               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
-#endif
 
        return input_dialog_open(title, message, NULL, default_string, FALSE, NULL);
 }
@@ -111,7 +108,7 @@ gchar *input_dialog(const gchar *title, const gchar *message,
 gchar *input_dialog_with_invisible(const gchar *title, const gchar *message,
                                   const gchar *default_string)
 {
-       if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
+       if (dialog && gtk_widget_get_visible(dialog)) return NULL;
 
        if (!dialog)
                input_dialog_create(TRUE);
@@ -125,10 +122,6 @@ gchar *input_dialog_with_invisible(const gchar *title, const gchar *message,
        gtk_widget_show(icon_p);
        is_pass = TRUE;
        gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
-#ifdef MAEMO
-       hildon_gtk_entry_set_input_mode(GTK_ENTRY(entry), 
-               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
-#endif
 
        return input_dialog_open(title, message, NULL, default_string, FALSE, NULL);
 }
@@ -137,7 +130,7 @@ gchar *input_dialog_with_invisible_checkbtn(const gchar *title, const gchar *mes
                                   const gchar *default_string, const gchar *checkbtn_label,
                                   gboolean *checkbtn_state)
 {
-       if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
+       if (dialog && gtk_widget_get_visible(dialog)) return NULL;
 
        if (!dialog)
                input_dialog_create(TRUE);
@@ -159,12 +152,8 @@ gchar *input_dialog_with_invisible_checkbtn(const gchar *title, const gchar *mes
        gtk_widget_show(icon_p);
        is_pass = TRUE;
        gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
-#ifdef MAEMO
-       hildon_gtk_entry_set_input_mode(GTK_ENTRY(entry), 
-               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
-#endif
 
-       return input_dialog_open(title, message, checkbtn_label, default_string, *checkbtn_state, checkbtn_state);
+       return input_dialog_open(title, message, checkbtn_label, default_string, (checkbtn_state? *checkbtn_state:FALSE), checkbtn_state);
 }
 
 gchar *input_dialog_combo(const gchar *title, const gchar *message,
@@ -178,7 +167,7 @@ gchar *input_dialog_combo_remember(const gchar *title, const gchar *message,
                          const gchar *default_string, GList *list,
                          gboolean *remember)
 {
-       if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
+       if (dialog && gtk_widget_get_visible(dialog)) return NULL;
 
        if (!dialog)
                input_dialog_create(FALSE);
@@ -196,10 +185,13 @@ gchar *input_dialog_combo_remember(const gchar *title, const gchar *message,
        gtk_widget_show(icon_q);
        gtk_widget_hide(icon_p);
        is_pass = FALSE;
-
+#if !GTK_CHECK_VERSION(2, 24, 0)
        combobox_unset_popdown_strings(GTK_COMBO_BOX(combo));
        combobox_set_popdown_strings(GTK_COMBO_BOX(combo), list);
-
+#else
+       combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(combo));
+       combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(combo), list);
+#endif
        return input_dialog_open(title, message, NULL, default_string, FALSE, remember);
 }
 
@@ -209,7 +201,7 @@ gchar *input_dialog_with_checkbtn(const gchar       *title,
                                   const gchar  *checkbtn_label,
                                   gboolean *checkbtn_state)
 {
-       if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
+       if (dialog && gtk_widget_get_visible(dialog)) return NULL;
 
        if (!dialog)
                input_dialog_create(FALSE);
@@ -227,10 +219,6 @@ gchar *input_dialog_with_checkbtn(const gchar      *title,
        gtk_widget_hide(icon_p);
        is_pass = FALSE;
        gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE);
-#ifdef MAEMO
-       hildon_gtk_entry_set_input_mode(GTK_ENTRY(entry), 
-               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
-#endif
 
        return input_dialog_open(title, message, checkbtn_label, default_string, 
                                 prefs_common.inherit_folder_props, checkbtn_state);
@@ -302,7 +290,6 @@ gchar *input_dialog_query_password_keep(const gchar *server, const gchar *user,
 static void input_dialog_create(gboolean is_password)
 {
        static PangoFontDescription *font_desc;
-       GtkWidget *w_hbox;
        GtkWidget *hbox;
        GtkWidget *vbox;
        GtkWidget *cancel_button;
@@ -313,7 +300,6 @@ static void input_dialog_create(gboolean is_password)
        gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
        gtk_window_set_default_size(GTK_WINDOW(dialog), 375, 100);
        gtk_window_set_title(GTK_WINDOW(dialog), "");
-       gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
 
        g_signal_connect(G_OBJECT(dialog), "delete_event",
                         G_CALLBACK(delete_event), NULL);
@@ -321,16 +307,15 @@ static void input_dialog_create(gboolean is_password)
                         G_CALLBACK(key_pressed), NULL);
        MANAGE_WINDOW_SIGNALS_CONNECT(dialog);
 
-       gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
+       vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+       gtk_box_set_spacing (GTK_BOX (vbox), 14);
        hbox = gtk_hbox_new (FALSE, 12);
        gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
        gtk_widget_show (hbox);
-       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
+       gtk_box_pack_start (GTK_BOX (vbox), hbox,
                            FALSE, FALSE, 0);
 
        /* for title label */
-       w_hbox = gtk_hbox_new(FALSE, 0);
-       
        icon_q = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
                                GTK_ICON_SIZE_DIALOG); 
        gtk_misc_set_alignment (GTK_MISC (icon_q), 0.5, 0.0);
@@ -354,7 +339,7 @@ static void input_dialog_create(gboolean is_password)
                gint size;
 
                size = pango_font_description_get_size
-                       (msg_title->style->font_desc);
+                       (gtk_widget_get_style(msg_title)->font_desc);
                font_desc = pango_font_description_new();
                pango_font_description_set_weight
                        (font_desc, PANGO_WEIGHT_BOLD);
@@ -375,7 +360,11 @@ static void input_dialog_create(gboolean is_password)
        g_signal_connect(G_OBJECT(entry), "activate",
                         G_CALLBACK(entry_activated), NULL);
 
+#if !GTK_CHECK_VERSION(2, 24, 0)
        combo = gtk_combo_box_entry_new_text();
+#else
+       combo = gtk_combo_box_text_new_with_entry();
+#endif
        gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN((combo)))), "activate",
                         G_CALLBACK(combo_activated), NULL);
@@ -383,18 +372,16 @@ static void input_dialog_create(gboolean is_password)
        remember_checkbtn = gtk_check_button_new_with_label(_("Remember this"));
        gtk_box_pack_start(GTK_BOX(vbox), remember_checkbtn, FALSE, FALSE, 0);
 
-       hbox = gtk_hbox_new(TRUE, 0);
-
        gtkut_stock_button_set_create(&confirm_area,
                                      &cancel_button, GTK_STOCK_CANCEL,
                                      &ok_button, GTK_STOCK_OK,
                                      NULL, NULL);
 
-       gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area),
+       gtk_box_pack_end(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(dialog))),
                         confirm_area, FALSE, FALSE, 0);
        gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
 
-       gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
+       gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
        
        gtk_widget_hide(remember_checkbtn);
 
@@ -421,7 +408,7 @@ static gchar *input_dialog_open(const gchar *title, const gchar *message,
 {
        gchar *str;
 
-       if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
+       if (dialog && gtk_widget_get_visible(dialog)) return NULL;
 
        if (!dialog)
                input_dialog_create(FALSE);
@@ -432,7 +419,7 @@ static gchar *input_dialog_open(const gchar *title, const gchar *message,
                gtk_button_set_label(GTK_BUTTON(remember_checkbtn), _("Remember this"));
 
        input_dialog_set(title, message, default_string);
-       gtk_widget_show(dialog);
+       gtk_window_present(GTK_WINDOW(dialog));
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_checkbtn),
                                     default_checkbtn_state);
@@ -441,8 +428,8 @@ static gchar *input_dialog_open(const gchar *title, const gchar *message,
        else
                gtk_widget_hide(remember_checkbtn);
 
-       gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
        manage_window_set_transient(GTK_WINDOW(dialog));
+       gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
 
        ack = fin = FALSE;
 
@@ -450,7 +437,6 @@ static gchar *input_dialog_open(const gchar *title, const gchar *message,
                gtk_main_iteration();
 
        manage_window_focus_out(dialog, NULL, NULL);
-       gtk_widget_hide(dialog);
 
        if (ack) {
                GtkEditable *editable;
@@ -473,6 +459,10 @@ static gchar *input_dialog_open(const gchar *title, const gchar *message,
        if (remember) {
                *remember = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(remember_checkbtn));
        }
+
+       gtk_widget_destroy(dialog);
+       dialog = NULL;
+
        if (is_pass)
                debug_print("return string = %s\n", str ? "********": ("none"));
        else
@@ -526,10 +516,10 @@ static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
 
 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                ack = FALSE;
                fin = TRUE;
-       } else if (event && event->keyval == GDK_Return) {
+       } else if (event && event->keyval == GDK_KEY_Return) {
                ack = TRUE;
                fin = TRUE;
                return TRUE; /* do not let Return pass - it