splitter.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: splitter.h
  3. // Purpose: interface of wxSplitterWindow
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxSP_NOBORDER 0x0000
  8. #define wxSP_THIN_SASH 0x0000 // NB: the default is 3D sash
  9. #define wxSP_NOSASH 0x0010
  10. #define wxSP_PERMIT_UNSPLIT 0x0040
  11. #define wxSP_LIVE_UPDATE 0x0080
  12. #define wxSP_3DSASH 0x0100
  13. #define wxSP_3DBORDER 0x0200
  14. #define wxSP_NO_XP_THEME 0x0400
  15. #define wxSP_BORDER wxSP_3DBORDER
  16. #define wxSP_3D (wxSP_3DBORDER | wxSP_3DSASH)
  17. enum wxSplitMode
  18. {
  19. wxSPLIT_HORIZONTAL = 1,
  20. wxSPLIT_VERTICAL
  21. };
  22. enum
  23. {
  24. wxSPLIT_DRAG_NONE,
  25. wxSPLIT_DRAG_DRAGGING,
  26. wxSPLIT_DRAG_LEFT_DOWN
  27. };
  28. /**
  29. @class wxSplitterWindow
  30. This class manages up to two subwindows. The current view can be split
  31. into two programmatically (perhaps from a menu command), and unsplit
  32. either programmatically or via the wxSplitterWindow user interface.
  33. @beginStyleTable
  34. @style{wxSP_3D}
  35. Draws a 3D effect border and sash.
  36. @style{wxSP_THIN_SASH}
  37. Draws a thin sash.
  38. @style{wxSP_3DSASH}
  39. Draws a 3D effect sash (part of default style).
  40. @style{wxSP_3DBORDER}
  41. Synonym for wxSP_BORDER.
  42. @style{wxSP_BORDER}
  43. Draws a standard border.
  44. @style{wxSP_NOBORDER}
  45. No border (default).
  46. @style{wxSP_NO_XP_THEME}
  47. Under Windows XP, switches off the attempt to draw the splitter
  48. using Windows XP theming, so the borders and sash will take on the
  49. pre-XP look.
  50. @style{wxSP_PERMIT_UNSPLIT}
  51. Always allow to unsplit, even with the minimum pane size other than zero.
  52. @style{wxSP_LIVE_UPDATE}
  53. Don't draw XOR line but resize the child windows immediately.
  54. @endStyleTable
  55. @beginEventEmissionTable{wxSplitterEvent}
  56. @event{EVT_SPLITTER_SASH_POS_CHANGING(id, func)}
  57. The sash position is in the process of being changed.
  58. May be used to modify the position of the tracking bar to properly
  59. reflect the position that would be set if the drag were to be completed
  60. at this point. Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGING event.
  61. @event{EVT_SPLITTER_SASH_POS_CHANGED(id, func)}
  62. The sash position was changed. May be used to modify the sash position
  63. before it is set, or to prevent the change from taking place.
  64. Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGED event.
  65. @event{EVT_SPLITTER_UNSPLIT(id, func)}
  66. The splitter has been just unsplit. Processes a @c wxEVT_SPLITTER_UNSPLIT event.
  67. @event{EVT_SPLITTER_DCLICK(id, func)}
  68. The sash was double clicked. The default behaviour is to unsplit the
  69. window when this happens (unless the minimum pane size has been set
  70. to a value greater than zero). Processes a @c wxEVT_SPLITTER_DOUBLECLICKED event.
  71. @endEventTable
  72. @library{wxcore}
  73. @category{miscwnd}
  74. @see wxSplitterEvent, @ref overview_splitterwindow
  75. */
  76. class wxSplitterWindow : public wxWindow
  77. {
  78. public:
  79. /**
  80. Default constructor
  81. */
  82. wxSplitterWindow();
  83. /**
  84. Constructor for creating the window.
  85. @param parent
  86. The parent of the splitter window.
  87. @param id
  88. The window identifier.
  89. @param pos
  90. The window position.
  91. @param size
  92. The window size.
  93. @param style
  94. The window style. See wxSplitterWindow.
  95. @param name
  96. The window name.
  97. @remarks
  98. After using this constructor, you must create either one or two
  99. subwindows with the splitter window as parent, and then call one
  100. of Initialize(), SplitVertically() and SplitHorizontally() in order
  101. to set the pane(s).
  102. You can create two windows, with one hidden when not being shown;
  103. or you can create and delete the second pane on demand.
  104. @see Initialize(), SplitVertically(), SplitHorizontally(), Create()
  105. */
  106. wxSplitterWindow(wxWindow* parent, wxWindowID id = wxID_ANY,
  107. const wxPoint& pos = wxDefaultPosition,
  108. const wxSize& size = wxDefaultSize,
  109. long style = wxSP_3D,
  110. const wxString& name = "splitterWindow");
  111. /**
  112. Destroys the wxSplitterWindow and its children.
  113. */
  114. virtual ~wxSplitterWindow();
  115. /**
  116. Creation function, for two-step construction.
  117. See wxSplitterWindow() for details.
  118. */
  119. bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
  120. const wxPoint& point = wxDefaultPosition,
  121. const wxSize& size = wxDefaultSize, long style = wxSP_3D,
  122. const wxString& name = "splitter");
  123. /**
  124. Returns the current minimum pane size (defaults to zero).
  125. @see SetMinimumPaneSize()
  126. */
  127. int GetMinimumPaneSize() const;
  128. /**
  129. Returns the current sash gravity.
  130. @see SetSashGravity()
  131. */
  132. double GetSashGravity() const;
  133. /**
  134. Returns the current sash position.
  135. @see SetSashPosition()
  136. */
  137. int GetSashPosition() const;
  138. /**
  139. Returns the default sash size in pixels or 0 if it is invisible.
  140. @see GetDefaultSashSize(), IsSashInvisible()
  141. */
  142. int GetSashSize() const;
  143. /**
  144. Returns the default sash size in pixels.
  145. The size of the sash is its width for a vertically split window and its
  146. height for a horizontally split one. Its other direction is the same as
  147. the client size of the window in the corresponding direction.
  148. The default sash size is platform-dependent because it conforms to the
  149. current platform look-and-feel and cannot be changed.
  150. @since 2.9.4
  151. */
  152. int GetDefaultSashSize() const;
  153. /**
  154. Gets the split mode.
  155. @see SetSplitMode(), SplitVertically(), SplitHorizontally().
  156. */
  157. wxSplitMode GetSplitMode() const;
  158. /**
  159. Returns the left/top or only pane.
  160. */
  161. wxWindow* GetWindow1() const;
  162. /**
  163. Returns the right/bottom pane.
  164. */
  165. wxWindow* GetWindow2() const;
  166. /**
  167. Initializes the splitter window to have one pane.
  168. The child window is shown if it is currently hidden.
  169. @param window
  170. The pane for the unsplit window.
  171. @remarks This should be called if you wish to initially view only a
  172. single pane in the splitter window.
  173. @see SplitVertically(), SplitHorizontally()
  174. */
  175. void Initialize(wxWindow* window);
  176. /**
  177. Returns @true if the sash is invisible even when the window is split, @false otherwise.
  178. @remark This is a shortcut for HasFlag(wxSP_NOSASH)
  179. @see SetSashInvisible()
  180. @since 2.9.4
  181. */
  182. bool IsSashInvisible() const;
  183. /**
  184. Returns @true if the window is split, @false otherwise.
  185. */
  186. bool IsSplit() const;
  187. /**
  188. Application-overridable function called when the sash is double-clicked with
  189. the left mouse button.
  190. @param x
  191. The x position of the mouse cursor.
  192. @param y
  193. The y position of the mouse cursor.
  194. @remarks The default implementation of this function calls Unsplit if the
  195. minimum pane size is zero.
  196. @see Unsplit()
  197. */
  198. virtual void OnDoubleClickSash(int x, int y);
  199. /**
  200. Application-overridable function called when the sash position is changed by
  201. user. It may return @false to prevent the change or @true to allow it.
  202. @param newSashPosition
  203. The new sash position (always positive or zero)
  204. @remarks The default implementation of this function verifies that the
  205. sizes of both panes of the splitter are greater than
  206. minimum pane size.
  207. */
  208. virtual bool OnSashPositionChange(int newSashPosition);
  209. /**
  210. Application-overridable function called when the window is unsplit, either
  211. programmatically or using the wxSplitterWindow user interface.
  212. @param removed
  213. The window being removed.
  214. @remarks The default implementation of this function simply hides
  215. removed. You may wish to delete the window.
  216. */
  217. virtual void OnUnsplit(wxWindow* removed);
  218. /**
  219. This function replaces one of the windows managed by the wxSplitterWindow with
  220. another one. It is in general better to use it instead of calling Unsplit()
  221. and then resplitting the window back because it will provoke much less flicker
  222. (if any). It is valid to call this function whether the splitter has two
  223. windows or only one.
  224. Both parameters should be non-@NULL and @a winOld must specify one of the
  225. windows managed by the splitter. If the parameters are incorrect or the window
  226. couldn't be replaced, @false is returned. Otherwise the function will return
  227. @true, but please notice that it will not delete the replaced window and you
  228. may wish to do it yourself.
  229. @see GetMinimumPaneSize()
  230. */
  231. bool ReplaceWindow(wxWindow* winOld, wxWindow* winNew);
  232. /**
  233. Sets the minimum pane size.
  234. @param paneSize
  235. Minimum pane size in pixels.
  236. @remarks The default minimum pane size is zero, which means that either
  237. pane can be reduced to zero by dragging the sash, thus
  238. removing one of the panes. To prevent this behaviour
  239. (and veto out-of-range sash dragging), set a minimum
  240. size, for example 20 pixels. If the wxSP_PERMIT_UNSPLIT
  241. style is used when a splitter window is created, the
  242. window may be unsplit even if minimum size is non-zero.
  243. @see GetMinimumPaneSize()
  244. */
  245. void SetMinimumPaneSize(int paneSize);
  246. /**
  247. Sets the sash gravity.
  248. @param gravity
  249. The sash gravity. Value between 0.0 and 1.0.
  250. @remarks
  251. Gravity is real factor which controls position of sash while resizing
  252. wxSplitterWindow. Gravity tells wxSplitterWindow how much will left/top
  253. window grow while resizing.
  254. Example values:
  255. - 0.0: only the bottom/right window is automatically resized
  256. - 0.5: both windows grow by equal size
  257. - 1.0: only left/top window grows
  258. Gravity should be a real value between 0.0 and 1.0.
  259. Default value of sash gravity is 0.0.
  260. That value is compatible with previous (before gravity was introduced)
  261. behaviour of wxSplitterWindow.
  262. @see GetSashGravity()
  263. */
  264. void SetSashGravity(double gravity);
  265. /**
  266. Sets the sash position.
  267. @param position
  268. The sash position in pixels.
  269. @param redraw
  270. If @true, resizes the panes and redraws the sash and border.
  271. @remarks Does not currently check for an out-of-range value.
  272. @see GetSashPosition()
  273. */
  274. void SetSashPosition(int position, bool redraw = true);
  275. /**
  276. Sets the split mode.
  277. @param mode
  278. Can be wxSPLIT_VERTICAL or wxSPLIT_HORIZONTAL.
  279. @remarks Only sets the internal variable; does not update the display.
  280. @see GetSplitMode(), SplitVertically(), SplitHorizontally().
  281. */
  282. void SetSplitMode(int mode);
  283. /**
  284. Sets whether the sash should be invisible, even when the window is
  285. split.
  286. When the sash is invisible, it doesn't appear on the screen at all and,
  287. in particular, doesn't allow the user to resize the windows.
  288. @remarks Only sets the internal variable; does not update the display.
  289. @param invisible
  290. If @true, the sash is always invisible, else it is shown when the
  291. window is split.
  292. @see IsSashInvisible()
  293. @since 2.9.4
  294. */
  295. void SetSashInvisible(bool invisible=true);
  296. /**
  297. Initializes the top and bottom panes of the splitter window.
  298. The child windows are shown if they are currently hidden.
  299. @param window1
  300. The top pane.
  301. @param window2
  302. The bottom pane.
  303. @param sashPosition
  304. The initial position of the sash. If this value is positive,
  305. it specifies the size of the upper pane. If it is negative, its
  306. absolute value gives the size of the lower pane.
  307. Finally, specify 0 (default) to choose the default position
  308. (half of the total window height).
  309. @return @true if successful, @false otherwise (the window was already split).
  310. @remarks This should be called if you wish to initially view two panes.
  311. It can also be called at any subsequent time, but the application
  312. should check that the window is not currently split using IsSplit().
  313. @see SplitVertically(), IsSplit(), Unsplit()
  314. */
  315. virtual bool SplitHorizontally(wxWindow* window1, wxWindow* window2,
  316. int sashPosition = 0);
  317. /**
  318. Initializes the left and right panes of the splitter window.
  319. The child windows are shown if they are currently hidden.
  320. @param window1
  321. The left pane.
  322. @param window2
  323. The right pane.
  324. @param sashPosition
  325. The initial position of the sash. If this value is positive, it
  326. specifies the size of the left pane. If it is negative, it is
  327. absolute value gives the size of the right pane.
  328. Finally, specify 0 (default) to choose the default position
  329. (half of the total window width).
  330. @return @true if successful, @false otherwise (the window was already split).
  331. @remarks This should be called if you wish to initially view two panes.
  332. It can also be called at any subsequent time, but the
  333. application should check that the window is not currently
  334. split using IsSplit().
  335. @see SplitHorizontally(), IsSplit(), Unsplit().
  336. */
  337. virtual bool SplitVertically(wxWindow* window1, wxWindow* window2,
  338. int sashPosition = 0);
  339. /**
  340. Unsplits the window.
  341. @param toRemove
  342. The pane to remove, or @NULL to remove the right or bottom pane.
  343. @return @true if successful, @false otherwise (the window was not split).
  344. @remarks This call will not actually delete the pane being removed; it
  345. calls OnUnsplit() which can be overridden for the desired
  346. behaviour. By default, the pane being removed is hidden.
  347. @see SplitHorizontally(), SplitVertically(), IsSplit(), OnUnsplit()
  348. */
  349. bool Unsplit(wxWindow* toRemove = NULL);
  350. /**
  351. Causes any pending sizing of the sash and child panes to take place
  352. immediately.
  353. Such resizing normally takes place in idle time, in order to wait for
  354. layout to be completed. However, this can cause unacceptable flicker as
  355. the panes are resized after the window has been shown.
  356. To work around this, you can perform window layout (for example by
  357. sending a size event to the parent window), and then call this function,
  358. before showing the top-level window.
  359. */
  360. void UpdateSize();
  361. };
  362. /**
  363. @class wxSplitterEvent
  364. This class represents the events generated by a splitter control.
  365. Also there is only one event class, the data associated to the different events
  366. is not the same and so not all accessor functions may be called for each event.
  367. The documentation mentions the kind of event(s) for which the given accessor
  368. function makes sense: calling it for other types of events will result
  369. in assert failure (in debug mode) and will return meaningless results.
  370. @beginEventTable{wxSplitterEvent}
  371. @event{EVT_SPLITTER_SASH_POS_CHANGING(id, func)}
  372. The sash position is in the process of being changed.
  373. May be used to modify the position of the tracking bar to properly
  374. reflect the position that would be set if the drag were to be completed
  375. at this point. Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGING event.
  376. @event{EVT_SPLITTER_SASH_POS_CHANGED(id, func)}
  377. The sash position was changed. May be used to modify the sash position
  378. before it is set, or to prevent the change from taking place.
  379. Processes a @c wxEVT_SPLITTER_SASH_POS_CHANGED event.
  380. @event{EVT_SPLITTER_UNSPLIT(id, func)}
  381. The splitter has been just unsplit. Processes a @c wxEVT_SPLITTER_UNSPLIT event.
  382. @event{EVT_SPLITTER_DCLICK(id, func)}
  383. The sash was double clicked. The default behaviour is to unsplit the
  384. window when this happens (unless the minimum pane size has been set
  385. to a value greater than zero). Processes a @c wxEVT_SPLITTER_DOUBLECLICKED event.
  386. @endEventTable
  387. @library{wxcore}
  388. @category{events}
  389. @see wxSplitterWindow, @ref overview_events
  390. */
  391. class wxSplitterEvent : public wxNotifyEvent
  392. {
  393. public:
  394. /**
  395. Constructor. Used internally by wxWidgets only.
  396. */
  397. wxSplitterEvent(wxEventType eventType = wxEVT_NULL,
  398. wxSplitterWindow* splitter = NULL);
  399. /**
  400. Returns the new sash position.
  401. May only be called while processing
  402. @c wxEVT_SPLITTER_SASH_POS_CHANGING and
  403. @c wxEVT_SPLITTER_SASH_POS_CHANGED events.
  404. */
  405. int GetSashPosition() const;
  406. /**
  407. Returns a pointer to the window being removed when a splitter window
  408. is unsplit.
  409. May only be called while processing
  410. @c wxEVT_SPLITTER_UNSPLIT events.
  411. */
  412. wxWindow* GetWindowBeingRemoved() const;
  413. /**
  414. Returns the x coordinate of the double-click point.
  415. May only be called while processing
  416. @c wxEVT_SPLITTER_DOUBLECLICKED events.
  417. */
  418. int GetX() const;
  419. /**
  420. Returns the y coordinate of the double-click point.
  421. May only be called while processing
  422. @c wxEVT_SPLITTER_DOUBLECLICKED events.
  423. */
  424. int GetY() const;
  425. /**
  426. In the case of @c wxEVT_SPLITTER_SASH_POS_CHANGED events,
  427. sets the new sash position.
  428. In the case of @c wxEVT_SPLITTER_SASH_POS_CHANGING events,
  429. sets the new tracking bar position so visual feedback during dragging will
  430. represent that change that will actually take place. Set to -1 from
  431. the event handler code to prevent repositioning.
  432. May only be called while processing
  433. @c wxEVT_SPLITTER_SASH_POS_CHANGING and
  434. @c wxEVT_SPLITTER_SASH_POS_CHANGED events.
  435. @param pos
  436. New sash position.
  437. */
  438. void SetSashPosition(int pos);
  439. };
  440. wxEventType wxEVT_SPLITTER_SASH_POS_CHANGED;
  441. wxEventType wxEVT_SPLITTER_SASH_POS_CHANGING;
  442. wxEventType wxEVT_SPLITTER_DOUBLECLICKED;
  443. wxEventType wxEVT_SPLITTER_UNSPLIT;