added textarea (WPF)

Sat, 14 Feb 2015 13:26:00 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 14 Feb 2015 13:26:00 +0100
changeset 88
04c81be1c5a0
parent 87
e624b6fa4c78
child 89
9a7e4a335b2b

added textarea (WPF)

application/main.c file | annotate | diff | comparison | revisions
ui/common/context.c file | annotate | diff | comparison | revisions
ui/wpf/UIcore/TextArea.cs file | annotate | diff | comparison | revisions
ui/wpf/UIcore/UIcore.csproj file | annotate | diff | comparison | revisions
ui/wpf/UIcore/Window.cs file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper.v12.suo file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/container.cpp file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/controls.cpp file | annotate | diff | comparison | revisions
ui/wpf/container.c file | annotate | diff | comparison | revisions
ui/wpf/container.h file | annotate | diff | comparison | revisions
ui/wpf/objs.mk file | annotate | diff | comparison | revisions
ui/wpf/text.c file | annotate | diff | comparison | revisions
ui/wpf/text.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sat Feb 14 10:30:45 2015 +0100
+++ b/application/main.c	Sat Feb 14 13:26:00 2015 +0100
@@ -33,6 +33,7 @@
 #include <ucx/buffer.h>
 #include <ucx/utils.h>
 
+/*
 typedef struct Person {
     char *name;
     char *mail;
@@ -90,23 +91,39 @@
 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);
+    printf("text: {%s}\n", ui_gettext(event->obj, "text"));
+    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_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_textarea_nv(obj, "text");
+    ui_show(obj);
+    ui_main();
+    /*
+	ui_locales_dir("/opt/app1/locales");
     ui_load_lang_def(NULL, "en_EN");
-    ui_init("app1", argc, argv);
     //ui_openfilefunc(action_new, NULL);
     
     
@@ -117,17 +134,7 @@
     //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);
@@ -174,5 +181,6 @@
     
     ui_show(window);
     ui_main();
+    */
     return (EXIT_SUCCESS);
 }
