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
21 class WXDLLEXPORT wxSplitterEvent
;
23 // ---------------------------------------------------------------------------
25 // ---------------------------------------------------------------------------
29 wxSPLIT_HORIZONTAL
= 1,
36 wxSPLIT_DRAG_DRAGGING
,
37 wxSPLIT_DRAG_LEFT_DOWN
40 class WXDLLEXPORT wxControlContainer
;
42 // ---------------------------------------------------------------------------
43 // wxSplitterWindow maintains one or two panes, with
44 // an optional vertical or horizontal split which
45 // can be used with the mouse or programmatically.
46 // ---------------------------------------------------------------------------
49 // 1) Perhaps make the borders sensitive to dragging in order to create a split.
50 // The MFC splitter window manages scrollbars as well so is able to
51 // put sash buttons on the scrollbars, but we probably don't want to go down
53 // 2) for wxWindows 2.0, we must find a way to set the WS_CLIPCHILDREN style
54 // to prevent flickering. (WS_CLIPCHILDREN doesn't work in all cases so can't be
57 class WXDLLEXPORT wxSplitterWindow
: public wxWindow
61 ////////////////////////////////////////////////////////////////////////////
64 // Default constructor
65 wxSplitterWindow() : m_container(this)
71 wxSplitterWindow(wxWindow
*parent
, wxWindowID id
= -1,
72 const wxPoint
& pos
= wxDefaultPosition
,
73 const wxSize
& size
= wxDefaultSize
,
75 const wxString
& name
= "splitter")
79 Create(parent
, id
, pos
, size
, style
, name
);
82 virtual ~wxSplitterWindow();
84 bool Create(wxWindow
*parent
, wxWindowID id
= -1,
85 const wxPoint
& pos
= wxDefaultPosition
,
86 const wxSize
& size
= wxDefaultSize
,
88 const wxString
& name
= "splitter");
90 // Gets the only or left/top pane
91 wxWindow
*GetWindow1() const { return m_windowOne
; }
93 // Gets the right/bottom pane
94 wxWindow
*GetWindow2() const { return m_windowTwo
; }
96 // Sets the split mode
97 void SetSplitMode(int mode
) { m_splitMode
= mode
; }
99 // Gets the split mode
100 int GetSplitMode() const { return m_splitMode
; };
102 // Initialize with one window
103 void Initialize(wxWindow
*window
);
105 // Associates the given window with window 2, drawing the appropriate sash
106 // and changing the split mode.
107 // Does nothing and returns FALSE if the window is already split.
108 // A sashPosition of 0 means choose a default sash position,
109 // negative sashPosition specifies the size of right/lower pane as it's
110 // absolute value rather than the size of left/upper pane.
111 virtual bool SplitVertically(wxWindow
*window1
,
113 int sashPosition
= 0);
114 virtual bool SplitHorizontally(wxWindow
*window1
,
116 int sashPosition
= 0);
118 // Removes the specified (or second) window from the view
119 // Doesn't actually delete the window.
120 bool Unsplit(wxWindow
*toRemove
= (wxWindow
*) NULL
);
122 // Replaces one of the windows with another one (neither old nor new
123 // parameter should be NULL)
124 bool ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
);
126 // Is the window split?
127 bool IsSplit() const { return (m_windowTwo
!= NULL
); }
129 // Sets the sash size
130 void SetSashSize(int width
) { m_sashSize
= width
; }
132 // Sets the border size
133 void SetBorderSize(int width
) { m_borderSize
= width
; }
135 // Gets the sash size
136 int GetSashSize() const { return m_sashSize
; }
138 // Gets the border size
139 int GetBorderSize() const { return m_borderSize
; }
141 // Set the sash position
142 void SetSashPosition(int position
, bool redraw
= TRUE
);
144 // Gets the sash position
145 int GetSashPosition() const { return m_sashPosition
; }
147 // If this is zero, we can remove panes by dragging the sash.
148 void SetMinimumPaneSize(int min
) { m_minimumPaneSize
= min
; }
149 int GetMinimumPaneSize() const { return m_minimumPaneSize
; }
151 // Called when the sash position is about to be changed, return
152 // FALSE from here to prevent the change from taking place.
153 // Repositions sash to minimum position if pane would be too small.
154 // newSashPosition here is always positive or zero.
155 virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition
))
158 // If the sash is moved to an extreme position, a subwindow
159 // is removed from the splitter window, and the app is
160 // notified. The app should delete or hide the window.
161 virtual void OnUnsplit(wxWindow
*WXUNUSED(removed
)) { }
163 // Called when the sash is double-clicked.
164 // The default behaviour is to remove the sash if the
165 // minimum pane size is zero.
166 virtual void OnDoubleClickSash(int WXUNUSED(x
), int WXUNUSED(y
)) { }
168 ////////////////////////////////////////////////////////////////////////////
171 // Paints the border and sash
172 void OnPaint(wxPaintEvent
& event
);
174 // Handles mouse events
175 void OnMouseEvent(wxMouseEvent
& ev
);
178 void OnSize(wxSizeEvent
& event
);
180 // In live mode, resize child windows in idle time
181 void OnIdle(wxIdleEvent
& event
);
184 virtual void DrawBorders(wxDC
& dc
);
187 virtual void DrawSash(wxDC
& dc
);
189 // Draws the sash tracker (for whilst moving the sash)
190 virtual void DrawSashTracker(int x
, int y
);
192 // Tests for x, y over sash
193 virtual bool SashHitTest(int x
, int y
, int tolerance
= 2);
195 // Resizes subwindows
196 virtual void SizeWindows();
198 // Initialize colours
201 void SetNeedUpdating(bool needUpdating
) { m_needUpdating
= needUpdating
; }
202 bool GetNeedUpdating() const { return m_needUpdating
; }
205 // our event handlers
206 void OnSashPosChanged(wxSplitterEvent
& event
);
207 void OnSashPosChanging(wxSplitterEvent
& event
);
208 void OnDoubleClick(wxSplitterEvent
& event
);
209 void OnUnsplitEvent(wxSplitterEvent
& event
);
210 void OnSetCursor(wxSetCursorEvent
& event
);
212 void SendUnsplitEvent(wxWindow
*winRemoved
);
215 // common part of all ctors
219 bool m_permitUnsplitAlways
;
220 bool m_needUpdating
; // when in live mode, set this to TRUE to resize children in idle
221 wxWindow
* m_windowOne
;
222 wxWindow
* m_windowTwo
;
227 int m_sashSize
; // Sash width or height
228 int m_sashPosition
; // Number of pixels from left or top
231 int m_minimumPaneSize
;
232 wxCursor
* m_sashCursorWE
;
233 wxCursor
* m_sashCursorNS
;
234 wxPen
* m_sashTrackerPen
;
235 wxPen
* m_lightShadowPen
;
236 wxPen
* m_mediumShadowPen
;
237 wxPen
* m_darkShadowPen
;
239 wxBrush
* m_faceBrush
;
243 WX_DECLARE_CONTROL_CONTAINER();
245 DECLARE_DYNAMIC_CLASS(wxSplitterWindow
)
246 DECLARE_EVENT_TABLE()
249 // ----------------------------------------------------------------------------
250 // event class and macros
251 // ----------------------------------------------------------------------------
253 // we reuse the same class for all splitter event types because this is the
254 // usual wxWin convention, but the three event types have different kind of
255 // data associated with them, so the accessors can be only used if the real
256 // event type matches with the one for which the accessors make sense
257 class WXDLLEXPORT wxSplitterEvent
: public wxCommandEvent
260 wxSplitterEvent(wxEventType type
= wxEVT_NULL
,
261 wxSplitterWindow
*splitter
= (wxSplitterWindow
*)NULL
)
262 : wxCommandEvent(type
)
264 SetEventObject(splitter
);
265 if (splitter
) m_id
= splitter
->GetId();
268 // SASH_POS_CHANGED methods
270 // setting the sash position to -1 prevents the change from taking place at
272 void SetSashPosition(int pos
)
274 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
275 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
280 int GetSashPosition() const
282 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
283 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
);
288 // UNSPLIT event methods
289 wxWindow
*GetWindowBeingRemoved() const
291 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT
);
296 // DCLICK event methods
299 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
306 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
);
312 friend class WXDLLEXPORT wxSplitterWindow
;
314 // data for the different types of event
317 int pos
; // position for SASH_POS_CHANGED event
318 wxWindow
*win
; // window being removed for UNSPLIT event
322 } pt
; // position of double click for DCLICK event
325 DECLARE_DYNAMIC_CLASS(wxSplitterEvent
)
328 typedef void (wxEvtHandler
::*wxSplitterEventFunction
)(wxSplitterEvent
&);
330 #define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \
331 DECLARE_EVENT_TABLE_ENTRY( \
332 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \
335 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
339 #define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \
340 DECLARE_EVENT_TABLE_ENTRY( \
341 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \
344 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
348 #define EVT_SPLITTER_DCLICK(id, fn) \
349 DECLARE_EVENT_TABLE_ENTRY( \
350 wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \
353 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
357 #define EVT_SPLITTER_UNSPLIT(id, fn) \
358 DECLARE_EVENT_TABLE_ENTRY( \
359 wxEVT_COMMAND_SPLITTER_UNSPLIT, \
362 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
366 #endif // __SPLITTERH_G__