github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/windows/winc/edit.go (about) 1 //go:build windows 2 3 /* 4 * Copyright (C) 2019 The Winc Authors. All Rights Reserved. 5 * Copyright (C) 2010-2013 Allen Dang. All Rights Reserved. 6 */ 7 8 package winc 9 10 import "github.com/secoba/wails/v2/internal/frontend/desktop/windows/winc/w32" 11 12 type Edit struct { 13 ControlBase 14 onChange EventManager 15 } 16 17 const passwordChar = '*' 18 const nopasswordChar = ' ' 19 20 func NewEdit(parent Controller) *Edit { 21 edt := new(Edit) 22 23 edt.InitControl("EDIT", parent, w32.WS_EX_CLIENTEDGE, w32.WS_CHILD|w32.WS_VISIBLE|w32.WS_TABSTOP|w32.ES_LEFT| 24 w32.ES_AUTOHSCROLL) 25 RegMsgHandler(edt) 26 27 edt.SetFont(DefaultFont) 28 edt.SetSize(200, 22) 29 return edt 30 } 31 32 // Events. 33 func (ed *Edit) OnChange() *EventManager { 34 return &ed.onChange 35 } 36 37 // Public methods. 38 func (ed *Edit) SetReadOnly(isReadOnly bool) { 39 w32.SendMessage(ed.hwnd, w32.EM_SETREADONLY, uintptr(w32.BoolToBOOL(isReadOnly)), 0) 40 } 41 42 // Public methods 43 func (ed *Edit) SetPassword(isPassword bool) { 44 if isPassword { 45 w32.SendMessage(ed.hwnd, w32.EM_SETPASSWORDCHAR, uintptr(passwordChar), 0) 46 } else { 47 w32.SendMessage(ed.hwnd, w32.EM_SETPASSWORDCHAR, 0, 0) 48 } 49 } 50 51 func (ed *Edit) WndProc(msg uint32, wparam, lparam uintptr) uintptr { 52 switch msg { 53 case w32.WM_COMMAND: 54 switch w32.HIWORD(uint32(wparam)) { 55 case w32.EN_CHANGE: 56 ed.onChange.Fire(NewEvent(ed, nil)) 57 } 58 /*case w32.WM_GETDLGCODE: 59 println("Edit") 60 if wparam == w32.VK_RETURN { 61 return w32.DLGC_WANTALLKEYS 62 }*/ 63 } 64 return w32.DefWindowProc(ed.hwnd, msg, wparam, lparam) 65 } 66 67 // MultiEdit is multiline text edit. 68 type MultiEdit struct { 69 ControlBase 70 onChange EventManager 71 } 72 73 func NewMultiEdit(parent Controller) *MultiEdit { 74 med := new(MultiEdit) 75 76 med.InitControl("EDIT", parent, w32.WS_EX_CLIENTEDGE, w32.WS_CHILD|w32.WS_VISIBLE|w32.WS_TABSTOP|w32.ES_LEFT| 77 w32.WS_VSCROLL|w32.WS_HSCROLL|w32.ES_MULTILINE|w32.ES_WANTRETURN|w32.ES_AUTOHSCROLL|w32.ES_AUTOVSCROLL) 78 RegMsgHandler(med) 79 80 med.SetFont(DefaultFont) 81 med.SetSize(200, 400) 82 return med 83 } 84 85 // Events 86 func (med *MultiEdit) OnChange() *EventManager { 87 return &med.onChange 88 } 89 90 // Public methods 91 func (med *MultiEdit) SetReadOnly(isReadOnly bool) { 92 w32.SendMessage(med.hwnd, w32.EM_SETREADONLY, uintptr(w32.BoolToBOOL(isReadOnly)), 0) 93 } 94 95 func (med *MultiEdit) AddLine(text string) { 96 if len(med.Text()) == 0 { 97 med.SetText(text) 98 } else { 99 med.SetText(med.Text() + "\r\n" + text) 100 } 101 } 102 103 func (med *MultiEdit) WndProc(msg uint32, wparam, lparam uintptr) uintptr { 104 switch msg { 105 106 case w32.WM_COMMAND: 107 switch w32.HIWORD(uint32(wparam)) { 108 case w32.EN_CHANGE: 109 med.onChange.Fire(NewEvent(med, nil)) 110 } 111 } 112 return w32.DefWindowProc(med.hwnd, msg, wparam, lparam) 113 }