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:
@@ -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 )
|
|
||||||
{
|
|
||||||
int colWidth = hcEvent->GetWidth();
|
|
||||||
|
|
||||||
OnSetColumnWidth(col, colWidth);
|
OnSetColumnWidth(col, colWidth);
|
||||||
OnColumWidthsChanged();
|
OnColumWidthsChanged();
|
||||||
|
|
||||||
pg->SendEvent(wxEVT_PG_COL_DRAGGING,
|
wxPropertyGrid* pg = m_manager->GetGrid();
|
||||||
NULL, NULL, 0,
|
pg->SendEvent(wxEVT_PG_COL_DRAGGING, NULL, NULL, 0,
|
||||||
(unsigned int)col);
|
(unsigned int)col);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if ( evtType == wxEVT_HEADER_BEGIN_RESIZE )
|
|
||||||
|
void OnBeginResize(wxHeaderCtrlEvent& evt)
|
||||||
{
|
{
|
||||||
|
int col = evt.GetColumn();
|
||||||
|
wxPropertyGrid* pg = m_manager->GetGrid();
|
||||||
|
|
||||||
// Don't allow resizing the rightmost column
|
// Don't allow resizing the rightmost column
|
||||||
// (like it's not allowed for the rightmost wxPropertyGrid splitter)
|
// (like it's not allowed for the rightmost wxPropertyGrid splitter)
|
||||||
if ( col == (int)m_page->GetColumnCount() - 1 )
|
if ( col == (int)m_page->GetColumnCount() - 1 )
|
||||||
hcEvent->Veto();
|
evt.Veto();
|
||||||
// Never allow column resize if layout is static
|
// Never allow column resize if layout is static
|
||||||
else if ( m_manager->HasFlag(wxPG_STATIC_SPLITTER) )
|
else if ( m_manager->HasFlag(wxPG_STATIC_SPLITTER) )
|
||||||
hcEvent->Veto();
|
evt.Veto();
|
||||||
// Allow application to veto dragging
|
// Allow application to veto dragging
|
||||||
else if ( pg->SendEvent(wxEVT_PG_COL_BEGIN_DRAG,
|
else if ( pg->SendEvent(wxEVT_PG_COL_BEGIN_DRAG,
|
||||||
NULL, NULL, 0,
|
NULL, NULL, 0,
|
||||||
(unsigned int)col) )
|
(unsigned int)col) )
|
||||||
hcEvent->Veto();
|
evt.Veto();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if ( evtType == wxEVT_HEADER_END_RESIZE )
|
|
||||||
|
void OnEndResize(wxHeaderCtrlEvent& evt)
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
|
Reference in New Issue
Block a user