Added Listboxes. You can't use the results just yet...
This commit is contained in:
parent
61d7f285ac
commit
88646445b0
|
@ -287,91 +287,89 @@ const (
|
|||
_EIMES_COMPLETECOMPSTRKILLFOCUS = 0x0004
|
||||
)
|
||||
|
||||
/*
|
||||
// Listbox styles.
|
||||
const (
|
||||
// from winuser.h
|
||||
LBS_NOTIFY = 0x0001
|
||||
LBS_SORT = 0x0002
|
||||
LBS_NOREDRAW = 0x0004
|
||||
LBS_MULTIPLESEL = 0x0008
|
||||
LBS_OWNERDRAWFIXED = 0x0010
|
||||
LBS_OWNERDRAWVARIABLE = 0x0020
|
||||
LBS_HASSTRINGS = 0x0040
|
||||
LBS_USETABSTOPS = 0x0080
|
||||
LBS_NOINTEGRALHEIGHT = 0x0100
|
||||
LBS_MULTICOLUMN = 0x0200
|
||||
LBS_WANTKEYBOARDINPUT = 0x0400
|
||||
LBS_EXTENDEDSEL = 0x0800
|
||||
LBS_DISABLENOSCROLL = 0x1000
|
||||
LBS_NODATA = 0x2000
|
||||
LBS_NOSEL = 0x4000
|
||||
LBS_COMBOBOX = 0x8000
|
||||
LBS_STANDARD = (LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER)
|
||||
_LBS_NOTIFY = 0x0001
|
||||
_LBS_SORT = 0x0002
|
||||
_LBS_NOREDRAW = 0x0004
|
||||
_LBS_MULTIPLESEL = 0x0008
|
||||
_LBS_OWNERDRAWFIXED = 0x0010
|
||||
_LBS_OWNERDRAWVARIABLE = 0x0020
|
||||
_LBS_HASSTRINGS = 0x0040
|
||||
_LBS_USETABSTOPS = 0x0080
|
||||
_LBS_NOINTEGRALHEIGHT = 0x0100
|
||||
_LBS_MULTICOLUMN = 0x0200
|
||||
_LBS_WANTKEYBOARDINPUT = 0x0400
|
||||
_LBS_EXTENDEDSEL = 0x0800
|
||||
_LBS_DISABLENOSCROLL = 0x1000
|
||||
_LBS_NODATA = 0x2000
|
||||
_LBS_NOSEL = 0x4000
|
||||
_LBS_COMBOBOX = 0x8000
|
||||
_LBS_STANDARD = (_LBS_NOTIFY | _LBS_SORT | _WS_VSCROLL | _WS_BORDER)
|
||||
)
|
||||
|
||||
// Listbox messages.
|
||||
// TODO filter out messages not provided in windows 2000
|
||||
const (
|
||||
// from winuser.h
|
||||
LB_ADDSTRING = 0x0180
|
||||
LB_INSERTSTRING = 0x0181
|
||||
LB_DELETESTRING = 0x0182
|
||||
LB_SELITEMRANGEEX = 0x0183
|
||||
LB_RESETCONTENT = 0x0184
|
||||
LB_SETSEL = 0x0185
|
||||
LB_SETCURSEL = 0x0186
|
||||
LB_GETSEL = 0x0187
|
||||
LB_GETCURSEL = 0x0188
|
||||
LB_GETTEXT = 0x0189
|
||||
LB_GETTEXTLEN = 0x018A
|
||||
LB_GETCOUNT = 0x018B
|
||||
LB_SELECTSTRING = 0x018C
|
||||
LB_DIR = 0x018D
|
||||
LB_GETTOPINDEX = 0x018E
|
||||
LB_FINDSTRING = 0x018F
|
||||
LB_GETSELCOUNT = 0x0190
|
||||
LB_GETSELITEMS = 0x0191
|
||||
LB_SETTABSTOPS = 0x0192
|
||||
LB_GETHORIZONTALEXTENT = 0x0193
|
||||
LB_SETHORIZONTALEXTENT = 0x0194
|
||||
LB_SETCOLUMNWIDTH = 0x0195
|
||||
LB_ADDFILE = 0x0196
|
||||
LB_SETTOPINDEX = 0x0197
|
||||
LB_GETITEMRECT = 0x0198
|
||||
LB_GETITEMDATA = 0x0199
|
||||
LB_SETITEMDATA = 0x019A
|
||||
LB_SELITEMRANGE = 0x019B
|
||||
LB_SETANCHORINDEX = 0x019C
|
||||
LB_GETANCHORINDEX = 0x019D
|
||||
LB_SETCARETINDEX = 0x019E
|
||||
LB_GETCARETINDEX = 0x019F
|
||||
LB_SETITEMHEIGHT = 0x01A0
|
||||
LB_GETITEMHEIGHT = 0x01A1
|
||||
LB_FINDSTRINGEXACT = 0x01A2
|
||||
LB_SETLOCALE = 0x01A5
|
||||
LB_GETLOCALE = 0x01A6
|
||||
LB_SETCOUNT = 0x01A7
|
||||
LB_INITSTORAGE = 0x01A8
|
||||
LB_ITEMFROMPOINT = 0x01A9
|
||||
LB_MULTIPLEADDSTRING = 0x01B1
|
||||
LB_GETLISTBOXINFO = 0x01B2
|
||||
_LB_ADDSTRING = 0x0180
|
||||
_LB_INSERTSTRING = 0x0181
|
||||
_LB_DELETESTRING = 0x0182
|
||||
_LB_SELITEMRANGEEX = 0x0183
|
||||
_LB_RESETCONTENT = 0x0184
|
||||
_LB_SETSEL = 0x0185
|
||||
_LB_SETCURSEL = 0x0186
|
||||
_LB_GETSEL = 0x0187
|
||||
_LB_GETCURSEL = 0x0188
|
||||
_LB_GETTEXT = 0x0189
|
||||
_LB_GETTEXTLEN = 0x018A
|
||||
_LB_GETCOUNT = 0x018B
|
||||
_LB_SELECTSTRING = 0x018C
|
||||
_LB_DIR = 0x018D
|
||||
_LB_GETTOPINDEX = 0x018E
|
||||
_LB_FINDSTRING = 0x018F
|
||||
_LB_GETSELCOUNT = 0x0190
|
||||
_LB_GETSELITEMS = 0x0191
|
||||
_LB_SETTABSTOPS = 0x0192
|
||||
_LB_GETHORIZONTALEXTENT = 0x0193
|
||||
_LB_SETHORIZONTALEXTENT = 0x0194
|
||||
_LB_SETCOLUMNWIDTH = 0x0195
|
||||
_LB_ADDFILE = 0x0196
|
||||
_LB_SETTOPINDEX = 0x0197
|
||||
_LB_GETITEMRECT = 0x0198
|
||||
_LB_GETITEMDATA = 0x0199
|
||||
_LB_SETITEMDATA = 0x019A
|
||||
_LB_SELITEMRANGE = 0x019B
|
||||
_LB_SETANCHORINDEX = 0x019C
|
||||
_LB_GETANCHORINDEX = 0x019D
|
||||
_LB_SETCARETINDEX = 0x019E
|
||||
_LB_GETCARETINDEX = 0x019F
|
||||
_LB_SETITEMHEIGHT = 0x01A0
|
||||
_LB_GETITEMHEIGHT = 0x01A1
|
||||
_LB_FINDSTRINGEXACT = 0x01A2
|
||||
_LB_SETLOCALE = 0x01A5
|
||||
_LB_GETLOCALE = 0x01A6
|
||||
_LB_SETCOUNT = 0x01A7
|
||||
_LB_INITSTORAGE = 0x01A8
|
||||
_LB_ITEMFROMPOINT = 0x01A9
|
||||
_LB_MULTIPLEADDSTRING = 0x01B1
|
||||
_LB_GETLISTBOXINFO = 0x01B2
|
||||
)
|
||||
|
||||
// Listbox WM_COMMAND notifications and message returns.
|
||||
// TODO filter out notifications not provided in windows 2000
|
||||
const (
|
||||
// from winuser.h
|
||||
LB_OKAY = 0
|
||||
LB_ERR = (-1) // TODO this will blow up the Go compiler if it's used
|
||||
LBN_ERRSPACE = (-2) // TODO this will blow up the Go compiler if it's used
|
||||
LBN_SELCHANGE = 1
|
||||
LBN_DBLCLK = 2
|
||||
LBN_SELCANCEL = 3
|
||||
LBN_SETFOCUS = 4
|
||||
LBN_KILLFOCUS = 5
|
||||
_LB_OKAY = 0
|
||||
_LB_ERR = (-1) // TODO this will blow up the Go compiler if it's used
|
||||
_LBN_ERRSPACE = (-2) // TODO this will blow up the Go compiler if it's used
|
||||
_LBN_SELCHANGE = 1
|
||||
_LBN_DBLCLK = 2
|
||||
_LBN_SELCANCEL = 3
|
||||
_LBN_SETFOCUS = 4
|
||||
_LBN_KILLFOCUS = 5
|
||||
)
|
||||
*/
|
||||
|
||||
// Static control styles.
|
||||
const (
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
// 14 february 2014
|
||||
//package ui
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Listbox is a vertical list of items, of which one or (optionally) more items can be selected at any given time.
|
||||
type Listbox struct {
|
||||
// TODO Select event
|
||||
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initItems []string
|
||||
}
|
||||
|
||||
// NewCombobox makes a new combobox with the given items. If multiple is true, the listbox allows multiple selection.
|
||||
func NewListbox(multiple bool, items ...string) (l *Listbox) {
|
||||
l = &Listbox{
|
||||
sysData: mksysdata(c_listbox),
|
||||
initItems: items,
|
||||
}
|
||||
l.sysData.alternate = multiple
|
||||
return l
|
||||
}
|
||||
|
||||
// TODO Append, InsertBefore, Delete
|
||||
|
||||
// TODO Selection
|
||||
|
||||
// TODO SelectedIndices
|
||||
|
||||
func (l *Listbox) make(window *sysData) (err error) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
err = l.sysData.make("", 300, 300, window)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, s := range l.initItems {
|
||||
err = l.sysData.append(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Listbox) setRect(x int, y int, width int, height int) error {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
return l.sysData.setRect(x, y, width, height)
|
||||
}
|
4
main.go
4
main.go
|
@ -14,7 +14,9 @@ func main() {
|
|||
cb2 := NewCombobox(false, "You can't edit me!", "No you can't!", "No you won't!")
|
||||
e := NewLineEdit("Enter text here too")
|
||||
l := NewLabel("This is a label")
|
||||
s := NewStack(Vertical, b, c, cb1, cb2, e, l)
|
||||
s0 := NewStack(Vertical, b, c, cb1, cb2, e, l)
|
||||
lb := NewListbox(true, "Select One", "Or More", "To Continue")
|
||||
s := NewStack(Horizontal, lb, s0)
|
||||
err := w.Open(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -37,6 +37,7 @@ func (c *cSysData) append(string) error {
|
|||
panic(runtime.GOOS + " sysData does not define append()")
|
||||
}
|
||||
// TODO insertAfter
|
||||
// TODO selectedIndex, selectedIndices, selectedTexts
|
||||
|
||||
const (
|
||||
c_window = iota
|
||||
|
@ -45,6 +46,7 @@ const (
|
|||
c_combobox
|
||||
c_lineedit
|
||||
c_label
|
||||
c_listbox
|
||||
nctypes
|
||||
)
|
||||
|
||||
|
|
|
@ -66,6 +66,15 @@ var classTypes = [nctypes]*classData{
|
|||
style: _SS_NOPREFIX | controlstyle,
|
||||
xstyle: 0 | controlxstyle,
|
||||
},
|
||||
c_listbox: &classData{
|
||||
name: "LISTBOX",
|
||||
style: 0 | controlstyle,
|
||||
xstyle: 0 | controlxstyle,
|
||||
altStyle: _LBS_EXTENDEDSEL | controlstyle,
|
||||
appendMsg: _LB_ADDSTRING,
|
||||
insertAfterMsg: _LB_INSERTSTRING,
|
||||
deleteMsg: _LB_DELETESTRING,
|
||||
},
|
||||
}
|
||||
|
||||
func (s *sysData) addChild(child *sysData) _HMENU {
|
||||
|
|
Loading…
Reference in New Issue