ui/gtk/menu.c

changeset 35
834d9c15a69f
parent 32
e5f4d8af567e
child 42
9af327d0e0e4
equal deleted inserted replaced
34:98e041f2f9a2 35:834d9c15a69f
241 241
242 ls->object = obj; 242 ls->object = obj;
243 ls->menu = GTK_MENU_SHELL(p); 243 ls->menu = GTK_MENU_SHELL(p);
244 ls->index = index; 244 ls->index = index;
245 ls->oldcount = 0; 245 ls->oldcount = 0;
246 ls->getvalue = il->getvalue;
246 247
247 UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST); 248 UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST);
248 ls->list = var->value; 249 ls->list = var->value;
249 250
250 ls->callback = il->callback; 251 ls->callback = il->callback;
272 mi = mi->next; 273 mi = mi->next;
273 i++; 274 i++;
274 } 275 }
275 } 276 }
276 277
277 char *str = ui_list_first(list->list); 278 void* elm = ui_list_first(list->list);
278 if(str) { 279 if(elm) {
279 GtkWidget *widget = gtk_separator_menu_item_new(); 280 GtkWidget *widget = gtk_separator_menu_item_new();
280 gtk_menu_shell_insert(list->menu, widget, list->index); 281 gtk_menu_shell_insert(list->menu, widget, list->index);
281 gtk_widget_show(widget); 282 gtk_widget_show(widget);
282 } 283 }
284
285 ui_getvaluefunc getvalue = list->getvalue;
283 int i = 1; 286 int i = 1;
284 while(str) { 287 while(elm) {
285 GtkWidget *widget = gtk_menu_item_new_with_label(str); 288 char *label = (char*) (getvalue ? getvalue(elm, 0) : elm);
289
290 GtkWidget *widget = gtk_menu_item_new_with_label(label);
286 gtk_menu_shell_insert(list->menu, widget, list->index + i); 291 gtk_menu_shell_insert(list->menu, widget, list->index + i);
287 gtk_widget_show(widget); 292 gtk_widget_show(widget);
288 293
289 if(list->callback) { 294 if(list->callback) {
290 // TODO: use mempool
291 UiEventData *event = malloc(sizeof(UiEventData)); 295 UiEventData *event = malloc(sizeof(UiEventData));
292 event->obj = list->object; 296 event->obj = list->object;
293 event->userdata = list->userdata; 297 event->userdata = list->userdata;
294 event->callback = list->callback; 298 event->callback = list->callback;
295 event->value = i - 1; 299 event->value = i - 1;
296 event->customdata = NULL; 300 event->customdata = elm;
297 301
298 g_signal_connect( 302 g_signal_connect(
299 widget, 303 widget,
300 "activate", 304 "activate",
301 G_CALLBACK(ui_menu_event_wrapper), 305 G_CALLBACK(ui_menu_event_wrapper),
305 "destroy", 309 "destroy",
306 G_CALLBACK(ui_destroy_userdata), 310 G_CALLBACK(ui_destroy_userdata),
307 event); 311 event);
308 } 312 }
309 313
310 str = ui_list_next(list->list); 314 elm = ui_list_next(list->list);
311 i++; 315 i++;
312 } 316 }
313 317
314 list->oldcount = i; 318 list->oldcount = i;
315 } 319 }
317 void ui_menu_event_wrapper(GtkMenuItem *item, UiEventData *event) { 321 void ui_menu_event_wrapper(GtkMenuItem *item, UiEventData *event) {
318 UiEvent evt; 322 UiEvent evt;
319 evt.obj = event->obj; 323 evt.obj = event->obj;
320 evt.window = event->obj->window; 324 evt.window = event->obj->window;
321 evt.document = event->obj->ctx->document; 325 evt.document = event->obj->ctx->document;
322 evt.eventdata = NULL; 326 evt.eventdata = event->customdata;
323 evt.intval = event->value; 327 evt.intval = event->value;
324 event->callback(&evt, event->userdata); 328 event->callback(&evt, event->userdata);
325 } 329 }
326 330
327 void ui_menu_event_toggled(GtkCheckMenuItem *ci, UiEventData *event) { 331 void ui_menu_event_toggled(GtkCheckMenuItem *ci, UiEventData *event) {

mercurial