added toolbar combobox (GTK)

Wed, 11 Feb 2015 11:34:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 11 Feb 2015 11:34:55 +0100
changeset 86
3c63f57a8f77
parent 85
91f45354d1e2
child 87
e624b6fa4c78

added toolbar combobox (GTK)

application/main.c file | annotate | diff | comparison | revisions
config.mk file | annotate | diff | comparison | revisions
make/gcc.mk 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/motif/toolkit.c file | annotate | diff | comparison | revisions
ui/ui/toolbar.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sun Feb 01 12:37:31 2015 +0100
+++ b/application/main.c	Wed Feb 11 11:34:55 2015 +0100
@@ -33,7 +33,6 @@
 #include <ucx/buffer.h>
 #include <ucx/utils.h>
 
-/*
 typedef struct Person {
     char *name;
     char *mail;
@@ -91,49 +90,23 @@
 void action_test(UiEvent *event, void *data) {
     //ui_select_tab(tabview, 0);
 }
-*/
 
 void action_menu(UiEvent *event, void *data) {
     printf("action_menu test: {%s}\n", data);
     fflush(stdout);
 }
 
-void action_button(UiEvent *event, void *data) {
-    printf("button clicked\n");
-    fflush(stdout);
+void action_combobox_select(UiEvent *event, void *data) {
+    UiList *list = data;
+    int i = event->intval;
+    printf("selection{%s}[%d]\n", ui_list_get(list, i), i);
 }
 
+
 int main(int argc, char** argv) { 
+    ui_locales_dir("/opt/app1/locales");
+    ui_load_lang_def(NULL, "en_EN");
     ui_init("app1", argc, argv);
-    
-    ui_menu("File");
-    ui_menuitem("Hello", action_menu, "hello");
-    ui_submenu("Submenu1");
-    ui_submenu("Submenu2");
-    ui_menuitem("item2", NULL, NULL);
-    ui_submenu_end();
-    ui_menuitem("item3", NULL, NULL);
-    ui_submenu_end();
-    ui_menuitem("item4", NULL, NULL);
-    
-    UiObject *obj = ui_window("Test", NULL);
-    ui_layout_fill(obj, FALSE);
-    ui_hbox(obj);
-    ui_button(obj, "HELLO", NULL, NULL);
-    ui_button(obj, "WORLD", NULL, NULL);
-    ui_layout_fill(obj, TRUE);
-    ui_button(obj, "BUTTON", NULL, NULL);
-    ui_end(obj);
-    ui_button(obj, "Test1", action_button, NULL);
-    ui_button(obj, "Test2", action_button, NULL);
-    ui_button(obj, "Test3", action_button, NULL);
-    ui_button(obj, "Test4", action_button, NULL);
-    ui_show(obj);
-    fflush(stdout);
-    ui_main();
-    /*
-	ui_locales_dir("/opt/app1/locales");
-    ui_load_lang_def(NULL, "en_EN");
     //ui_openfilefunc(action_new, NULL);
     
     
@@ -144,7 +117,17 @@
     //ui_checkitem("Check", action_button, NULL);
     
     ui_toolitem_st("button", UI_STOCK_GO_BACK, action_button, NULL);
+    
+    UiList *cb = ui_list_new();
+    ui_list_append(cb, "Hello World");
+    ui_list_append(cb, "2");
+    ui_list_append(cb, "3");
+    ui_list_append(cb, "4");
+    ui_list_append(cb, "5");
+    ui_toolbar_combobox_str("combobox", cb, action_combobox_select, cb);
+    
     ui_toolbar_add_default("button");
+    ui_toolbar_add_default("combobox");
     
     printf("create window\n");
     UiObject *window = ui_window("Mod0", NULL);
@@ -191,6 +174,5 @@
     
     ui_show(window);
     ui_main();
-    */
     return (EXIT_SUCCESS);
 }
--- a/config.mk	Sun Feb 01 12:37:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-#
-# config.mk generated by configure
-#
-
-PREFIX = /opt/mk12
-
-include $(BUILD_ROOT)/make/mingw.mk
-
-
-# toolkit configuration
-CFLAGS += -DUI_WPF 
-
-LDFLAGS += $(BUILD_ROOT)/build/UIwrapper/UIwrapper.lib
-#LDFLAGS += -mwindows
-
-TOOLKIT = wpf
-
--- a/make/gcc.mk	Sun Feb 01 12:37:31 2015 +0100
+++ b/make/gcc.mk	Wed Feb 11 11:34:55 2015 +0100
@@ -42,4 +42,4 @@
 LIB_EXT = a
 APP_EXT =
 
-PACKAGE_SCRIPT = package_windows.sh
+PACKAGE_SCRIPT = package_unix.sh
--- a/ui/gtk/toolbar.c	Sun Feb 01 12:37:31 2015 +0100
+++ b/ui/gtk/toolbar.c	Wed Feb 11 11:34:55 2015 +0100
@@ -155,6 +155,50 @@
 }
 
 
