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