Tue, 26 Jan 2016 19:45:28 +0100
added combobox (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/common/types.c | file | annotate | diff | comparison | revisions | |
ui/gtk/container.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolbar.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolbar.h | file | annotate | diff | comparison | revisions | |
ui/gtk/tree.c | file | annotate | diff | comparison | revisions | |
ui/gtk/tree.h | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/ui/tree.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Mon Jan 25 16:36:31 2016 +0100 +++ b/application/main.c Tue Jan 26 19:45:28 2016 +0100 @@ -124,6 +124,7 @@ UiObject *obj = ui_window("Test", NULL); ui_context_closefunc(obj->ctx, window_close, NULL); +/* UIWIDGET w = ui_drawingarea(obj, draw, NULL); ctxmenu = ui_contextmenu_w(obj, w); ui_widget_menuitem(obj, "Test1", NULL, NULL); @@ -131,13 +132,23 @@ ui_widget_menuitem(obj, "Test3", NULL, NULL); ui_widget_menuitem(obj, "Test4", NULL, NULL); ui_drawingarea_mousehandler(obj, w, click, NULL); +*/ -/* - ui_vbox_sp(obj, 8, 4); +///* + ui_vbox_sp(obj, 8, 4); + + UiList *list = ui_list_new(); + ui_list_append(list, "Hello"); + ui_list_append(list, "World"); + ui_list_append(list, "Test"); + + ui_combobox_str(obj, list, NULL, NULL); + ui_button(obj, "Button", NULL, NULL); ui_button(obj, "Button", NULL, NULL); ui_button(obj, "Button", NULL, NULL); ui_button(obj, "Button", NULL, NULL); + ui_end(obj); //*/
--- a/ui/common/types.c Mon Jan 25 16:36:31 2016 +0100 +++ b/ui/common/types.c Tue Jan 26 19:45:28 2016 +0100 @@ -82,7 +82,7 @@ /* --------------------------- UiList --------------------------- */ -UiList* ui_list_new() { +UiList* ui_list_new(void) { UiList *list = malloc(sizeof(UiList)); list->first = ui_list_first; list->next = ui_list_next;
--- a/ui/gtk/container.c Mon Jan 25 16:36:31 2016 +0100 +++ b/ui/gtk/container.c Tue Jan 26 19:45:28 2016 +0100 @@ -236,7 +236,7 @@ UIWIDGET ui_vbox_sp(UiObject *obj, int margin, int spacing) { UiContainer *ct = uic_get_current_container(obj); - GtkWidget *vbox = ui_gtk_vbox_new(spacing); + GtkWidget *vbox = ui_gtk_vbox_new(spacing); GtkWidget *widget = margin > 0 ? box_set_margin(vbox, margin) : vbox; ct->add(ct, widget, TRUE);
--- 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"); -} -
--- a/ui/gtk/toolbar.h Mon Jan 25 16:36:31 2016 +0100 +++ b/ui/gtk/toolbar.h Tue Jan 26 19:45:28 2016 +0100 @@ -106,7 +106,7 @@ void add_toolitem_toggle_st_widget(GtkToolbar *tb, UiStToolItem *item, UiObject *obj); void add_toolbar_combobox(GtkToolbar *tb, UiToolbarComboBox *cb, UiObject *obj); -void add_toolbara_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj); +void add_toolbar_combobox_nv(GtkToolbar *tb, UiToolbarComboBoxNV *cb, UiObject *obj); void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e); void ui_combobox_update(UiEvent *event, void *combobox);
--- a/ui/gtk/tree.c Mon Jan 25 16:36:31 2016 +0100 +++ b/ui/gtk/tree.c Tue Jan 26 19:45:28 2016 +0100 @@ -307,3 +307,90 @@ int *indices = gtk_tree_path_get_indices(path); return indices[depth - 1]; } + + +/* --------------------------- ComboBox --------------------------- */ + +UIWIDGET ui_combobox_str(UiObject *obj, UiList *list, ui_callback f, void *udata) { + return ui_combobox(obj, list, ui_strmodel_getvalue, f, udata); +} + +UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { + UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); + listptr->list = list; + return ui_combobox_var(obj, listptr, getvalue, f, udata); +} + +UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { + UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST); + if(var) { + UiListVar *value = var->value; + return ui_combobox_var(obj, value->listptr, getvalue, f, udata); + } else { + // TODO: error + } + return NULL; +} + +UIWIDGET ui_combobox_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { + UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1); + modelinfo->getvalue = getvalue; + UiListModel *model = ui_list_model_new(list, modelinfo); + + GtkWidget *combobox = ui_create_combobox(obj, model, f, udata); + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, combobox, FALSE); +} + +GtkWidget* ui_create_combobox(UiObject *obj, UiListModel *model, ui_callback f, void *udata) { + GtkWidget *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model)); + + UiList *list = model->list->list; + list->observers = ui_add_observer( + 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(f) { + UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData)); + event->obj = obj; + event->userdata = udata; + event->callback = f; + event->value = 0; + + g_signal_connect( + combobox, + "changed", + G_CALLBACK(ui_combobox_change_event), + event); + } + + return combobox; +} + +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"); +} +
--- a/ui/gtk/tree.h Mon Jan 25 16:36:31 2016 +0100 +++ b/ui/gtk/tree.h Tue Jan 26 19:45:28 2016 +0100 @@ -69,6 +69,11 @@ UiTreeEventData *event); int ui_tree_path_list_index(GtkTreePath *path); +UIWIDGET ui_combobox_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata); +GtkWidget* ui_create_combobox(UiObject *obj, UiListModel *model, ui_callback f, void *udata); +void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e); +void ui_combobox_update(UiEvent *event, void *combobox); + #ifdef __cplusplus } #endif
--- a/ui/ui/toolkit.h Mon Jan 25 16:36:31 2016 +0100 +++ b/ui/ui/toolkit.h Tue Jan 26 19:45:28 2016 +0100 @@ -335,7 +335,7 @@ void ui_notify_except(UiObserver *observer, UiObserver *exc, void *data); -UiList* ui_list_new(); +UiList* ui_list_new(void); void* ui_list_first(UiList *list); void* ui_list_next(UiList *list); void* ui_list_get(UiList *list, int i);
--- a/ui/ui/tree.h Mon Jan 25 16:36:31 2016 +0100 +++ b/ui/ui/tree.h Tue Jan 26 19:45:28 2016 +0100 @@ -107,6 +107,10 @@ UIWIDGET ui_table(UiObject *obj, UiList *model, UiModelInfo *modelinfo); +UIWIDGET ui_combobox_str(UiObject *obj, UiList *list, ui_callback f, void *udata); +UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata); +UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata); + #ifdef __cplusplus } #endif