]>
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 |
c801d85f | 20 | |
42e69d6b | 21 | class WXDLLEXPORT wxSplitterEvent; |
c801d85f | 22 | |
42e69d6b VZ |
23 | // --------------------------------------------------------------------------- |
24 | // splitter constants | |
25 | // --------------------------------------------------------------------------- | |
c801d85f | 26 | |
42e69d6b VZ |
27 | enum |
28 | { | |
29 | wxSPLIT_HORIZONTAL = 1, | |
30 | wxSPLIT_VERTICAL | |
31 | }; | |
c801d85f | 32 | |
42e69d6b VZ |
33 | enum |
34 | { | |
35 | wxSPLIT_DRAG_NONE, | |
36 | wxSPLIT_DRAG_DRAGGING, | |
37 | wxSPLIT_DRAG_LEFT_DOWN | |
38 | }; | |
39 | ||
40 | // --------------------------------------------------------------------------- | |
41 | // wxSplitterWindow maintains one or two panes, with | |
42 | // an optional vertical or horizontal split which | |
43 | // can be used with the mouse or programmatically. | |
44 | // --------------------------------------------------------------------------- | |
c801d85f KB |
45 | |
46 | // TODO: | |
47 | // 1) Perhaps make the borders sensitive to dragging in order to create a split. | |
48 | // The MFC splitter window manages scrollbars as well so is able to | |
49 | // put sash buttons on the scrollbars, but we probably don't want to go down | |
50 | // this path. | |
51 | // 2) for wxWindows 2.0, we must find a way to set the WS_CLIPCHILDREN style | |
52 | // to prevent flickering. (WS_CLIPCHILDREN doesn't work in all cases so can't be | |
53 | // standard). | |
54 | ||
55 | class WXDLLEXPORT wxSplitterWindow: public wxWindow | |
56 | { | |
0d559d69 | 57 | public: |
c801d85f KB |
58 | |
59 | //////////////////////////////////////////////////////////////////////////// | |
60 | // Public API | |
61 | ||
62 | // Default constructor | |
f6bcfd97 BP |
63 | wxSplitterWindow() |
64 | { | |
65 | Init(); | |
66 | } | |
c801d85f KB |
67 | |
68 | // Normal constructor | |
0d559d69 VZ |
69 | wxSplitterWindow(wxWindow *parent, wxWindowID id = -1, |
70 | const wxPoint& pos = wxDefaultPosition, | |
71 | const wxSize& size = wxDefaultSize, | |
dead66ba | 72 | long style = wxSP_3D, |
f6bcfd97 BP |
73 | const wxString& name = "splitter") |
74 | { | |
75 | Init(); | |
76 | Create(parent, id, pos, size, style, name); | |
77 | } | |
78 | ||
0d559d69 | 79 | ~wxSplitterWindow(); |
c801d85f | 80 | |
f6bcfd97 BP |
81 | bool Create(wxWindow *parent, wxWindowID id = -1, |
82 | const wxPoint& pos = wxDefaultPosition, | |
83 | const wxSize& size = wxDefaultSize, | |
dead66ba | 84 | long style = wxSP_3D, |
f6bcfd97 BP |
85 | const wxString& name = "splitter"); |
86 | ||
c801d85f | 87 | // Gets the only or left/top pane |
0d559d69 | 88 | wxWindow *GetWindow1() const { return m_windowOne; } |
c801d85f KB |
89 | |
90 | // Gets the right/bottom pane | |
0d559d69 | 91 | wxWindow *GetWindow2() const { return m_windowTwo; } |
c801d85f KB |
92 | |
93 | // Sets the split mode | |
0d559d69 | 94 | void SetSplitMode(int mode) { m_splitMode = mode; } |
c801d85f KB |
95 | |
96 | // Gets the split mode | |
0d559d69 | 97 | int GetSplitMode() const { return m_splitMode; }; |
c801d85f KB |
98 | |
99 | // Initialize with one window | |
100 | void Initialize(wxWindow *window); | |
101 | ||
102 | // Associates the given window with window 2, drawing the appropriate sash | |
103 | // and changing the split mode. | |
104 | // Does nothing and returns FALSE if the window is already split. | |
0d559d69 VZ |
105 | // A sashPosition of 0 means choose a default sash position, |
106 | // negative sashPosition specifies the size of right/lower pane as it's | |
107 | // absolute value rather than the size of left/upper pane. | |
cce4b3fe VZ |
108 | virtual bool SplitVertically(wxWindow *window1, |
109 | wxWindow *window2, | |
110 | int sashPosition = 0); | |
111 | virtual bool SplitHorizontally(wxWindow *window1, | |
112 | wxWindow *window2, | |
113 | int sashPosition = 0); | |
c801d85f KB |
114 | |
115 | // Removes the specified (or second) window from the view | |
116 | // Doesn't actually delete the window. | |
c67daf87 | 117 | bool Unsplit(wxWindow *toRemove = (wxWindow *) NULL); |
c801d85f | 118 | |
3ad5e06b VZ |
119 | // Replaces one of the windows with another one (neither old nor new |
120 | // parameter should be NULL) | |
121 | bool ReplaceWindow(wxWindow *winOld, wxWindow *winNew); | |
122 | ||
c801d85f | 123 | // Is the window split? |
0d559d69 | 124 | bool IsSplit() const { return (m_windowTwo != NULL); } |
c801d85f KB |
125 | |
126 | // Sets the sash size | |
0d559d69 | 127 | void SetSashSize(int width) { m_sashSize = width; } |
c801d85f KB |
128 | |
129 | // Sets the border size | |
0d559d69 | 130 | void SetBorderSize(int width) { m_borderSize = width; } |
c801d85f KB |
131 | |
132 | // Gets the sash size | |
0d559d69 | 133 | int GetSashSize() const { return m_sashSize; } |
c801d85f KB |
134 | |
135 | // Gets the border size | |
0d559d69 | 136 | int GetBorderSize() const { return m_borderSize; } |
c801d85f KB |
137 | |
138 | // Set the sash position | |
42e69d6b | 139 | void SetSashPosition(int position, bool redraw = TRUE); |
c801d85f KB |
140 | |
141 | // Gets the sash position | |
0d559d69 | 142 | int GetSashPosition() const { return m_sashPosition; } |
c801d85f KB |
143 | |
144 | // If this is zero, we can remove panes by dragging the sash. | |
0d559d69 VZ |
145 | void SetMinimumPaneSize(int min) { m_minimumPaneSize = min; } |
146 | int GetMinimumPaneSize() const { return m_minimumPaneSize; } | |
147 | ||
148 | // Called when the sash position is about to be changed, return | |
149 | // FALSE from here to prevent the change from taking place. | |
021e7626 | 150 | // Repositions sash to minimum position if pane would be too small. |
0d559d69 | 151 | // newSashPosition here is always positive or zero. |
42e69d6b VZ |
152 | virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition)) |
153 | { return TRUE; } | |
c801d85f KB |
154 | |
155 | // If the sash is moved to an extreme position, a subwindow | |
156 | // is removed from the splitter window, and the app is | |
157 | // notified. The app should delete or hide the window. | |
42e69d6b | 158 | virtual void OnUnsplit(wxWindow *WXUNUSED(removed)) { } |
c801d85f KB |
159 | |
160 | // Called when the sash is double-clicked. | |
161 | // The default behaviour is to remove the sash if the | |
162 | // minimum pane size is zero. | |
42e69d6b | 163 | virtual void OnDoubleClickSash(int WXUNUSED(x), int WXUNUSED(y)) { } |
c801d85f KB |
164 | |
165 | //////////////////////////////////////////////////////////////////////////// | |
166 | // Implementation | |
167 | ||
168 | // Paints the border and sash | |
169 | void OnPaint(wxPaintEvent& event); | |
170 | ||
171 | // Handles mouse events | |
172 | void OnMouseEvent(wxMouseEvent& ev); | |
173 | ||
174 | // Adjusts the panes | |
175 | void OnSize(wxSizeEvent& event); | |
176 | ||
72195a0f RR |
177 | // In live mode, resize child windows in idle time |
178 | void OnIdle(wxIdleEvent& event); | |
179 | ||
c801d85f | 180 | // Draws borders |
f6bcfd97 | 181 | virtual void DrawBorders(wxDC& dc); |
c801d85f KB |
182 | |
183 | // Draws the sash | |
f6bcfd97 | 184 | virtual void DrawSash(wxDC& dc); |
c801d85f KB |
185 | |
186 | // Draws the sash tracker (for whilst moving the sash) | |
f6bcfd97 | 187 | virtual void DrawSashTracker(int x, int y); |
c801d85f KB |
188 | |
189 | // Tests for x, y over sash | |
f6bcfd97 | 190 | virtual bool SashHitTest(int x, int y, int tolerance = 2); |
c801d85f KB |
191 | |
192 | // Resizes subwindows | |
f6bcfd97 | 193 | virtual void SizeWindows(); |
c801d85f KB |
194 | |
195 | // Initialize colours | |
0d559d69 | 196 | void InitColours(); |
c801d85f | 197 | |
f6bcfd97 BP |
198 | void SetNeedUpdating(bool needUpdating) { m_needUpdating = needUpdating; } |
199 | bool GetNeedUpdating() const { return m_needUpdating ; } | |
200 | ||
0d559d69 | 201 | protected: |
42e69d6b VZ |
202 | // our event handlers |
203 | void OnSashPosChanged(wxSplitterEvent& event); | |
370938d9 | 204 | void OnSashPosChanging(wxSplitterEvent& event); |
42e69d6b VZ |
205 | void OnDoubleClick(wxSplitterEvent& event); |
206 | void OnUnsplitEvent(wxSplitterEvent& event); | |
43b5058d | 207 | void OnSetCursor(wxSetCursorEvent& event); |
42e69d6b VZ |
208 | |
209 | void SendUnsplitEvent(wxWindow *winRemoved); | |
210 | ||
8062a6ab | 211 | protected: |
f6bcfd97 BP |
212 | void Init(); |
213 | ||
214 | ||
c801d85f | 215 | int m_splitMode; |
370938d9 | 216 | bool m_permitUnsplitAlways; |
f6bcfd97 | 217 | bool m_needUpdating; // when in live mode, set this to TRUE to resize children in idle |
c801d85f KB |
218 | wxWindow* m_windowOne; |
219 | wxWindow* m_windowTwo; | |
220 | int m_dragMode; | |
221 | int m_oldX; | |
222 | int m_oldY; | |
223 | int m_borderSize; | |
224 | int m_sashSize; // Sash width or height | |
225 | int m_sashPosition; // Number of pixels from left or top | |
226 | int m_firstX; | |
227 | int m_firstY; | |
228 | int m_minimumPaneSize; | |
229 | wxCursor* m_sashCursorWE; | |
230 | wxCursor* m_sashCursorNS; | |
231 | wxPen* m_sashTrackerPen; | |
232 | wxPen* m_lightShadowPen; | |
233 | wxPen* m_mediumShadowPen; | |
234 | wxPen* m_darkShadowPen; | |
235 | wxPen* m_hilightPen; | |
236 | wxBrush* m_faceBrush; | |
237 | wxPen* m_facePen; | |
0d559d69 VZ |
238 | |
239 | private: | |
240 | DECLARE_DYNAMIC_CLASS(wxSplitterWindow) | |
241 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
242 | }; |
243 | ||
42e69d6b VZ |
244 | // ---------------------------------------------------------------------------- |
245 | // event class and macros | |
246 | // ---------------------------------------------------------------------------- | |
247 | ||
248 | // we reuse the same class for all splitter event types because this is the | |
249 | // usual wxWin convention, but the three event types have different kind of | |
250 | // data associated with them, so the accessors can be only used if the real | |
251 | // event type matches with the one for which the accessors make sense | |
252 | class WXDLLEXPORT wxSplitterEvent : public wxCommandEvent | |
253 | { | |
254 | public: | |
255 | wxSplitterEvent(wxEventType type = wxEVT_NULL, | |
256 | wxSplitterWindow *splitter = (wxSplitterWindow *)NULL) | |
257 | : wxCommandEvent(type) | |
258 | { | |
259 | SetEventObject(splitter); | |
0656d2e6 | 260 | if (splitter) m_id = splitter->GetId(); |
42e69d6b VZ |
261 | } |
262 | ||
263 | // SASH_POS_CHANGED methods | |
264 | ||
265 | // setting the sash position to -1 prevents the change from taking place at | |
266 | // all | |
267 | void SetSashPosition(int pos) | |
268 | { | |
370938d9 UB |
269 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED |
270 | || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING); | |
42e69d6b VZ |
271 | |
272 | m_data.pos = pos; | |
273 | } | |
274 | ||
275 | int GetSashPosition() const | |
276 | { | |
370938d9 UB |
277 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED |
278 | || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING); | |
42e69d6b VZ |
279 | |
280 | return m_data.pos; | |
281 | } | |
282 | ||
283 | // UNSPLIT event methods | |
284 | wxWindow *GetWindowBeingRemoved() const | |
285 | { | |
286 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT ); | |
287 | ||
288 | return m_data.win; | |
289 | } | |
290 | ||
291 | // DCLICK event methods | |
292 | int GetX() const | |
293 | { | |
294 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED ); | |
295 | ||
296 | return m_data.pt.x; | |
297 | } | |
298 | ||
299 | int GetY() const | |
300 | { | |
301 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED ); | |
302 | ||
303 | return m_data.pt.y; | |
304 | } | |
305 | ||
306 | private: | |
d5a07b9e | 307 | friend class WXDLLEXPORT wxSplitterWindow; |
42e69d6b VZ |
308 | |
309 | // data for the different types of event | |
310 | union | |
311 | { | |
312 | int pos; // position for SASH_POS_CHANGED event | |
313 | wxWindow *win; // window being removed for UNSPLIT event | |
314 | struct | |
315 | { | |
316 | int x, y; | |
317 | } pt; // position of double click for DCLICK event | |
318 | } m_data; | |
319 | ||
320 | DECLARE_DYNAMIC_CLASS(wxSplitterEvent) | |
321 | }; | |
322 | ||
323 | typedef void (wxEvtHandler::*wxSplitterEventFunction)(wxSplitterEvent&); | |
324 | ||
325 | #define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \ | |
2e4df4bf | 326 | DECLARE_EVENT_TABLE_ENTRY( \ |
42e69d6b VZ |
327 | wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \ |
328 | id, \ | |
329 | -1, \ | |
330 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
331 | NULL \ | |
82a5f02c | 332 | ), |
42e69d6b | 333 | |
370938d9 | 334 | #define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \ |
2e4df4bf | 335 | DECLARE_EVENT_TABLE_ENTRY( \ |
370938d9 UB |
336 | wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \ |
337 | id, \ | |
338 | -1, \ | |
339 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
340 | NULL \ | |
82a5f02c | 341 | ), |
370938d9 UB |
342 | |
343 | #define EVT_SPLITTER_DCLICK(id, fn) \ | |
2e4df4bf | 344 | DECLARE_EVENT_TABLE_ENTRY( \ |
370938d9 | 345 | wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \ |
42e69d6b VZ |
346 | id, \ |
347 | -1, \ | |
348 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
349 | NULL \ | |
82a5f02c | 350 | ), |
42e69d6b VZ |
351 | |
352 | #define EVT_SPLITTER_UNSPLIT(id, fn) \ | |
2e4df4bf | 353 | DECLARE_EVENT_TABLE_ENTRY( \ |
42e69d6b VZ |
354 | wxEVT_COMMAND_SPLITTER_UNSPLIT, \ |
355 | id, \ | |
356 | -1, \ | |
357 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
358 | NULL \ | |
82a5f02c | 359 | ), |
42e69d6b | 360 | |
0d559d69 | 361 | #endif // __SPLITTERH_G__ |