summaryrefslogtreecommitdiff
path: root/riscos/configure/con_fonts.c
blob: c2aa1dcf6329ae316c3c3e2d216b70c5ab2d5bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Copyright 2005 Richard Wilson <info@tinct.net>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdbool.h>

#include "utils/nsoption.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "desktop/plot_style.h"
#include "css/css.h"

#include "riscos/dialog.h"
#include "riscos/font.h"
#include "riscos/menus.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/configure.h"
#include "riscos/configure/configure.h"


#define FONT_SANS_FIELD 3
#define FONT_SANS_MENU 4
#define FONT_SERIF_FIELD 6
#define FONT_SERIF_MENU 7
#define FONT_MONOSPACE_FIELD 9
#define FONT_MONOSPACE_MENU 10
#define FONT_CURSIVE_FIELD 12
#define FONT_CURSIVE_MENU 13
#define FONT_FANTASY_FIELD 15
#define FONT_FANTASY_MENU 16
#define FONT_DEFAULT_FIELD 18
#define FONT_DEFAULT_MENU 19
#define FONT_DEFAULT_SIZE 23
#define FONT_DEFAULT_DEC 24
#define FONT_DEFAULT_INC 25
#define FONT_MINIMUM_SIZE 28
#define FONT_MINIMUM_DEC 29
#define FONT_MINIMUM_INC 30
#define FONT_DEFAULT_BUTTON 32
#define FONT_CANCEL_BUTTON 33
#define FONT_OK_BUTTON 34

/* This menu only ever gets created once */
/** \todo The memory claimed for this menu should
 * probably be released at some point */
static wimp_menu *default_menu;

static const char *font_names[PLOT_FONT_FAMILY_COUNT] = {
	"Sans-serif",
	"Serif",
	"Monospace",
	"Cursive",
	"Fantasy"
};

static void ro_gui_options_fonts_default(wimp_pointer *pointer);
static bool ro_gui_options_fonts_ok(wimp_w w);
static bool ro_gui_options_fonts_init_menu(void);

bool ro_gui_options_fonts_initialise(wimp_w w)
{
	/* set the current values */
	ro_gui_set_icon_decimal(w, FONT_DEFAULT_SIZE, nsoption_int(font_size), 1);
	ro_gui_set_icon_decimal(w, FONT_MINIMUM_SIZE, nsoption_int(font_min_size), 1);
	ro_gui_set_icon_string(w, FONT_SANS_FIELD, nsoption_charp(font_sans), true);
	ro_gui_set_icon_string(w, FONT_SERIF_FIELD, nsoption_charp(font_serif), true);
	ro_gui_set_icon_string(w, FONT_MONOSPACE_FIELD, nsoption_charp(font_mono), true);
	ro_gui_set_icon_string(w, FONT_CURSIVE_FIELD, nsoption_charp(font_cursive), true);
	ro_gui_set_icon_string(w, FONT_FANTASY_FIELD, nsoption_charp(font_fantasy), true);
	ro_gui_set_icon_string(w, FONT_DEFAULT_FIELD,
			       font_names[nsoption_int(font_default)], true);

	if (!ro_gui_options_fonts_init_menu())
		return false;

	/* initialise all functions for a newly created window */
	ro_gui_wimp_event_register_menu_gright(w, FONT_SANS_FIELD,
			FONT_SANS_MENU, rufl_family_menu);
	ro_gui_wimp_event_register_menu_gright(w, FONT_SERIF_FIELD,
			FONT_SERIF_MENU, rufl_family_menu);
	ro_gui_wimp_event_register_menu_gright(w, FONT_MONOSPACE_FIELD,
			FONT_MONOSPACE_MENU, rufl_family_menu);
	ro_gui_wimp_event_register_menu_gright(w, FONT_CURSIVE_FIELD,
			FONT_CURSIVE_MENU, rufl_family_menu);
	ro_gui_wimp_event_register_menu_gright(w, FONT_FANTASY_FIELD,
			FONT_FANTASY_MENU, rufl_family_menu);
	ro_gui_wimp_event_register_menu_gright(w, FONT_DEFAULT_FIELD,
			FONT_DEFAULT_MENU, default_menu);
	ro_gui_wimp_event_register_numeric_field(w, FONT_DEFAULT_SIZE,
			FONT_DEFAULT_INC, FONT_DEFAULT_DEC, 50, 1000, 1, 1);
	ro_gui_wimp_event_register_numeric_field(w, FONT_MINIMUM_SIZE,
			FONT_MINIMUM_INC, FONT_MINIMUM_DEC, 10, 500, 1, 1);
	ro_gui_wimp_event_register_button(w, FONT_DEFAULT_BUTTON,
			ro_gui_options_fonts_default);
	ro_gui_wimp_event_register_cancel(w, FONT_CANCEL_BUTTON);
	ro_gui_wimp_event_register_ok(w, FONT_OK_BUTTON,
			ro_gui_options_fonts_ok);
	ro_gui_wimp_event_set_help_prefix(w, "HelpFontConfig");
	ro_gui_wimp_event_memorise(w);
	return true;

}

