added toolbar (WPF)

Sun, 15 Feb 2015 15:44:24 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 15 Feb 2015 15:44:24 +0100
changeset 89
9a7e4a335b2b
parent 88
04c81be1c5a0
child 90
2019fdbaadfd

added toolbar (WPF)

application/main.c file | annotate | diff | comparison | revisions
ui/wpf/UIcore/Application.cs file | annotate | diff | comparison | revisions
ui/wpf/UIcore/MainToolBar.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/UIwrapper.vcxproj file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/UIwrapper.vcxproj.filters file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/menu.cpp file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/toolbar.cpp file | annotate | diff | comparison | revisions
ui/wpf/UIwrapper/UIwrapper/toolbar.h file | annotate | diff | comparison | revisions
ui/wpf/menu.c file | annotate | diff | comparison | revisions
ui/wpf/menu.h file | annotate | diff | comparison | revisions
ui/wpf/objs.mk file | annotate | diff | comparison | revisions
ui/wpf/toolbar.c file | annotate | diff | comparison | revisions
ui/wpf/toolbar.h file | annotate | diff | comparison | revisions
ui/wpf/toolkit.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sat Feb 14 13:26:00 2015 +0100
+++ b/application/main.c	Sun Feb 15 15:44:24 2015 +0100
@@ -117,6 +117,11 @@
     ui_submenu_end();
     ui_menuitem("item4", NULL, NULL);
     
+    ui_toolitem("button1", "Test", action_button, NULL);
+    ui_toolitem("button2", "OK", action_button, NULL);
+    ui_toolbar_add_default("button1");
+    ui_toolbar_add_default("button2");
+    
     UiObject *obj = ui_window("Test", NULL);
     ui_textarea_nv(obj, "text");
     ui_show(obj);
--- a/ui/wpf/UIcore/Application.cs	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/UIcore/Application.cs	Sun Feb 15 15:44:24 2015 +0100
@@ -22,7 +22,8 @@
 
         public String Name;
         public List<Window> Windows = new List<Window>();
