2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2022 the Claws Mail team and 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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "claws-features.h"
25 #include <glib/gi18n.h>
27 #include <gdk/gdkkeysyms.h>
30 #include "manage_window.h"
31 #include "description_window.h"
33 #include "prefs_gtk.h"
35 static void description_create (DescriptionWindow
*dwindow
);
36 static gboolean
description_window_key_pressed (GtkWidget
*widget
,
39 static gboolean
description_window_focus_in_event (GtkWidget
*widget
,
42 static gboolean
description_window_focus_out_event (GtkWidget
*widget
,
45 static void description_window_destroy (GtkWidget
*parent
,
48 void description_window_create(DescriptionWindow
*dwindow
)
50 if (!dwindow
->window
) {
51 description_create(dwindow
);
53 gtk_window_set_transient_for(GTK_WINDOW(dwindow
->window
), GTK_WINDOW(dwindow
->parent
));
54 dwindow
->parent_modal
= gtk_window_get_modal(GTK_WINDOW(dwindow
->parent
));
56 gtk_window_set_modal(GTK_WINDOW(dwindow
->parent
), TRUE
);
58 gtk_window_set_modal(GTK_WINDOW(dwindow
->window
), TRUE
);
60 gtk_window_set_destroy_with_parent(GTK_WINDOW(dwindow
->window
), TRUE
);
61 gtk_widget_show(dwindow
->window
);
63 } else g_print("window exists\n");
66 static void description_create(DescriptionWindow
* dwindow
)
74 GtkWidget
*scrolledwin
;
79 int *max_width
= g_new0(int, dwindow
->columns
), width
=0;
82 dwindow
->window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "description_window");
84 gtk_window_set_title(GTK_WINDOW(dwindow
->window
),
85 gettext(dwindow
->title
));
86 gtk_container_set_border_width(GTK_CONTAINER(dwindow
->window
), 8);
87 gtk_window_set_resizable(GTK_WINDOW(dwindow
->window
), TRUE
);
88 gtk_window_set_type_hint(GTK_WINDOW(dwindow
->window
), GDK_WINDOW_TYPE_HINT_DIALOG
);
90 /* Check number of lines to be show */
92 for (i
= 0; dwindow
->symbol_table
[i
] != NULL
; i
= i
+ dwindow
->columns
) {
96 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
97 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
98 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
100 table
= gtk_grid_new();
101 gtk_container_add(GTK_CONTAINER(scrolledwin
), table
);
102 gtk_container_set_border_width(GTK_CONTAINER(table
), 4);
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_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
121 gtk_label_set_use_markup(GTK_LABEL(label
), TRUE
);
122 gtk_label_set_xalign(GTK_LABEL(label
), 0.0);
123 gtk_label_set_yalign(GTK_LABEL(label
), 0.0);
124 gtk_widget_set_margin_end(GTK_WIDGET(label
), 12);
125 gtk_grid_attach(GTK_GRID(table
), label
, col
, line
, 1, 1);
127 gtk_widget_get_preferred_size(label
, &req
, NULL
);
128 if(req
.width
> max_width
[j
])
129 max_width
[j
] = req
.width
;
132 GtkWidget
*separator
;
134 separator
= gtk_separator_new(GTK_ORIENTATION_HORIZONTAL
);
135 gtk_grid_attach(GTK_GRID(table
), separator
, 0, line
, 1, 1);
140 for(j
=0; j
<dwindow
->columns
; j
++)
141 width
+= max_width
[j
];
146 gtkut_stock_button_set_create(&hbbox
, &close_btn
, "window-close", _("_Close"),
147 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
149 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, VSPACING_NARROW
);
150 gtk_container_add(GTK_CONTAINER(dwindow
->window
), vbox
);
152 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
153 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
155 label
= gtk_label_new(gettext(dwindow
->description
));
156 gtk_widget_set_size_request(GTK_WIDGET(label
), width
-2, -1);
157 gtk_label_set_justify(GTK_LABEL(label
), GTK_JUSTIFY_LEFT
);
158 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
159 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
161 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(scrolledwin
),
163 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(hbbox
),
166 gtk_widget_grab_default(close_btn
);
168 g_signal_connect(G_OBJECT(close_btn
), "clicked",
169 G_CALLBACK(description_window_destroy
), dwindow
);
170 g_signal_connect(G_OBJECT(dwindow
->window
), "key_press_event",
171 G_CALLBACK(description_window_key_pressed
), dwindow
);
172 g_signal_connect(G_OBJECT(dwindow
->window
), "focus_in_event",
173 G_CALLBACK(description_window_focus_in_event
), NULL
);
174 g_signal_connect(G_OBJECT(dwindow
->window
), "focus_out_event",
175 G_CALLBACK(description_window_focus_out_event
), NULL
);
176 g_signal_connect(G_OBJECT(dwindow
->window
), "destroy",
177 G_CALLBACK(description_window_destroy
), dwindow
);
180 g_signal_connect(G_OBJECT(dwindow
->parent
), "hide",
181 G_CALLBACK(description_window_destroy
), dwindow
);
183 gtk_widget_show_all(vbox
);
184 gtk_widget_set_size_request(dwindow
->window
,
185 (width
< 400) ? 400 : width
, 450);
188 static gboolean
description_window_key_pressed(GtkWidget
*widget
,
192 if (event
&& event
->keyval
== GDK_KEY_Escape
)
193 description_window_destroy(widget
, data
);
197 static gboolean
description_window_focus_in_event (GtkWidget
*widget
,
198 GdkEventFocus
*event
,
201 if (gtk_grab_get_current() != widget
)
202 gtk_grab_add(GTK_WIDGET(widget
));
207 static gboolean
description_window_focus_out_event (GtkWidget
*widget
,
208 GdkEventFocus
*event
,
211 gtk_grab_remove(GTK_WIDGET(widget
));
216 static void description_window_destroy (GtkWidget
*widget
, gpointer data
)
218 DescriptionWindow
*dwindow
= (DescriptionWindow
*) data
;
220 if(dwindow
->window
) {
221 gtk_widget_hide(dwindow
->window
);
222 gtk_widget_destroy(dwindow
->window
);
223 dwindow
->window
= NULL
;
226 if(dwindow
->parent
) {
227 if (GTK_IS_WINDOW(dwindow
->parent
))
228 gtk_window_set_modal(GTK_WINDOW(dwindow
->parent
), dwindow
->parent_modal
);
229 g_signal_handlers_disconnect_by_func(G_OBJECT(dwindow
->parent
),
230 description_window_destroy
, dwindow
->parent
);