X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e2bfe6731edfca732418012b03438db85b4aa0dd..fe79f76ba9aa2f89165481d7ed796f69df979875:/include/wx/headerctrl.h diff --git a/include/wx/headerctrl.h b/include/wx/headerctrl.h index 50c897137a..10ae50118c 100644 --- a/include/wx/headerctrl.h +++ b/include/wx/headerctrl.h @@ -13,6 +13,7 @@ #include "wx/control.h" +#include "wx/dynarray.h" #include "wx/vector.h" #include "wx/headercol.h" @@ -20,6 +21,7 @@ // notice that the classes in this header are defined in the core library even // although currently they're only used by wxGrid which is in wxAdv because we // plan to use it in wxListCtrl which is in core too in the future +class WXDLLIMPEXP_FWD_CORE wxHeaderCtrlEvent; // ---------------------------------------------------------------------------- // constants @@ -68,7 +70,7 @@ public: // set the number of columns in the control // // this also calls UpdateColumn() for all columns - void SetColumnCount(unsigned int count) { DoSetCount(count); } + void SetColumnCount(unsigned int count); // return the number of columns in the control as set by SetColumnCount() unsigned int GetColumnCount() const { return DoGetCount(); } @@ -84,6 +86,29 @@ public: DoUpdate(idx); } + // set the columns order: the array defines the column index which appears + // the given position, it must have GetColumnCount() elements and contain + // all indices exactly once + void SetColumnsOrder(const wxArrayInt& order); + wxArrayInt GetColumnsOrder() const; + + // get the index of the column at the given display position + unsigned int GetColumnAt(unsigned int pos) const; + + // get the position at which this column is currently displayed + unsigned int GetColumnPos(unsigned int idx) const; + + // reset the columns order to the natural one + void ResetColumnsOrder(); + + // helper function used by the generic version of this control and also + // wxGrid: reshuffles the array of column indices indexed by positions + // (i.e. using the same convention as for SetColumnsOrder()) so that the + // column with the given index is found at the specified position + static void MoveColumnInOrderArray(wxArrayInt& order, + unsigned int idx, + unsigned int pos); + // implementation only from now on // ------------------------------- @@ -99,7 +124,26 @@ public: protected: // this method must be implemented by the derived classes to return the // information for the given column - virtual wxHeaderColumnBase& GetColumn(unsigned int idx) = 0; + virtual wxHeaderColumn& GetColumn(unsigned int idx) = 0; + + // this method is called from the default EVT_HEADER_SEPARATOR_DCLICK + // handler to update the fitting column width of the given column, it + // should return true if the width was really updated + virtual bool UpdateColumnWidthToFit(unsigned int WXUNUSED(idx), + int WXUNUSED(widthTitle)) + { + return false; + } + + // this method can be overridden in the derived classes to do something + // (e.g. update/resize some internal data structures) before the number of + // columns in the control changes + virtual void OnColumnCountChanging(unsigned int WXUNUSED(count)) { } + + + // helper function for the derived classes: update the array of column + // indices after the number of columns changed + void DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int count); private: // methods implementing our public API and defined in platform-specific @@ -110,8 +154,16 @@ private: virtual void DoScrollHorz(int dx) = 0; + virtual void DoSetColumnsOrder(const wxArrayInt& order) = 0; + virtual wxArrayInt DoGetColumnsOrder() const = 0; + // this window doesn't look nice with the border so don't use it by default virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + + // event handlers + void OnSeparatorDClick(wxHeaderCtrlEvent& event); + + DECLARE_EVENT_TABLE() }; // ---------------------------------------------------------------------------- @@ -209,7 +261,17 @@ public: void RemoveSortIndicator(); protected: - virtual wxHeaderColumnBase& GetColumn(unsigned int idx); + // implement/override base class methods + virtual wxHeaderColumn& GetColumn(unsigned int idx); + virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle); + + // and define another one to be overridden in the derived classes: it + // should return the best width for the given column contents or -1 if not + // implemented, we use it to implement UpdateColumnWidthToFit() + virtual int GetBestFittingWidth(unsigned int WXUNUSED(idx)) const + { + return -1; + } private: // functions implementing our public API @@ -236,4 +298,103 @@ private: DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple) }; +// ---------------------------------------------------------------------------- +// wxHeaderCtrl events +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_CORE wxHeaderCtrlEvent : public wxNotifyEvent +{ +public: + wxHeaderCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) + : wxNotifyEvent(commandType, winid), + m_col(-1), + m_width(0), + m_order(static_cast(-1)) + { + } + + wxHeaderCtrlEvent(const wxHeaderCtrlEvent& event) + : wxNotifyEvent(event), + m_col(event.m_col), + m_width(event.m_width), + m_order(event.m_order) + { + } + + // the column which this event pertains to: valid for all header events + int GetColumn() const { return m_col; } + void SetColumn(int col) { m_col = col; } + + // the width of the column: valid for column resizing/dragging events only + int GetWidth() const { return m_width; } + void SetWidth(int width) { m_width = width; } + + // the new position of the column: for end reorder events only + unsigned int GetNewOrder() const { return m_order; } + void SetNewOrder(unsigned int order) { m_order = order; } + + virtual wxEvent *Clone() const { return new wxHeaderCtrlEvent(*this); } + +protected: + // the column affected by the event + int m_col; + + // the current width for the dragging events + int m_width; + + // the new column position for end reorder event + unsigned int m_order; + +private: + DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent) +}; + + +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_CLICK; +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK; +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK; + +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DCLICK; +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK; +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK; + +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; + +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_RESIZE; +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RESIZING; +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_RESIZE; + +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_REORDER; +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_REORDER; + +extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED; + +typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&); + +#define wxHeaderCtrlEventHandler(func) \ + (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \ + wxHeaderCtrlEventFunction, &func) + +#define wx__DECLARE_HEADER_EVT(evt, id, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn)) + +#define EVT_HEADER_CLICK(id, fn) wx__DECLARE_HEADER_EVT(CLICK, id, fn) +#define EVT_HEADER_RIGHT_CLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_CLICK, id, fn) +#define EVT_HEADER_MIDDLE_CLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_CLICK, id, fn) + +#define EVT_HEADER_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(DCLICK, id, fn) +#define EVT_HEADER_RIGHT_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_DCLICK, id, fn) +#define EVT_HEADER_MIDDLE_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_DCLICK, id, fn) + +#define EVT_HEADER_SEPARATOR_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(SEPARATOR_DCLICK, id, fn) + +#define EVT_HEADER_BEGIN_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_RESIZE, id, fn) +#define EVT_HEADER_RESIZING(id, fn) wx__DECLARE_HEADER_EVT(RESIZING, id, fn) +#define EVT_HEADER_END_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(END_RESIZE, id, fn) + +#define EVT_HEADER_BEGIN_REORDER(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_REORDER, id, fn) +#define EVT_HEADER_END_REORDER(id, fn) wx__DECLARE_HEADER_EVT(END_REORDER, id, fn) + +#define EVT_HEADER_DRAGGING_CANCELLED(id, fn) wx__DECLARE_HEADER_EVT(DRAGGING_CANCELLED, id, fn) + #endif // _WX_HEADERCTRL_H_