2006-09-30 [colin] 2.5.2cvs26
[claws.git] / src / prefs_fonts.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 <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_folderviewfont;
46         GtkWidget *entry_messageviewfont;
47 #ifdef USE_GNOMEPRINT
48         GtkWidget *print_checkbutton;
49         GtkWidget *entry_messageprintfont;
50 #endif
51 } FontsPage;
52
53 void prefs_fonts_create_widget(PrefsPage *_page, GtkWindow *window, 
54                                gpointer data)
55 {
56         FontsPage *prefs_fonts = (FontsPage *) _page;
57
58         GtkWidget *table;
59         GtkWidget *entry_folderviewfont;
60         GtkWidget *entry_messageviewfont;
61         GtkWidget *tmplabel;
62 #ifdef USE_GNOMEPRINT
63         GtkWidget *entry_messageprintfont;
64         GtkWidget *print_checkbutton;
65 #endif
66         GtkWidget *vbox;
67
68         table = gtk_table_new(7, 2, FALSE);
69         gtk_widget_show(table);
70         gtk_container_set_border_width(GTK_CONTAINER(table), VBOX_BORDER);
71         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
72         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
73
74         tmplabel = gtk_label_new (_("Folder and Message Lists"));
75         gtk_widget_show (tmplabel);
76         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 0, 1,
77                          (GtkAttachOptions) GTK_FILL,
78                          (GtkAttachOptions) (0), 0, 0);
79         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
80         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
81
82         entry_folderviewfont = gtk_font_button_new_with_font (prefs_common.normalfont);
83         g_object_set(G_OBJECT(entry_folderviewfont), 
84                               "use-font", TRUE, 
85                               NULL);
86         gtk_widget_show (entry_folderviewfont);
87         gtk_table_attach (GTK_TABLE (table), entry_folderviewfont, 1, 2, 0, 1,
88                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
89                          (GtkAttachOptions) (0), 0, 0);
90
91         tmplabel = gtk_label_new (_("Message"));
92         gtk_widget_show (tmplabel);
93         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 2, 3,
94                          (GtkAttachOptions) GTK_FILL,
95                          (GtkAttachOptions) (0), 0, 0);
96         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
97         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
98
99         entry_messageviewfont = gtk_font_button_new_with_font (prefs_common.textfont);
100         g_object_set(G_OBJECT(entry_messageviewfont), 
101                               "use-font", TRUE, 
102                               NULL);
103         gtk_widget_show (entry_messageviewfont);
104         gtk_table_attach (GTK_TABLE (table), entry_messageviewfont, 1, 2, 2, 3,
105                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
106                          (GtkAttachOptions) (0), 0, 0);
107
108 #ifdef USE_GNOMEPRINT
109         /* print check button */
110         print_checkbutton = gtk_check_button_new_with_label(_("Use different font for printing"));
111         gtk_widget_show(print_checkbutton);
112         gtk_table_attach (GTK_TABLE (table), print_checkbutton, 0, 2, 4, 5,
113                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
114                          (GtkAttachOptions) (0), 0, 0);
115         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(print_checkbutton),
116                  prefs_common.use_different_print_font);
117
118         /* print font label */
119         tmplabel = gtk_label_new (_("Message Printing"));
120         gtk_widget_show (tmplabel);
121         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 6, 7,
122                          (GtkAttachOptions) GTK_FILL,
123                          (GtkAttachOptions) (0), 0, 0);
124         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
125         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
126         SET_TOGGLE_SENSITIVITY (print_checkbutton, tmplabel);
127
128         /* print font button */
129         entry_messageprintfont = gtk_font_button_new_with_font (prefs_common.printfont);
130         g_object_set(G_OBJECT(entry_messageprintfont), 
131                               "use-font", TRUE, 
132                               NULL);
133         gtk_widget_show (entry_messageprintfont);
134         gtk_table_attach (GTK_TABLE (table), entry_messageprintfont, 1, 2, 6, 7,
135                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
136                          (GtkAttachOptions) (0), 0, 0);
137         SET_TOGGLE_SENSITIVITY (print_checkbutton, entry_messageprintfont);
138 #endif
139
140         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
141         gtk_widget_show(vbox);
142         gtk_table_attach (GTK_TABLE (table), vbox, 0, 4, 4, 5,
143                          (GtkAttachOptions) GTK_FILL,
144                          (GtkAttachOptions) (0), 0, 0);
145         
146         prefs_fonts->window                     = GTK_WIDGET(window);
147         prefs_fonts->entry_folderviewfont       = entry_folderviewfont;
148         prefs_fonts->entry_messageviewfont      = entry_messageviewfont;
149 #ifdef USE_GNOMEPRINT
150         prefs_fonts->entry_messageprintfont     = entry_messageprintfont;
151         prefs_fonts->print_checkbutton          = print_checkbutton;
152 #endif
153
154         prefs_fonts->page.widget = table;
155 }
156
157 void prefs_fonts_save(PrefsPage *_page)
158 {
159         FontsPage *fonts = (FontsPage *) _page;
160
161         g_free(prefs_common.normalfont);
162         prefs_common.normalfont = g_strdup(gtk_font_button_get_font_name
163                 (GTK_FONT_BUTTON(fonts->entry_folderviewfont)));
164                 
165         g_free(prefs_common.smallfont);         
166         prefs_common.smallfont  = g_strdup(gtk_font_button_get_font_name
167                 (GTK_FONT_BUTTON(fonts->entry_folderviewfont)));
168
169         g_free(prefs_common.textfont);          
170         prefs_common.textfont   = g_strdup(gtk_font_button_get_font_name
171                 (GTK_FONT_BUTTON(fonts->entry_messageviewfont)));
172
173 #ifdef USE_GNOMEPRINT
174         g_free(prefs_common.printfont);         
175         prefs_common.printfont   = g_strdup(gtk_font_button_get_font_name
176                 (GTK_FONT_BUTTON(fonts->entry_messageprintfont)));
177         prefs_common.use_different_print_font = gtk_toggle_button_get_active
178                         (GTK_TOGGLE_BUTTON(fonts->print_checkbutton));
179 #endif
180
181         main_window_reflect_prefs_all();
182 }
183
184 static void prefs_fonts_destroy_widget(PrefsPage *_page)
185 {
186         /* FontsPage *fonts = (FontsPage *) _page; */
187
188 }
189
190 FontsPage *prefs_fonts;
191
192 void prefs_fonts_init(void)
193 {
194         FontsPage *page;
195         static gchar *path[3];
196
197         path[0] = _("Display");
198         path[1] = _("Fonts");
199         path[2] = NULL;
200
201         page = g_new0(FontsPage, 1);
202         page->page.path = path;
203         page->page.create_widget = prefs_fonts_create_widget;
204         page->page.destroy_widget = prefs_fonts_destroy_widget;
205         page->page.save_page = prefs_fonts_save;
206         page->page.weight = 135.0;
207         prefs_gtk_register_page((PrefsPage *) page);
208         prefs_fonts = page;
209 }
210
211 void prefs_fonts_done(void)
212 {
213         prefs_gtk_unregister_page((PrefsPage *) prefs_fonts);
214         g_free(prefs_fonts);
215 }