]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/splitter.h
moved MGL initialization to earlier stage (crashes otherwise...) and implemented...
[wxWidgets.git] / include / wx / generic / splitter.h
CommitLineData
c801d85f
KB
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
0d559d69 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __SPLITTERH_G__
13#define __SPLITTERH_G__
14
15#ifdef __GNUG__
42e69d6b 16 #pragma interface "splitter.h"
c801d85f
KB
17#endif
18
42e69d6b 19#include "wx/window.h" // base class declaration
0013a77b 20#include "wx/containr.h" // wxControlContainer
c801d85f 21
42e69d6b 22class WXDLLEXPORT wxSplitterEvent;
c801d85f 23
42e69d6b
VZ
24// ---------------------------------------------------------------------------
25// splitter constants
26// ---------------------------------------------------------------------------
c801d85f 27
42e69d6b
VZ
28enum
29{
30 wxSPLIT_HORIZONTAL = 1,
31 wxSPLIT_VERTICAL
32};
c801d85f 33
42e69d6b
VZ
34enum
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// ---------------------------------------------------------------------------
c801d85f
KB
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
56class WXDLLEXPORT wxSplitterWindow: public wxWindow
57{
0d559d69 58public:
c801d85f
KB
59
60////////////////////////////////////////////////////////////////////////////
61// Public API
62
63 // Default constructor
9948d31f 64 wxSplitterWindow()
f6bcfd97
BP
65 {
66 Init();
67 }
c801d85f
KB
68
69 // Normal constructor
0d559d69
VZ
70 wxSplitterWindow(wxWindow *parent, wxWindowID id = -1,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
dead66ba 73 long style = wxSP_3D,
f6bcfd97
BP
74 const wxString& name = "splitter")
75 {
76 Init();
77 Create(parent, id, pos, size, style, name);
78 }
79
6b55490a 80 virtual ~wxSplitterWindow();
c801d85f 81
f6bcfd97
BP
82 bool Create(wxWindow *parent, wxWindowID id = -1,
83 const wxPoint& pos = wxDefaultPosition,
84 const wxSize& size = wxDefaultSize,
dead66ba 85 long style = wxSP_3D,
f6bcfd97
BP
86 const wxString& name = "splitter");
87
c801d85f 88 // Gets the only or left/top pane
0d559d69 89 wxWindow *GetWindow1() const { return m_windowOne; }
c801d85f
KB
90
91 // Gets the right/bottom pane
0d559d69 92 wxWindow *GetWindow2() const { return m_windowTwo; }
c801d85f
KB
93
94 // Sets the split mode
0d559d69 95 void SetSplitMode(int mode) { m_splitMode = mode; }
c801d85f
KB
96
97 // Gets the split mode
0d559d69 98 int GetSplitMode() const { return m_splitMode; };
c801d85f
KB
99
100 // Initialize with one window
101 void Initialize(wxWindow *window);
102
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.
0d559d69
VZ
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.
cce4b3fe
VZ
109 virtual bool SplitVertically(wxWindow *window1,
110 wxWindow *window2,
111 int sashPosition = 0);
112 virtual bool SplitHorizontally(wxWindow *window1,
113 wxWindow *window2,
114 int sashPosition = 0);
c801d85f
KB
115
116 // Removes the specified (or second) window from the view
117 // Doesn't actually delete the window.
c67daf87 118 bool Unsplit(wxWindow *toRemove = (wxWindow *) NULL);
c801d85f 119
3ad5e06b
VZ
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);
123
c801d85f 124 // Is the window split?
0d559d69 125 bool IsSplit() const { return (m_windowTwo != NULL); }
c801d85f
KB
126
127 // Sets the sash size
0d559d69 128 void SetSashSize(int width) { m_sashSize = width; }
c801d85f
KB
129
130 // Sets the border size
0d559d69 131 void SetBorderSize(int width) { m_borderSize = width; }
c801d85f
KB
132
133 // Gets the sash size
0d559d69 134 int GetSashSize() const { return m_sashSize; }
c801d85f
KB
135
136 // Gets the border size
0d559d69 137 int GetBorderSize() const { return m_borderSize; }
c801d85f
KB
138
139 // Set the sash position
42e69d6b 140 void SetSashPosition(int position, bool redraw = TRUE);
c801d85f
KB
141
142 // Gets the sash position
0d559d69 143 int GetSashPosition() const { return m_sashPosition; }
c801d85f
KB
144
145 // If this is zero, we can remove panes by dragging the sash.
0d559d69
VZ
146 void SetMinimumPaneSize(int min) { m_minimumPaneSize = min; }
147 int GetMinimumPaneSize() const { return m_minimumPaneSize; }
148
149 // Called when the sash position is about to be changed, return
150 // FALSE from here to prevent the change from taking place.
021e7626 151 // Repositions sash to minimum position if pane would be too small.
0d559d69 152 // newSashPosition here is always positive or zero.
42e69d6b
VZ
153 virtual bool OnSashPositionChange(int WXUNUSED(newSashPosition))
154 { return TRUE; }
c801d85f
KB
155
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.
42e69d6b 159 virtual void OnUnsplit(wxWindow *WXUNUSED(removed)) { }
c801d85f
KB
160
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.
42e69d6b 164 virtual void OnDoubleClickSash(int WXUNUSED(x), int WXUNUSED(y)) { }
c801d85f
KB
165
166////////////////////////////////////////////////////////////////////////////
167// Implementation
168
169 // Paints the border and sash
170 void OnPaint(wxPaintEvent& event);
171
172 // Handles mouse events
173 void OnMouseEvent(wxMouseEvent& ev);
174
175 // Adjusts the panes
176 void OnSize(wxSizeEvent& event);
177
72195a0f
RR
178 // In live mode, resize child windows in idle time
179 void OnIdle(wxIdleEvent& event);
180
c801d85f 181 // Draws borders
f6bcfd97 182 virtual void DrawBorders(wxDC& dc);
c801d85f
KB
183
184 // Draws the sash
f6bcfd97 185 virtual void DrawSash(wxDC& dc);
c801d85f
KB
186
187 // Draws the sash tracker (for whilst moving the sash)
f6bcfd97 188 virtual void DrawSashTracker(int x, int y);
c801d85f
KB
189
190 // Tests for x, y over sash
f6bcfd97 191 virtual bool SashHitTest(int x, int y, int tolerance = 2);
c801d85f
KB
192
193 // Resizes subwindows
f6bcfd97 194 virtual void SizeWindows();
c801d85f
KB
195
196 // Initialize colours
0d559d69 197 void InitColours();
c801d85f 198
f6bcfd97
BP
199 void SetNeedUpdating(bool needUpdating) { m_needUpdating = needUpdating; }
200 bool GetNeedUpdating() const { return m_needUpdating ; }
201
0d559d69 202protected:
42e69d6b
VZ
203 // our event handlers
204 void OnSashPosChanged(wxSplitterEvent& event);
370938d9 205 void OnSashPosChanging(wxSplitterEvent& event);
42e69d6b
VZ
206 void OnDoubleClick(wxSplitterEvent& event);
207 void OnUnsplitEvent(wxSplitterEvent& event);
43b5058d 208 void OnSetCursor(wxSetCursorEvent& event);
42e69d6b
VZ
209
210 void SendUnsplitEvent(wxWindow *winRemoved);
211
8062a6ab 212protected:
6b55490a 213 // common part of all ctors
f6bcfd97
BP
214 void Init();
215
c801d85f 216 int m_splitMode;
370938d9 217 bool m_permitUnsplitAlways;
f6bcfd97 218 bool m_needUpdating; // when in live mode, set this to TRUE to resize children in idle
c801d85f
KB
219 wxWindow* m_windowOne;
220 wxWindow* m_windowTwo;
221 int m_dragMode;
222 int m_oldX;
223 int m_oldY;
224 int m_borderSize;
225 int m_sashSize; // Sash width or height
226 int m_sashPosition; // Number of pixels from left or top
227 int m_firstX;
228 int m_firstY;
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;
236 wxPen* m_hilightPen;
237 wxBrush* m_faceBrush;
238 wxPen* m_facePen;
0d559d69
VZ
239
240private:
6b55490a
VZ
241 WX_DECLARE_CONTROL_CONTAINER();
242
0d559d69
VZ
243 DECLARE_DYNAMIC_CLASS(wxSplitterWindow)
244 DECLARE_EVENT_TABLE()
c801d85f
KB
245};
246
42e69d6b
VZ
247// ----------------------------------------------------------------------------
248// event class and macros
249// ----------------------------------------------------------------------------
250
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
255class WXDLLEXPORT wxSplitterEvent : public wxCommandEvent
256{
257public:
258 wxSplitterEvent(wxEventType type = wxEVT_NULL,
259 wxSplitterWindow *splitter = (wxSplitterWindow *)NULL)
260 : wxCommandEvent(type)
261 {
262 SetEventObject(splitter);
0656d2e6 263 if (splitter) m_id = splitter->GetId();
42e69d6b
VZ
264 }
265
266 // SASH_POS_CHANGED methods
267
268 // setting the sash position to -1 prevents the change from taking place at
269 // all
270 void SetSashPosition(int pos)
271 {
370938d9
UB
272 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
273 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING);
42e69d6b
VZ
274
275 m_data.pos = pos;
276 }
277
278 int GetSashPosition() const
279 {
370938d9
UB
280 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
281 || GetEventType() == wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING);
42e69d6b
VZ
282
283 return m_data.pos;
284 }
285
286 // UNSPLIT event methods
287 wxWindow *GetWindowBeingRemoved() const
288 {
289 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_UNSPLIT );
290
291 return m_data.win;
292 }
293
294 // DCLICK event methods
295 int GetX() const
296 {
297 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED );
298
299 return m_data.pt.x;
300 }
301
302 int GetY() const
303 {
304 wxASSERT( GetEventType() == wxEVT_COMMAND_SPLITTER_DOUBLECLICKED );
305
306 return m_data.pt.y;
307 }
308
309private:
d5a07b9e 310 friend class WXDLLEXPORT wxSplitterWindow;
42e69d6b
VZ
311
312 // data for the different types of event
313 union
314 {
315 int pos; // position for SASH_POS_CHANGED event
316 wxWindow *win; // window being removed for UNSPLIT event
317 struct
318 {
319 int x, y;
320 } pt; // position of double click for DCLICK event
321 } m_data;
322
323 DECLARE_DYNAMIC_CLASS(wxSplitterEvent)
324};
325
326typedef void (wxEvtHandler::*wxSplitterEventFunction)(wxSplitterEvent&);
327
328#define EVT_SPLITTER_SASH_POS_CHANGED(id, fn) \
2e4df4bf 329 DECLARE_EVENT_TABLE_ENTRY( \
42e69d6b
VZ
330 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, \
331 id, \
332 -1, \
333 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
334 NULL \
82a5f02c 335 ),
42e69d6b 336
370938d9 337#define EVT_SPLITTER_SASH_POS_CHANGING(id, fn) \
2e4df4bf 338 DECLARE_EVENT_TABLE_ENTRY( \
370938d9
UB
339 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, \
340 id, \
341 -1, \
342 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
343 NULL \
82a5f02c 344 ),
370938d9
UB
345
346#define EVT_SPLITTER_DCLICK(id, fn) \
2e4df4bf 347 DECLARE_EVENT_TABLE_ENTRY( \
370938d9 348 wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, \
42e69d6b
VZ
349 id, \
350 -1, \
351 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
352 NULL \
82a5f02c 353 ),
42e69d6b
VZ
354
355#define EVT_SPLITTER_UNSPLIT(id, fn) \
2e4df4bf 356 DECLARE_EVENT_TABLE_ENTRY( \
42e69d6b
VZ
357 wxEVT_COMMAND_SPLITTER_UNSPLIT, \
358 id, \
359 -1, \
360 (wxObjectEventFunction)(wxEventFunction)(wxSplitterEventFunction) &fn, \
361 NULL \
82a5f02c 362 ),
42e69d6b 363
0d559d69 364#endif // __SPLITTERH_G__