List DefaultItems (windows).

This commit is contained in:
Nuno Cruces 2022-12-05 11:16:59 +00:00
parent 7d3236562f
commit 589e1b5b01
3 changed files with 13 additions and 2 deletions

View File

@ -52,6 +52,8 @@ const (
WM_USER = 0x0400
EM_SETSEL = 0x00b1
LB_ADDSTRING = 0x0180
LB_SETSEL = 0x0185
LB_SETCURSEL = 0x0186
LB_GETCURSEL = 0x0188
LB_GETSELCOUNT = 0x0190
LB_GETSELITEMS = 0x0191

View File

@ -52,7 +52,7 @@ const (
radioListKind
)
// DefaultItems returns an Option to set the items to initially select (macOS only).
// DefaultItems returns an Option to set the items to initially select (Windows and macOS only).
func DefaultItems(items ...string) Option {
return funcOption(func(o *options) { o.defaultItems = items })
}

View File

@ -107,8 +107,17 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
12, 206, 75, 24, dlg.wnd, win.IDNO, instance, nil)
}
for _, item := range dlg.items {
for i, item := range dlg.items {
win.SendMessagePointer(dlg.listCtl, win.LB_ADDSTRING, 0, unsafe.Pointer(strptr(item)))
for _, def := range opts.defaultItems {
if def == item {
if dlg.multiple {
win.SendMessage(dlg.listCtl, win.LB_SETSEL, 1, uintptr(i))
} else {
win.SendMessage(dlg.listCtl, win.LB_SETCURSEL, uintptr(i), 0)
}
}
}
}
dlg.layout(getDPI(dlg.wnd))