Refactor propgrid sample
Simplify implementation by creating panel and sizer holding wxPG instance only once in FormMain ctor.
This commit is contained in:
parent
81f8e8d742
commit
d9f8eec602
@ -1822,45 +1822,6 @@ wxEND_EVENT_TABLE()
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void FormMain::InitPanel()
|
||||
{
|
||||
if ( m_panel )
|
||||
m_panel->Destroy();
|
||||
|
||||
wxWindow* panel = new wxPanel(this, wxID_ANY,
|
||||
wxPoint(0, 0), wxSize(400, 400),
|
||||
wxTAB_TRAVERSAL);
|
||||
m_panel = panel;
|
||||
|
||||
// Column
|
||||
wxBoxSizer* topSizer = new wxBoxSizer ( wxVERTICAL );
|
||||
|
||||
m_topSizer = topSizer;
|
||||
}
|
||||
|
||||
void FormMain::FinalizePanel( bool wasCreated )
|
||||
{
|
||||
// Button for tab traversal testing
|
||||
m_topSizer->Add( new wxButton(m_panel, wxID_ANY,
|
||||
"Should be able to move here with Tab"),
|
||||
wxSizerFlags(0).Expand());
|
||||
m_topSizer->Add( new wxButton(m_panel, ID_SHOWPOPUP,
|
||||
"Show Popup"),
|
||||
wxSizerFlags(0).Expand());
|
||||
|
||||
m_panel->SetSizer( m_topSizer );
|
||||
m_topSizer->SetSizeHints( m_panel );
|
||||
|
||||
wxBoxSizer* panelSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
panelSizer->Add( m_panel, wxSizerFlags(1).Expand().FixedMinSize());
|
||||
|
||||
SetSizer( panelSizer );
|
||||
panelSizer->SetSizeHints( this );
|
||||
|
||||
if ( wasCreated )
|
||||
FinalizeFramePosition();
|
||||
}
|
||||
|
||||
void FormMain::PopulateGrid()
|
||||
{
|
||||
wxPropertyGridManager* pgman = m_pPropGridManager;
|
||||
@ -1911,10 +1872,6 @@ void FormMain::CreateGrid( int style, int extraStyle )
|
||||
//| wxPG_EX_GREY_LABEL_WHEN_DISABLED
|
||||
//| wxPG_EX_HELP_AS_TOOLTIPS
|
||||
|
||||
bool wasCreated = m_panel ? false : true;
|
||||
|
||||
InitPanel();
|
||||
|
||||
//
|
||||
// This shows how to combine two static choice descriptors
|
||||
m_combinedFlags.Add( WXSIZEOF(_fs_windowstyle_labels), _fs_windowstyle_labels, _fs_windowstyle_values );
|
||||
@ -1960,10 +1917,17 @@ void FormMain::CreateGrid( int style, int extraStyle )
|
||||
|
||||
//m_pPropGridManager->SetSplitterLeft(true);
|
||||
//m_pPropGridManager->SetSplitterPosition(137);
|
||||
}
|
||||
|
||||
m_topSizer->Add( m_pPropGridManager, wxSizerFlags(1).Expand());
|
||||
void FormMain::ReplaceGrid(int style, int extraStyle)
|
||||
{
|
||||
wxPropertyGridManager* pgmanOld = m_pPropGridManager;
|
||||
CreateGrid(style, extraStyle);
|
||||
m_topSizer->Replace(pgmanOld, m_pPropGridManager);
|
||||
pgmanOld->Destroy();
|
||||
m_pPropGridManager->SetFocus();
|
||||
|
||||
FinalizePanel(wasCreated);
|
||||
m_panel->Layout();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@ -1976,7 +1940,7 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size
|
||||
SetIcon(wxICON(sample));
|
||||
|
||||
m_propGrid = NULL;
|
||||
m_panel = NULL;
|
||||
m_pPropGridManager = NULL;
|
||||
m_hasHeader = false;
|
||||
m_labelEditingEnabled = false;
|
||||
|
||||
@ -1991,34 +1955,6 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size
|
||||
wxInitAllImageHandlers();
|
||||
#endif
|
||||
|
||||
// Register all editors (SpinCtrl etc.)
|
||||
wxPropertyGridInterface::RegisterAdditionalEditors();
|
||||
|
||||
// Register our sample custom editors
|
||||
m_pSampleMultiButtonEditor =
|
||||
wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
|
||||
|
||||
CreateGrid( // style
|
||||
wxPG_BOLD_MODIFIED |
|
||||
wxPG_SPLITTER_AUTO_CENTER |
|
||||
wxPG_AUTO_SORT |
|
||||
//wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
|
||||
//wxPG_TOOLTIPS |
|
||||
//wxPG_HIDE_CATEGORIES |
|
||||
//wxPG_LIMITED_EDITING |
|
||||
wxPG_TOOLBAR |
|
||||
wxPG_DESCRIPTION,
|
||||
// extra style
|
||||
#if wxALWAYS_NATIVE_DOUBLE_BUFFER
|
||||
wxPG_EX_NATIVE_DOUBLE_BUFFERING |
|
||||
#endif // wxALWAYS_NATIVE_DOUBLE_BUFFER
|
||||
wxPG_EX_MODE_BUTTONS |
|
||||
wxPG_EX_MULTIPLE_SELECTION
|
||||
//| wxPG_EX_AUTO_UNSPECIFIED_VALUES
|
||||
//| wxPG_EX_GREY_LABEL_WHEN_DISABLED
|
||||
//| wxPG_EX_HELP_AS_TOOLTIPS
|
||||
);
|
||||
|
||||
//
|
||||
// Create menu bar
|
||||
wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF);
|
||||
@ -2150,6 +2086,53 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size
|
||||
SetStatusText(wxEmptyString);
|
||||
#endif // wxUSE_STATUSBAR
|
||||
|
||||
// Register all editors (SpinCtrl etc.)
|
||||
wxPropertyGridInterface::RegisterAdditionalEditors();
|
||||
|
||||
// Register our sample custom editors
|
||||
m_pSampleMultiButtonEditor =
|
||||
wxPropertyGrid::RegisterEditorClass(new wxSampleMultiButtonEditor());
|
||||
|
||||
m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||
|
||||
CreateGrid( // style
|
||||
wxPG_BOLD_MODIFIED |
|
||||
wxPG_SPLITTER_AUTO_CENTER |
|
||||
wxPG_AUTO_SORT |
|
||||
//wxPG_HIDE_MARGIN|wxPG_STATIC_SPLITTER |
|
||||
//wxPG_TOOLTIPS |
|
||||
//wxPG_HIDE_CATEGORIES |
|
||||
//wxPG_LIMITED_EDITING |
|
||||
wxPG_TOOLBAR |
|
||||
wxPG_DESCRIPTION,
|
||||
// extra style
|
||||
#if wxALWAYS_NATIVE_DOUBLE_BUFFER
|
||||
wxPG_EX_NATIVE_DOUBLE_BUFFERING |
|
||||
#endif // wxALWAYS_NATIVE_DOUBLE_BUFFER
|
||||
wxPG_EX_MODE_BUTTONS |
|
||||
wxPG_EX_MULTIPLE_SELECTION
|
||||
//| wxPG_EX_AUTO_UNSPECIFIED_VALUES
|
||||
//| wxPG_EX_GREY_LABEL_WHEN_DISABLED
|
||||
//| wxPG_EX_HELP_AS_TOOLTIPS
|
||||
);
|
||||
|
||||
m_topSizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
m_topSizer->Add(m_pPropGridManager, wxSizerFlags(1).Expand());
|
||||
|
||||
// Button for tab traversal testing
|
||||
m_topSizer->Add(new wxButton(m_panel, wxID_ANY,
|
||||
"Should be able to move here with Tab"),
|
||||
wxSizerFlags(0).Expand());
|
||||
m_topSizer->Add(new wxButton(m_panel, ID_SHOWPOPUP,
|
||||
"Show Popup"),
|
||||
wxSizerFlags(0).Expand());
|
||||
|
||||
m_panel->SetSizer(m_topSizer);
|
||||
m_topSizer->SetSizeHints(m_panel);
|
||||
|
||||
m_panel->Layout();
|
||||
|
||||
FinalizeFramePosition();
|
||||
|
||||
#if wxUSE_LOGWINDOW
|
||||
@ -2933,9 +2916,7 @@ void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) )
|
||||
extraStyle = flags;
|
||||
}
|
||||
|
||||
CreateGrid( style, extraStyle );
|
||||
|
||||
FinalizeFramePosition();
|
||||
ReplaceGrid( style, extraStyle );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
@ -158,13 +158,12 @@ public:
|
||||
|
||||
|
||||
void CreateGrid( int style, int extraStyle );
|
||||
void ReplaceGrid(int style, int extraStyle);
|
||||
void FinalizeFramePosition();
|
||||
|
||||
// These are used in CreateGrid(), and in tests to compose
|
||||
// grids for testing purposes.
|
||||
void InitPanel();
|
||||
void PopulateGrid();
|
||||
void FinalizePanel( bool wasCreated = true );
|
||||
|
||||
void PopulateWithStandardItems();
|
||||
void PopulateWithExamples();
|
||||
|
@ -482,7 +482,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
}
|
||||
|
||||
// Recreate grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
@ -502,7 +502,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
}
|
||||
|
||||
// Recreate grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
@ -812,7 +812,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
// Test multiple selection
|
||||
RT_START_TEST(MULTIPLE_SELECTION)
|
||||
if ( !(pgman->GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION) )
|
||||
CreateGrid( -1, wxPG_EX_MULTIPLE_SELECTION);
|
||||
ReplaceGrid( -1, wxPG_EX_MULTIPLE_SELECTION);
|
||||
pgman = m_pPropGridManager;
|
||||
|
||||
pg = pgman->GetGrid();
|
||||
@ -942,7 +942,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
pg->EndLabelEdit(0);
|
||||
|
||||
// Recreate grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
@ -1231,7 +1231,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
enumProp->DeleteChoice(ind);
|
||||
|
||||
// Recreate the original grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
@ -1364,7 +1364,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
RT_FAILURE();
|
||||
|
||||
// Recreate the original grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
|
||||
// Grid clear
|
||||
@ -1375,33 +1375,24 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
RT_FAILURE();
|
||||
|
||||
// Recreate the original grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
{
|
||||
RT_START_TEST(SetSplitterPosition)
|
||||
|
||||
InitPanel();
|
||||
|
||||
const int trySplitterPos = 50;
|
||||
|
||||
int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
|
||||
pgman = m_pPropGridManager =
|
||||
new wxPropertyGridManager(m_panel, wxID_ANY,
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize,
|
||||
style );
|
||||
ReplaceGrid(style, -1);
|
||||
pgman = m_pPropGridManager;
|
||||
|
||||
PopulateGrid();
|
||||
pgman->SetSplitterPosition(trySplitterPos);
|
||||
|
||||
if ( pgman->GetGrid()->GetSplitterPosition() != trySplitterPos )
|
||||
RT_FAILURE_MSG(wxString::Format("Splitter position was %i (should have been %i)",(int)pgman->GetGrid()->GetSplitterPosition(),trySplitterPos));
|
||||
|
||||
m_topSizer->Add( m_pPropGridManager, wxSizerFlags(1).Expand());
|
||||
FinalizePanel();
|
||||
|
||||
wxSize origSz = GetSize();
|
||||
|
||||
wxSize sz = origSz;
|
||||
@ -1414,7 +1405,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
SetSize(origSz);
|
||||
|
||||
// Recreate the original grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
@ -1525,7 +1516,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
}
|
||||
|
||||
// Recreate the original grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
@ -1773,7 +1764,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
RT_START_TEST(MultipleColumns)
|
||||
|
||||
// Test with multiple columns
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
FinalizeFramePosition();
|
||||
pgman = m_pPropGridManager;
|
||||
for ( i=3; i<12; i+=2 )
|
||||
@ -1797,7 +1788,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
{
|
||||
int flag = 1<<i;
|
||||
RT_MSG(wxString::Format("Style: 0x%X",flag));
|
||||
CreateGrid( flag, -1 );
|
||||
ReplaceGrid( flag, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
Update();
|
||||
wxMilliSleep(500);
|
||||
@ -1809,14 +1800,14 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
|
||||
{
|
||||
int flag = 1<<i;
|
||||
RT_MSG(wxString::Format("ExStyle: 0x%X",flag));
|
||||
CreateGrid( -1, flag );
|
||||
ReplaceGrid( -1, flag );
|
||||
pgman = m_pPropGridManager;
|
||||
Update();
|
||||
wxMilliSleep(500);
|
||||
}
|
||||
|
||||
// Recreate the original grid
|
||||
CreateGrid( -1, -1 );
|
||||
ReplaceGrid( -1, -1 );
|
||||
pgman = m_pPropGridManager;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user