summaryrefslogtreecommitdiffstatshomepage
path: root/lineedit.go
diff options
context:
space:
mode:
authorAlexander Neumann <an2048@gmail.com>2012-10-30 15:06:10 +0100
committerAlexander Neumann <an2048@gmail.com>2012-10-30 15:06:10 +0100
commit6920b4874faffbda25bbc7ab11fdcdd03640e958 (patch)
tree10066452accb7ed5c237b5157d3b6d633cc80812 /lineedit.go
parentBegin replacing previous data binding system with a new one based on properties (diff)
downloadwireguard-windows-6920b4874faffbda25bbc7ab11fdcdd03640e958.tar.xz
wireguard-windows-6920b4874faffbda25bbc7ab11fdcdd03640e958.zip
Add some properties to many widgets
Diffstat (limited to 'lineedit.go')
-rw-r--r--lineedit.go40
1 files changed, 34 insertions, 6 deletions
diff --git a/lineedit.go b/lineedit.go
index 991683a0..53753382 100644
--- a/lineedit.go
+++ b/lineedit.go
@@ -22,13 +22,15 @@ type LineEdit struct {
validator Validator
editingFinishedPublisher EventPublisher
returnPressedPublisher EventPublisher
- textChangedPublisher EventPublisher
- charWidthFont *Font
- charWidth int
+ // textChangedPublisher EventPublisher
+ textProperty *Property
+ readOnlyProperty *Property
+ charWidthFont *Font
+ charWidth int
}
func newLineEdit(parent Widget) (*LineEdit, error) {
- le := &LineEdit{}
+ le := new(LineEdit)
if err := InitWidget(
le,
@@ -39,6 +41,28 @@ func newLineEdit(parent Widget) (*LineEdit, error) {
return nil, err
}
+ le.textProperty = NewProperty(
+ "Text",
+ func() interface{} {
+ return le.Text()
+ },
+ func(v interface{}) error {
+ return le.SetText(v.(string))
+ },
+ nil)
+
+ le.readOnlyProperty = NewProperty(
+ "ReadOnly",
+ func() interface{} {
+ return le.ReadOnly()
+ },
+ func(v interface{}) error {
+ return le.SetReadOnly(v.(bool))
+ },
+ nil)
+
+ le.MustRegisterProperties(le.textProperty, le.readOnlyProperty)
+
return le, nil
}
@@ -129,6 +153,10 @@ func (le *LineEdit) SetText(value string) error {
return setWidgetText(le.hWnd, value)
}
+func (le *LineEdit) TextProperty() *Property {
+ return le.textProperty
+}
+
func (le *LineEdit) TextSelection() (start, end int) {
le.SendMessage(EM_GETSEL, uintptr(unsafe.Pointer(&start)), uintptr(unsafe.Pointer(&end)))
return
@@ -235,7 +263,7 @@ func (le *LineEdit) ReturnPressed() *Event {
}
func (le *LineEdit) TextChanged() *Event {
- return le.textChangedPublisher.Event()
+ return le.textProperty.Changed()
}
func (le *LineEdit) WndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
@@ -255,7 +283,7 @@ func (le *LineEdit) WndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintp
case WM_COMMAND:
switch HIWORD(uint32(wParam)) {
case EN_CHANGE:
- le.textChangedPublisher.Publish()
+ le.textProperty.changedEventPublisher.Publish()
}
case WM_GETDLGCODE: