]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __SPLITTERH_G__ | |
13 | #define __SPLITTERH_G__ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "splitter.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/window.h" // base class declaration | |
20 | ||
21 | class WXDLLEXPORT wxSplitterEvent; | |
22 | ||
23 | // --------------------------------------------------------------------------- | |
24 | // splitter constants | |
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | enum | |
28 | { | |
29 | wxSPLIT_HORIZONTAL = 1, | |
30 | wxSPLIT_VERTICAL | |
31 | }; | |
32 | ||
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 | // --------------------------------------------------------------------------- | |
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 | { | |
57 | public: | |
58 | ||
59 | //////////////////////////////////////////////////////////////////////////// | |
60 | // Public API | |
61 | ||
62 | // Default constructor | |
63 | wxSplitterWindow() | |
64 | { | |
65 | Init(); | |
66 | } | |
67 | ||
68 | // Normal constructor | |
69 | wxSplitterWindow(wxWindow *parent, wxWindowID id = -1, | |
70 | const wxPoint& pos = wxDefaultPosition, | |
71 | const wxSize& size = wxDefaultSize, | |
72 | long style = wxSP_3D|wxCLIP_CHILDREN, | |
73 | const wxString& name = "splitter") | |
74 | { | |
75 | Init(); | |
76 | Create(parent, id, pos, size, style, name); | |
77 | } | |
78 | ||
79 | ~wxSplitterWindow(); | |
80 | ||
81 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
82 | const wxPoint& pos = wxDefaultPosition, | |
83 | const wxSize& size = wxDefaultSize, | |
84 | long style = wxSP_3D|wxCLIP_CHILDREN, | |
85 | const wxString& name = "splitter"); | |
86 | ||
87 | // Gets the only or left/top pane | |
88 | wxWindow *GetWindow1() const { return m_windowOne; } | |
89 | ||
90 | // Gets the right/bottom pane | |
91 | wxWindow *GetWindow2() const { return m_windowTwo; } | |
92 | ||
93 | // Sets the split mode | |
94 | void SetSplitMode(int mode) { m_splitMode = mode; } | |
95 | ||
96 | // Gets the split mode | |
97 | int GetSplitMode() const { return m_splitMode; }; | |
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. | |
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. | |
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); | |
114 | ||
115 | // Removes the specified (or second) window from the view | |
116 | // Doesn't actually delete the window. | |
117 | bool Unsplit(wxWindow *toRemove = (wxWindow *) NULL); | |
118 | ||
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 | ||
123 | // Is the window split? | |
124 | bool IsSplit() const { return (m_windowTwo != NULL); } | |
125 | ||
126 | // Sets the sash size | |
127 | void SetSashSize(int width) { m_sashSize = width; } | |
128 | ||
129 | // Sets the border size | |
130 | void SetBorderSize(int width) { m_borderSize = width; } | |
131 | ||
132 | // Gets the sash size | |
133 | int GetSashSize() const { return m_sashSize; } | |
134 | ||
135 | // Gets the border size | |
136 | int GetBorderSize() const { return m_borderSize; } | |
137 | ||
138 | // Set the sash position | |
139 | void SetSashPosition(int position, bool redraw = TRUE); | |
140 | ||
141 | // Gets the sash position | |
142 | int GetSashPosition() const { return m_sashPosition; } | |
143 | ||
144 | // If this is zero, we can remove panes by dragging the sash. | |
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. | |
150 | // Repositions sash to minimum position if pane would be too small. | |
151 | // newSashPosition here is always positive or zero. | |
152 | virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition)) | |
153 | { return TRUE; } | |
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. | |
158 | virtual void OnUnsplit(wxWindow *WXUNUSED(removed)) { } | |
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. | |
163 | virtual void OnDoubleClickSash(int WXUNUSED(x), int WXUNUSED(y)) { } | |
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 | ||
177 | // In live mode, resize child windows in idle time | |
178 | void OnIdle(wxIdleEvent& event); | |
179 | ||
180 | // Draws borders | |
181 | virtual void DrawBorders(wxDC& dc); | |
182 | ||
183 | // Draws the sash | |
184 | virtual void DrawSash(wxDC& dc); | |
185 | ||
186 | // Draws the sash tracker (for whilst moving the sash) | |
187 | virtual void DrawSashTracker(int x, int y); | |
188 | ||
189 | // Tests for x, y over sash | |
190 | virtual bool SashHitTest(int x, int y, int tolerance = 2); | |
191 | ||
192 | // Resizes subwindows | |
193 | virtual void SizeWindows(); | |
194 | ||
195 | // Initialize colours | |
196 | void InitColours(); | |
197 | ||
198 | void SetNeedUpdating(bool needUpdating) { m_needUpdating = needUpdating; } | |
199 | bool GetNeedUpdating() const { return m_needUpdating ; } | |
200 | ||
201 | protected: | |
202 | // our event handlers | |
203 | void OnSashPosChanged(wxSplitterEvent& event); | |
204 | void OnSashPosChanging(wxSplitterEvent& event); | |
205 | void OnDoubleClick(wxSplitterEvent& event); | |
206 | void OnUnsplitEvent(wxSplitterEvent& event); | |
207 | void OnSetCursor(wxSetCursorEvent& event); | |
208 | ||
209 | void SendUnsplitEvent(wxWindow *winRemoved); | |
210 | ||
211 | protected: | |
212 | void Init(); | |
213 | ||
214 | ||
215 | int m_splitMode; | |
216 | bool m_permitUnsplitAlways; | |
217 | bool m_needUpdating; // when in live mode, set this to TRUE to resize children in idle | |
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; | |
238 | ||
239 | private: | |
240 | DECLARE_DYNAMIC_CLASS(wxSplitterWindow) | |
241 | DECLARE_EVENT_TABLE() | |
242 | }; | |
243 | ||
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); | |
260 | if (splitter) m_id = splitter->GetId(); | |
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 | { | |
269 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED | |
270 | || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING); | |
271 | ||
272 | m_data.pos = pos; | |
273 | } | |
274 | ||
275 | int GetSashPosition() const | |
276 | { | |
277 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED | |
278 | || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING); | |
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: | |
307 | friend class WXDLLEXPORT wxSplitterWindow; | |
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) \ | |
326 | DECLARE_EVENT_TABLE_ENTRY( \ | |
327 | wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \ | |
328 | id, \ | |
329 | -1, \ | |
330 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
331 | NULL \ | |
332 | ), | |
333 | ||
334 | #define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \ | |
335 | DECLARE_EVENT_TABLE_ENTRY( \ | |
336 | wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \ | |
337 | id, \ | |
338 | -1, \ | |
339 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
340 | NULL \ | |
341 | ), | |
342 | ||
343 | #define EVT_SPLITTER_DCLICK(id, fn) \ | |
344 | DECLARE_EVENT_TABLE_ENTRY( \ | |
345 | wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \ | |
346 | id, \ | |
347 | -1, \ | |
348 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
349 | NULL \ | |
350 | ), | |
351 | ||
352 | #define EVT_SPLITTER_UNSPLIT(id, fn) \ | |
353 | DECLARE_EVENT_TABLE_ENTRY( \ | |
354 | wxEVT_COMMAND_SPLITTER_UNSPLIT, \ | |
355 | id, \ | |
356 | -1, \ | |
357 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
358 | NULL \ | |
359 | ), | |
360 | ||
361 | #endif // __SPLITTERH_G__ |