]>
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 | |
0d559d69 | 63 | wxSplitterWindow(); |
c801d85f KB |
64 | |
65 | // Normal constructor | |
0d559d69 VZ |
66 | wxSplitterWindow(wxWindow *parent, wxWindowID id = -1, |
67 | const wxPoint& pos = wxDefaultPosition, | |
68 | const wxSize& size = wxDefaultSize, | |
69 | long style = wxSP_3D|wxCLIP_CHILDREN, | |
70 | const wxString& name = "splitter"); | |
71 | ~wxSplitterWindow(); | |
c801d85f KB |
72 | |
73 | // Gets the only or left/top pane | |
0d559d69 | 74 | wxWindow *GetWindow1() const { return m_windowOne; } |
c801d85f KB |
75 | |
76 | // Gets the right/bottom pane | |
0d559d69 | 77 | wxWindow *GetWindow2() const { return m_windowTwo; } |
c801d85f KB |
78 | |
79 | // Sets the split mode | |
0d559d69 | 80 | void SetSplitMode(int mode) { m_splitMode = mode; } |
c801d85f KB |
81 | |
82 | // Gets the split mode | |
0d559d69 | 83 | int GetSplitMode() const { return m_splitMode; }; |
c801d85f KB |
84 | |
85 | // Initialize with one window | |
86 | void Initialize(wxWindow *window); | |
87 | ||
88 | // Associates the given window with window 2, drawing the appropriate sash | |
89 | // and changing the split mode. | |
90 | // Does nothing and returns FALSE if the window is already split. | |
0d559d69 VZ |
91 | // A sashPosition of 0 means choose a default sash position, |
92 | // negative sashPosition specifies the size of right/lower pane as it's | |
93 | // absolute value rather than the size of left/upper pane. | |
cce4b3fe VZ |
94 | virtual bool SplitVertically(wxWindow *window1, |
95 | wxWindow *window2, | |
96 | int sashPosition = 0); | |
97 | virtual bool SplitHorizontally(wxWindow *window1, | |
98 | wxWindow *window2, | |
99 | int sashPosition = 0); | |
c801d85f KB |
100 | |
101 | // Removes the specified (or second) window from the view | |
102 | // Doesn't actually delete the window. | |
c67daf87 | 103 | bool Unsplit(wxWindow *toRemove = (wxWindow *) NULL); |
c801d85f | 104 | |
3ad5e06b VZ |
105 | // Replaces one of the windows with another one (neither old nor new |
106 | // parameter should be NULL) | |
107 | bool ReplaceWindow(wxWindow *winOld, wxWindow *winNew); | |
108 | ||
c801d85f | 109 | // Is the window split? |
0d559d69 | 110 | bool IsSplit() const { return (m_windowTwo != NULL); } |
c801d85f KB |
111 | |
112 | // Sets the sash size | |
0d559d69 | 113 | void SetSashSize(int width) { m_sashSize = width; } |
c801d85f KB |
114 | |
115 | // Sets the border size | |
0d559d69 | 116 | void SetBorderSize(int width) { m_borderSize = width; } |
c801d85f KB |
117 | |
118 | // Gets the sash size | |
0d559d69 | 119 | int GetSashSize() const { return m_sashSize; } |
c801d85f KB |
120 | |
121 | // Gets the border size | |
0d559d69 | 122 | int GetBorderSize() const { return m_borderSize; } |
c801d85f KB |
123 | |
124 | // Set the sash position | |
42e69d6b | 125 | void SetSashPosition(int position, bool redraw = TRUE); |
c801d85f KB |
126 | |
127 | // Gets the sash position | |
0d559d69 | 128 | int GetSashPosition() const { return m_sashPosition; } |
c801d85f KB |
129 | |
130 | // If this is zero, we can remove panes by dragging the sash. | |
0d559d69 VZ |
131 | void SetMinimumPaneSize(int min) { m_minimumPaneSize = min; } |
132 | int GetMinimumPaneSize() const { return m_minimumPaneSize; } | |
133 | ||
134 | // Called when the sash position is about to be changed, return | |
135 | // FALSE from here to prevent the change from taking place. | |
021e7626 | 136 | // Repositions sash to minimum position if pane would be too small. |
0d559d69 | 137 | // newSashPosition here is always positive or zero. |
42e69d6b VZ |
138 | virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition)) |
139 | { return TRUE; } | |
c801d85f KB |
140 | |
141 | // If the sash is moved to an extreme position, a subwindow | |
142 | // is removed from the splitter window, and the app is | |
143 | // notified. The app should delete or hide the window. | |
42e69d6b | 144 | virtual void OnUnsplit(wxWindow *WXUNUSED(removed)) { } |
c801d85f KB |
145 | |
146 | // Called when the sash is double-clicked. | |
147 | // The default behaviour is to remove the sash if the | |
148 | // minimum pane size is zero. | |
42e69d6b | 149 | virtual void OnDoubleClickSash(int WXUNUSED(x), int WXUNUSED(y)) { } |
c801d85f KB |
150 | |
151 | //////////////////////////////////////////////////////////////////////////// | |
152 | // Implementation | |
153 | ||
154 | // Paints the border and sash | |
155 | void OnPaint(wxPaintEvent& event); | |
156 | ||
157 | // Handles mouse events | |
158 | void OnMouseEvent(wxMouseEvent& ev); | |
159 | ||
160 | // Adjusts the panes | |
161 | void OnSize(wxSizeEvent& event); | |
162 | ||
163 | // Draws borders | |
164 | void DrawBorders(wxDC& dc); | |
165 | ||
166 | // Draws the sash | |
167 | void DrawSash(wxDC& dc); | |
168 | ||
169 | // Draws the sash tracker (for whilst moving the sash) | |
debe6624 | 170 | void DrawSashTracker(int x, int y); |
c801d85f KB |
171 | |
172 | // Tests for x, y over sash | |
debe6624 | 173 | bool SashHitTest(int x, int y, int tolerance = 2); |
c801d85f KB |
174 | |
175 | // Resizes subwindows | |
0d559d69 | 176 | void SizeWindows(); |
c801d85f KB |
177 | |
178 | // Initialize colours | |
0d559d69 | 179 | void InitColours(); |
c801d85f | 180 | |
0d559d69 | 181 | protected: |
42e69d6b VZ |
182 | // our event handlers |
183 | void OnSashPosChanged(wxSplitterEvent& event); | |
184 | void OnDoubleClick(wxSplitterEvent& event); | |
185 | void OnUnsplitEvent(wxSplitterEvent& event); | |
186 | ||
187 | void SendUnsplitEvent(wxWindow *winRemoved); | |
188 | ||
c801d85f KB |
189 | int m_splitMode; |
190 | wxWindow* m_windowOne; | |
191 | wxWindow* m_windowTwo; | |
192 | int m_dragMode; | |
193 | int m_oldX; | |
194 | int m_oldY; | |
195 | int m_borderSize; | |
196 | int m_sashSize; // Sash width or height | |
197 | int m_sashPosition; // Number of pixels from left or top | |
198 | int m_firstX; | |
199 | int m_firstY; | |
200 | int m_minimumPaneSize; | |
201 | wxCursor* m_sashCursorWE; | |
202 | wxCursor* m_sashCursorNS; | |
203 | wxPen* m_sashTrackerPen; | |
204 | wxPen* m_lightShadowPen; | |
205 | wxPen* m_mediumShadowPen; | |
206 | wxPen* m_darkShadowPen; | |
207 | wxPen* m_hilightPen; | |
208 | wxBrush* m_faceBrush; | |
209 | wxPen* m_facePen; | |
0d559d69 VZ |
210 | |
211 | private: | |
212 | DECLARE_DYNAMIC_CLASS(wxSplitterWindow) | |
213 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
214 | }; |
215 | ||
42e69d6b VZ |
216 | // ---------------------------------------------------------------------------- |
217 | // event class and macros | |
218 | // ---------------------------------------------------------------------------- | |
219 | ||
220 | // we reuse the same class for all splitter event types because this is the | |
221 | // usual wxWin convention, but the three event types have different kind of | |
222 | // data associated with them, so the accessors can be only used if the real | |
223 | // event type matches with the one for which the accessors make sense | |
224 | class WXDLLEXPORT wxSplitterEvent : public wxCommandEvent | |
225 | { | |
226 | public: | |
227 | wxSplitterEvent(wxEventType type = wxEVT_NULL, | |
228 | wxSplitterWindow *splitter = (wxSplitterWindow *)NULL) | |
229 | : wxCommandEvent(type) | |
230 | { | |
231 | SetEventObject(splitter); | |
232 | } | |
233 | ||
234 | // SASH_POS_CHANGED methods | |
235 | ||
236 | // setting the sash position to -1 prevents the change from taking place at | |
237 | // all | |
238 | void SetSashPosition(int pos) | |
239 | { | |
240 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED ); | |
241 | ||
242 | m_data.pos = pos; | |
243 | } | |
244 | ||
245 | int GetSashPosition() const | |
246 | { | |
247 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED ); | |
248 | ||
249 | return m_data.pos; | |
250 | } | |
251 | ||
252 | // UNSPLIT event methods | |
253 | wxWindow *GetWindowBeingRemoved() const | |
254 | { | |
255 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT ); | |
256 | ||
257 | return m_data.win; | |
258 | } | |
259 | ||
260 | // DCLICK event methods | |
261 | int GetX() const | |
262 | { | |
263 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED ); | |
264 | ||
265 | return m_data.pt.x; | |
266 | } | |
267 | ||
268 | int GetY() const | |
269 | { | |
270 | wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED ); | |
271 | ||
272 | return m_data.pt.y; | |
273 | } | |
274 | ||
275 | private: | |
276 | friend wxSplitterWindow; | |
277 | ||
278 | // data for the different types of event | |
279 | union | |
280 | { | |
281 | int pos; // position for SASH_POS_CHANGED event | |
282 | wxWindow *win; // window being removed for UNSPLIT event | |
283 | struct | |
284 | { | |
285 | int x, y; | |
286 | } pt; // position of double click for DCLICK event | |
287 | } m_data; | |
288 | ||
289 | DECLARE_DYNAMIC_CLASS(wxSplitterEvent) | |
290 | }; | |
291 | ||
292 | typedef void (wxEvtHandler::*wxSplitterEventFunction)(wxSplitterEvent&); | |
293 | ||
294 | #define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \ | |
295 | { \ | |
296 | wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \ | |
297 | id, \ | |
298 | -1, \ | |
299 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
300 | NULL \ | |
301 | }, | |
302 | ||
303 | #define EVT_SPLITTER_DCLICK(id, fn) \ | |
304 | { \ | |
305 | wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \ | |
306 | id, \ | |
307 | -1, \ | |
308 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
309 | NULL \ | |
310 | }, | |
311 | ||
312 | #define EVT_SPLITTER_UNSPLIT(id, fn) \ | |
313 | { \ | |
314 | wxEVT_COMMAND_SPLITTER_UNSPLIT, \ | |
315 | id, \ | |
316 | -1, \ | |
317 | (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \ | |
318 | NULL \ | |
319 | }, | |
320 | ||
0d559d69 | 321 | #endif // __SPLITTERH_G__ |