]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: splitter.h | |
3 | // Purpose: wxSplitterWindow class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
0d559d69 | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef __SPLITTERH_G__ | |
13 | #define __SPLITTERH_G__ | |
14 | ||
15 | #ifdef __GNUG__ | |
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 | 22 | class WXDLLEXPORT wxSplitterEvent; |
c801d85f | 23 | |
42e69d6b VZ |
24 | // --------------------------------------------------------------------------- |
25 | // splitter constants | |
26 | // --------------------------------------------------------------------------- | |
c801d85f | 27 | |
2e8cc3e8 | 28 | enum wxSplitMode |
42e69d6b VZ |
29 | { |
30 | wxSPLIT_HORIZONTAL = 1, | |
31 | wxSPLIT_VERTICAL | |
32 | }; | |
c801d85f | 33 | |
42e69d6b VZ |
34 | enum |
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. | |
52 | // 2) for wxWindows 2.0, we must find a way to set the WS_CLIPCHILDREN style | |
53 | // to prevent flickering. (WS_CLIPCHILDREN doesn't work in all cases so can't be | |
54 | // standard). | |
55 | ||
56 | class WXDLLEXPORT wxSplitterWindow: public wxWindow | |
57 | { | |
0d559d69 | 58 | public: |
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 | |
0d559d69 VZ |
70 | wxSplitterWindow(wxWindow *parent, wxWindowID id = -1, |
71 | const wxPoint& pos = wxDefaultPosition, | |
72 | const wxSize& size = wxDefaultSize, | |
dead66ba | 73 | long style = wxSP_3D, |
f6bcfd97 BP |
74 | const wxString& name = "splitter") |
75 | { | |
76 | Init(); | |
77 | Create(parent, id, pos, size, style, name); | |
78 | } | |
79 | ||
6b55490a | 80 | virtual ~wxSplitterWindow(); |
c801d85f | 81 | |
f6bcfd97 BP |
82 | bool Create(wxWindow *parent, wxWindowID id = -1, |
83 | const wxPoint& pos = wxDefaultPosition, | |
84 | const wxSize& size = wxDefaultSize, | |
dead66ba | 85 | long style = wxSP_3D, |
f6bcfd97 BP |
86 | const wxString& name = "splitter"); |
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. | |
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 | ||
c801d85f | 132 | // Is the window split? |
0d559d69 | 133 | bool IsSplit() const { return (m_windowTwo != NULL); } |
c801d85f KB |
134 | |
135 | // Sets the sash size | |
0d559d69 | 136 | void SetSashSize(int width) { m_sashSize = width; } |
c801d85f KB |
137 | |
138 | // Sets the border size | |
0d559d69 | 139 | void SetBorderSize(int width) { m_borderSize = width; } |
c801d85f KB |
140 | |
141 | // Gets the sash size | |
0d559d69 | 142 | int GetSashSize() const { return m_sashSize; } |
c801d85f KB |
143 | |
144 | // Gets the border size | |
0d559d69 | 145 | int GetBorderSize() const { return m_borderSize; } |
c801d85f KB |
146 | |
147 | // Set the sash position | |
42e69d6b | 148 | void SetSashPosition(int position, bool redraw = TRUE); |
c801d85f KB |
149 | |
150 | // Gets the sash position | |
0d559d69 | 151 | int GetSashPosition() const { return m_sashPosition; } |
c801d85f KB |
152 | |
153 | // If this is zero, we can remove panes by dragging the sash. | |
0d559d69 VZ |
154 | void SetMinimumPaneSize(int min) { m_minimumPaneSize = min; } |
155 | int GetMinimumPaneSize() const { return m_minimumPaneSize; } | |
156 | ||
157 | // Called when the sash position is about to be changed, return | |
158 | // FALSE from here to prevent the change from taking place. | |
021e7626 | 159 | // Repositions sash to minimum position if pane would be too small. |
0d559d69 | 160 | // newSashPosition here is always positive or zero. |
42e69d6b VZ |
161 | virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition)) |
162 | { return TRUE; } | |
c801d85f KB |
163 | |
164 | // If the sash is moved to an extreme position, a subwindow | |
165 | // is removed from the splitter window, and the app is | |
166 | // notified. The app should delete or hide the window. | |
42e69d6b | 167 | virtual void OnUnsplit(wxWindow *WXUNUSED(removed)) { } |
c801d85f KB |
168 | |
169 | // Called when the sash is double-clicked. | |
170 | // The default behaviour is to remove the sash if the | |
171 | // minimum pane size is zero. | |
42e69d6b | 172 | virtual void OnDoubleClickSash(int WXUNUSED(x), int WXUNUSED(y)) { } |
c801d85f KB |
173 | |
174 | //////////////////////////////////////////////////////////////////////////// | |
175 | // Implementation | |
176 | ||
177 | // Paints the border and sash | |
178 | void OnPaint(wxPaintEvent& event); | |
179 | ||
180 | // Handles mouse events | |
181 | void OnMouseEvent(wxMouseEvent& ev); | |
182 | ||
183 | // Adjusts the panes | |
184 | void OnSize(wxSizeEvent& event); | |
185 | ||
72195a0f RR |
186 | // In live mode, resize child windows in idle time |
187 | void OnIdle(wxIdleEvent& event); | |
188 | ||
c801d85f | 189 | // Draws borders |
f6bcfd97 | 190 | virtual void DrawBorders(wxDC& dc); |
c801d85f KB |
191 | |
192 | // Draws the sash | |
f6bcfd97 | 193 | virtual void DrawSash(wxDC& dc); |
c801d85f KB |
194 | |
195 | // Draws the sash tracker (for whilst moving the sash) | |
f6bcfd97 | 196 | virtual void DrawSashTracker(int x, int y); |
c801d85f KB |
197 | |
198 | // Tests for x, y over sash | |
f6bcfd97 | 199 | virtual bool SashHitTest(int x, int y, int tolerance = 2); |
c801d85f KB |
200 | |
201 | // Resizes subwindows | |
f6bcfd97 | 202 | virtual void SizeWindows(); |
c801d85f KB |
203 | |
204 | // Initialize colours | |
0d559d69 | 205 | void InitColours(); |
c801d85f | 206 | |
f6bcfd97 BP |
207 | void SetNeedUpdating(bool needUpdating) { m_needUpdating = needUpdating; } |
208 | bool GetNeedUpdating() const { return m_needUpdating ; } | |
209 | ||
0d559d69 | 210 | protected: |
42e69d6b VZ |
211 | // our event handlers |
212 | void OnSashPosChanged(wxSplitterEvent& event); | |
370938d9 | 213 | void OnSashPosChanging(wxSplitterEvent& event); |
42e69d6b VZ |
214 | void OnDoubleClick(wxSplitterEvent& event); |
215 | void OnUnsplitEvent(wxSplitterEvent& event); | |
43b5058d | 216 | void OnSetCursor(wxSetCursorEvent& event); |
42e69d6b VZ |
217 | |
218 | void SendUnsplitEvent(wxWindow *winRemoved); | |
219 | ||
8062a6ab | 220 | protected: |
6b55490a | 221 | // common part of all ctors |
f6bcfd97 | 222 | void Init(); |
2e8cc3e8 VZ |
223 | |
224 | // common part of SplitVertically() and SplitHorizontally() | |
225 | bool DoSplit(wxSplitMode mode, | |
226 | wxWindow *window1, wxWindow *window2, | |
227 | int sashPosition); | |
228 | ||
d76ac8ed | 229 | // adjusts sash position with respect to min. pane and window sizes |
2e8cc3e8 VZ |
230 | int AdjustSashPosition(int sashPos) const; |
231 | ||
232 | // get either width or height depending on the split mode | |
233 | int GetWindowSize() const; | |
f6bcfd97 | 234 | |
2e8cc3e8 | 235 | wxSplitMode m_splitMode; |
370938d9 | 236 | bool m_permitUnsplitAlways; |
f6bcfd97 | 237 | bool m_needUpdating; // when in live mode, set this to TRUE to resize children in idle |
c801d85f KB |
238 | wxWindow* m_windowOne; |
239 | wxWindow* m_windowTwo; | |
240 | int m_dragMode; | |
241 | int m_oldX; | |
242 | int m_oldY; | |
243 | int m_borderSize; | |
244 | int m_sashSize; // Sash width or height | |
245 | int m_sashPosition; // Number of pixels from left or top | |
246 | int m_firstX; | |
247 | int m_firstY; | |
248 | int m_minimumPaneSize; | |
249 | wxCursor* m_sashCursorWE; | |
250 | wxCursor* m_sashCursorNS; | |
251 | wxPen* m_sashTrackerPen; | |
252 | wxPen* m_lightShadowPen; | |
253 | wxPen* m_mediumShadowPen; | |
254 | wxPen* m_darkShadowPen; | |
255 | wxPen* m_hilightPen; | |
256 | wxBrush* m_faceBrush; | |
257 | wxPen* m_facePen; | |
0d559d69 VZ |
258 | |
259 | private: | |
6b55490a VZ |
260 | WX_DECLARE_CONTROL_CONTAINER(); |
261 | ||
0d559d69 VZ |
262 | DECLARE_DYNAMIC_CLASS(wxSplitterWindow) |
263 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
264 | }; |
265 | ||
42e69d6b VZ |
266 | // ---------------------------------------------------------------------------- |
267 | // event class and macros | |
268 | // ---------------------------------------------------------------------------- | |
269 | ||
270 | // we reuse the same class for all splitter event types because this is the | |
271 | // usual wxWin convention, but the three event types have different kind of | |
272 | // data associated with them, so the accessors can be only used if the real | |
273 | // event type matches with the one for which the accessors make sense | |
274 | class WXDLLEXPORT wxSplitterEvent : public wxCommandEvent | |
275 | { | |
276 | public: | |
277 | wxSplitterEvent(wxEventType type = wxEVT_NULL, | |
278 | wxSplitterWindow *splitter = (wxSplitterWindow *)NULL) | |
279 | : wxCommandEvent(type) | |
280 | { | |
281 | SetEventObject(splitter); | |
0656d2e6 | 282 | if (splitter) m_id = splitter->GetId(); |
42e69d6b VZ |
283 | } |
284 | ||
285 | // SASH_POS_CHANGED methods | |
286 | ||
287 | // setting the sash position to -1 prevents the change from taking place at | |
288 | // all | |
289 | void SetSashPosition(int pos) | |
290 | { | |
370938d9 UB |
291 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED |
292 | || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING); | |
42e69d6b VZ |
293 | |
294 | m_data.pos = pos; | |
295 | } | |
296 | ||
297 | int GetSashPosition() const | |
298 | { | |
370938d9 UB |
299 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED |
300 | || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING); | |
42e69d6b VZ |
301 | |
302 | return m_data.pos; | |
303 | } | |
304 | ||
305 | // UNSPLIT event methods | |
306 | wxWindow *GetWindowBeingRemoved() const | |
307 | { | |
308 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT ); | |
309 | ||
310 | return m_data.win; | |
311 | } | |
312 | ||
313 | // DCLICK event methods | |
314 | int GetX() const | |
315 | { | |
316 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED ); | |
317 | ||
318 | return m_data.pt.x; | |
319 | } | |
320 | ||
321 | int GetY() const | |
322 | { | |
323 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED ); | |
324 | ||
325 | return m_data.pt.y; | |
326 | } | |
327 | ||
328 | private: | |
d5a07b9e | 329 | friend class WXDLLEXPORT wxSplitterWindow; |
42e69d6b VZ |
330 | |
331 | // data for the different types of event | |
332 | union | |
333 | { | |
334 | int pos; // position for SASH_POS_CHANGED event | |
335 | wxWindow *win; // window being removed for UNSPLIT event | |
336 | struct | |
337 | { | |
338 | int x, y; | |
339 | } pt; // position of double click for DCLICK event | |
340 | } m_data; | |
341 | ||
342 | DECLARE_DYNAMIC_CLASS(wxSplitterEvent) | |
343 | }; | |
344 | ||
345 | typedef void (wxEvtHandler::*wxSplitterEventFunction)(wxSplitterEvent&); | |
346 | ||
347 | #define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \ | |
2e4df4bf | 348 | DECLARE_EVENT_TABLE_ENTRY( \ |
42e69d6b VZ |
349 | wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \ |
350 | id, \ | |
351 | -1, \ | |
352 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
353 | NULL \ | |
82a5f02c | 354 | ), |
42e69d6b | 355 | |
370938d9 | 356 | #define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \ |
2e4df4bf | 357 | DECLARE_EVENT_TABLE_ENTRY( \ |
370938d9 UB |
358 | wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \ |
359 | id, \ | |
360 | -1, \ | |
361 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
362 | NULL \ | |
82a5f02c | 363 | ), |
370938d9 UB |
364 | |
365 | #define EVT_SPLITTER_DCLICK(id, fn) \ | |
2e4df4bf | 366 | DECLARE_EVENT_TABLE_ENTRY( \ |
370938d9 | 367 | wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \ |
42e69d6b VZ |
368 | id, \ |
369 | -1, \ | |
370 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
371 | NULL \ | |
82a5f02c | 372 | ), |
42e69d6b VZ |
373 | |
374 | #define EVT_SPLITTER_UNSPLIT(id, fn) \ | |
2e4df4bf | 375 | DECLARE_EVENT_TABLE_ENTRY( \ |
42e69d6b VZ |
376 | wxEVT_COMMAND_SPLITTER_UNSPLIT, \ |
377 | id, \ | |
378 | -1, \ | |
379 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
380 | NULL \ | |
82a5f02c | 381 | ), |
42e69d6b | 382 | |
0d559d69 | 383 | #endif // __SPLITTERH_G__ |