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