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)

78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 using System;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 using System.Collections.Generic;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 using System.Linq;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 using System.Text;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 using System.Threading;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 using System.Threading.Tasks;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 using System.Windows;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 using System.Windows.Controls;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 namespace UI
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 {
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
12 public class MainWindow : Window, Container
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
13 {
85
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
14 public Layout Layout
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
15 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
16 get
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
17 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
18 return Container.Layout;
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
19 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
20 set
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
21 {
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
22 Container.Layout = value;
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
23 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
24 }
91f45354d1e2 added ui_layout_fill (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
25
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
26 public IntPtr Object;
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
27 public Container Container;
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
28
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
29 public MainWindow(String title, IntPtr uiobj)
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 {
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 Title = title;
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
32 Object = uiobj;
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 Width = 300;
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 Height = 300;
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
35
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
36 Grid windowGrid = new Grid();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
37 ColumnDefinition column = new ColumnDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
38 column.Width = new GridLength(1, GridUnitType.Star);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
39 windowGrid.ColumnDefinitions.Add(column);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
40 this.AddChild(windowGrid);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
41 int rowIndex = 0;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
42
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
43 // menu
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
44 Application app = Application.GetInstance();
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
45 if (!app.AppMenu.IsEmpty() && false)
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
46 {
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
47 System.Windows.Controls.Menu menu = app.AppMenu.CreateMenu(uiobj);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
48
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
49 RowDefinition menuRow = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
50 menuRow.Height = GridLength.Auto;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
51 windowGrid.RowDefinitions.Add(menuRow);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
52
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
53 Grid.SetRow(menu, 0);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
54 Grid.SetColumn(menu, rowIndex);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
55 windowGrid.Children.Add(menu);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
56 rowIndex++;
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
57 }
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
58
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
59 // TODO: toolbar
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
60
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
61 // content
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
62 RowDefinition contentRow = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
63 contentRow.Height = new GridLength(1, GridUnitType.Star);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
64 windowGrid.RowDefinitions.Add(contentRow);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
65 BoxContainer vbox = new BoxContainer(BoxOrientation.VERTICAL);
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
66 Grid.SetColumn(vbox, 0);
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
67 Grid.SetRow(vbox, rowIndex);
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
68 windowGrid.Children.Add(vbox);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
69 rowIndex++;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
70
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
71 Container = vbox;
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
72
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
73 Closed += CloseEvent;
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 }
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
76 public static MainWindow CreateMainWindow(String title, IntPtr uiobj)
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 {
82
0cdb8089a29f added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
78 return Application.GetInstance().Exec<MainWindow>(() => new MainWindow(title, uiobj));
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 public void ShowWindow()
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 {
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 Application.GetInstance().Exec(() => this.Show());
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
84 Application.GetInstance().AddWindow(this);
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
85 }
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
86
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
87 public void CloseEvent(object sender, System.EventArgs e)
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
88 {
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
89 Application.GetInstance().RemoveWindow(this);
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
91
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
92 public void Add(UIElement control, bool fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
93 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
94 Container.Add(control, fill);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
95 }
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }

mercurial