ui/win32/menu.c

changeset 1219
86ed681698aa
parent 1060
74bed80a0503
equal deleted inserted replaced
1218:943fc009bd1c 1219:86ed681698aa
287 ls->object = obj; 287 ls->object = obj;
288 ls->menu = parent; 288 ls->menu = parent;
289 ls->command_ids = cxArrayListCreate(a, sizeof(uint64_t), 16); 289 ls->command_ids = cxArrayListCreate(a, sizeof(uint64_t), 16);
290 ls->index = pos; 290 ls->index = pos;
291 ls->getvalue = il->getvalue; 291 ls->getvalue = il->getvalue;
292 ls->getvaluedata = NULL; // TODO
292 ls->callback = il->callback; 293 ls->callback = il->callback;
293 ls->userdata = il->userdata; 294 ls->userdata = il->userdata;
294 ls->addseparator = il->addseparator; 295 ls->addseparator = il->addseparator;
295 ls->var = var; 296 ls->var = var;
296 297
337 cx_foreach(uint64_t *, id, i) { 338 cx_foreach(uint64_t *, id, i) {
338 DeleteMenu(list->menu, *id, MF_BYCOMMAND); 339 DeleteMenu(list->menu, *id, MF_BYCOMMAND);
339 } 340 }
340 cxListClear(list->command_ids); // TODO: we could reuse some of the ids 341 cxListClear(list->command_ids); // TODO: we could reuse some of the ids
341 342
342 ui_getvaluefunc getvalue = list->getvalue; 343 ui_getvaluefunc2 getvalue = list->getvalue;
344 void *getvaluedata = list->getvaluedata;
343 void* elm = ui_list_first(ls); 345 void* elm = ui_list_first(ls);
344 346
345 int pos = list->index; 347 int pos = list->index;
348 int row = 0;
346 while(elm) { 349 while(elm) {
347 char *label = (char*) (getvalue ? getvalue(elm, 0) : elm); 350 UiBool freeResult = FALSE;
351 char *label = (char*) (getvalue ? getvalue(ls, elm, row, 0, getvaluedata, &freeResult) : elm);
348 if (!label) { 352 if (!label) {
349 label = ""; 353 label = "";
350 } 354 }
351 355
352 uint64_t id = ++obj->ctx->command_id_counter; 356 uint64_t id = ++obj->ctx->command_id_counter;
353 InsertMenu(list->menu, pos++, MF_STRING, id, label); 357 InsertMenu(list->menu, pos++, MF_STRING, id, label);
354 cxListAdd(list->command_ids, &id); 358 cxListAdd(list->command_ids, &id);
355 359
360 if (freeResult) {
361 free(label);
362 }
363
356 elm = ui_list_next(ls); 364 elm = ui_list_next(ls);
365 row++;
357 } 366 }
358 } 367 }
359 368
360 369
361 void ui_add_menu_checklist(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) { 370 void ui_add_menu_checklist(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) {

mercurial