headercol.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/headercol.h
  3. // Purpose: interface of wxHeaderColumn
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-12-01
  6. // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. /**
  10. Column width special values.
  11. */
  12. enum
  13. {
  14. /// Special value used for column width meaning unspecified or default.
  15. wxCOL_WIDTH_DEFAULT = -1,
  16. /**
  17. Size the column automatically to fit all values.
  18. @note On OS X, this style is only implemented in the Cocoa build on
  19. OS X >= 10.5; it behaves identically to wxCOL_WIDTH_DEFAULT otherwise.
  20. */
  21. wxCOL_WIDTH_AUTOSIZE = -2
  22. };
  23. /**
  24. Bit flags used as wxHeaderColumn flags.
  25. */
  26. enum
  27. {
  28. /// Column can be resized (included in default flags).
  29. wxCOL_RESIZABLE = 1,
  30. /// Column can be clicked to toggle the sort order by its contents.
  31. wxCOL_SORTABLE = 2,
  32. /// Column can be dragged to change its order (included in default).
  33. wxCOL_REORDERABLE = 4,
  34. /// Column is not shown at all.
  35. wxCOL_HIDDEN = 8,
  36. /// Default flags for wxHeaderColumn ctor.
  37. wxCOL_DEFAULT_FLAGS = wxCOL_RESIZABLE | wxCOL_REORDERABLE
  38. };
  39. /**
  40. @class wxHeaderColumn
  41. Represents a column header in controls displaying tabular data such as
  42. wxDataViewCtrl or wxGrid.
  43. Notice that this is an abstract base class which is implemented (usually
  44. using the information stored in the associated control) by the different
  45. controls using wxHeaderCtrl. As the control only needs to retrieve the
  46. information about the column, this class defines only the methods for
  47. accessing the various column properties but not for changing them as the
  48. setters might not be needed at all, e.g. if the column attributes can only
  49. be changed via the methods of the main associated control (this is the case
  50. for wxGrid for example). If you do want to allow changing them directly
  51. using the column itself, you should inherit from wxSettableHeaderColumn
  52. instead of this class.
  53. Finally, if you don't already store the column information at all anywhere,
  54. you should use the concrete wxHeaderColumnSimple class and
  55. wxHeaderCtrlSimple.
  56. @library{wxcore}
  57. @category{ctrl}
  58. */
  59. class wxHeaderColumn
  60. {
  61. public:
  62. /**
  63. Get the text shown in the column header.
  64. */
  65. virtual wxString GetTitle() const = 0;
  66. /**
  67. Returns the bitmap in the header of the column, if any.
  68. If the column has no associated bitmap, wxNullBitmap should be returned.
  69. */
  70. virtual wxBitmap GetBitmap() const = 0;
  71. /**
  72. Returns the current width of the column.
  73. @return
  74. Width of the column in pixels, never wxCOL_WIDTH_DEFAULT or
  75. wxCOL_WIDTH_AUTOSIZE.
  76. */
  77. virtual int GetWidth() const = 0;
  78. /**
  79. Return the minimal column width.
  80. @return
  81. The minimal width such that the user can't resize the column to
  82. lesser size (notice that it is still possible to set the column
  83. width to smaller value from the program code). Return 0 from here
  84. to allow resizing the column to arbitrarily small size.
  85. */
  86. virtual int GetMinWidth() const = 0;
  87. /**
  88. Returns the current column alignment.
  89. @return
  90. One of wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT.
  91. */
  92. virtual wxAlignment GetAlignment() const = 0;
  93. /**
  94. Get the column flags.
  95. This method retrieves all the flags at once, you can also use HasFlag()
  96. to test for any individual flag or IsResizeable(), IsSortable(),
  97. IsReorderable() and IsHidden() to test for particular flags.
  98. */
  99. virtual int GetFlags() const = 0;
  100. /**
  101. Return @true if the specified flag is currently set for this column.
  102. */
  103. bool HasFlag(int flag) const;
  104. /**
  105. Return true if the column can be resized by the user.
  106. Equivalent to HasFlag(wxCOL_RESIZABLE).
  107. */
  108. virtual bool IsResizeable() const;
  109. /**
  110. Returns @true if the column can be clicked by user to sort the control
  111. contents by the field in this column.
  112. This corresponds to wxCOL_SORTABLE flag which is off by default.
  113. */
  114. virtual bool IsSortable() const;
  115. /**
  116. Returns @true if the column can be dragged by user to change its order.
  117. This corresponds to wxCOL_REORDERABLE flag which is on by default.
  118. */
  119. virtual bool IsReorderable() const;
  120. /**
  121. Returns @true if the column is currently hidden.
  122. This corresponds to wxCOL_HIDDEN flag which is off by default.
  123. */
  124. virtual bool IsHidden() const;
  125. /**
  126. Returns @true if the column is currently shown.
  127. This corresponds to the absence of wxCOL_HIDDEN flag.
  128. */
  129. bool IsShown() const;
  130. /**
  131. Returns @true if the column is currently used for sorting.
  132. */
  133. virtual bool IsSortKey() const = 0;
  134. /**
  135. Returns @true, if the sort order is ascending.
  136. Notice that it only makes sense to call this function if the column is
  137. used for sorting at all, i.e. if IsSortKey() returns @true.
  138. */
  139. virtual bool IsSortOrderAscending() const = 0;
  140. };
  141. /**
  142. @class wxSettableHeaderColumn
  143. Adds methods to set the column attributes to wxHeaderColumn.
  144. This class adds setters for the column attributes defined by
  145. wxHeaderColumn. It is still an abstract base class and needs to be
  146. implemented before using it with wxHeaderCtrl.
  147. @library{wxcore}
  148. @category{ctrl}
  149. */
  150. class wxSettableHeaderColumn : public wxHeaderColumn
  151. {
  152. public:
  153. /**
  154. Set the text to display in the column header.
  155. */
  156. virtual void SetTitle(const wxString& title) = 0;
  157. /**
  158. Set the bitmap to be displayed in the column header.
  159. Notice that the bitmaps displayed in different columns of the same
  160. control must all be of the same size.
  161. */
  162. virtual void SetBitmap(const wxBitmap& bitmap) = 0;
  163. /**
  164. Set the column width.
  165. @param width
  166. The column width in pixels or the special wxCOL_WIDTH_DEFAULT
  167. (meaning to use default width) or wxCOL_WIDTH_AUTOSIZE (size to
  168. fit the content) value.
  169. */
  170. virtual void SetWidth(int width) = 0;
  171. /**
  172. Set the minimal column width.
  173. This method can be used with resizable columns (i.e. those for which
  174. wxCOL_RESIZABLE flag is set in GetFlags() or, alternatively,
  175. IsResizeable() returns @true) to prevent the user from making them
  176. narrower than the given width.
  177. @param minWidth
  178. The minimal column width in pixels, may be 0 to remove any
  179. previously set restrictions.
  180. */
  181. virtual void SetMinWidth(int minWidth) = 0;
  182. /**
  183. Set the alignment of the column header.
  184. @param align
  185. The text alignment in horizontal direction only or wxALIGN_NOT to
  186. use the default alignment, The possible values here are
  187. wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT with
  188. wxALIGN_CENTRE_HORIZONTAL being also supported as synonym for
  189. wxALIGN_CENTRE for consistency (but notice that GetAlignment()
  190. never returns it).
  191. */
  192. virtual void SetAlignment(wxAlignment align) = 0;
  193. /**
  194. Set the column flags.
  195. This method allows to set all flags at once, see also generic
  196. ChangeFlag(), SetFlag(), ClearFlag() and ToggleFlag() methods below as
  197. well as specific SetResizeable(), SetSortable(), SetReorderable() and
  198. SetHidden() ones.
  199. @param flags
  200. Combination of wxCOL_RESIZABLE, wxCOL_SORTABLE, wxCOL_REORDERABLE
  201. and wxCOL_HIDDEN bit flags.
  202. */
  203. virtual void SetFlags(int flags) = 0;
  204. /**
  205. Set or clear the given flag.
  206. @param flag
  207. The flag to set or clear.
  208. @param set
  209. If @true, set the flag, i.e. equivalent to calling SetFlag(),
  210. otherwise clear it, as ClearFlag().
  211. @see SetFlags()
  212. */
  213. void ChangeFlag(int flag, bool set);
  214. /**
  215. Set the specified flag for the column.
  216. @see SetFlags()
  217. */
  218. void SetFlag(int flag);
  219. /**
  220. Clear the specified flag for the column.
  221. @see SetFlags()
  222. */
  223. void ClearFlag(int flag);
  224. /**
  225. Toggle the specified flag for the column.
  226. If the flag is currently set, equivalent to ClearFlag(), otherwise --
  227. to SetFlag().
  228. @see SetFlags()
  229. */
  230. void ToggleFlag(int flag);
  231. /**
  232. Call this to enable or disable interactive resizing of the column by
  233. the user.
  234. By default, the columns are resizable.
  235. Equivalent to ChangeFlag(wxCOL_RESIZABLE, resizable).
  236. */
  237. virtual void SetResizeable(bool resizable);
  238. /**
  239. Allow clicking the column to sort the control contents by the field in
  240. this column.
  241. By default, the columns are not sortable so you need to explicitly call
  242. this function to allow sorting by the field corresponding to this
  243. column.
  244. Equivalent to ChangeFlag(wxCOL_SORTABLE, sortable).
  245. */
  246. virtual void SetSortable(bool sortable);
  247. /**
  248. Allow changing the column order by dragging it.
  249. Equivalent to ChangeFlag(wxCOL_REORDERABLE, reorderable).
  250. */
  251. virtual void SetReorderable(bool reorderable);
  252. /**
  253. Hide or show the column.
  254. By default all columns are shown but some of them can be completely
  255. hidden from view by calling this function.
  256. Equivalent to ChangeFlag(wxCOL_HIDDEN, hidden).
  257. */
  258. virtual void SetHidden(bool hidden);
  259. /**
  260. Don't use this column for sorting.
  261. This is the reverse of SetSortOrder() and is called to indicate that
  262. this column is not used for sorting any longer.
  263. */
  264. void UnsetAsSortKey();
  265. /**
  266. Sets this column as the sort key for the associated control.
  267. This function indicates that this column is currently used for sorting
  268. the control and also sets the sorting direction. Notice that actual
  269. sorting is only done in the control associated with the header, this
  270. function doesn't do any sorting on its own.
  271. Don't confuse this function with SetSortable() which should be used to
  272. indicate that the column @em may be used for sorting while this one is
  273. used to indicate that it currently @em is used for sorting. Of course,
  274. SetSortOrder() can be only called for sortable columns.
  275. @param ascending
  276. If @true, sort in ascending order, otherwise in descending order.
  277. */
  278. virtual void SetSortOrder(bool ascending) = 0;
  279. /**
  280. Inverses the sort order.
  281. This function is typically called when the user clicks on a column used
  282. for sorting to change sort order from ascending to descending or vice
  283. versa.
  284. @see SetSortOrder(), IsSortOrderAscending()
  285. */
  286. void ToggleSortOrder();
  287. };
  288. /**
  289. @class wxHeaderColumnSimple
  290. Simple container for the information about the column.
  291. This is a concrete class implementing all wxSettableHeaderColumn class
  292. methods in a trivial way, i.e. by just storing the information in the
  293. object itself. It is used by and with wxHeaderCtrlSimple, e.g.
  294. @code
  295. wxHeaderCtrlSimple * header = new wxHeaderCtrlSimple(...);
  296. wxHeaderColumnSimple col("Title");
  297. col.SetWidth(100);
  298. col.SetSortable(100);
  299. header->AppendColumn(col);
  300. @endcode
  301. @library{wxcore}
  302. @category{ctrl}
  303. */
  304. class wxHeaderColumnSimple : public wxSettableHeaderColumn
  305. {
  306. public:
  307. //@{
  308. /**
  309. Constructor for a column header.
  310. The first constructor creates a header showing the given text @a title
  311. while the second one creates one showing the specified @a bitmap image.
  312. */
  313. wxHeaderColumnSimple(const wxString& title,
  314. int width = wxCOL_WIDTH_DEFAULT,
  315. wxAlignment align = wxALIGN_NOT,
  316. int flags = wxCOL_DEFAULT_FLAGS);
  317. wxHeaderColumnSimple(const wxBitmap &bitmap,
  318. int width = wxCOL_WIDTH_DEFAULT,
  319. wxAlignment align = wxALIGN_CENTER,
  320. int flags = wxCOL_DEFAULT_FLAGS);
  321. //@}
  322. //@{
  323. /// Trivial implementations of the base class pure virtual functions.
  324. virtual void SetTitle(const wxString& title);
  325. virtual wxString GetTitle() const;
  326. virtual void SetBitmap(const wxBitmap& bitmap);
  327. virtual wxBitmap GetBitmap() const;
  328. virtual void SetWidth(int width);
  329. virtual int GetWidth() const;
  330. virtual void SetMinWidth(int minWidth);
  331. virtual int GetMinWidth() const;
  332. virtual void SetAlignment(wxAlignment align);
  333. virtual wxAlignment GetAlignment() const;
  334. virtual void SetFlags(int flags);
  335. virtual int GetFlags() const;
  336. virtual bool IsSortKey() const;
  337. virtual void SetSortOrder(bool ascending);
  338. virtual bool IsSortOrderAscending() const;
  339. //@}
  340. };