ui/gtk/toolbar.c

changeset 116
480354705c2f
parent 90
2019fdbaadfd
child 140
c03c338a7dcf
--- a/ui/gtk/toolbar.c	Mon Jan 25 16:36:31 2016 +0100
+++ b/ui/gtk/toolbar.c	Tue Jan 26 19:45:28 2016 +0100
@@ -33,6 +33,7 @@
 #include "toolbar.h"
 #include "button.h"
 #include "image.h"
+#include "tree.h"
 #include "../../ucx/mempool.h"
 #include "../common/context.h"
 
@@ -189,7 +190,7 @@
         void *udata)
 {
     UiToolbarComboBoxNV *cb = malloc(sizeof(UiToolbarComboBoxNV));
-    cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox;  
+    cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox_nv;  
     cb->listname = listname;
     cb->getvalue = getvalue;
     cb->callback = f;
@@ -360,58 +361,13 @@
     listptr->list = cb->list;
     UiListModel *model = ui_list_model_new(listptr, modelinfo);
     
-    GtkWidget *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
-    cb->list->observers = ui_add_observer(
-            cb->list->observers,
-            (ui_callback)ui_listview_update,
-            combobox);
-    
-    GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
-    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE);
-    gtk_cell_layout_set_attributes(
-            GTK_CELL_LAYOUT(combobox),
-            renderer,
-            "text",
-            0,
-            NULL);
-    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
-    
-    // add callback
-    if(cb->callback) {
-        UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
-        event->obj = obj;
-        event->userdata = cb->userdata;
-        event->callback = cb->callback;
-        event->value = 0;
-
-        g_signal_connect(
-                combobox,
-                "changed",
-                G_CALLBACK(ui_combobox_change_event),
-                event);
-    }
-    
+    GtkWidget *combobox = ui_create_combobox(obj, model, cb->callback, cb->userdata);
     GtkToolItem *item = gtk_tool_item_new();
     gtk_container_add(GTK_CONTAINER(item), combobox);
     gtk_toolbar_insert(tb, item, -1);
 }
 
-void add_toolbara_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj) {
-    
+void add_toolbar_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj) {
+    // TODO
 }
 
-void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) {
-    UiEvent event;
-    event.obj = e->obj;
-    event.window = event.obj->window;
-    event.document = event.obj->ctx->document;
-    event.eventdata = NULL;
-    event.intval = gtk_combo_box_get_active(widget);
-    e->callback(&event, e->userdata);
-}
-
-void ui_combobox_update(UiEvent *event, void *combobox) {
-    printf("ui_combobox_update\n");
-    printf("TODO: implement\n");
-}
-

mercurial