diff options
| author | Pietro Gagliardi <[email protected]> | 2014-10-18 17:03:07 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-10-18 17:03:07 -0400 |
| commit | 62048303a34f6cac733798651adb53b640e2114a (patch) | |
| tree | b03994dfe1d5cfbc94be65075f3345a45166bbef /button_windows.go | |
| parent | 8c8b642adbed274133b6e9d975c7ca8786300d2c (diff) | |
Merged new container/sizing stuff.
Diffstat (limited to 'button_windows.go')
| -rw-r--r-- | button_windows.go | 48 |
1 files changed, 10 insertions, 38 deletions
diff --git a/button_windows.go b/button_windows.go index 38e43d5..ff5a251 100644 --- a/button_windows.go +++ b/button_windows.go @@ -10,8 +10,7 @@ import ( import "C" type button struct { - _hwnd C.HWND - _textlen C.LONG + *controlSingleHWNDWithText clicked *event } @@ -22,12 +21,13 @@ func newButton(text string) *button { C.BS_PUSHBUTTON|C.WS_TABSTOP, 0) b := &button{ - _hwnd: hwnd, + controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd), clicked: newEvent(), } + b.fpreferredSize = b.xpreferredSize b.SetText(text) - C.controlSetControlFont(b._hwnd) - C.setButtonSubclass(b._hwnd, unsafe.Pointer(b)) + C.controlSetControlFont(b.hwnd) + C.setButtonSubclass(b.hwnd, unsafe.Pointer(b)) return b } @@ -36,11 +36,11 @@ func (b *button) OnClicked(e func()) { } func (b *button) Text() string { - return baseText(b) + return b.text() } func (b *button) SetText(text string) { - baseSetText(b, text) + b.setText(text) } //export buttonClicked @@ -49,51 +49,23 @@ func buttonClicked(data unsafe.Pointer) { b.clicked.fire() } -func (b *button) hwnd() C.HWND { - return b._hwnd -} - -func (b *button) textlen() C.LONG { - return b._textlen -} - -func (b *button) settextlen(len C.LONG) { - b._textlen = len -} - -func (b *button) setParent(p *controlParent) { - basesetParent(b, p) -} - -func (b *button) allocate(x int, y int, width int, height int, d *sizing) []*allocation { - return baseallocate(b, x, y, width, height, d) -} - const ( // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing buttonHeight = 14 ) -func (b *button) preferredSize(d *sizing) (width, height int) { +func (b *button) xpreferredSize(d *sizing) (width, height int) { // comctl32.dll version 6 thankfully provides a method to grab this... var size C.SIZE size.cx = 0 // explicitly ask for ideal size size.cy = 0 - if C.SendMessageW(b._hwnd, C.BCM_GETIDEALSIZE, 0, C.LPARAM(uintptr(unsafe.Pointer(&size)))) != C.FALSE { + if C.SendMessageW(b.hwnd, C.BCM_GETIDEALSIZE, 0, C.LPARAM(uintptr(unsafe.Pointer(&size)))) != C.FALSE { return int(size.cx), int(size.cy) } // that failed, fall back println("message failed; falling back") // don't worry about the error return from GetSystemMetrics(); there's no way to tell (explicitly documented as such) xmargins := 2 * int(C.GetSystemMetrics(C.SM_CXEDGE)) - return xmargins + int(b._textlen), fromdlgunitsY(buttonHeight, d) -} - -func (b *button) commitResize(a *allocation, d *sizing) { - basecommitResize(b, a, d) -} - -func (b *button) getAuxResizeInfo(d *sizing) { - basegetAuxResizeInfo(b, d) + return xmargins + int(b.textlen), fromdlgunitsY(buttonHeight, d) } |
