X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1bb7462687e4ce250372f6201a92a155a6f67af6..382818261588a4578a09c5cdc7a250af1e63199e:/include/wx/headerctrl.h diff --git a/include/wx/headerctrl.h b/include/wx/headerctrl.h index 512171a3db..64ca3c4540 100644 --- a/include/wx/headerctrl.h +++ b/include/wx/headerctrl.h @@ -30,10 +30,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 +90,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 @@ -98,6 +106,9 @@ public: // 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 @@ -107,6 +118,39 @@ public: unsigned int pos); + // UI helpers + // ---------- + + // 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); + + // 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(); + + // implementation only from now on // ------------------------------- @@ -121,7 +165,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 @@ -132,11 +176,34 @@ 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 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 // implementations @@ -154,6 +221,7 @@ private: // event handlers void OnSeparatorDClick(wxHeaderCtrlEvent& event); + void OnRClick(wxHeaderCtrlEvent& event); DECLARE_EVENT_TABLE() }; @@ -254,7 +322,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