Mercurial > repos > rhope
annotate window.c @ 75:0083b2f7b3c7
Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 06 Jul 2010 07:52:59 -0400 |
parents | 94c885692eb5 |
children |
rev | line source |
---|---|
0 | 1 #include <stdlib.h> |
2 #include <string.h> | |
3 #include "structs.h" | |
4 #include "datum.h" | |
5 #include "interp.h" | |
6 #include "vis_threading.h" | |
7 #include "debugmacros.h" | |
8 | |
9 #ifdef SYLLABLE | |
10 #include "syl_window.h" | |
11 VIS_CRITICAL_SECTION(app_lock); | |
12 #else | |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
13 #ifdef GTK |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
14 #include "gtk_window.h" |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
15 VIS_CRITICAL_SECTION(gtk_init_lock); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
16 #else |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
17 #ifdef WIN32 |
0 | 18 #include "ms_window.h" |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
19 VIS_CRITICAL_SECTION(hwnd_lock); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
20 #endif |
0 | 21 #endif |
22 #endif | |
23 | |
24 /* | |
25 typedef struct | |
26 { | |
27 os::Window * wind; | |
28 int refcount; | |
29 VIS_CRITICAL_SECTION(lock) | |
30 } os_window; | |
31 | |
32 typedef struct | |
33 { | |
34 os_window * os_wind; | |
35 datum * title; | |
36 double width; | |
37 double height; | |
38 double xpos; | |
39 double ypos; | |
40 } vis_window_shown;*/ | |
41 | |
42 void vis_window_init() | |
43 { | |
44 #ifdef SYLLABLE | |
45 DEBUGPUTS("Initializing app_lock"); | |
46 | |
47 VIS_InitializeCriticalSection(app_lock); | |
48 #else | |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
49 #ifdef GTK |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
50 VIS_InitializeCriticalSection(gtk_init_lock); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
51 #else |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
52 #ifdef WIN32 |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
53 VIS_InitializeCriticalSection(hwnd_lock); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
54 #endif |
0 | 55 #endif |
56 #endif | |
57 } | |
58 | |
59 int vis_window_new(datum ** inputlist, queue_entry * worker_entry) | |
60 { | |
61 vis_window * window; | |
62 datum * window_datum = new_datum(BUILTIN_TYPE_WINDOW, 1, sizeof(vis_window), worker_entry->instance->def->program); | |
63 window = (vis_window *)(window_datum->c.generic.data); | |
64 window->title = inputlist[0]; | |
65 DEBUGPRINTF("Type: %d\n", window->title->company->type_id); | |
66 DEBUGPRINTF("Length: %d\n", window->title->c.generic.len); | |
67 window->width = inputlist[1]->c.real; | |
68 window->height = inputlist[2]->c.real; | |
69 | |
70 window->widget_dict = create_dict(worker_entry->instance->def->program); | |
71 window->widget_xpos = create_dict(worker_entry->instance->def->program); | |
72 window->widget_ypos = create_dict(worker_entry->instance->def->program); | |
73 window->id_list = create_list(worker_entry->instance->def->program); | |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
74 window->menu = NULL; |
0 | 75 release_ref(inputlist[1]); |
76 release_ref(inputlist[2]); | |
77 inputlist[0] = window_datum; | |
78 return 0; | |
79 } | |
80 | |
81 int vis_window_add_widget(datum ** inputlist, queue_entry * worker_entry) | |
82 { | |
83 datum * params[3]; | |
84 vis_window * window; | |
85 inputlist[0] = copy_datum(inputlist[0], 0); | |
86 window = (vis_window *)(inputlist[0]->c.generic.data); | |
87 DEBUGPRINTF("xpos nodes: %d\n", ((dict_data *)window->widget_xpos->c.generic.data)->num_nodes); | |
88 params[0] = window->widget_dict; | |
89 params[1] = add_ref(inputlist[1]); | |
90 params[2] = inputlist[2]; | |
91 DEBUGPUTS("Adding widget to widget_dict\n"); | |
92 DEBUGPRINTF("xpos nodes: %d\n", ((dict_data *)window->widget_xpos->c.generic.data)->num_nodes); | |
93 DEBUGPRINTF("widget_dict->datas: %X, xpos->datas: %X\n", window->widget_dict->c.generic.data, window->widget_xpos->c.generic.data); | |
94 DEBUGPRINTF("sizeof(dict_data): %d, sizeof(ternary_node), %d\n", sizeof(dict_data), sizeof(ternary_node)); | |
95 vis_dict_set(params, NULL); | |
96 DEBUGPRINTF("xpos nodes: %d\n", ((dict_data *)window->widget_xpos->c.generic.data)->num_nodes); | |
97 window->widget_dict = params[0]; | |
98 params[0] = window->widget_xpos; | |
99 params[1] = add_ref(inputlist[1]); | |
100 params[2] = inputlist[3]; | |
101 DEBUGPUTS("Adding xpos to xpos_dict\n"); | |
102 vis_dict_set(params, NULL); | |
103 window->widget_xpos = params[0]; | |
104 params[0] = window->widget_ypos; | |
105 params[1] = add_ref(inputlist[1]); | |
106 params[2] = inputlist[4]; | |
107 DEBUGPUTS("Adding ypos to ypos_dict\n"); | |
108 vis_dict_set(params, NULL); | |
109 window->widget_ypos = params[0]; | |
110 params[0] = window->id_list; | |
111 params[1] = inputlist[1]; | |
112 DEBUGPUTS("Adding id to id list\n"); | |
113 DEBUGPRINTF("xpos nodes: %d\n", ((dict_data *)window->widget_xpos->c.generic.data)->num_nodes); | |
114 vis_list_append(params, NULL); | |
115 window->id_list = params[0]; | |
116 return 0; | |
117 } | |
118 | |
119 int vis_window_wait_close(datum ** inputlist, queue_entry * worker_entry) | |
120 { | |
121 vis_window_shown * window = (vis_window_shown *)(inputlist[0]->c.generic.data); | |
122 VIS_EnterCriticalSection(window->lock); | |
123 if(window->is_open && !window->wait_entry) | |
124 { | |
125 window->wait_entry = (queue_entry *)malloc(sizeof(queue_entry)); | |
126 memcpy(window->wait_entry, worker_entry, sizeof(queue_entry)); | |
127 VIS_LeaveCriticalSection(window->lock); | |
128 release_ref(inputlist[0]); | |
129 return 1; | |
130 } | |
131 else | |
132 { | |
133 VIS_LeaveCriticalSection(window->lock); | |
134 release_ref(inputlist[0]); | |
135 inputlist[0] = new_datum(BUILTIN_TYPE_YESNO, 2, 0, worker_entry->instance->def->program); | |
136 datum_set_yesno(inputlist[0], DATUM_NO); | |
137 return 0; | |
138 } | |
139 } | |
140 | |
141 | |
142 | |
143 void vis_window_closed(datum * window_datum) | |
144 { | |
145 datum * params[1]; | |
146 queue_entry * temp; | |
147 vis_window_shown * window = (vis_window_shown *)(window_datum->c.generic.data); | |
148 | |
149 VIS_EnterCriticalSection(window->lock); | |
150 window->is_open = FALSE; | |
151 //window->wind = NULL; | |
152 temp = window->wait_entry; | |
153 window->wait_entry = NULL; | |
154 VIS_LeaveCriticalSection(window->lock); | |
155 release_ref(window_datum); | |
156 if(temp) | |
157 { | |
158 //TODO send YESNO output | |
159 params[0] = new_datum(BUILTIN_TYPE_YESNO, 2, 0, temp->instance->def->program); | |
160 datum_set_yesno(params[0], DATUM_YES); | |
161 process_outputs(params, temp->worker_num, temp->instance); | |
162 //worker_complete(*temp); | |
163 cleanup_check(*temp); | |
164 free(temp); | |
165 } | |
166 | |
167 } | |
168 | |
169 void widget_new(datum ** inputlist, int type, program * prog) | |
170 { | |
171 vis_widget * widget; | |
172 datum * output = new_datum(type, 1, sizeof(vis_widget), prog); | |
173 widget = (vis_widget *)(output->c.generic.data); | |
174 widget->label = inputlist[0]; | |
175 widget->width = inputlist[1]->c.real; | |
176 release_ref(inputlist[1]); | |
177 widget->height = inputlist[2]->c.real; | |
178 release_ref(inputlist[2]); | |
179 widget->handler_dict = create_dict(prog); | |
180 widget->value = NULL; | |
181 DEBUGPRINTF("widget_new: type = %d, handler_dict = %X\n", type, widget->handler_dict); | |
182 inputlist[0] = output; | |
183 } | |
184 | |
185 int vis_button_new(datum ** inputlist, queue_entry * worker_entry) | |
186 { | |
187 widget_new(inputlist, BUILTIN_TYPE_BUTTON, worker_entry->instance->def->program); | |
188 return 0; | |
189 } | |
190 | |
191 int vis_button_set_handler(datum ** inputlist, queue_entry * workere_entry) | |
192 { | |
193 vis_widget * widget; | |
194 datum * params[3]; | |
195 inputlist[0] = copy_datum(inputlist[0], 0); | |
196 widget = (vis_widget *)(inputlist[0]->c.generic.data); | |
197 params[0] = widget->handler_dict; | |
198 params[1] = inputlist[1]; | |
199 params[2] = inputlist[2]; | |
200 //DEBUGPUTS("\n\nvis_button_set_handler vis_dict_set\n"); | |
201 vis_dict_set(params, NULL); | |
202 DEBUGPUTS("after vis_dict_set\n\n\n"); | |
203 widget->handler_dict = params[0]; | |
204 return 0; | |
205 } | |
206 | |
207 int vis_inputbox_new(datum ** inputlist, queue_entry * worker_entry) | |
208 { | |
209 vis_widget * widget; | |
210 datum * output = new_datum(BUILTIN_TYPE_INPUTBOX, 1, sizeof(vis_widget), worker_entry->instance->def->program); | |
211 widget = (vis_widget *)(output->c.generic.data); | |
212 widget->value = inputlist[0]; | |
213 widget->width = inputlist[1]->c.real; | |
214 release_ref(inputlist[1]); | |
215 widget->height = inputlist[2]->c.real; | |
216 release_ref(inputlist[2]); | |
217 widget->label = NULL; | |
218 widget->handler_dict = NULL; | |
219 widget->flags = 0; | |
220 inputlist[0] = output; | |
221 return 0; | |
222 } | |
223 | |
224 int vis_inputbox_settype(datum ** inputlist, queue_entry * worker_entry) | |
225 { | |
226 vis_widget * widget; | |
227 inputlist[0] = copy_datum(inputlist[0], 0); | |
228 widget = (vis_widget *)(inputlist[0]->c.generic.data); | |
229 if(!strcmp((char *)(inputlist[1]->c.generic.data), "multiline")) | |
230 widget->flags = 1; | |
231 else if(!strcmp((char *)(inputlist[1]->c.generic.data), "numeric")) | |
232 widget->flags = 2; | |
233 else if(!strcmp((char *)(inputlist[1]->c.generic.data), "password")) | |
234 widget->flags = 3; | |
235 else if(!strcmp((char *)(inputlist[1]->c.generic.data), "read only")) | |
236 widget->flags = 4; | |
237 else | |
238 widget->flags = 0; | |
239 return 0; | |
240 } | |
241 | |
242 int vis_customwidget_new(datum ** inputlist, queue_entry * worker_entry) | |
243 { | |
244 widget_new(inputlist, BUILTIN_TYPE_CUSTOM_WIDGET, worker_entry->instance->def->program); | |
245 return 0; | |
246 } | |
247 | |
248 | |
249 int vis_checkbox_new(datum ** params, queue_entry * entry) | |
250 { | |
251 vis_widget * widget; | |
252 widget_new(params, BUILTIN_TYPE_CHECKBOX, entry->instance->def->program); | |
253 widget = params[0]->c.generic.data; | |
254 widget->value = params[3]; | |
255 return 0; | |
256 } | |
257 | |
258 int vis_dropdown_new(datum ** params, queue_entry * entry) | |
259 { | |
260 vis_widget * widget; | |
261 widget_new(params, BUILTIN_TYPE_DROPDOWN, entry->instance->def->program); | |
262 widget = params[0]->c.generic.data; | |
263 widget->selected_index = -1; | |
264 return 0; | |
265 } | |
266 | |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
267 //Also used for Set Data@Datagrid |
0 | 268 int vis_dropdown_settext(datum ** params, queue_entry * entry) |
269 { | |
270 vis_widget * widget; | |
271 params[0] = copy_datum(params[0], 0); | |
272 widget = params[0]->c.generic.data; | |
273 widget->selected_index = -1; | |
274 release_ref(widget->value); | |
275 widget->value = params[1]; | |
276 return 0; | |
277 } | |
278 | |
279 int vis_dropdown_select(datum ** params, queue_entry * entry) | |
280 { | |
281 vis_widget * widget; | |
282 params[0] = copy_datum(params[0], 0); | |
283 widget = params[0]->c.generic.data; | |
284 release_ref(widget->value); | |
285 widget->value = NULL; | |
286 widget->selected_index = params[1]->c.integers.num_a; | |
287 release_ref(params[1]); | |
288 return 0; | |
289 } | |
290 | |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
291 int vis_datagrid_new(datum ** inputlist, queue_entry * worker_entry) |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
292 { |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
293 widget_new(inputlist, BUILTIN_TYPE_DATAGRID, worker_entry->instance->def->program); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
294 return 0; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
295 } |
0 | 296 |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
297 int vis_menu_new(datum ** inputlist, queue_entry * worker_entry) |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
298 { |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
299 vis_menu * menu; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
300 inputlist[0] = new_datum(BUILTIN_TYPE_MENU, 1, sizeof(vis_menu), worker_entry->instance->def->program); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
301 menu = inputlist[0]->c.generic.data; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
302 menu->label_list = create_list(worker_entry->instance->def->program); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
303 menu->action_list = create_list(worker_entry->instance->def->program); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
304 return 0; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
305 } |
0 | 306 |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
307 int vis_menu_add_item(datum ** inputlist, queue_entry * worker_entry) |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
308 { |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
309 datum * wparams[2]; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
310 vis_menu * menu; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
311 inputlist[0] = copy_datum(inputlist[0], 0); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
312 menu = inputlist[0]->c.generic.data; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
313 wparams[0] = menu->label_list; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
314 wparams[1] = inputlist[1]; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
315 vis_list_append(wparams, worker_entry); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
316 menu->label_list = wparams[0]; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
317 wparams[0] = menu->action_list; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
318 wparams[1] = inputlist[2]; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
319 vis_list_append(wparams, worker_entry); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
320 menu->action_list = wparams[0]; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
321 return 0; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
322 } |
0 | 323 |
3
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
324 int vis_window_set_menu(datum ** inputlist, queue_entry * worker_entry) |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
325 { |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
326 vis_window * window; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
327 inputlist[0] = copy_datum(inputlist[0], 0); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
328 window = inputlist[0]->c.generic.data; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
329 release_ref(window->menu); |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
330 window->menu = inputlist[1]; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
331 return 0; |
94c885692eb5
Partial set of fixes and enhancements from Linux box
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
332 } |
0 | 333 |
334 |