diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index 7fc0b6a989..b896aad986 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -102,6 +102,16 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo int pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize(); int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ); + m_layersOuterSizer = new wxBoxSizer( wxVERTICAL ); + m_windowLayers->SetSizer( m_layersOuterSizer ); + m_windowLayers->SetScrollRate( 0, 5 ); + m_windowLayers->Bind( wxEVT_SET_FOCUS, &APPEARANCE_CONTROLS::OnSetFocus, this ); + + m_objectsOuterSizer = new wxBoxSizer( wxVERTICAL ); + m_windowObjects->SetSizer( m_objectsOuterSizer ); + m_windowObjects->SetScrollRate( 0, 5 ); + m_windowObjects->Bind( wxEVT_SET_FOCUS, &APPEARANCE_CONTROLS::OnSetFocus, this ); + m_btnNetInspector->SetBitmapLabel( KiBitmap( list_nets_xpm ) ); m_btnConfigureNetClasses->SetBitmapLabel( KiBitmap( options_generic_xpm ) ); @@ -173,6 +183,8 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo m_paneLayerDisplay->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); + m_currentLayer = F_Cu; + loadDefaultLayerPresets(); rebuildObjects(); OnBoardChanged(); @@ -240,6 +252,22 @@ void APPEARANCE_CONTROLS::OnNotebookPageChanged( wxNotebookEvent& aEvent ) m_sizerOuter->Layout(); Thaw(); #endif + + Bind( wxEVT_IDLE, &APPEARANCE_CONTROLS::idleFocusHandler, this ); +} + + +void APPEARANCE_CONTROLS::idleFocusHandler( wxIdleEvent& aEvent ) +{ + passOnFocus(); + Unbind( wxEVT_IDLE, &APPEARANCE_CONTROLS::idleFocusHandler, this ); +} + + +void APPEARANCE_CONTROLS::OnSetFocus( wxFocusEvent& aEvent ) +{ + passOnFocus(); + aEvent.Skip(); } @@ -316,23 +344,19 @@ void APPEARANCE_CONTROLS::OnLayerChanged() PCB_LAYER_ID current = m_frame->GetActiveLayer(); - for( std::unique_ptr& setting : m_layerSettings ) - { - LAYER_NUM layer = setting->id; + wxASSERT( m_layerSettingsMap.count( current ) ); + wxASSERT( m_layerSettingsMap.count( m_currentLayer ) ); - if( setting->ctl_panel ) - { - setting->ctl_panel->SetBackgroundColour( current == layer ? - highlightColor : normalColor ); - } + APPEARANCE_SETTING* oldSetting = m_layerSettingsMap.at( m_currentLayer ); + APPEARANCE_SETTING* newSetting = m_layerSettingsMap.at( current ); - if( setting->ctl_indicator ) - { - setting->ctl_indicator->SetIndicatorState( current == layer ? - ROW_ICON_PROVIDER::STATE::ON : - ROW_ICON_PROVIDER::STATE::OFF ); - } - } + oldSetting->ctl_panel->SetBackgroundColour( normalColor ); + newSetting->ctl_panel->SetBackgroundColour( highlightColor ); + + oldSetting->ctl_indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::OFF ); + newSetting->ctl_indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::ON ); + + m_currentLayer = current; #if defined( __WXMAC__ ) || defined( __WXMSW__ ) Refresh(); @@ -516,7 +540,7 @@ void APPEARANCE_CONTROLS::rebuildLayers() #endif m_layerSettings.clear(); - m_layers_outer_sizer->Clear( true ); + m_layersOuterSizer->Clear( true ); auto appendLayer = [&]( std::unique_ptr& aSetting ) @@ -560,7 +584,7 @@ void APPEARANCE_CONTROLS::rebuildLayers() sizer->AddSpacer( 5 ); sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxTOP, topMargin ); - m_layers_outer_sizer->Add( panel, 0, wxEXPAND, 0 ); + m_layersOuterSizer->Add( panel, 0, wxEXPAND, 0 ); aSetting->ctl_panel = panel; aSetting->ctl_indicator = indicator; @@ -593,6 +617,7 @@ void APPEARANCE_CONTROLS::rebuildLayers() { wxASSERT( m_layerContextMenu ); PopupMenu( m_layerContextMenu ); + passOnFocus(); }; panel->Bind( wxEVT_RIGHT_DOWN, rightClickHandler ); @@ -688,7 +713,8 @@ void APPEARANCE_CONTROLS::rebuildLayers() #endif } - m_layers_outer_sizer->Layout(); + m_layersOuterSizer->AddSpacer( 10 ); + m_windowLayers->Layout(); } @@ -909,6 +935,7 @@ void APPEARANCE_CONTROLS::onLayerClick( wxMouseEvent& aEvent ) #endif m_frame->SetActiveLayer( layer ); + passOnFocus(); } @@ -996,8 +1023,8 @@ void APPEARANCE_CONTROLS::rebuildObjects() int labelWidth = 0; m_objectSettings.clear(); - m_objectsSizer->Clear( true ); - m_objectsSizer->AddSpacer( 5 ); + m_objectsOuterSizer->Clear( true ); + m_objectsOuterSizer->AddSpacer( 5 ); auto appendObject = [&]( const std::unique_ptr& aSetting ) @@ -1090,6 +1117,7 @@ void APPEARANCE_CONTROLS::rebuildObjects() slider->Bind( wxEVT_SCROLL_CHANGED, opacitySliderHandler ); slider->Bind( wxEVT_SCROLL_THUMBTRACK, opacitySliderHandler ); + slider->Bind( wxEVT_SET_FOCUS, &APPEARANCE_CONTROLS::OnSetFocus, this ); } else { @@ -1099,8 +1127,8 @@ void APPEARANCE_CONTROLS::rebuildObjects() } aSetting->ctl_text = label; - m_objectsSizer->Add( sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 ); - m_objectsSizer->AddSpacer( 1 ); + m_objectsOuterSizer->Add( sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 ); + m_objectsOuterSizer->AddSpacer( 1 ); }; for( const APPEARANCE_SETTING& s_setting : s_objectSettings ) @@ -1136,12 +1164,12 @@ void APPEARANCE_CONTROLS::rebuildObjects() for( const std::unique_ptr& setting : m_objectSettings ) { if( setting->spacer ) - m_objectsSizer->AddSpacer( m_pointSize ); + m_objectsOuterSizer->AddSpacer( m_pointSize ); else appendObject( setting ); } - m_objectsSizer->Layout(); + m_objectsOuterSizer->Layout(); } diff --git a/pcbnew/widgets/appearance_controls.h b/pcbnew/widgets/appearance_controls.h index 7e677a0ab8..28e1fd18b3 100644 --- a/pcbnew/widgets/appearance_controls.h +++ b/pcbnew/widgets/appearance_controls.h @@ -157,6 +157,8 @@ protected: void OnNotebookPageChanged( wxNotebookEvent& event ) override; + void OnSetFocus( wxFocusEvent& aEvent ) override; + private: PCB_BASE_FRAME* m_frame; @@ -168,6 +170,8 @@ private: BOARD* m_board; + PCB_LAYER_ID m_currentLayer; + std::vector> m_layerSettings; std::map m_layerSettingsMap; @@ -202,6 +206,9 @@ private: /// The name of the netclass that was right-clicked wxString m_contextMenuNetclass; + wxBoxSizer* m_layersOuterSizer; + wxBoxSizer* m_objectsOuterSizer; + // The built-in layer presets static LAYER_PRESET presetNoLayers; @@ -288,6 +295,8 @@ private: void handleBoardItemsChanged(); void passOnFocus(); + + void idleFocusHandler( wxIdleEvent& aEvent ); }; #endif diff --git a/pcbnew/widgets/appearance_controls_base.cpp b/pcbnew/widgets/appearance_controls_base.cpp index 78e114f00f..45449d662f 100644 --- a/pcbnew/widgets/appearance_controls_base.cpp +++ b/pcbnew/widgets/appearance_controls_base.cpp @@ -20,17 +20,8 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID m_panelLayers = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_panelLayersSizer = new wxBoxSizer( wxVERTICAL ); - m_windowLayers = new wxScrolledWindow( m_panelLayers, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); - m_windowLayers->SetScrollRate( 0, 5 ); - m_windowLayers->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); - - m_layers_outer_sizer = new wxBoxSizer( wxVERTICAL ); - - - m_windowLayers->SetSizer( m_layers_outer_sizer ); - m_windowLayers->Layout(); - m_layers_outer_sizer->Fit( m_windowLayers ); - m_panelLayersSizer->Add( m_windowLayers, 1, wxEXPAND|wxTOP, 5 ); + m_windowLayers = new wxScrolledCanvas( m_panelLayers, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL ); + m_panelLayersSizer->Add( m_windowLayers, 1, wxEXPAND, 5 ); m_paneLayerDisplay = new wxCollapsiblePane( m_panelLayers, wxID_ANY, wxT("Layer Display Options"), wxDefaultPosition, wxDefaultSize, wxCP_DEFAULT_STYLE|wxCP_NO_TLW_RESIZE ); m_paneLayerDisplay->Collapse( true ); @@ -86,16 +77,7 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID m_objectsPanelSizer = new wxBoxSizer( wxVERTICAL ); - m_windowObjects = new wxScrolledWindow( m_panelObjects, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); - m_windowObjects->SetScrollRate( 0, 5 ); - m_windowObjects->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); - - m_objectsSizer = new wxBoxSizer( wxVERTICAL ); - - - m_windowObjects->SetSizer( m_objectsSizer ); - m_windowObjects->Layout(); - m_objectsSizer->Fit( m_windowObjects ); + m_windowObjects = new wxScrolledCanvas( m_panelObjects, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL ); m_objectsPanelSizer->Add( m_windowObjects, 1, wxEXPAND, 5 ); @@ -268,20 +250,42 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID m_sizerOuter->Fit( this ); // Connect Events + this->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ) ); m_notebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( APPEARANCE_CONTROLS_BASE::OnNotebookPageChanged ), NULL, this ); + m_notebook->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelLayers->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_paneLayerDisplay->Connect( wxEVT_COLLAPSIBLEPANE_CHANGED, wxCollapsiblePaneEventHandler( APPEARANCE_CONTROLS_BASE::OnLayerDisplayPaneChanged ), NULL, this ); + m_paneLayerDisplay->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_cbFlipBoard->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( APPEARANCE_CONTROLS_BASE::OnFlipBoardChecked ), NULL, this ); + m_panelObjects->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelNetsAndClasses->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelNets->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_btnNetInspector->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelNetclasses->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_btnConfigureNetClasses->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_paneNetDisplay->Connect( wxEVT_COLLAPSIBLEPANE_CHANGED, wxCollapsiblePaneEventHandler( APPEARANCE_CONTROLS_BASE::OnNetDisplayPaneChanged ), NULL, this ); + m_paneNetDisplay->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_cbLayerPresets->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( APPEARANCE_CONTROLS_BASE::onLayerPresetChanged ), NULL, this ); } APPEARANCE_CONTROLS_BASE::~APPEARANCE_CONTROLS_BASE() { // Disconnect Events + this->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ) ); m_notebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( APPEARANCE_CONTROLS_BASE::OnNotebookPageChanged ), NULL, this ); + m_notebook->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelLayers->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_paneLayerDisplay->Disconnect( wxEVT_COLLAPSIBLEPANE_CHANGED, wxCollapsiblePaneEventHandler( APPEARANCE_CONTROLS_BASE::OnLayerDisplayPaneChanged ), NULL, this ); + m_paneLayerDisplay->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_cbFlipBoard->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( APPEARANCE_CONTROLS_BASE::OnFlipBoardChecked ), NULL, this ); + m_panelObjects->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelNetsAndClasses->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelNets->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_btnNetInspector->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_panelNetclasses->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); + m_btnConfigureNetClasses->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_paneNetDisplay->Disconnect( wxEVT_COLLAPSIBLEPANE_CHANGED, wxCollapsiblePaneEventHandler( APPEARANCE_CONTROLS_BASE::OnNetDisplayPaneChanged ), NULL, this ); + m_paneNetDisplay->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ), NULL, this ); m_cbLayerPresets->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( APPEARANCE_CONTROLS_BASE::onLayerPresetChanged ), NULL, this ); } diff --git a/pcbnew/widgets/appearance_controls_base.fbp b/pcbnew/widgets/appearance_controls_base.fbp index f472cdc3e6..d466a8c945 100644 --- a/pcbnew/widgets/appearance_controls_base.fbp +++ b/pcbnew/widgets/appearance_controls_base.fbp @@ -49,6 +49,7 @@ wxTAB_TRAVERSAL + OnSetFocus m_sizerOuter @@ -112,10 +113,11 @@ OnNotebookPageChanged + OnSetFocus Layers - 0 + 1 1 1 @@ -167,6 +169,7 @@ wxTAB_TRAVERSAL + OnSetFocus m_panelLayersSizer @@ -174,9 +177,9 @@ protected 5 - wxEXPAND|wxTOP + wxEXPAND 1 - + 1 1 1 @@ -186,13 +189,16 @@ - wxSYS_COLOUR_WINDOW + 1 0 + wxScrolledCanvas 1 + 1 + 0 Dock 0 @@ -204,6 +210,7 @@ 0 0 wxID_ANY + #include <wx/scrolwin.h> 0 @@ -219,8 +226,7 @@ 1 Resizable - 0 - 5 + 1 ; ; forward_declare @@ -228,13 +234,7 @@ - wxHSCROLL|wxVSCROLL - - - m_layers_outer_sizer - wxVERTICAL - protected - + wxVSCROLL @@ -300,6 +300,7 @@ OnLayerDisplayPaneChanged + OnSetFocus bSizer121 @@ -753,6 +754,7 @@ wxTAB_TRAVERSAL + OnSetFocus m_objectsPanelSizer @@ -762,7 +764,7 @@ 5 wxEXPAND 1 - + 1 1 1 @@ -772,13 +774,16 @@ - wxSYS_COLOUR_WINDOW + 1 0 + wxScrolledCanvas 1 + 1 + 0 Dock 0 @@ -790,6 +795,7 @@ 0 0 wxID_ANY + #include <wx/scrolwin.h> 0 @@ -805,8 +811,7 @@ 1 Resizable - 0 - 5 + 1 ; ; forward_declare @@ -814,13 +819,7 @@ - wxHSCROLL|wxVSCROLL - - - m_objectsSizer - wxVERTICAL - protected - + wxVSCROLL @@ -829,7 +828,7 @@ Nets - 1 + 0 1 1 @@ -881,6 +880,7 @@ wxTAB_TRAVERSAL + OnSetFocus bSizer16 @@ -999,6 +999,7 @@ wxTAB_TRAVERSAL + OnSetFocus bSizer192 @@ -1208,6 +1209,7 @@ + OnSetFocus @@ -1332,6 +1334,7 @@ wxTAB_TRAVERSAL + OnSetFocus bSizer21 @@ -1477,6 +1480,7 @@ + OnSetFocus @@ -1614,6 +1618,7 @@ OnNetDisplayPaneChanged + OnSetFocus bSizer1211 diff --git a/pcbnew/widgets/appearance_controls_base.h b/pcbnew/widgets/appearance_controls_base.h index 460a0a54af..7c75b965bc 100644 --- a/pcbnew/widgets/appearance_controls_base.h +++ b/pcbnew/widgets/appearance_controls_base.h @@ -9,15 +9,15 @@ #include #include -#include -#include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -47,8 +47,7 @@ class APPEARANCE_CONTROLS_BASE : public wxPanel wxNotebook* m_notebook; wxPanel* m_panelLayers; wxBoxSizer* m_panelLayersSizer; - wxScrolledWindow* m_windowLayers; - wxBoxSizer* m_layers_outer_sizer; + wxScrolledCanvas* m_windowLayers; wxCollapsiblePane* m_paneLayerDisplay; wxStaticText* m_staticText13; wxRadioButton* m_rbHighContrastNormal; @@ -58,8 +57,7 @@ class APPEARANCE_CONTROLS_BASE : public wxPanel wxCheckBox* m_cbFlipBoard; wxPanel* m_panelObjects; wxBoxSizer* m_objectsPanelSizer; - wxScrolledWindow* m_windowObjects; - wxBoxSizer* m_objectsSizer; + wxScrolledCanvas* m_windowObjects; wxPanel* m_panelNetsAndClasses; wxSplitterWindow* m_netsTabSplitter; wxPanel* m_panelNets; @@ -82,6 +80,7 @@ class APPEARANCE_CONTROLS_BASE : public wxPanel wxChoice* m_cbLayerPresets; // Virtual event handlers, overide them in your derived class + virtual void OnSetFocus( wxFocusEvent& event ) { event.Skip(); } virtual void OnNotebookPageChanged( wxNotebookEvent& event ) { event.Skip(); } virtual void OnLayerDisplayPaneChanged( wxCollapsiblePaneEvent& event ) { event.Skip(); } virtual void OnFlipBoardChecked( wxCommandEvent& event ) { event.Skip(); }