2008-09-17 [colin] 3.5.0cvs112
[claws.git] / src / prefs_fonts.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2007 Hiroyuki Yamamoto & The Claws Mail 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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
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 <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
33
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
36
37 #include "gtk/prefswindow.h"
38
39 typedef struct _FontsPage
40 {
41         PrefsPage page;
42
43         GtkWidget *window;              /* do not modify */
44
45         GtkWidget *entry_folderview_smallfont;
46         GtkWidget *entry_folderview_normalfont;
47         GtkWidget *entry_folderview_boldfont;
48         GtkWidget *entry_messageviewfont;
49         GtkWidget *derive_from_normalfont_checkbutton;
50 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
51         GtkWidget *print_checkbutton;
52         GtkWidget *entry_messageprintfont;
53 #endif
54 } FontsPage;
55
56 static void prefs_fonts_create_widget(PrefsPage *_page, GtkWindow *window, 
57                                gpointer data)
58 {
59         FontsPage *prefs_fonts = (FontsPage *) _page;
60
61         GtkWidget *table;
62         GtkWidget *entry_folderview_smallfont;
63         GtkWidget *entry_folderview_normalfont;
64         GtkWidget *entry_folderview_boldfont;
65         GtkWidget *entry_messageviewfont;
66         GtkWidget *tmplabel;
67 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
68         GtkWidget *entry_messageprintfont;
69         GtkWidget *print_checkbutton;
70 #endif
71         GtkWidget *derive_from_normalfont_checkbutton;
72         GtkWidget *vbox;
73         gint      row = 0;
74
75         table = gtk_table_new(10, 2, FALSE);
76         gtk_widget_show(table);
77         gtk_container_set_border_width(GTK_CONTAINER(table), VBOX_BORDER);
78         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
79         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
80
81         /* normal font label */
82         tmplabel = gtk_label_new (_("Folder and Message Lists"));
83         gtk_widget_show (tmplabel);
84         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
85                          (GtkAttachOptions) GTK_FILL,
86                          (GtkAttachOptions) (0), 0, 0);
87         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
88         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
89
90         /* normal font button */
91         entry_folderview_normalfont = gtk_font_button_new_with_font (prefs_common.normalfont);
92         g_object_set(G_OBJECT(entry_folderview_normalfont), 
93                               "use-font", TRUE, 
94                               NULL);
95         gtk_widget_show (entry_folderview_normalfont);
96         gtk_table_attach (GTK_TABLE (table), entry_folderview_normalfont, 1, 2, row, row+1,
97                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
98                          (GtkAttachOptions) (0), 0, 0);
99         row++;
100
101         /* message font label */
102         tmplabel = gtk_label_new (_("Message"));
103         gtk_widget_show (tmplabel);
104         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
105                          (GtkAttachOptions) GTK_FILL,
106                          (GtkAttachOptions) (0), 0, 0);
107         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
108         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
109
110         /* message font button */
111         entry_messageviewfont = gtk_font_button_new_with_font (prefs_common.textfont);
112         g_object_set(G_OBJECT(entry_messageviewfont), 
113                               "use-font", TRUE, 
114                               NULL);
115         gtk_widget_show (entry_messageviewfont);
116         gtk_table_attach (GTK_TABLE (table), entry_messageviewfont, 1, 2, row, row+1,
117                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
118                          (GtkAttachOptions) (0), 0, 0);
119         row++;
120
121         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
122         gtk_widget_show(vbox);
123         gtk_table_attach (GTK_TABLE (table), vbox, 0, 4, row, row+1,
124                          (GtkAttachOptions) GTK_FILL,
125                          (GtkAttachOptions) (0), 0, 0);
126         row++;
127         
128         /* derive from normal font check button */
129         derive_from_normalfont_checkbutton = gtk_check_button_new_with_label(_("Derive small and bold fonts from Folder and Message Lists font"));
130         gtk_widget_show(derive_from_normalfont_checkbutton);
131         gtk_table_attach (GTK_TABLE (table), derive_from_normalfont_checkbutton, 0, 2, row, row+1,
132                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
133                          (GtkAttachOptions) (0), 0, 0);
134         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(derive_from_normalfont_checkbutton),
135                  prefs_common.derive_from_normal_font);
136         row++;
137
138         /* small font label */
139         tmplabel = gtk_label_new (_("Small"));
140         gtk_widget_show (tmplabel);
141         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
142                          (GtkAttachOptions) GTK_FILL,
143                          (GtkAttachOptions) (0), 0, 0);
144         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
145         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
146         SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, tmplabel);
147
148         /* small font button */
149         entry_folderview_smallfont = gtk_font_button_new_with_font (prefs_common.smallfont);
150         g_object_set(G_OBJECT(entry_folderview_smallfont), 
151                               "use-font", TRUE, 
152                               NULL);
153         gtk_widget_show (entry_folderview_smallfont);
154         gtk_table_attach (GTK_TABLE (table), entry_folderview_smallfont, 1, 2, row, row+1,
155                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
156                          (GtkAttachOptions) (0), 0, 0);
157         SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, entry_folderview_smallfont);
158         row++;
159
160         /* bold font label */
161         tmplabel = gtk_label_new (_("Bold"));
162         gtk_widget_show (tmplabel);
163         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
164                          (GtkAttachOptions) GTK_FILL,
165                          (GtkAttachOptions) (0), 0, 0);
166         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
167         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
168         SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, tmplabel);
169
170         /* bold font button */
171         entry_folderview_boldfont = gtk_font_button_new_with_font (prefs_common.boldfont);
172         g_object_set(G_OBJECT(entry_folderview_boldfont), 
173                               "use-font", TRUE, 
174                               NULL);
175         gtk_widget_show (entry_folderview_boldfont);
176         gtk_table_attach (GTK_TABLE (table), entry_folderview_boldfont, 1, 2, row, row+1,
177                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
178                          (GtkAttachOptions) (0), 0, 0);
179         SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton, entry_folderview_boldfont);
180         row++;
181
182 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
183         /* print check button */
184         print_checkbutton = gtk_check_button_new_with_label(_("Use different font for printing"));
185         gtk_widget_show(print_checkbutton);
186         gtk_table_attach (GTK_TABLE (table), print_checkbutton, 0, 2, row, row+1,
187                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
188                          (GtkAttachOptions) (0), 0, 0);
189         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(print_checkbutton),
190                  prefs_common.use_different_print_font);
191         row++;
192
193         /* print font label */
194         tmplabel = gtk_label_new (_("Message Printing"));
195         gtk_widget_show (tmplabel);
196         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, row, row+1,
197                          (GtkAttachOptions) GTK_FILL,
198                          (GtkAttachOptions) (0), 0, 0);
199         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
200         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
201         SET_TOGGLE_SENSITIVITY (print_checkbutton, tmplabel);
202
203         /* print font button */
204         entry_messageprintfont = gtk_font_button_new_with_font (prefs_common.printfont);
205         g_object_set(G_OBJECT(entry_messageprintfont), 
206                               "use-font", TRUE, 
207                               NULL);
208         gtk_widget_show (entry_messageprintfont);
209         gtk_table_attach (GTK_TABLE (table), entry_messageprintfont, 1, 2, row, row+1,
210                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
211                          (GtkAttachOptions) (0), 0, 0);
212         SET_TOGGLE_SENSITIVITY (print_checkbutton, entry_messageprintfont);
213         row++;
214 #endif
215
216         prefs_fonts->window                     = GTK_WIDGET(window);
217         prefs_fonts->entry_folderview_smallfont = entry_folderview_smallfont;
218         prefs_fonts->entry_folderview_normalfont = entry_folderview_normalfont;
219         prefs_fonts->entry_folderview_boldfont   = entry_folderview_boldfont;
220         prefs_fonts->entry_messageviewfont      = entry_messageviewfont;
221         prefs_fonts->derive_from_normalfont_checkbutton = derive_from_normalfont_checkbutton;
222 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
223         prefs_fonts->entry_messageprintfont     = entry_messageprintfont;
224         prefs_fonts->print_checkbutton          = print_checkbutton;
225 #endif
226
227         prefs_fonts->page.widget = table;
228 }
229
230 static void prefs_fonts_save(PrefsPage *_page)
231 {
232         FontsPage *fonts = (FontsPage *) _page;
233
234         g_free(prefs_common.boldfont);
235         prefs_common.boldfont = g_strdup(gtk_font_button_get_font_name
236                 (GTK_FONT_BUTTON(fonts->entry_folderview_boldfont)));
237
238         g_free(prefs_common.normalfont);
239         prefs_common.normalfont = g_strdup(gtk_font_button_get_font_name
240                 (GTK_FONT_BUTTON(fonts->entry_folderview_normalfont)));
241                 
242         g_free(prefs_common.smallfont);         
243         prefs_common.smallfont  = g_strdup(gtk_font_button_get_font_name
244                 (GTK_FONT_BUTTON(fonts->entry_folderview_smallfont)));
245
246         g_free(prefs_common.textfont);          
247         prefs_common.textfont   = g_strdup(gtk_font_button_get_font_name
248                 (GTK_FONT_BUTTON(fonts->entry_messageviewfont)));
249
250         prefs_common.derive_from_normal_font = gtk_toggle_button_get_active
251                         (GTK_TOGGLE_BUTTON(fonts->derive_from_normalfont_checkbutton));
252
253 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
254         g_free(prefs_common.printfont);         
255         prefs_common.printfont   = g_strdup(gtk_font_button_get_font_name
256                 (GTK_FONT_BUTTON(fonts->entry_messageprintfont)));
257         prefs_common.use_different_print_font = gtk_toggle_button_get_active
258                         (GTK_TOGGLE_BUTTON(fonts->print_checkbutton));
259 #endif
260
261         main_window_reflect_prefs_all();
262 }
263
264 static void prefs_fonts_destroy_widget(PrefsPage *_page)
265 {
266         /* FontsPage *fonts = (FontsPage *) _page; */
267
268 }
269
270 FontsPage *prefs_fonts;
271
272 void prefs_fonts_init(void)
273 {
274         FontsPage *page;
275         static gchar *path[3];
276
277         path[0] = _("Display");
278         path[1] = _("Fonts");
279         path[2] = NULL;
280
281         page = g_new0(FontsPage, 1);
282         page->page.path = path;
283         page->page.create_widget = prefs_fonts_create_widget;
284         page->page.destroy_widget = prefs_fonts_destroy_widget;
285         page->page.save_page = prefs_fonts_save;
286         page->page.weight = 135.0;
287         prefs_gtk_register_page((PrefsPage *) page);
288         prefs_fonts = page;
289 }
290
291 void prefs_fonts_done(void)
292 {
293         prefs_gtk_unregister_page((PrefsPage *) prefs_fonts);
294         g_free(prefs_fonts);
295 }