X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f66553919504e2d24a1846960a547ff1fd52eb67..438959cca892a7651634cc3a7aad4819ac49b23c:/include/wx/headerctrl.h?ds=sidebyside diff --git a/include/wx/headerctrl.h b/include/wx/headerctrl.h index 10ae50118c..10c49e181e 100644 --- a/include/wx/headerctrl.h +++ b/include/wx/headerctrl.h @@ -13,6 +13,8 @@ #include "wx/control.h" +#if wxUSE_HEADERCTRL + #include "wx/dynarray.h" #include "wx/vector.h" @@ -30,10 +32,14 @@ class WXDLLIMPEXP_FWD_CORE wxHeaderCtrlEvent; enum { // allow column drag and drop - wxHD_DRAGDROP = 0x0001, + wxHD_ALLOW_REORDER = 0x0001, + + // allow hiding (and showing back) the columns using the menu shown by + // right clicking the header + wxHD_ALLOW_HIDE = 0x0002, // style used by default when creating the control - wxHD_DEFAULT_STYLE = wxHD_DRAGDROP + wxHD_DEFAULT_STYLE = wxHD_ALLOW_REORDER }; extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[]; @@ -86,6 +92,10 @@ public: DoUpdate(idx); } + + // columns order + // ------------- + // 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 @@ -110,6 +120,43 @@ public: unsigned int pos); + // UI helpers + // ---------- + +#if wxUSE_MENUS + // show the popup menu containing all columns with check marks for the ones + // which are currently shown and return true if something was done using it + // (in this case UpdateColumnVisibility() will have been called) or false + // if the menu was cancelled + // + // this is called from the default right click handler for the controls + // with wxHD_ALLOW_HIDE style + bool ShowColumnsMenu(const wxPoint& pt, const wxString& title = wxString()); + + // append the entries for all our columns to the given menu, with the + // currently visible columns being checked + // + // this is used by ShowColumnsMenu() but can also be used if you use your + // own custom columns menu but nevertheless want to show all the columns in + // it + // + // the ids of the items corresponding to the columns are consecutive and + // start from idColumnsBase + void AddColumnsItems(wxMenu& menu, int idColumnsBase = 0); +#endif // wxUSE_MENUS + + // show the columns customization dialog and return true if something was + // changed using it (in which case UpdateColumnVisibility() and/or + // UpdateColumnsOrder() will have been called) + // + // this is called by the control itself from ShowColumnsMenu() (which in + // turn is only called by the control if wxHD_ALLOW_HIDE style was + // specified) and if the control has wxHD_ALLOW_REORDER style as well + bool ShowCustomizeDialog(); + + // compute column title width + int GetColumnTitleWidth(const wxHeaderColumn& col); + // implementation only from now on // ------------------------------- @@ -124,7 +171,7 @@ public: protected: // this method must be implemented by the derived classes to return the // information for the given column - virtual wxHeaderColumn& GetColumn(unsigned int idx) = 0; + virtual const wxHeaderColumn& GetColumn(unsigned int idx) const = 0; // this method is called from the default EVT_HEADER_SEPARATOR_DCLICK // handler to update the fitting column width of the given column, it @@ -135,6 +182,24 @@ protected: return false; } + // this method is called from ShowColumnsMenu() and must be overridden to + // update the internal column visibility (there is no need to call + // UpdateColumn() from here, this will be done internally) + virtual void UpdateColumnVisibility(unsigned int WXUNUSED(idx), + bool WXUNUSED(show)) + { + wxFAIL_MSG( "must be overridden if called" ); + } + + // this method is called from ShowCustomizeDialog() to reorder all columns + // at once and should be implemented for controls using wxHD_ALLOW_REORDER + // style (there is no need to call SetColumnsOrder() from here, this is + // done by the control itself) + virtual void UpdateColumnsOrder(const wxArrayInt& WXUNUSED(order)) + { + wxFAIL_MSG( "must be overridden if called" ); + } + // 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 @@ -145,6 +210,10 @@ protected: // indices after the number of columns changed void DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int count); +protected: + // this window doesn't look nice with the border so don't use it by default + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + private: // methods implementing our public API and defined in platform-specific // implementations @@ -157,11 +226,12 @@ private: 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); +#if wxUSE_MENUS + void OnRClick(wxHeaderCtrlEvent& event); +#endif // wxUSE_MENUS DECLARE_EVENT_TABLE() }; @@ -262,7 +332,7 @@ public: protected: // implement/override base class methods - virtual wxHeaderColumn& GetColumn(unsigned int idx); + virtual const wxHeaderColumn& GetColumn(unsigned int idx) const; virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle); // and define another one to be overridden in the derived classes: it @@ -284,7 +354,10 @@ private: void Init(); // bring the column count in sync with the number of columns we store - void UpdateColumnCount() { SetColumnCount(m_cols.size()); } + void UpdateColumnCount() + { + SetColumnCount(static_cast(m_cols.size())); + } // all our current columns @@ -295,7 +368,7 @@ private: unsigned int m_sortKey; - DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple) + wxDECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple); }; // ---------------------------------------------------------------------------- @@ -350,33 +423,32 @@ private: }; -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; +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_CLICK, wxHeaderCtrlEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_RIGHT_CLICK, wxHeaderCtrlEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_MIDDLE_CLICK, wxHeaderCtrlEvent ); -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; +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_DCLICK, wxHeaderCtrlEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_RIGHT_DCLICK, wxHeaderCtrlEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_MIDDLE_DCLICK, wxHeaderCtrlEvent ); -extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_SEPARATOR_DCLICK, wxHeaderCtrlEvent ); -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; +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_BEGIN_RESIZE, wxHeaderCtrlEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_RESIZING, wxHeaderCtrlEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_END_RESIZE, wxHeaderCtrlEvent ); -extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_REORDER; -extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_REORDER; +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_BEGIN_REORDER, wxHeaderCtrlEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_END_REORDER, wxHeaderCtrlEvent ); -extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED; +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HEADER_DRAGGING_CANCELLED, wxHeaderCtrlEvent ); typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&); #define wxHeaderCtrlEventHandler(func) \ - (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \ - wxHeaderCtrlEventFunction, &func) + wxEVENT_HANDLER_CAST(wxHeaderCtrlEventFunction, func) #define wx__DECLARE_HEADER_EVT(evt, id, fn) \ - wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn)) + wx__DECLARE_EVT1(wxEVT_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) @@ -397,4 +469,21 @@ typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&); #define EVT_HEADER_DRAGGING_CANCELLED(id, fn) wx__DECLARE_HEADER_EVT(DRAGGING_CANCELLED, id, fn) +// old wxEVT_COMMAND_* constants +#define wxEVT_COMMAND_HEADER_CLICK wxEVT_HEADER_CLICK +#define wxEVT_COMMAND_HEADER_RIGHT_CLICK wxEVT_HEADER_RIGHT_CLICK +#define wxEVT_COMMAND_HEADER_MIDDLE_CLICK wxEVT_HEADER_MIDDLE_CLICK +#define wxEVT_COMMAND_HEADER_DCLICK wxEVT_HEADER_DCLICK +#define wxEVT_COMMAND_HEADER_RIGHT_DCLICK wxEVT_HEADER_RIGHT_DCLICK +#define wxEVT_COMMAND_HEADER_MIDDLE_DCLICK wxEVT_HEADER_MIDDLE_DCLICK +#define wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK wxEVT_HEADER_SEPARATOR_DCLICK +#define wxEVT_COMMAND_HEADER_BEGIN_RESIZE wxEVT_HEADER_BEGIN_RESIZE +#define wxEVT_COMMAND_HEADER_RESIZING wxEVT_HEADER_RESIZING +#define wxEVT_COMMAND_HEADER_END_RESIZE wxEVT_HEADER_END_RESIZE +#define wxEVT_COMMAND_HEADER_BEGIN_REORDER wxEVT_HEADER_BEGIN_REORDER +#define wxEVT_COMMAND_HEADER_END_REORDER wxEVT_HEADER_END_REORDER +#define wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED wxEVT_HEADER_DRAGGING_CANCELLED + +#endif // wxUSE_HEADERCTRL + #endif // _WX_HEADERCTRL_H_