/[james]/archive/guilib/guitest.c
ViewVC logotype

Contents of /archive/guilib/guitest.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations) (download) (as text)
Mon Feb 10 22:56:40 2003 UTC (21 years, 8 months ago) by james
File MIME type: text/x-csrc
File size: 18766 byte(s)
Initial import.

1 /*
2 * guitest.c
3 *
4 * Test program for portable gui library
5 */
6
7
8 #include "gui.h"
9
10
11 #define MARGIN 16
12
13
14 const char *task_name = "guitest";
15
16 struct gui_ta *test_doc;
17 struct gui_ta_position test_pos;
18 struct gui_ta_selection test_sel;
19 unsigned int selection = 0;
20
21
22 void click(gui_window_id window_id, unsigned int x, unsigned int y, unsigned int z)
23 {
24 switch (z)
25 {
26 case gui_CLICK:
27 {
28 gui_ta_position_xy(test_doc, &test_pos, x < MARGIN ? 0 : x - MARGIN, y < MARGIN ? 0 : y - MARGIN);
29 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
30 if (selection)
31 {
32 selection = 0;
33 gui_refresh_window(window_id);
34 }
35 break;
36 }
37 case gui_CLICK_RIGHT:
38 {
39 struct gui_ta_position pos;
40
41 gui_ta_position_xy(test_doc, &pos, x - MARGIN, y - MARGIN);
42 if (pos.content < test_pos.content ||
43 (pos.content == test_pos.content && (pos.word < test_pos.word ||
44 (pos.word == test_pos.word && pos.offset < test_pos.offset))))
45 {
46 test_sel.start = pos;
47 test_sel.end = test_pos;
48 }
49 else
50 {
51 test_sel.start = test_pos;
52 test_sel.end = pos;
53 }
54
55 selection = 1;
56 gui_refresh_window(window_id);
57 break;
58 }
59 case gui_CLICK_MENU:
60 {
61 gui_ta_export(test_doc, "export");
62 }
63 }
64 }
65
66
67 void redraw(const gui_window_id window_id, unsigned int invalid[])
68 {
69 if (invalid[0] <= MARGIN) gui_fill(0xffffff, invalid[0], invalid[1], MARGIN, invalid[3]);
70 if (invalid[1] <= MARGIN) gui_fill(0xffffff, invalid[0], invalid[1], invalid[2], MARGIN);
71 if (invalid[2] >= test_doc->width + MARGIN)
72 gui_fill(0xffffff, test_doc->width + MARGIN, invalid[1], invalid[2], invalid[3]);
73 if (invalid[3] >= test_doc->height + MARGIN)
74 gui_fill(0xffffff, invalid[0], test_doc->height + MARGIN, invalid[2], invalid[3]);
75
76 if (!(invalid[2] < MARGIN || invalid[0] > test_doc->width + MARGIN ||
77 invalid[3] < MARGIN || invalid[1] > test_doc->height + MARGIN))
78 gui_ta_render(test_doc, MARGIN, MARGIN, invalid, selection ? &test_sel : NULL);
79 }
80
81
82 void resize(const gui_window_id window_id, unsigned int width, unsigned int height)
83 {
84 if (width != test_doc->width + 2 * MARGIN)
85 {
86 gui_ta_reformat(test_doc, width - 2 * MARGIN);
87 gui_window_extent(window_id, 0, test_doc->height + 2 * MARGIN);
88 gui_ta_position_cwo(test_doc, &test_pos);
89 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
90 gui_refresh_window(window_id);
91 }
92 }
93
94
95 void input(const gui_window_id window_id, wchar_t key)
96 {
97 const unsigned int height = test_doc->height;
98
99 printf("input: key = %04x\n", key);
100
101 if ((key > 31 || key == 8) && selection)
102 {
103 selection = 0;
104 gui_ta_delete(test_doc, &test_sel.start, &test_sel.end, window_id, MARGIN, MARGIN);
105 test_pos = test_sel.start;
106 }
107
108 if (key > 32 && key != 127)
109 {
110 gui_ta_insert_char(test_doc, &test_pos, key, window_id, MARGIN, MARGIN);
111 test_pos.offset++;
112 }
113 else if (key == 32)
114 {
115 gui_ta_insert_split(test_doc, &test_pos, window_id, MARGIN, MARGIN);
116 test_pos.word++;
117 test_pos.offset = 0;
118 }
119 else if (key == 13)
120 {
121 gui_ta_insert_newline(test_doc, &test_pos, window_id, MARGIN, MARGIN);
122 test_pos.content++;
123 test_pos.word = test_pos.offset = 0;
124 /* test_pos.word++;
125 test_pos.offset = 0;*/
126 }
127 else if (key == 8 && !selection)
128 {
129 struct gui_ta_position start = test_pos;
130
131 if (start.offset > 0)
132 start.offset--;
133 else if (start.word > 0)
134 {
135 start.word--;
136 start.offset = wcslen((*(*test_doc->content)[start.content]->word)[start.word]->text);
137 }
138 else if (start.content > 0)
139 {
140 start.content--;
141 start.word = (*test_doc->content)[start.content]->words - 1;
142 start.offset = wcslen((*(*test_doc->content)[start.content]->word)[start.word]->text);
143 }
144 else
145 return;
146
147 gui_ta_delete(test_doc, &start, &test_pos, window_id, MARGIN, MARGIN);
148 test_pos = start;
149 }
150 else if (key == 127 && !selection)
151 {
152 struct gui_ta_position end = test_pos;
153
154 if (end.offset < wcslen((*(*test_doc->content)[end.content]->word)[end.word]->text))
155 end.offset++;
156 else if (end.word < (*test_doc->content)[end.content]->words - 1)
157 {
158 end.word++;
159 end.offset = 0;
160 }
161 else if (end.content < test_doc->contents - 1)
162 {
163 end.content++;
164 end.word = 0;
165 end.offset = 0;
166 }
167 else
168 return;
169
170 gui_ta_delete(test_doc, &test_pos, &end, window_id, MARGIN, MARGIN);
171 }
172
173 gui_ta_position_cwo(test_doc, &test_pos);
174 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
175
176 if (height != test_doc->height)
177 gui_window_extent(window_id, 2000, test_doc->height + 2 * MARGIN);
178 }
179
180
181 void key(const gui_window_id window_id, unsigned int key)
182 {
183 const unsigned int height = test_doc->height;
184
185 if (key == KEY_LEFT)
186 {
187 if (test_pos.offset > 0)
188 test_pos.offset--;
189 else if (test_pos.word > 0)
190 {
191 test_pos.word--;
192 test_pos.offset = wcslen((*(*test_doc->content)[test_pos.content]->word)[test_pos.word]->text);
193 }
194 else if (test_pos.content > 0)
195 {
196 test_pos.content--;
197 test_pos.word = (*test_doc->content)[test_pos.content]->words - 1;
198 test_pos.offset = wcslen((*(*test_doc->content)[test_pos.content]->word)[test_pos.word]->text);
199 }
200 else
201 return;
202 }
203 else if (key == KEY_RIGHT)
204 {
205 if (test_pos.offset < wcslen((*(*test_doc->content)[test_pos.content]->word)[test_pos.word]->text))
206 test_pos.offset++;
207 else if (test_pos.word < (*test_doc->content)[test_pos.content]->words - 1)
208 {
209 test_pos.word++;
210 test_pos.offset = 0;
211 }
212 else if (test_pos.content < test_doc->contents - 1)
213 {
214 test_pos.content++;
215 test_pos.word = 0;
216 test_pos.offset = 0;
217 }
218 else
219 return;
220 }
221 else if (key == KEY_DOWN)
222 {
223 gui_ta_position_xy(test_doc, &test_pos, test_pos.x, test_pos.y + 1);
224 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
225 return;
226 }
227 else if (key == KEY_UP)
228 {
229 gui_ta_position_xy(test_doc, &test_pos, test_pos.x,
230 test_pos.y - (*test_doc->content)[test_pos.content]->leading);
231 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
232 return;
233 }
234
235 gui_ta_position_cwo(test_doc, &test_pos);
236 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
237
238 if (height != test_doc->height)
239 gui_window_extent(window_id, 2000, test_doc->height + 2 * MARGIN);
240 }
241
242
243 void menuf(const gui_window_id window_id, signed int items[])
244 {
245 static char length[40];
246 gui_window_id info;
247 unsigned int c, words = 0;
248
249 switch (items[0])
250 {
251 case 0:
252 switch (items[1])
253 {
254 case 0:
255 for (c = 0; c < test_doc->contents; c++)
256 words += (*test_doc->content)[c]->words;
257 sprintf(length, gui_message[35], test_doc->contents, words);
258 gui_start_dialog(gui_message[32], 600, 1, "help!");
259 gui_create_display_box(gui_message[33], "Untitled", gui_message[39]);
260 gui_create_display_box(gui_message[34], length, gui_message[40]);
261 gui_create_display_box(gui_message[36], "Unicode text", gui_message[41]);
262 gui_create_display_box(gui_message[37], "22:25:01 27 Mar 2001",
263 gui_message[42]);
264 info = gui_create_dialog();
265 break;
266 }
267 break;
268
269 case 2:
270 switch (items[1])
271 {
272 case 3:
273 gui_ta_align(test_doc, test_pos.content, ALIGN_LEFT, window_id, MARGIN, MARGIN);
274 gui_ta_position_cwo(test_doc, &test_pos);
275 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
276 break;
277 case 4:
278 gui_ta_align(test_doc, test_pos.content, ALIGN_CENTRE, window_id, MARGIN, MARGIN);
279 gui_ta_position_cwo(test_doc, &test_pos);
280 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
281 break;
282 case 5:
283 gui_ta_align(test_doc, test_pos.content, ALIGN_RIGHT, window_id, MARGIN, MARGIN);
284 gui_ta_position_cwo(test_doc, &test_pos);
285 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
286 break;
287 case 6:
288 gui_ta_align(test_doc, test_pos.content, ALIGN_FULL, window_id, MARGIN, MARGIN);
289 gui_ta_position_cwo(test_doc, &test_pos);
290 gui_ta_caret(window_id, test_doc, &test_pos, MARGIN, MARGIN);
291 break;
292 }
293 break;
294 }
295 }
296
297
298 void task_initialise(void)
299 {
300 unsigned int helvetica, times;
301 wchar_t par1[] = { 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0020,
302 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0020,
303 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0020,
304 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0020,
305 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0020,
306 0x00a0, 0x00b0, 0x00c0, 0x00d0, 0x00e0, 0x00f0, 0x0020,
307 0x00a8, 0x00b8, 0x00c8, 0x00d8, 0x00e8, 0x00f8, 0x0020,
308 0x0100, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170, 0x0020,
309 0x0108, 0x0118, 0x0128, 0x0138, 0x0148, 0x0158, 0x0168, 0x0178, 0x0020,
310 0x02bc, 0x0399, 0x03b1, 0x03c8, 0x0414, 0x0423, 0x043f, 0x044a, 0x0020,
311 0x2010, 0x2020, 0x2030, 0x2122, 0x2212, 0x2251, 0xfb01, 0xfb02,
312 ' ','C','u','r','a','b','i','t','u','r',' ','s','e','m','p','e','r',' ','v','e','l','i','t','.',' ','S','e','d',' ','u','t',' ','p','e','d','e',' ','s','e','d',' ','e','r','a','t',' ','c','o','n','s','e','c','t','e','t','u','e','r',' ','p','e','l','l','e','n','t','e','s','q','u','e','.',' ','C','u','r','a','b','i','t','u','r',' ','m','a','u','r','i','s','.',' ','D','o','n','e','c',' ','a',' ','j','u','s','t','o',' ','e','u',' ','l','o','r','e','m',' ','t','i','n','c','i','d','u','n','t',' ','n','o','n','u','m','m','y','.',' ','P','r','a','e','s','e','n','t',' ','c','o','n','s','e','q','u','a','t',' ','e','s','t',' ','n','o','n',' ','l','a','c','u','s','.',' ','C','u','r','a','b','i','t','u','r',' ','c','u','r','s','u','s','.',' ','M','o','r','b','i',' ','u','l','t','r','i','c','e','s',',',' ','v','e','l','i','t',' ','i','n',' ','l','u','c','t','u','s',' ','s','c','e','l','e','r','i','s','q','u','e',',',' ','n','u','l','l','a',' ','t','u','r','p','i','s',' ','v','i','v','e','r','r','a',' ','m','a','s','s','a',',',' ','a',' ','i','n','t','e','r','d','u','m',' ','p','e','d','e',' ','t','o','r','t','o','r',' ','v','e','l',' ','l','a','c','u','s','.',' ','Q','u','i','s','q','u','e',' ','p','o','r','t','a',' ','l','i','b','e','r','o',' ','e','t',' ','d','o','l','o','r','.',' ','M','a','u','r','i','s',' ','t','e','m','p','o','r','.',' ','S','e','d',' ','a','n','t','e','.',' ','S','e','d',' ','u','l','t','r','i','c','e','s',',',' ','p','e','d','e',' ','a','t',' ','s','o','d','a','l','e','s',' ','p','o','r','t','t','i','t','o','r',',',' ','i','p','s','u','m',' ','s','a','p','i','e','n',' ','f','e','r','m','e','n','t','u','m',' ','l','e','o',',',' ','e','u',' ','c','o','n','s','e','q','u','a','t',' ','a','r','c','u',' ','q','u','a','m',' ','e','u',' ','l','a','c','u','s','.',' ','P','h','a','s','e','l','l','u','s',' ','b','l','a','n','d','i','t','.',' ','M','o','r','b','i',' ','s','i','t',' ','a','m','e','t',' ','l','e','c','t','u','s',' ','a','c',' ','p','u','r','u','s',' ','v','e','n','e','n','a','t','i','s',' ','l','o','b','o','r','t','i','s','.',' ','F','u','s','c','e',' ','v','e','l',' ','e','r','o','s','.',' ','F','u','s','c','e',' ','a','d','i','p','i','s','c','i','n','g','.',' ','A','e','n','e','a','n',' ','s','i','t',' ','a','m','e','t',' ','l','e','c','t','u','s',' ','n','o','n',' ','e','s','t',' ','c','o','n','s','e','c','t','e','t','u','e','r',' ','f','e','u','g','i','a','t','.',' ','N','u','n','c',' ','n','e','c',' ','a','n','t','e',' ','v','i','t','a','e',' ','l','e','c','t','u','s',' ','m','a','l','e','s','u','a','d','a',' ','v','e','h','i','c','u','l','a','.',' ','E','t','i','a','m',' ','a','u','c','t','o','r','.',' ','I','n','t','e','g','e','r',' ','s','e','m','p','e','r',' ','p','h','a','r','e','t','r','a',' ','m','a','s','s','a','.',' ','V','e','s','t','i','b','u','l','u','m',' ','a','n','t','e',' ','i','p','s','u','m',' ','p','r','i','m','i','s',' ','i','n',' ','f','a','u','c','i','b','u','s',' ','o','r','c','i',' ','l','u','c','t','u','s',' ','e','t',' ','u','l','t','r','i','c','e','s',' ','p','o','s','u','e','r','e',' ','c','u','b','i','l','i','a',' ','C','u','r','a','e',';',' ','V','e','s','t','i','b','u','l','u','m',' ','n','e','c',' ','l','e','c','t','u','s',' ','e','g','e','t',' ','l','a','c','u','s',' ','m','o','l','l','i','s',' ','v','e','s','t','i','b','u','l','u','m','.',' ','F','u','s','c','e',' ','a','u','g','u','e','.', 0 };
313 wchar_t par2[] = { 0x00b0, 0x00c0, 0x00d0, 0x00e0, 0x00f0, 0x0020,
314 0x00a8, 0x00b8, 0x00c8, 0x00d8, 0x00e8, 0x00f8, 0x0020,
315 0x0100, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170, 0x0020,
316 0x0108, 0x0118, 0x0128, 0x0138, 0x0148, 0x0158, 0x0168, 0x0178, 0x0020,
317 0x02bc, 0x0399, 0x03b1, 0x03c8, 0x0414, 0x0423, 0x043f, 0x044a, 0x0020,
318 0x2010, 0x2020, 0x2030, 0x2122, 0x2212, 0x2251, 0xfb01, 0xfb02, 0x0020,
319 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0020,
320 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0020,
321 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0020,
322 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0020,
323 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036,
324 ' ','C','u','r','a','b','i','t','u','r',' ','s','e','m','p','e','r',' ','v','e','l','i','t','.',' ','S','e','d',' ','u','t',' ','p','e','d','e',' ','s','e','d',' ','e','r','a','t',' ','c','o','n','s','e','c','t','e','t','u','e','r',' ','p','e','l','l','e','n','t','e','s','q','u','e','.',' ','C','u','r','a','b','i','t','u','r',' ','m','a','u','r','i','s','.',' ','D','o','n','e','c',' ','a',' ','j','u','s','t','o',' ','e','u',' ','l','o','r','e','m',' ','t','i','n','c','i','d','u','n','t',' ','n','o','n','u','m','m','y','.',' ','P','r','a','e','s','e','n','t',' ','c','o','n','s','e','q','u','a','t',' ','e','s','t',' ','n','o','n',' ','l','a','c','u','s','.',' ','C','u','r','a','b','i','t','u','r',' ','c','u','r','s','u','s','.',' ','M','o','r','b','i',' ','u','l','t','r','i','c','e','s',',',' ','v','e','l','i','t',' ','i','n',' ','l','u','c','t','u','s',' ','s','c','e','l','e','r','i','s','q','u','e',',',' ','n','u','l','l','a',' ','t','u','r','p','i','s',' ','v','i','v','e','r','r','a',' ','m','a','s','s','a',',',' ','a',' ','i','n','t','e','r','d','u','m',' ','p','e','d','e',' ','t','o','r','t','o','r',' ','v','e','l',' ','l','a','c','u','s','.',' ','Q','u','i','s','q','u','e',' ','p','o','r','t','a',' ','l','i','b','e','r','o',' ','e','t',' ','d','o','l','o','r','.',' ','M','a','u','r','i','s',' ','t','e','m','p','o','r','.',' ','S','e','d',' ','a','n','t','e','.',' ','S','e','d',' ','u','l','t','r','i','c','e','s',',',' ','p','e','d','e',' ','a','t',' ','s','o','d','a','l','e','s',' ','p','o','r','t','t','i','t','o','r',',',' ','i','p','s','u','m',' ','s','a','p','i','e','n',' ','f','e','r','m','e','n','t','u','m',' ','l','e','o',',',' ','e','u',' ','c','o','n','s','e','q','u','a','t',' ','a','r','c','u',' ','q','u','a','m',' ','e','u',' ','l','a','c','u','s','.',' ','P','h','a','s','e','l','l','u','s',' ','b','l','a','n','d','i','t','.',' ','M','o','r','b','i',' ','s','i','t',' ','a','m','e','t',' ','l','e','c','t','u','s',' ','a','c',' ','p','u','r','u','s',' ','v','e','n','e','n','a','t','i','s',' ','l','o','b','o','r','t','i','s','.',' ','F','u','s','c','e',' ','v','e','l',' ','e','r','o','s','.',' ','F','u','s','c','e',' ','a','d','i','p','i','s','c','i','n','g','.',' ','A','e','n','e','a','n',' ','s','i','t',' ','a','m','e','t',' ','l','e','c','t','u','s',' ','n','o','n',' ','e','s','t',' ','c','o','n','s','e','c','t','e','t','u','e','r',' ','f','e','u','g','i','a','t','.',' ','N','u','n','c',' ','n','e','c',' ','a','n','t','e',' ','v','i','t','a','e',' ','l','e','c','t','u','s',' ','m','a','l','e','s','u','a','d','a',' ','v','e','h','i','c','u','l','a','.',' ','E','t','i','a','m',' ','a','u','c','t','o','r','.',' ','I','n','t','e','g','e','r',' ','s','e','m','p','e','r',' ','p','h','a','r','e','t','r','a',' ','m','a','s','s','a','.',' ','V','e','s','t','i','b','u','l','u','m',' ','a','n','t','e',' ','i','p','s','u','m',' ','p','r','i','m','i','s',' ','i','n',' ','f','a','u','c','i','b','u','s',' ','o','r','c','i',' ','l','u','c','t','u','s',' ','e','t',' ','u','l','t','r','i','c','e','s',' ','p','o','s','u','e','r','e',' ','c','u','b','i','l','i','a',' ','C','u','r','a','e',';',' ','V','e','s','t','i','b','u','l','u','m',' ','n','e','c',' ','l','e','c','t','u','s',' ','e','g','e','t',' ','l','a','c','u','s',' ','m','o','l','l','i','s',' ','v','e','s','t','i','b','u','l','u','m','.',' ','F','u','s','c','e',' ','a','u','g','u','e','.',0 };
325 gui_window_id window, dialog;
326 gui_gadget_id magnitude, direction;
327 gui_menu_id menu;
328
329 test_doc = gui_ta(1400);
330
331 times = gui_ta_get_style(test_doc, 300, 300, 0x000000, 0xffffff, "Times");
332 helvetica = gui_ta_get_style(test_doc, 300, 300, 0xffffff, 0x0000ff, "Helvetica");
333
334 gui_ta_add_paragraph(test_doc, 60, 15, par1, times, ALIGN_LEFT);
335 /* gui_ta_add_space(test_doc, 100); */
336 gui_ta_add_paragraph(test_doc, 60, 15, par2, times, ALIGN_CENTRE);
337 gui_ta_add_paragraph(test_doc, 60, 15, par1, helvetica, ALIGN_RIGHT);
338 /* gui_ta_add_space(test_doc, 50); */
339 gui_ta_add_paragraph(test_doc, 60, 15, par2, helvetica, ALIGN_FULL);
340
341 menu = gui_menu(2, 4);
342 gui_menu_attach(menu, 0, gui_menu(8, 3));
343 gui_menu_attach(menu, 1, gui_menu(13, 5));
344 gui_menu_attach(menu, 2, gui_menu(20, 7));
345 gui_menu_attach(menu, 3, gui_menu(29, 1));
346
347 window = gui_create_window(gui_V_SCROLL_BAR, gui_message[0], test_doc->width + 2 * MARGIN,
348 test_doc->height + 2 * MARGIN, NULL, redraw, click, resize, key, input,
349 menuf, menu, NULL, "hi");
350
351 /* gui_start_dialog("guitest dialog");
352 gui_create_label("Resolve vector");
353 magnitude = gui_create_text_box("Magnitude", "0-9.");
354 direction = gui_create_text_box("Direction", "0-9.");
355 gui_create_button("Resolve!", NULL);
356 gui_create_button("Close", NULL);
357 dialog = gui_create_dialog();*/
358 }
359
360
361 void task_finalise(void)
362 {
363 gui_ta_remove(test_doc);
364 }

  ViewVC Help
Powered by ViewVC 1.1.26