-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.go
121 lines (89 loc) · 2.4 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
// 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/`
var mainWindowWindowClassRegistered bool
type MainWindow struct {
TopLevelWindow
menu *Menu
toolBar *ToolBar
clientComposite *Composite
}
func NewMainWindow() (*MainWindow, error) {
ensureRegisteredWindowClass(mainWindowWindowClass, &mainWindowWindowClassRegistered)
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")
// This forces display of focus rectangles, as soon as the user starts to type.
SendMessage(mw.hWnd, 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) wndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case WM_SIZE, WM_SIZING:
SendMessage(mw.toolBar.hWnd, TB_AUTOSIZE, 0, 0)
mw.clientComposite.SetBounds(mw.ClientBounds())
}
return mw.TopLevelWindow.wndProc(hwnd, msg, wParam, lParam)
}