-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushbutton.go
126 lines (96 loc) · 2.22 KB
/
pushbutton.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
// 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 (
"os"
"unsafe"
)
import . "walk/winapi"
var pushButtonOrigWndProcPtr uintptr
var _ subclassedWidget = &PushButton{}
type PushButton struct {
Button
}
func NewPushButton(parent Container) (*PushButton, os.Error) {
pb := &PushButton{}
if err := initChildWidget(
pb,
parent,
"BUTTON",
WS_TABSTOP|WS_VISIBLE|BS_PUSHBUTTON,
0); err != nil {
return nil, err
}
return pb, nil
}
func (*PushButton) origWndProcPtr() uintptr {
return pushButtonOrigWndProcPtr
}
func (*PushButton) setOrigWndProcPtr(ptr uintptr) {
pushButtonOrigWndProcPtr = ptr
}
func (*PushButton) LayoutFlags() LayoutFlags {
return GrowableHorz
}
func (pb *PushButton) SizeHint() Size {
var s Size
SendMessage(pb.hWnd, BCM_GETIDEALSIZE, 0, uintptr(unsafe.Pointer(&s)))
minSize := pb.dialogBaseUnitsToPixels(Size{50, 14})
s.Width = maxi(s.Width, minSize.Width)
s.Height = maxi(s.Height, minSize.Height)
return s
}
func (pb *PushButton) ensureProperDialogDefaultButton(hwndFocus HWND) {
widget := widgetFromHWND(hwndFocus)
if widget == nil {
return
}
if _, ok := widget.(*PushButton); ok {
return
}
root := rootWidget(pb)
if root == nil {
return
}
dlg, ok := root.(dialogish)
if !ok {
return
}
defBtn := dlg.DefaultButton()
if defBtn == nil {
return
}
if err := defBtn.setAndClearStyleBits(BS_DEFPUSHBUTTON, BS_PUSHBUTTON); err != nil {
return
}
if err := defBtn.Invalidate(); err != nil {
return
}
}
func (pb *PushButton) wndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case WM_GETDLGCODE:
hwndFocus := GetFocus()
if hwndFocus == pb.hWnd {
root := rootWidget(pb)
if root == nil {
break
}
dlg, ok := root.(dialogish)
if !ok {
break
}
defBtn := dlg.DefaultButton()
if defBtn == pb {
pb.setAndClearStyleBits(BS_DEFPUSHBUTTON, BS_PUSHBUTTON)
return DLGC_BUTTON | DLGC_DEFPUSHBUTTON
}
break
}
pb.ensureProperDialogDefaultButton(hwndFocus)
case WM_KILLFOCUS:
pb.ensureProperDialogDefaultButton(HWND(wParam))
}
return pb.Button.wndProc(hwnd, msg, wParam, lParam)
}