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