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
)
97 wxASSERT_MSG( mode
== wxSPLIT_VERTICAL
|| mode
== wxSPLIT_HORIZONTAL
,
98 _T("invalid split mode") );
100 m_splitMode
= (wxSplitMode
)mode
;
103 // Gets the split mode
104 wxSplitMode
GetSplitMode() const { return m_splitMode
; };
106 // Initialize with one window
107 void Initialize(wxWindow
*window
);
109 // Associates the given window with window 2, drawing the appropriate sash
110 // and changing the split mode.
111 // Does nothing and returns FALSE if the window is already split.
112 // A sashPosition of 0 means choose a default sash position,
113 // negative sashPosition specifies the size of right/lower pane as it's
114 // absolute value rather than the size of left/upper pane.
115 virtual bool SplitVertically(wxWindow
*window1
,
117 int sashPosition
= 0)
118 { return DoSplit(wxSPLIT_VERTICAL
, window1
, window2
, sashPosition
); }
119 virtual bool SplitHorizontally(wxWindow
*window1
,
121 int sashPosition
= 0)
122 { return DoSplit(wxSPLIT_HORIZONTAL
, window1
, window2
, sashPosition
); }
124 // Removes the specified (or second) window from the view
125 // Doesn't actually delete the window.
126 bool Unsplit(wxWindow
*toRemove
= (wxWindow
*) NULL
);
128 // Replaces one of the windows with another one (neither old nor new
129 // parameter should be NULL)
130 bool ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
);
132 // Is the window split?
133 bool IsSplit() const { return (m_windowTwo
!= NULL
); }
135 // Sets the sash size
136 void SetSashSize(int width
) { m_sashSize
= width
; }
138 // Sets the border size
139 void SetBorderSize(int width
) { m_borderSize
= width
; }
141 // Gets the sash size
142 int GetSashSize() const { return m_sashSize
; }
144 // Gets the border size
145 int GetBorderSize() const { return m_borderSize
; }
147 // Set the sash position
148 void SetSashPosition(int position
, bool redraw
= TRUE
);
150 // Gets the sash position
151 int GetSashPosition() const { return m_sashPosition
; }
153 // If this is zero, we can remove panes by dragging the sash.
154 void SetMinimumPaneSize(int min
);
155 int GetMinimumPaneSize() const { return m_minimumPaneSize
; }
157 // Called when the sash position is about to be changed, return
158 // FALSE from here to prevent the change from taking place.
159 // Repositions sash to minimum position if pane would be too small.
160 // newSashPosition here is always positive or zero.
161 virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition
))
164 // If the sash is moved to an extreme position, a subwindow
165 // is removed from the splitter window, and the app is
166 // notified. The app should delete or hide the window.
167 virtual void OnUnsplit(wxWindow
*WXUNUSED(removed
)) { }
169 // Called when the sash is double-clicked.
170 // The default behaviour is to remove the sash if the
171 // minimum pane size is zero.
172 virtual void OnDoubleClickSash(int WXUNUSED(x
), int WXUNUSED(y
)) { }
174 ////////////////////////////////////////////////////////////////////////////
177 // Paints the border and sash
178 void OnPaint(wxPaintEvent
& event
);
180 // Handles mouse events
181 void OnMouseEvent(wxMouseEvent
& ev
);
184 void OnSize(wxSizeEvent
& event
);
186 // In live mode, resize child windows in idle time
187 void OnIdle(wxIdleEvent
& event
);
190 virtual void DrawBorders(wxDC
& dc
);
193 virtual void DrawSash(wxDC
& dc
);
195 // Draws the sash tracker (for whilst moving the sash)
196 virtual void DrawSashTracker(int x
, int y
);
198 // Tests for x, y over sash
199 virtual bool SashHitTest(int x
, int y
, int tolerance
= 2);
201 // Resizes subwindows
202 virtual void SizeWindows();
204 // Initialize colours
207 void SetNeedUpdating(bool needUpdating
) { m_needUpdating
= needUpdating
; }
208 bool GetNeedUpdating() const { return m_needUpdating
; }
211 // our event handlers
212 void OnSashPosChanged(wxSplitterEvent
& event
);
213 void OnSashPosChanging(wxSplitterEvent
& event
);
214 void OnDoubleClick(wxSplitterEvent
& event
);
215 void OnUnsplitEvent(wxSplitterEvent
& event
);
216 void OnSetCursor(wxSetCursorEvent
& event
);
218 void SendUnsplitEvent(wxWindow
*winRemoved
);
221 // common part of all ctors
224 // common part of SplitVertically() and SplitHorizontally()
225 bool DoSplit(wxSplitMode mode
,
226 wxWindow
*window1
, wxWindow
*window2
,
229 // adjusts sash position with respect to min. pane and window sizes
230 int AdjustSashPosition(int sashPos
) const;
232 // get either width or height depending on the split mode
233 int GetWindowSize() const;
235 // set m_sashPosition w/ safeguards
236 void DoSetSashPosition(int sashPos
);
238 wxSplitMode m_splitMode
;
239 bool m_permitUnsplitAlways
;
240 bool m_needUpdating
; // when in live mode, set this to TRUE to resize children in idle
241 wxWindow
* m_windowOne
;
242 wxWindow
* m_windowTwo
;
247 int m_sashSize
; // Sash width or height
248 int m_sashPosition
; // Number of pixels from left or top
249 int m_requestedSashPosition
;
252 int m_minimumPaneSize
;
253 wxCursor
* m_sashCursorWE
;
254 wxCursor
* m_sashCursorNS
;
255 wxPen
* m_sashTrackerPen
;
256 wxPen
* m_lightShadowPen
;
257 wxPen
* m_mediumShadowPen
;
258 wxPen
* m_darkShadowPen
;
260 wxBrush
* m_faceBrush
;
264 WX_DECLARE_CONTROL_CONTAINER();
266 DECLARE_DYNAMIC_CLASS(wxSplitterWindow
)
267 DECLARE_EVENT_TABLE()
270 // ----------------------------------------------------------------------------
271 // event class and macros
272 // ----------------------------------------------------------------------------
274 // we reuse the same class for all splitter event types because this is the
275 // usual wxWin convention, but the three event types have different kind of
276 // data associated with them, so the accessors can be only used if the real
277 // event type matches with the one for which the accessors make sense
278 class WXDLLEXPORT wxSplitterEvent
: public wxCommandEvent
281 wxSplitterEvent(wxEventType type
= wxEVT_NULL
,
282 wxSplitterWindow
*splitter
= (wxSplitterWindow
*)NULL
)
283 : wxCommandEvent(type
)
285 SetEventObject(splitter
);
286 if (splitter
) m_id
= splitter
->GetId();
289 // SASH_POS_CHANGED methods
291 // setting the sash position to -1 prevents the change from taking place at
293 void SetSashPosition(int pos
)
295 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
296 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
301 int GetSashPosition() const
303 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
304 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
309 // UNSPLIT event methods
310 wxWindow
*GetWindowBeingRemoved() const
312 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT
);
317 // DCLICK event methods
320 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
327 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
333 friend class WXDLLEXPORT wxSplitterWindow
;
335 // data for the different types of event
338 int pos
; // position for SASH_POS_CHANGED event
339 wxWindow
*win
; // window being removed for UNSPLIT event
343 } pt
; // position of double click for DCLICK event
346 DECLARE_DYNAMIC_CLASS(wxSplitterEvent
)
349 typedef void (wxEvtHandler::*wxSplitterEventFunction
)(wxSplitterEvent
&);
351 #define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \
352 DECLARE_EVENT_TABLE_ENTRY( \
353 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \
356 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
360 #define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \
361 DECLARE_EVENT_TABLE_ENTRY( \
362 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \
365 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
369 #define EVT_SPLITTER_DCLICK(id, fn) \
370 DECLARE_EVENT_TABLE_ENTRY( \
371 wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \
374 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
378 #define EVT_SPLITTER_UNSPLIT(id, fn) \
379 DECLARE_EVENT_TABLE_ENTRY( \
380 wxEVT_COMMAND_SPLITTER_UNSPLIT, \
383 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
387 #endif // __SPLITTERH_G__