ui/wpf/UIcore/Window.cs

Wed, 11 Feb 2015 11:34:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 11 Feb 2015 11:34:55 +0100
changeset 86
3c63f57a8f77
parent 85
91f45354d1e2
child 88
04c81be1c5a0
permissions
-rw-r--r--

added toolbar combobox (GTK)

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();
            if (!app.AppMenu.IsEmpty() && false)
            {
                System.Windows.Controls.Menu menu = app.AppMenu.CreateMenu(uiobj);

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

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

            // TODO: toolbar

            // 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 static MainWindow CreateMainWindow(String title, IntPtr uiobj)
        {
            return Application.GetInstance().Exec<MainWindow>(() => new MainWindow(title, uiobj));
        }

        public void ShowWindow()
        {
            Application.GetInstance().Exec(() => 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