ui/wpf/UIcore/Window.cs

Thu, 15 Feb 2024 21:33:08 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 15 Feb 2024 21:33:08 +0100
branch
newapi
changeset 262
81778b9589d0
parent 138
d781436e2490
permissions
-rw-r--r--

port progressbar to new API (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();
137
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
45 System.Windows.Controls.Menu menu = null;
89
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
46 if (!app.Menu.IsEmpty())
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
47 {
137
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
48 menu = app.Menu.CreateMenu(uiobj);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
49
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
50 RowDefinition menuRow = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
51 menuRow.Height = GridLength.Auto;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
52 windowGrid.RowDefinitions.Add(menuRow);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
53
89
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
54 Grid.SetRow(menu, rowIndex);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
55 Grid.SetColumn(menu, 0);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
56 windowGrid.Children.Add(menu);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
57 rowIndex++;
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
58 }
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
59
89
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
60 // toolbar
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
61 if(app.ToolBar.HasItems())
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
62 {
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
63 System.Windows.Controls.ToolBarTray tray = app.ToolBar.CreateToolBarTray(uiobj);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
64 RowDefinition menuRow = new RowDefinition();
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
65 menuRow.Height = GridLength.Auto;
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
66 windowGrid.RowDefinitions.Add(menuRow);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
67
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
68 Grid.SetRow(tray, rowIndex);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
69 Grid.SetColumn(tray, 0);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
70 windowGrid.Children.Add(tray);
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
71 rowIndex++;
137
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
72
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
73 if(menu != null)
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
74 {
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
75 menu.Background = tray.Background;
c9b8b9e0cfe8 adds drawingarea (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
76 }
89
9a7e4a335b2b added toolbar (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
77 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
78
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
79 // content
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
80 RowDefinition contentRow = new RowDefinition();
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
81 contentRow.Height = new GridLength(1, GridUnitType.Star);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
82 windowGrid.RowDefinitions.Add(contentRow);
138
d781436e2490 adds scrolledwindow and tabview container (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 137
diff changeset
83 BoxContainer vbox = new BoxContainer(BoxOrientation.VERTICAL, 0, 0);
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
84 Grid.SetColumn(vbox, 0);
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
85 Grid.SetRow(vbox, rowIndex);
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
86 windowGrid.Children.Add(vbox);
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
87 rowIndex++;
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
88
84
a56c2baa9429 added vbox,hbox function (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
89 Container = vbox;
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
90
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
91 Closed += CloseEvent;
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 public void ShowWindow()
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 {
135
b9dc9cdfa23a refactors architecture (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 89
diff changeset
96 this.Show();
81
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
97 Application.GetInstance().AddWindow(this);
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
98 }
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
99
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
100 public void CloseEvent(object sender, System.EventArgs e)
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
101 {
5eb765a7a793 added menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
102 Application.GetInstance().RemoveWindow(this);
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 }
83
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
104
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
105 public void Add(UIElement control, bool fill)
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
106 {
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
107 Container.Add(control, fill);
a38aec91bd66 added box layout and button (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 82
diff changeset
108 }
78
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 }
135920fe441b added initial WPF code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }

mercurial