Renames.
This commit is contained in:
parent
31912f59fa
commit
537e3cbab3
3 changed files with 129 additions and 126 deletions
113
entry_windows.go
113
entry_windows.go
|
@ -17,8 +17,8 @@ func entry(text string, opts options) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
defer setup()()
|
defer setup()()
|
||||||
wnd := &entryWnd{font: getFont()}
|
dlg := &entryDialog{font: getFont()}
|
||||||
defer wnd.font.delete()
|
defer dlg.font.delete()
|
||||||
|
|
||||||
if opts.ctx != nil && opts.ctx.Err() != nil {
|
if opts.ctx != nil && opts.ctx.Err() != nil {
|
||||||
return "", opts.ctx.Err()
|
return "", opts.ctx.Err()
|
||||||
|
@ -35,47 +35,47 @@ func entry(text string, opts options) (string, error) {
|
||||||
}
|
}
|
||||||
defer unregisterClass.Call(cls, instance)
|
defer unregisterClass.Call(cls, instance)
|
||||||
|
|
||||||
wnd.handle, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
|
dlg.wnd, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
|
||||||
cls, strptr(*opts.title),
|
cls, strptr(*opts.title),
|
||||||
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
|
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
|
||||||
0x80000000, // CW_USEDEFAULT
|
0x80000000, // CW_USEDEFAULT
|
||||||
0x80000000, // CW_USEDEFAULT
|
0x80000000, // CW_USEDEFAULT
|
||||||
281, 141, 0, 0, instance, uintptr(unsafe.Pointer(wnd)))
|
281, 141, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
|
||||||
|
|
||||||
wnd.textCtl, _, _ = createWindowEx.Call(0,
|
dlg.textCtl, _, _ = createWindowEx.Call(0,
|
||||||
strptr("STATIC"), strptr(text),
|
strptr("STATIC"), strptr(text),
|
||||||
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
|
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
|
||||||
12, 10, 241, 16, wnd.handle, 0, instance, 0)
|
12, 10, 241, 16, dlg.wnd, 0, instance, 0)
|
||||||
|
|
||||||
var flags uintptr = 0x50030080 // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|ES_AUTOHSCROLL
|
var flags uintptr = 0x50030080 // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|ES_AUTOHSCROLL
|
||||||
if opts.hideText {
|
if opts.hideText {
|
||||||
flags |= 0x20 // ES_PASSWORD
|
flags |= 0x20 // ES_PASSWORD
|
||||||
}
|
}
|
||||||
wnd.editCtl, _, _ = createWindowEx.Call(0x200, // WS_EX_CLIENTEDGE
|
dlg.editCtl, _, _ = createWindowEx.Call(0x200, // WS_EX_CLIENTEDGE
|
||||||
strptr("EDIT"), strptr(opts.entryText),
|
strptr("EDIT"), strptr(opts.entryText),
|
||||||
flags,
|
flags,
|
||||||
12, 30, 241, 24, wnd.handle, 0, instance, 0)
|
12, 30, 241, 24, dlg.wnd, 0, instance, 0)
|
||||||
|
|
||||||
wnd.okBtn, _, _ = createWindowEx.Call(0,
|
dlg.okBtn, _, _ = createWindowEx.Call(0,
|
||||||
strptr("BUTTON"), strptr(*opts.okLabel),
|
strptr("BUTTON"), strptr(*opts.okLabel),
|
||||||
0x50030001, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
|
0x50030001, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
|
||||||
12, 66, 75, 24, wnd.handle, 1 /* IDOK */, instance, 0)
|
12, 66, 75, 24, dlg.wnd, 1 /* IDOK */, instance, 0)
|
||||||
wnd.cancelBtn, _, _ = createWindowEx.Call(0,
|
dlg.cancelBtn, _, _ = createWindowEx.Call(0,
|
||||||
strptr("BUTTON"), strptr(*opts.cancelLabel),
|
strptr("BUTTON"), strptr(*opts.cancelLabel),
|
||||||
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
||||||
12, 66, 75, 24, wnd.handle, 2 /* IDCANCEL */, instance, 0)
|
12, 66, 75, 24, dlg.wnd, 2 /* IDCANCEL */, instance, 0)
|
||||||
if opts.extraButton != nil {
|
if opts.extraButton != nil {
|
||||||
wnd.extraBtn, _, _ = createWindowEx.Call(0,
|
dlg.extraBtn, _, _ = createWindowEx.Call(0,
|
||||||
strptr("BUTTON"), strptr(*opts.extraButton),
|
strptr("BUTTON"), strptr(*opts.extraButton),
|
||||||
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
||||||
12, 66, 75, 24, wnd.handle, 7 /* IDNO */, instance, 0)
|
12, 66, 75, 24, dlg.wnd, 7 /* IDNO */, instance, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
wnd.layout(getDPI(wnd.handle))
|
dlg.layout(getDPI(dlg.wnd))
|
||||||
centerWindow(wnd.handle)
|
centerWindow(dlg.wnd)
|
||||||
setFocus.Call(wnd.editCtl)
|
setFocus.Call(dlg.editCtl)
|
||||||
showWindow.Call(wnd.handle, 1 /* SW_SHOWNORMAL */, 0)
|
showWindow.Call(dlg.wnd, 1 /* SW_SHOWNORMAL */, 0)
|
||||||
sendMessage.Call(wnd.editCtl, 0xb1 /* EM_SETSEL */, 0, intptr(-1))
|
sendMessage.Call(dlg.editCtl, 0xb1 /* EM_SETSEL */, 0, intptr(-1))
|
||||||
|
|
||||||
if opts.ctx != nil {
|
if opts.ctx != nil {
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
|
@ -83,63 +83,64 @@ func entry(text string, opts options) (string, error) {
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-opts.ctx.Done():
|
case <-opts.ctx.Done():
|
||||||
sendMessage.Call(wnd.handle, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
|
sendMessage.Call(dlg.wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
|
||||||
case <-wait:
|
case <-wait:
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := messageLoop(wnd.handle); err != nil {
|
if err := messageLoop(dlg.wnd); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if opts.ctx != nil && opts.ctx.Err() != nil {
|
if opts.ctx != nil && opts.ctx.Err() != nil {
|
||||||
return "", opts.ctx.Err()
|
return "", opts.ctx.Err()
|
||||||
}
|
}
|
||||||
return wnd.out, wnd.err
|
return dlg.out, dlg.err
|
||||||
}
|
}
|
||||||
|
|
||||||
type entryWnd struct {
|
type entryDialog struct {
|
||||||
handle uintptr
|
out string
|
||||||
|
err error
|
||||||
|
|
||||||
|
wnd uintptr
|
||||||
textCtl uintptr
|
textCtl uintptr
|
||||||
editCtl uintptr
|
editCtl uintptr
|
||||||
okBtn uintptr
|
okBtn uintptr
|
||||||
cancelBtn uintptr
|
cancelBtn uintptr
|
||||||
extraBtn uintptr
|
extraBtn uintptr
|
||||||
out string
|
|
||||||
err error
|
|
||||||
font font
|
font font
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wnd *entryWnd) layout(dpi dpi) {
|
func (d *entryDialog) layout(dpi dpi) {
|
||||||
font := wnd.font.forDPI(dpi)
|
font := d.font.forDPI(dpi)
|
||||||
sendMessage.Call(wnd.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.editCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.editCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
setWindowPos.Call(wnd.handle, 0, 0, 0, dpi.scale(281), dpi.scale(141), 0x6) // SWP_NOZORDER|SWP_NOMOVE
|
setWindowPos.Call(d.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(141), 0x6) // SWP_NOZORDER|SWP_NOMOVE
|
||||||
setWindowPos.Call(wnd.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.editCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.editCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
if wnd.extraBtn == 0 {
|
if d.extraBtn == 0 {
|
||||||
setWindowPos.Call(wnd.okBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.okBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
} else {
|
} else {
|
||||||
setWindowPos.Call(wnd.okBtn, 0, dpi.scale(12), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.okBtn, 0, dpi.scale(12), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.extraBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.extraBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func entryProc(hwnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
|
func entryProc(wnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
|
||||||
var wnd *entryWnd
|
var dlg *entryDialog
|
||||||
switch msg {
|
switch msg {
|
||||||
case 0x0081: // WM_NCCREATE
|
case 0x0081: // WM_NCCREATE
|
||||||
saveBackRef(hwnd, *lparam)
|
saveBackRef(wnd, *lparam)
|
||||||
wnd = (*entryWnd)(*lparam)
|
dlg = (*entryDialog)(*lparam)
|
||||||
case 0x0082: // WM_NCDESTROY
|
case 0x0082: // WM_NCDESTROY
|
||||||
deleteBackRef(hwnd)
|
deleteBackRef(wnd)
|
||||||
default:
|
default:
|
||||||
wnd = (*entryWnd)(loadBackRef(hwnd))
|
dlg = (*entryDialog)(loadBackRef(wnd))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg {
|
switch msg {
|
||||||
|
@ -147,27 +148,27 @@ func entryProc(hwnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer)
|
||||||
postQuitMessage.Call(0)
|
postQuitMessage.Call(0)
|
||||||
|
|
||||||
case 0x0010: // WM_CLOSE
|
case 0x0010: // WM_CLOSE
|
||||||
wnd.err = ErrCanceled
|
dlg.err = ErrCanceled
|
||||||
destroyWindow.Call(hwnd)
|
destroyWindow.Call(wnd)
|
||||||
|
|
||||||
case 0x0111: // WM_COMMAND
|
case 0x0111: // WM_COMMAND
|
||||||
switch wparam {
|
switch wparam {
|
||||||
default:
|
default:
|
||||||
return 1
|
return 1
|
||||||
case 1, 6: // IDOK, IDYES
|
case 1, 6: // IDOK, IDYES
|
||||||
wnd.out = getWindowString(wnd.editCtl)
|
dlg.out = getWindowString(dlg.editCtl)
|
||||||
case 2: // IDCANCEL
|
case 2: // IDCANCEL
|
||||||
wnd.err = ErrCanceled
|
dlg.err = ErrCanceled
|
||||||
case 7: // IDNO
|
case 7: // IDNO
|
||||||
wnd.err = ErrExtraButton
|
dlg.err = ErrExtraButton
|
||||||
}
|
}
|
||||||
destroyWindow.Call(hwnd)
|
destroyWindow.Call(wnd)
|
||||||
|
|
||||||
case 0x02e0: // WM_DPICHANGED
|
case 0x02e0: // WM_DPICHANGED
|
||||||
wnd.layout(dpi(uint32(wparam) >> 16))
|
dlg.layout(dpi(uint32(wparam) >> 16))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
res, _, _ := syscall.Syscall6(defWindowProc.Addr(), 4, hwnd, uintptr(msg), wparam, uintptr(unsafe.Pointer(lparam)), 0, 0)
|
res, _, _ := defWindowProc.Call(wnd, uintptr(msg), wparam, uintptr(unsafe.Pointer(lparam)))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
131
list_windows.go
131
list_windows.go
|
@ -29,12 +29,12 @@ func listDlg(text string, items []string, multiple bool, opts options) ([]string
|
||||||
}
|
}
|
||||||
|
|
||||||
defer setup()()
|
defer setup()()
|
||||||
wnd := &listWnd{
|
dlg := &listDialog{
|
||||||
items: items,
|
items: items,
|
||||||
multiple: multiple,
|
multiple: multiple,
|
||||||
font: getFont(),
|
font: getFont(),
|
||||||
}
|
}
|
||||||
defer wnd.font.delete()
|
defer dlg.font.delete()
|
||||||
|
|
||||||
if opts.ctx != nil && opts.ctx.Err() != nil {
|
if opts.ctx != nil && opts.ctx.Err() != nil {
|
||||||
return nil, opts.ctx.Err()
|
return nil, opts.ctx.Err()
|
||||||
|
@ -51,50 +51,50 @@ func listDlg(text string, items []string, multiple bool, opts options) ([]string
|
||||||
}
|
}
|
||||||
defer unregisterClass.Call(cls, instance)
|
defer unregisterClass.Call(cls, instance)
|
||||||
|
|
||||||
wnd.handle, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
|
dlg.wnd, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
|
||||||
cls, strptr(*opts.title),
|
cls, strptr(*opts.title),
|
||||||
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
|
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
|
||||||
0x80000000, // CW_USEDEFAULT
|
0x80000000, // CW_USEDEFAULT
|
||||||
0x80000000, // CW_USEDEFAULT
|
0x80000000, // CW_USEDEFAULT
|
||||||
281, 281, 0, 0, instance, uintptr(unsafe.Pointer(wnd)))
|
281, 281, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
|
||||||
|
|
||||||
wnd.textCtl, _, _ = createWindowEx.Call(0,
|
dlg.textCtl, _, _ = createWindowEx.Call(0,
|
||||||
strptr("STATIC"), strptr(text),
|
strptr("STATIC"), strptr(text),
|
||||||
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
|
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
|
||||||
12, 10, 241, 16, wnd.handle, 0, instance, 0)
|
12, 10, 241, 16, dlg.wnd, 0, instance, 0)
|
||||||
|
|
||||||
var flags uintptr = 0x50320000 // WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_GROUP|WS_TABSTOP
|
var flags uintptr = 0x50320000 // WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_GROUP|WS_TABSTOP
|
||||||
if multiple {
|
if multiple {
|
||||||
flags |= 0x0800 // LBS_EXTENDEDSEL
|
flags |= 0x0800 // LBS_EXTENDEDSEL
|
||||||
}
|
}
|
||||||
wnd.listCtl, _, _ = createWindowEx.Call(0x200, // WS_EX_CLIENTEDGE
|
dlg.listCtl, _, _ = createWindowEx.Call(0x200, // WS_EX_CLIENTEDGE
|
||||||
strptr("LISTBOX"), strptr(opts.entryText),
|
strptr("LISTBOX"), strptr(opts.entryText),
|
||||||
flags,
|
flags,
|
||||||
12, 30, 241, 164, wnd.handle, 0, instance, 0)
|
12, 30, 241, 164, dlg.wnd, 0, instance, 0)
|
||||||
|
|
||||||
wnd.okBtn, _, _ = createWindowEx.Call(0,
|
dlg.okBtn, _, _ = createWindowEx.Call(0,
|
||||||
strptr("BUTTON"), strptr(*opts.okLabel),
|
strptr("BUTTON"), strptr(*opts.okLabel),
|
||||||
0x50030001, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
|
0x50030001, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
|
||||||
12, 206, 75, 24, wnd.handle, 1 /* IDOK */, instance, 0)
|
12, 206, 75, 24, dlg.wnd, 1 /* IDOK */, instance, 0)
|
||||||
wnd.cancelBtn, _, _ = createWindowEx.Call(0,
|
dlg.cancelBtn, _, _ = createWindowEx.Call(0,
|
||||||
strptr("BUTTON"), strptr(*opts.cancelLabel),
|
strptr("BUTTON"), strptr(*opts.cancelLabel),
|
||||||
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
||||||
12, 206, 75, 24, wnd.handle, 2 /* IDCANCEL */, instance, 0)
|
12, 206, 75, 24, dlg.wnd, 2 /* IDCANCEL */, instance, 0)
|
||||||
if opts.extraButton != nil {
|
if opts.extraButton != nil {
|
||||||
wnd.extraBtn, _, _ = createWindowEx.Call(0,
|
dlg.extraBtn, _, _ = createWindowEx.Call(0,
|
||||||
strptr("BUTTON"), strptr(*opts.extraButton),
|
strptr("BUTTON"), strptr(*opts.extraButton),
|
||||||
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
|
||||||
12, 206, 75, 24, wnd.handle, 7 /* IDNO */, instance, 0)
|
12, 206, 75, 24, dlg.wnd, 7 /* IDNO */, instance, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
sendMessage.Call(wnd.listCtl, 0x180 /* LB_ADDSTRING */, 0, strptr(item))
|
sendMessage.Call(dlg.listCtl, 0x180 /* LB_ADDSTRING */, 0, strptr(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
wnd.layout(getDPI(wnd.handle))
|
dlg.layout(getDPI(dlg.wnd))
|
||||||
centerWindow(wnd.handle)
|
centerWindow(dlg.wnd)
|
||||||
setFocus.Call(wnd.listCtl)
|
setFocus.Call(dlg.listCtl)
|
||||||
showWindow.Call(wnd.handle, 1 /* SW_SHOWNORMAL */, 0)
|
showWindow.Call(dlg.wnd, 1 /* SW_SHOWNORMAL */, 0)
|
||||||
|
|
||||||
if opts.ctx != nil {
|
if opts.ctx != nil {
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
|
@ -102,65 +102,66 @@ func listDlg(text string, items []string, multiple bool, opts options) ([]string
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-opts.ctx.Done():
|
case <-opts.ctx.Done():
|
||||||
sendMessage.Call(wnd.handle, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
|
sendMessage.Call(dlg.wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
|
||||||
case <-wait:
|
case <-wait:
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := messageLoop(wnd.handle); err != nil {
|
if err := messageLoop(dlg.wnd); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if opts.ctx != nil && opts.ctx.Err() != nil {
|
if opts.ctx != nil && opts.ctx.Err() != nil {
|
||||||
return nil, opts.ctx.Err()
|
return nil, opts.ctx.Err()
|
||||||
}
|
}
|
||||||
return wnd.out, wnd.err
|
return dlg.out, dlg.err
|
||||||
}
|
}
|
||||||
|
|
||||||
type listWnd struct {
|
type listDialog struct {
|
||||||
handle uintptr
|
items []string
|
||||||
|
multiple bool
|
||||||
|
out []string
|
||||||
|
err error
|
||||||
|
|
||||||
|
wnd uintptr
|
||||||
textCtl uintptr
|
textCtl uintptr
|
||||||
listCtl uintptr
|
listCtl uintptr
|
||||||
okBtn uintptr
|
okBtn uintptr
|
||||||
cancelBtn uintptr
|
cancelBtn uintptr
|
||||||
extraBtn uintptr
|
extraBtn uintptr
|
||||||
multiple bool
|
|
||||||
items []string
|
|
||||||
out []string
|
|
||||||
err error
|
|
||||||
font font
|
font font
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wnd *listWnd) layout(dpi dpi) {
|
func (d *listDialog) layout(dpi dpi) {
|
||||||
font := wnd.font.forDPI(dpi)
|
font := d.font.forDPI(dpi)
|
||||||
sendMessage.Call(wnd.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.listCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.listCtl, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
sendMessage.Call(wnd.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
sendMessage.Call(d.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
|
||||||
setWindowPos.Call(wnd.handle, 0, 0, 0, dpi.scale(281), dpi.scale(281), 0x6) // SWP_NOZORDER|SWP_NOMOVE
|
setWindowPos.Call(d.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), 0x6) // SWP_NOZORDER|SWP_NOMOVE
|
||||||
setWindowPos.Call(wnd.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.listCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.listCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), 0x4) // SWP_NOZORDER
|
||||||
if wnd.extraBtn == 0 {
|
if d.extraBtn == 0 {
|
||||||
setWindowPos.Call(wnd.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
} else {
|
} else {
|
||||||
setWindowPos.Call(wnd.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
setWindowPos.Call(wnd.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func listProc(hwnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
|
func listProc(wnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
|
||||||
var wnd *listWnd
|
var dlg *listDialog
|
||||||
switch msg {
|
switch msg {
|
||||||
case 0x0081: // WM_NCCREATE
|
case 0x0081: // WM_NCCREATE
|
||||||
saveBackRef(hwnd, *lparam)
|
saveBackRef(wnd, *lparam)
|
||||||
wnd = (*listWnd)(*lparam)
|
dlg = (*listDialog)(*lparam)
|
||||||
case 0x0082: // WM_NCDESTROY
|
case 0x0082: // WM_NCDESTROY
|
||||||
deleteBackRef(hwnd)
|
deleteBackRef(wnd)
|
||||||
default:
|
default:
|
||||||
wnd = (*listWnd)(loadBackRef(hwnd))
|
dlg = (*listDialog)(loadBackRef(wnd))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg {
|
switch msg {
|
||||||
|
@ -168,44 +169,44 @@ func listProc(hwnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer)
|
||||||
postQuitMessage.Call(0)
|
postQuitMessage.Call(0)
|
||||||
|
|
||||||
case 0x0010: // WM_CLOSE
|
case 0x0010: // WM_CLOSE
|
||||||
wnd.err = ErrCanceled
|
dlg.err = ErrCanceled
|
||||||
destroyWindow.Call(hwnd)
|
destroyWindow.Call(wnd)
|
||||||
|
|
||||||
case 0x0111: // WM_COMMAND
|
case 0x0111: // WM_COMMAND
|
||||||
switch wparam {
|
switch wparam {
|
||||||
default:
|
default:
|
||||||
return 1
|
return 1
|
||||||
case 1, 6: // IDOK, IDYES
|
case 1, 6: // IDOK, IDYES
|
||||||
if wnd.multiple {
|
if dlg.multiple {
|
||||||
if len, _, _ := sendMessage.Call(wnd.listCtl, 0x190 /* LB_GETSELCOUNT */, 0, 0); int32(len) >= 0 {
|
if len, _, _ := sendMessage.Call(dlg.listCtl, 0x190 /* LB_GETSELCOUNT */, 0, 0); int32(len) >= 0 {
|
||||||
wnd.out = make([]string, len)
|
dlg.out = make([]string, len)
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
indices := make([]int32, len)
|
indices := make([]int32, len)
|
||||||
sendMessage.Call(wnd.listCtl, 0x191 /* LB_GETSELITEMS */, len, uintptr(unsafe.Pointer(&indices[0])))
|
sendMessage.Call(dlg.listCtl, 0x191 /* LB_GETSELITEMS */, len, uintptr(unsafe.Pointer(&indices[0])))
|
||||||
for i, idx := range indices {
|
for i, idx := range indices {
|
||||||
wnd.out[i] = wnd.items[idx]
|
dlg.out[i] = dlg.items[idx]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if idx, _, _ := sendMessage.Call(wnd.listCtl, 0x188 /* LB_GETCURSEL */, 0, 0); int32(idx) >= 0 {
|
if idx, _, _ := sendMessage.Call(dlg.listCtl, 0x188 /* LB_GETCURSEL */, 0, 0); int32(idx) >= 0 {
|
||||||
wnd.out = []string{wnd.items[idx]}
|
dlg.out = []string{dlg.items[idx]}
|
||||||
} else {
|
} else {
|
||||||
wnd.out = []string{}
|
dlg.out = []string{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 2: // IDCANCEL
|
case 2: // IDCANCEL
|
||||||
wnd.err = ErrCanceled
|
dlg.err = ErrCanceled
|
||||||
case 7: // IDNO
|
case 7: // IDNO
|
||||||
wnd.err = ErrExtraButton
|
dlg.err = ErrExtraButton
|
||||||
}
|
}
|
||||||
destroyWindow.Call(hwnd)
|
destroyWindow.Call(wnd)
|
||||||
|
|
||||||
case 0x02e0: // WM_DPICHANGED
|
case 0x02e0: // WM_DPICHANGED
|
||||||
wnd.layout(dpi(uint32(wparam) >> 16))
|
dlg.layout(dpi(uint32(wparam) >> 16))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
res, _, _ := syscall.Syscall6(defWindowProc.Addr(), 4, hwnd, uintptr(msg), wparam, uintptr(unsafe.Pointer(lparam)), 0, 0)
|
res, _, _ := defWindowProc.Call(wnd, uintptr(msg), wparam, uintptr(unsafe.Pointer(lparam)))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,16 +137,17 @@ func progressDlg(opts options, dlg *progressDialog) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type progressDialog struct {
|
type progressDialog struct {
|
||||||
max int
|
done chan struct{}
|
||||||
done chan struct{}
|
init sync.WaitGroup
|
||||||
init sync.WaitGroup
|
max int
|
||||||
|
err error
|
||||||
|
|
||||||
wnd uintptr
|
wnd uintptr
|
||||||
textCtl uintptr
|
textCtl uintptr
|
||||||
progCtl uintptr
|
progCtl uintptr
|
||||||
okBtn uintptr
|
okBtn uintptr
|
||||||
cancelBtn uintptr
|
cancelBtn uintptr
|
||||||
extraBtn uintptr
|
extraBtn uintptr
|
||||||
err error
|
|
||||||
font font
|
font font
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +270,7 @@ func progressProc(wnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointe
|
||||||
dlg.layout(dpi(uint32(wparam) >> 16))
|
dlg.layout(dpi(uint32(wparam) >> 16))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
res, _, _ := syscall.Syscall6(defWindowProc.Addr(), 4, wnd, uintptr(msg), wparam, uintptr(unsafe.Pointer(lparam)), 0, 0)
|
res, _, _ := defWindowProc.Call(wnd, uintptr(msg), wparam, uintptr(unsafe.Pointer(lparam)))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue