Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 06c8b6c89a
Fetching contributors…

Cannot retrieve contributors at this time

144 lines (111 sloc) 3.12 kb
// Copyright 2010 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 walk
import (
"syscall"
"unsafe"
)
import (
. "github.com/lxn/go-winapi"
)
type TextEdit struct {
WidgetBase
bindingMember string
textChangedPublisher EventPublisher
}
func NewTextEdit(parent Container) (*TextEdit, error) {
te := &TextEdit{}
if err := InitChildWidget(
te,
parent,
"EDIT",
WS_TABSTOP|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_WANTRETURN,
WS_EX_CLIENTEDGE); err != nil {
return nil, err
}
return te, nil
}
func (*TextEdit) LayoutFlags() LayoutFlags {
return ShrinkableHorz | ShrinkableVert | GrowableHorz | GrowableVert | GreedyHorz | GreedyVert
}
func (te *TextEdit) MinSizeHint() Size {
return te.dialogBaseUnitsToPixels(Size{20, 12})
}
func (te *TextEdit) SizeHint() Size {
return Size{100, 100}
}
func (te *TextEdit) BindingMember() string {
return te.bindingMember
}
func (te *TextEdit) SetBindingMember(member string) error {
if err := validateBindingMemberSyntax(member); err != nil {
return err
}
te.bindingMember = member
return nil
}
func (te *TextEdit) BindingValue() interface{} {
return te.Text()
}
func (te *TextEdit) SetBindingValue(value interface{}) error {
return te.SetText(value.(string))
}
func (te *TextEdit) BindingValueChanged() *Event {
return te.TextChanged()
}
func (te *TextEdit) Text() string {
return widgetText(te.hWnd)
}
func (te *TextEdit) TextLength() int {
return int(SendMessage(te.hWnd, WM_GETTEXTLENGTH, 0, 0))
}
func (te *TextEdit) SetText(value string) error {
return setWidgetText(te.hWnd, value)
}
func (te *TextEdit) TextSelection() (start, end int) {
te.SendMessage(EM_GETSEL, uintptr(unsafe.Pointer(&start)), uintptr(unsafe.Pointer(&end)))
return
}
func (te *TextEdit) SetTextSelection(start, end int) {
te.SendMessage(EM_SETSEL, uintptr(start), uintptr(end))
}
func (te *TextEdit) ReplaceSelectedText(text string, canUndo bool) {
te.SendMessage(EM_REPLACESEL,
uintptr(BoolToBOOL(canUndo)),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))))
}
func (te *TextEdit) AppendText(value string) {
s, e := te.TextSelection()
l := te.TextLength()
te.SetTextSelection(l, l)
te.ReplaceSelectedText(value, false)
te.SetTextSelection(s, e)
}
func (te *TextEdit) ReadOnly() bool {
return te.hasStyleBits(ES_READONLY)
}
func (te *TextEdit) SetReadOnly(readOnly bool) error {
if 0 == te.SendMessage(EM_SETREADONLY, uintptr(BoolToBOOL(readOnly)), 0) {
return newError("SendMessage(EM_SETREADONLY)")
}
return nil
}
func (te *TextEdit) TextChanged() *Event {
return te.textChangedPublisher.Event()
}
func (te *TextEdit) WndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case WM_COMMAND:
switch HIWORD(uint32(wParam)) {
case EN_CHANGE:
te.textChangedPublisher.Publish()
}
case WM_GETDLGCODE:
if wParam == VK_RETURN {
return DLGC_WANTALLKEYS
}
return DLGC_HASSETSEL | DLGC_WANTARROWS | DLGC_WANTCHARS
}
return te.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
}
Jump to Line
Something went wrong with that request. Please try again.