Fri, 11 Dec 2020 11:46:19 +0100
add drawingarea and textarea group
--- a/application/Makefile Thu Dec 10 13:43:25 2020 +0100 +++ b/application/Makefile Fri Dec 11 11:46:19 2020 +0100 @@ -35,6 +35,7 @@ SRC += application.c SRC += menu.c SRC += window.c +SRC += browser.c OBJ = $(SRC:%.c=../build/application/%.$(OBJ_EXT))
--- a/application/application.h Thu Dec 10 13:43:25 2020 +0100 +++ b/application/application.h Fri Dec 11 11:46:19 2020 +0100 @@ -19,6 +19,10 @@ #ifdef __cplusplus extern "C" { #endif + +enum ApplicationUIGroups { + APPGR_DOCUMENT_OPEN = 0 +}; void application_startup(UiEvent *event, void *data);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/application/browser.c Fri Dec 11 11:46:19 2020 +0100 @@ -0,0 +1,22 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +#include "browser.h" + +#include <stdio.h> +#include <stdlib.h> + +UIWIDGET document_browser_create(UiObject *obj) { + ui_layout_width(obj, 250); + UIWIDGET browser = ui_drawingarea(obj, browser_draw, NULL); + return browser; +} + +void browser_draw(UiEvent *event, UiGraphics *g, void *udata) { + ui_graphics_color(g, 100, 100, 100); + + ui_draw_rect(g, 0, 0, g->width, g->height, TRUE); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/application/browser.h Fri Dec 11 11:46:19 2020 +0100 @@ -0,0 +1,34 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: browser.h + * Author: olaf + * + * Created on 11. Dezember 2020, 10:56 + */ + +#ifndef APP_BROWSER_H +#define APP_BROWSER_H + +#include "application.h" + +#include <ui/graphics.h> + +#ifdef __cplusplus +extern "C" { +#endif + +UIWIDGET document_browser_create(UiObject *obj); + +void browser_draw(UiEvent *event, UiGraphics *g, void *udata); + +#ifdef __cplusplus +} +#endif + +#endif /* APP_BROWSER_H */ +
--- a/application/menu.c Thu Dec 10 13:43:25 2020 +0100 +++ b/application/menu.c Fri Dec 11 11:46:19 2020 +0100 @@ -27,6 +27,7 @@ */ #include "menu.h" +#include "window.h" #include <stdio.h> #include <stdlib.h> @@ -34,8 +35,8 @@ #pragma clang diagnostic ignored "-Wdeprecated-declarations" static UiInteger *tb_sidebar; -static UiInteger *tb_browser; -static UiInteger *tb_editor; +static UiInteger *tb_singleview; +static UiInteger *tb_dualview; static void create_main_menu(void) { ui_menu("File"); @@ -50,19 +51,25 @@ static void create_main_toolbar(void) { UiContext *ctx = ui_global_context(); tb_sidebar = ui_int_new(ctx, NULL); - tb_browser = ui_int_new(ctx, NULL); - tb_editor = ui_int_new(ctx, NULL); + tb_singleview = ui_int_new(ctx, NULL); + tb_dualview = ui_int_new(ctx, NULL); + tb_sidebar->observers = ui_add_observer(tb_sidebar->observers, action_show_sidebar, NULL); + tb_singleview->observers = ui_add_observer(tb_singleview->observers, action_singleview, NULL); + tb_dualview->observers = ui_add_observer(tb_dualview->observers, action_dualview, NULL); ui_toolitem_toggle("show-sidebar", "Sidebar", NULL, tb_sidebar); - ui_toolitem_toggle("show-browser", "Browser", NULL, tb_browser); - ui_toolitem_toggle("show-editor", "Editor", NULL, tb_editor); + ui_toolitem_toggle("singleview", "S", NULL, tb_singleview); + ui_toolitem_toggle("dualview", "D", NULL, tb_dualview); + tb_sidebar->value = 1; - tb_browser->value = 1; - tb_editor->value = 1; + tb_singleview->value = 0; + tb_dualview->value = 1; ui_toolbar_add_default("show-sidebar"); - ui_toolbar_add_default("show-browser"); - ui_toolbar_add_default("show-editor"); + ui_toolbar_add_default("@separator"); + ui_toolbar_add_default("singleview"); + ui_toolbar_add_default("dualview"); + ui_toolbar_add_default("@separator"); } void menu_init(void) { @@ -71,13 +78,47 @@ } void action_show_sidebar(UiEvent *event, void *udata) { + WindowData *w = event->window; + ui_set_visible(w->sidebar, event->intval); +} + +static void change_view(WindowData *w, int dual) { + if(dual) { + ui_set_visible(w->browser, TRUE); + ui_set_visible(w->editor, TRUE); + } else { + UiBool e, b; + if(w->editorIsOpen) { + e = TRUE; + b = FALSE; + } else { + e = FALSE; + b = TRUE; + } + ui_set_visible(w->browser, b); + ui_set_visible(w->editor, e); + } +} + +void action_dualview(UiEvent *event, void *udata) { + int s = event->intval == 1 ? 0 : 1; + tb_singleview->set(tb_singleview, s); + change_view(event->window, event->intval); +} + +void action_singleview(UiEvent *event, void *udata) { + int s = event->intval == 1 ? 0 : 1; + tb_dualview->set(tb_dualview, s); + change_view(event->window, s); +} + + + + +void action_test1(UiEvent *event, void *udata) { } -void action_show_browser(UiEvent *event, void *udata) { +void action_test2(UiEvent *event, void *udata) { } - -void action_show_editor(UiEvent *event, void *udata) { - -}
--- a/application/menu.h Thu Dec 10 13:43:25 2020 +0100 +++ b/application/menu.h Fri Dec 11 11:46:19 2020 +0100 @@ -38,8 +38,11 @@ void menu_init(void); void action_show_sidebar(UiEvent *event, void *udata); -void action_show_browser(UiEvent *event, void *udata); -void action_show_editor(UiEvent *event, void *udata); +void action_dualview(UiEvent *event, void *udata); +void action_singleview(UiEvent *event, void *udata); + +void action_test1(UiEvent *event, void *udata); +void action_test2(UiEvent *event, void *udata); #ifdef __cplusplus }
--- a/application/window.c Thu Dec 10 13:43:25 2020 +0100 +++ b/application/window.c Fri Dec 11 11:46:19 2020 +0100 @@ -28,6 +28,7 @@ #include "window.h" #include "menu.h" +#include "browser.h" #include <stdio.h> #include <stdlib.h> @@ -35,6 +36,7 @@ UiObject* window_create(void) { UiObject *obj = ui_window("Note", NULL); WindowData *window = ui_malloc(obj->ctx, sizeof(WindowData)); + memset(window, 0, sizeof(WindowData)); obj->window = window; UI_CTN(obj, ui_hsplitpane(obj, 3)) { @@ -44,9 +46,10 @@ ui_listview_nv(obj, "notebooks", NULL, NULL, NULL); } - window->browser = ui_label(obj, "Browser"); + window->browser = document_browser_create(obj); window->editor = ui_textarea_nv(obj, "text"); + ui_widget_set_groups(obj->ctx, ui_textarea_gettextwidget(window->editor), (ui_enablefunc)ui_set_enabled, APPGR_DOCUMENT_OPEN, -1); } return obj;
--- a/application/window.h Thu Dec 10 13:43:25 2020 +0100 +++ b/application/window.h Fri Dec 11 11:46:19 2020 +0100 @@ -39,6 +39,8 @@ UIWIDGET sidebar; UIWIDGET browser; UIWIDGET editor; + + UiBool editorIsOpen; } WindowData; UiObject* window_create(void);
--- a/ui/common/context.c Thu Dec 10 13:43:25 2020 +0100 +++ b/ui/common/context.c Fri Dec 11 11:46:19 2020 +0100 @@ -395,7 +395,6 @@ } - void ui_set_group(UiContext *ctx, int group) { if(ucx_list_find(ctx->groups, (void*)(intptr_t)group, NULL, NULL) == -1) { ctx->groups = ucx_list_append_a(ctx->mempool->allocator, ctx->groups, (void*)(intptr_t)group); @@ -456,7 +455,7 @@ break; } } - ui_set_enabled(gw->widget, enable); + gw->enable(gw->widget, enable); } if(groups) { @@ -464,11 +463,28 @@ } } -void uic_add_group_widget(UiContext *ctx, void *widget, UcxList *groups) { +void ui_widget_set_groups(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...) { + // get groups + UcxList *groups = NULL; + va_list ap; + va_start(ap, enable); + int group; + while((group = va_arg(ap, int)) != -1) { + groups = ucx_list_append(groups, (void*)(intptr_t)group); + } + va_end(ap); + + uic_add_group_widget(ctx, widget, enable, groups); + + ucx_list_free(groups); +} + +void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, UcxList *groups) { UcxMempool *mp = ctx->mempool; UiGroupWidget *gw = ucx_mempool_malloc(mp, sizeof(UiGroupWidget)); gw->widget = widget; + gw->enable = enable; gw->numgroups = ucx_list_size(groups); gw->groups = ucx_mempool_calloc(mp, gw->numgroups, sizeof(int)); int i = 0;
--- a/ui/common/context.h Thu Dec 10 13:43:25 2020 +0100 +++ b/ui/common/context.h Fri Dec 11 11:46:19 2020 +0100 @@ -91,9 +91,10 @@ }; struct UiGroupWidget { - UIWIDGET widget; - int *groups; - int numgroups; + void *widget; + ui_enablefunc enable; + int *groups; + int numgroups; }; @@ -121,7 +122,7 @@ void uic_remove_bound_var(UiContext *ctx, UiVar *var); void uic_check_group_widgets(UiContext *ctx); -void uic_add_group_widget(UiContext *ctx, void *widget, UcxList *groups); +void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, UcxList *groups); #ifdef __cplusplus
--- a/ui/gtk/menu.c Thu Dec 10 13:43:25 2020 +0100 +++ b/ui/gtk/menu.c Fri Dec 11 11:46:19 2020 +0100 @@ -265,7 +265,7 @@ gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget); if(i->groups) { - uic_add_group_widget(obj->ctx, widget, i->groups); + uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, i->groups); } } @@ -301,7 +301,7 @@ gtk_menu_shell_append(GTK_MENU_SHELL(parent), widget); if(i->groups) { - uic_add_group_widget(obj->ctx, widget, i->groups); + uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, i->groups); } } @@ -554,7 +554,7 @@ gtk_menu_shell_append(GTK_MENU_SHELL(ct->menu), widget); if(groups) { - uic_add_group_widget(obj->ctx, widget, groups); + uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups); } } @@ -604,6 +604,6 @@ gtk_menu_shell_append(GTK_MENU_SHELL(ct->menu), widget); if(groups) { - uic_add_group_widget(obj->ctx, widget, groups); + uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups); } }
--- a/ui/gtk/text.c Thu Dec 10 13:43:25 2020 +0100 +++ b/ui/gtk/text.c Fri Dec 11 11:46:19 2020 +0100 @@ -173,6 +173,10 @@ return NULL; } +UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { + return gtk_bin_get_child(GTK_BIN(textarea)); +} + char* ui_textarea_get(UiText *text) { if(text->value.ptr) { text->value.free(text->value.ptr);
--- a/ui/gtk/toolbar.c Thu Dec 10 13:43:25 2020 +0100 +++ b/ui/gtk/toolbar.c Fri Dec 11 11:46:19 2020 +0100 @@ -275,7 +275,7 @@ gtk_toolbar_insert(tb, button, -1); if(item->groups) { - uic_add_group_widget(obj->ctx, button, item->groups); + uic_add_group_widget(obj->ctx, button, (ui_enablefunc)ui_set_enabled, item->groups); } } @@ -304,7 +304,7 @@ gtk_toolbar_insert(tb, button, -1); if(item->groups) { - uic_add_group_widget(obj->ctx, button, item->groups); + uic_add_group_widget(obj->ctx, button, (ui_enablefunc)ui_set_enabled, item->groups); } } @@ -366,7 +366,7 @@ gtk_toolbar_insert(tb, button, -1); if(item->groups) { - uic_add_group_widget(obj->ctx, button, item->groups); + uic_add_group_widget(obj->ctx, button, (ui_enablefunc)ui_set_enabled, item->groups); } } @@ -390,7 +390,7 @@ } void ui_tool_toggle_button_set(UiInteger *integer, int64_t value) { - gboolean s = integer->value != 0 ? TRUE : FALSE; + gboolean s = value != 0 ? TRUE : FALSE; gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(integer->obj), s); integer->value = s; }
--- a/ui/ui/text.h Thu Dec 10 13:43:25 2020 +0100 +++ b/ui/ui/text.h Fri Dec 11 11:46:19 2020 +0100 @@ -38,6 +38,8 @@ UIWIDGET ui_textarea(UiObject *obj, UiText *value); UIWIDGET ui_textarea_nv(UiObject *obj, char *varname); +UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea); + void ui_text_undo(UiText *value); void ui_text_redo(UiText *value);
--- a/ui/ui/toolkit.h Thu Dec 10 13:43:25 2020 +0100 +++ b/ui/ui/toolkit.h Fri Dec 11 11:46:19 2020 +0100 @@ -126,6 +126,8 @@ typedef void(*ui_freefunc)(void*); +typedef void(*ui_enablefunc)(void*, UiBool); + struct UiObject { /* * native widget @@ -314,6 +316,8 @@ void ui_attach_document(UiContext *ctx, void *document); void ui_detach_document2(UiContext *ctx, void *document); +void ui_widget_set_groups(UiContext *ctx, UIWIDGET widget, ui_enablefunc enable, ...); + void ui_set_group(UiContext *ctx, int group); void ui_unset_group(UiContext *ctx, int group); int* ui_active_groups(UiContext *ctx, int *ngroups);