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