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