1 |
james |
16 |
/* |
2 |
|
|
* dialog_riscos.c -- dialog creation, RISC OS |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "gui.h" |
6 |
|
|
|
7 |
|
|
/****************************************************************************************/ |
8 |
|
|
/* Dialog creation functions */ |
9 |
|
|
/****************************************************************************************/ |
10 |
|
|
|
11 |
|
|
#define DIALOG_ICON_CHUNK 10 |
12 |
|
|
#define DIALOG_NONE 0xffffffff |
13 |
|
|
|
14 |
|
|
static gui_window_id dialog_id = DIALOG_NONE; |
15 |
|
|
static wimp_window *dialog_block; |
16 |
|
|
static int dialog_block_icons; |
17 |
|
|
static int dialog_icons; |
18 |
|
|
static int dialog_y; |
19 |
|
|
static int dialog_x; |
20 |
|
|
static struct gui_dialog_icon *dialog_icon; |
21 |
|
|
|
22 |
|
|
/* |
23 |
|
|
* gui_start_dialog -- start creating a dialogue window |
24 |
|
|
* |
25 |
|
|
* => title -- window title |
26 |
|
|
* |
27 |
|
|
* <= nothing |
28 |
|
|
*/ |
29 |
|
|
|
30 |
|
|
void gui_start_dialog(char *title, unsigned int width, |
31 |
|
|
bool close, const char *help) |
32 |
|
|
{ |
33 |
|
|
assert(dialog_id == DIALOG_NONE); |
34 |
|
|
|
35 |
|
|
#ifdef DEBUG |
36 |
|
|
printf("gui_start_dialog: title = '%s'\n", title); |
37 |
|
|
fflush(stdout); |
38 |
|
|
#endif |
39 |
|
|
|
40 |
|
|
dialog_id = gui_get_free_window_id(); |
41 |
|
|
|
42 |
|
|
dialog_block_icons = DIALOG_ICON_CHUNK; |
43 |
|
|
dialog_icons = 0; |
44 |
|
|
dialog_y = 4; |
45 |
|
|
dialog_x = width; |
46 |
|
|
|
47 |
|
|
dialog_icon = malloc(dialog_block_icons * sizeof(struct gui_dialog_icon)); |
48 |
|
|
if (!dialog_icon) gui_raise_error("memory"); |
49 |
|
|
|
50 |
|
|
dialog_block = malloc(wimp_SIZEOF_WINDOW(dialog_block_icons)); |
51 |
|
|
if (!dialog_block) gui_raise_error("memory"); |
52 |
|
|
|
53 |
|
|
dialog_block->flags = wimp_WINDOW_MOVEABLE | wimp_WINDOW_AUTO_REDRAW | |
54 |
|
|
wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_BACK_ICON | wimp_WINDOW_TITLE_ICON | |
55 |
|
|
(close ? wimp_WINDOW_CLOSE_ICON : 0); |
56 |
|
|
dialog_block->title_fg = wimp_COLOUR_BLACK; |
57 |
|
|
dialog_block->title_bg = wimp_COLOUR_LIGHT_GREY; |
58 |
|
|
dialog_block->work_fg = wimp_COLOUR_BLACK; |
59 |
|
|
dialog_block->work_bg = wimp_COLOUR_VERY_LIGHT_GREY; |
60 |
|
|
dialog_block->highlight_bg = wimp_COLOUR_CREAM; |
61 |
|
|
dialog_block->extent.x0 = dialog_block->extent.y1 = 0; |
62 |
|
|
dialog_block->extent.x1 = width; |
63 |
|
|
dialog_block->title_flags = wimp_ICON_TEXT | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | |
64 |
|
|
wimp_ICON_INDIRECTED; |
65 |
|
|
dialog_block->work_flags = 0; |
66 |
|
|
dialog_block->sprite_area = (osspriteop_area *) 1; |
67 |
|
|
dialog_block->xmin = dialog_block->ymin = 1; |
68 |
|
|
dialog_block->title_data.indirected_text.text = title; |
69 |
|
|
dialog_block->title_data.indirected_text.validation = 0; |
70 |
|
|
|
71 |
|
|
gui_window_list[dialog_id].title = title; |
72 |
|
|
gui_window_list[dialog_id].help = help; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
/* |
77 |
|
|
* gui_create_dialog -- finish creating and open a dialogue window |
78 |
|
|
* |
79 |
|
|
* => nothing |
80 |
|
|
* |
81 |
|
|
* <= window id |
82 |
|
|
*/ |
83 |
|
|
|
84 |
|
|
gui_window_id gui_create_dialog() |
85 |
|
|
{ |
86 |
|
|
gui_window_id id = dialog_id; |
87 |
|
|
wimp_w handle; |
88 |
|
|
wimp_open open; |
89 |
|
|
|
90 |
|
|
assert(dialog_id != DIALOG_NONE); |
91 |
|
|
|
92 |
|
|
dialog_y += 4; |
93 |
|
|
|
94 |
|
|
dialog_block->extent.y0 = -dialog_y; |
95 |
|
|
dialog_block->icon_count = dialog_icons; |
96 |
|
|
|
97 |
|
|
gui_error = xwimp_create_window(dialog_block, &handle); |
98 |
|
|
gui_check_error(); |
99 |
|
|
|
100 |
|
|
gui_window_list[dialog_id].used = DIALOG; |
101 |
|
|
gui_window_list[dialog_id].handle = handle; |
102 |
|
|
gui_window_list[dialog_id].close_fn = gui_remove_window; |
103 |
|
|
gui_window_list[dialog_id].redraw_fn = NULL; |
104 |
|
|
gui_window_list[dialog_id].click_fn = NULL; |
105 |
|
|
gui_window_list[dialog_id].resize_fn = NULL; |
106 |
|
|
gui_window_list[dialog_id].key_fn = NULL; |
107 |
|
|
gui_window_list[dialog_id].input_fn = NULL; |
108 |
|
|
gui_window_list[dialog_id].menu_fn = NULL; |
109 |
|
|
gui_window_list[dialog_id].width = dialog_block->extent.x1; |
110 |
|
|
gui_window_list[dialog_id].height = dialog_y; |
111 |
|
|
gui_window_list[dialog_id].menu = NULL; |
112 |
|
|
gui_window_list[dialog_id].icon = dialog_icon; |
113 |
|
|
|
114 |
|
|
free(dialog_block); |
115 |
|
|
|
116 |
|
|
open.w = handle; |
117 |
|
|
open.visible.x0 = open.visible.y0 = 300; |
118 |
|
|
open.visible.x1 = 300 + gui_window_list[dialog_id].width; |
119 |
|
|
open.visible.y1 = 300 + dialog_y; |
120 |
|
|
open.xscroll = open.yscroll = 0; |
121 |
|
|
open.next = wimp_TOP; |
122 |
|
|
gui_error = xwimp_open_window(&open); |
123 |
|
|
gui_check_error(); |
124 |
|
|
|
125 |
|
|
dialog_id = DIALOG_NONE; |
126 |
|
|
|
127 |
|
|
#ifdef DEBUG |
128 |
|
|
printf("gui_create_dialog: id = 0x%x, handle = 0x%x\n", dialog_id, |
129 |
|
|
(unsigned int) handle); |
130 |
|
|
fflush(stdout); |
131 |
|
|
#endif |
132 |
|
|
|
133 |
|
|
return id; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
|
137 |
|
|
/* |
138 |
|
|
* ensure_dialog_space -- allocate memory for icons if necessary |
139 |
|
|
* |
140 |
|
|
* => nothing |
141 |
|
|
* |
142 |
|
|
* <= nothing |
143 |
|
|
*/ |
144 |
|
|
|
145 |
|
|
void ensure_dialog_space(void) |
146 |
|
|
{ |
147 |
|
|
if (dialog_icons == dialog_block_icons) |
148 |
|
|
{ |
149 |
|
|
dialog_block_icons += DIALOG_ICON_CHUNK; |
150 |
|
|
dialog_block = realloc(dialog_block, wimp_SIZEOF_WINDOW(dialog_block_icons)); |
151 |
|
|
dialog_icon = realloc(dialog_icon, dialog_block_icons * sizeof(struct gui_dialog_icon)); |
152 |
|
|
if (!dialog_block || !dialog_icon) |
153 |
|
|
{ |
154 |
|
|
/* free(dialog_block);*/ |
155 |
|
|
dialog_id = DIALOG_NONE; |
156 |
|
|
gui_raise_error("memory"); |
157 |
|
|
} |
158 |
|
|
} |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
|
162 |
|
|
/* |
163 |
|
|
* gui_create_label -- create a text label |
164 |
|
|
* |
165 |
|
|
* => text -- label text |
166 |
|
|
* |
167 |
|
|
* <= nothing |
168 |
|
|
*/ |
169 |
|
|
|
170 |
|
|
void gui_create_label(char *text, const char *help) |
171 |
|
|
{ |
172 |
|
|
assert(dialog_id != DIALOG_NONE); |
173 |
|
|
|
174 |
|
|
#ifdef DEBUG |
175 |
|
|
printf("gui_create_label: text = '%s'\n", text); |
176 |
|
|
fflush(stdout); |
177 |
|
|
#endif |
178 |
|
|
|
179 |
|
|
ensure_dialog_space(); |
180 |
|
|
|
181 |
|
|
dialog_block->icons[dialog_icons].extent.x0 = 0; |
182 |
|
|
dialog_block->icons[dialog_icons].extent.y0 = -(dialog_y + 52); |
183 |
|
|
dialog_block->icons[dialog_icons].extent.x1 = dialog_block->extent.x1; |
184 |
|
|
dialog_block->icons[dialog_icons].extent.y1 = -dialog_y; |
185 |
|
|
dialog_block->icons[dialog_icons].flags = wimp_ICON_TEXT | wimp_ICON_HCENTRED | |
186 |
|
|
wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | |
187 |
|
|
wimp_BUTTON_NEVER << wimp_ICON_BUTTON_TYPE_SHIFT | |
188 |
|
|
wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT | |
189 |
|
|
wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT; |
190 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.text = text; |
191 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.validation = 0; |
192 |
|
|
|
193 |
|
|
dialog_icon[dialog_icons].type = ICON_NONE; |
194 |
|
|
dialog_icon[dialog_icons].help = help; |
195 |
|
|
|
196 |
|
|
dialog_icons++; |
197 |
|
|
dialog_y += 52; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
|
201 |
|
|
/* |
202 |
|
|
* gui_create_text_box -- create a labelled writeable text box |
203 |
|
|
* |
204 |
|
|
* => text -- label text |
205 |
|
|
* mask -- entry mask (eg. '0-9' etc) |
206 |
|
|
* |
207 |
|
|
* <= gadget id |
208 |
|
|
* 0 if an error occurred |
209 |
|
|
*/ |
210 |
|
|
|
211 |
|
|
gui_gadget_id gui_create_text_box(char *text, const char *mask, const char *help) |
212 |
|
|
{ |
213 |
|
|
assert(dialog_id != DIALOG_NONE); |
214 |
|
|
|
215 |
|
|
#ifdef DEBUG |
216 |
|
|
printf("gui_create_text_box: text = '%s', mask = '%s'\n", text, mask); |
217 |
|
|
fflush(stdout); |
218 |
|
|
#endif |
219 |
|
|
|
220 |
|
|
ensure_dialog_space(); |
221 |
|
|
|
222 |
|
|
dialog_block->icons[dialog_icons].extent.x0 = 0; |
223 |
|
|
dialog_block->icons[dialog_icons].extent.y0 = -(dialog_y + 60); |
224 |
|
|
dialog_block->icons[dialog_icons].extent.x1 = dialog_block->extent.x1 * 0.25; |
225 |
|
|
dialog_block->icons[dialog_icons].extent.y1 = -dialog_y; |
226 |
|
|
dialog_block->icons[dialog_icons].flags = wimp_ICON_TEXT | wimp_ICON_RJUSTIFIED | |
227 |
|
|
wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | |
228 |
|
|
wimp_BUTTON_NEVER << wimp_ICON_BUTTON_TYPE_SHIFT | |
229 |
|
|
wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT | |
230 |
|
|
wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT; |
231 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.text = text; |
232 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.validation = 0; |
233 |
|
|
|
234 |
|
|
dialog_icon[dialog_icons].type = ICON_NONE; |
235 |
|
|
dialog_icon[dialog_icons].help = help; |
236 |
|
|
|
237 |
|
|
dialog_icons++; |
238 |
|
|
|
239 |
|
|
ensure_dialog_space(); |
240 |
|
|
|
241 |
|
|
dialog_block->icons[dialog_icons].extent.x0 = dialog_block->extent.x1 * 0.25; |
242 |
|
|
dialog_block->icons[dialog_icons].extent.y0 = -(dialog_y + 56); |
243 |
|
|
dialog_block->icons[dialog_icons].extent.x1 = dialog_block->extent.x1 - 8; |
244 |
|
|
dialog_block->icons[dialog_icons].extent.y1 = -(dialog_y + 4); |
245 |
|
|
dialog_block->icons[dialog_icons].flags = wimp_ICON_TEXT | wimp_ICON_VCENTRED | |
246 |
|
|
wimp_ICON_INDIRECTED | wimp_ICON_BORDER | wimp_ICON_FILLED | |
247 |
|
|
wimp_BUTTON_WRITABLE << wimp_ICON_BUTTON_TYPE_SHIFT | |
248 |
|
|
wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT | |
249 |
|
|
wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT; |
250 |
|
|
if (!(dialog_block->icons[dialog_icons].data.indirected_text.text = calloc(20, 1))) |
251 |
|
|
{ |
252 |
|
|
free(dialog_block); |
253 |
|
|
dialog_id = DIALOG_NONE; |
254 |
|
|
gui_raise_error("memory"); |
255 |
|
|
} |
256 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.validation = (char *) "kta;pptr_write,4,4"; |
257 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.size = 20; |
258 |
|
|
|
259 |
|
|
dialog_icon[dialog_icons].type = ICON_NONE; |
260 |
|
|
dialog_icon[dialog_icons].help = help; |
261 |
|
|
|
262 |
|
|
dialog_icons++; |
263 |
|
|
dialog_y += 60; |
264 |
|
|
|
265 |
|
|
return (gui_gadget_id) dialog_icons - 1; |
266 |
|
|
} |
267 |
|
|
|
268 |
|
|
|
269 |
|
|
/* |
270 |
|
|
* gui_create_text_box -- create a labelled display text box |
271 |
|
|
* |
272 |
|
|
* => text -- label text |
273 |
|
|
* value -- display text |
274 |
|
|
* |
275 |
|
|
* <= gadget id |
276 |
|
|
* 0 if an error occurred |
277 |
|
|
*/ |
278 |
|
|
|
279 |
|
|
gui_gadget_id gui_create_display_box(char *text, char *value, const char *help) |
280 |
|
|
{ |
281 |
|
|
assert(dialog_id != DIALOG_NONE); |
282 |
|
|
|
283 |
|
|
#ifdef DEBUG |
284 |
|
|
printf("gui_create_display_box: text = '%s'\n", text); |
285 |
|
|
fflush(stdout); |
286 |
|
|
#endif |
287 |
|
|
|
288 |
|
|
ensure_dialog_space(); |
289 |
|
|
|
290 |
|
|
dialog_block->icons[dialog_icons].extent.x0 = 0; |
291 |
|
|
dialog_block->icons[dialog_icons].extent.y0 = -(dialog_y + 60); |
292 |
|
|
dialog_block->icons[dialog_icons].extent.x1 = dialog_block->extent.x1 * 0.25; |
293 |
|
|
dialog_block->icons[dialog_icons].extent.y1 = -dialog_y; |
294 |
|
|
dialog_block->icons[dialog_icons].flags = wimp_ICON_TEXT | wimp_ICON_RJUSTIFIED | |
295 |
|
|
wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | |
296 |
|
|
wimp_BUTTON_NEVER << wimp_ICON_BUTTON_TYPE_SHIFT | |
297 |
|
|
wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT | |
298 |
|
|
wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT; |
299 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.text = text; |
300 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.validation = 0; |
301 |
|
|
|
302 |
|
|
dialog_icon[dialog_icons].type = ICON_NONE; |
303 |
|
|
dialog_icon[dialog_icons].help = help; |
304 |
|
|
|
305 |
|
|
dialog_icons++; |
306 |
|
|
|
307 |
|
|
ensure_dialog_space(); |
308 |
|
|
|
309 |
|
|
dialog_block->icons[dialog_icons].extent.x0 = dialog_block->extent.x1 * 0.25; |
310 |
|
|
dialog_block->icons[dialog_icons].extent.y0 = -(dialog_y + 56); |
311 |
|
|
dialog_block->icons[dialog_icons].extent.x1 = dialog_block->extent.x1 - 8; |
312 |
|
|
dialog_block->icons[dialog_icons].extent.y1 = -(dialog_y + 4); |
313 |
|
|
dialog_block->icons[dialog_icons].flags = wimp_ICON_TEXT | wimp_ICON_VCENTRED | |
314 |
|
|
wimp_ICON_INDIRECTED | wimp_ICON_BORDER | wimp_ICON_FILLED | |
315 |
|
|
wimp_BUTTON_NEVER << wimp_ICON_BUTTON_TYPE_SHIFT | |
316 |
|
|
wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT | |
317 |
|
|
wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT; |
318 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.text = value; |
319 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.validation = (char *) "r2"; |
320 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.size = 20; |
321 |
|
|
|
322 |
|
|
dialog_icon[dialog_icons].type = ICON_NONE; |
323 |
|
|
dialog_icon[dialog_icons].help = help; |
324 |
|
|
|
325 |
|
|
dialog_icons++; |
326 |
|
|
dialog_y += 60; |
327 |
|
|
|
328 |
|
|
return (gui_gadget_id) dialog_icons - 1; |
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
|
332 |
|
|
/* |
333 |
|
|
* gui_create_button -- create an action button |
334 |
|
|
* |
335 |
|
|
* => text -- button text |
336 |
|
|
* click_fn -- function called when button is clicked |
337 |
|
|
* |
338 |
|
|
* <= nothing |
339 |
|
|
*/ |
340 |
|
|
|
341 |
|
|
void gui_create_button(char *text, void (*click_fn)(gui_window_id window_id, gui_gadget_id gadget_id), const char *help) |
342 |
|
|
{ |
343 |
|
|
unsigned const int border = (dialog_x == dialog_block->extent.x1 ? 8 : 0); |
344 |
|
|
|
345 |
|
|
assert(dialog_id != DIALOG_NONE); |
346 |
|
|
|
347 |
|
|
#ifdef DEBUG |
348 |
|
|
printf("gui_create_button: text = '%s'\n", text); |
349 |
|
|
fflush(stdout); |
350 |
|
|
#endif |
351 |
|
|
|
352 |
|
|
ensure_dialog_space(); |
353 |
|
|
|
354 |
|
|
if (dialog_x == dialog_block->extent.x1) dialog_y += 84; |
355 |
|
|
|
356 |
|
|
dialog_block->icons[dialog_icons].extent.x0 = dialog_x - 140 - border * 2; |
357 |
|
|
dialog_block->icons[dialog_icons].extent.y0 = -(dialog_y - 16 + border); |
358 |
|
|
dialog_block->icons[dialog_icons].extent.x1 = dialog_x - 8; |
359 |
|
|
dialog_block->icons[dialog_icons].extent.y1 = -(dialog_y - 68 - border); |
360 |
|
|
dialog_block->icons[dialog_icons].flags = wimp_ICON_TEXT | wimp_ICON_HCENTRED | |
361 |
|
|
wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_BORDER | wimp_ICON_FILLED | |
362 |
|
|
wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT | |
363 |
|
|
wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT | |
364 |
|
|
wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT; |
365 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.text = text; |
366 |
|
|
dialog_block->icons[dialog_icons].data.indirected_text.validation = |
367 |
|
|
(dialog_x == dialog_block->extent.x1 ? (char *) "r6,3" : (char *) "r5,3"); |
368 |
|
|
|
369 |
|
|
dialog_icon[dialog_icons].type = ICON_ACTION; |
370 |
|
|
dialog_icon[dialog_icons].click_fn = click_fn; |
371 |
|
|
dialog_icon[dialog_icons].help = help; |
372 |
|
|
|
373 |
|
|
dialog_icons++; |
374 |
|
|
dialog_x -= 140 + border * 2; |
375 |
|
|
} |