+ bool SendEvent(wxEventType type, unsigned int n)
+ {
+ wxDataViewCtrl * const owner = GetOwner();
+ wxDataViewEvent event(type, owner->GetId());
+
+ event.SetEventObject(owner);
+ event.SetColumn(n);
+ event.SetDataViewColumn(owner->GetColumn(n));
+ event.SetModel(owner->GetModel());
+
+ // for events created by wxDataViewHeaderWindow the
+ // row / value fields are not valid
+ return owner->GetEventHandler()->ProcessEvent(event);
+ }
+
+ void OnClick(wxHeaderCtrlEvent& event)
+ {
+ const unsigned idx = event.GetColumn();
+
+ if ( SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, idx) )
+ return;
+
+ // default handling for the column click is to sort by this column or
+ // toggle its sort order
+ wxDataViewCtrl * const owner = GetOwner();
+ wxDataViewColumn * const col = owner->GetColumn(idx);
+ if ( !col->IsSortable() )
+ {
+ // no default handling for non-sortable columns
+ event.Skip();
+ return;
+ }
+
+ if ( col->IsSortKey() )
+ {
+ // already using this column for sorting, just change the order
+ col->ToggleSortOrder();
+ }
+ else // not using this column for sorting yet
+ {
+ // first unset the old sort column if any
+ int oldSortKey = owner->GetSortingColumnIndex();
+ if ( oldSortKey != wxNOT_FOUND )
+ {
+ owner->GetColumn(oldSortKey)->UnsetAsSortKey();
+ owner->OnColumnChange(oldSortKey);
+ }
+
+ owner->SetSortingColumnIndex(idx);
+ col->SetAsSortKey();
+ }
+
+ wxDataViewModel * const model = owner->GetModel();
+ if ( model )
+ model->Resort();
+
+ owner->OnColumnChange(idx);
+ }
+
+ void OnRClick(wxHeaderCtrlEvent& event)
+ {
+ if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,
+ event.GetColumn()) )
+ event.Skip();
+ }
+
+ void OnEndResize(wxHeaderCtrlEvent& event)
+ {
+ wxDataViewCtrl * const owner = GetOwner();
+
+ const unsigned col = event.GetColumn();
+ owner->GetColumn(col)->SetWidth(event.GetWidth());
+ GetOwner()->OnColumnChange(col);
+ }
+
+ void OnEndReorder(wxHeaderCtrlEvent& event)
+ {
+ wxDataViewCtrl * const owner = GetOwner();
+ owner->ColumnMoved(owner->GetColumn(event.GetColumn()),
+ event.GetNewOrder());
+ }
+
+ DECLARE_EVENT_TABLE()