-        public ApplicationMenu AppMenu = new ApplicationMenu();
+        public ApplicationMenu Menu = new ApplicationMenu();
+        public MainToolBar ToolBar = new MainToolBar();
         
         private Application() : base()
         {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/UIcore/MainToolBar.cs	Sun Feb 15 15:44:24 2015 +0100
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace UI
+{
+    public class MainToolBar
+    {
+        Dictionary<string, IToolItem> Items = new Dictionary<string, IToolItem>();
+        List<string> Defaults = new List<string>();
+
+        public MainToolBar()
+        {
+
+        }
+
+        public bool HasItems()
+        {
+            return Defaults.Count > 0 ? true : false;
+        }
+
+        public void AddDefault(string itemName)
+        {
+            Defaults.Add(itemName);
+        }
+
+        public void AddToolItem(string name, string label, Action<IntPtr> action)
+        {
+            ToolItem item = new ToolItem();
+            item.Label = label;
+            item.Action = action;
+            Items.Add(name, item);
+        }
+
+        public ToolBarTray CreateToolBarTray(IntPtr objptr)
+        {
+            ToolBarTray tray = new ToolBarTray();
+
+            ToolBar toolbar = new ToolBar();
+            tray.ToolBars.Add(toolbar);
+            foreach(string s in Defaults)
+            {
+                IToolItem item = Items[s];
+                item.AddTo(toolbar, objptr);
+            }
+
+            return tray;
+        }
+    }
+
+    public interface IToolItem
+    {
+        void AddTo(System.Windows.Controls.ToolBar toolbar, IntPtr uiobj);
+    }
+
+    public class ToolItem : IToolItem
+    {
+        public string Label { get; set; }
+        // TODO: icon
+        public Action<IntPtr> Action { get; set; }
+
+        public void AddTo(System.Windows.Controls.ToolBar toolbar, IntPtr uiobj)
+        {
+            Button button = new Button();
+            button.Content = Label;
+
+            EventCallback e = new EventCallback(uiobj, Action);
+            button.Click += e.Callback;
+
+            toolbar.Items.Add(button);
+        }
+    }
+}
--- a/ui/wpf/UIcore/UIcore.csproj	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/UIcore/UIcore.csproj	Sun Feb 15 15:44:24 2015 +0100
@@ -48,6 +48,7 @@
   <ItemGroup>
     <Compile Include="Container.cs" />
     <Compile Include="Controls.cs" />
+    <Compile Include="MainToolBar.cs" />
     <Compile Include="Menu.cs" />
     <Compile Include="TextArea.cs" />
     <Compile Include="Toolkit.cs" />
--- a/ui/wpf/UIcore/Window.cs	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/UIcore/Window.cs	Sun Feb 15 15:44:24 2015 +0100
@@ -42,21 +42,33 @@
 
             // menu
             Application app = Application.GetInstance();
-            if (!app.AppMenu.IsEmpty())
+            if (!app.Menu.IsEmpty())
             {
-                System.Windows.Controls.Menu menu = app.AppMenu.CreateMenu(uiobj);
+                System.Windows.Controls.Menu menu = app.Menu.CreateMenu(uiobj);
 
                 RowDefinition menuRow = new RowDefinition();
                 menuRow.Height = GridLength.Auto;
                 windowGrid.RowDefinitions.Add(menuRow);
 
-                Grid.SetRow(menu, 0);
-                Grid.SetColumn(menu, rowIndex);
+                Grid.SetRow(menu, rowIndex);
+                Grid.SetColumn(menu, 0);
                 windowGrid.Children.Add(menu);
                 rowIndex++;
             }
 
-            // TODO: toolbar
+            // toolbar
+            if(app.ToolBar.HasItems())
+            {
+                System.Windows.Controls.ToolBarTray tray = app.ToolBar.CreateToolBarTray(uiobj);
+                RowDefinition menuRow = new RowDefinition();
+                menuRow.Height = GridLength.Auto;
+                windowGrid.RowDefinitions.Add(menuRow);
+
+                Grid.SetRow(tray, rowIndex);
+                Grid.SetColumn(tray, 0);
+                windowGrid.Children.Add(tray);
+                rowIndex++;
+            }
 
             // content
             RowDefinition contentRow = new RowDefinition();
Binary file ui/wpf/UIwrapper/UIwrapper.v12.suo has changed
--- a/ui/wpf/UIwrapper/UIwrapper/UIwrapper.vcxproj	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/UIwrapper/UIwrapper/UIwrapper.vcxproj	Sun Feb 15 15:44:24 2015 +0100
@@ -156,6 +156,7 @@
     <ClInclude Include="menu.h" />
     <ClInclude Include="resource.h" />
     <ClInclude Include="Stdafx.h" />
+    <ClInclude Include="toolbar.h" />
     <ClInclude Include="toolkit.h" />
     <ClInclude Include="window.h" />
   </ItemGroup>
@@ -164,6 +165,7 @@
     <ClCompile Include="controls.cpp" />
     <ClCompile Include="menu.cpp" />
     <ClCompile Include="container.cpp" />
+    <ClCompile Include="toolbar.cpp" />
     <ClCompile Include="window.cpp" />
     <ClCompile Include="Stdafx.cpp">
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
--- a/ui/wpf/UIwrapper/UIwrapper/UIwrapper.vcxproj.filters	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/UIwrapper/UIwrapper/UIwrapper.vcxproj.filters	Sun Feb 15 15:44:24 2015 +0100
@@ -36,6 +36,9 @@
     <ClInclude Include="container.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="toolbar.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="AssemblyInfo.cpp">
@@ -59,6 +62,9 @@
     <ClCompile Include="container.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="toolbar.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Text Include="ReadMe.txt" />
--- a/ui/wpf/UIwrapper/UIwrapper/menu.cpp	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/UIwrapper/UIwrapper/menu.cpp	Sun Feb 15 15:44:24 2015 +0100
@@ -7,20 +7,20 @@
 #using "UIcore.dll"
 
 UI_EXPORT void __stdcall UImenu(char *label) {
-	UI::Application::GetInstance()->AppMenu->AddMenu(gcnew String(label));
+	UI::Application::GetInstance()->Menu->AddMenu(gcnew String(label));
 }
 
 UI_EXPORT void __stdcall UIsubmenu(char *label) {
-	UI::Application::GetInstance()->AppMenu->AddSubMenu(gcnew String(label));
+	UI::Application::GetInstance()->Menu->AddSubMenu(gcnew String(label));
 }
 
 UI_EXPORT void __stdcall UIsubmenu_end() {
-	UI::Application::GetInstance()->AppMenu->EndSubMenu();
+	UI::Application::GetInstance()->Menu->EndSubMenu();
 }
 
 
 UI_EXPORT void __stdcall UImenuitem(char *label, UIcallback f, void *eventdata) {
 	ObjEventWrapper ^e = gcnew ObjEventWrapper(f, eventdata);
-	UI::Application::GetInstance()->AppMenu->AddMenuItem(gcnew String(label), e->GetAction());
+	UI::Application::GetInstance()->Menu->AddMenuItem(gcnew String(label), e->GetAction());
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/UIwrapper/UIwrapper/toolbar.cpp	Sun Feb 15 15:44:24 2015 +0100
@@ -0,0 +1,49 @@
+/*
+* 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 "stdafx.h"
+#include <stdio.h>
+
+#include "toolbar.h"
+
+#using "UIcore.dll"
+
+UI_EXPORT void __stdcall UItoolitem(char *name, char *label, UIcallback f, void *eventdata) {
+	ObjEventWrapper ^e = gcnew ObjEventWrapper(f, eventdata);
+	UI::Application::GetInstance()->ToolBar->AddToolItem(gcnew String(name), gcnew String(label), e->GetAction());
+}
+
+
+
+
+
+UI_EXPORT void __stdcall UItoolbar_add_default(char *name) {
+	UI::Application::GetInstance()->ToolBar->AddDefault(gcnew String(name));
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/UIwrapper/UIwrapper/toolbar.h	Sun Feb 15 15:44:24 2015 +0100
@@ -0,0 +1,32 @@
+/*
+* 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.
+*/
+
+
+#pragma once
+
+#include "toolkit.h"
--- a/ui/wpf/menu.c	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/menu.c	Sun Feb 15 15:44:24 2015 +0100
@@ -45,7 +45,7 @@
 }
 
 void ui_menuitem(char *label, ui_callback f, void *userdata) {
-    ui_callback cb = NULL;
+    UIcallback cb = NULL;
     void *e = NULL;
     if (f) {
         UiEventData *event = malloc(sizeof(UiEventData));
@@ -53,7 +53,7 @@
         event->user_data = userdata;
         event->callback = f;
         event->value = 0;
-        cb = (ui_callback)ui_menu_callback;
+        cb = (UIcallback)ui_obj_callback;
         e = event;
     }
     
@@ -61,7 +61,7 @@
 }
 
 
-void ui_menu_callback(UiObject *obj, UiEventData *e) {
+void ui_obj_callback(UiObject *obj, UiEventData *e) {
     UiEvent event;
     event.obj = obj;
     event.window = obj->window;
--- a/ui/wpf/menu.h	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/menu.h	Sun Feb 15 15:44:24 2015 +0100
@@ -18,11 +18,11 @@
 UI_IMPORT void __stdcall UImenu(char *label);
 UI_IMPORT void __stdcall UIsubmenu(char *label);
 UI_IMPORT void __stdcall UIsubmenu_end();
-UI_IMPORT void __stdcall UImenuitem(char *label, ui_callback f, void *udata);
+UI_IMPORT void __stdcall UImenuitem(char *label, UIcallback f, void *udata);
 
 
 
-void ui_menu_callback(UiObject *obj, UiEventData *e);
+void ui_obj_callback(UiObject *obj, UiEventData *e);
 
 #ifdef	__cplusplus
 }
--- a/ui/wpf/objs.mk	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/objs.mk	Sun Feb 15 15:44:24 2015 +0100
@@ -33,6 +33,7 @@
 WPFOBJ += window.o
 WPFOBJ += container.o
 WPFOBJ += menu.o
+WPFOBJ += toolbar.o
 WPFOBJ += button.o
 WPFOBJ += text.o
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/toolbar.c	Sun Feb 15 15:44:24 2015 +0100
@@ -0,0 +1,56 @@
+/*
+ * 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 "toolbar.h"
+#include "menu.h"
+#include "../common/context.h"
+
+void ui_toolitem(char *name, char *label, ui_callback f, void *udata) {
+    UIcallback cb = NULL;
+    void *e = NULL;
+    if (f) {
+        UiEventData *event = malloc(sizeof(UiEventData));
+        event->obj = NULL;
+        event->user_data = udata;
+        event->callback = f;
+        event->value = 0;
+        cb = (UIcallback)ui_obj_callback;
+        e = event;
+    }
+    
+    UItoolitem(name, label, cb, e);
+}
+
+void ui_toolbar_add_default(char *name) {
+    UItoolbar_add_default(name);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/wpf/toolbar.h	Sun Feb 15 15:44:24 2015 +0100
@@ -0,0 +1,50 @@
+/*
+ * 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 TOOLBAR_H
+#define	TOOLBAR_H
+
+#include "../ui/toolbar.h"
+#include "toolkit.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+UI_IMPORT void __stdcall UItoolitem(char *name, char *label, UIcallback callback, void *eventdata);
+
+
+UI_IMPORT void __stdcall UItoolbar_add_default(char *name);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* TOOLBAR_H */
+
--- a/ui/wpf/toolkit.h	Sat Feb 14 13:26:00 2015 +0100
+++ b/ui/wpf/toolkit.h	Sun Feb 15 15:44:24 2015 +0100
@@ -48,6 +48,8 @@
     int         value;
 } UiEventData;
 
+typedef void(*UIcallback)(void*,void*);
+
 UI_IMPORT void __stdcall UIinit(char *appname);
 UI_IMPORT void __stdcall UImain();
 UI_IMPORT void __stdcall UIshow(UIWIDGET widget);

mercurial