2005-01-24 [paul] 1.0.0cvs12.1
[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 "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_summaryviewfont;
47         GtkWidget *entry_messageviewfont;
48         GtkWidget *entry_boldfont;
49 } FontsPage;
50
51 void prefs_fonts_create_widget(PrefsPage *_page, GtkWindow *window, 
52                                gpointer data)
53 {
54         FontsPage *prefs_fonts = (FontsPage *) _page;
55
56         GtkWidget *table;
57         GtkWidget *entry_folderviewfont;
58         GtkWidget *entry_summaryviewfont;
59         GtkWidget *entry_messageviewfont;
60         GtkWidget *entry_boldfont;
61         GtkWidget *tmplabel;
62         GtkWidget *vbox;
63         GtkWidget *hint_label;
64
65         table = gtk_table_new(8, 2, FALSE);
66         gtk_widget_show(table);
67         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
68         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
69         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
70
71         tmplabel = gtk_label_new (_("Folder List"));
72         gtk_widget_show (tmplabel);
73         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 0, 1,
74                          (GtkAttachOptions) GTK_FILL,
75                          (GtkAttachOptions) (0), 0, 0);
76         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
77         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
78
79         entry_folderviewfont = gtk_font_button_new_with_font (prefs_common.normalfont);
80         g_object_set(G_OBJECT(entry_folderviewfont), 
81                               "use-font", TRUE, 
82                               NULL);
83         gtk_widget_show (entry_folderviewfont);
84         gtk_table_attach (GTK_TABLE (table), entry_folderviewfont, 1, 2, 0, 1,
85                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
86                          (GtkAttachOptions) (0), 0, 0);
87
88         tmplabel = gtk_label_new (_("Message List"));
89         gtk_widget_show (tmplabel);
90         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 1, 2,
91                          (GtkAttachOptions) GTK_FILL,
92                          (GtkAttachOptions) (0), 0, 0);
93         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
94         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
95
96         entry_summaryviewfont = gtk_font_button_new_with_font (prefs_common.smallfont);
97         g_object_set(G_OBJECT(entry_summaryviewfont), 
98                               "use-font", TRUE, 
99                               NULL);
100         gtk_widget_show (entry_summaryviewfont);
101         gtk_table_attach (GTK_TABLE (table), entry_summaryviewfont, 1, 2, 1, 2,
102                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
103                          (GtkAttachOptions) (0), 0, 0);
104
105         tmplabel = gtk_label_new (_("Message"));
106         gtk_widget_show (tmplabel);
107         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 2, 3,
108                          (GtkAttachOptions) GTK_FILL,
109                          (GtkAttachOptions) (0), 0, 0);
110         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
111         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
112
113         entry_messageviewfont = gtk_font_button_new_with_font (prefs_common.textfont);
114         g_object_set(G_OBJECT(entry_messageviewfont), 
115                               "use-font", TRUE, 
116                               NULL);
117         gtk_widget_show (entry_messageviewfont);
118         gtk_table_attach (GTK_TABLE (table), entry_messageviewfont, 1, 2, 2, 3,
119                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
120                          (GtkAttachOptions) (0), 0, 0);
121
122         tmplabel = gtk_label_new (_("Bold"));
123         gtk_widget_show (tmplabel);
124         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 3, 4,
125                          (GtkAttachOptions) GTK_FILL,
126                          (GtkAttachOptions) (0), 0, 0);
127         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
128         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
129
130         entry_boldfont = gtk_font_button_new_with_font (prefs_common.boldfont);
131         g_object_set(G_OBJECT(entry_boldfont), 
132                               "use-font", TRUE, 
133                               NULL);
134         gtk_widget_show (entry_boldfont);
135         gtk_table_attach (GTK_TABLE (table), entry_boldfont, 1, 2, 3, 4,
136                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
137                          (GtkAttachOptions) (0), 0, 0);
138
139         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
140         gtk_widget_show(vbox);
141         gtk_table_attach (GTK_TABLE (table), vbox, 0, 4, 4, 5,
142                          (GtkAttachOptions) GTK_FILL,
143                          (GtkAttachOptions) (0), 0, 0);
144         
145         hint_label = gtk_label_new (_("You will need to restart for the "
146                                       "changes to take effect"));
147         gtk_widget_show (hint_label);
148         gtk_box_pack_start (GTK_BOX (vbox), 
149                             hint_label, FALSE, FALSE, 0);
150         gtk_misc_set_alignment(GTK_MISC(hint_label), 0.5, 0.5);
151
152         prefs_fonts->window                = GTK_WIDGET(window);
153         prefs_fonts->entry_folderviewfont  = entry_folderviewfont;
154         prefs_fonts->entry_summaryviewfont = entry_summaryviewfont;
155         prefs_fonts->entry_messageviewfont = entry_messageviewfont;
156         prefs_fonts->entry_boldfont        = entry_boldfont;
157
158         prefs_fonts->page.widget = table;
159 }
160
161 void prefs_fonts_save(PrefsPage *_page)
162 {
163         FontsPage *fonts = (FontsPage *) _page;
164
165         g_free(prefs_common.normalfont);
166         prefs_common.normalfont = g_strdup(gtk_font_button_get_font_name
167                 (GTK_FONT_BUTTON(fonts->entry_folderviewfont)));
168                 
169         g_free(prefs_common.smallfont);         
170         prefs_common.smallfont  = g_strdup(gtk_font_button_get_font_name
171                 (GTK_FONT_BUTTON(fonts->entry_summaryviewfont)));
172
173         g_free(prefs_common.textfont);          
174         prefs_common.textfont   = g_strdup(gtk_font_button_get_font_name
175                 (GTK_FONT_BUTTON(fonts->entry_messageviewfont)));
176
177         g_free(prefs_common.boldfont);
178         prefs_common.boldfont   = g_strdup(gtk_font_button_get_font_name
179                 (GTK_FONT_BUTTON(fonts->entry_boldfont)));
180 }
181
182 static void prefs_fonts_destroy_widget(PrefsPage *_page)
183 {
184         /* FontsPage *fonts = (FontsPage *) _page; */
185
186 }
187
188 FontsPage *prefs_fonts;
189
190 void prefs_fonts_init(void)
191 {
192         FontsPage *page;
193         static gchar *path[3];
194
195         path[0] = _("Display");
196         path[1] = _("Fonts");
197         path[2] = NULL;
198
199         page = g_new0(FontsPage, 1);
200         page->page.path = path;
201         page->page.create_widget = prefs_fonts_create_widget;
202         page->page.destroy_widget = prefs_fonts_destroy_widget;
203         page->page.save_page = prefs_fonts_save;
204         page->page.weight = 60.0;
205         prefs_gtk_register_page((PrefsPage *) page);
206         prefs_fonts = page;
207 }
208
209 void prefs_fonts_done(void)
210 {
211         prefs_gtk_unregister_page((PrefsPage *) prefs_fonts);
212         g_free(prefs_fonts);
213 }