diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-03 09:18:35 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-03 09:18:35 -0400 |
| commit | 1aea308645585f2fbc6c8b170381c811d562cc99 (patch) | |
| tree | 1db721a972133a1ed0d9808eafabfbed66f6892f /redo/checkbox_windows.go | |
| parent | 585f5f5b62da3170d4398b39670d16811013d078 (diff) | |
Set up the Control restructure and migrated the Windows implementation over. Lots of repetition, but hopefully more correct and maintainable!
Diffstat (limited to 'redo/checkbox_windows.go')
| -rw-r--r-- | redo/checkbox_windows.go | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/redo/checkbox_windows.go b/redo/checkbox_windows.go index 633f8e7..2dcf519 100644 --- a/redo/checkbox_windows.go +++ b/redo/checkbox_windows.go @@ -10,20 +10,38 @@ import ( import "C" type checkbox struct { - *button + *controlbase + toggled *event } func newCheckbox(text string) *checkbox { + // don't use BS_AUTOCHECKBOX here because it creates problems when refocusing (see http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx) + // we'll handle actually toggling the check state ourselves (see controls_windows.c) + cc := newControl(buttonclass, + C.BS_CHECKBOX | C.WS_TABSTOP, + 0) + cc.setText(text) + C.controlSetControlFont(cc.hwnd) c := &checkbox{ - // don't use BS_AUTOCHECKBOX here because it creates problems when refocusing (see http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx) - // we'll handle actually toggling the check state ourselves (see controls_windows.c) - button: startNewButton(text, C.BS_CHECKBOX), + controlbase: cc, + toggled: newEvent(), } - c.fpreferredSize = c.checkboxpreferredSize C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c)) return c } +func (c *checkbox) OnToggled(e func()) { + c.toggled.set(e) +} + +func (c *checkbox) Text() string { + return c.text() +} + +func (c *checkbox) SetText(text string) { + c.setText(text) +} + func (c *checkbox) Checked() bool { if C.checkboxChecked(c.hwnd) == C.FALSE { return false @@ -42,10 +60,26 @@ func (c *checkbox) SetChecked(checked bool) { //export checkboxToggled func checkboxToggled(data unsafe.Pointer) { c := (*checkbox)(data) - c.clicked.fire() + c.toggled.fire() println("checkbox toggled") } +func (c *checkbox) setParent(p *controlParent) { + basesetParent(c.controlbase, p) +} + +func (c *checkbox) containerShow() { + basecontainerShow(c.controlbase) +} + +func (c *checkbox) containerHide() { + basecontainerHide(c.controlbase) +} + +func (c *checkbox) allocate(x int, y int, width int, height int, d *sizing) []*allocation { + return baseallocate(c, x, y, width, height, d) +} + const ( // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing checkboxHeight = 10 @@ -53,7 +87,15 @@ const ( checkboxXFromLeftOfBoxToLeftOfLabel = 12 ) -func (c *checkbox) checkboxpreferredSize(d *sizing) (width, height int) { +func (c *checkbox) preferredSize(d *sizing) (width, height int) { return fromdlgunitsX(checkboxXFromLeftOfBoxToLeftOfLabel, d) + int(c.textlen), fromdlgunitsY(checkboxHeight, d) } + +func (c *checkbox) commitResize(a *allocation, d *sizing) { + basecommitResize(c.controlbase, a, d) +} + +func (c *checkbox) getAuxResizeInfo(d *sizing) { + basegetAuxResizeInfo(d) +} |
