ui/gtk/menu.c

changeset 32
e5f4d8af567e
parent 29
3fc287f06305
child 35
834d9c15a69f
equal deleted inserted replaced
31:bf810176ddb8 32:e5f4d8af567e
72 } 72 }
73 73
74 return mb; 74 return mb;
75 } 75 }
76 76
77 void ui_add_menu_items(GtkWidget *parent, int i, UiMenu *menu, UiObject *obj) {
78 UiMenuItemI *it = menu->items_begin;
79 int index = 0;
80 while(it) {
81 createMenuItem[it->type](parent, index, it, obj);
82 it = it->next;
83 index++;
84 }
85 }
86
77 void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj) { 87 void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj) {
78 UiMenu *menu = (UiMenu*)item; 88 UiMenu *menu = (UiMenu*)item;
79 89
80 GtkWidget *menu_widget = gtk_menu_new(); 90 GtkWidget *menu_widget = gtk_menu_new();
81 GtkWidget *menu_item = gtk_menu_item_new_with_mnemonic(menu->label); 91 GtkWidget *menu_item = gtk_menu_item_new_with_mnemonic(menu->label);
82 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu_widget); 92 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu_widget);
83 93
84 UiMenuItemI *it = menu->items_begin; 94 ui_add_menu_items(menu_widget, i, menu, obj);
85 int index = 0; 95
86 while(it) {
87 createMenuItem[it->type](menu_widget, index, it, obj);
88
89 it = it->next;
90 index++;
91 }
92 96
93 gtk_menu_shell_append(GTK_MENU_SHELL(parent), menu_item); 97 gtk_menu_shell_append(GTK_MENU_SHELL(parent), menu_item);
94 } 98 }
95 99
96 void add_menuitem_widget(GtkWidget *parent, int index, UiMenuItemI *item, UiObject *obj) { 100 void add_menuitem_widget(GtkWidget *parent, int index, UiMenuItemI *item, UiObject *obj) {
103 UiEventData *event = malloc(sizeof(UiEventData)); 107 UiEventData *event = malloc(sizeof(UiEventData));
104 event->obj = obj; 108 event->obj = obj;
105 event->userdata = i->userdata; 109 event->userdata = i->userdata;
106 event->callback = i->callback; 110 event->callback = i->callback;
107 event->value = 0; 111 event->value = 0;
112 event->customdata = NULL;
108 113
109 g_signal_connect( 114 g_signal_connect(
110 widget, 115 widget,
111 "activate", 116 "activate",
112 G_CALLBACK(ui_menu_event_wrapper), 117 G_CALLBACK(ui_menu_event_wrapper),
119 } 124 }
120 125
121 gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget); 126 gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget);
122 127
123 if(i->groups) { 128 if(i->groups) {
124 uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, i->groups); 129 CxList *groups = cxArrayListCreateSimple(sizeof(int), i->ngroups);
130 cxListAddArray(groups, i->groups, i->ngroups);
131 uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups);
132 cxListDestroy(groups);
125 } 133 }
126 } 134 }
127 135
128 /* 136 /*
129 void add_menuitem_st_widget( 137 void add_menuitem_st_widget(
183 UiEventData *event = malloc(sizeof(UiEventData)); 191 UiEventData *event = malloc(sizeof(UiEventData));
184 event->obj = obj; 192 event->obj = obj;
185 event->userdata = ci->userdata; 193 event->userdata = ci->userdata;
186 event->callback = ci->callback; 194 event->callback = ci->callback;
187 event->value = 0; 195 event->value = 0;
188 196 event->customdata = NULL;
197
189 g_signal_connect( 198 g_signal_connect(
190 widget, 199 widget,
191 "toggled", 200 "toggled",
192 G_CALLBACK(ui_menu_event_toggled), 201 G_CALLBACK(ui_menu_event_toggled),
193 event); 202 event);
233 ls->object = obj; 242 ls->object = obj;
234 ls->menu = GTK_MENU_SHELL(p); 243 ls->menu = GTK_MENU_SHELL(p);
235 ls->index = index; 244 ls->index = index;
236 ls->oldcount = 0; 245 ls->oldcount = 0;
237 246
238 // TODO: 247 UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST);
239 //ls->list = il->list; 248 ls->list = var->value;
240 249
241 ls->callback = il->callback; 250 ls->callback = il->callback;
242 ls->userdata = il->userdata; 251 ls->userdata = il->userdata;
243 252
244 ls->list->observers = ui_add_observer( 253 ls->list->observers = ui_add_observer(
282 UiEventData *event = malloc(sizeof(UiEventData)); 291 UiEventData *event = malloc(sizeof(UiEventData));
283 event->obj = list->object; 292 event->obj = list->object;
284 event->userdata = list->userdata; 293 event->userdata = list->userdata;
285 event->callback = list->callback; 294 event->callback = list->callback;
286 event->value = i - 1; 295 event->value = i - 1;
296 event->customdata = NULL;
287 297
288 g_signal_connect( 298 g_signal_connect(
289 widget, 299 widget,
290 "activate", 300 "activate",
291 G_CALLBACK(ui_menu_event_wrapper), 301 G_CALLBACK(ui_menu_event_wrapper),
406 UiEventData *event = malloc(sizeof(UiEventData)); 416 UiEventData *event = malloc(sizeof(UiEventData));
407 event->obj = obj; 417 event->obj = obj;
408 event->userdata = userdata; 418 event->userdata = userdata;
409 event->callback = f; 419 event->callback = f;
410 event->value = 0; 420 event->value = 0;
421 event->customdata = NULL;
411 422
412 g_signal_connect( 423 g_signal_connect(
413 widget, 424 widget,
414 "activate", 425 "activate",
415 G_CALLBACK(ui_menu_event_wrapper), 426 G_CALLBACK(ui_menu_event_wrapper),
460 UiEventData *event = malloc(sizeof(UiEventData)); 471 UiEventData *event = malloc(sizeof(UiEventData));
461 event->obj = obj; 472 event->obj = obj;
462 event->userdata = userdata; 473 event->userdata = userdata;
463 event->callback = f; 474 event->callback = f;
464 event->value = 0; 475 event->value = 0;
476 event->customdata = NULL;
465 477
466 g_signal_connect( 478 g_signal_connect(
467 widget, 479 widget,
468 "activate", 480 "activate",
469 G_CALLBACK(ui_menu_event_wrapper), 481 G_CALLBACK(ui_menu_event_wrapper),

mercurial