gbsizer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: gbsizer.h
  3. // Purpose: interface of wxGBPosition
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxGBPosition
  9. This class represents the position of an item in a virtual grid of rows and
  10. columns managed by a wxGridBagSizer.
  11. @library{wxcore}
  12. @category{winlayout}
  13. */
  14. class wxGBPosition
  15. {
  16. public:
  17. /**
  18. Default constructor, setting the row and column to (0,0).
  19. */
  20. wxGBPosition();
  21. /**
  22. Construct a new wxGBPosition, setting the row and column.
  23. */
  24. wxGBPosition(int row, int col);
  25. /**
  26. Get the current column value.
  27. */
  28. int GetCol() const;
  29. /**
  30. Get the current row value.
  31. */
  32. int GetRow() const;
  33. /**
  34. Set a new column value.
  35. */
  36. void SetCol(int col);
  37. /**
  38. Set a new row value.
  39. */
  40. void SetRow(int row);
  41. /**
  42. Compare inequality of two wxGBPositions.
  43. */
  44. bool operator!=(const wxGBPosition& p) const;
  45. /**
  46. Compare equality of two wxGBPositions.
  47. */
  48. bool operator==(const wxGBPosition& p) const;
  49. };
  50. /**
  51. @class wxGridBagSizer
  52. A wxSizer that can lay out items in a virtual grid like a wxFlexGridSizer
  53. but in this case explicit positioning of the items is allowed using
  54. wxGBPosition, and items can optionally span more than one row and/or column
  55. using wxGBSpan.
  56. @library{wxcore}
  57. @category{winlayout}
  58. */
  59. class wxGridBagSizer : public wxFlexGridSizer
  60. {
  61. public:
  62. /**
  63. Constructor, with optional parameters to specify the gap between the
  64. rows and columns.
  65. */
  66. wxGridBagSizer(int vgap = 0, int hgap = 0);
  67. //@{
  68. /**
  69. Adds the given item to the given position.
  70. @return A valid pointer if the item was successfully placed at the
  71. given position, or @NULL if something was already there.
  72. */
  73. wxSizerItem* Add(wxWindow* window, const wxGBPosition& pos,
  74. const wxGBSpan& span = wxDefaultSpan,
  75. int flag = 0, int border = 0, wxObject* userData = NULL);
  76. wxSizerItem* Add(wxSizer* sizer, const wxGBPosition& pos,
  77. const wxGBSpan& span = wxDefaultSpan,
  78. int flag = 0, int border = 0, wxObject* userData = NULL);
  79. wxSizerItem* Add(wxGBSizerItem* item);
  80. /**
  81. Adds a spacer to the given position.
  82. @a width and @a height specify the dimension of the spacer to be added.
  83. @return A valid pointer if the spacer was successfully placed at the
  84. given position, or @NULL if something was already there.
  85. */
  86. wxSizerItem* Add(int width, int height, const wxGBPosition& pos,
  87. const wxGBSpan& span = wxDefaultSpan,
  88. int flag = 0, int border = 0, wxObject* userData = NULL);
  89. //@}
  90. /**
  91. Called when the managed size of the sizer is needed or when layout
  92. needs done.
  93. */
  94. wxSize CalcMin();
  95. //@{
  96. /**
  97. Look at all items and see if any intersect (or would overlap) the given
  98. item. Returns @true if so, @false if there would be no overlap. If an
  99. @a excludeItem is given then it will not be checked for intersection,
  100. for example it may be the item we are checking the position of.
  101. */
  102. bool CheckForIntersection(wxGBSizerItem* item,
  103. wxGBSizerItem* excludeItem = NULL);
  104. bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span,
  105. wxGBSizerItem* excludeItem = NULL);
  106. //@}
  107. //@{
  108. /**
  109. Find the sizer item for the given window or subsizer, returns @NULL if
  110. not found. (non-recursive)
  111. */
  112. wxGBSizerItem* FindItem(wxWindow* window);
  113. wxGBSizerItem* FindItem(wxSizer* sizer);
  114. //@}
  115. /**
  116. Return the sizer item located at the point given in pt, or @NULL if
  117. there is no item at that point. The (x,y) coordinates in @a pt
  118. correspond to the client coordinates of the window using the sizer for
  119. layout. (non-recursive)
  120. */
  121. wxGBSizerItem* FindItemAtPoint(const wxPoint& pt);
  122. /**
  123. Return the sizer item for the given grid cell, or @NULL if there is no
  124. item at that position. (non-recursive)
  125. */
  126. wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos);
  127. /**
  128. Return the sizer item that has a matching user data (it only compares
  129. pointer values) or @NULL if not found. (non-recursive)
  130. */
  131. wxGBSizerItem* FindItemWithData(const wxObject* userData);
  132. /**
  133. Get the size of the specified cell, including hgap and vgap. Only valid
  134. after window layout has been performed.
  135. */
  136. wxSize GetCellSize(int row, int col) const;
  137. /**
  138. Get the size used for cells in the grid with no item.
  139. */
  140. wxSize GetEmptyCellSize() const;
  141. //@{
  142. /**
  143. Get the grid position of the specified item.
  144. */
  145. wxGBPosition GetItemPosition(wxWindow* window);
  146. wxGBPosition GetItemPosition(wxSizer* sizer);
  147. wxGBPosition GetItemPosition(size_t index);
  148. //@}
  149. //@{
  150. /**
  151. Get the row/col spanning of the specified item.
  152. */
  153. wxGBSpan GetItemSpan(wxWindow* window);
  154. wxGBSpan GetItemSpan(wxSizer* sizer);
  155. wxGBSpan GetItemSpan(size_t index);
  156. //@}
  157. /**
  158. Called when the managed size of the sizer is needed or when layout
  159. needs done.
  160. */
  161. void RecalcSizes();
  162. /**
  163. Set the size used for cells in the grid with no item.
  164. */
  165. void SetEmptyCellSize(const wxSize& sz);
  166. //@{
  167. /**
  168. Set the grid position of the specified item. Returns @true on success.
  169. If the move is not allowed (because an item is already there) then
  170. @false is returned.
  171. */
  172. bool SetItemPosition(wxWindow* window, const wxGBPosition& pos);
  173. bool SetItemPosition(wxSizer* sizer, const wxGBPosition& pos);
  174. bool SetItemPosition(size_t index, const wxGBPosition& pos);
  175. //@}
  176. //@{
  177. /**
  178. Set the row/col spanning of the specified item. Returns @true on
  179. success. If the move is not allowed (because an item is already there)
  180. then @false is returned.
  181. */
  182. bool SetItemSpan(wxWindow* window, const wxGBSpan& span);
  183. bool SetItemSpan(wxSizer* sizer, const wxGBSpan& span);
  184. bool SetItemSpan(size_t index, const wxGBSpan& span);
  185. //@}
  186. };
  187. /**
  188. @class wxGBSizerItem
  189. The wxGBSizerItem class is used by the wxGridBagSizer for tracking the
  190. items in the sizer. It adds grid position and spanning information to the
  191. normal wxSizerItem by adding wxGBPosition and wxGBSpan attributes. Most of
  192. the time you will not need to use a wxGBSizerItem directly in your code,
  193. but there are a couple of cases where it is handy.
  194. @library{wxcore}
  195. @category{winlayout}
  196. */
  197. class wxGBSizerItem : public wxSizerItem
  198. {
  199. public:
  200. /**
  201. Construct a sizer item for tracking a spacer.
  202. */
  203. wxGBSizerItem(int width, int height, const wxGBPosition& pos,
  204. const wxGBSpan& span=wxDefaultSpan, int flag=0, int border=0,
  205. wxObject* userData=NULL);
  206. /**
  207. Construct a sizer item for tracking a window.
  208. */
  209. wxGBSizerItem(wxWindow* window, const wxGBPosition& pos,
  210. const wxGBSpan& span=wxDefaultSpan, int flag=0, int border=0,
  211. wxObject* userData=NULL);
  212. /**
  213. Construct a sizer item for tracking a subsizer.
  214. */
  215. wxGBSizerItem(wxSizer* sizer, const wxGBPosition& pos,
  216. const wxGBSpan& span=wxDefaultSpan, int flag=0, int border=0,
  217. wxObject* userData=NULL);
  218. /**
  219. Get the row and column of the endpoint of this item.
  220. */
  221. void GetEndPos(int& row, int& col);
  222. //@{
  223. /**
  224. Get the grid position of the item.
  225. */
  226. wxGBPosition GetPos() const;
  227. void GetPos(int& row, int& col) const;
  228. //@}
  229. //@{
  230. /**
  231. Get the row and column spanning of the item.
  232. */
  233. wxGBSpan GetSpan() const;
  234. void GetSpan(int& rowspan, int& colspan) const;
  235. //@}
  236. /**
  237. Returns @true if this item and the @a other item intersect.
  238. */
  239. bool Intersects(const wxGBSizerItem& other);
  240. /**
  241. Returns @true if the given pos/span would intersect with this item.
  242. */
  243. bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
  244. /**
  245. If the item is already a member of a sizer then first ensure that there
  246. is no other item that would intersect with this one at the new
  247. position, then set the new position. Returns @true if the change is
  248. successful and after the next Layout the item will be moved.
  249. */
  250. bool SetPos(const wxGBPosition& pos);
  251. /**
  252. If the item is already a member of a sizer then first ensure that there
  253. is no other item that would intersect with this one with its new
  254. spanning size, then set the new spanning. Returns @true if the change
  255. is successful and after the next Layout the item will be resized.
  256. */
  257. bool SetSpan(const wxGBSpan& span);
  258. wxGridBagSizer* GetGBSizer() const;
  259. void SetGBSizer(wxGridBagSizer* sizer);
  260. };
  261. /**
  262. @class wxGBSpan
  263. This class is used to hold the row and column spanning attributes of items
  264. in a wxGridBagSizer.
  265. @library{wxcore}
  266. @category{winlayout}
  267. */
  268. class wxGBSpan
  269. {
  270. public:
  271. /**
  272. Default constructor, setting the rowspan and colspan to (1,1) meaning
  273. that the item occupies one cell in each direction.
  274. */
  275. wxGBSpan();
  276. /**
  277. Construct a new wxGBSpan, setting the @a rowspan and @a colspan.
  278. */
  279. wxGBSpan(int rowspan, int colspan);
  280. /**
  281. Get the current colspan value.
  282. */
  283. int GetColspan() const;
  284. /**
  285. Get the current rowspan value.
  286. */
  287. int GetRowspan() const;
  288. /**
  289. Set a new colspan value.
  290. */
  291. void SetColspan(int colspan);
  292. /**
  293. Set a new rowspan value.
  294. */
  295. void SetRowspan(int rowspan);
  296. /**
  297. Compare inequality of two wxGBSpans.
  298. */
  299. bool operator!=(const wxGBSpan& o) const;
  300. /**
  301. Compare equality of two wxGBSpans.
  302. */
  303. bool operator==(const wxGBSpan& o) const;
  304. };
  305. const wxGBSpan wxDefaultSpan;