From 7399fdc3984930024085abfaaeb0a40617979111 Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Fri, 22 Jan 2010 19:59:27 +0000 Subject: [PATCH] improved focus handling, still need to handle the tab change --- pcbnew/layer_widget.cpp | 25 ++++++++++++++++++------- pcbnew/layer_widget.h | 12 +++++++++--- pcbnew/pcbframe.cpp | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/pcbnew/layer_widget.cpp b/pcbnew/layer_widget.cpp index c53a4a46b5..c411f37d66 100644 --- a/pcbnew/layer_widget.cpp +++ b/pcbnew/layer_widget.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "macros.h" #include "common.h" @@ -350,6 +351,15 @@ void LAYER_WIDGET::OnRenderCheckBox( wxCommandEvent& event ) } +void LAYER_WIDGET::OnTabChange( wxNotebookEvent& event ) +{ +// printf("OnTabChange\n"); +// passOnFocus(); // this segfaults, cannot enable it. + // maybe we need to find a way to call the stock tab change event handler + // first, then call passOnFocus() before we consider this event done. +} + + wxWindow* LAYER_WIDGET::getLayerComp( int aSizerNdx ) { if( (unsigned) aSizerNdx < m_LayersFlexGridSizer->GetChildren().GetCount() ) @@ -456,19 +466,16 @@ void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec ) void LAYER_WIDGET::passOnFocus() { - wxWindow* parent = GetParent(); - parent->SetFocus(); - -// printf( "passOnFocus() %p %p\n", parent, m_OriginalParent ); + m_FocusOwner->SetFocus(); } //------------------------------------------------------------ -LAYER_WIDGET::LAYER_WIDGET( wxWindow* parent ) : - LAYER_PANEL_BASE( parent ) +LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner ) : + LAYER_PANEL_BASE( aParent ) { - m_OriginalParent = parent; + m_FocusOwner = aFocusOwner; m_CurrentRow = -1; @@ -486,6 +493,10 @@ LAYER_WIDGET::LAYER_WIDGET( wxWindow* parent ) : Connect( ID_SHOW_ALL_COPPERS, ID_SHOW_NO_COPPERS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( LAYER_WIDGET::OnPopupSelection ), NULL, this ); + + // trap the tab changes so that we can call passOnFocus(). + m_notebook->Connect( -1, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, + wxNotebookEventHandler( LAYER_WIDGET::OnTabChange ) ); } diff --git a/pcbnew/layer_widget.h b/pcbnew/layer_widget.h index 911f60bc3d..5caca5d66e 100644 --- a/pcbnew/layer_widget.h +++ b/pcbnew/layer_widget.h @@ -74,7 +74,7 @@ public: protected: - wxWindow* m_OriginalParent; + wxWindow* m_FocusOwner; wxBitmap* m_BlankBitmap; wxBitmap* m_RightArrowBitmap; wxSize m_BitmapSize; @@ -116,6 +116,9 @@ protected: void OnRenderCheckBox( wxCommandEvent& event ); + void OnTabChange( wxNotebookEvent& event ); + + /** * Function getLayerComp * returns the component within the m_LayersFlexGridSizer at aSizerNdx or @@ -148,8 +151,11 @@ protected: public: - /** Constructor */ - LAYER_WIDGET( wxWindow* parent ); + /** Constructor + * @param aFocusOwner is the window that should be sent the focus after + * every operation. + */ + LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner ); /** * Function GetBestSize diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 7a5f6f3030..a9494db3d1 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -228,7 +228,7 @@ WinEDA_PcbFrame::WinEDA_PcbFrame( wxWindow* father, m_show_microwave_tools = false; m_show_layer_manager_tools = true; - m_Layers = new LYRS( this ); + m_Layers = new LYRS( this, DrawPanel ); SetBoard( new BOARD( NULL, this ) );