Do not parent file or directory dialogs to panels.

Parenting dialogs to child windows of top level windows is most likely
not defined behavior.  It's also likely that this behavior varies across
platforms so it' best not to risk doing it.  wxWidgets does not check if
the dialog parent is actually a top level window.  There may be other
places we are doing this with our message dialogs so we should do an
audit.
This commit is contained in:
Wayne Stambaugh 2024-02-02 09:20:36 -05:00
parent 0113e7053d
commit 2b1bf369f2
6 changed files with 26 additions and 15 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -344,8 +344,10 @@ void PANEL_COMMON_SETTINGS::OnPDFViewerClick( wxCommandEvent& event )
Pgm().ReadPdfBrowserInfos();
wxFileName fn = Pgm().GetPdfBrowserName();
wxFileDialog dlg( this, _( "Select Preferred PDF Viewer" ), fn.GetPath(), fn.GetFullPath(),
wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxFileDialog dlg( topLevelParent, _( "Select Preferred PDF Viewer" ), fn.GetPath(),
fn.GetFullPath(), wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL )
return;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 CERN
* Copyright (C) 2015-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015-2024 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -365,7 +365,9 @@ void WX_HTML_REPORT_PANEL::onBtnSaveToFile( wxCommandEvent& event )
else
fn = m_reportFileName;
wxFileDialog dlg( this, _( "Save Report File" ), fn.GetPath(), fn.GetFullName(),
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxFileDialog dlg( topLevelParent, _( "Save Report File" ), fn.GetPath(), fn.GetFullName(),
FILEEXT::TextFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() != wxID_OK )

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2017 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2021 CERN
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -606,7 +606,9 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
if( m_cur_grid == m_project_grid )
openDir = m_lastProjectLibDir;
wxFileDialog dlg( this, _( "Add Library" ), openDir, wxEmptyString, fileFiltersStr,
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxFileDialog dlg( topLevelParent, _( "Add Library" ), openDir, wxEmptyString, fileFiltersStr,
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
if( dlg.ShowModal() == wxID_CANCEL )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -525,7 +525,8 @@ void PANEL_PACKAGES_VIEW::OnDownloadVersionClicked( wxCommandEvent& event )
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
KICAD_SETTINGS* app_settings = mgr.GetAppSettings<KICAD_SETTINGS>();
wxFileDialog dialog( this, _( "Save Package" ), app_settings->m_PcmLastDownloadDir,
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxFileDialog dialog( topLevelParent, _( "Save Package" ), app_settings->m_PcmLastDownloadDir,
wxString::Format( wxT( "%s_v%s.zip" ), package.identifier, version ),
wxT( "ZIP files (*.zip)|*.zip" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 1992-2011 jean-pierre.charras
* Copyright (C) 1992-2023 Kicad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2024 Kicad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -154,8 +154,10 @@ void PANEL_REGULATOR::OnDataFileSelection( wxCommandEvent& event )
wildcard.Printf( _( "PCB Calculator data file" ) + wxT( " (*.%s)|*.%s" ),
DataFileNameExt, DataFileNameExt );
wxFileDialog dlg( this, _( "Select PCB Calculator Data File" ), wxEmptyString, fullfilename,
wildcard, wxFD_OPEN );
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxFileDialog dlg( topLevelParent, _( "Select PCB Calculator Data File" ),
wxEmptyString, fullfilename, wildcard, wxFD_OPEN );
if( dlg.ShowModal() == wxID_CANCEL )
return;

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2013-2021 CERN
* Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2012-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -957,9 +957,11 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
wxArrayString files;
wxWindow* topLevelParent = wxGetTopLevelParent( this );
if( fileDesc.m_IsFile )
{
wxFileDialog dlg( this, title, openDir, wxEmptyString, fileDesc.FileFilter(),
wxFileDialog dlg( topLevelParent, title, openDir, wxEmptyString, fileDesc.FileFilter(),
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
int result = dlg.ShowModal();
@ -976,7 +978,7 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
}
else
{
wxDirDialog dlg( nullptr, title, openDir,
wxDirDialog dlg( topLevelParent, title, openDir,
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST | wxDD_MULTIPLE );
int result = dlg.ShowModal();