2014-07-15 21:29:45 -05:00
|
|
|
// 15 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
2014-07-17 14:10:26 -05:00
|
|
|
"unsafe"
|
2014-07-15 21:29:45 -05:00
|
|
|
)
|
|
|
|
|
2014-07-17 21:16:32 -05:00
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
2014-07-15 21:29:45 -05:00
|
|
|
type widgetbase struct {
|
2014-07-17 21:16:32 -05:00
|
|
|
hwnd C.HWND
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
2014-07-17 23:22:21 -05:00
|
|
|
func newWidget(class C.LPCWSTR, style C.DWORD, extstyle C.DWORD) *widgetbase {
|
2014-07-15 21:29:45 -05:00
|
|
|
return &widgetbase{
|
2014-07-17 21:16:32 -05:00
|
|
|
hwnd: C.newWidget(class, style, extstyle),
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// these few methods are embedded by all the various Controls since they all will do the same thing
|
|
|
|
|
|
|
|
func (w *widgetbase) unparent() {
|
2014-07-17 21:16:32 -05:00
|
|
|
C.controlSetParent(w.hwnd, C.msgwin)
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetbase) parent(win *window) {
|
2014-07-17 21:16:32 -05:00
|
|
|
C.controlSetParent(w.hwnd, win.hwnd)
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't embed these as exported; let each Control decide if it should
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *widgetbase) text() string {
|
|
|
|
return getWindowText(w.hwnd)
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (w *widgetbase) settext(text string) {
|
|
|
|
C.setWindowText(w.hwnd, toUTF16(text))
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type button struct {
|
|
|
|
*widgetbase
|
2014-07-17 14:10:26 -05:00
|
|
|
clicked *event
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
2014-07-17 21:16:32 -05:00
|
|
|
var buttonclass = toUTF16("BUTTON")
|
2014-07-15 21:29:45 -05:00
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func newButton(text string) *button {
|
|
|
|
op: func() {
|
|
|
|
w := newWidget(buttonclass,
|
|
|
|
C.BS_PUSHBUTTON | C.WS_TABSTOP,
|
|
|
|
0)
|
|
|
|
C.setWindowText(w.hwnd, toUTF16(text))
|
|
|
|
C.controlSetControlFont(w.hwnd)
|
|
|
|
b := &button{
|
|
|
|
widgetbase: w,
|
|
|
|
clicked: newEvent(),
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
2014-07-19 08:44:32 -05:00
|
|
|
C.setButtonSubclass(w.hwnd, unsafe.Pointer(b))
|
|
|
|
return b
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (b *button) OnClicked(e func()) {
|
|
|
|
b.clicked.set(e)
|
2014-07-15 21:29:45 -05:00
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (b *button) Text() string {
|
2014-07-15 21:29:45 -05:00
|
|
|
return b.text()
|
|
|
|
}
|
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
func (b *button) SetText(text string) {
|
2014-07-15 21:29:45 -05:00
|
|
|
return b.settext(text)
|
|
|
|
}
|
2014-07-17 14:10:26 -05:00
|
|
|
|
2014-07-17 21:16:32 -05:00
|
|
|
//export buttonClicked
|
|
|
|
func buttonClicked(data unsafe.Pointer) {
|
|
|
|
b := (*button)(data)
|
|
|
|
b.clicked.fire()
|
|
|
|
println("button clicked")
|
2014-07-17 14:10:26 -05:00
|
|
|
}
|