2005-08-13 [hoa] 1.9.13cvs33
[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 <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         GtkWidget *entry_boldfont;
48 } FontsPage;
49
50 void prefs_fonts_create_widget(PrefsPage *_page, GtkWindow *window, 
51                                gpointer data)
52 {
53         FontsPage *prefs_fonts = (FontsPage *) _page;
54
55         GtkWidget *table;
56         GtkWidget *entry_folderviewfont;
57         GtkWidget *entry_messageviewfont;
58         GtkWidget *entry_boldfont;
59         GtkWidget *tmplabel;
60         GtkWidget *vbox;
61
62         table = gtk_table_new(7, 2, FALSE);
63         gtk_widget_show(table);
64         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
65         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
66         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
67
68         tmplabel = gtk_label_new (_("Folder and Message Lists"));
69         gtk_widget_show (tmplabel);
70         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 0, 1,
71                          (GtkAttachOptions) GTK_FILL,
72                          (GtkAttachOptions) (0), 0, 0);
73         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
74         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
75
76         entry_folderviewfont = gtk_font_button_new_with_font (prefs_common.normalfont);
77         g_object_set(G_OBJECT(entry_folderviewfont), 
78                               "use-font", TRUE, 
79                               NULL);
80         gtk_widget_show (entry_folderviewfont);
81         gtk_table_attach (GTK_TABLE (table), entry_folderviewfont, 1, 2, 0, 1,
82                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
83                          (GtkAttachOptions) (0), 0, 0);
84
85         tmplabel = gtk_label_new (_("Message"));
86         gtk_widget_show (tmplabel);
87         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 2, 3,
88                          (GtkAttachOptions) GTK_FILL,
89                          (GtkAttachOptions) (0), 0, 0);
90         gtk_label_set_justify(GTK_LABEL(tmplabel), GTK_JUSTIFY_RIGHT);
91         gtk_misc_set_alignment(GTK_MISC(tmplabel), 1, 0.5);
92
93         entry_messageviewfont = gtk_font_button_new_with_font (prefs_common.textfont);
94         g_object_set(G_OBJECT(entry_messageviewfont), 
95                               "use-font", TRUE, 
96                               NULL);
97         gtk_widget_show (entry_messageviewfont);
98         gtk_table_attach (GTK_TABLE (table), entry_messageviewfont, 1, 2, 2, 3,
99                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
100                          (GtkAttachOptions) (0), 0, 0);
101
102         tmplabel = gtk_label_new (_("Bold"));
103         gtk_widget_show (tmplabel);
104         gtk_table_attach (GTK_TABLE (table), tmplabel, 0, 1, 3, 4,
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         entry_boldfont = gtk_font_button_new_with_font (prefs_common.boldfont);
111         g_object_set(G_OBJECT(entry_boldfont), 
112                               "use-font", TRUE, 
113                               NULL);
114         gtk_widget_show (entry_boldfont);
115         gtk_table_attach (GTK_TABLE (table), entry_boldfont, 1, 2, 3, 4,
116                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
117                          (GtkAttachOptions) (0), 0, 0);
118
119         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
120         gtk_widget_show(vbox);
121         gtk_table_attach (GTK_TABLE (table), vbox, 0, 4, 4, 5,
122                          (GtkAttachOptions) GTK_FILL,
123                          (GtkAttachOptions) (0), 0, 0);
124         
125         prefs_fonts->window                = GTK_WIDGET(window);
126         prefs_fonts->entry_folderviewfont  = entry_folderviewfont;
127         prefs_fonts->entry_messageviewfont = entry_messageviewfont;
128         prefs_fonts->entry_boldfont        = entry_boldfont;
129
130         prefs_fonts->page.widget = table;
131 }
132
133 void prefs_fonts_save(PrefsPage *_page)
134 {
135         FontsPage *fonts = (FontsPage *) _page;
136
137         g_free(prefs_common.normalfont);
138         prefs_common.normalfont = g_strdup(gtk_font_button_get_font_name
139                 (GTK_FONT_BUTTON(fonts->entry_folderviewfont)));
140                 
141         g_free(prefs_common.smallfont);         
142         prefs_common.smallfont  = g_strdup(gtk_font_button_get_font_name
143                 (GTK_FONT_BUTTON(fonts->entry_folderviewfont)));
144
145         g_free(prefs_common.textfont);          
146         prefs_common.textfont   = g_strdup(gtk_font_button_get_font_name
147                 (GTK_FONT_BUTTON(fonts->entry_messageviewfont)));
148
149         g_free(prefs_common.boldfont);
150         prefs_common.boldfont   = g_strdup(gtk_font_button_get_font_name
151                 (GTK_FONT_BUTTON(fonts->entry_boldfont)));
152                 
153         main_window_reflect_prefs_all();
154 }
155
156 static void prefs_fonts_destroy_widget(PrefsPage *_page)
157 {
158         /* FontsPage *fonts = (FontsPage *) _page; */
159
160 }
161
162 FontsPage *prefs_fonts;
163
164 void prefs_fonts_init(void)
165 {
166         FontsPage *page;
167         static gchar *path[3];
168
169         path[0] = _("Display");
170         path[1] = _("Fonts");
171         path[2] = NULL;
172
173         page = g_new0(FontsPage, 1);
174         page->page.path = path;
175         page->page.create_widget = prefs_fonts_create_widget;
176         page->page.destroy_widget = prefs_fonts_destroy_widget;
177         page->page.save_page = prefs_fonts_save;
178         page->page.weight = 135.0;
179         prefs_gtk_register_page((PrefsPage *) page);
180         prefs_fonts = page;
181 }
182
183 void prefs_fonts_done(void)
184 {
185         prefs_gtk_unregister_page((PrefsPage *) prefs_fonts);
186         g_free(prefs_fonts);
187 }