diff --git a/common/widgets/ui_common.cpp b/common/widgets/ui_common.cpp index 820768b7a8..851206fe10 100644 --- a/common/widgets/ui_common.cpp +++ b/common/widgets/ui_common.cpp @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include #include @@ -267,4 +270,39 @@ bool KIUI::IsInputControlEditable( wxWindow* aFocus ) bool KIUI::IsModalDialogFocused() { return Pgm().m_ModalDialogCount > 0; +} + + +void KIUI::Disable( wxWindow* aWindow ) +{ + wxScrollBar* scrollBar = dynamic_cast( aWindow ); + wxGrid* grid = dynamic_cast( aWindow ); + wxStyledTextCtrl* scintilla = dynamic_cast( aWindow ); + wxControl* control = dynamic_cast( aWindow ); + + if( scrollBar ) + { + // Leave a scroll bar active + } + else if( grid ) + { + for( int row = 0; row < grid->GetNumberRows(); ++row ) + { + for( int col = 0; col < grid->GetNumberCols(); ++col ) + grid->SetReadOnly( row, col ); + } + } + else if( scintilla ) + { + scintilla->SetReadOnly( true ); + } + else if( control ) + { + control->Disable(); + } + else + { + for( wxWindow* child : aWindow->GetChildren() ) + Disable( child ); + } } \ No newline at end of file diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index 512dcd2793..a24f84931a 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -87,16 +87,8 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : if( Prj().IsReadOnly() ) { - m_infoBar->ShowMessage( _( "Project is missing or read-only. " - "Settings will not be editable." ), - wxICON_WARNING ); - - m_formatting->Disable(); - m_fieldNameTemplates->Disable(); - m_severities->Disable(); - m_pinMap->Disable(); - m_netclasses->Disable(); - m_textVars->Disable(); + m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be " + "editable." ), wxICON_WARNING ); } } @@ -113,6 +105,8 @@ void DIALOG_SCHEMATIC_SETUP::OnPageChange( wxBookCtrlEvent& event ) { int page = event.GetSelection(); + KIUI::Disable( m_treebook->GetPage( page ) ); + // Enable the reset button only if the page is resettable if( m_resetButton ) { diff --git a/include/widgets/ui_common.h b/include/widgets/ui_common.h index b54ed4cf8d..4b4a811182 100644 --- a/include/widgets/ui_common.h +++ b/include/widgets/ui_common.h @@ -95,6 +95,12 @@ bool IsInputControlEditable( wxWindow* aControl ); bool IsModalDialogFocused(); +/** + * Makes a window read-only. Does some extra work over wxWindow::Disable() to make sure you + * can still scroll around in sub-windows. + */ +void Disable( wxWindow* aWindow ); + } SEVERITY SeverityFromString( const wxString& aSeverity ); diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index 2e52a79c30..41b6e5aaa1 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -113,25 +113,15 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : // Connect Events m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED, - wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), - nullptr, this ); + wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), nullptr, + this ); finishDialogSettings(); if( Prj().IsReadOnly() ) { - m_infoBar->ShowMessage( _( "Project is missing or read-only. " - "Some settings will not be editable." ), - wxICON_WARNING ); - - m_boardFinish->Disable(); - m_maskAndPaste->Disable(); - m_textAndGraphics->Disable(); - m_textVars->Disable(); - m_constraints->Disable(); - m_tracksAndVias->Disable(); - m_netclasses->Disable(); - m_severities->Disable(); + m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not " + "be editable." ), wxICON_WARNING ); } } @@ -139,23 +129,25 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : DIALOG_BOARD_SETUP::~DIALOG_BOARD_SETUP() { m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED, - wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), - nullptr, this ); + wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), nullptr, + this ); } void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event ) { - if( event.GetSelection() == m_physicalStackupPage ) + int page = event.GetSelection(); + + if( page == m_physicalStackupPage ) m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() ); - else if( event.GetSelection() == m_layerSetupPage ) + else if( page == m_layerSetupPage ) m_layers->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() ); + else + KIUI::Disable( m_treebook->GetPage( page ) ); #ifdef __WXMAC__ // Work around an OSX bug where the wxGrid children don't get placed correctly until // the first resize event - int page = event.GetSelection(); - if( m_macHack[ page ] ) { wxSize pageSize = m_treebook->GetPage( page )->GetSize();