From 4bc8c392da86e9cbb598412dfd3de8e0cae49c66 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 8 Mar 2021 00:57:16 +0000 Subject: [PATCH] Import from github.com/gen2brain/dlgs. --- dlgs_windows.go => entry_windows.go | 202 ++++------------------------ go.mod | 2 +- go.sum | 19 ++- 3 files changed, 45 insertions(+), 178 deletions(-) rename dlgs_windows.go => entry_windows.go (71%) diff --git a/dlgs_windows.go b/entry_windows.go similarity index 71% rename from dlgs_windows.go rename to entry_windows.go index ca91536..f1b4a9d 100644 --- a/dlgs_windows.go +++ b/entry_windows.go @@ -1,22 +1,34 @@ -// +build windows,!linux,!darwin,!js +// This file was imported from: github.com/gen2brain/dlgs +// Copyright (c) 2017, Milan Nikolic +// Licensed under the BSD 2-Clause "Simplified" License. -package dlgs +package zenity import ( - "strings" "syscall" - "unicode/utf16" "unsafe" ) -var ( - user32 = syscall.NewLazyDLL("user32.dll") - gdi32 = syscall.NewLazyDLL("gdi32.dll") - comdlg32 = syscall.NewLazyDLL("comdlg32.dll") - shell32 = syscall.NewLazyDLL("shell32.dll") - kernel32 = syscall.NewLazyDLL("kernel32.dll") +func entry(text string, opts options) (string, bool, error) { + var title string + if opts.title != nil { + title = *opts.title + } + return editBox(title, text, opts.entryText, "ClassEntry", false) +} + +func password(opts options) (string, string, bool, error) { + var title string + if opts.title != nil { + title = *opts.title + } + pass, ok, err := editBox(title, "Type your password", "", "ClassPassword", true) + return "", pass, ok, err +} + +var ( + gdi32 = syscall.NewLazyDLL("gdi32.dll") - messageBoxW = user32.NewProc("MessageBoxW") createWindowExW = user32.NewProc("CreateWindowExW") defWindowProcW = user32.NewProc("DefWindowProcW") destroyWindowW = user32.NewProc("DestroyWindow") @@ -27,7 +39,6 @@ var ( registerClassExW = user32.NewProc("RegisterClassExW") unregisterClassW = user32.NewProc("UnregisterClassW") translateMessageW = user32.NewProc("TranslateMessage") - setWindowTextW = user32.NewProc("SetWindowTextW") getWindowTextLengthW = user32.NewProc("GetWindowTextLengthW") getWindowTextW = user32.NewProc("GetWindowTextW") getWindowLongW = user32.NewProc("GetWindowLongW") @@ -42,30 +53,10 @@ var ( createFontIndirectW = gdi32.NewProc("CreateFontIndirectW") - getOpenFileNameW = comdlg32.NewProc("GetOpenFileNameW") - chooseColorW = comdlg32.NewProc("ChooseColorW") - - shBrowseForFolderW = shell32.NewProc("SHBrowseForFolderW") - shGetPathFromIDListW = shell32.NewProc("SHGetPathFromIDListW") - getModuleHandleW = kernel32.NewProc("GetModuleHandleW") ) const ( - mbOk = 0x00000000 - mbYesNo = 0x00000004 - - mbDefaultIcon1 = 0x00000000 - mbDefaultIcon2 = 0x00000100 - - mbIconInfo = 0x00000040 - mbIconWarning = 0x00000030 - mbIconError = 0x00000010 - mbIconQuestion = 0x00000020 - - idOk = 1 - idYes = 6 - swShow = 5 swShowNormal = 1 swUseDefault = 0x80000000 @@ -97,46 +88,14 @@ const ( wmKeydown = 0x0100 wmInitDialog = 0x0110 - ofnAllowMultiSelect = 0x00000200 - ofnExplorer = 0x00080000 - ofnFileMustExist = 0x00001000 - ofnHideReadOnly = 0x00000004 - ofnOverwriteprompt = 0x00000002 - esPassword = 0x0020 esAutoVScroll = 0x0040 esAutoHScroll = 0x0080 - bifEditBox = 0x00000010 - bifNewDialogStyle = 0x00000040 - - ccRgbInit = 0x00000001 - ccFullOpen = 0x00000002 - - lbAddString = 0x0180 - lbGetCurSel = 0x0188 - lbGetSelCount = 0x0190 - lbGetSelItems = 0x0191 - lbGetItemData = 0x0199 - lbSetItemData = 0x019A - - lbSeparator = "LB_SEP" - - lbsExtendedsel = 0x0800 - - dtsUpdown = 0x0001 - dtsShowNone = 0x0002 - dtsShortDateFormat = 0x0000 - dtsLongDateFormat = 0x0004 - dtmFirst = 0x1000 dtmGetSystemTime = dtmFirst + 1 dtmSetSystemTime = dtmFirst + 2 - gdtError = -1 - gdtValid = 0 - gdtNone = 1 - vkEscape = 0x1B enUpdate = 0x0400 bsPushButton = 0 @@ -220,76 +179,6 @@ type rectW struct { bottom int32 } -// openfilenameW https://msdn.microsoft.com/en-us/library/windows/desktop/ms646839.aspx -type openfilenameW struct { - lStructSize uint32 - hwndOwner syscall.Handle - hInstance syscall.Handle - lpstrFilter *uint16 - lpstrCustomFilter *uint16 - nMaxCustFilter uint32 - nFilterIndex uint32 - lpstrFile *uint16 - nMaxFile uint32 - lpstrFileTitle *uint16 - nMaxFileTitle uint32 - lpstrInitialDir *uint16 - lpstrTitle *uint16 - flags uint32 - nFileOffset uint16 - nFileExtension uint16 - lpstrDefExt *uint16 - lCustData uintptr - lpfnHook syscall.Handle - lpTemplateName *uint16 - pvReserved unsafe.Pointer - dwReserved uint32 - flagsEx uint32 -} - -// browseinfoW http://msdn.microsoft.com/en-us/library/windows/desktop/bb773205.aspx -type browseinfoW struct { - owner syscall.Handle - root *uint16 - displayName *uint16 - title *uint16 - flags uint32 - callbackFunc uintptr - lParam uintptr - image int32 -} - -// choosecolorW https://msdn.microsoft.com/en-us/library/windows/desktop/ms646830.aspx -type choosecolorW struct { - lStructSize uint32 - hwndOwner syscall.Handle - hInstance syscall.Handle - rgbResult uint32 - lpCustColors *uint32 - flags uint32 - lCustData uintptr - lpfnHook uintptr - lpTemplateName *uint16 -} - -// systemtimeW https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950.aspx -type systemtimeW struct { - wYear uint16 - wMonth uint16 - wDayOfWeek uint16 - wDay uint16 - wHour uint16 - wMinute uint16 - wSecond uint16 - wMilliseconds uint16 -} - -func messageBox(title, text string, flags int) int { - ret, _, _ := messageBoxW.Call(0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))), uintptr(uint(flags))) - return int(ret) -} - func getModuleHandle() (syscall.Handle, error) { ret, _, err := getModuleHandleW.Call(uintptr(0)) if ret == 0 { @@ -352,7 +241,7 @@ func getMessage(msg *msgW, hwnd syscall.Handle, msgFilterMin, msgFilterMax uint3 return int32(ret) != 0, nil } -func sendMessage(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) uintptr { +func _sendMessage(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) uintptr { ret, _, _ := sendMessageW.Call(uintptr(hwnd), uintptr(msg), wparam, lparam, 0, 0) return ret } @@ -369,10 +258,6 @@ func translateMessage(msg *msgW) { translateMessageW.Call(uintptr(unsafe.Pointer(msg))) } -func setWindowText(hwnd syscall.Handle, text string) { - setWindowTextW.Call(uintptr(hwnd), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text)))) -} - func getWindowTextLength(hwnd syscall.Handle) int { ret, _, _ := getWindowTextLengthW.Call(uintptr(hwnd)) return int(ret) @@ -438,26 +323,6 @@ func getSystemMetrics(nindex int32) int32 { return int32(ret) } -func getOpenFileName(lpofn *openfilenameW) bool { - ret, _, _ := getOpenFileNameW.Call(uintptr(unsafe.Pointer(lpofn)), 0, 0) - return ret != 0 -} - -func shBrowseForFolder(lpbi *browseinfoW) uintptr { - ret, _, _ := shBrowseForFolderW.Call(uintptr(unsafe.Pointer(lpbi)), 0, 0) - return ret -} - -func shGetPathFromIDList(pidl uintptr, pszPath *uint16) bool { - ret, _, _ := shGetPathFromIDListW.Call(pidl, uintptr(unsafe.Pointer(pszPath)), 0) - return ret != 0 -} - -func chooseColor(lpcc *choosecolorW) bool { - ret, _, _ := chooseColorW.Call(uintptr(unsafe.Pointer(lpcc)), 0, 0) - return ret != 0 -} - func centerWindow(hwnd syscall.Handle) { var rc rectW getWindowRect(hwnd, &rc) @@ -506,17 +371,6 @@ func messageLoop(hwnd syscall.Handle) error { return nil } -func utf16PtrFromString(s string) *uint16 { - b := utf16.Encode([]rune(s)) - return &b[0] -} - -func stringFromUtf16Ptr(p *uint16) string { - b := *(*[maxPath]uint16)(unsafe.Pointer(p)) - r := utf16.Decode(b[:]) - return strings.Trim(string(r), "\x00") -} - // editBox displays textedit/inputbox dialog. func editBox(title, text, defaultText, className string, password bool) (string, bool, error) { var out string @@ -579,10 +433,10 @@ func editBox(title, text, defaultText, className string, password bool) (string, setWindowLong(hwnd, gwlStyle, getWindowLong(hwnd, gwlStyle)^wsMaximizeBox) font := getMessageFont() - sendMessage(hwndText, wmSetFont, font, 0) - sendMessage(hwndEdit, wmSetFont, font, 0) - sendMessage(hwndOK, wmSetFont, font, 0) - sendMessage(hwndCancel, wmSetFont, font, 0) + _sendMessage(hwndText, wmSetFont, font, 0) + _sendMessage(hwndEdit, wmSetFont, font, 0) + _sendMessage(hwndOK, wmSetFont, font, 0) + _sendMessage(hwndCancel, wmSetFont, font, 0) centerWindow(hwnd) diff --git a/go.mod b/go.mod index 258ec01..fb8ab28 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,5 @@ require ( go.uber.org/goleak v1.0.0 // test golang.org/x/image v0.0.0-20201208152932-35266b937fa6 golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect - golang.org/x/tools v0.0.0-20200129045341-207d3de1faaf // indirect + golang.org/x/tools v0.1.0 // indirect ) diff --git a/go.sum b/go.sum index 50c158b..9727dc9 100644 --- a/go.sum +++ b/go.sum @@ -10,30 +10,43 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.uber.org/goleak v1.0.0 h1:qsup4IcBdlmsnGfqyLl4Ntn3C2XCCuKAE7DwHpScyUo= go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI= golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200129045341-207d3de1faaf h1:mFgR10kFfr83r2+nXf0GZC2FKrFhMSs9NdJ0YdEaGiY= -golang.org/x/tools v0.0.0-20200129045341-207d3de1faaf/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=