2012-05-16 [paul] 3.8.0cvs42
[claws.git] / src / gtk / description_window.c
index 2cb1d1ba0e959e116e72157c58578f9f66a2b417..3d74689ef52271029a80635c40e4e08ba63c448f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2011 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
@@ -50,20 +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_modal(GTK_WINDOW(dwindow->parent), TRUE);
                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);
+                               G_CALLBACK(gtk_widget_destroyed), &dwindow->window);
 
-               gtk_main();
-
-               if (dwindow->window) {
-                       gtk_widget_hide(dwindow->window);
-                       gtk_widget_destroy(dwindow->window);
-                       dwindow->window = NULL; 
-               }
        } else g_print("windows exist\n");
 }
 
@@ -80,7 +74,7 @@ static void description_create(DescriptionWindow * dwindow)
        int sz;
        int line;
        int j;
-       int max_width = 0;
+       int *max_width = g_new0(int, dwindow->columns), width=0;
        GtkRequisition req;
        
        dwindow->window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "description_window");
@@ -131,8 +125,8 @@ static void description_create(DescriptionWindow * dwindow)
                                                 (GtkAttachOptions) (0), 0, 2);
 
                                gtk_widget_size_request(label, &req);
-                               if(req.width > max_width)
-                                       max_width = req.width;
+                               if(req.width > max_width[j])
+                                       max_width[j] = req.width;
                        }
                } else {
                        GtkWidget *separator;
@@ -146,8 +140,12 @@ static void description_create(DescriptionWindow * dwindow)
                line++;
        }
 
-       max_width += 150;
+       for(j=0; j<dwindow->columns; j++)
+               width += max_width[j];
 
+       g_free(max_width);
+       width += 100;
+       
        gtkut_stock_button_set_create(&hbbox, &close_btn, GTK_STOCK_CLOSE,
                                      NULL, NULL, NULL, NULL);
 
@@ -158,7 +156,7 @@ static void description_create(DescriptionWindow * dwindow)
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 
        label = gtk_label_new(gettext(dwindow->description));
-       gtk_widget_set_size_request(GTK_WIDGET(label), max_width-2, -1);
+       gtk_widget_set_size_request(GTK_WIDGET(label), width-2, -1);
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
        gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
@@ -171,30 +169,30 @@ static void description_create(DescriptionWindow * dwindow)
        gtk_widget_grab_default(close_btn);
 
        g_signal_connect(G_OBJECT(close_btn), "clicked",
-                        G_CALLBACK(description_window_destroy), dwindow->parent);
+                        G_CALLBACK(description_window_destroy), dwindow);
        g_signal_connect(G_OBJECT(dwindow->window), "key_press_event",
-                        G_CALLBACK(description_window_key_pressed), dwindow->parent);
+                        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(description_window_destroy), dwindow->parent);
+                        G_CALLBACK(description_window_destroy), dwindow);
        
        if(dwindow->parent)
                g_signal_connect(G_OBJECT(dwindow->parent), "hide",
-                       G_CALLBACK(description_window_destroy), dwindow->parent);
+                       G_CALLBACK(description_window_destroy), dwindow);
 
        gtk_widget_show_all(vbox);
        gtk_widget_set_size_request(dwindow->window,
-                               (max_width < 400) ? 400 : max_width, 450);      
+                               (width < 400) ? 400 : width, 450);      
 }
 
 static gboolean description_window_key_pressed(GtkWidget *widget,
                                               GdkEventKey *event,
                                               gpointer data)
 {
-       if (event && event->keyval == GDK_Escape)
+       if (event && event->keyval == GDK_KEY_Escape)
                description_window_destroy(widget, data);
        return FALSE;
 }
@@ -218,10 +216,17 @@ static gboolean description_window_focus_out_event (GtkWidget *widget,
        return FALSE;
 }
 
-static void description_window_destroy (GtkWidget *widget, gpointer parent)
+static void description_window_destroy (GtkWidget *widget, gpointer data)
 {
-       if(parent)
-               g_signal_handlers_disconnect_by_func(G_OBJECT(parent), 
-                                             description_window_destroy, parent);
-       gtk_main_quit();
+       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);
 }