From 2bedb362579061ddae45946c51fdcc44121bec0b Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Wed, 8 Jun 2022 20:33:10 +0100 Subject: [PATCH] Attach (windows). --- color_windows.go | 1 + date_windows.go | 3 ++- entry_windows.go | 3 ++- file_windows.go | 7 ++++++- list_windows.go | 3 ++- msg_windows.go | 3 ++- progress_windows.go | 3 ++- pwd_windows.go | 3 ++- util_unix.go | 5 ++--- zenity.go | 4 +++- 10 files changed, 24 insertions(+), 11 deletions(-) diff --git a/color_windows.go b/color_windows.go index 32eb9e0..f9a68c3 100644 --- a/color_windows.go +++ b/color_windows.go @@ -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 { diff --git a/date_windows.go b/date_windows.go index 4748739..82ee7b6 100644 --- a/date_windows.go +++ b/date_windows.go @@ -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), diff --git a/entry_windows.go b/entry_windows.go index 0038cfa..216bd63 100644 --- a/entry_windows.go +++ b/entry_windows.go @@ -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), diff --git a/file_windows.go b/file_windows.go index e0a2b90..ca90e2c 100644 --- a/file_windows.go +++ b/file_windows.go @@ -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 { diff --git a/list_windows.go b/list_windows.go index fc2cdeb..f2e0934 100644 --- a/list_windows.go +++ b/list_windows.go @@ -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), diff --git a/msg_windows.go b/msg_windows.go index def918d..c1084c4 100644 --- a/msg_windows.go +++ b/msg_windows.go @@ -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() diff --git a/progress_windows.go b/progress_windows.go index f2aa241..df47739 100644 --- a/progress_windows.go +++ b/progress_windows.go @@ -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, diff --git a/pwd_windows.go b/pwd_windows.go index 9f85423..6698f60 100644 --- a/pwd_windows.go +++ b/pwd_windows.go @@ -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:"), diff --git a/util_unix.go b/util_unix.go index fe6c168..111cd47 100644 --- a/util_unix.go +++ b/util_unix.go @@ -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") diff --git a/zenity.go b/zenity.go index b37a095..1a8dbf6 100644 --- a/zenity.go +++ b/zenity.go @@ -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") } }