2008-01-09 [colin] 3.2.0cvs34
[claws.git] / src / gtk / description_window.c
index 5297d6c109adbe0ac9fe9bc280275dce9451d1a3..20096034fc635fc5eed23f78e3a62eb358aec6fc 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2007 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -41,7 +41,8 @@ static gboolean description_window_focus_in_event     (GtkWidget *widget,
 static gboolean description_window_focus_out_event     (GtkWidget *widget,
                                                         GdkEventFocus *event,
                                                         gpointer data);
-
+static void description_window_destroy                 (GtkWidget *parent,
+                                                        gpointer data);
 
 void description_window_create(DescriptionWindow *dwindow)
 {
@@ -49,21 +50,14 @@ void description_window_create(DescriptionWindow *dwindow)
                description_create(dwindow);
        
                gtk_window_set_transient_for(GTK_WINDOW(dwindow->window), GTK_WINDOW(dwindow->parent));
-
+               gtk_window_set_destroy_with_parent(GTK_WINDOW(dwindow->window), TRUE);
                gtk_widget_show(dwindow->window);
 
                /* in case the description window is closed using the WM's [X] button */
                g_signal_connect(G_OBJECT(dwindow->window), "destroy",
                                GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dwindow->window);
 
-               gtk_main();
-
-               if (dwindow->window) {
-                       gtk_widget_hide(dwindow->window);
-                       gtk_widget_destroy(dwindow->window);
-                       dwindow->window = NULL; 
-               }
-       } else printf("windows exist\n");
+       } else g_print("windows exist\n");
 }
 
 static void description_create(DescriptionWindow * dwindow)
@@ -82,7 +76,7 @@ static void description_create(DescriptionWindow * dwindow)
        int max_width = 0;
        GtkRequisition req;
        
-       dwindow->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       dwindow->window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "description_window");
        
        gtk_window_set_title(GTK_WINDOW(dwindow->window),
                             gettext(dwindow->title));
@@ -96,7 +90,6 @@ static void description_create(DescriptionWindow * dwindow)
        }
        
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
-       gtk_widget_show(scrolledwin);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
        
@@ -150,23 +143,17 @@ static void description_create(DescriptionWindow * dwindow)
 
        gtkut_stock_button_set_create(&hbbox, &close_btn, GTK_STOCK_CLOSE,
                                      NULL, NULL, NULL, NULL);
-       gtk_widget_show(hbbox);
 
        vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
-       gtk_widget_show(vbox);
        gtk_container_add(GTK_CONTAINER(dwindow->window), vbox);
 
        hbox = gtk_hbox_new(FALSE, 0);
-       gtk_widget_show(hbox);
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 
        label = gtk_label_new(gettext(dwindow->description));
-       gtk_widget_show(label);
+       gtk_widget_set_size_request(GTK_WIDGET(label), max_width-2, -1);
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
        gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
-       gtk_widget_size_request(label, &req);
-       if(req.width > max_width)
-               max_width = req.width + 20;
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
 
        gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(scrolledwin),
@@ -177,17 +164,21 @@ static void description_create(DescriptionWindow * dwindow)
        gtk_widget_grab_default(close_btn);
 
        g_signal_connect(G_OBJECT(close_btn), "clicked",
-                        G_CALLBACK(gtk_main_quit), NULL);
+                        G_CALLBACK(description_window_destroy), dwindow);
        g_signal_connect(G_OBJECT(dwindow->window), "key_press_event",
-                        G_CALLBACK(description_window_key_pressed), NULL);
+                        G_CALLBACK(description_window_key_pressed), dwindow);
        g_signal_connect(G_OBJECT(dwindow->window), "focus_in_event",
                         G_CALLBACK(description_window_focus_in_event), NULL);
        g_signal_connect(G_OBJECT(dwindow->window), "focus_out_event",
                         G_CALLBACK(description_window_focus_out_event), NULL);
        g_signal_connect(G_OBJECT(dwindow->window), "delete_event",
-                        G_CALLBACK(gtk_main_quit), NULL);
+                        G_CALLBACK(description_window_destroy), dwindow);
+       
+       if(dwindow->parent)
+               g_signal_connect(G_OBJECT(dwindow->parent), "hide",
+                       G_CALLBACK(description_window_destroy), dwindow);
 
-       gtk_widget_show_all(table);
+       gtk_widget_show_all(vbox);
        gtk_widget_set_size_request(dwindow->window,
                                (max_width < 400) ? 400 : max_width, 450);      
 }
@@ -197,7 +188,7 @@ static gboolean description_window_key_pressed(GtkWidget *widget,
                                               gpointer data)
 {
        if (event && event->keyval == GDK_Escape)
-               gtk_main_quit();
+               description_window_destroy(widget, data);
        return FALSE;
 }
 
@@ -220,5 +211,17 @@ static gboolean description_window_focus_out_event (GtkWidget *widget,
        return FALSE;
 }
 
-
-
+static void description_window_destroy (GtkWidget *widget, gpointer data)
+{
+       DescriptionWindow *dwindow = (DescriptionWindow *) data;
+       
+       if(dwindow->window) {
+               gtk_widget_hide(dwindow->window);
+               gtk_widget_destroy(dwindow->window);
+               dwindow->window = NULL;
+       }
+       
+       if(dwindow->parent)
+               g_signal_handlers_disconnect_by_func(G_OBJECT(dwindow->parent), 
+                                       description_window_destroy, dwindow->parent);
+}