From c7bbbeed63845afed62f31540dcdf7cd682a6f72 Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Sat, 30 Jan 2010 17:42:22 +0000 Subject: [PATCH] enhance getLayerComp()'s params --- pcbnew/layer_widget.cpp | 52 ++++++++++++++++++++--------------------- pcbnew/layer_widget.h | 12 +++++----- pcbnew/pcbframe.cpp | 6 ++--- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/pcbnew/layer_widget.cpp b/pcbnew/layer_widget.cpp index 80581f878b..6c663174a6 100644 --- a/pcbnew/layer_widget.cpp +++ b/pcbnew/layer_widget.cpp @@ -191,7 +191,7 @@ void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event ) if( row >= rowCount ) row = rowCount - 1; - layer = getDecodedId( getLayerComp( row * LYR_COLUMN_COUNT )->GetId() ); + layer = getDecodedId( getLayerComp( row, 0 )->GetId() ); } else @@ -287,10 +287,11 @@ void LAYER_WIDGET::OnTabChange( wxNotebookEvent& event ) } -wxWindow* LAYER_WIDGET::getLayerComp( int aSizerNdx ) +wxWindow* LAYER_WIDGET::getLayerComp( int aRow, int aColumn ) { - if( (unsigned) aSizerNdx < m_LayersFlexGridSizer->GetChildren().GetCount() ) - return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow(); + int ndx = aRow * LYR_COLUMN_COUNT + aColumn; + if( (unsigned) ndx < m_LayersFlexGridSizer->GetChildren().GetCount() ) + return m_LayersFlexGridSizer->GetChildren()[ndx]->GetWindow(); return NULL; } @@ -301,7 +302,7 @@ int LAYER_WIDGET::findLayerRow( int aLayer ) for( int row=0; rowGetId() )) @@ -311,10 +312,11 @@ int LAYER_WIDGET::findLayerRow( int aLayer ) } -wxWindow* LAYER_WIDGET::getRenderComp( int aSizerNdx ) +wxWindow* LAYER_WIDGET::getRenderComp( int aRow, int aColumn ) { - if( (unsigned) aSizerNdx < m_RenderFlexGridSizer->GetChildren().GetCount() ) - return m_RenderFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow(); + int ndx = aRow * RND_COLUMN_COUNT + aColumn; + if( (unsigned) ndx < m_RenderFlexGridSizer->GetChildren().GetCount() ) + return m_RenderFlexGridSizer->GetChildren()[ndx]->GetWindow(); return NULL; } @@ -325,7 +327,7 @@ int LAYER_WIDGET::findRenderRow( int aId ) for( int row=0; rowGetId() )) @@ -644,16 +646,11 @@ void LAYER_WIDGET::SelectLayerRow( int aRow ) // enable the layer tab at index 0 m_notebook->SetSelection( 0 ); - int oldNdx = LYR_COLUMN_COUNT * m_CurrentRow; - int newNdx = LYR_COLUMN_COUNT * aRow; - - m_CurrentRow = aRow; - - wxStaticBitmap* oldbm = (wxStaticBitmap*) getLayerComp( oldNdx ); + wxStaticBitmap* oldbm = (wxStaticBitmap*) getLayerComp( m_CurrentRow, 0 ); if( oldbm ) oldbm->SetBitmap( *m_BlankBitmap ); - wxStaticBitmap* newbm = (wxStaticBitmap*) getLayerComp( newNdx ); + wxStaticBitmap* newbm = (wxStaticBitmap*) getLayerComp( aRow, 0 ); if( newbm ) { newbm->SetBitmap( *m_RightArrowBitmap ); @@ -663,9 +660,11 @@ void LAYER_WIDGET::SelectLayerRow( int aRow ) // I don't expect the scrolling to be needed at all because // the minimum window size may end up being established so that the // scroll bars will not be visible. - getLayerComp( newNdx + 1 /* 1 is column */ )->SetFocus(); + getLayerComp( aRow, 1 )->SetFocus(); } + m_CurrentRow = aRow; + // give the focus back to the app. passOnFocus(); } @@ -680,10 +679,9 @@ void LAYER_WIDGET::SelectLayer( int aLayer ) int LAYER_WIDGET::GetSelectedLayer() { - // column 0 in the layer scroll window has a wxStaticBitmap, get its ID. - wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( m_CurrentRow * LYR_COLUMN_COUNT ); - if( bm ) - return getDecodedId( bm->GetId() ); + wxWindow* w = getLayerComp( m_CurrentRow, 0 ); + if( w ) + return getDecodedId( w->GetId() ); return -1; } @@ -694,7 +692,7 @@ void LAYER_WIDGET::SetLayerVisible( int aLayer, bool isVisible ) int row = findLayerRow( aLayer ); if( row >= 0 ) { - wxCheckBox* cb = (wxCheckBox*) getLayerComp( row * LYR_COLUMN_COUNT + 3 ); + wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, 3 ); wxASSERT( cb ); cb->SetValue( isVisible ); // does not fire an event } @@ -706,7 +704,7 @@ bool LAYER_WIDGET::IsLayerVisible( int aLayer ) int row = findLayerRow( aLayer ); if( row >= 0 ) { - wxCheckBox* cb = (wxCheckBox*) getLayerComp( row * LYR_COLUMN_COUNT + 3 ); + wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, 3 ); wxASSERT( cb ); return cb->GetValue(); } @@ -720,7 +718,7 @@ void LAYER_WIDGET::SetLayerColor( int aLayer, int aColor ) if( row >= 0 ) { int col = 1; // bitmap button is column 1 - wxBitmapButton* bmb = (wxBitmapButton*) getLayerComp( row * LYR_COLUMN_COUNT + col ); + wxBitmapButton* bmb = (wxBitmapButton*) getLayerComp( row, col ); wxASSERT( bmb ); wxBitmap bm = makeBitmap( aColor ); @@ -737,7 +735,7 @@ int LAYER_WIDGET::GetLayerColor( int aLayer ) if( row >= 0 ) { int col = 1; // bitmap button is column 1 - wxBitmapButton* bmb = (wxBitmapButton*) getLayerComp( row * LYR_COLUMN_COUNT + col ); + wxBitmapButton* bmb = (wxBitmapButton*) getLayerComp( row, col ); wxASSERT( bmb ); wxString colorTxt = bmb->GetName(); @@ -755,7 +753,7 @@ void LAYER_WIDGET::SetRenderState( int aId, bool isSet ) if( row >= 0 ) { int col = 1; // checkbox is column 1 - wxCheckBox* cb = (wxCheckBox*) getRenderComp( row * RND_COLUMN_COUNT + col ); + wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col ); wxASSERT( cb ); cb->SetValue( isSet ); // does not fire an event } @@ -768,7 +766,7 @@ bool LAYER_WIDGET::GetRenderState( int aId ) if( row >= 0 ) { int col = 1; // checkbox is column 1 - wxCheckBox* cb = (wxCheckBox*) getRenderComp( row * RND_COLUMN_COUNT + col ); + wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col ); wxASSERT( cb ); return cb->GetValue(); } diff --git a/pcbnew/layer_widget.h b/pcbnew/layer_widget.h index d54751bf18..37e38b5717 100644 --- a/pcbnew/layer_widget.h +++ b/pcbnew/layer_widget.h @@ -155,14 +155,14 @@ protected: /** * Function getLayerComp - * returns the component within the m_LayersFlexGridSizer at aSizerNdx or - * NULL if \a aSizerNdx is out of range. + * returns the component within the m_LayersFlexGridSizer at aRow and aCol + * or NULL if \a these parameters are out of range. * - * @param aSizerNdx is the 0 based index into all the wxWindows which have - * been added to the m_LayersFlexGridSizer. + * @param aRow is the row index + * @param aColumn is the column */ - wxWindow* getLayerComp( int aSizerNdx ); - wxWindow* getRenderComp( int aSizerNdx ); + wxWindow* getLayerComp( int aRow, int aColumn ); + wxWindow* getRenderComp( int aRow, int aColumn ); /** * Function findLayerRow diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index dcf08df127..345e123c1c 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -169,7 +169,7 @@ void PCB_LAYER_WIDGET::installRightLayerClickHandler() { for( int col=0; colConnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PCB_LAYER_WIDGET::onRightDownLayers ), NULL, this ); @@ -214,7 +214,7 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) rowCount = GetLayerRowCount(); for( int row=rowCount-1; row>=0; --row ) { - wxCheckBox* cb = (wxCheckBox*) getLayerComp( row*LYR_COLUMN_COUNT + 3 ); + wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, 3 ); int layer = getDecodedId( cb->GetId() ); if( IsValidCopperLayerIndex( layer ) ) { @@ -225,7 +225,7 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) for( int row=0; rowGetId() ); if( IsValidCopperLayerIndex( layer ) )