From 2b1bf369f2caad50dc0ecae8d715998a8fd6a793 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 2 Feb 2024 09:20:36 -0500 Subject: [PATCH] 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. --- common/dialogs/panel_common_settings.cpp | 8 +++++--- common/widgets/wx_html_report_panel.cpp | 6 ++++-- eeschema/dialogs/panel_sym_lib_table.cpp | 6 ++++-- kicad/pcm/dialogs/panel_packages_view.cpp | 5 +++-- pcb_calculator/calculator_panels/panel_regulator.cpp | 8 +++++--- pcbnew/dialogs/panel_fp_lib_table.cpp | 8 +++++--- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/common/dialogs/panel_common_settings.cpp b/common/dialogs/panel_common_settings.cpp index 49e81447c8..41bab0e854 100644 --- a/common/dialogs/panel_common_settings.cpp +++ b/common/dialogs/panel_common_settings.cpp @@ -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; diff --git a/common/widgets/wx_html_report_panel.cpp b/common/widgets/wx_html_report_panel.cpp index 8c50688dff..25b50ababd 100644 --- a/common/widgets/wx_html_report_panel.cpp +++ b/common/widgets/wx_html_report_panel.cpp @@ -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 * * 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 ) diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index bb80f61a0e..ae9993b414 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2017 Wayne Stambaugh * 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 ) diff --git a/kicad/pcm/dialogs/panel_packages_view.cpp b/kicad/pcm/dialogs/panel_packages_view.cpp index 391c41403d..32a0ac92fa 100644 --- a/kicad/pcm/dialogs/panel_packages_view.cpp +++ b/kicad/pcm/dialogs/panel_packages_view.cpp @@ -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(); - 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 ); diff --git a/pcb_calculator/calculator_panels/panel_regulator.cpp b/pcb_calculator/calculator_panels/panel_regulator.cpp index f558a774fb..31513855c3 100644 --- a/pcb_calculator/calculator_panels/panel_regulator.cpp +++ b/pcb_calculator/calculator_panels/panel_regulator.cpp @@ -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; diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index 9b4fe9c19d..85fc2ab1aa 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * 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();