Use separate event handlers to handle individual wxPGHeaderCtrl events

The code to handle events split into separate functions dedicated to handle the events of specific type is more readable than the code concentrated in one function handling all kinds of events.
This commit is contained in:
Artur Wieczorek
2019-05-21 23:11:43 +02:00
parent 5fc0af423e
commit e45c6b0dd1

View File

@@ -239,6 +239,10 @@ public:
// Seed titles with defaults // Seed titles with defaults
m_columns[0]->SetTitle(_("Property")); m_columns[0]->SetTitle(_("Property"));
m_columns[1]->SetTitle(_("Value")); m_columns[1]->SetTitle(_("Value"));
Bind(wxEVT_HEADER_RESIZING, &wxPGHeaderCtrl::OnResizing, this);
Bind(wxEVT_HEADER_BEGIN_RESIZE, &wxPGHeaderCtrl::OnBeginResize, this);
Bind(wxEVT_HEADER_END_RESIZE, &wxPGHeaderCtrl::OnEndResize, this);
} }
virtual ~wxPGHeaderCtrl() virtual ~wxPGHeaderCtrl()
@@ -352,56 +356,45 @@ private:
wxPG_SPLITTER_FROM_EVENT); wxPG_SPLITTER_FROM_EVENT);
} }
virtual bool ProcessEvent( wxEvent& event ) wxOVERRIDE void OnResizing(wxHeaderCtrlEvent& evt)
{ {
wxHeaderCtrlEvent* hcEvent = wxDynamicCast(&event, wxHeaderCtrlEvent); int col = evt.GetColumn();
if ( hcEvent ) int colWidth = evt.GetWidth();
{
wxPropertyGrid* pg = m_manager->GetGrid();
int col = hcEvent->GetColumn();
wxEventType evtType = event.GetEventType();
if ( evtType == wxEVT_HEADER_RESIZING ) OnSetColumnWidth(col, colWidth);
{ OnColumWidthsChanged();
int colWidth = hcEvent->GetWidth();
OnSetColumnWidth(col, colWidth); wxPropertyGrid* pg = m_manager->GetGrid();
OnColumWidthsChanged(); pg->SendEvent(wxEVT_PG_COL_DRAGGING, NULL, NULL, 0,
(unsigned int)col);
}
pg->SendEvent(wxEVT_PG_COL_DRAGGING, void OnBeginResize(wxHeaderCtrlEvent& evt)
NULL, NULL, 0, {
(unsigned int)col); int col = evt.GetColumn();
wxPropertyGrid* pg = m_manager->GetGrid();
return true; // Don't allow resizing the rightmost column
} // (like it's not allowed for the rightmost wxPropertyGrid splitter)
else if ( evtType == wxEVT_HEADER_BEGIN_RESIZE ) if ( col == (int)m_page->GetColumnCount() - 1 )
{ evt.Veto();
// Don't allow resizing the rightmost column // Never allow column resize if layout is static
// (like it's not allowed for the rightmost wxPropertyGrid splitter) else if ( m_manager->HasFlag(wxPG_STATIC_SPLITTER) )
if ( col == (int)m_page->GetColumnCount() - 1 ) evt.Veto();
hcEvent->Veto(); // Allow application to veto dragging
// Never allow column resize if layout is static else if ( pg->SendEvent(wxEVT_PG_COL_BEGIN_DRAG,
else if ( m_manager->HasFlag(wxPG_STATIC_SPLITTER) ) NULL, NULL, 0,
hcEvent->Veto(); (unsigned int)col) )
// Allow application to veto dragging evt.Veto();
else if ( pg->SendEvent(wxEVT_PG_COL_BEGIN_DRAG, }
NULL, NULL, 0,
(unsigned int)col) )
hcEvent->Veto();
return true; void OnEndResize(wxHeaderCtrlEvent& evt)
} {
else if ( evtType == wxEVT_HEADER_END_RESIZE ) int col = evt.GetColumn();
{ wxPropertyGrid* pg = m_manager->GetGrid();
pg->SendEvent(wxEVT_PG_COL_END_DRAG, pg->SendEvent(wxEVT_PG_COL_END_DRAG,
NULL, NULL, 0, NULL, NULL, 0,
(unsigned int)col); (unsigned int)col);
return true;
}
}
return wxHeaderCtrl::ProcessEvent(event);
} }
wxPropertyGridManager* m_manager; wxPropertyGridManager* m_manager;