ui/wpf/UIcore/Window.cs

Mon, 23 Jan 2017 10:50:22 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 23 Jan 2017 10:50:22 +0100
changeset 137
c9b8b9e0cfe8
parent 135
b9dc9cdfa23a
child 138
d781436e2490
permissions
-rw-r--r--

adds drawingarea (WPF)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace UI
{
    public class MainWindow : Window, Container
    {
        public Layout Layout
        {
            get
            {
                return Container.Layout;
            }
            set
            {
                Container.Layout = value;
            }
        }
        
        public IntPtr Object;
        public Container Container;
        
        public MainWindow(String title, IntPtr uiobj)
        {
            Title = title;
            Object = uiobj;
            Width = 300;
            Height = 300;

            Grid windowGrid = new Grid();
            ColumnDefinition column = new ColumnDefinition();
            column.Width = new GridLength(1, GridUnitType.Star);
            windowGrid.ColumnDefinitions.Add(column);
            this.AddChild(windowGrid);
            int rowIndex = 0;

            // menu
            Application app = Application.GetInstance();
            System.Windows.Controls.Menu menu = null;
            if (!app.Menu.IsEmpty())
            {
                menu = app.Menu.CreateMenu(uiobj);

                RowDefinition menuRow = new RowDefinition();
                menuRow.Height = GridLength.Auto;
                windowGrid.RowDefinitions.Add(menuRow);

                Grid.SetRow(menu, rowIndex);
                Grid.SetColumn(menu, 0);
                windowGrid.Children.Add(menu);
                rowIndex++;
            }

            // 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++;

                if(menu != null)
                {
                    menu.Background = tray.Background;
                }
            }

            // content
            RowDefinition contentRow = new RowDefinition();
            contentRow.Height = new GridLength(1, GridUnitType.Star);
            windowGrid.RowDefinitions.Add(contentRow);
            BoxContainer vbox = new BoxContainer(BoxOrientation.VERTICAL);
            Grid.SetColumn(vbox, 0);
            Grid.SetRow(vbox, rowIndex);
            windowGrid.Children.Add(vbox);
            rowIndex++;

            Container = vbox;

            Closed += CloseEvent;
        }

        public void ShowWindow()
        {
            this.Show();
            Application.GetInstance().AddWindow(this);
        }

        public void CloseEvent(object sender, System.EventArgs e)
        {
            Application.GetInstance().RemoveWindow(this);
        }

        public void Add(UIElement control, bool fill)
        {
            Container.Add(control, fill);
        }
    }
}

mercurial