2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <glib/gi18n.h>
27 #include <gdk/gdkkeysyms.h>
29 #include "manage_window.h"
30 #include "description_window.h"
33 static void description_create (DescriptionWindow *dwindow);
34 static gboolean description_window_key_pressed (GtkWidget *widget,
37 static gboolean description_window_focus_in_event (GtkWidget *widget,
40 static gboolean description_window_focus_out_event (GtkWidget *widget,
45 void description_window_create(DescriptionWindow *dwindow)
47 if (!dwindow->window) {
48 description_create(dwindow);
50 gtk_window_set_transient_for(GTK_WINDOW(dwindow->window), GTK_WINDOW(dwindow->parent));
52 gtk_widget_show(dwindow->window);
54 /* in case the description window is closed using the WM's [X] button */
55 g_signal_connect(G_OBJECT(dwindow->window), "destroy",
56 GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dwindow->window);
60 if (dwindow->window) {
61 gtk_widget_hide(dwindow->window);
62 gtk_widget_destroy(dwindow->window);
63 dwindow->window = NULL;
65 } else printf("windows exist\n");
68 static void description_create(DescriptionWindow * dwindow)
74 GtkWidget *scrolledwin;
80 dwindow->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
81 gtk_widget_set_size_request(dwindow->window,400,450);
83 gtk_window_set_title(GTK_WINDOW(dwindow->window),
84 gettext(dwindow->title));
85 gtk_container_set_border_width(GTK_CONTAINER(dwindow->window), 8);
86 gtk_window_set_resizable(GTK_WINDOW(dwindow->window), TRUE);
88 /* Check number of lines to be show */
90 for (i = 0; dwindow->symbol_table[i] != NULL; i = i + dwindow->columns) {
94 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
95 gtk_widget_show(scrolledwin);
96 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
98 table = gtk_table_new(sz, dwindow->columns, FALSE);
99 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwin), table);
100 gtk_container_set_border_width(GTK_CONTAINER(table), 4);
102 gtk_table_set_col_spacings(GTK_TABLE(table), 10);
105 for(i = 0; dwindow->symbol_table[i] != NULL; i = i + dwindow->columns) {
106 if(dwindow->symbol_table[i][0] != '\0') {
109 for (j = 0; j < dwindow->columns; j++) {
112 /* Expand using next NULL columns */
113 while ((colend < dwindow->columns) &&
114 (dwindow->symbol_table[i+colend] == NULL)) {
118 label = gtk_label_new(gettext(dwindow->symbol_table[i+col]));
119 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
120 gtk_misc_set_alignment (GTK_MISC(label), 0, 0);
121 gtk_table_attach(GTK_TABLE(table), label,
122 col, colend, line, line+1,
123 GTK_EXPAND | GTK_FILL, 0,
127 GtkWidget *separator;
129 separator = gtk_hseparator_new();
130 gtk_table_attach(GTK_TABLE(table), separator,
131 0, dwindow->columns, line, line+1,
132 GTK_EXPAND | GTK_FILL, 0,
138 gtkut_stock_button_set_create(&hbbox, &close_btn, GTK_STOCK_CLOSE,
139 NULL, NULL, NULL, NULL);
140 gtk_widget_show(hbbox);
142 vbox = gtk_vbox_new(FALSE, 0);
143 gtk_widget_show(vbox);
144 gtk_container_add(GTK_CONTAINER(dwindow->window), vbox);
145 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(scrolledwin),
147 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbbox),
151 gtk_table_attach_defaults(GTK_TABLE(table), hbbox,
154 gtk_widget_grab_default(close_btn);
155 g_signal_connect(G_OBJECT(close_btn), "clicked",
156 G_CALLBACK(gtk_main_quit), NULL);
157 g_signal_connect(G_OBJECT(dwindow->window), "key_press_event",
158 G_CALLBACK(description_window_key_pressed), NULL);
159 g_signal_connect(G_OBJECT(dwindow->window), "focus_in_event",
160 G_CALLBACK(description_window_focus_in_event), NULL);
161 g_signal_connect(G_OBJECT(dwindow->window), "focus_out_event",
162 G_CALLBACK(description_window_focus_out_event), NULL);
163 g_signal_connect(G_OBJECT(dwindow->window), "delete_event",
164 G_CALLBACK(gtk_main_quit), NULL);
166 gtk_widget_show_all(table);
169 static gboolean description_window_key_pressed(GtkWidget *widget,
173 if (event && event->keyval == GDK_Escape)
178 static gboolean description_window_focus_in_event (GtkWidget *widget,
179 GdkEventFocus *event,
182 if (gtk_grab_get_current() != widget)
183 gtk_grab_add(GTK_WIDGET(widget));
188 static gboolean description_window_focus_out_event (GtkWidget *widget,
189 GdkEventFocus *event,
192 gtk_grab_remove(GTK_WIDGET(widget));