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