Fix (win32).

This commit is contained in:
Nuno Cruces 2021-04-05 18:58:32 +01:00
parent 279bde180a
commit c55b72982e
3 changed files with 16 additions and 13 deletions

View file

@ -1,7 +1,6 @@
package zenity
import (
"math"
"strconv"
"syscall"
"unsafe"
@ -315,14 +314,14 @@ func editBox(title, text string, opts options) (out string, ok bool, err error)
defer unregisterClass.Call(cls, instance)
wnd, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
cls, stringUintptr(title),
cls, strptr(title),
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
0x80000000, // CW_USEDEFAULT
0x80000000, // CW_USEDEFAULT
281, 140, 0, 0, instance)
textCtl, _, _ = createWindowEx.Call(0,
stringUintptr("STATIC"), stringUintptr(text),
strptr("STATIC"), strptr(text),
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
12, 10, 241, 16, wnd, 0, instance)
@ -331,21 +330,21 @@ func editBox(title, text string, opts options) (out string, ok bool, err error)
flags |= 0x20 // ES_PASSWORD
}
editCtl, _, _ = createWindowEx.Call(0x200, // WS_EX_CLIENTEDGE
stringUintptr("EDIT"), stringUintptr(opts.entryText),
strptr("EDIT"), strptr(opts.entryText),
flags,
12, 30, 241, 24, wnd, 0, instance)
okBtn, _, _ = createWindowEx.Call(0,
stringUintptr("BUTTON"), stringUintptr(*opts.okLabel),
strptr("BUTTON"), strptr(*opts.okLabel),
0x50030001, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
12, 65, 75, 24, wnd, 1 /* IDOK */, instance)
cancelBtn, _, _ = createWindowEx.Call(0,
stringUintptr("BUTTON"), stringUintptr(*opts.cancelLabel),
strptr("BUTTON"), strptr(*opts.cancelLabel),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 65, 75, 24, wnd, 2 /* IDCANCEL */, instance)
if opts.extraButton != nil {
extraBtn, _, _ = createWindowEx.Call(0,
stringUintptr("BUTTON"), stringUintptr(*opts.extraButton),
strptr("BUTTON"), strptr(*opts.extraButton),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 65, 75, 24, wnd, 7 /* IDNO */, instance)
}
@ -354,7 +353,7 @@ func editBox(title, text string, opts options) (out string, ok bool, err error)
centerWindow(wnd)
setFocus.Call(editCtl)
showWindow.Call(wnd, 1 /* SW_SHOWNORMAL */, 0)
sendMessage.Call(editCtl, 0xb1 /* EM_SETSEL */, 0, math.MaxUint64 /* -1 */)
sendMessage.Call(editCtl, 0xb1 /* EM_SETSEL */, 0, intptr(-1))
err = nil
if err := messageLoop(wnd); err != nil {

View file

@ -54,10 +54,10 @@ func message(kind messageKind, text string, opts options) (bool, error) {
var title uintptr
if opts.title != nil {
title = stringUintptr(*opts.title)
title = strptr(*opts.title)
}
s, _, err := messageBox.Call(0, stringUintptr(text), title, flags)
s, _, err := messageBox.Call(0, strptr(text), title, flags)
if opts.ctx != nil && opts.ctx.Err() != nil {
return false, opts.ctx.Err()
@ -96,7 +96,7 @@ func hookMessageLabels(kind messageKind, opts options) (unhook context.CancelFun
text = opts.extraButton
}
if text != nil {
setWindowText.Call(wnd, stringUintptr(*text))
setWindowText.Call(wnd, strptr(*text))
}
}
return 1

View file

@ -168,16 +168,20 @@ func hookDialogTitle(ctx context.Context, title *string) (unhook context.CancelF
var init func(wnd uintptr)
if title != nil {
init = func(wnd uintptr) {
setWindowText.Call(wnd, stringUintptr(*title))
setWindowText.Call(wnd, strptr(*title))
}
}
return hookDialog(ctx, init)
}
func stringUintptr(s string) uintptr {
func strptr(s string) uintptr {
return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
}
func intptr(i int64) uintptr {
return uintptr(i)
}
// https://github.com/wine-mirror/wine/blob/master/include/unknwn.idl
type _IUnknownVtbl struct {