2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2009 Hiroyuki Yamamoto & The Claws Mail Team
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.
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.
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/>.
30 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
37 #include "gtk/prefswindow.h"
39 typedef struct _FontsPage
43 GtkWidget
*window
; /* do not modify */
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 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
51 GtkWidget
*print_checkbutton
;
52 GtkWidget
*entry_messageprintfont
;
56 static void prefs_fonts_create_widget(PrefsPage
*_page
, GtkWindow
*window
,
59 FontsPage
*prefs_fonts
= (FontsPage
*) _page
;
62 GtkWidget
*entry_folderview_smallfont
;
63 GtkWidget
*entry_folderview_normalfont
;
64 GtkWidget
*entry_folderview_boldfont
;
65 GtkWidget
*entry_messageviewfont
;
67 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
68 GtkWidget
*entry_messageprintfont
;
69 GtkWidget
*print_checkbutton
;
71 GtkWidget
*derive_from_normalfont_checkbutton
;
75 table
= gtk_table_new(10, 2, FALSE
);
76 gtk_widget_show(table
);
77 gtk_container_set_border_width(GTK_CONTAINER(table
), VBOX_BORDER
);
78 gtk_table_set_row_spacings(GTK_TABLE(table
), 4);
79 gtk_table_set_col_spacings(GTK_TABLE(table
), 8);
81 /* normal font label */
82 tmplabel
= gtk_label_new (_("Folder and Message Lists"));
83 gtk_widget_show (tmplabel
);
84 gtk_table_attach (GTK_TABLE (table
), tmplabel
, 0, 1, row
, row
+1,
85 (GtkAttachOptions
) GTK_FILL
,
86 (GtkAttachOptions
) (0), 0, 0);
87 gtk_label_set_justify(GTK_LABEL(tmplabel
), GTK_JUSTIFY_RIGHT
);
88 gtk_misc_set_alignment(GTK_MISC(tmplabel
), 1, 0.5);
90 /* normal font button */
91 entry_folderview_normalfont
= gtk_font_button_new_with_font (prefs_common
.normalfont
);
92 g_object_set(G_OBJECT(entry_folderview_normalfont
),
95 gtk_widget_show (entry_folderview_normalfont
);
96 gtk_table_attach (GTK_TABLE (table
), entry_folderview_normalfont
, 1, 2, row
, row
+1,
97 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
98 (GtkAttachOptions
) (0), 0, 0);
101 /* message font label */
102 tmplabel
= gtk_label_new (_("Message"));
103 gtk_widget_show (tmplabel
);
104 gtk_table_attach (GTK_TABLE (table
), tmplabel
, 0, 1, row
, row
+1,
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);
110 /* message font button */
111 entry_messageviewfont
= gtk_font_button_new_with_font (prefs_common
.textfont
);
112 g_object_set(G_OBJECT(entry_messageviewfont
),
115 gtk_widget_show (entry_messageviewfont
);
116 gtk_table_attach (GTK_TABLE (table
), entry_messageviewfont
, 1, 2, row
, row
+1,
117 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
118 (GtkAttachOptions
) (0), 0, 0);
121 vbox
= gtk_vbox_new(FALSE
, VSPACING_NARROW
);
122 gtk_widget_show(vbox
);
123 gtk_table_attach (GTK_TABLE (table
), vbox
, 0, 4, row
, row
+1,
124 (GtkAttachOptions
) GTK_FILL
,
125 (GtkAttachOptions
) (0), 0, 0);
128 /* derive from normal font check button */
129 derive_from_normalfont_checkbutton
= gtk_check_button_new_with_label(_("Derive small and bold fonts from Folder and Message Lists font"));
130 gtk_widget_show(derive_from_normalfont_checkbutton
);
131 gtk_table_attach (GTK_TABLE (table
), derive_from_normalfont_checkbutton
, 0, 2, row
, row
+1,
132 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
133 (GtkAttachOptions
) (0), 0, 0);
134 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(derive_from_normalfont_checkbutton
),
135 prefs_common
.derive_from_normal_font
);
138 /* small font label */
139 tmplabel
= gtk_label_new (_("Small"));
140 gtk_widget_show (tmplabel
);
141 gtk_table_attach (GTK_TABLE (table
), tmplabel
, 0, 1, row
, row
+1,
142 (GtkAttachOptions
) GTK_FILL
,
143 (GtkAttachOptions
) (0), 0, 0);
144 gtk_label_set_justify(GTK_LABEL(tmplabel
), GTK_JUSTIFY_RIGHT
);
145 gtk_misc_set_alignment(GTK_MISC(tmplabel
), 1, 0.5);
146 SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton
, tmplabel
);
148 /* small font button */
149 entry_folderview_smallfont
= gtk_font_button_new_with_font (prefs_common
.smallfont
);
150 g_object_set(G_OBJECT(entry_folderview_smallfont
),
153 gtk_widget_show (entry_folderview_smallfont
);
154 gtk_table_attach (GTK_TABLE (table
), entry_folderview_smallfont
, 1, 2, row
, row
+1,
155 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
156 (GtkAttachOptions
) (0), 0, 0);
157 SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton
, entry_folderview_smallfont
);
160 /* bold font label */
161 tmplabel
= gtk_label_new (_("Bold"));
162 gtk_widget_show (tmplabel
);
163 gtk_table_attach (GTK_TABLE (table
), tmplabel
, 0, 1, row
, row
+1,
164 (GtkAttachOptions
) GTK_FILL
,
165 (GtkAttachOptions
) (0), 0, 0);
166 gtk_label_set_justify(GTK_LABEL(tmplabel
), GTK_JUSTIFY_RIGHT
);
167 gtk_misc_set_alignment(GTK_MISC(tmplabel
), 1, 0.5);
168 SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton
, tmplabel
);
170 /* bold font button */
171 entry_folderview_boldfont
= gtk_font_button_new_with_font (prefs_common
.boldfont
);
172 g_object_set(G_OBJECT(entry_folderview_boldfont
),
175 gtk_widget_show (entry_folderview_boldfont
);
176 gtk_table_attach (GTK_TABLE (table
), entry_folderview_boldfont
, 1, 2, row
, row
+1,
177 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
178 (GtkAttachOptions
) (0), 0, 0);
179 SET_TOGGLE_SENSITIVITY_REVERSE (derive_from_normalfont_checkbutton
, entry_folderview_boldfont
);
182 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
183 /* print check button */
184 print_checkbutton
= gtk_check_button_new_with_label(_("Use different font for printing"));
185 gtk_widget_show(print_checkbutton
);
186 gtk_table_attach (GTK_TABLE (table
), print_checkbutton
, 0, 2, row
, row
+1,
187 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
188 (GtkAttachOptions
) (0), 0, 0);
189 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(print_checkbutton
),
190 prefs_common
.use_different_print_font
);
193 /* print font label */
194 tmplabel
= gtk_label_new (_("Message Printing"));
195 gtk_widget_show (tmplabel
);
196 gtk_table_attach (GTK_TABLE (table
), tmplabel
, 0, 1, row
, row
+1,
197 (GtkAttachOptions
) GTK_FILL
,
198 (GtkAttachOptions
) (0), 0, 0);
199 gtk_label_set_justify(GTK_LABEL(tmplabel
), GTK_JUSTIFY_RIGHT
);
200 gtk_misc_set_alignment(GTK_MISC(tmplabel
), 1, 0.5);
201 SET_TOGGLE_SENSITIVITY (print_checkbutton
, tmplabel
);
203 /* print font button */
204 entry_messageprintfont
= gtk_font_button_new_with_font (prefs_common
.printfont
);
205 g_object_set(G_OBJECT(entry_messageprintfont
),
208 gtk_widget_show (entry_messageprintfont
);
209 gtk_table_attach (GTK_TABLE (table
), entry_messageprintfont
, 1, 2, row
, row
+1,
210 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
211 (GtkAttachOptions
) (0), 0, 0);
212 SET_TOGGLE_SENSITIVITY (print_checkbutton
, entry_messageprintfont
);
216 prefs_fonts
->window
= GTK_WIDGET(window
);
217 prefs_fonts
->entry_folderview_smallfont
= entry_folderview_smallfont
;
218 prefs_fonts
->entry_folderview_normalfont
= entry_folderview_normalfont
;
219 prefs_fonts
->entry_folderview_boldfont
= entry_folderview_boldfont
;
220 prefs_fonts
->entry_messageviewfont
= entry_messageviewfont
;
221 prefs_fonts
->derive_from_normalfont_checkbutton
= derive_from_normalfont_checkbutton
;
222 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
223 prefs_fonts
->entry_messageprintfont
= entry_messageprintfont
;
224 prefs_fonts
->print_checkbutton
= print_checkbutton
;
227 prefs_fonts
->page
.widget
= table
;
230 static void prefs_fonts_save(PrefsPage
*_page
)
232 FontsPage
*fonts
= (FontsPage
*) _page
;
234 g_free(prefs_common
.boldfont
);
235 prefs_common
.boldfont
= g_strdup(gtk_font_button_get_font_name
236 (GTK_FONT_BUTTON(fonts
->entry_folderview_boldfont
)));
238 g_free(prefs_common
.normalfont
);
239 prefs_common
.normalfont
= g_strdup(gtk_font_button_get_font_name
240 (GTK_FONT_BUTTON(fonts
->entry_folderview_normalfont
)));
242 g_free(prefs_common
.smallfont
);
243 prefs_common
.smallfont
= g_strdup(gtk_font_button_get_font_name
244 (GTK_FONT_BUTTON(fonts
->entry_folderview_smallfont
)));
246 g_free(prefs_common
.textfont
);
247 prefs_common
.textfont
= g_strdup(gtk_font_button_get_font_name
248 (GTK_FONT_BUTTON(fonts
->entry_messageviewfont
)));
250 prefs_common
.derive_from_normal_font
= gtk_toggle_button_get_active
251 (GTK_TOGGLE_BUTTON(fonts
->derive_from_normalfont_checkbutton
));
253 #if defined(USE_GNOMEPRINT) || GTK_CHECK_VERSION(2,10,0)
254 g_free(prefs_common
.printfont
);
255 prefs_common
.printfont
= g_strdup(gtk_font_button_get_font_name
256 (GTK_FONT_BUTTON(fonts
->entry_messageprintfont
)));
257 prefs_common
.use_different_print_font
= gtk_toggle_button_get_active
258 (GTK_TOGGLE_BUTTON(fonts
->print_checkbutton
));
261 main_window_reflect_prefs_all();
264 static void prefs_fonts_destroy_widget(PrefsPage
*_page
)
266 /* FontsPage *fonts = (FontsPage *) _page; */
270 FontsPage
*prefs_fonts
;
272 void prefs_fonts_init(void)
275 static gchar
*path
[3];
277 path
[0] = _("Display");
278 path
[1] = _("Fonts");
281 page
= g_new0(FontsPage
, 1);
282 page
->page
.path
= path
;
283 page
->page
.create_widget
= prefs_fonts_create_widget
;
284 page
->page
.destroy_widget
= prefs_fonts_destroy_widget
;
285 page
->page
.save_page
= prefs_fonts_save
;
286 page
->page
.weight
= 135.0;
287 prefs_gtk_register_page((PrefsPage
*) page
);
291 void prefs_fonts_done(void)
293 prefs_gtk_unregister_page((PrefsPage
*) prefs_fonts
);