1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSashWindow implementation. A sash window has an optional
4 // sash on each edge, allowing it to be dragged. An event
5 // is generated when the sash is released.
6 // Author: Julian Smart
10 // Copyright: (c) Julian Smart
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_SASHWIN_H_G_
15 #define _WX_SASHWIN_H_G_
20 #include "wx/window.h"
21 #include "wx/string.h"
23 #define wxSASH_DRAG_NONE 0
24 #define wxSASH_DRAG_DRAGGING 1
25 #define wxSASH_DRAG_LEFT_DOWN 2
27 enum wxSashEdgePosition
{
36 * wxSashEdge represents one of the four edges of a window.
39 class WXDLLIMPEXP_ADV wxSashEdge
44 #if WXWIN_COMPATIBILITY_2_6
49 bool m_show
; // Is the sash showing?
50 #if WXWIN_COMPATIBILITY_2_6
51 bool m_border
; // Do we draw a border?
53 int m_margin
; // The margin size
60 #define wxSW_NOBORDER 0x0000
61 //#define wxSW_3D 0x0010
62 #define wxSW_BORDER 0x0020
63 #define wxSW_3DSASH 0x0040
64 #define wxSW_3DBORDER 0x0080
65 #define wxSW_3D (wxSW_3DSASH | wxSW_3DBORDER)
68 * wxSashWindow allows any of its edges to have a sash which can be dragged
69 * to resize the window. The actual content window will be created as a child
73 class WXDLLIMPEXP_ADV wxSashWindow
: public wxWindow
76 // Default constructor
83 wxSashWindow(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
84 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"))
87 Create(parent
, id
, pos
, size
, style
, name
);
90 virtual ~wxSashWindow();
92 bool Create(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
93 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"));
95 // Set whether there's a sash in this position
96 void SetSashVisible(wxSashEdgePosition edge
, bool sash
);
98 // Get whether there's a sash in this position
99 bool GetSashVisible(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_show
; }
101 #if WXWIN_COMPATIBILITY_2_6
102 // Set whether there's a border in this position
103 // This value is unused in wxSashWindow.
104 void SetSashBorder(wxSashEdgePosition edge
, bool border
) { m_sashes
[edge
].m_border
= border
; }
106 // Get whether there's a border in this position
107 // This value is unused in wxSashWindow.
108 bool HasBorder(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_border
; }
112 int GetEdgeMargin(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_margin
; }
114 // Sets the default sash border size
115 void SetDefaultBorderSize(int width
) { m_borderSize
= width
; }
117 // Gets the default sash border size
118 int GetDefaultBorderSize() const { return m_borderSize
; }
120 // Sets the addition border size between child and sash window
121 void SetExtraBorderSize(int width
) { m_extraBorderSize
= width
; }
123 // Gets the addition border size between child and sash window
124 int GetExtraBorderSize() const { return m_extraBorderSize
; }
126 virtual void SetMinimumSizeX(int min
) { m_minimumPaneSizeX
= min
; }
127 virtual void SetMinimumSizeY(int min
) { m_minimumPaneSizeY
= min
; }
128 virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX
; }
129 virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY
; }
131 virtual void SetMaximumSizeX(int max
) { m_maximumPaneSizeX
= max
; }
132 virtual void SetMaximumSizeY(int max
) { m_maximumPaneSizeY
= max
; }
133 virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX
; }
134 virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY
; }
136 ////////////////////////////////////////////////////////////////////////////
139 // Paints the border and sash
140 void OnPaint(wxPaintEvent
& event
);
142 // Handles mouse events
143 void OnMouseEvent(wxMouseEvent
& ev
);
146 void OnSize(wxSizeEvent
& event
);
148 #if defined(__WXMSW__) || defined(__WXMAC__)
149 // Handle cursor correctly
150 void OnSetCursor(wxSetCursorEvent
& event
);
154 void DrawBorders(wxDC
& dc
);
157 void DrawSash(wxSashEdgePosition edge
, wxDC
& dc
);
160 void DrawSashes(wxDC
& dc
);
162 // Draws the sash tracker (for whilst moving the sash)
163 void DrawSashTracker(wxSashEdgePosition edge
, int x
, int y
);
165 // Tests for x, y over sash
166 wxSashEdgePosition
SashHitTest(int x
, int y
, int tolerance
= 2);
168 // Resizes subwindows
171 // Initialize colours
177 wxSashEdge m_sashes
[4];
179 wxSashEdgePosition m_draggingEdge
;
183 int m_extraBorderSize
;
186 int m_minimumPaneSizeX
;
187 int m_minimumPaneSizeY
;
188 int m_maximumPaneSizeX
;
189 int m_maximumPaneSizeY
;
190 wxCursor
* m_sashCursorWE
;
191 wxCursor
* m_sashCursorNS
;
192 wxColour m_lightShadowColour
;
193 wxColour m_mediumShadowColour
;
194 wxColour m_darkShadowColour
;
195 wxColour m_hilightColour
;
196 wxColour m_faceColour
;
197 bool m_mouseCaptured
;
198 wxCursor
* m_currentCursor
;
201 DECLARE_DYNAMIC_CLASS(wxSashWindow
)
202 DECLARE_EVENT_TABLE()
203 DECLARE_NO_COPY_CLASS(wxSashWindow
)
206 BEGIN_DECLARE_EVENT_TYPES()
207 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
,
208 wxEVT_SASH_DRAGGED
, wxEVT_FIRST
+ 1200)
209 END_DECLARE_EVENT_TYPES()
211 enum wxSashDragStatus
214 wxSASH_STATUS_OUT_OF_RANGE
217 class WXDLLIMPEXP_ADV wxSashEvent
: public wxCommandEvent
220 wxSashEvent(int id
= 0, wxSashEdgePosition edge
= wxSASH_NONE
)
222 m_eventType
= (wxEventType
) wxEVT_SASH_DRAGGED
;
227 void SetEdge(wxSashEdgePosition edge
) { m_edge
= edge
; }
228 wxSashEdgePosition
GetEdge() const { return m_edge
; }
230 //// The rectangle formed by the drag operation
231 void SetDragRect(const wxRect
& rect
) { m_dragRect
= rect
; }
232 wxRect
GetDragRect() const { return m_dragRect
; }
234 //// Whether the drag caused the rectangle to be reversed (e.g.
235 //// dragging the top below the bottom)
236 void SetDragStatus(wxSashDragStatus status
) { m_dragStatus
= status
; }
237 wxSashDragStatus
GetDragStatus() const { return m_dragStatus
; }
240 wxSashEdgePosition m_edge
;
242 wxSashDragStatus m_dragStatus
;
245 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashEvent
)
248 typedef void (wxEvtHandler::*wxSashEventFunction
)(wxSashEvent
&);
250 #define wxSashEventHandler(func) \
251 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSashEventFunction, &func)
253 #define EVT_SASH_DRAGGED(id, fn) \
254 wx__DECLARE_EVT1(wxEVT_SASH_DRAGGED, id, wxSashEventHandler(fn))
255 #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) \
256 wx__DECLARE_EVT2(wxEVT_SASH_DRAGGED, id1, id2, wxSashEventHandler(fn))