laywin.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: laywin.h
  3. // Purpose: interface of wxLayoutAlgorithm
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Enumeration used by wxLayoutAlgorithm.
  9. */
  10. enum wxLayoutOrientation
  11. {
  12. wxLAYOUT_HORIZONTAL,
  13. wxLAYOUT_VERTICAL
  14. };
  15. /**
  16. Enumeration used by wxLayoutAlgorithm.
  17. */
  18. enum wxLayoutAlignment
  19. {
  20. wxLAYOUT_NONE,
  21. wxLAYOUT_TOP,
  22. wxLAYOUT_LEFT,
  23. wxLAYOUT_RIGHT,
  24. wxLAYOUT_BOTTOM
  25. };
  26. /**
  27. @class wxLayoutAlgorithm
  28. wxLayoutAlgorithm implements layout of subwindows in MDI or SDI frames.
  29. It sends a wxCalculateLayoutEvent event to children of the frame, asking them
  30. for information about their size. For MDI parent frames, the algorithm allocates
  31. the remaining space to the MDI client window (which contains the MDI child frames).
  32. For SDI (normal) frames, a 'main' window is specified as taking up the
  33. remaining space.
  34. Because the event system is used, this technique can be applied to any windows,
  35. which are not necessarily 'aware' of the layout classes (no virtual functions
  36. in wxWindow refer to wxLayoutAlgorithm or its events).
  37. However, you may wish to use wxSashLayoutWindow for your subwindows since this
  38. class provides handlers for the required events, and accessors to specify the
  39. desired size of the window. The sash behaviour in the base class can be used,
  40. optionally, to make the windows user-resizable.
  41. wxLayoutAlgorithm is typically used in IDE (integrated development environment)
  42. applications, where there are several resizable windows in addition to the MDI
  43. client window, or other primary editing window. Resizable windows might include
  44. toolbars, a project window, and a window for displaying error and warning messages.
  45. When a window receives an OnCalculateLayout event, it should call SetRect in
  46. the given event object, to be the old supplied rectangle minus whatever space
  47. the window takes up. It should also set its own size accordingly.
  48. wxSashLayoutWindow::OnCalculateLayout generates an OnQueryLayoutInfo event
  49. which it sends to itself to determine the orientation, alignment and size of
  50. the window, which it gets from internal member variables set by the application.
  51. The algorithm works by starting off with a rectangle equal to the whole frame
  52. client area. It iterates through the frame children, generating
  53. wxLayoutAlgorithm::OnCalculateLayout events which subtract the window size and
  54. return the remaining rectangle for the next window to process.
  55. It is assumed (by wxSashLayoutWindow::OnCalculateLayout) that a window stretches
  56. the full dimension of the frame client, according to the orientation it specifies.
  57. For example, a horizontal window will stretch the full width of the remaining
  58. portion of the frame client area.
  59. In the other orientation, the window will be fixed to whatever size was
  60. specified by wxLayoutAlgorithm::OnQueryLayoutInfo. An alignment setting will
  61. make the window 'stick' to the left, top, right or bottom of the remaining
  62. client area. This scheme implies that order of window creation is important.
  63. Say you wish to have an extra toolbar at the top of the frame, a project window
  64. to the left of the MDI client window, and an output window above the status bar.
  65. You should therefore create the windows in this order: toolbar, output window,
  66. project window. This ensures that the toolbar and output window take up space
  67. at the top and bottom, and then the remaining height in-between is used for
  68. the project window.
  69. wxLayoutAlgorithm is quite independent of the way in which
  70. wxLayoutAlgorithm::OnCalculateLayout chooses to interpret a window's size and
  71. alignment. Therefore you could implement a different window class with a new
  72. wxLayoutAlgorithm::OnCalculateLayout event handler, that has a more sophisticated
  73. way of laying out the windows. It might allow specification of whether stretching
  74. occurs in the specified orientation, for example, rather than always assuming
  75. stretching.
  76. (This could, and probably should, be added to the existing implementation).
  77. @note wxLayoutAlgorithm has nothing to do with wxLayoutConstraints.
  78. It is an alternative way of specifying layouts for which the normal
  79. constraint system is unsuitable.
  80. @beginEventEmissionTable{wxQueryLayoutInfoEvent,wxCalculateLayoutEvent}
  81. @event{EVT_QUERY_LAYOUT_INFO(func)}
  82. Process a @c wxEVT_QUERY_LAYOUT_INFO event, to get size, orientation and
  83. alignment from a window. See wxQueryLayoutInfoEvent.
  84. @event{EVT_CALCULATE_LAYOUT(func)}
  85. Process a @c wxEVT_CALCULATE_LAYOUT event, which asks the window to take a
  86. 'bite' out of a rectangle provided by the algorithm. See wxCalculateLayoutEvent.
  87. @endEventTable
  88. Note that the algorithm object does not respond to events, but itself generates the
  89. previous events in order to calculate window sizes.
  90. @library{wxadv}
  91. @category{winlayout}
  92. @see wxSashEvent, wxSashLayoutWindow, @ref overview_events
  93. */
  94. class wxLayoutAlgorithm : public wxObject
  95. {
  96. public:
  97. /**
  98. Default constructor.
  99. */
  100. wxLayoutAlgorithm();
  101. /**
  102. Destructor.
  103. */
  104. virtual ~wxLayoutAlgorithm();
  105. /**
  106. Lays out the children of a normal frame. @a mainWindow is set to occupy the
  107. remaining space. This function simply calls LayoutWindow().
  108. */
  109. bool LayoutFrame(wxFrame* frame, wxWindow* mainWindow = NULL);
  110. /**
  111. Lays out the children of an MDI parent frame. If @a rect is non-@NULL, the
  112. given rectangle will be used as a starting point instead of the frame's client
  113. area. The MDI client window is set to occupy the remaining space.
  114. */
  115. bool LayoutMDIFrame(wxMDIParentFrame* frame, wxRect* rect = NULL);
  116. /**
  117. Lays out the children of a normal frame or other window.
  118. @a mainWindow is set to occupy the remaining space. If this is not specified,
  119. then the last window that responds to a calculate layout event in query mode will
  120. get the remaining space (that is, a non-query OnCalculateLayout event will
  121. not be sent to this window and the window will be set to the remaining size).
  122. */
  123. bool LayoutWindow(wxWindow* parent, wxWindow* mainWindow = NULL);
  124. };
  125. /**
  126. @class wxSashLayoutWindow
  127. wxSashLayoutWindow responds to OnCalculateLayout events generated by wxLayoutAlgorithm.
  128. It allows the application to use simple accessors to specify how the window
  129. should be laid out, rather than having to respond to events.
  130. The fact that the class derives from wxSashWindow allows sashes to be used if
  131. required, to allow the windows to be user-resizable.
  132. The documentation for wxLayoutAlgorithm explains the purpose of this class in
  133. more detail.
  134. For the window styles see wxSashWindow.
  135. This class handles the EVT_QUERY_LAYOUT_INFO and EVT_CALCULATE_LAYOUT events
  136. for you. However, if you use sashes, see wxSashWindow for relevant event information.
  137. See also wxLayoutAlgorithm for information about the layout events.
  138. @library{wxadv}
  139. @category{miscwnd}
  140. @see wxLayoutAlgorithm, wxSashWindow, @ref overview_events
  141. */
  142. class wxSashLayoutWindow : public wxSashWindow
  143. {
  144. public:
  145. /**
  146. Default ctor.
  147. */
  148. wxSashLayoutWindow();
  149. /**
  150. Constructs a sash layout window, which can be a child of a frame, dialog or any
  151. other non-control window.
  152. @param parent
  153. Pointer to a parent window.
  154. @param id
  155. Window identifier. If -1, will automatically create an identifier.
  156. @param pos
  157. Window position. wxDefaultPosition is (-1, -1) which indicates that
  158. wxSashLayoutWindows should generate a default position for the window.
  159. If using the wxSashLayoutWindow class directly, supply an actual position.
  160. @param size
  161. Window size. wxDefaultSize is (-1, -1) which indicates that
  162. wxSashLayoutWindows should generate a default size for the window.
  163. @param style
  164. Window style. For window styles, please see wxSashLayoutWindow.
  165. @param name
  166. Window name.
  167. */
  168. wxSashLayoutWindow(wxWindow* parent, wxWindowID id,
  169. const wxPoint& pos = wxDefaultPosition,
  170. const wxSize& size = wxDefaultSize,
  171. long style = wxCLIP_CHILDREN | wxSW_3D,
  172. const wxString& name = "layoutWindow");
  173. /**
  174. Initializes a sash layout window, which can be a child of a frame, dialog or
  175. any other non-control window.
  176. @param parent
  177. Pointer to a parent window.
  178. @param id
  179. Window identifier. If -1, will automatically create an identifier.
  180. @param pos
  181. Window position. wxDefaultPosition is (-1, -1) which indicates that
  182. wxSashLayoutWindows should generate a default position for the window.
  183. If using the wxSashLayoutWindow class directly, supply an actual position.
  184. @param size
  185. Window size. wxDefaultSize is (-1, -1) which indicates that
  186. wxSashLayoutWindows should generate a default size for the window.
  187. @param style
  188. Window style. For window styles, please see wxSashLayoutWindow.
  189. @param name
  190. Window name.
  191. */
  192. bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
  193. const wxPoint& pos = wxDefaultPosition,
  194. const wxSize& size = wxDefaultSize,
  195. long style = wxCLIP_CHILDREN | wxSW_3D,
  196. const wxString& name = "layoutWindow");
  197. /**
  198. Returns the alignment of the window: one of wxLAYOUT_TOP, wxLAYOUT_LEFT,
  199. wxLAYOUT_RIGHT, wxLAYOUT_BOTTOM.
  200. */
  201. wxLayoutAlignment GetAlignment() const;
  202. /**
  203. Returns the orientation of the window: one of wxLAYOUT_HORIZONTAL,
  204. wxLAYOUT_VERTICAL.
  205. */
  206. wxLayoutOrientation GetOrientation() const;
  207. /**
  208. The default handler for the event that is generated by wxLayoutAlgorithm.
  209. The implementation of this function calls wxCalculateLayoutEvent::SetRect
  210. to shrink the provided size according to how much space this window takes up.
  211. For further details, see wxLayoutAlgorithm and wxCalculateLayoutEvent.
  212. */
  213. void OnCalculateLayout(wxCalculateLayoutEvent& event);
  214. /**
  215. The default handler for the event that is generated by OnCalculateLayout to get
  216. size, alignment and orientation information for the window.
  217. The implementation of this function uses member variables as set by accessors
  218. called by the application.
  219. For further details, see wxLayoutAlgorithm and wxQueryLayoutInfoEvent.
  220. */
  221. void OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event);
  222. /**
  223. Sets the alignment of the window (which edge of the available parent client
  224. area the window is attached to). @a alignment is one of wxLAYOUT_TOP, wxLAYOUT_LEFT,
  225. wxLAYOUT_RIGHT, wxLAYOUT_BOTTOM.
  226. */
  227. void SetAlignment(wxLayoutAlignment alignment);
  228. /**
  229. Sets the default dimensions of the window. The dimension other than the
  230. orientation will be fixed to this value, and the orientation dimension
  231. will be ignored and the window stretched to fit the available space.
  232. */
  233. void SetDefaultSize(const wxSize& size);
  234. /**
  235. Sets the orientation of the window (the direction the window will stretch in,
  236. to fill the available parent client area). @a orientation is one of
  237. wxLAYOUT_HORIZONTAL, wxLAYOUT_VERTICAL.
  238. */
  239. void SetOrientation(wxLayoutOrientation orientation);
  240. };
  241. /**
  242. @class wxQueryLayoutInfoEvent
  243. This event is sent when wxLayoutAlgorithm wishes to get the size, orientation
  244. and alignment of a window. More precisely, the event is sent by the
  245. OnCalculateLayout handler which is itself invoked by wxLayoutAlgorithm.
  246. @beginEventTable{wxQueryLayoutInfoEvent}
  247. @event{EVT_QUERY_LAYOUT_INFO(func)}
  248. Process a @c wxEVT_QUERY_LAYOUT_INFO event, to get size, orientation and alignment
  249. from a window.
  250. @endEventTable
  251. @library{wxadv}
  252. @category{events}
  253. @see wxCalculateLayoutEvent, wxSashLayoutWindow, wxLayoutAlgorithm.
  254. */
  255. class wxQueryLayoutInfoEvent : public wxEvent
  256. {
  257. public:
  258. /**
  259. Constructor.
  260. */
  261. wxQueryLayoutInfoEvent(wxWindowID id = 0);
  262. /**
  263. Specifies the alignment of the window (which side of the remaining parent
  264. client area the window sticks to).
  265. One of wxLAYOUT_TOP, wxLAYOUT_LEFT, wxLAYOUT_RIGHT, wxLAYOUT_BOTTOM.
  266. */
  267. wxLayoutAlignment GetAlignment() const;
  268. /**
  269. Returns the flags associated with this event. Not currently used.
  270. */
  271. int GetFlags() const;
  272. /**
  273. Returns the orientation that the event handler specified to the event object.
  274. May be one of wxLAYOUT_HORIZONTAL, wxLAYOUT_VERTICAL.
  275. */
  276. wxLayoutOrientation GetOrientation() const;
  277. /**
  278. Returns the requested length of the window in the direction of the window
  279. orientation. This information is not yet used.
  280. */
  281. int GetRequestedLength() const;
  282. /**
  283. Returns the size that the event handler specified to the event object as being
  284. the requested size of the window.
  285. */
  286. wxSize GetSize() const;
  287. /**
  288. Call this to specify the alignment of the window (which side of the remaining
  289. parent client area the window sticks to).
  290. May be one of wxLAYOUT_TOP, wxLAYOUT_LEFT, wxLAYOUT_RIGHT, wxLAYOUT_BOTTOM.
  291. */
  292. void SetAlignment(wxLayoutAlignment alignment);
  293. /**
  294. Sets the flags associated with this event. Not currently used.
  295. */
  296. void SetFlags(int flags);
  297. /**
  298. Call this to specify the orientation of the window.
  299. May be one of wxLAYOUT_HORIZONTAL, wxLAYOUT_VERTICAL.
  300. */
  301. void SetOrientation(wxLayoutOrientation orientation);
  302. /**
  303. Sets the requested length of the window in the direction of the window
  304. orientation. This information is not yet used.
  305. */
  306. void SetRequestedLength(int length);
  307. /**
  308. Call this to let the calling code know what the size of the window is.
  309. */
  310. void SetSize(const wxSize& size);
  311. };
  312. wxEventType wxEVT_QUERY_LAYOUT_INFO;
  313. /**
  314. @class wxCalculateLayoutEvent
  315. This event is sent by wxLayoutAlgorithm to calculate the amount of the
  316. remaining client area that the window should occupy.
  317. @beginEventTable{wxCalculateLayoutEvent}
  318. @event{EVT_CALCULATE_LAYOUT(func)}
  319. Process a @c wxEVT_CALCULATE_LAYOUT event, which asks the window to take a
  320. 'bite' out of a rectangle provided by the algorithm.
  321. @endEventTable
  322. @library{wxadv}
  323. @category{events}
  324. @see wxQueryLayoutInfoEvent, wxSashLayoutWindow, wxLayoutAlgorithm.
  325. */
  326. class wxCalculateLayoutEvent : public wxEvent
  327. {
  328. public:
  329. /**
  330. Constructor.
  331. */
  332. wxCalculateLayoutEvent(wxWindowID id = 0);
  333. /**
  334. Returns the flags associated with this event. Not currently used.
  335. */
  336. int GetFlags() const;
  337. /**
  338. Before the event handler is entered, returns the remaining parent client area
  339. that the window could occupy.
  340. When the event handler returns, this should contain the remaining parent
  341. client rectangle, after the event handler has subtracted the area that its
  342. window occupies.
  343. */
  344. wxRect GetRect() const;
  345. /**
  346. Sets the flags associated with this event. Not currently used.
  347. */
  348. void SetFlags(int flags);
  349. /**
  350. Call this to specify the new remaining parent client area, after the space
  351. occupied by the window has been subtracted.
  352. */
  353. void SetRect(const wxRect& rect);
  354. };
  355. wxEventType wxEVT_CALCULATE_LAYOUT;