NetSurf
con_fonts.c
Go to the documentation of this file.
1/*
2 * Copyright 2005 Richard Wilson <info@tinct.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf 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, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdbool.h>
20#include <stddef.h>
21
22#include "utils/nsoption.h"
23#include "utils/messages.h"
24#include "netsurf/plot_style.h"
25
26#include "riscos/gui.h"
27#include "riscos/font.h"
28#include "riscos/menus.h"
29#include "riscos/wimp.h"
30#include "riscos/wimp_event.h"
31#include "riscos/configure.h"
33#include "riscos/dialog.h"
34
35
36#define FONT_SANS_FIELD 3
37#define FONT_SANS_MENU 4
38#define FONT_SERIF_FIELD 6
39#define FONT_SERIF_MENU 7
40#define FONT_MONOSPACE_FIELD 9
41#define FONT_MONOSPACE_MENU 10
42#define FONT_CURSIVE_FIELD 12
43#define FONT_CURSIVE_MENU 13
44#define FONT_FANTASY_FIELD 15
45#define FONT_FANTASY_MENU 16
46#define FONT_DEFAULT_FIELD 18
47#define FONT_DEFAULT_MENU 19
48#define FONT_DEFAULT_SIZE 23
49#define FONT_DEFAULT_DEC 24
50#define FONT_DEFAULT_INC 25
51#define FONT_MINIMUM_SIZE 28
52#define FONT_MINIMUM_DEC 29
53#define FONT_MINIMUM_INC 30
54#define FONT_DEFAULT_BUTTON 32
55#define FONT_CANCEL_BUTTON 33
56#define FONT_OK_BUTTON 34
57
58/* This menu only ever gets created once */
59/** \todo The memory claimed for this menu should
60 * probably be released at some point */
61static wimp_menu *default_menu;
62
63static const char *font_names[PLOT_FONT_FAMILY_COUNT] = {
64 "Sans-serif",
65 "Serif",
66 "Monospace",
67 "Cursive",
68 "Fantasy"
69};
70
71static void ro_gui_options_fonts_default(wimp_pointer *pointer);
72static bool ro_gui_options_fonts_ok(wimp_w w);
73static bool ro_gui_options_fonts_init_menu(void);
74
76{
77 /* set the current values */
86 font_names[nsoption_int(font_default)], true);
87
89 return false;
90
91 /* initialise all functions for a newly created window */
93 FONT_SANS_MENU, rufl_family_menu);
95 FONT_SERIF_MENU, rufl_family_menu);
97 FONT_MONOSPACE_MENU, rufl_family_menu);
99 FONT_CURSIVE_MENU, rufl_family_menu);
101 FONT_FANTASY_MENU, rufl_family_menu);
105 FONT_DEFAULT_INC, FONT_DEFAULT_DEC, 50, 1000, 1, 1);
107 FONT_MINIMUM_INC, FONT_MINIMUM_DEC, 10, 500, 1, 1);
113 ro_gui_wimp_event_set_help_prefix(w, "HelpFontConfig");
115 return true;
116
117}
118
119void ro_gui_options_fonts_default(wimp_pointer *pointer)
120{
121 const char *fallback = nsfont_fallback_font();
122
123 /* set the default values */
124 ro_gui_set_icon_decimal(pointer->w, FONT_DEFAULT_SIZE, 128, 1);
125 ro_gui_set_icon_decimal(pointer->w, FONT_MINIMUM_SIZE, 85, 1);
127 nsfont_exists("Homerton") ? "Homerton" : fallback, true);
129 nsfont_exists("Trinity") ? "Trinity" : fallback, true);
131 nsfont_exists("Corpus") ? "Corpus" : fallback, true);
133 nsfont_exists("Churchill") ? "Churchill" : fallback, true);
135 nsfont_exists("Sassoon") ? "Sassoon" : fallback, true);
137 font_names[0], true);
138}
139
141{
142 unsigned int i;
143
144 nsoption_set_int(font_size,
146
147 nsoption_set_int(font_min_size,
149
150 if (nsoption_int(font_size) < nsoption_int(font_min_size)) {
151 nsoption_set_int(font_size, nsoption_int(font_min_size));
153
154}
155
156 nsoption_set_charp(font_sans,
158
159 nsoption_set_charp(font_serif,
161
162 nsoption_set_charp(font_mono,
164
165 nsoption_set_charp(font_cursive,
167
168 nsoption_set_charp(font_fantasy,
170
171 for (i = 0; i != 5; i++) {
172 if (!strcmp(font_names[i], ro_gui_get_icon_string(w,
174 break;
175 }
176 if (i == 5)
177 /* this should never happen, but still */
178 i = 0;
179
180 nsoption_set_int(font_default, i);
181
183 return true;
184}
185
187{
188 unsigned int i;
189
190 if (default_menu)
191 /* Already exists */
192 return true;
193
194 default_menu = malloc(wimp_SIZEOF_MENU(5));
195 if (!default_menu) {
196 ro_warn_user("NoMemory", 0);
197 return false;
198 }
199 default_menu->title_data.indirected_text.text =
200 (char *) messages_get("DefaultFonts");
202 for (i = 0; i < 5; i++) {
203 default_menu->entries[i].data.indirected_text.text =
204 (char *) font_names[i];
205 default_menu->entries[i].data.indirected_text.size =
206 strlen(font_names[i]);
207 }
208 return true;
209}
#define FONT_DEFAULT_MENU
Definition: con_fonts.c:47
#define FONT_MONOSPACE_MENU
Definition: con_fonts.c:41
#define FONT_FANTASY_MENU
Definition: con_fonts.c:45
#define FONT_DEFAULT_SIZE
Definition: con_fonts.c:48
#define FONT_DEFAULT_DEC
Definition: con_fonts.c:49
#define FONT_DEFAULT_BUTTON
Definition: con_fonts.c:54
#define FONT_OK_BUTTON
Definition: con_fonts.c:56
static void ro_gui_options_fonts_default(wimp_pointer *pointer)
Definition: con_fonts.c:119
#define FONT_CURSIVE_FIELD
Definition: con_fonts.c:42
#define FONT_MINIMUM_DEC
Definition: con_fonts.c:52
#define FONT_MINIMUM_INC
Definition: con_fonts.c:53
#define FONT_MONOSPACE_FIELD
Definition: con_fonts.c:40
bool ro_gui_options_fonts_initialise(wimp_w w)
Definition: con_fonts.c:75
#define FONT_SERIF_FIELD
Definition: con_fonts.c:38
#define FONT_SANS_MENU
Definition: con_fonts.c:37
static bool ro_gui_options_fonts_ok(wimp_w w)
Definition: con_fonts.c:140
#define FONT_CURSIVE_MENU
Definition: con_fonts.c:43
#define FONT_DEFAULT_INC
Definition: con_fonts.c:50
static wimp_menu * default_menu
Definition: con_fonts.c:61
#define FONT_MINIMUM_SIZE
Definition: con_fonts.c:51
#define FONT_SERIF_MENU
Definition: con_fonts.c:39
static const char * font_names[PLOT_FONT_FAMILY_COUNT]
Definition: con_fonts.c:63
#define FONT_SANS_FIELD
Definition: con_fonts.c:36
#define FONT_CANCEL_BUTTON
Definition: con_fonts.c:55
static bool ro_gui_options_fonts_init_menu(void)
Definition: con_fonts.c:186
#define FONT_DEFAULT_FIELD
Definition: con_fonts.c:46
#define FONT_FANTASY_FIELD
Definition: con_fonts.c:44
Automated RISC OS WIMP event handling (interface).
RISC OS option setting (interface).
void ro_gui_save_options(void)
Save the current options.
Definition: dialog.c:670
const char * nsfont_fallback_font(void)
Retrieve the fallback font name.
Definition: font.c:165
bool nsfont_exists(const char *font_family)
Check if a font family is available.
Definition: font.c:199
RISC OS font interface.
void ro_gui_menu_init_structure(wimp_menu *menu, int entries)
Initialise the basic state of a menu structure so all entries are indirected text with no flags,...
Definition: menus.c:682
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
plotter style interfaces, generic styles and style colour helpers.
@ PLOT_FONT_FAMILY_COUNT
Number of generic families.
Definition: plot_style.h:94
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2077
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
Definition: nsoption.h:348
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
Definition: nsoption.h:372
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8)
Set the contents of a text or sprite icon to a string.
Definition: wimp.c:269
int ro_gui_get_icon_decimal(wimp_w w, wimp_i i, int decimal_places)
Get the contents of an icon as a number.
Definition: wimp.c:423
const char * ro_gui_get_icon_string(wimp_w w, wimp_i i)
Read the contents of a text or sprite icon.
Definition: wimp.c:235
void ro_gui_set_icon_decimal(wimp_w w, wimp_i i, int value, int decimal_places)
Set the contents of an icon to a number.
Definition: wimp.c:392
General RISC OS WIMP/OS library functions (interface).
bool ro_gui_wimp_event_register_numeric_field(wimp_w w, wimp_i i, wimp_i up, wimp_i down, int min, int max, int stepping, int decimal_places)
Register a numeric field to be automatically handled.
Definition: wimp_event.c:1287
bool ro_gui_wimp_event_set_help_prefix(wimp_w w, const char *help_prefix)
Set the associated help prefix for a given window.
Definition: wimp_event.c:390
bool ro_gui_wimp_event_register_menu_gright(wimp_w w, wimp_i i, wimp_i gright, wimp_menu *menu)
Register an icon menu to be automatically handled.
Definition: wimp_event.c:1331
bool ro_gui_wimp_event_register_cancel(wimp_w w, wimp_i i)
Register a function to be called for the Cancel action on a window.
Definition: wimp_event.c:1403
bool ro_gui_wimp_event_memorise(wimp_w w)
Memorises the current state of any registered components in a window.
Definition: wimp_event.c:139
bool ro_gui_wimp_event_register_ok(wimp_w w, wimp_i i, bool(*callback)(wimp_w w))
Register a function to be called for the OK action on a window.
Definition: wimp_event.c:1417
bool ro_gui_wimp_event_register_button(wimp_w w, wimp_i i, void(*callback)(wimp_pointer *pointer))
Register a function to be called when a particular button is pressed.
Definition: wimp_event.c:1387
Automated RISC OS WIMP event handling (interface).