remove gtk_window_set_wmclass()
[claws.git] / src / prefs_fonts.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2004 Hiroyuki Yamamoto & The Sylpheed-Claws Team
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 "defs.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <gtk/gtk.h>
31 #include <gdk/gdkkeysyms.h>
32
33 #include "intl.h"
34 #include "utils.h"
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
37
38 #include "gtk/gtkutils.h"
39 #include "gtk/prefswindow.h"
40
41 #include "manage_window.h"
42
43 typedef struct _FontsPage
44 {
45         PrefsPage page;
46
47         GtkWidget *window;              /* do not modify */
48
49         GtkWidget *entry_folderviewfont;
50         GtkWidget *entry_summaryviewfont;
51         GtkWidget *entry_messageviewfont;
52         GtkWidget *entry_boldfont;
53 } FontsPage;
54
55 static GtkWidget *font_sel_win;
56 static guint font_sel_conn_id;
57
58 static void prefs_font_select   (GtkButton *button, GtkEntry *entry);
59
60 static void prefs_font_selection_key_pressed    (GtkWidget      *widget,
61                                                  GdkEventKey    *event,
62                                                  gpointer        data);
63 static void prefs_font_selection_ok             (GtkButton      *button, GtkEntry *entry);
64
65 static void prefs_font_select(GtkButton *button, GtkEntry *entry)
66 {
67         gchar *font_name;
68         
69         g_return_if_fail(entry != NULL);
70         
71         if (!font_sel_win) {
72                 font_sel_win = gtk_font_selection_dialog_new
73                         (_("Font selection"));
74                 gtk_window_set_position(GTK_WINDOW(font_sel_win),
75                                     GTK_WIN_POS_CENTER);
76                 g_signal_connect(G_OBJECT(font_sel_win), "delete_event",
77                                  G_CALLBACK(gtk_widget_hide_on_delete),
78                                  NULL);
79                 g_signal_connect(G_OBJECT(font_sel_win), "key_press_event",
80                                  G_CALLBACK(prefs_font_selection_key_pressed),
81                                  NULL);
82                 g_signal_connect_swapped
83                         (G_OBJECT(GTK_FONT_SELECTION_DIALOG(font_sel_win)->cancel_button),
84                          "clicked",
85                          G_CALLBACK(gtk_widget_hide_on_delete),
86                          G_OBJECT(font_sel_win));
87         }
88
89         if(font_sel_conn_id) {
90                 g_signal_handler_disconnect
91                         (G_OBJECT(GTK_FONT_SELECTION_DIALOG(font_sel_win)->ok_button), 
92                          font_sel_conn_id);
93         }
94         font_sel_conn_id = g_signal_connect
95                 (G_OBJECT(GTK_FONT_SELECTION_DIALOG(font_sel_win)->ok_button),
96                  "clicked", G_CALLBACK(prefs_font_selection_ok), entry);
97
98         font_name = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
99         gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(font_sel_win), font_name);
100         g_free(font_name);
101         manage_window_set_transient(GTK_WINDOW(font_sel_win));
102         gtk_window_set_modal(GTK_WINDOW(font_sel_win), TRUE);
103         gtk_widget_grab_focus
104                 (GTK_FONT_SELECTION_DIALOG(font_sel_win)->ok_button);
105         gtk_widget_show(font_sel_win);
106 }
107
108 static void prefs_font_selection_key_pressed(GtkWidget *widget,
109                                              GdkEventKey *event,
110                                              gpointer data)
111 {
112         if (event && event->keyval == GDK_Escape)
113                 gtk_widget_hide(font_sel_win);
114 }
115
116 static void prefs_font_selection_ok(GtkButton *button, GtkEntry *entry)
117 {
118         gchar *fontname;
119
120         fontname = gtk_font_selection_dialog_get_font_name
121                 (GTK_FONT_SELECTION_DIALOG(font_sel_win));
122
123         if (fontname) {
124                 gtk_entry_set_text(entry, fontname);
125
126                 g_free(fontname);
127         }
128
129         gtk_widget_hide(font_sel_win);
130 }
131
132 void prefs_fonts_create_widget(PrefsPage *_page, GtkWindow *window, 
133                                gpointer data)
134 {
135         FontsPage *prefs_fonts = (FontsPage *) _page;
136
137         GtkWidget *table;
138         GtkWidget *entry_folderviewfont;
139         GtkWidget *entry_summaryviewfont;
140         GtkWidget *entry_messageviewfont;
141         GtkWidget *entry_boldfont;
142         GtkWidget *tmplabel, *tmpbutton;
143         GtkWidget *vbox;
144         GtkWidget *hint_label;
145
146         table = gtk_table_new(8, 3, FALSE);
147         gtk_widget_show(table);
148         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
149         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
150         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
151
152         tmplabel = gtk_label_new (_("Folder List"));
153         gtk_widget_show (tmplabel);
154         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 0, 1,
155                          (GtkAttachOptions) GTK_FILL,
156                          (GtkAttachOptions) (0), 0, 0);
157         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
158         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
159
160         entry_folderviewfont = gtk_entry_new ();
161         gtk_widget_show (entry_folderviewfont);
162         gtk_table_attach (GTK_TABLE (table), entry_folderviewfont, 1, 2, 0, 1,
163                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
164                          (GtkAttachOptions) (0), 0, 0);
165         gtk_entry_set_text(GTK_ENTRY(entry_folderviewfont), prefs_common.normalfont);
166
167         tmpbutton = gtk_button_new_with_label (" ... ");
168         gtk_widget_show (tmpbutton);
169         gtk_table_attach (GTK_TABLE (table), tmpbutton, 2, 3, 0, 1,
170                           0, 0, 0, 0);
171         g_signal_connect(G_OBJECT(tmpbutton), "clicked",
172                          G_CALLBACK(prefs_font_select), entry_folderviewfont);
173
174         tmplabel = gtk_label_new (_("Message List"));
175         gtk_widget_show (tmplabel);
176         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 1, 2,
177                          (GtkAttachOptions) GTK_FILL,
178                          (GtkAttachOptions) (0), 0, 0);
179         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
180         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
181
182         entry_summaryviewfont = gtk_entry_new ();
183         gtk_widget_show (entry_summaryviewfont);
184         gtk_table_attach (GTK_TABLE (table), entry_summaryviewfont, 1, 2, 1, 2,
185                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
186                          (GtkAttachOptions) (0), 0, 0);
187         gtk_entry_set_text(GTK_ENTRY(entry_summaryviewfont), prefs_common.smallfont);
188
189         tmpbutton = gtk_button_new_with_label (" ... ");
190         gtk_widget_show (tmpbutton);
191         gtk_table_attach (GTK_TABLE (table), tmpbutton, 2, 3, 1, 2,
192                           0, 0, 0, 0);
193         g_signal_connect(G_OBJECT(tmpbutton), "clicked",
194                          G_CALLBACK(prefs_font_select), entry_summaryviewfont);
195
196         tmplabel = gtk_label_new (_("Message"));
197         gtk_widget_show (tmplabel);
198         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 2, 3,
199                          (GtkAttachOptions) GTK_FILL,
200                          (GtkAttachOptions) (0), 0, 0);
201         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
202         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
203
204         entry_messageviewfont = gtk_entry_new ();
205         gtk_widget_show (entry_messageviewfont);
206         gtk_table_attach (GTK_TABLE (table), entry_messageviewfont, 1, 2, 2, 3,
207                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
208                          (GtkAttachOptions) (0), 0, 0);
209         gtk_entry_set_text(GTK_ENTRY(entry_messageviewfont), prefs_common.textfont);
210
211         tmpbutton = gtk_button_new_with_label (" ... ");
212         gtk_widget_show (tmpbutton);
213         gtk_table_attach (GTK_TABLE (table), tmpbutton, 2, 3, 2, 3,
214                           0, 0, 0, 0);
215         g_signal_connect(G_OBJECT(tmpbutton), "clicked",
216                          G_CALLBACK(prefs_font_select), entry_messageviewfont);
217
218         tmplabel = gtk_label_new (_("Bold"));
219         gtk_widget_show (tmplabel);
220         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 3, 4,
221                          (GtkAttachOptions) GTK_FILL,
222                          (GtkAttachOptions) (0), 0, 0);
223         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
224         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
225
226         entry_boldfont = gtk_entry_new ();
227         gtk_widget_show (entry_boldfont);
228         gtk_table_attach (GTK_TABLE (table), entry_boldfont, 1, 2, 3, 4,
229                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
230                          (GtkAttachOptions) (0), 0, 0);
231         gtk_entry_set_text(GTK_ENTRY(entry_boldfont), prefs_common.boldfont);
232
233         tmpbutton = gtk_button_new_with_label (" ... ");
234         gtk_widget_show (tmpbutton);
235         gtk_table_attach (GTK_TABLE (table), tmpbutton, 2, 3, 3, 4,
236                           0, 0, 0, 0);
237         g_signal_connect(G_OBJECT(tmpbutton), "clicked",
238                          G_CALLBACK(prefs_font_select), entry_boldfont);
239
240         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
241         gtk_widget_show(vbox);
242         gtk_table_attach (GTK_TABLE (table), vbox, 0, 4, 4, 5,
243                          (GtkAttachOptions) GTK_FILL,
244                          (GtkAttachOptions) (0), 0, 0);
245         
246         hint_label = gtk_label_new (_("You will need to restart for the "
247                                       "changes to take effect"));
248         gtk_widget_show (hint_label);
249         gtk_box_pack_start (GTK_BOX (vbox), 
250                             hint_label, FALSE, FALSE, 0);
251         gtk_misc_set_alignment(GTK_MISC(hint_label), 0.5, 0.5);
252
253         prefs_fonts->window                = GTK_WIDGET(window);
254         prefs_fonts->entry_folderviewfont  = entry_folderviewfont;
255         prefs_fonts->entry_summaryviewfont = entry_summaryviewfont;
256         prefs_fonts->entry_messageviewfont = entry_messageviewfont;
257         prefs_fonts->entry_boldfont        = entry_boldfont;
258
259         prefs_fonts->page.widget = table;
260 }
261
262 void prefs_fonts_save(PrefsPage *_page)
263 {
264         FontsPage *fonts = (FontsPage *) _page;
265
266         prefs_common.normalfont = gtk_editable_get_chars
267                 (GTK_EDITABLE(fonts->entry_folderviewfont), 0, -1);
268         prefs_common.smallfont  = gtk_editable_get_chars
269                 (GTK_EDITABLE(fonts->entry_summaryviewfont), 0, -1);
270         prefs_common.textfont   = gtk_editable_get_chars
271                 (GTK_EDITABLE(fonts->entry_messageviewfont), 0, -1);
272         prefs_common.boldfont   = gtk_editable_get_chars
273                 (GTK_EDITABLE(fonts->entry_boldfont), 0, -1);
274 }
275
276 static void prefs_fonts_destroy_widget(PrefsPage *_page)
277 {
278         /* FontsPage *fonts = (FontsPage *) _page; */
279
280 }
281
282 FontsPage *prefs_fonts;
283
284 void prefs_fonts_init(void)
285 {
286         FontsPage *page;
287
288         page = g_new0(FontsPage, 1);
289         page->page.path = _("Display/Fonts");
290         page->page.create_widget = prefs_fonts_create_widget;
291         page->page.destroy_widget = prefs_fonts_destroy_widget;
292         page->page.save_page = prefs_fonts_save;
293         page->page.weight = 60.0;
294         prefs_gtk_register_page((PrefsPage *) page);
295         prefs_fonts = page;
296 }
297
298 void prefs_fonts_done(void)
299 {
300         prefs_gtk_unregister_page((PrefsPage *) prefs_fonts);
301         g_free(prefs_fonts);
302 }