0.8.9claws11
[claws.git] / src / gtk / description_window.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <glib.h>
25 #include <gtk/gtk.h>
26 #include <gdk/gdkkeysyms.h>
27
28 #include "intl.h"
29 #include "manage_window.h"
30 #include "description_window.h"
31 #include "gtkutils.h"
32
33 static void description_create                  (DescriptionWindow *dwindow);
34 static void description_window_key_pressed      (GtkWidget *widget,
35                                                  GdkEventKey *event,
36                                                  gpointer data);
37
38 void description_window_create(DescriptionWindow *dwindow)
39 {
40         if (!dwindow->window)
41                 description_create(dwindow);
42
43         manage_window_set_transient(GTK_WINDOW(dwindow->window));
44         gtk_widget_show(dwindow->window);
45         gtk_main();
46         gtk_widget_hide(dwindow->window);
47 }
48
49 static void description_create(DescriptionWindow * dwindow)
50 {
51         GtkWidget *vbox;
52         GtkWidget *table;
53         GtkWidget *hbbox;
54         GtkWidget *ok_btn;
55         GtkWidget *scrolledwin;
56         int i;
57         int sz;
58         int line;
59         int j;
60
61         dwindow->window = gtk_window_new(GTK_WINDOW_DIALOG);
62         gtk_widget_set_usize(dwindow->window,400,450);
63         
64         gtk_window_set_title(GTK_WINDOW(dwindow->window),
65                              gettext(dwindow->title));
66         gtk_container_set_border_width(GTK_CONTAINER(dwindow->window), 8);
67         gtk_window_set_position(GTK_WINDOW(dwindow->window), GTK_WIN_POS_CENTER);
68         gtk_window_set_modal(GTK_WINDOW(dwindow->window), TRUE);
69         gtk_window_set_policy(GTK_WINDOW(dwindow->window), FALSE, FALSE, FALSE);
70
71         /* Check number of lines to be show */
72         sz = 0;
73         for (i = 0; dwindow->symbol_table[i] != NULL; i = i + dwindow->columns) {
74                 sz++;
75         }
76         
77         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
78         gtk_widget_show(scrolledwin);
79         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
80         
81         table = gtk_table_new(sz, dwindow->columns, FALSE);
82         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwin), table);
83         gtk_container_set_border_width(GTK_CONTAINER(table), 4);
84
85         gtk_table_set_col_spacings(GTK_TABLE(table), 10);
86
87         line = 0;
88         for(i = 0; dwindow->symbol_table[i] != NULL; i = i + dwindow->columns) {
89                 if(dwindow->symbol_table[i][0] != '\0') {
90                         GtkWidget *label;
91
92                         for (j = 0; j < dwindow->columns; j++) {
93                                 gint col = j;
94                                 gint colend = j+1;
95                                 /* Expand using next NULL columns */
96                                 while ((colend < dwindow->columns) && 
97                                        (dwindow->symbol_table[i+colend] == NULL)) {
98                                        colend++;
99                                        j++;
100                                 }
101                                 label = gtk_label_new(gettext(dwindow->symbol_table[i+col]));
102                                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
103                                 gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
104                                 gtk_table_attach(GTK_TABLE(table), label,
105                                                  col, colend, line, line+1,
106                                                  GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
107                                                  0, 0);
108                         }
109                 } else {
110                         GtkWidget *separator;
111                         
112                         separator = gtk_hseparator_new();
113                         gtk_table_attach(GTK_TABLE(table), separator,
114                                          0, dwindow->columns, line, line+1,
115                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
116                                          0, 4);
117                 }
118                 line++;
119         }
120
121         gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
122                                 NULL, NULL, NULL, NULL);
123         gtk_widget_show(hbbox);
124
125         vbox = gtk_vbox_new(FALSE, 0);
126         gtk_widget_show(vbox);
127         gtk_container_add(GTK_CONTAINER(dwindow->window), vbox);
128         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(scrolledwin),
129                            TRUE, TRUE, 0);
130         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbbox),
131                            FALSE, FALSE, 3);
132                            
133 /* OLD CODE
134         gtk_table_attach_defaults(GTK_TABLE(table), hbbox,
135                                   1, 2, i, i+1);
136 */
137         gtk_widget_grab_default(ok_btn);
138         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
139                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
140         gtk_signal_connect
141                 (GTK_OBJECT(dwindow->window), "key_press_event",
142                  GTK_SIGNAL_FUNC(description_window_key_pressed),
143                  NULL);
144         gtk_signal_connect(GTK_OBJECT(dwindow->window), "delete_event",
145                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
146
147         gtk_widget_show_all(table);
148 }
149
150 static void description_window_key_pressed(GtkWidget *widget,
151                                            GdkEventKey *event,
152                                            gpointer data)
153 {
154         if (event && event->keyval == GDK_Escape)
155                 gtk_main_quit();
156 }
157