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
49 DECLARE_DYNAMIC_CLASS(wxSplitterWindow
)
53 ////////////////////////////////////////////////////////////////////////////
56 // Default constructor
57 wxSplitterWindow(void);
60 wxSplitterWindow(wxWindow
*parent
, const wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
61 const wxSize
& size
= wxDefaultSize
, const long style
= wxSP_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "splitter");
62 ~wxSplitterWindow(void);
64 // Gets the only or left/top pane
65 inline wxWindow
*GetWindow1(void) { return m_windowOne
; }
67 // Gets the right/bottom pane
68 inline wxWindow
*GetWindow2(void) { return m_windowTwo
; }
70 // Sets the split mode
71 inline void SetSplitMode(const int mode
) { m_splitMode
= mode
; }
73 // Gets the split mode
74 inline int GetSplitMode(void) const { return m_splitMode
; };
76 // Initialize with one window
77 void Initialize(wxWindow
*window
);
79 // Associates the given window with window 2, drawing the appropriate sash
80 // and changing the split mode.
81 // Does nothing and returns FALSE if the window is already split.
82 // A sashPosition of -1 means choose a default sash position.
83 bool SplitVertically(wxWindow
*window1
, wxWindow
*window2
, const int sashPosition
= -1);
84 bool SplitHorizontally(wxWindow
*window1
, wxWindow
*window2
, const int sashPosition
= -1);
86 // Removes the specified (or second) window from the view
87 // Doesn't actually delete the window.
88 bool Unsplit(wxWindow
*toRemove
= NULL
);
90 // Is the window split?
91 inline bool IsSplit(void) const { return (m_windowTwo
!= NULL
); }
94 inline void SetSashSize(const int width
) { m_sashSize
= width
; }
96 // Sets the border size
97 inline void SetBorderSize(const int width
) { m_borderSize
= width
; }
100 inline int GetSashSize(void) const { return m_sashSize
; }
102 // Gets the border size
103 inline int GetBorderSize(void) const { return m_borderSize
; }
105 // Set the sash position
106 void SetSashPosition(const int position
, const bool redaw
= TRUE
);
108 // Gets the sash position
109 inline int GetSashPosition(void) const { return m_sashPosition
; }
111 // If this is zero, we can remove panes by dragging the sash.
112 inline void SetMinimumPaneSize(const int min
) { m_minimumPaneSize
= min
; }
113 inline int GetMinimumPaneSize(void) const { return m_minimumPaneSize
; }
115 // If the sash is moved to an extreme position, a subwindow
116 // is removed from the splitter window, and the app is
117 // notified. The app should delete or hide the window.
118 virtual void OnUnsplit(wxWindow
*removed
) { removed
->Show(FALSE
); }
120 // Called when the sash is double-clicked.
121 // The default behaviour is to remove the sash if the
122 // minimum pane size is zero.
123 virtual void OnDoubleClickSash(int x
, int y
);
125 ////////////////////////////////////////////////////////////////////////////
128 // Paints the border and sash
129 void OnPaint(wxPaintEvent
& event
);
131 // Handles mouse events
132 void OnMouseEvent(wxMouseEvent
& ev
);
135 void OnSize(wxSizeEvent
& event
);
138 void DrawBorders(wxDC
& dc
);
141 void DrawSash(wxDC
& dc
);
143 // Draws the sash tracker (for whilst moving the sash)
144 void DrawSashTracker(const int x
, const int y
);
146 // Tests for x, y over sash
147 bool SashHitTest(const int x
, const int y
, const int tolerance
= 2);
149 // Resizes subwindows
150 void SizeWindows(void);
152 // Initialize colours
153 void InitColours(void);
157 wxWindow
* m_windowOne
;
158 wxWindow
* m_windowTwo
;
163 int m_sashSize
; // Sash width or height
164 int m_sashPosition
; // Number of pixels from left or top
167 int m_minimumPaneSize
;
168 wxCursor
* m_sashCursorWE
;
169 wxCursor
* m_sashCursorNS
;
170 wxPen
* m_sashTrackerPen
;
171 wxPen
* m_lightShadowPen
;
172 wxPen
* m_mediumShadowPen
;
173 wxPen
* m_darkShadowPen
;
175 wxBrush
* m_faceBrush
;
177 DECLARE_EVENT_TABLE()