diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go index 14bcdfc..989c80d 100644 --- a/gtkcalls_unix.go +++ b/gtkcalls_unix.go @@ -154,6 +154,12 @@ func gtk_entry_new() *gtkWidget { return fromgtkwidget(C.gtk_entry_new()) } +func gtkPasswordEntryNew() *gtkWidget { + e := gtk_entry_new() + C.gtk_entry_set_visibility(togtkentry(e), C.FALSE) + return e +} + func gtk_entry_set_text(widget *gtkWidget, text string) { ctext := C.CString(text) defer C.free(unsafe.Pointer(ctext)) diff --git a/lineedit.go b/lineedit.go index 61f1cf7..bcb28ac 100644 --- a/lineedit.go +++ b/lineedit.go @@ -9,10 +9,11 @@ import ( type LineEdit struct { // TODO Typing event - lock sync.Mutex - created bool - sysData *sysData - initText string + lock sync.Mutex + created bool + sysData *sysData + initText string + password bool } // NewLineEdit makes a new LineEdit with the specified text. @@ -23,6 +24,14 @@ func NewLineEdit(text string) *LineEdit { } } +// NewPasswordEdit makes a new LineEdit which allows the user to enter a password. +func NewPasswordEdit() *LineEdit { + return &LineEdit{ + sysData: mksysdata(c_lineedit), + password: true, + } +} + // SetText sets the LineEdit's text. func (l *LineEdit) SetText(text string) (err error) { l.lock.Lock() @@ -50,6 +59,7 @@ func (l *LineEdit) make(window *sysData) error { l.lock.Lock() defer l.lock.Unlock() + l.sysData.alternate = l.password err := l.sysData.make(l.initText, window) if err != nil { return err diff --git a/main_test.go b/main_test.go index c778d2a..4960dd3 100644 --- a/main_test.go +++ b/main_test.go @@ -26,7 +26,8 @@ func TestMain(t *testing.T) { incButton := NewButton("Inc") decButton := NewButton("Dec") sincdec := NewStack(Horizontal, incButton, decButton) - s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec) + password := NewPasswordEdit() + s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec, password) lb1 := NewListbox(true, "Select One", "Or More", "To Continue") lb2 := NewListbox(false, "Select", "Only", "One", "Please") i := 0 @@ -55,11 +56,12 @@ mainloop: case <-w.Closing: break mainloop case <-b.Clicked: - err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s", + err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s | %s", c.Checked(), cb1.Selection(), cb2.Selection(), - e.Text())) + e.Text(), + password.Text())) if err != nil { panic(err) } diff --git a/sysdata.go b/sysdata.go index 51f1d5e..f6a4455 100644 --- a/sysdata.go +++ b/sysdata.go @@ -17,7 +17,7 @@ type cSysData struct { ctype int event chan struct{} resize func(x int, y int, width int, height int) error - alternate bool // editable for Combobox, multi-select for listbox + alternate bool // editable for Combobox, multi-select for listbox, password for lineedit } func (c *cSysData) make(initText string, window *sysData) error { panic(runtime.GOOS + " sysData does not define make()") diff --git a/sysdata_unix.go b/sysdata_unix.go index e45ddec..0852362 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -86,6 +86,7 @@ var classTypes = [nctypes]*classData{ }, c_lineedit: &classData{ make: gtk_entry_new, + makeAlt: gtkPasswordEntryNew, setText: gtk_entry_set_text, text: gtk_entry_get_text, }, diff --git a/sysdata_windows.go b/sysdata_windows.go index 81a2d11..b541bee 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -70,6 +70,7 @@ var classTypes = [nctypes]*classData{ name: "EDIT", style: _ES_AUTOHSCROLL | _WS_BORDER | controlstyle, xstyle: 0 | controlxstyle, + altStyle: _ES_PASSWORD | _ES_AUTOHSCROLL | _WS_BORDER | controlstyle, font: &controlFont, }, c_label: &classData{ diff --git a/todo.md b/todo.md index 05c0a18..5e19768 100644 --- a/todo.md +++ b/todo.md @@ -5,8 +5,9 @@ so I don't forget: - determine if a selection in a non-editable combobox has been made - see if we really need to track errors on Combobox.Selection() - in fact, see if we really need to track errors on a lot of things... -- password entry fields, character-limited entry fields, numeric entry fields, multiline entry fields +- character-limited entry fields, numeric entry fields, multiline entry fields - possible rename of LineEdit? + - especially for password fields - NewPasswordEntry()? - more flexible size appropriation: allow a small button to be at the top of everything in the main() example here - [Windows] should ListBox have a border style? - a different border on LineEdits?