ui/motif/menu.c

branch
newapi
changeset 420
28a5920bebe0
parent 419
7d15cad351fc
equal deleted inserted replaced
419:7d15cad351fc 420:28a5920bebe0
35 #include "toolkit.h" 35 #include "toolkit.h"
36 #include "stock.h" 36 #include "stock.h"
37 #include "container.h" 37 #include "container.h"
38 #include "../common/context.h" 38 #include "../common/context.h"
39 #include "../common/menu.h" 39 #include "../common/menu.h"
40 #include "../common/types.h"
40 #include "../ui/window.h" 41 #include "../ui/window.h"
41 42
42 #include <cx/linked_list.h> 43 #include <cx/linked_list.h>
43 #include <cx/array_list.h> 44 #include <cx/array_list.h>
44 45
199 XtManageChild(button); 200 XtManageChild(button);
200 201
201 ui_bind_radiobutton(obj, button, NULL, it->varname, it->callback, it->userdata, 0); 202 ui_bind_radiobutton(obj, button, NULL, it->varname, it->callback, it->userdata, 0);
202 } 203 }
203 204
204 void add_checkitemnv_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) {
205
206 }
207
208 void add_menuitem_list_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { 205 void add_menuitem_list_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) {
209 206 UiMenuItemList *il = (UiMenuItemList*)item;
210 } 207 const CxAllocator *a = obj->ctx->allocator;
208
209 UiActiveMenuItemList *ls = cxMalloc(
210 a,
211 sizeof(UiActiveMenuItemList));
212 ls->object = obj;
213 ls->menu = p;
214 ls->index = i;
215 ls->oldcount = 0;
216 ls->getvalue = il->getvalue;
217 ls->callback = il->callback;
218 ls->userdata = il->userdata;
219 ls->addseparator = TRUE;
220
221 ls->var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST); //uic_widget_var(obj->ctx, obj->ctx, NULL, il->varname, UI_VAR_LIST);
222 UiList *list = ls->var->value;
223
224 UiObserver *observer = ui_observer_new((ui_callback)ui_update_menuitem_list, ls);
225 list->observers = ui_obsvlist_add(list->observers, observer);
226 uic_list_register_observer_destructor(obj->ctx, list, observer);
227
228 ui_update_menuitem_list(NULL, ls);
229 }
230
231 void ui_update_menuitem_list(UiEvent *event, UiActiveMenuItemList *list) {
232 XmString s = NULL;
233 Arg args[4];
234 int n;
235
236 UiList *ls;
237 if(list->var && list->var->value) {
238 ls = list->var->value;
239 } else {
240 return;
241 }
242
243 if(list->oldcount > 0) {
244 Widget *children;
245 int nc;
246
247 XtVaGetValues(
248 list->menu,
249 XmNchildren,
250 &children,
251 XmNnumChildren,
252 &nc,
253 NULL);
254
255 for(int i=0;i<list->oldcount;i++) {
256 XtDestroyWidget(children[list->index + i]);
257 }
258 }
259
260 void* elm = ui_list_first(ls);
261 int i = 0;
262 if(elm && list->addseparator) {
263 Widget s = XmCreateSeparatorGadget(list->menu, "menuseparator", NULL, 0);
264 XtManageChild(s);
265 i++;
266 }
267
268 ui_getvaluefunc getvalue = list->getvalue;
269 while(elm) {
270 n = 0;
271 char *label = (char*) (getvalue ? getvalue(elm, 0) : elm);
272 if(label) {
273 s = XmStringCreateLocalized(label);
274 XtSetArg(args[n], XmNlabelString, s); n++;
275 }
276
277 Widget mitem = XtCreateManagedWidget(
278 "menubutton",
279 xmPushButtonWidgetClass,
280 list->menu,
281 args,
282 n);
283 if(s) {
284 XmStringFree(s);
285 }
286
287 if(list->callback) {
288 UiEventData *eventdata = malloc(sizeof(UiEventData));
289 eventdata->callback = list->callback;
290 eventdata->userdata = list->userdata;
291 eventdata->obj = list->object;
292 eventdata->value = 0;
293 XtAddCallback(
294 mitem,
295 XmNactivateCallback,
296 (XtCallbackProc)ui_push_button_callback,
297 eventdata);
298 XtAddCallback(
299 mitem,
300 XmNdestroyCallback,
301 (XtCallbackProc)ui_destroy_eventdata,
302 eventdata);
303 }
304
305 elm = ui_list_next(ls);
306 i++;
307 }
308
309 list->oldcount = i;
310 }

mercurial