diff --git a/common/properties/pg_editors.cpp b/common/properties/pg_editors.cpp index acc15f6d20..1401291fee 100644 --- a/common/properties/pg_editors.cpp +++ b/common/properties/pg_editors.cpp @@ -26,6 +26,7 @@ #include const wxString PG_UNIT_EDITOR::EDITOR_NAME = wxS( "KiCadUnitEditor" ); +const wxString PG_CHECKBOX_EDITOR::EDITOR_NAME = wxS( "KiCadCheckboxEditor" ); PG_UNIT_EDITOR::PG_UNIT_EDITOR( EDA_DRAW_FRAME* aFrame ) : @@ -187,3 +188,22 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr return changed; } + + +PG_CHECKBOX_EDITOR::PG_CHECKBOX_EDITOR() : + wxPGCheckBoxEditor() +{ +} + + +wxPGWindowList PG_CHECKBOX_EDITOR::CreateControls( wxPropertyGrid* aGrid, wxPGProperty* aProperty, + const wxPoint& aPos, const wxSize& aSize ) const +{ + // Override wx behavior and toggle unspecified checkboxes to "true" + // CreateControls for a checkbox editor is only triggered when the user activates the checkbox + // Set the value to false here; the base class will then trigger an event setting it true. + if( aProperty->IsValueUnspecified() ) + aProperty->SetValueFromInt( 0 ); + + return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize ); +} diff --git a/common/properties/pg_properties.cpp b/common/properties/pg_properties.cpp index c9735d926d..e2e6cc2937 100644 --- a/common/properties/pg_properties.cpp +++ b/common/properties/pg_properties.cpp @@ -139,8 +139,7 @@ wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty ) } else if( typeId == TYPE_HASH( bool ) ) { - ret = new wxBoolProperty(); - ret->SetAttribute( wxPG_BOOL_USE_CHECKBOX, true ); + ret = new PGPROPERTY_BOOL(); } else if( typeId == TYPE_HASH( wxString ) ) { @@ -348,3 +347,18 @@ bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aStr aVariant = EscapeString( aString, CTX_QUOTED_STR ); return true; } + + +PGPROPERTY_BOOL::PGPROPERTY_BOOL( const wxString& aLabel, const wxString& aName, bool aValue ) : + wxBoolProperty( aLabel, aName, aValue ) +{ + SetEditor( PG_CHECKBOX_EDITOR::EDITOR_NAME ); +} + + +const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const +{ + wxCHECK_MSG( m_customEditor, wxPGEditor_CheckBox, + wxT( "Make sure to set custom editor for PGPROPERTY_BOOL!" ) ); + return m_customEditor; +} diff --git a/include/properties/pg_editors.h b/include/properties/pg_editors.h index 1208018c17..f8c35ca3bd 100644 --- a/include/properties/pg_editors.h +++ b/include/properties/pg_editors.h @@ -64,4 +64,20 @@ protected: std::unique_ptr m_unitBinder; }; + +class PG_CHECKBOX_EDITOR : public wxPGCheckBoxEditor +{ +public: + static const wxString EDITOR_NAME; + + PG_CHECKBOX_EDITOR(); + + virtual ~PG_CHECKBOX_EDITOR() {} + + wxString GetName() const override { return EDITOR_NAME; } + + wxPGWindowList CreateControls( wxPropertyGrid* aGrid, wxPGProperty* aProperty, + const wxPoint& aPos, const wxSize& aSize ) const override; +}; + #endif //KICAD_PG_EDITORS_H diff --git a/include/properties/pg_properties.h b/include/properties/pg_properties.h index f3b25138c5..7e2a9d449c 100644 --- a/include/properties/pg_properties.h +++ b/include/properties/pg_properties.h @@ -169,4 +169,16 @@ public: int aFlags = 0 ) const override; }; + +class PGPROPERTY_BOOL : public wxBoolProperty +{ +public: + PGPROPERTY_BOOL( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL, + bool aValue = false ); + + virtual ~PGPROPERTY_BOOL() = default; + + const wxPGEditor* DoGetEditorClass() const override; +}; + #endif /* PG_PROPERTIES_H */ diff --git a/pcbnew/widgets/pcb_properties_panel.cpp b/pcbnew/widgets/pcb_properties_panel.cpp index b66711bfad..16c92dc873 100644 --- a/pcbnew/widgets/pcb_properties_panel.cpp +++ b/pcbnew/widgets/pcb_properties_panel.cpp @@ -50,15 +50,23 @@ PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* a if( it != wxPGGlobalVars->m_mapEditorClasses.end() ) { - m_editor = static_cast( it->second ); - m_editor->UpdateFrame( m_frame ); + m_unitEditorInstance = static_cast( it->second ); + m_unitEditorInstance->UpdateFrame( m_frame ); found = true; } if( !found ) { PG_UNIT_EDITOR* new_editor = new PG_UNIT_EDITOR( m_frame ); - m_editor = static_cast( wxPropertyGrid::RegisterEditorClass( new_editor ) ); + m_unitEditorInstance = static_cast( wxPropertyGrid::RegisterEditorClass( new_editor ) ); + } + + it = wxPGGlobalVars->m_mapEditorClasses.find( PG_CHECKBOX_EDITOR::EDITOR_NAME ); + + if( it == wxPGGlobalVars->m_mapEditorClasses.end() ) + { + PG_CHECKBOX_EDITOR* cbEditor = new PG_CHECKBOX_EDITOR(); + m_checkboxEditorInstance = static_cast( wxPropertyGrid::RegisterEditorClass( cbEditor ) ); } } @@ -66,7 +74,7 @@ PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* a PCB_PROPERTIES_PANEL::~PCB_PROPERTIES_PANEL() { - m_editor->UpdateFrame( nullptr ); + m_unitEditorInstance->UpdateFrame( nullptr ); } diff --git a/pcbnew/widgets/pcb_properties_panel.h b/pcbnew/widgets/pcb_properties_panel.h index 8cd346bb98..dd8e66a8ec 100644 --- a/pcbnew/widgets/pcb_properties_panel.h +++ b/pcbnew/widgets/pcb_properties_panel.h @@ -28,6 +28,7 @@ class BOARD; class PCB_EDIT_FRAME; class PROPERTY_MANAGER; class PG_UNIT_EDITOR; +class PG_CHECKBOX_EDITOR; class PCB_PROPERTIES_PANEL : public PROPERTIES_PANEL { @@ -52,7 +53,8 @@ protected: PCB_EDIT_FRAME* m_frame; PROPERTY_MANAGER& m_propMgr; - PG_UNIT_EDITOR* m_editor; + PG_UNIT_EDITOR* m_unitEditorInstance; + PG_CHECKBOX_EDITOR* m_checkboxEditorInstance; wxPGChoices m_nets; };