ui/gtk/toolbar.c

changeset 116
480354705c2f
parent 90
2019fdbaadfd
child 140
c03c338a7dcf
equal deleted inserted replaced
115:102fc0b8fe3e 116:480354705c2f
31 #include <string.h> 31 #include <string.h>
32 32
33 #include "toolbar.h" 33 #include "toolbar.h"
34 #include "button.h" 34 #include "button.h"
35 #include "image.h" 35 #include "image.h"
36 #include "tree.h"
36 #include "../../ucx/mempool.h" 37 #include "../../ucx/mempool.h"
37 #include "../common/context.h" 38 #include "../common/context.h"
38 39
39 static UcxMap *toolbar_items; 40 static UcxMap *toolbar_items;
40 static UcxList *defaults; 41 static UcxList *defaults;
187 ui_model_getvalue_f getvalue, 188 ui_model_getvalue_f getvalue,
188 ui_callback f, 189 ui_callback f,
189 void *udata) 190 void *udata)
190 { 191 {
191 UiToolbarComboBoxNV *cb = malloc(sizeof(UiToolbarComboBoxNV)); 192 UiToolbarComboBoxNV *cb = malloc(sizeof(UiToolbarComboBoxNV));
192 cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox; 193 cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox_nv;
193 cb->listname = listname; 194 cb->listname = listname;
194 cb->getvalue = getvalue; 195 cb->getvalue = getvalue;
195 cb->callback = f; 196 cb->callback = f;
196 cb->userdata = udata; 197 cb->userdata = udata;
197 198
358 modelinfo->getvalue = cb->getvalue; 359 modelinfo->getvalue = cb->getvalue;
359 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); 360 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
360 listptr->list = cb->list; 361 listptr->list = cb->list;
361 UiListModel *model = ui_list_model_new(listptr, modelinfo); 362 UiListModel *model = ui_list_model_new(listptr, modelinfo);
362 363
363 GtkWidget *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model)); 364 GtkWidget *combobox = ui_create_combobox(obj, model, cb->callback, cb->userdata);
364 cb->list->observers = ui_add_observer(
365 cb->list->observers,
366 (ui_callback)ui_listview_update,
367 combobox);
368
369 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
370 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE);
371 gtk_cell_layout_set_attributes(
372 GTK_CELL_LAYOUT(combobox),
373 renderer,
374 "text",
375 0,
376 NULL);
377 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
378
379 // add callback
380 if(cb->callback) {
381 UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
382 event->obj = obj;
383 event->userdata = cb->userdata;
384 event->callback = cb->callback;
385 event->value = 0;
386
387 g_signal_connect(
388 combobox,
389 "changed",
390 G_CALLBACK(ui_combobox_change_event),
391 event);
392 }
393
394 GtkToolItem *item = gtk_tool_item_new(); 365 GtkToolItem *item = gtk_tool_item_new();
395 gtk_container_add(GTK_CONTAINER(item), combobox); 366 gtk_container_add(GTK_CONTAINER(item), combobox);
396 gtk_toolbar_insert(tb, item, -1); 367 gtk_toolbar_insert(tb, item, -1);
397 } 368 }
398 369
399 void add_toolbara_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj) { 370 void add_toolbar_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj) {
400 371 // TODO
401 } 372 }
402 373
403 void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) {
404 UiEvent event;
405 event.obj = e->obj;
406 event.window = event.obj->window;
407 event.document = event.obj->ctx->document;
408 event.eventdata = NULL;
409 event.intval = gtk_combo_box_get_active(widget);
410 e->callback(&event, e->userdata);
411 }
412
413 void ui_combobox_update(UiEvent *event, void *combobox) {
414 printf("ui_combobox_update\n");
415 printf("TODO: implement\n");
416 }
417

mercurial