Attach (windows).

This commit is contained in:
Nuno Cruces 2022-06-08 20:33:10 +01:00
parent 52eb3aeda1
commit 2bedb36257
10 changed files with 24 additions and 11 deletions

View file

@ -33,6 +33,7 @@ func selectColor(opts options) (color.Color, error) {
var args _CHOOSECOLOR
args.StructSize = uint32(unsafe.Sizeof(args))
args.Owner, _ = opts.attach.(uintptr)
args.CustColors = &customColors
if opts.color != nil {

View file

@ -56,11 +56,12 @@ func (dlg *calendarDialog) setup(text string, opts options) (time.Time, error) {
}
defer unregisterClass.Call(cls, instance)
owner, _ := opts.attach.(uintptr)
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 281, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
281, 281, owner, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), strptr(text),

View file

@ -55,11 +55,12 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) {
}
defer unregisterClass.Call(cls, instance)
owner, _ := opts.attach.(uintptr)
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 141, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
281, 141, owner, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), strptr(text),

View file

@ -43,6 +43,7 @@ func selectFile(opts options) (string, error) {
var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args))
args.Owner, _ = opts.attach.(uintptr)
args.Flags = _OFN_NOCHANGEDIR | _OFN_FILEMUSTEXIST | _OFN_EXPLORER
if opts.title != nil {
@ -88,6 +89,7 @@ func selectFileMultiple(opts options) ([]string, error) {
var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args))
args.Owner, _ = opts.attach.(uintptr)
args.Flags = _OFN_NOCHANGEDIR | _OFN_ALLOWMULTISELECT | _OFN_FILEMUSTEXIST | _OFN_EXPLORER
if opts.title != nil {
@ -158,6 +160,7 @@ func selectFileSave(opts options) (string, error) {
var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args))
args.Owner, _ = opts.attach.(uintptr)
args.Flags = _OFN_NOCHANGEDIR | _OFN_PATHMUSTEXIST | _OFN_NOREADONLYRETURN | _OFN_EXPLORER
if opts.title != nil {
@ -268,7 +271,8 @@ func pickFolders(opts options, multi bool) (str string, lst []string, err error)
defer unhook()
}
hr, _, _ = dialog.Call(dialog.Show, 0)
owner, _ := opts.attach.(uintptr)
hr, _, _ = dialog.Call(dialog.Show, owner)
if opts.ctx != nil && opts.ctx.Err() != nil {
return "", nil, opts.ctx.Err()
}
@ -328,6 +332,7 @@ func pickFolders(opts options, multi bool) (str string, lst []string, err error)
func browseForFolder(opts options) (string, []string, error) {
var args _BROWSEINFO
args.Owner, _ = opts.attach.(uintptr)
args.Flags = 0x1 // BIF_RETURNONLYFSDIRS
if opts.title != nil {

View file

@ -72,11 +72,12 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
}
defer unregisterClass.Call(cls, instance)
owner, _ := opts.attach.(uintptr)
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 281, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
281, 281, owner, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), strptr(text),

View file

@ -70,7 +70,8 @@ func message(kind messageKind, text string, opts options) error {
title = syscall.StringToUTF16Ptr(*opts.title)
}
s, _, err := messageBox.Call(0, strptr(text), uintptr(unsafe.Pointer(title)), flags)
owner, _ := opts.attach.(uintptr)
s, _, err := messageBox.Call(owner, strptr(text), uintptr(unsafe.Pointer(title)), flags)
if opts.ctx != nil && opts.ctx.Err() != nil {
return opts.ctx.Err()

View file

@ -135,11 +135,12 @@ func (dlg *progressDialog) setup(opts options) error {
}
defer unregisterClass.Call(cls, instance)
owner, _ := opts.attach.(uintptr)
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 133, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
281, 133, owner, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), 0,

View file

@ -65,11 +65,12 @@ func (dlg *passwordDialog) setup(opts options) (string, string, error) {
}
defer unregisterClass.Call(cls, instance)
owner, _ := opts.attach.(uintptr)
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 191, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
281, 191, owner, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.uTextCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), strptr("Username:"),

View file

@ -4,7 +4,6 @@ package zenity
import (
"bytes"
"fmt"
"os/exec"
"strconv"
"strings"
@ -16,8 +15,8 @@ func appendGeneral(args []string, opts options) []string {
if opts.title != nil {
args = append(args, "--title", *opts.title)
}
if opts.attach != nil {
args = append(args, "--attach", fmt.Sprint(opts.attach))
if id, ok := opts.attach.(int); ok {
args = append(args, "--attach", strconv.Itoa(id))
}
if opts.modal {
args = append(args, "--modal")

View file

@ -214,7 +214,9 @@ func Attach(id any) Option {
}
default:
if _, ok := id.(int); !ok {
switch id.(type) {
case int:
default:
panic("interface conversion: expected int")
}
}