33 |
33 |
34 #include "toolbar.h" |
34 #include "toolbar.h" |
35 #include "button.h" |
35 #include "button.h" |
36 #include "stock.h" |
36 #include "stock.h" |
37 #include "list.h" |
37 #include "list.h" |
38 #include <ucx/mempool.h> |
38 |
|
39 #include <cx/hash_map.h> |
|
40 #include <cx/linked_list.h> |
|
41 #include <cx/array_list.h> |
|
42 |
39 #include "../common/context.h" |
43 #include "../common/context.h" |
40 |
44 |
41 static UcxMap *toolbar_items; |
45 static CxMap *toolbar_items; |
42 static UcxList *defaults; |
46 static CxList *defaults; |
43 |
47 |
44 void ui_toolbar_init() { |
48 void ui_toolbar_init() { |
45 toolbar_items = ucx_map_new(16); |
49 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
|
50 defaults = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
46 } |
51 } |
47 |
52 |
48 void ui_toolitem(char *name, char *label, ui_callback f, void *userdata) { |
53 void ui_toolitem(char *name, char *label, ui_callback f, void *userdata) { |
49 UiToolItem *item = malloc(sizeof(UiToolItem)); |
54 UiToolItem *item = malloc(sizeof(UiToolItem)); |
50 item->item.add_to = (ui_toolbar_add_f)add_toolitem_widget; |
55 item->item.add_to = (ui_toolbar_add_f)add_toolitem_widget; |
53 item->callback = f; |
58 item->callback = f; |
54 item->userdata = userdata; |
59 item->userdata = userdata; |
55 item->groups = NULL; |
60 item->groups = NULL; |
56 item->isimportant = FALSE; |
61 item->isimportant = FALSE; |
57 |
62 |
58 ucx_map_cstr_put(toolbar_items, name, item); |
63 cxMapPut(toolbar_items, name, item); |
59 } |
64 } |
60 |
65 |
61 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) { |
66 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *userdata) { |
62 ui_toolitem_stgr(name, stockid, f, userdata, -1); |
67 ui_toolitem_stgr(name, stockid, f, userdata, -1); |
63 } |
68 } |
74 // add groups |
79 // add groups |
75 va_list ap; |
80 va_list ap; |
76 va_start(ap, userdata); |
81 va_start(ap, userdata); |
77 int group; |
82 int group; |
78 while((group = va_arg(ap, int)) != -1) { |
83 while((group = va_arg(ap, int)) != -1) { |
79 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
84 if(!item->groups) { |
|
85 item->groups = cxArrayListCreateSimple(sizeof(int), 16); |
|
86 } |
|
87 cxListAdd(item->groups, &group); |
80 } |
88 } |
81 va_end(ap); |
89 va_end(ap); |
82 |
90 |
83 ucx_map_cstr_put(toolbar_items, name, item); |
91 cxMapPut(toolbar_items, name, item); |
84 } |
92 } |
85 |
93 |
86 void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata) { |
94 void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata) { |
87 // TODO |
95 // TODO |
88 |
96 |
93 item->callback = f; |
101 item->callback = f; |
94 item->userdata = udata; |
102 item->userdata = udata; |
95 item->groups = NULL; |
103 item->groups = NULL; |
96 item->isimportant = FALSE; |
104 item->isimportant = FALSE; |
97 |
105 |
98 ucx_map_cstr_put(toolbar_items, name, item); |
106 cxMapPut(toolbar_items, name, item); |
99 } |
107 } |
100 |
108 |
101 |
109 |
102 void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) { |
110 void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...) { |
103 // TODO |
111 // TODO |
113 // add groups |
121 // add groups |
114 va_list ap; |
122 va_list ap; |
115 va_start(ap, udata); |
123 va_start(ap, udata); |
116 int group; |
124 int group; |
117 while((group = va_arg(ap, int)) != -1) { |
125 while((group = va_arg(ap, int)) != -1) { |
118 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
126 if(!item->groups) { |
|
127 item->groups = cxArrayListCreateSimple(sizeof(int), 16); |
|
128 } |
|
129 cxListAdd(item->groups, &group); |
119 } |
130 } |
120 va_end(ap); |
131 va_end(ap); |
121 |
132 |
122 ucx_map_cstr_put(toolbar_items, name, item); |
133 cxMapPut(toolbar_items, name, item); |
123 } |
134 } |
124 |
135 |
125 void ui_toolitem_toggle_imggr(char *name, char *label, char *img, ui_callback f, void *udata, ...) { |
136 void ui_toolitem_toggle_imggr(char *name, char *label, char *img, ui_callback f, void *udata, ...) { |
126 // TODO |
137 // TODO |
127 |
138 |
137 // add groups |
148 // add groups |
138 va_list ap; |
149 va_list ap; |
139 va_start(ap, udata); |
150 va_start(ap, udata); |
140 int group; |
151 int group; |
141 while((group = va_arg(ap, int)) != -1) { |
152 while((group = va_arg(ap, int)) != -1) { |
142 item->groups = ucx_list_append(item->groups, (void*)(intptr_t)group); |
153 if(!item->groups) { |
|
154 item->groups = cxArrayListCreateSimple(sizeof(int), 16); |
|
155 } |
|
156 cxListAdd(item->groups, &group); |
143 } |
157 } |
144 va_end(ap); |
158 va_end(ap); |
145 |
159 |
146 ucx_map_cstr_put(toolbar_items, name, item); |
160 cxMapPut(toolbar_items, name, item); |
147 } |
161 } |
148 |
162 |
149 void ui_toolbar_combobox( |
163 void ui_toolbar_combobox( |
150 char *name, |
164 char *name, |
151 UiList *list, |
165 UiList *list, |
184 cb->listname = listname; |
198 cb->listname = listname; |
185 cb->getvalue = getvalue; |
199 cb->getvalue = getvalue; |
186 cb->callback = f; |
200 cb->callback = f; |
187 cb->userdata = udata; |
201 cb->userdata = udata; |
188 |
202 |
189 ucx_map_cstr_put(toolbar_items, name, cb); |
203 cxMapPut(toolbar_items, name, cb); |
190 } |
204 } |
191 |
205 |
192 |
206 |
193 void ui_toolbar_add_default(char *name) { |
207 void ui_toolbar_add_default(char *name) { |
194 char *s = strdup(name); |
208 char *s = strdup(name); |
195 defaults = ucx_list_append(defaults, s); |
209 cxListAdd(defaults, s); |
196 } |
210 } |
197 |
211 |
198 Widget ui_create_toolbar(UiObject *obj, Widget parent) { |
212 Widget ui_create_toolbar(UiObject *obj, Widget parent) { |
199 if(!defaults) { |
213 if(!defaults) { |
200 return NULL; |
214 return NULL; |
211 XtSetArg(args[0], XmNorientation, XmHORIZONTAL); |
225 XtSetArg(args[0], XmNorientation, XmHORIZONTAL); |
212 XtSetArg(args[1], XmNpacking, XmPACK_TIGHT); |
226 XtSetArg(args[1], XmNpacking, XmPACK_TIGHT); |
213 XtSetArg(args[2], XmNspacing, 1); |
227 XtSetArg(args[2], XmNspacing, 1); |
214 Widget toolbar = XmCreateRowColumn (frame, "toolbar", args, 3); |
228 Widget toolbar = XmCreateRowColumn (frame, "toolbar", args, 3); |
215 |
229 |
216 UCX_FOREACH(elm, defaults) { |
230 CxIterator i = cxListIterator(defaults); |
217 UiToolItemI *item = ucx_map_cstr_get(toolbar_items, elm->data); |
231 cx_foreach(char *, def, i) { |
|
232 UiToolItemI *item = cxMapGet(toolbar_items, def); |
218 if(item) { |
233 if(item) { |
219 item->add_to(toolbar, item, obj); |
234 item->add_to(toolbar, item, obj); |
220 } else if(!strcmp(elm->data, "@separator")) { |
235 } else if(!strcmp(def, "@separator")) { |
221 // TODO |
236 // TODO |
222 } else { |
237 } else { |
223 fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data); |
238 fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", def); |
224 } |
239 } |
225 } |
240 } |
226 |
241 |
227 XtManageChild(toolbar); |
242 XtManageChild(toolbar); |
228 XtManageChild(frame); |
243 XtManageChild(frame); |
240 Widget button = XmCreatePushButton(parent, "toolbar_button", args, 3); |
255 Widget button = XmCreatePushButton(parent, "toolbar_button", args, 3); |
241 |
256 |
242 XmStringFree(label); |
257 XmStringFree(label); |
243 |
258 |
244 if(item->callback) { |
259 if(item->callback) { |
245 UiEventData *event = ucx_mempool_malloc( |
260 UiEventData *event = cxMalloc( |
246 obj->ctx->mempool, |
261 obj->ctx->allocator, |
247 sizeof(UiEventData)); |
262 sizeof(UiEventData)); |
248 event->obj = obj; |
263 event->obj = obj; |
249 event->userdata = item->userdata; |
264 event->userdata = item->userdata; |
250 event->callback = item->callback; |
265 event->callback = item->callback; |
251 XtAddCallback( |
266 XtAddCallback( |
274 Widget button = XmCreatePushButton(parent, "toolbar_button", args, 3); |
289 Widget button = XmCreatePushButton(parent, "toolbar_button", args, 3); |
275 |
290 |
276 XmStringFree(label); |
291 XmStringFree(label); |
277 |
292 |
278 if(item->callback) { |
293 if(item->callback) { |
279 UiEventData *event = ucx_mempool_malloc( |
294 UiEventData *event = cxMalloc( |
280 obj->ctx->mempool, |
295 obj->ctx->allocator, |
281 sizeof(UiEventData)); |
296 sizeof(UiEventData)); |
282 event->obj = obj; |
297 event->obj = obj; |
283 event->userdata = item->userdata; |
298 event->userdata = item->userdata; |
284 event->callback = item->callback; |
299 event->callback = item->callback; |
285 XtAddCallback( |
300 XtAddCallback( |
307 Widget button = XmCreateToggleButton(parent, "toolbar_toggle_button", args, 4); |
322 Widget button = XmCreateToggleButton(parent, "toolbar_toggle_button", args, 4); |
308 |
323 |
309 XmStringFree(label); |
324 XmStringFree(label); |
310 |
325 |
311 if(item->callback) { |
326 if(item->callback) { |
312 UiEventData *event = ucx_mempool_malloc( |
327 UiEventData *event = cxMalloc( |
313 obj->ctx->mempool, |
328 obj->ctx->allocator, |
314 sizeof(UiEventData)); |
329 sizeof(UiEventData)); |
315 event->obj = obj; |
330 event->obj = obj; |
316 event->userdata = item->userdata; |
331 event->userdata = item->userdata; |
317 event->callback = item->callback; |
332 event->callback = item->callback; |
318 XtAddCallback( |
333 XtAddCallback( |
332 void add_toolitem_st_toggle_widget(Widget parent, UiStToolItem *item, UiObject *obj) { |
347 void add_toolitem_st_toggle_widget(Widget parent, UiStToolItem *item, UiObject *obj) { |
333 |
348 |
334 } |
349 } |
335 |
350 |
336 void add_toolbar_combobox(Widget tb, UiToolbarComboBox *item, UiObject *obj) { |
351 void add_toolbar_combobox(Widget tb, UiToolbarComboBox *item, UiObject *obj) { |
337 UiListView *listview = ucx_mempool_malloc( |
352 UiListView *listview = cxMalloc( |
338 obj->ctx->mempool, |
353 obj->ctx->allocator, |
339 sizeof(UiListView)); |
354 sizeof(UiListView)); |
340 |
355 |
341 UiVar *var = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiVar)); |
356 UiVar *var = cxMalloc(obj->ctx->allocator, sizeof(UiVar)); |
342 var->value = item->list; |
357 var->value = item->list; |
343 var->type = UI_VAR_SPECIAL; |
358 var->type = UI_VAR_SPECIAL; |
344 |
359 |
345 Arg args[8]; |
360 Arg args[8]; |
346 XtSetArg(args[0], XmNshadowThickness, 1); |
361 XtSetArg(args[0], XmNshadowThickness, 1); |