1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading;
6 using System.Threading.Tasks;
7 using System.Windows;
8 using System.Windows.Controls;
9
10 namespace UI
11 {
12 public class MainWindow : Window, Container
13 {
14 public Layout Layout
15 {
16 get
17 {
18 return Container.Layout;
19 }
20 set
21 {
22 Container.Layout = value;
23 }
24 }
25
26 public IntPtr Object;
27 public Container Container;
28
29 public MainWindow(String title, IntPtr uiobj)
30 {
31 Title = title;
32 Object = uiobj;
33 Width = 300;
34 Height = 300;
35
36 Grid windowGrid = new Grid();
37 ColumnDefinition column = new ColumnDefinition();
38 column.Width = new GridLength(1, GridUnitType.Star);
39 windowGrid.ColumnDefinitions.Add(column);
40 this.AddChild(windowGrid);
41 int rowIndex = 0;
42
43 // menu
44 Application app = Application.GetInstance();
45 System.Windows.Controls.Menu menu = null;
46 if (!app.Menu.IsEmpty())
47 {
48 menu = app.Menu.CreateMenu(uiobj);
49
50 RowDefinition menuRow = new RowDefinition();
51 menuRow.Height = GridLength.Auto;
52 windowGrid.RowDefinitions.Add(menuRow);
53
54 Grid.SetRow(menu, rowIndex);
55 Grid.SetColumn(menu, 0);
56 windowGrid.Children.Add(menu);
57 rowIndex++;
58 }
59
60 // toolbar
61 if(app.ToolBar.HasItems())
62 {
63 System.Windows.Controls.ToolBarTray tray = app.ToolBar.CreateToolBarTray(uiobj);
64 RowDefinition menuRow = new RowDefinition();
65 menuRow.Height = GridLength.Auto;
66 windowGrid.RowDefinitions.Add(menuRow);
67
68 Grid.SetRow(tray, rowIndex);
69 Grid.SetColumn(tray, 0);
70 windowGrid.Children.Add(tray);
71 rowIndex++;
72
73 if(menu != null)
74 {
75 menu.Background = tray.Background;
76 }
77 }
78
79 // content
80 RowDefinition contentRow = new RowDefinition();
81 contentRow.Height = new GridLength(1, GridUnitType.Star);
82 windowGrid.RowDefinitions.Add(contentRow);
83 BoxContainer vbox = new BoxContainer(BoxOrientation.VERTICAL, 0, 0);
84 Grid.SetColumn(vbox, 0);
85 Grid.SetRow(vbox, rowIndex);
86 windowGrid.Children.Add(vbox);
87 rowIndex++;
88
89 Container = vbox;
90
91 Closed += CloseEvent;
92 }
93
94 public void ShowWindow()
95 {
96 this.Show();
97 Application.GetInstance().AddWindow(this);
98 }
99
100 public void CloseEvent(object sender, System.EventArgs e)
101 {
102 Application.GetInstance().RemoveWindow(this);
103 }
104
105 public void Add(UIElement control, bool fill)
106 {
107 Container.Add(control, fill);
108 }
109 }
110 }
111