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