0.8.8claws58
[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
59         dwindow->window = gtk_window_new(GTK_WINDOW_DIALOG);
60         gtk_widget_set_usize(dwindow->window,400,450);
61         
62         gtk_window_set_title(GTK_WINDOW(dwindow->window),
63                              gettext(dwindow->title));
64         gtk_container_set_border_width(GTK_CONTAINER(dwindow->window), 8);
65         gtk_window_set_position(GTK_WINDOW(dwindow->window), GTK_WIN_POS_CENTER);
66         gtk_window_set_modal(GTK_WINDOW(dwindow->window), TRUE);
67         gtk_window_set_policy(GTK_WINDOW(dwindow->window), FALSE, FALSE, FALSE);
68
69         /* Check number of lines to be show */
70         sz = 0;
71         for (i = 0; dwindow->symbol_table[i] != NULL; i = i + dwindow->columns) {
72                 sz++;
73         }
74         
75         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
76         gtk_widget_show(scrolledwin);
77         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
78         
79         table = gtk_table_new(sz, dwindow->columns, FALSE);
80         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwin), table);
81         gtk_container_set_border_width(GTK_CONTAINER(table), 4);
82
83         gtk_table_set_col_spacings(GTK_TABLE(table), 10);
84
85         for(i = 0; dwindow->symbol_table[i] != NULL; i = i + dwindow->columns) {
86                 if(dwindow->symbol_table[i][0] != '\0') {
87                         GtkWidget *label;
88
89                         label = gtk_label_new(dwindow->symbol_table[i]);
90                         gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
91                         gtk_table_attach(GTK_TABLE(table), label,
92                                          0, 1, i, i+1,
93                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
94                                          0, 0);
95                                          
96                         label = gtk_label_new(gettext(dwindow->symbol_table[i+1]));
97                         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
98                         gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
99                         gtk_table_attach(GTK_TABLE(table), label,
100                                          1, 2, i, i+1,
101                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
102                                          0, 0);
103                 } else {
104                         GtkWidget *separator;
105                         
106                         separator = gtk_hseparator_new();
107                         gtk_table_attach(GTK_TABLE(table), separator,
108                                          0, 2, i, i+1,
109                                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
110                                          0, 4);
111                 }
112         }
113
114         gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
115                                 NULL, NULL, NULL, NULL);
116         gtk_widget_show(hbbox);
117
118         vbox = gtk_vbox_new(FALSE, 0);
119         gtk_widget_show(vbox);
120         gtk_container_add(GTK_CONTAINER(dwindow->window), vbox);
121         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(scrolledwin),
122                            TRUE, TRUE, 0);
123         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbbox),
124                            FALSE, FALSE, 3);
125                            
126 /* OLD CODE
127         gtk_table_attach_defaults(GTK_TABLE(table), hbbox,
128                                   1, 2, i, i+1);
129 */
130         gtk_widget_grab_default(ok_btn);
131         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
132                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
133         gtk_signal_connect
134                 (GTK_OBJECT(dwindow->window), "key_press_event",
135                  GTK_SIGNAL_FUNC(description_window_key_pressed),
136                  NULL);
137         gtk_signal_connect(GTK_OBJECT(dwindow->window), "delete_event",
138                            GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
139
140         gtk_widget_show_all(table);
141 }
142
143 static void description_window_key_pressed(GtkWidget *widget,
144                                            GdkEventKey *event,
145                                            gpointer data)
146 {
147         if (event && event->keyval == GDK_Escape)
148                 gtk_main_quit();
149 }
150