-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.go
167 lines (124 loc) · 3.5 KB
/
mainwindow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package walk
import . "github.com/lxn/go-winapi"
const mainWindowWindowClass = `\o/ Walk_MainWindow_Class \o/`
func init() {
MustRegisterWindowClass(mainWindowWindowClass)
}
type MainWindow struct {
TopLevelWindow
menu *Menu
toolBar *ToolBar
clientComposite *Composite
}
func NewMainWindow() (*MainWindow, error) {
mw := &MainWindow{}
if err := InitWidget(
mw,
nil,
mainWindowWindowClass,
WS_OVERLAPPEDWINDOW,
WS_EX_CONTROLPARENT); err != nil {
return nil, err
}
succeeded := false
defer func() {
if !succeeded {
mw.Dispose()
}
}()
mw.SetPersistent(true)
var err error
if mw.menu, err = newMenuBar(); err != nil {
return nil, err
}
SetMenu(mw.hWnd, mw.menu.hMenu)
if mw.toolBar, err = NewToolBar(mw); err != nil {
return nil, err
}
if mw.clientComposite, err = NewComposite(mw); err != nil {
return nil, err
}
mw.clientComposite.SetName("clientComposite")
mw.clientComposite.children.observer = mw
// This forces display of focus rectangles, as soon as the user starts to type.
mw.SendMessage(WM_CHANGEUISTATE, UIS_INITIALIZE, 0)
succeeded = true
return mw, nil
}
func (mw *MainWindow) Children() *WidgetList {
if mw.clientComposite == nil {
return nil
}
return mw.clientComposite.Children()
}
func (mw *MainWindow) Layout() Layout {
if mw.clientComposite == nil {
return nil
}
return mw.clientComposite.Layout()
}
func (mw *MainWindow) SetLayout(value Layout) error {
if mw.clientComposite == nil {
return newError("clientComposite not initialized")
}
return mw.clientComposite.SetLayout(value)
}
func (mw *MainWindow) Menu() *Menu {
return mw.menu
}
func (mw *MainWindow) ToolBar() *ToolBar {
return mw.toolBar
}
func (mw *MainWindow) ClientBounds() Rectangle {
bounds := mw.WidgetBase.ClientBounds()
if mw.toolBar.Actions().Len() > 0 {
tlbBounds := mw.toolBar.Bounds()
bounds.Y += tlbBounds.Height
bounds.Height -= tlbBounds.Height
}
return bounds
}
func (mw *MainWindow) Show() {
DrawMenuBar(mw.hWnd)
if mw.clientComposite.layout != nil {
mw.clientComposite.layout.Update(false)
}
mw.TopLevelWindow.Show()
}
func (mw *MainWindow) onInsertingWidget(index int, widget Widget) error {
return mw.clientComposite.onInsertingWidget(index, widget)
}
func (mw *MainWindow) onInsertedWidget(index int, widget Widget) error {
err := mw.clientComposite.onInsertedWidget(index, widget)
if err == nil {
minClientSize := mw.Layout().MinSize()
clientSize := mw.clientComposite.Size()
if clientSize.Width < minClientSize.Width || clientSize.Height < minClientSize.Height {
mw.SetClientSize(minClientSize)
}
}
return err
}
func (mw *MainWindow) onRemovingWidget(index int, widget Widget) error {
return mw.clientComposite.onRemovingWidget(index, widget)
}
func (mw *MainWindow) onRemovedWidget(index int, widget Widget) error {
return mw.clientComposite.onRemovedWidget(index, widget)
}
func (mw *MainWindow) onClearingWidgets() error {
return mw.clientComposite.onClearingWidgets()
}
func (mw *MainWindow) onClearedWidgets() error {
return mw.clientComposite.onClearedWidgets()
}
func (mw *MainWindow) WndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case WM_SIZE, WM_SIZING:
mw.toolBar.SendMessage(TB_AUTOSIZE, 0, 0)
mw.clientComposite.SetBounds(mw.ClientBounds())
}
return mw.TopLevelWindow.WndProc(hwnd, msg, wParam, lParam)
}