]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/splitter.h
GCC 4.0 (Apple 4059) is a little bit pickier than 3.3.
[wxWidgets.git] / include / wx / generic / splitter.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
3e58dcb9 2// Name: wx/splitter.h
c801d85f
KB
3// Purpose: wxSplitterWindow class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
371a5b4e 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __SPLITTERH_G__
13#define __SPLITTERH_G__
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
42e69d6b 16 #pragma interface "splitter.h"
c801d85f
KB
17#endif
18
42e69d6b 19#include "wx/window.h" // base class declaration
0013a77b 20#include "wx/containr.h" // wxControlContainer
c801d85f 21
42e69d6b 22class WXDLLEXPORT wxSplitterEvent;
c801d85f 23
42e69d6b
VZ
24// ---------------------------------------------------------------------------
25// splitter constants
26// ---------------------------------------------------------------------------
c801d85f 27
2e8cc3e8 28enum wxSplitMode
42e69d6b
VZ
29{
30 wxSPLIT_HORIZONTAL = 1,
31 wxSPLIT_VERTICAL
32};
c801d85f 33
42e69d6b
VZ
34enum
35{
36 wxSPLIT_DRAG_NONE,
37 wxSPLIT_DRAG_DRAGGING,
38 wxSPLIT_DRAG_LEFT_DOWN
39};
40
41// ---------------------------------------------------------------------------
42// wxSplitterWindow maintains one or two panes, with
43// an optional vertical or horizontal split which
44// can be used with the mouse or programmatically.
45// ---------------------------------------------------------------------------
c801d85f
KB
46
47// TODO:
48// 1) Perhaps make the borders sensitive to dragging in order to create a split.
49// The MFC splitter window manages scrollbars as well so is able to
50// put sash buttons on the scrollbars, but we probably don't want to go down
51// this path.
77ffb593 52// 2) for wxWidgets 2.0, we must find a way to set the WS_CLIPCHILDREN style
c801d85f
KB
53// to prevent flickering. (WS_CLIPCHILDREN doesn't work in all cases so can't be
54// standard).
55
56class WXDLLEXPORT wxSplitterWindow: public wxWindow
57{
0d559d69 58public:
c801d85f
KB
59
60////////////////////////////////////////////////////////////////////////////
61// Public API
62
63 // Default constructor
9948d31f 64 wxSplitterWindow()
f6bcfd97
BP
65 {
66 Init();
67 }
c801d85f
KB
68
69 // Normal constructor
ca65c044 70 wxSplitterWindow(wxWindow *parent, wxWindowID id = wxID_ANY,
0d559d69
VZ
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
dead66ba 73 long style = wxSP_3D,
2b5f62a0 74 const wxString& name = wxT("splitter"))
f6bcfd97
BP
75 {
76 Init();
77 Create(parent, id, pos, size, style, name);
78 }
79
6b55490a 80 virtual ~wxSplitterWindow();
c801d85f 81
ca65c044 82 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
f6bcfd97
BP
83 const wxPoint& pos = wxDefaultPosition,
84 const wxSize& size = wxDefaultSize,
dead66ba 85 long style = wxSP_3D,
2b5f62a0 86 const wxString& name = wxT("splitter"));
f6bcfd97 87
c801d85f 88 // Gets the only or left/top pane
0d559d69 89 wxWindow *GetWindow1() const { return m_windowOne; }
c801d85f
KB
90
91 // Gets the right/bottom pane
0d559d69 92 wxWindow *GetWindow2() const { return m_windowTwo; }
c801d85f
KB
93
94 // Sets the split mode
2e8cc3e8
VZ
95 void SetSplitMode(int mode)
96 {
97 wxASSERT_MSG( mode == wxSPLIT_VERTICAL || mode == wxSPLIT_HORIZONTAL,
98 _T("invalid split mode") );
99
100 m_splitMode = (wxSplitMode)mode;
101 }
c801d85f
KB
102
103 // Gets the split mode
2e8cc3e8 104 wxSplitMode GetSplitMode() const { return m_splitMode; };
c801d85f
KB
105
106 // Initialize with one window
107 void Initialize(wxWindow *window);
108
109 // Associates the given window with window 2, drawing the appropriate sash
110 // and changing the split mode.
4395fb21 111 // Does nothing and returns false if the window is already split.
0d559d69
VZ
112 // A sashPosition of 0 means choose a default sash position,
113 // negative sashPosition specifies the size of right/lower pane as it's
114 // absolute value rather than the size of left/upper pane.
cce4b3fe
VZ
115 virtual bool SplitVertically(wxWindow *window1,
116 wxWindow *window2,
2e8cc3e8
VZ
117 int sashPosition = 0)
118 { return DoSplit(wxSPLIT_VERTICAL, window1, window2, sashPosition); }
cce4b3fe
VZ
119 virtual bool SplitHorizontally(wxWindow *window1,
120 wxWindow *window2,
2e8cc3e8
VZ
121 int sashPosition = 0)
122 { return DoSplit(wxSPLIT_HORIZONTAL, window1, window2, sashPosition); }
c801d85f
KB
123
124 // Removes the specified (or second) window from the view
125 // Doesn't actually delete the window.
c67daf87 126 bool Unsplit(wxWindow *toRemove = (wxWindow *) NULL);
c801d85f 127
3ad5e06b
VZ
128 // Replaces one of the windows with another one (neither old nor new
129 // parameter should be NULL)
130 bool ReplaceWindow(wxWindow *winOld, wxWindow *winNew);
131
7e521b01
JS
132 // Make sure the child window sizes are updated. This is useful
133 // for reducing flicker by updating the sizes before a
134 // window is shown, if you know the overall size is correct.
135 void UpdateSize();
136
c801d85f 137 // Is the window split?
0d559d69 138 bool IsSplit() const { return (m_windowTwo != NULL); }
c801d85f
KB
139
140 // Sets the sash size
844adaa4 141 void SetSashSize(int width) { m_sashSize = width; }
c801d85f
KB
142
143 // Sets the border size
b3208e11 144 void SetBorderSize(int WXUNUSED(width)) { }
c801d85f
KB
145
146 // Gets the sash size
b3208e11 147 int GetSashSize() const;
c801d85f
KB
148
149 // Gets the border size
b3208e11 150 int GetBorderSize() const;
c801d85f
KB
151
152 // Set the sash position
4395fb21 153 void SetSashPosition(int position, bool redraw = true);
c801d85f
KB
154
155 // Gets the sash position
0d559d69 156 int GetSashPosition() const { return m_sashPosition; }
c801d85f 157
14b4c0ff
VZ
158 // Set the sash gravity
159 void SetSashGravity(double gravity);
160
161 // Gets the sash gravity
162 double GetSashGravity() const { return m_sashGravity; }
163
c801d85f 164 // If this is zero, we can remove panes by dragging the sash.
ca39e409 165 void SetMinimumPaneSize(int min);
0d559d69
VZ
166 int GetMinimumPaneSize() const { return m_minimumPaneSize; }
167
3e58dcb9
VZ
168 // NB: the OnXXX() functions below are for backwards compatibility only,
169 // don't use them in new code but handle the events instead!
170
171 // called when the sash position is about to change, may return a new value
172 // for the sash or -1 to prevent the change from happening at all
173 virtual int OnSashPositionChanging(int newSashPosition);
174
0d559d69 175 // Called when the sash position is about to be changed, return
4395fb21 176 // false from here to prevent the change from taking place.
021e7626 177 // Repositions sash to minimum position if pane would be too small.
0d559d69 178 // newSashPosition here is always positive or zero.
3e58dcb9 179 virtual bool OnSashPositionChange(int newSashPosition);
c801d85f
KB
180
181 // If the sash is moved to an extreme position, a subwindow
182 // is removed from the splitter window, and the app is
183 // notified. The app should delete or hide the window.
3e58dcb9 184 virtual void OnUnsplit(wxWindow *removed);
c801d85f
KB
185
186 // Called when the sash is double-clicked.
187 // The default behaviour is to remove the sash if the
188 // minimum pane size is zero.
3e58dcb9 189 virtual void OnDoubleClickSash(int x, int y);
c801d85f
KB
190
191////////////////////////////////////////////////////////////////////////////
192// Implementation
193
194 // Paints the border and sash
195 void OnPaint(wxPaintEvent& event);
196
197 // Handles mouse events
198 void OnMouseEvent(wxMouseEvent& ev);
199
200 // Adjusts the panes
201 void OnSize(wxSizeEvent& event);
202
72195a0f 203 // In live mode, resize child windows in idle time
5180055b 204 void OnInternalIdle();
72195a0f 205
c801d85f 206 // Draws the sash
f6bcfd97 207 virtual void DrawSash(wxDC& dc);
c801d85f
KB
208
209 // Draws the sash tracker (for whilst moving the sash)
f6bcfd97 210 virtual void DrawSashTracker(int x, int y);
c801d85f
KB
211
212 // Tests for x, y over sash
b3208e11 213 virtual bool SashHitTest(int x, int y, int tolerance = 5);
c801d85f
KB
214
215 // Resizes subwindows
f6bcfd97 216 virtual void SizeWindows();
c801d85f 217
f6bcfd97
BP
218 void SetNeedUpdating(bool needUpdating) { m_needUpdating = needUpdating; }
219 bool GetNeedUpdating() const { return m_needUpdating ; }
220
53409666 221#ifdef __WXMAC__
14b4c0ff 222 virtual bool MacClipGrandChildren() const { return true ; }
53409666 223#endif
976b3cb3 224
0d559d69 225protected:
3e58dcb9 226 // event handlers
91ce04cf 227#if defined(__WXMSW__) || defined(__WXMAC__)
43b5058d 228 void OnSetCursor(wxSetCursorEvent& event);
3e58dcb9 229#endif // wxMSW
42e69d6b 230
4395fb21 231 // send the given event, return false if the event was processed and vetoed
3e58dcb9
VZ
232 // by the user code
233 inline bool DoSendEvent(wxSplitterEvent& event);
42e69d6b 234
6b55490a 235 // common part of all ctors
f6bcfd97 236 void Init();
2e8cc3e8
VZ
237
238 // common part of SplitVertically() and SplitHorizontally()
239 bool DoSplit(wxSplitMode mode,
240 wxWindow *window1, wxWindow *window2,
241 int sashPosition);
242
d76ac8ed 243 // adjusts sash position with respect to min. pane and window sizes
2e8cc3e8
VZ
244 int AdjustSashPosition(int sashPos) const;
245
246 // get either width or height depending on the split mode
247 int GetWindowSize() const;
74c57d1f
VZ
248
249 // convert the user specified sash position which may be > 0 (as is), < 0
250 // (specifying the size of the right pane) or 0 (use default) to the real
251 // position to be passed to DoSetSashPosition()
252 int ConvertSashPosition(int sashPos) const;
253
254 // set the real sash position, sashPos here must be positive
63ec9dbb 255 //
4395fb21 256 // returns true if the sash position has been changed, false otherwise
63ec9dbb
VZ
257 bool DoSetSashPosition(int sashPos);
258
259 // set the sash position and send an event about it having been changed
260 void SetSashPositionAndNotify(int sashPos);
f6bcfd97 261
af99040c
VZ
262 // callbacks executed when we detect that the mouse has entered or left
263 // the sash
264 virtual void OnEnterSash();
265 virtual void OnLeaveSash();
266
153b7996
VZ
267 // set the cursor appropriate for the current split mode
268 void SetResizeCursor();
269
af99040c
VZ
270 // redraw the splitter if its "hotness" changed if necessary
271 void RedrawIfHotSensitive(bool isHot);
272
976b3cb3
VZ
273 // return the best size of the splitter equal to best sizes of its
274 // subwindows
275 virtual wxSize DoGetBestSize() const;
276
277
2e8cc3e8 278 wxSplitMode m_splitMode;
c801d85f
KB
279 wxWindow* m_windowOne;
280 wxWindow* m_windowTwo;
281 int m_dragMode;
282 int m_oldX;
283 int m_oldY;
c801d85f 284 int m_sashPosition; // Number of pixels from left or top
14b4c0ff 285 double m_sashGravity;
844adaa4 286 int m_sashSize;
14b4c0ff 287 wxSize m_lastSize;
ca39e409 288 int m_requestedSashPosition;
153b7996 289 int m_sashPositionCurrent; // while dragging
c801d85f
KB
290 int m_firstX;
291 int m_firstY;
292 int m_minimumPaneSize;
153b7996
VZ
293 wxCursor m_sashCursorWE;
294 wxCursor m_sashCursorNS;
b3208e11 295 wxPen *m_sashTrackerPen;
0d559d69 296
4395fb21 297 // when in live mode, set this to true to resize children in idle
af99040c
VZ
298 bool m_needUpdating:1;
299 bool m_permitUnsplitAlways:1;
300 bool m_isHot:1;
4395fb21 301 bool m_checkRequestedSashPosition:1;
af99040c 302
0d559d69 303private:
6b55490a
VZ
304 WX_DECLARE_CONTROL_CONTAINER();
305
0d559d69
VZ
306 DECLARE_DYNAMIC_CLASS(wxSplitterWindow)
307 DECLARE_EVENT_TABLE()
22f3361e 308 DECLARE_NO_COPY_CLASS(wxSplitterWindow)
c801d85f
KB
309};
310
42e69d6b
VZ
311// ----------------------------------------------------------------------------
312// event class and macros
313// ----------------------------------------------------------------------------
314
315// we reuse the same class for all splitter event types because this is the
316// usual wxWin convention, but the three event types have different kind of
317// data associated with them, so the accessors can be only used if the real
318// event type matches with the one for which the accessors make sense
3e58dcb9 319class WXDLLEXPORT wxSplitterEvent : public wxNotifyEvent
42e69d6b
VZ
320{
321public:
322 wxSplitterEvent(wxEventType type = wxEVT_NULL,
323 wxSplitterWindow *splitter = (wxSplitterWindow *)NULL)
3e58dcb9 324 : wxNotifyEvent(type)
42e69d6b
VZ
325 {
326 SetEventObject(splitter);
0656d2e6 327 if (splitter) m_id = splitter->GetId();
42e69d6b
VZ
328 }
329
330 // SASH_POS_CHANGED methods
331
332 // setting the sash position to -1 prevents the change from taking place at
333 // all
334 void SetSashPosition(int pos)
335 {
370938d9
UB
336 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
337 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING);
42e69d6b
VZ
338
339 m_data.pos = pos;
340 }
341
342 int GetSashPosition() const
343 {
370938d9
UB
344 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
345 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING);
42e69d6b
VZ
346
347 return m_data.pos;
348 }
349
350 // UNSPLIT event methods
351 wxWindow *GetWindowBeingRemoved() const
352 {
353 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT );
354
355 return m_data.win;
356 }
357
358 // DCLICK event methods
359 int GetX() const
360 {
361 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED );
362
363 return m_data.pt.x;
364 }
365
366 int GetY() const
367 {
368 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED );
369
370 return m_data.pt.y;
371 }
372
373private:
d5a07b9e 374 friend class WXDLLEXPORT wxSplitterWindow;
42e69d6b
VZ
375
376 // data for the different types of event
377 union
378 {
379 int pos; // position for SASH_POS_CHANGED event
380 wxWindow *win; // window being removed for UNSPLIT event
381 struct
382 {
383 int x, y;
384 } pt; // position of double click for DCLICK event
385 } m_data;
386
fc7a2a60 387 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSplitterEvent)
42e69d6b
VZ
388};
389
390typedef void (wxEvtHandler::*wxSplitterEventFunction)(wxSplitterEvent&);
391
7fa03f04 392#define wxSplitterEventHandler(func) \
d94c09cd 393 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSplitterEventFunction, &func)
7fa03f04
VZ
394
395#define wx__DECLARE_SPLITTEREVT(evt, id, fn) \
396 wx__DECLARE_EVT1(wxEVT_COMMAND_SPLITTER_ ## evt, id, wxSplitterEventHandler(fn))
397
398#define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \
399 wx__DECLARE_SPLITTEREVT(SASH_POS_CHANGED, id, fn)
400
401#define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \
402 wx__DECLARE_SPLITTEREVT(SASH_POS_CHANGING, id, fn)
403
404#define EVT_SPLITTER_DCLICK(id, fn) \
405 wx__DECLARE_SPLITTEREVT(DOUBLECLICKED, id, fn)
406
407#define EVT_SPLITTER_UNSPLIT(id, fn) \
408 wx__DECLARE_SPLITTEREVT(UNSPLIT, id, fn)
42e69d6b 409
0d559d69 410#endif // __SPLITTERH_G__