--- a/ui/common/context.c	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/common/context.c	Sat Feb 14 13:26:00 2015 +0100
@@ -395,7 +395,7 @@
         } else {
             fprintf(
                     stderr,
-                    "UI Error: requested variable %s is not an string.\n",
+                    "UI Error: requested variable %s is not a text.\n",
                     name);
         }
     } else {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/UIcore/TextArea.cs	Sat Feb 14 13:26:00 2015 +0100
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace UI
+{
+    public class TextArea : System.Windows.Controls.TextBox
+    {
+        public TextArea(Container container, String text) : base()
+        {
+            AcceptsReturn = true;
+            IsUndoEnabled = false; // we need our own undo stack
+            if (text != null)
+            {
+                Text = text;
+            }
+            VerticalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto;
+            HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto;
+            
+            container.Add(this, true);
+        }
+
+        public static TextArea CreateTextArea(Container container, String text)
+        {
+            return Application.GetInstance().Exec<TextArea>(() => new TextArea(container, text));
+        }
+
+
+        // ------------------ UiText methods ------------------
+
+        public void SetText(String str)
+        {
+            Application.GetInstance().Exec(() => Text = str);
+        }
+
+        public String GetText()
+        {
+            return Application.GetInstance().Exec<String>(() => Text);
+        }
+
+        public String GetSubString(int begin, int end)
+        {
+            return null;
+        }
+
+        public void Insert(int pos, String str)
+        {
+
+        }
+
+        public int Position()
+        {
+            return Application.GetInstance().Exec<int>(() => CaretIndex);
+        }
+
+        public int Selection()
+        {
+            return 0;
+        }
+
+        public int Length()
+        {
+            return Application.GetInstance().Exec<int>(() => Text.Length);
+        }
+
+        public void Remove(int begin, int end)
+        {
+
+        }
+    }
+}
--- a/ui/wpf/UIcore/UIcore.csproj	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/wpf/UIcore/UIcore.csproj	Sat Feb 14 13:26:00 2015 +0100
@@ -49,6 +49,7 @@
     <Compile Include="Container.cs" />
     <Compile Include="Controls.cs" />
     <Compile Include="Menu.cs" />
+    <Compile Include="TextArea.cs" />
     <Compile Include="Toolkit.cs" />
     <Compile Include="Window.cs" />
     <Compile Include="Application.cs" />
--- a/ui/wpf/UIcore/Window.cs	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/wpf/UIcore/Window.cs	Sat Feb 14 13:26:00 2015 +0100
@@ -42,7 +42,7 @@
 
             // menu
             Application app = Application.GetInstance();
-            if (!app.AppMenu.IsEmpty() && false)
+            if (!app.AppMenu.IsEmpty())
             {
                 System.Windows.Controls.Menu menu = app.AppMenu.CreateMenu(uiobj);
 
Binary file ui/wpf/UIwrapper/UIwrapper.v12.suo has changed
--- a/ui/wpf/UIwrapper/UIwrapper/container.cpp	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/wpf/UIwrapper/UIwrapper/container.cpp	Sat Feb 14 13:26:00 2015 +0100
@@ -27,5 +27,5 @@
 
 UI_EXPORT void __stdcall UIlayout_fill(gcroot<UI::Container^> *container, int fill) {
 	UI::Container ^ct = *container;
-	ct->Layout->Fill = fill;
+	ct->Layout->Fill = fill != 0;
 }
--- a/ui/wpf/UIwrapper/UIwrapper/controls.cpp	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/wpf/UIwrapper/UIwrapper/controls.cpp	Sat Feb 14 13:26:00 2015 +0100
@@ -15,4 +15,55 @@
 
 	*button = UI::Controls::Button(*container, gcnew String(label), handler);
 	return button;
-}
\ No newline at end of file
+}
+
+
+UI_EXPORT void* __stdcall UItextarea(gcroot<UI::Container^> *container, char *text) {
+	String ^str = nullptr;
+	if (text) {
+		str = gcnew String(text);
+	}
+	
+	gcroot<UI::TextArea^> *textarea = new gcroot<UI::TextArea^>();
+	*textarea = UI::TextArea::CreateTextArea(*container, str);
+
+	return textarea;
+}
+
+UI_EXPORT void  __stdcall UItextarea_set(gcroot<UI::TextArea^> *textarea, char *str) {
+	(*textarea)->SetText(gcnew String(str));
+}
+
+UI_EXPORT char* __stdcall UItextarea_get(gcroot<UI::TextArea^> *textarea) {
+	String ^str = (*textarea)->GetText();
+	return (char*)(void*)Marshal::StringToHGlobalAnsi(str);
+}
+
+UI_EXPORT char* __stdcall UItextarea_getsubstr(gcroot<UI::TextArea^> *textarea, int begin, int end) {
+	String ^str = (*textarea)->GetSubString(begin, end);
+	return (char*)(void*)Marshal::StringToHGlobalAnsi(str);
+}
+
+UI_EXPORT void __stdcall UItextarea_insert(gcroot<UI::TextArea^> *textarea, int position, char *str) {
+	// TODO
+}
+
+UI_EXPORT int __stdcall UItextarea_position(gcroot<UI::TextArea^> *textarea) {
+	return (*textarea)->Position();
+}
+
+UI_EXPORT void __stdcall UItextarea_selection(gcroot<UI::TextArea^> *textarea, int *begin, int *end) {
+	// TODO
+}
+
+UI_EXPORT int __stdcall UItextarea_length(gcroot<UI::TextArea^> *textarea) {
+	return (*textarea)->Length();
+}
+
+UI_EXPORT void __stdcall UItextarea_remove(gcroot<UI::TextArea^> *textarea, int begin, int end) {
+	// TODO
+}
+
+UI_EXPORT void __stdcall UIfreestr(char *str) {
+	Marshal::FreeHGlobal((IntPtr)(void*)str);
+}
--- a/ui/wpf/container.c	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/wpf/container.c	Sat Feb 14 13:26:00 2015 +0100
@@ -1,3 +1,31 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2015 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 
--- a/ui/wpf/container.h	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/wpf/container.h	Sat Feb 14 13:26:00 2015 +0100
@@ -1,8 +1,29 @@
-/* 
- * File:   container.h
- * Author: Olaf
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2015 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
  *
- * Created on 31. Januar 2015, 23:20
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef CONTAINER_H
--- a/ui/wpf/objs.mk	Sat Feb 14 10:30:45 2015 +0100
+++ b/ui/wpf/objs.mk	Sat Feb 14 13:26:00 2015 +0100
@@ -34,6 +34,7 @@
 WPFOBJ += container.o
 WPFOBJ += menu.o
 WPFOBJ += button.o
+WPFOBJ += text.o
 
 TOOLKITOBJS += $(WPFOBJ:%=$(WPF_OBJPRE)%)
 TOOLKITSOURCE += $(WPFOBJ:%.o=wpf/%.c)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/text.c	Sat Feb 14 13:26:00 2015 +0100
@@ -0,0 +1,118 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2015 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "text.h"
+
+UIWIDGET ui_textarea(UiObject *obj, UiText *value) {
+    UiContainer *container = uic_get_current_container(obj); 
+    UIWIDGET textarea = UItextarea(container, value ? value->value : NULL);
+    
+    if(value) {
+        value->get = ui_textarea_get;
+        value->set = ui_textarea_set;
+        value->getsubstr = ui_textarea_getsubstr;
+        value->insert = ui_textarea_insert;
+        value->position = ui_textarea_position;
+        value->selection = ui_textarea_selection;
+        value->length = ui_textarea_length;
+        value->remove = ui_textarea_remove;
+        value->value = NULL;
+        value->obj = textarea;
+        if(!value->undomgr) {
+            //value->undomgr = ;
+        }
+    }
+    
+    return textarea;
+}
+
+UIWIDGET ui_textarea_nv(UiObject *obj, char *varname) {
+    UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_TEXT);
+    if(var) {
+        UiText *value = var->value;
+        return ui_textarea(obj, value);
+    } else {
+        // TODO: error
+    }
+    return NULL;
+}
+
+char* ui_textarea_get(UiText *text) {
+    if(text->value) {
+        UIfreestr(text->value);
+    }
+    text->value = UItextarea_get(text->obj);
+    return text->value;
+}
+
+void ui_textarea_set(UiText *text, char *str) {
+    if(text->value) {
+        UIfreestr(text->value);
+        text->value = NULL;
+    }
+    UItextarea_set(text->obj, str);
+}
+
+char* ui_textarea_getsubstr(UiText *text, int begin, int end) {
+    if(text->value) {
+        UIfreestr(text->value);
+    }
+    text->value = UItextarea_getsubstr(text->obj, begin, end);
+    return text->value;
+}
+
+void ui_textarea_insert(UiText *text, int pos, char *str) {
+    if(text->value) {
+        UIfreestr(text->value);
+        text->value = NULL;
+    }
+    UItextarea_insert(text->obj, pos, str);
+}
+
+int ui_textarea_position(UiText *text) {
+    return UItextarea_position(text->obj);
+}
+
+void ui_textarea_selection(UiText *text, int *begin, int *end) {
+    UItextarea_selection(text->obj, begin, end);
+}
+
+int ui_textarea_length(UiText *text) {
+    return UItextarea_length(text->obj);
+}
+
+void ui_textarea_remove(UiText *text, int begin, int end) {
+    if(text->value) {
+        UIfreestr(text->value);
+        text->value = NULL;
+    }
+    UItextarea_remove(text->obj, begin, end);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/text.h	Sat Feb 14 13:26:00 2015 +0100
@@ -0,0 +1,66 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2015 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEXT_H
+#define	TEXT_H
+
+#include "../ui/text.h"
+#include "toolkit.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+UI_IMPORT UIWIDGET __stdcall UItextarea(void *container, char *text);
+
+char* ui_textarea_get(UiText *text);
+void ui_textarea_set(UiText *text, char *str);
+char* ui_textarea_getsubstr(UiText *text, int begin, int end);
+void ui_textarea_insert(UiText *text, int pos, char *str);
+int ui_textarea_position(UiText *text);
+void ui_textarea_selection(UiText *text, int *begin, int *end);
+int ui_textarea_length(UiText *text);
+void ui_textarea_remove(UiText *text, int begin, int end);
+
+UI_IMPORT void __stdcall UItextarea_set(UIWIDGET textarea, char *str);
+UI_IMPORT char* __stdcall UItextarea_get(UIWIDGET textarea);
+UI_IMPORT char* __stdcall UItextarea_getsubstr(UIWIDGET textarea, int begin, int end);
+UI_IMPORT void __stdcall UItextarea_insert(UIWIDGET textarea, int pos, char *str);
+UI_IMPORT int __stdcall UItextarea_position(UIWIDGET textarea);
+UI_IMPORT void __stdcall UItextarea_selection(UIWIDGET textarea, int *begin, int *end);
+UI_IMPORT int __stdcall UItextarea_length(UIWIDGET textarea);
+UI_IMPORT void __stdcall UItextarea_remove(UIWIDGET textarea, int begin, int end);
+
+UI_IMPORT void __stdcall UIfreestr(char *str);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* TEXT_H */
+

mercurial