# HG changeset patch # User Olaf Wintermann # Date 1424011464 -3600 # Node ID 9a7e4a335b2b91716eb6f48b5a8f3e6ed01fc4e7 # Parent 04c81be1c5a02b4de0000a5ab2dd93c7ad9d4ace added toolbar (WPF) diff -r 04c81be1c5a0 -r 9a7e4a335b2b application/main.c --- 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); diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIcore/Application.cs --- 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 Windows = new List(); - public ApplicationMenu AppMenu = new ApplicationMenu(); + public ApplicationMenu Menu = new ApplicationMenu(); + public MainToolBar ToolBar = new MainToolBar(); private Application() : base() { diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIcore/MainToolBar.cs --- /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 Items = new Dictionary(); + List Defaults = new List(); + + 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 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 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); + } + } +} diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIcore/UIcore.csproj --- 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 @@ + diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIcore/Window.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(); diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIwrapper/UIwrapper.v12.suo Binary file ui/wpf/UIwrapper/UIwrapper.v12.suo has changed diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIwrapper/UIwrapper/UIwrapper.vcxproj --- 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 @@ + @@ -164,6 +165,7 @@ + Create diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIwrapper/UIwrapper/UIwrapper.vcxproj.filters --- 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 @@ Headerdateien + + Headerdateien + @@ -59,6 +62,9 @@ Quelldateien + + Quelldateien + diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIwrapper/UIwrapper/menu.cpp --- 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()); } diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIwrapper/UIwrapper/toolbar.cpp --- /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 + +#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)); +} + diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/UIwrapper/UIwrapper/toolbar.h --- /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" diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/menu.c --- 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; diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/menu.h --- 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 } diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/objs.mk --- 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 diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/toolbar.c --- /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 +#include + +#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); +} + + diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/toolbar.h --- /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 */ + diff -r 04c81be1c5a0 -r 9a7e4a335b2b ui/wpf/toolkit.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);