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