+void ui_toolbar_combobox(
+        char *name,
+        UiList *list,
+        ui_model_getvalue_f getvalue,
+        ui_callback f,
+        void *udata)
+{
+    UiToolbarComboBox *cb = malloc(sizeof(UiToolbarComboBox));
+    cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox;  
+    cb->list = list;
+    cb->getvalue = getvalue;
+    cb->callback = f;
+    cb->userdata = udata;
+    
+    ucx_map_cstr_put(toolbar_items, name, cb);
+}
+
+void ui_toolbar_combobox_str(
+        char *name,
+        UiList *list,
+        ui_callback f,
+        void *udata)
+{
+    ui_toolbar_combobox(name, list, ui_strmodel_getvalue, f, udata);
+}
+
+void ui_toolbar_combobox_nv(
+        char *name,
+        char *listname,
+        ui_model_getvalue_f getvalue,
+        ui_callback f,
+        void *udata)
+{
+    UiToolbarComboBoxNV *cb = malloc(sizeof(UiToolbarComboBoxNV));
+    cb->item.add_to = (ui_toolbar_add_f)add_toolbar_combobox;  
+    cb->listname = listname;
+    cb->getvalue = getvalue;
+    cb->callback = f;
+    cb->userdata = udata;
+    
+    ucx_map_cstr_put(toolbar_items, name, cb);
+}
+
+
 void ui_toolbar_add_default(char *name) {
     char *s = strdup(name);
     defaults = ucx_list_append(defaults, s);
@@ -306,3 +350,66 @@
         uic_add_group_widget(obj->ctx, button, item->groups);
     }
 }
+
+void add_toolbar_combobox(GtkToolbar *tb, UiToolbarComboBox *cb, UiObject *obj) {
+    UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, "", -1);
+    modelinfo->getvalue = cb->getvalue;
+    UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
+    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);
+    }
+    
+    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 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	Sun Feb 01 12:37:31 2015 +0100
+++ b/ui/gtk/toolbar.h	Wed Feb 11 11:34:55 2015 +0100
@@ -33,6 +33,9 @@
 #include "../../ucx/map.h"
 #include "../../ucx/list.h"
 
+#include "model.h"
+#include "tree.h"
+
 #ifdef	__cplusplus
 extern "C" {
 #endif
@@ -41,6 +44,9 @@
 typedef struct UiToolItem     UiToolItem;
 typedef struct UiStToolItem   UiStToolItem;
 
+typedef struct UiToolbarComboBox   UiToolbarComboBox;
+typedef struct UiToolbarComboBoxNV UiToolbarComboBoxNV;
+
 typedef void(*ui_toolbar_add_f)(GtkToolbar*, UiToolItemI*, UiObject*);
 
 struct UiToolItemI {
@@ -66,6 +72,22 @@
     int            isimportant;
 };
 
+struct UiToolbarComboBox {
+    UiToolItemI         item;
+    UiList              *list;
+    ui_model_getvalue_f getvalue;
+    ui_callback         callback;
+    void                *userdata;
+};
+
+struct UiToolbarComboBoxNV {
+    UiToolItemI         item;
+    char                *listname;
+    ui_model_getvalue_f getvalue;
+    ui_callback         callback;
+    void                *userdata;
+};
+
 void ui_toolbar_init();
 
 void ui_toolitem_vstgr(
@@ -83,6 +105,10 @@
 void add_toolitem_toggle_widget(GtkToolbar *tb, UiToolItem *item, UiObject *obj);
 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 ui_combobox_change_event(GtkComboBox *widget, UiEventData *e);
+void ui_combobox_update(UiEvent *event, void *combobox);
 
 #ifdef	__cplusplus
 }
--- a/ui/gtk/tree.c	Sun Feb 01 12:37:31 2015 +0100
+++ b/ui/gtk/tree.c	Wed Feb 11 11:34:55 2015 +0100
@@ -78,7 +78,7 @@
     
     // add callback
     if(f) {
-        UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData));
+        UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
         event->obj = obj;
         event->userdata = udata;
         event->activate = f;
--- a/ui/motif/toolkit.c	Sun Feb 01 12:37:31 2015 +0100
+++ b/ui/motif/toolkit.c	Wed Feb 11 11:34:55 2015 +0100
@@ -50,7 +50,7 @@
 
 int event_pipe[2];
 
-/*
+///*
 static String fallback[] = {
     	//"*fontList: -dt-interface system-medium-r-normal-s*utf*:",    
         "*renderTable: rt",
@@ -74,7 +74,7 @@
 	NULL
 };
 //*/
-///*
+/*
 static String fallback[] = {
     	//"*fontList: -dt-interface system-medium-r-normal-s*utf*:",    
         "*text_area*renderTable: f1",
--- a/ui/ui/toolbar.h	Sun Feb 01 12:37:31 2015 +0100
+++ b/ui/ui/toolbar.h	Wed Feb 11 11:34:55 2015 +0100
@@ -46,6 +46,10 @@
 void ui_toolitem_toggle_stgr(char *name, char *stockid, ui_callback f, void *udata, ...);
 void ui_toolitem_toggle_imggr(char *name, char *label, char *img, ui_callback f, void *udata, ...);
 
+void ui_toolbar_combobox(char *name, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata);
+void ui_toolbar_combobox_str(char *name, UiList *list, ui_callback f, void *udata);
+void ui_toolbar_combobox_nv(char *name, char *listname, ui_model_getvalue_f getvalue, ui_callback f, void *udata);
+
 void ui_toolbar_add_default(char *name);
 
 #ifdef	__cplusplus

mercurial