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
64 wxSplitterWindow() : m_container(this)
70 wxSplitterWindow(wxWindow
*parent
, wxWindowID id
= -1,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxString
& name
= "splitter")
78 Create(parent
, id
, pos
, size
, style
, name
);
81 virtual ~wxSplitterWindow();
83 bool Create(wxWindow
*parent
, wxWindowID id
= -1,
84 const wxPoint
& pos
= wxDefaultPosition
,
85 const wxSize
& size
= wxDefaultSize
,
87 const wxString
& name
= "splitter");
89 // Gets the only or left/top pane
90 wxWindow
*GetWindow1() const { return m_windowOne
; }
92 // Gets the right/bottom pane
93 wxWindow
*GetWindow2() const { return m_windowTwo
; }
95 // Sets the split mode
96 void SetSplitMode(int mode
) { m_splitMode
= mode
; }
98 // Gets the split mode
99 int GetSplitMode() const { return m_splitMode
; };
101 // Initialize with one window
102 void Initialize(wxWindow
*window
);
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
,
112 int sashPosition
= 0);
113 virtual bool SplitHorizontally(wxWindow
*window1
,
115 int sashPosition
= 0);
117 // Removes the specified (or second) window from the view
118 // Doesn't actually delete the window.
119 bool Unsplit(wxWindow
*toRemove
= (wxWindow
*) NULL
);
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
);
125 // Is the window split?
126 bool IsSplit() const { return (m_windowTwo
!= NULL
); }
128 // Sets the sash size
129 void SetSashSize(int width
) { m_sashSize
= width
; }
131 // Sets the border size
132 void SetBorderSize(int width
) { m_borderSize
= width
; }
134 // Gets the sash size
135 int GetSashSize() const { return m_sashSize
; }
137 // Gets the border size
138 int GetBorderSize() const { return m_borderSize
; }
140 // Set the sash position
141 void SetSashPosition(int position
, bool redraw
= TRUE
);
143 // Gets the sash position
144 int GetSashPosition() const { return m_sashPosition
; }
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
; }
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
))
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
)) { }
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
)) { }
167 ////////////////////////////////////////////////////////////////////////////
170 // Paints the border and sash
171 void OnPaint(wxPaintEvent
& event
);
173 // Handles mouse events
174 void OnMouseEvent(wxMouseEvent
& ev
);
177 void OnSize(wxSizeEvent
& event
);
179 // In live mode, resize child windows in idle time
180 void OnIdle(wxIdleEvent
& event
);
183 virtual void DrawBorders(wxDC
& dc
);
186 virtual void DrawSash(wxDC
& dc
);
188 // Draws the sash tracker (for whilst moving the sash)
189 virtual void DrawSashTracker(int x
, int y
);
191 // Tests for x, y over sash
192 virtual bool SashHitTest(int x
, int y
, int tolerance
= 2);
194 // Resizes subwindows
195 virtual void SizeWindows();
197 // Initialize colours
200 void SetNeedUpdating(bool needUpdating
) { m_needUpdating
= needUpdating
; }
201 bool GetNeedUpdating() const { return m_needUpdating
; }
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
);
211 void SendUnsplitEvent(wxWindow
*winRemoved
);
214 // common part of all ctors
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
;
226 int m_sashSize
; // Sash width or height
227 int m_sashPosition
; // Number of pixels from left or top
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
;
238 wxBrush
* m_faceBrush
;
242 WX_DECLARE_CONTROL_CONTAINER();
244 DECLARE_DYNAMIC_CLASS(wxSplitterWindow
)
245 DECLARE_EVENT_TABLE()
248 // ----------------------------------------------------------------------------
249 // event class and macros
250 // ----------------------------------------------------------------------------
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
259 wxSplitterEvent(wxEventType type
= wxEVT_NULL
,
260 wxSplitterWindow
*splitter
= (wxSplitterWindow
*)NULL
)
261 : wxCommandEvent(type
)
263 SetEventObject(splitter
);
264 if (splitter
) m_id
= splitter
->GetId();
267 // SASH_POS_CHANGED methods
269 // setting the sash position to -1 prevents the change from taking place at
271 void SetSashPosition(int pos
)
273 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
274 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
279 int GetSashPosition() const
281 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
282 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
287 // UNSPLIT event methods
288 wxWindow
*GetWindowBeingRemoved() const
290 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT
);
295 // DCLICK event methods
298 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
305 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
311 friend class WXDLLEXPORT wxSplitterWindow
;
313 // data for the different types of event
316 int pos
; // position for SASH_POS_CHANGED event
317 wxWindow
*win
; // window being removed for UNSPLIT event
321 } pt
; // position of double click for DCLICK event
324 DECLARE_DYNAMIC_CLASS(wxSplitterEvent
)
327 typedef void (wxEvtHandler
::*wxSplitterEventFunction
)(wxSplitterEvent
&);
329 #define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \
330 DECLARE_EVENT_TABLE_ENTRY( \
331 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \
334 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
338 #define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \
339 DECLARE_EVENT_TABLE_ENTRY( \
340 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \
343 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
347 #define EVT_SPLITTER_DCLICK(id, fn) \
348 DECLARE_EVENT_TABLE_ENTRY( \
349 wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \
352 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
356 #define EVT_SPLITTER_UNSPLIT(id, fn) \
357 DECLARE_EVENT_TABLE_ENTRY( \
358 wxEVT_COMMAND_SPLITTER_UNSPLIT, \
361 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
365 #endif // __SPLITTERH_G__