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