Permalink
Browse files

Use SendMessage method instead of func where possible.

  • Loading branch information...
1 parent 6571c22 commit 367f3b2da6a6b783d15384ba807be430caf1a6d1 @lxn committed Sep 16, 2012
Showing with 191 additions and 192 deletions.
  1. +2 −2 button.go
  2. +7 −7 combobox.go
  3. +4 −4 dateedit.go
  4. +1 −1 dialog.go
  5. +101 −101 examples/logview/logview.go
  6. +9 −9 lineedit.go
  7. +5 −5 listbox.go
  8. +2 −2 mainwindow.go
  9. +5 −5 progressbar.go
  10. +1 −1 pushbutton.go
  11. +30 −30 tableview.go
  12. +3 −3 textedit.go
  13. +11 −12 toolbar.go
  14. +3 −3 tooltip.go
  15. +3 −3 toplevelwindow.go
  16. +2 −2 treeview.go
  17. +2 −2 widget.go
View
@@ -32,7 +32,7 @@ func (b *Button) SetText(value string) error {
}
func (b *Button) Checked() bool {
- return SendMessage(b.hWnd, BM_GETCHECK, 0, 0) == BST_CHECKED
+ return b.SendMessage(BM_GETCHECK, 0, 0) == BST_CHECKED
}
func (b *Button) SetChecked(value bool) {
@@ -44,7 +44,7 @@ func (b *Button) SetChecked(value bool) {
chk = BST_UNCHECKED
}
- SendMessage(b.hWnd, BM_SETCHECK, chk, 0)
+ b.SendMessage(BM_SETCHECK, chk, 0)
}
func (b *Button) Clicked() *Event {
View
@@ -85,7 +85,7 @@ func (cb *ComboBox) insertItemAt(index int) error {
str := cb.itemString(index)
lp := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
- if CB_ERR == SendMessage(cb.hWnd, CB_INSERTSTRING, uintptr(index), lp) {
+ if CB_ERR == cb.SendMessage(CB_INSERTSTRING, uintptr(index), lp) {
return newError("SendMessage(CB_INSERTSTRING)")
}
@@ -96,7 +96,7 @@ func (cb *ComboBox) resetItems() error {
cb.SetSuspended(true)
defer cb.SetSuspended(false)
- if FALSE == SendMessage(cb.hWnd, CB_RESETCONTENT, 0, 0) {
+ if FALSE == cb.SendMessage(CB_RESETCONTENT, 0, 0) {
return newError("SendMessage(CB_RESETCONTENT)")
}
@@ -126,7 +126,7 @@ func (cb *ComboBox) attachModel() {
cb.itemsResetHandlerHandle = cb.model.ItemsReset().Attach(itemsResetHandler)
itemChangedHandler := func(index int) {
- if CB_ERR == SendMessage(cb.hWnd, CB_DELETESTRING, uintptr(index), 0) {
+ if CB_ERR == cb.SendMessage(CB_DELETESTRING, uintptr(index), 0) {
newError("SendMessage(CB_DELETESTRING)")
}
@@ -206,11 +206,11 @@ func (cb *ComboBox) calculateMaxItemTextWidth() int {
}
func (cb *ComboBox) CurrentIndex() int {
- return int(SendMessage(cb.hWnd, CB_GETCURSEL, 0, 0))
+ return int(cb.SendMessage(CB_GETCURSEL, 0, 0))
}
func (cb *ComboBox) SetCurrentIndex(value int) error {
- index := int(SendMessage(cb.hWnd, CB_SETCURSEL, uintptr(value), 0))
+ index := int(cb.SendMessage(CB_SETCURSEL, uintptr(value), 0))
if index != value {
return newError("invalid index")
@@ -237,12 +237,12 @@ func (cb *ComboBox) SetText(value string) error {
}
func (cb *ComboBox) TextSelection() (start, end int) {
- SendMessage(cb.hWnd, CB_GETEDITSEL, uintptr(unsafe.Pointer(&start)), uintptr(unsafe.Pointer(&end)))
+ cb.SendMessage(CB_GETEDITSEL, uintptr(unsafe.Pointer(&start)), uintptr(unsafe.Pointer(&end)))
return
}
func (cb *ComboBox) SetTextSelection(start, end int) {
- SendMessage(cb.hWnd, CB_SETEDITSEL, 0, uintptr(MAKELONG(uint16(start), uint16(end))))
+ cb.SendMessage(CB_SETEDITSEL, 0, uintptr(MAKELONG(uint16(start), uint16(end))))
}
func (cb *ComboBox) WndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
View
@@ -66,7 +66,7 @@ func (de *DateEdit) SizeHint() Size {
func (de *DateEdit) systemTime() (*SYSTEMTIME, error) {
var st SYSTEMTIME
- switch SendMessage(de.hWnd, DTM_GETSYSTEMTIME, 0, uintptr(unsafe.Pointer(&st))) {
+ switch de.SendMessage(DTM_GETSYSTEMTIME, 0, uintptr(unsafe.Pointer(&st))) {
case GDT_VALID:
return &st, nil
@@ -86,7 +86,7 @@ func (de *DateEdit) setSystemTime(st *SYSTEMTIME) error {
wParam = GDT_NONE
}
- if 0 == SendMessage(de.hWnd, DTM_SETSYSTEMTIME, wParam, uintptr(unsafe.Pointer(st))) {
+ if 0 == de.SendMessage(DTM_SETSYSTEMTIME, wParam, uintptr(unsafe.Pointer(st))) {
return newError("SendMessage(DTM_SETSYSTEMTIME)")
}
@@ -98,7 +98,7 @@ func (de *DateEdit) setSystemTime(st *SYSTEMTIME) error {
func (de *DateEdit) Range() (min, max time.Time) {
var st [2]SYSTEMTIME
- ret := SendMessage(de.hWnd, DTM_GETRANGE, 0, uintptr(unsafe.Pointer(&st[0])))
+ ret := de.SendMessage(DTM_GETRANGE, 0, uintptr(unsafe.Pointer(&st[0])))
if ret&GDTR_MIN > 0 {
min = systemTimeToTime(&st[0])
@@ -133,7 +133,7 @@ func (de *DateEdit) SetRange(min, max time.Time) error {
st[1] = *timeToSystemTime(max)
}
- if 0 == SendMessage(de.hWnd, DTM_SETRANGE, wParam, uintptr(unsafe.Pointer(&st[0]))) {
+ if 0 == de.SendMessage(DTM_SETRANGE, wParam, uintptr(unsafe.Pointer(&st[0]))) {
return newError("SendMessage(DTM_SETRANGE)")
}
View
@@ -66,7 +66,7 @@ func NewDialog(owner RootWidget) (*Dialog, error) {
dlg.children = newWidgetList(dlg)
// This forces display of focus rectangles, as soon as the user starts to type.
- SendMessage(dlg.hWnd, WM_CHANGEUISTATE, UIS_INITIALIZE, 0)
+ dlg.SendMessage(WM_CHANGEUISTATE, UIS_INITIALIZE, 0)
dlg.result = DlgCmdClose
@@ -1,105 +1,105 @@
// Copyright 2012 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 main
-
+package main
+
+import (
+ "errors"
+ "syscall"
+ "unsafe"
+)
+
import (
- "errors"
- "unsafe"
- "syscall"
-)
-
-import . "github.com/lxn/go-winapi"
-import (
- "github.com/lxn/walk"
-)
-
-type LogView struct {
- walk.WidgetBase
- logChan chan string
-}
-
-const (
- TEM_APPENDTEXT = WM_USER + 6
-)
-
-func NewLogView(parent walk.Container) (*LogView, error) {
- lc := make(chan string, 1024)
- te := &LogView{logChan:lc}
-
- if err := walk.InitChildWidget(
- te,
- parent,
- "EDIT",
- WS_TABSTOP|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_WANTRETURN,
- WS_EX_CLIENTEDGE); err != nil {
- return nil, err
- }
- te.setReadOnly(true)
- SendMessage(te.Handle(), EM_SETLIMITTEXT, 4294967295, 0)
- return te, nil
-}
-
-func (*LogView) LayoutFlags() walk.LayoutFlags {
- return walk.ShrinkableHorz | walk.ShrinkableVert | walk.GrowableHorz | walk.GrowableVert | walk.GreedyHorz | walk.GreedyVert
-}
-
-func (te *LogView) MinSizeHint() walk.Size {
- return walk.Size{20, 12}
-}
-
-func (te *LogView) SizeHint() walk.Size {
- return walk.Size{100, 100}
-}
-
-func (te *LogView) setTextSelection(start, end int) {
- SendMessage(te.Handle(), EM_SETSEL, uintptr(start), uintptr(end))
-}
-
-func (te *LogView) textLength() int{
- return int(SendMessage(te.Handle(), 0x000E, uintptr(0), uintptr(0)))
-}
-
-func (te *LogView) AppendText(value string) {
- textLength := te.textLength()
- te.setTextSelection(textLength, textLength)
- SendMessage(te.Handle(), EM_REPLACESEL, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))))
-}
-
-func (te *LogView) setReadOnly(readOnly bool) error {
- if 0 == SendMessage(te.Handle(), EM_SETREADONLY, uintptr(BoolToBOOL(readOnly)), 0) {
- return errors.New("fail to call EM_SETREADONLY")
- }
-
- return nil
-}
-
-func (te *LogView) PostAppendText(value string){
- te.logChan <- value
- PostMessage(te.Handle(), TEM_APPENDTEXT, 0, 0)
-}
-
-func (te *LogView) Write(p []byte)(int, error){
- te.PostAppendText(string(p) + "\r\n")
- return len(p), nil
-}
-
-func (te *LogView) WndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
- switch msg {
- case WM_GETDLGCODE:
- if wParam == VK_RETURN {
- return DLGC_WANTALLKEYS
- }
-
- return DLGC_HASSETSEL | DLGC_WANTARROWS | DLGC_WANTCHARS
- case TEM_APPENDTEXT:
- select {
- case value := <- te.logChan:
- te.AppendText(value)
- default:
- return 0
- }
- }
-
- return te.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
-}
+ . "github.com/lxn/go-winapi"
+ "github.com/lxn/walk"
+)
+
+type LogView struct {
+ walk.WidgetBase
+ logChan chan string
+}
+
+const (
+ TEM_APPENDTEXT = WM_USER + 6
+)
+
+func NewLogView(parent walk.Container) (*LogView, error) {
+ lc := make(chan string, 1024)
+ lv := &LogView{logChan: lc}
+
+ if err := walk.InitChildWidget(
+ lv,
+ parent,
+ "EDIT",
+ WS_TABSTOP|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_WANTRETURN,
+ WS_EX_CLIENTEDGE); err != nil {
+ return nil, err
+ }
+ lv.setReadOnly(true)
+ lv.SendMessage(EM_SETLIMITTEXT, 4294967295, 0)
+ return lv, nil
+}
+
+func (*LogView) LayoutFlags() walk.LayoutFlags {
+ return walk.ShrinkableHorz | walk.ShrinkableVert | walk.GrowableHorz | walk.GrowableVert | walk.GreedyHorz | walk.GreedyVert
+}
+
+func (*LogView) MinSizeHint() walk.Size {
+ return walk.Size{20, 12}
+}
+
+func (*LogView) SizeHint() walk.Size {
+ return walk.Size{100, 100}
+}
+
+func (lv *LogView) setTextSelection(start, end int) {
+ lv.SendMessage(EM_SETSEL, uintptr(start), uintptr(end))
+}
+
+func (lv *LogView) textLength() int {
+ return int(lv.SendMessage(0x000E, uintptr(0), uintptr(0)))
+}
+
+func (lv *LogView) AppendText(value string) {
+ textLength := lv.textLength()
+ lv.setTextSelection(textLength, textLength)
+ lv.SendMessage(EM_REPLACESEL, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))))
+}
+
+func (lv *LogView) setReadOnly(readOnly bool) error {
+ if 0 == lv.SendMessage(EM_SETREADONLY, uintptr(BoolToBOOL(readOnly)), 0) {
+ return errors.New("fail to call EM_SETREADONLY")
+ }
+
+ return nil
+}
+
+func (lv *LogView) PostAppendText(value string) {
+ lv.logChan <- value
+ PostMessage(lv.Handle(), TEM_APPENDTEXT, 0, 0)
+}
+
+func (lv *LogView) Write(p []byte) (int, error) {
+ lv.PostAppendText(string(p) + "\r\n")
+ return len(p), nil
+}
+
+func (lv *LogView) WndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
+ switch msg {
+ case WM_GETDLGCODE:
+ if wParam == VK_RETURN {
+ return DLGC_WANTALLKEYS
+ }
+
+ return DLGC_HASSETSEL | DLGC_WANTARROWS | DLGC_WANTCHARS
+ case TEM_APPENDTEXT:
+ select {
+ case value := <-lv.logChan:
+ lv.AppendText(value)
+ default:
+ return 0
+ }
+ }
+
+ return lv.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
+}
View
@@ -63,7 +63,7 @@ func NewLineEdit(parent Container) (*LineEdit, error) {
func (le *LineEdit) CueBanner() string {
buf := make([]uint16, 128)
- if FALSE == SendMessage(le.hWnd, EM_GETCUEBANNER, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf))) {
+ if FALSE == le.SendMessage(EM_GETCUEBANNER, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf))) {
newError("EM_GETCUEBANNER failed")
return ""
}
@@ -72,19 +72,19 @@ func (le *LineEdit) CueBanner() string {
}
func (le *LineEdit) SetCueBanner(value string) error {
- if FALSE == SendMessage(le.hWnd, EM_SETCUEBANNER, FALSE, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value)))) {
+ if FALSE == le.SendMessage(EM_SETCUEBANNER, FALSE, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value)))) {
return newError("EM_SETCUEBANNER failed")
}
return nil
}
func (le *LineEdit) MaxLength() int {
- return int(SendMessage(le.hWnd, EM_GETLIMITTEXT, 0, 0))
+ return int(le.SendMessage(EM_GETLIMITTEXT, 0, 0))
}
func (le *LineEdit) SetMaxLength(value int) {
- SendMessage(le.hWnd, EM_LIMITTEXT, uintptr(value), 0)
+ le.SendMessage(EM_LIMITTEXT, uintptr(value), 0)
}
func (le *LineEdit) Text() string {
@@ -96,28 +96,28 @@ func (le *LineEdit) SetText(value string) error {
}
func (le *LineEdit) TextSelection() (start, end int) {
- SendMessage(le.hWnd, EM_GETSEL, uintptr(unsafe.Pointer(&start)), uintptr(unsafe.Pointer(&end)))
+ le.SendMessage(EM_GETSEL, uintptr(unsafe.Pointer(&start)), uintptr(unsafe.Pointer(&end)))
return
}
func (le *LineEdit) SetTextSelection(start, end int) {
- SendMessage(le.hWnd, EM_SETSEL, uintptr(start), uintptr(end))
+ le.SendMessage(EM_SETSEL, uintptr(start), uintptr(end))
}
func (le *LineEdit) PasswordMode() bool {
- return SendMessage(le.hWnd, EM_GETPASSWORDCHAR, 0, 0) != 0
+ return le.SendMessage(EM_GETPASSWORDCHAR, 0, 0) != 0
}
func (le *LineEdit) SetPasswordMode(value bool) {
- SendMessage(le.hWnd, EM_SETPASSWORDCHAR, uintptr('*'), 0)
+ le.SendMessage(EM_SETPASSWORDCHAR, uintptr('*'), 0)
}
func (le *LineEdit) ReadOnly() bool {
return le.hasStyleBits(ES_READONLY)
}
func (le *LineEdit) SetReadOnly(readOnly bool) error {
- if 0 == SendMessage(le.hWnd, EM_SETREADONLY, uintptr(BoolToBOOL(readOnly)), 0) {
+ if 0 == le.SendMessage(EM_SETREADONLY, uintptr(BoolToBOOL(readOnly)), 0) {
return newError("SendMessage(EM_SETREADONLY)")
}
Oops, something went wrong. Retry.

0 comments on commit 367f3b2

Please sign in to comment.