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"
20 #include "wx/window.h"
21 #include "wx/string.h"
23 #define WXSPLITTER_VERSION 1.0
25 #define wxSPLIT_HORIZONTAL 1
26 #define wxSPLIT_VERTICAL 2
28 #define wxSPLIT_DRAG_NONE 0
29 #define wxSPLIT_DRAG_DRAGGING 1
30 #define wxSPLIT_DRAG_LEFT_DOWN 2
33 * wxSplitterWindow maintains one or two panes, with
34 * an optional vertical or horizontal split which
35 * can be used with the mouse or programmatically.
39 // 1) Perhaps make the borders sensitive to dragging in order to create a split.
40 // The MFC splitter window manages scrollbars as well so is able to
41 // put sash buttons on the scrollbars, but we probably don't want to go down
43 // 2) for wxWindows 2.0, we must find a way to set the WS_CLIPCHILDREN style
44 // to prevent flickering. (WS_CLIPCHILDREN doesn't work in all cases so can't be
47 class WXDLLEXPORT wxSplitterWindow
: public wxWindow
51 ////////////////////////////////////////////////////////////////////////////
54 // Default constructor
58 wxSplitterWindow(wxWindow
*parent
, wxWindowID id
= -1,
59 const wxPoint
& pos
= wxDefaultPosition
,
60 const wxSize
& size
= wxDefaultSize
,
61 long style
= wxSP_3D
|wxCLIP_CHILDREN
,
62 const wxString
& name
= "splitter");
65 // Gets the only or left/top pane
66 wxWindow
*GetWindow1() const { return m_windowOne
; }
68 // Gets the right/bottom pane
69 wxWindow
*GetWindow2() const { return m_windowTwo
; }
71 // Sets the split mode
72 void SetSplitMode(int mode
) { m_splitMode
= mode
; }
74 // Gets the split mode
75 int GetSplitMode() const { return m_splitMode
; };
77 // Initialize with one window
78 void Initialize(wxWindow
*window
);
80 // Associates the given window with window 2, drawing the appropriate sash
81 // and changing the split mode.
82 // Does nothing and returns FALSE if the window is already split.
83 // A sashPosition of 0 means choose a default sash position,
84 // negative sashPosition specifies the size of right/lower pane as it's
85 // absolute value rather than the size of left/upper pane.
86 virtual bool SplitVertically(wxWindow
*window1
,
88 int sashPosition
= 0);
89 virtual bool SplitHorizontally(wxWindow
*window1
,
91 int sashPosition
= 0);
93 // Removes the specified (or second) window from the view
94 // Doesn't actually delete the window.
95 bool Unsplit(wxWindow
*toRemove
= (wxWindow
*) NULL
);
97 // Is the window split?
98 bool IsSplit() const { return (m_windowTwo
!= NULL
); }
100 // Sets the sash size
101 void SetSashSize(int width
) { m_sashSize
= width
; }
103 // Sets the border size
104 void SetBorderSize(int width
) { m_borderSize
= width
; }
106 // Gets the sash size
107 int GetSashSize() const { return m_sashSize
; }
109 // Gets the border size
110 int GetBorderSize() const { return m_borderSize
; }
112 // Set the sash position
113 void SetSashPosition(int position
, bool redaw
= TRUE
);
115 // Gets the sash position
116 int GetSashPosition() const { return m_sashPosition
; }
118 // If this is zero, we can remove panes by dragging the sash.
119 void SetMinimumPaneSize(int min
) { m_minimumPaneSize
= min
; }
120 int GetMinimumPaneSize() const { return m_minimumPaneSize
; }
122 // Called when the sash position is about to be changed, return
123 // FALSE from here to prevent the change from taking place.
124 // newSashPosition here is always positive or zero.
125 virtual bool OnSashPositionChange(int newSashPosition
);
127 // If the sash is moved to an extreme position, a subwindow
128 // is removed from the splitter window, and the app is
129 // notified. The app should delete or hide the window.
130 virtual void OnUnsplit(wxWindow
*removed
) { removed
->Show(FALSE
); }
132 // Called when the sash is double-clicked.
133 // The default behaviour is to remove the sash if the
134 // minimum pane size is zero.
135 virtual void OnDoubleClickSash(int x
, int y
);
137 ////////////////////////////////////////////////////////////////////////////
140 // Paints the border and sash
141 void OnPaint(wxPaintEvent
& event
);
143 // Handles mouse events
144 void OnMouseEvent(wxMouseEvent
& ev
);
147 void OnSize(wxSizeEvent
& event
);
150 void DrawBorders(wxDC
& dc
);
153 void DrawSash(wxDC
& dc
);
155 // Draws the sash tracker (for whilst moving the sash)
156 void DrawSashTracker(int x
, int y
);
158 // Tests for x, y over sash
159 bool SashHitTest(int x
, int y
, int tolerance
= 2);
161 // Resizes subwindows
164 // Initialize colours
169 wxWindow
* m_windowOne
;
170 wxWindow
* m_windowTwo
;
175 int m_sashSize
; // Sash width or height
176 int m_sashPosition
; // Number of pixels from left or top
179 int m_minimumPaneSize
;
180 wxCursor
* m_sashCursorWE
;
181 wxCursor
* m_sashCursorNS
;
182 wxPen
* m_sashTrackerPen
;
183 wxPen
* m_lightShadowPen
;
184 wxPen
* m_mediumShadowPen
;
185 wxPen
* m_darkShadowPen
;
187 wxBrush
* m_faceBrush
;
191 DECLARE_DYNAMIC_CLASS(wxSplitterWindow
)
192 DECLARE_EVENT_TABLE()
195 #endif // __SPLITTERH_G__