From fa35fdc60046ed0f3af24ac8148a71d5966714eb Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 27 Apr 2019 20:35:39 +0200 Subject: [PATCH] Preserve header and label editing mode while recreating the grid For some operations when grid needs to be recreated currently selected options to show the header and to enable label editing are being ignored and it can be seen a discrepancy between the options selected (and shown) in the menu and the mode of just created wxPropertyGrid. To avoid this inconsistency respective flags can be stored and used to enable/disable features in just created grid. --- samples/propgrid/propgrid.cpp | 20 ++++++++++++++++---- samples/propgrid/propgrid.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 640e93d3c2..a07bd17147 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -1958,6 +1958,13 @@ void FormMain::CreateGrid( int style, int extraStyle ) PopulateGrid(); + m_propGrid->MakeColumnEditable(0, m_labelEditingEnabled); + m_pPropGridManager->ShowHeader(m_hasHeader); + if ( m_hasHeader ) + { + m_pPropGridManager->SetColumnTitle(2, "Units"); + } + // Change some attributes in all properties //pgman->SetPropertyAttributeAll(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING,true); @@ -1980,6 +1987,8 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size m_propGrid = NULL; m_panel = NULL; + m_hasHeader = false; + m_labelEditingEnabled = false; #ifdef __WXMAC__ // we need this in order to allow the about menu relocation, since ABOUT is @@ -2102,10 +2111,12 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size "Select window style flags used by the grid."); menuTry->AppendCheckItem(ID_ENABLELABELEDITING, "Enable label editing", "This calls wxPropertyGrid::MakeColumnEditable(0)"); + menuTry->Check(ID_ENABLELABELEDITING, m_labelEditingEnabled); #if wxUSE_HEADERCTRL menuTry->AppendCheckItem(ID_SHOWHEADER, "Enable header", "This calls wxPropertyGridManager::ShowHeader()"); + menuTry->Check(ID_SHOWHEADER, m_hasHeader); #endif // wxUSE_HEADERCTRL menuTry->AppendSeparator(); menuTry->AppendRadioItem( ID_COLOURSCHEME1, "Standard Colour Scheme" ); @@ -2692,7 +2703,8 @@ void FormMain::OnFreezeClick( wxCommandEvent& event ) void FormMain::OnEnableLabelEditing(wxCommandEvent& event) { - m_propGrid->MakeColumnEditable(0, event.IsChecked()); + m_labelEditingEnabled = event.IsChecked(); + m_propGrid->MakeColumnEditable(0, m_labelEditingEnabled); } // ----------------------------------------------------------------------- @@ -2700,9 +2712,9 @@ void FormMain::OnEnableLabelEditing(wxCommandEvent& event) #if wxUSE_HEADERCTRL void FormMain::OnShowHeader( wxCommandEvent& event ) { - bool show = event.IsChecked(); - m_pPropGridManager->ShowHeader(show); - if ( show ) + m_hasHeader = event.IsChecked(); + m_pPropGridManager->ShowHeader(m_hasHeader); + if ( m_hasHeader ) { m_pPropGridManager->SetColumnTitle(2, "Units"); } diff --git a/samples/propgrid/propgrid.h b/samples/propgrid/propgrid.h index 7827ed3395..e20115b0b8 100644 --- a/samples/propgrid/propgrid.h +++ b/samples/propgrid/propgrid.h @@ -153,6 +153,8 @@ public: wxVariant m_storedValues; wxString m_savedState; + bool m_hasHeader; + bool m_labelEditingEnabled; void CreateGrid( int style, int extraStyle );