1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSplitterWindow class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __SPLITTERH_G__
13 #define __SPLITTERH_G__
16 #pragma interface "splitter.h"
19 #include "wx/window.h" // base class declaration
20 #include "wx/containr.h" // wxControlContainer
22 class WXDLLEXPORT wxSplitterEvent
;
24 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
30 wxSPLIT_HORIZONTAL
= 1,
37 wxSPLIT_DRAG_DRAGGING
,
38 wxSPLIT_DRAG_LEFT_DOWN
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 // ---------------------------------------------------------------------------
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
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
56 class WXDLLEXPORT wxSplitterWindow
: public wxWindow
60 ////////////////////////////////////////////////////////////////////////////
63 // Default constructor
70 wxSplitterWindow(wxWindow
*parent
, wxWindowID id
= -1,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxString
& name
= "splitter")
77 Create(parent
, id
, pos
, size
, style
, name
);
80 virtual ~wxSplitterWindow();
82 bool Create(wxWindow
*parent
, wxWindowID id
= -1,
83 const wxPoint
& pos
= wxDefaultPosition
,
84 const wxSize
& size
= wxDefaultSize
,
86 const wxString
& name
= "splitter");
88 // Gets the only or left/top pane
89 wxWindow
*GetWindow1() const { return m_windowOne
; }
91 // Gets the right/bottom pane
92 wxWindow
*GetWindow2() const { return m_windowTwo
; }
94 // Sets the split mode
95 void SetSplitMode(int mode
) { m_splitMode
= mode
; }
97 // Gets the split mode
98 int GetSplitMode() const { return m_splitMode
; };
100 // Initialize with one window
101 void Initialize(wxWindow
*window
);
103 // Associates the given window with window 2, drawing the appropriate sash
104 // and changing the split mode.
105 // Does nothing and returns FALSE if the window is already split.
106 // A sashPosition of 0 means choose a default sash position,
107 // negative sashPosition specifies the size of right/lower pane as it's
108 // absolute value rather than the size of left/upper pane.
109 virtual bool SplitVertically(wxWindow
*window1
,
111 int sashPosition
= 0);
112 virtual bool SplitHorizontally(wxWindow
*window1
,
114 int sashPosition
= 0);
116 // Removes the specified (or second) window from the view
117 // Doesn't actually delete the window.
118 bool Unsplit(wxWindow
*toRemove
= (wxWindow
*) NULL
);
120 // Replaces one of the windows with another one (neither old nor new
121 // parameter should be NULL)
122 bool ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
);
124 // Is the window split?
125 bool IsSplit() const { return (m_windowTwo
!= NULL
); }
127 // Sets the sash size
128 void SetSashSize(int width
) { m_sashSize
= width
; }
130 // Sets the border size
131 void SetBorderSize(int width
) { m_borderSize
= width
; }
133 // Gets the sash size
134 int GetSashSize() const { return m_sashSize
; }
136 // Gets the border size
137 int GetBorderSize() const { return m_borderSize
; }
139 // Set the sash position
140 void SetSashPosition(int position
, bool redraw
= TRUE
);
142 // Gets the sash position
143 int GetSashPosition() const { return m_sashPosition
; }
145 // If this is zero, we can remove panes by dragging the sash.
146 void SetMinimumPaneSize(int min
) { m_minimumPaneSize
= min
; }
147 int GetMinimumPaneSize() const { return m_minimumPaneSize
; }
149 // Called when the sash position is about to be changed, return
150 // FALSE from here to prevent the change from taking place.
151 // Repositions sash to minimum position if pane would be too small.
152 // newSashPosition here is always positive or zero.
153 virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition
))
156 // If the sash is moved to an extreme position, a subwindow
157 // is removed from the splitter window, and the app is
158 // notified. The app should delete or hide the window.
159 virtual void OnUnsplit(wxWindow
*WXUNUSED(removed
)) { }
161 // Called when the sash is double-clicked.
162 // The default behaviour is to remove the sash if the
163 // minimum pane size is zero.
164 virtual void OnDoubleClickSash(int WXUNUSED(x
), int WXUNUSED(y
)) { }
166 ////////////////////////////////////////////////////////////////////////////
169 // Paints the border and sash
170 void OnPaint(wxPaintEvent
& event
);
172 // Handles mouse events
173 void OnMouseEvent(wxMouseEvent
& ev
);
176 void OnSize(wxSizeEvent
& event
);
178 // In live mode, resize child windows in idle time
179 void OnIdle(wxIdleEvent
& event
);
182 virtual void DrawBorders(wxDC
& dc
);
185 virtual void DrawSash(wxDC
& dc
);
187 // Draws the sash tracker (for whilst moving the sash)
188 virtual void DrawSashTracker(int x
, int y
);
190 // Tests for x, y over sash
191 virtual bool SashHitTest(int x
, int y
, int tolerance
= 2);
193 // Resizes subwindows
194 virtual void SizeWindows();
196 // Initialize colours
199 void SetNeedUpdating(bool needUpdating
) { m_needUpdating
= needUpdating
; }
200 bool GetNeedUpdating() const { return m_needUpdating
; }
203 // our event handlers
204 void OnSashPosChanged(wxSplitterEvent
& event
);
205 void OnSashPosChanging(wxSplitterEvent
& event
);
206 void OnDoubleClick(wxSplitterEvent
& event
);
207 void OnUnsplitEvent(wxSplitterEvent
& event
);
208 void OnSetCursor(wxSetCursorEvent
& event
);
210 void SendUnsplitEvent(wxWindow
*winRemoved
);
213 // common part of all ctors
217 bool m_permitUnsplitAlways
;
218 bool m_needUpdating
; // when in live mode, set this to TRUE to resize children in idle
219 wxWindow
* m_windowOne
;
220 wxWindow
* m_windowTwo
;
225 int m_sashSize
; // Sash width or height
226 int m_sashPosition
; // Number of pixels from left or top
229 int m_minimumPaneSize
;
230 wxCursor
* m_sashCursorWE
;
231 wxCursor
* m_sashCursorNS
;
232 wxPen
* m_sashTrackerPen
;
233 wxPen
* m_lightShadowPen
;
234 wxPen
* m_mediumShadowPen
;
235 wxPen
* m_darkShadowPen
;
237 wxBrush
* m_faceBrush
;
241 WX_DECLARE_CONTROL_CONTAINER();
243 DECLARE_DYNAMIC_CLASS(wxSplitterWindow
)
244 DECLARE_EVENT_TABLE()
247 // ----------------------------------------------------------------------------
248 // event class and macros
249 // ----------------------------------------------------------------------------
251 // we reuse the same class for all splitter event types because this is the
252 // usual wxWin convention, but the three event types have different kind of
253 // data associated with them, so the accessors can be only used if the real
254 // event type matches with the one for which the accessors make sense
255 class WXDLLEXPORT wxSplitterEvent
: public wxCommandEvent
258 wxSplitterEvent(wxEventType type
= wxEVT_NULL
,
259 wxSplitterWindow
*splitter
= (wxSplitterWindow
*)NULL
)
260 : wxCommandEvent(type
)
262 SetEventObject(splitter
);
263 if (splitter
) m_id
= splitter
->GetId();
266 // SASH_POS_CHANGED methods
268 // setting the sash position to -1 prevents the change from taking place at
270 void SetSashPosition(int pos
)
272 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
273 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
278 int GetSashPosition() const
280 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
281 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
286 // UNSPLIT event methods
287 wxWindow
*GetWindowBeingRemoved() const
289 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT
);
294 // DCLICK event methods
297 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
304 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
310 friend class WXDLLEXPORT wxSplitterWindow
;
312 // data for the different types of event
315 int pos
; // position for SASH_POS_CHANGED event
316 wxWindow
*win
; // window being removed for UNSPLIT event
320 } pt
; // position of double click for DCLICK event
323 DECLARE_DYNAMIC_CLASS(wxSplitterEvent
)
326 typedef void (wxEvtHandler::*wxSplitterEventFunction
)(wxSplitterEvent
&);
328 #define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \
329 DECLARE_EVENT_TABLE_ENTRY( \
330 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \
333 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
337 #define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \
338 DECLARE_EVENT_TABLE_ENTRY( \
339 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \
342 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
346 #define EVT_SPLITTER_DCLICK(id, fn) \
347 DECLARE_EVENT_TABLE_ENTRY( \
348 wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \
351 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
355 #define EVT_SPLITTER_UNSPLIT(id, fn) \
356 DECLARE_EVENT_TABLE_ENTRY( \
357 wxEVT_COMMAND_SPLITTER_UNSPLIT, \
360 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
364 #endif // __SPLITTERH_G__