diff --git a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp index 1b2028d4d3..07f6f96eca 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp +++ b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp @@ -118,10 +118,7 @@ int EDA_3D_CONTROLLER::Main( const TOOL_EVENT& aEvent ) if( evt->IsCancelInteractive() ) { wxWindow* canvas = m_toolMgr->GetToolHolder()->GetToolCanvas(); - wxWindow* topLevelParent = canvas->GetParent(); - - while( topLevelParent && !topLevelParent->IsTopLevel() ) - topLevelParent = topLevelParent->GetParent(); + wxWindow* topLevelParent = wxGetTopLevelParent( canvas->GetParent() ); if( topLevelParent && dynamic_cast( topLevelParent ) ) { diff --git a/common/widgets/color_swatch.cpp b/common/widgets/color_swatch.cpp index f4ed61c673..335970143d 100644 --- a/common/widgets/color_swatch.cpp +++ b/common/widgets/color_swatch.cpp @@ -200,10 +200,7 @@ COLOR_SWATCH::COLOR_SWATCH( wxWindow* aParent, wxWindowID aID, const wxPoint& aP void COLOR_SWATCH::setupEvents( bool aTriggerWithSingleClick ) { - wxWindow* topLevelParent = GetParent(); - - while( topLevelParent && !topLevelParent->IsTopLevel() ) - topLevelParent = topLevelParent->GetParent(); + wxWindow* topLevelParent = wxGetTopLevelParent( GetParent() ); if( topLevelParent && dynamic_cast( topLevelParent ) ) { diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index 52d6a631f7..e98cbc0f25 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.cpp @@ -37,6 +37,7 @@ #include #include #include +#include "wx/app.h" constexpr int RECENT_SEARCHES_MAX = 10; @@ -610,10 +611,7 @@ void LIB_TREE::showPreview( wxDataViewItem aItem ) { m_hoverItem = aItem; - wxWindow* topLevelParent = m_parent; - - while( topLevelParent && !topLevelParent->IsTopLevel() ) - topLevelParent = topLevelParent->GetParent(); + wxWindow* topLevelParent = wxGetTopLevelParent( m_parent ); m_previewWindow = new wxPopupWindow( topLevelParent ); m_previewWindow->SetPosition( wxPoint( m_tree_ctrl->GetScreenRect().GetRight() - 10, @@ -647,15 +645,8 @@ void LIB_TREE::onIdle( wxIdleEvent& aEvent ) // The wxDataViewCtrl won't give us its mouseMoved events so we're forced to use idle // events to track the hover state - wxWindow* topLevelParent = m_parent; - - while( topLevelParent && !topLevelParent->IsTopLevel() ) - topLevelParent = topLevelParent->GetParent(); - - wxWindow* topLevelFocus = FindFocus(); - - while( topLevelFocus && !topLevelFocus->IsTopLevel() ) - topLevelFocus = topLevelFocus->GetParent(); + wxWindow* topLevelParent = wxGetTopLevelParent( m_parent ); + wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() ); wxPoint screenPos = wxGetMousePosition(); wxRect screenRect = m_tree_ctrl->GetScreenRect();