void ro_gui_options_fonts_default(wimp_pointer *pointer)
{
	const char *fallback = nsfont_fallback_font();

	/* set the default values */
	ro_gui_set_icon_decimal(pointer->w, FONT_DEFAULT_SIZE, 128, 1);
	ro_gui_set_icon_decimal(pointer->w, FONT_MINIMUM_SIZE, 85, 1);
	ro_gui_set_icon_string(pointer->w, FONT_SANS_FIELD,
			nsfont_exists("Homerton") ? "Homerton" : fallback, true);
	ro_gui_set_icon_string(pointer->w, FONT_SERIF_FIELD,
			nsfont_exists("Trinity") ? "Trinity" : fallback, true);
	ro_gui_set_icon_string(pointer->w, FONT_MONOSPACE_FIELD,
			nsfont_exists("Corpus") ? "Corpus" : fallback, true);
	ro_gui_set_icon_string(pointer->w, FONT_CURSIVE_FIELD,
			nsfont_exists("Churchill") ? "Churchill" : fallback, true);
	ro_gui_set_icon_string(pointer->w, FONT_FANTASY_FIELD,
			nsfont_exists("Sassoon") ? "Sassoon" : fallback, true);
	ro_gui_set_icon_string(pointer->w, FONT_DEFAULT_FIELD,
			font_names[0], true);
}

bool ro_gui_options_fonts_ok(wimp_w w)
{
	unsigned int i;

	nsoption_set_int(font_size,
			 ro_gui_get_icon_decimal(w, FONT_DEFAULT_SIZE, 1));

	nsoption_set_int(font_min_size,
			 ro_gui_get_icon_decimal(w, FONT_MINIMUM_SIZE, 1));

	if (nsoption_int(font_size) < nsoption_int(font_min_size)) {
		nsoption_set_int(font_size, nsoption_int(font_min_size));
		ro_gui_set_icon_decimal(w, FONT_DEFAULT_SIZE, nsoption_int(font_size), 1);
	
}

	nsoption_set_charp(font_sans,
			   strdup(ro_gui_get_icon_string(w, FONT_SANS_FIELD)));

	nsoption_set_charp(font_serif,
			   strdup(ro_gui_get_icon_string(w, FONT_SERIF_FIELD)));

	nsoption_set_charp(font_mono,
			   strdup(ro_gui_get_icon_string(w, FONT_MONOSPACE_FIELD)));

	nsoption_set_charp(font_cursive,
			   strdup(ro_gui_get_icon_string(w, FONT_CURSIVE_FIELD)));

	nsoption_set_charp(font_fantasy,
			   strdup(ro_gui_get_icon_string(w, FONT_FANTASY_FIELD)));

	for (i = 0; i != 5; i++) {
		if (!strcmp(font_names[i], ro_gui_get_icon_string(w,
				FONT_DEFAULT_FIELD)))
			break;
	}
	if (i == 5)
		/* this should never happen, but still */
		i = 0;

	nsoption_set_int(font_default, i);

	ro_gui_save_options();
	return true;
}

bool ro_gui_options_fonts_init_menu(void)
{
	unsigned int i;

	if (default_menu)
		/* Already exists */
		return true;

	default_menu = malloc(wimp_SIZEOF_MENU(5));
	if (!default_menu) {
		warn_user("NoMemory", 0);
		return false;
	}
	default_menu->title_data.indirected_text.text =
			(char *) messages_get("DefaultFonts");
	ro_gui_menu_init_structure(default_menu, 5);
	for (i = 0; i < 5; i++) {
		default_menu->entries[i].data.indirected_text.text =
				(char *) font_names[i];
		default_menu->entries[i].data.indirected_text.size =
				strlen(font_names[i]);
	}
	return true;
}