summaryrefslogtreecommitdiff
path: root/riscos/configure/con_memory.c
blob: 1bfa8d56796fa98590b3bb31894117f239e906e8 (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
/*
 * This file is part of NetSurf, http://netsurf-browser.org/
 * Licensed under the GNU General Public License,
 *		  http://www.opensource.org/licenses/gpl-license
 * Copyright 2006 Richard Wilson <info@tinct.net>
 */

#include "desktop/options.h"
#include "riscos/bitmap.h"
#include "riscos/options.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/dialog.h"
#include "riscos/configure/configure.h"


#define MEMORY_DIRECT_FIELD 3
#define MEMORY_DIRECT_DEC 4
#define MEMORY_DIRECT_INC 5
#define MEMORY_DIRECT_TEXT 6
#define MEMORY_DIRECT_AUTO 7
#define MEMORY_COMPRESSED_FIELD 9
#define MEMORY_COMPRESSED_DEC 10
#define MEMORY_COMPRESSED_INC 11
#define MEMORY_COMPRESSED_TEXT 12
#define MEMORY_COMPRESSED_AUTO 13
#define MEMORY_DEFAULT_BUTTON 14
#define MEMORY_CANCEL_BUTTON 15
#define MEMORY_OK_BUTTON 16

static bool ro_gui_options_memory_click(wimp_pointer *pointer);
static bool ro_gui_options_memory_ok(wimp_w w);
static void ro_gui_options_update_shading(wimp_w w);

bool ro_gui_options_memory_initialise(wimp_w w) {
	/* set the current values */
	ro_gui_set_icon_decimal(w, MEMORY_DIRECT_FIELD,
			(bitmap_direct_size * 10) >> 20, 1);
	ro_gui_set_icon_decimal(w, MEMORY_COMPRESSED_FIELD,
			(bitmap_compressed_size * 10) >> 20, 1);
	ro_gui_set_icon_selected_state(w, MEMORY_DIRECT_AUTO,
			(option_image_memory_direct == -1));
	ro_gui_set_icon_selected_state(w, MEMORY_COMPRESSED_AUTO,
			(option_image_memory_compressed == -1));
	ro_gui_options_update_shading(w);

	/* register icons */
	ro_gui_wimp_event_register_checkbox(w, MEMORY_DIRECT_AUTO);
	ro_gui_wimp_event_register_checkbox(w, MEMORY_COMPRESSED_AUTO);
	ro_gui_wimp_event_register_text_field(w, MEMORY_DIRECT_TEXT);
	ro_gui_wimp_event_register_text_field(w, MEMORY_COMPRESSED_TEXT);
	ro_gui_wimp_event_register_numeric_field(w, MEMORY_DIRECT_FIELD,
			MEMORY_DIRECT_INC, MEMORY_DIRECT_DEC,
			10, 5120, 10, 1);
	ro_gui_wimp_event_register_numeric_field(w, MEMORY_COMPRESSED_FIELD,
			MEMORY_COMPRESSED_INC, MEMORY_COMPRESSED_DEC,
			10, 5120, 10, 1);
	ro_gui_wimp_event_register_mouse_click(w,
			ro_gui_options_memory_click);
	ro_gui_wimp_event_register_cancel(w, MEMORY_CANCEL_BUTTON);
	ro_gui_wimp_event_register_ok(w, MEMORY_OK_BUTTON,
			ro_gui_options_memory_ok);
	ro_gui_wimp_event_set_help_prefix(w, "HelpMemoryConfig");
	ro_gui_wimp_event_memorise(w);
	return true;

}

bool ro_gui_options_memory_click(wimp_pointer *pointer) {
	switch (pointer->i) {
		case MEMORY_DIRECT_AUTO:
			ro_gui_options_update_shading(pointer->w);
			return false;
		case MEMORY_COMPRESSED_AUTO:
			ro_gui_options_update_shading(pointer->w);
			return false;
		case MEMORY_DEFAULT_BUTTON:
			ro_gui_set_icon_decimal(pointer->w, MEMORY_DIRECT_FIELD,
					(bitmap_direct_size * 10) >> 20, 1);
			ro_gui_set_icon_decimal(pointer->w, MEMORY_COMPRESSED_FIELD,
					(bitmap_compressed_size * 10) >> 20, 1);
			ro_gui_set_icon_selected_state(pointer->w,
					MEMORY_DIRECT_AUTO, true);
			ro_gui_set_icon_selected_state(pointer->w,
					MEMORY_COMPRESSED_AUTO, true);
			ro_gui_options_update_shading(pointer->w);
			return true;
	}
	return false;
}

void ro_gui_options_update_shading(wimp_w w) {
	bool shaded;

	shaded = ro_gui_get_icon_selected_state(w, MEMORY_DIRECT_AUTO);
	ro_gui_set_icon_shaded_state(w, MEMORY_DIRECT_FIELD, shaded);
	ro_gui_set_icon_shaded_state(w, MEMORY_DIRECT_INC, shaded);
	ro_gui_set_icon_shaded_state(w, MEMORY_DIRECT_DEC, shaded);
	ro_gui_set_icon_shaded_state(w, MEMORY_DIRECT_TEXT, shaded);
	shaded = ro_gui_get_icon_selected_state(w, MEMORY_COMPRESSED_AUTO);
	ro_gui_set_icon_shaded_state(w, MEMORY_COMPRESSED_FIELD, shaded);
	ro_gui_set_icon_shaded_state(w, MEMORY_COMPRESSED_INC, shaded);
	ro_gui_set_icon_shaded_state(w, MEMORY_COMPRESSED_DEC, shaded);
	ro_gui_set_icon_shaded_state(w, MEMORY_COMPRESSED_TEXT, shaded);
}

bool ro_gui_options_memory_ok(wimp_w w) {
	/* set the option values */
	if (ro_gui_get_icon_selected_state(w, MEMORY_DIRECT_AUTO))
		option_image_memory_direct = -1;
	else
		option_image_memory_direct =
			(((ro_gui_get_icon_decimal(w, MEMORY_DIRECT_FIELD, 1)
				<< 10) + 1023) / 10);
	if (ro_gui_get_icon_selected_state(w, MEMORY_COMPRESSED_AUTO))
		option_image_memory_compressed = -1;
	else
		option_image_memory_compressed =
			(((ro_gui_get_icon_decimal(w, MEMORY_COMPRESSED_FIELD, 1)
				<< 10) + 1023) / 10);
	/* update the memory usage */
	bitmap_initialise_memory();
	ro_gui_set_icon_decimal(w, MEMORY_DIRECT_FIELD,
			(bitmap_direct_size * 10) >> 20, 1);
	ro_gui_set_icon_decimal(w, MEMORY_COMPRESSED_FIELD,
			(bitmap_compressed_size * 10) >> 20, 1);
	/* save the options */
	ro_gui_save_options();
	return true;
}