+ wxGrid *GetOwner() const { return static_cast<wxGrid *>(GetParent()); }
+
+ // override the base class method to update our m_columns array
+ virtual void OnColumnCountChanging(unsigned int count)
+ {
+ const unsigned countOld = m_columns.size();
+ if ( count < countOld )
+ {
+ // just discard the columns which don't exist any more (notice that
+ // we can't use resize() here as it would require the vector
+ // value_type, i.e. wxGridHeaderColumn to be default constructible,
+ // which it is not)
+ m_columns.erase(m_columns.begin() + count, m_columns.end());
+ }
+ else // new columns added
+ {
+ // add columns for the new elements
+ for ( unsigned n = countOld; n < count; n++ )
+ m_columns.push_back(wxGridHeaderColumn(GetOwner(), n));
+ }
+ }
+
+ // override to implement column auto sizing
+ virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
+ {
+ // TODO: currently grid doesn't support computing the column best width
+ // from its contents so we just use the best label width as is
+ GetOwner()->SetColSize(idx, widthTitle);
+
+ return true;
+ }
+
+ // overridden to react to the actions using the columns popup menu
+ virtual void UpdateColumnVisibility(unsigned int idx, bool show)
+ {
+ GetOwner()->SetColSize(idx, show ? wxGRID_AUTOSIZE : 0);
+
+ // as this is done by the user we should notify the main program about
+ // it
+ GetOwner()->SendEvent(wxEVT_GRID_COL_SIZE, -1, idx);
+ }
+
+ // overridden to react to the columns order changes in the customization
+ // dialog
+ virtual void UpdateColumnsOrder(const wxArrayInt& order)
+ {
+ GetOwner()->SetColumnsOrder(order);
+ }
+
+
+ // event handlers forwarding wxHeaderCtrl events to wxGrid
+ void OnClick(wxHeaderCtrlEvent& event)
+ {
+ GetOwner()->DoColHeaderClick(event.GetColumn());
+ }
+
+ void OnBeginResize(wxHeaderCtrlEvent& event)
+ {
+ GetOwner()->DoStartResizeCol(event.GetColumn());
+
+ event.Skip();
+ }
+
+ void OnResizing(wxHeaderCtrlEvent& event)
+ {
+ GetOwner()->DoUpdateResizeColWidth(event.GetWidth());
+ }
+
+ void OnEndResize(wxHeaderCtrlEvent& event)
+ {
+ GetOwner()->DoEndDragResizeCol();
+
+ event.Skip();
+ }
+
+ void OnBeginReorder(wxHeaderCtrlEvent& event)
+ {
+ GetOwner()->DoStartMoveCol(event.GetColumn());
+ }
+
+ void OnEndReorder(wxHeaderCtrlEvent& event)
+ {
+ GetOwner()->DoEndMoveCol(event.GetNewOrder());
+ }
+
+ wxVector<wxGridHeaderColumn> m_columns;
+
+ DECLARE_EVENT_TABLE()
+ DECLARE_NO_COPY_CLASS(wxGridHeaderCtrl)
+};
+
+BEGIN_EVENT_TABLE(wxGridHeaderCtrl, wxHeaderCtrl)
+ EVT_HEADER_CLICK(wxID_ANY, wxGridHeaderCtrl::OnClick)
+
+ EVT_HEADER_BEGIN_RESIZE(wxID_ANY, wxGridHeaderCtrl::OnBeginResize)
+ EVT_HEADER_RESIZING(wxID_ANY, wxGridHeaderCtrl::OnResizing)
+ EVT_HEADER_END_RESIZE(wxID_ANY, wxGridHeaderCtrl::OnEndResize)
+
+ EVT_HEADER_BEGIN_REORDER(wxID_ANY, wxGridHeaderCtrl::OnBeginReorder)
+ EVT_HEADER_END_REORDER(wxID_ANY, wxGridHeaderCtrl::OnEndReorder)
+END_EVENT_TABLE()
+
+// common base class for various grid subwindows
+class WXDLLIMPEXP_ADV wxGridSubwindow : public wxWindow
+{
+public:
+ wxGridSubwindow(wxGrid *owner,
+ int additionalStyle = 0,
+ const wxString& name = wxPanelNameStr)
+ : wxWindow(owner, wxID_ANY,
+ wxDefaultPosition, wxDefaultSize,
+ wxBORDER_NONE | additionalStyle,
+ name)
+ {
+ m_owner = owner;
+ }
+
+ virtual bool AcceptsFocus() const { return false; }