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