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