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
42 wxSashEdge() { m_show
= false; m_border
= false; m_margin
= 0; }
44 bool m_show
; // Is the sash showing?
45 bool m_border
; // Do we draw a border?
46 int m_margin
; // The margin size
53 #define wxSW_NOBORDER 0x0000
54 //#define wxSW_3D 0x0010
55 #define wxSW_BORDER 0x0020
56 #define wxSW_3DSASH 0x0040
57 #define wxSW_3DBORDER 0x0080
58 #define wxSW_3D (wxSW_3DSASH | wxSW_3DBORDER)
61 * wxSashWindow allows any of its edges to have a sash which can be dragged
62 * to resize the window. The actual content window will be created as a child
66 class WXDLLIMPEXP_ADV wxSashWindow
: public wxWindow
69 // Default constructor
76 wxSashWindow(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
77 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"))
80 Create(parent
, id
, pos
, size
, style
, name
);
85 bool Create(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
86 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"));
88 // Set whether there's a sash in this position
89 void SetSashVisible(wxSashEdgePosition edge
, bool sash
);
91 // Get whether there's a sash in this position
92 bool GetSashVisible(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_show
; }
94 // Set whether there's a border in this position
95 void SetSashBorder(wxSashEdgePosition edge
, bool border
) { m_sashes
[edge
].m_border
= border
; }
97 // Get whether there's a border in this position
98 bool HasBorder(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_border
; }
101 int GetEdgeMargin(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_margin
; }
103 // Sets the default sash border size
104 void SetDefaultBorderSize(int width
) { m_borderSize
= width
; }
106 // Gets the default sash border size
107 int GetDefaultBorderSize() const { return m_borderSize
; }
109 // Sets the addition border size between child and sash window
110 void SetExtraBorderSize(int width
) { m_extraBorderSize
= width
; }
112 // Gets the addition border size between child and sash window
113 int GetExtraBorderSize() const { return m_extraBorderSize
; }
115 virtual void SetMinimumSizeX(int min
) { m_minimumPaneSizeX
= min
; }
116 virtual void SetMinimumSizeY(int min
) { m_minimumPaneSizeY
= min
; }
117 virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX
; }
118 virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY
; }
120 virtual void SetMaximumSizeX(int max
) { m_maximumPaneSizeX
= max
; }
121 virtual void SetMaximumSizeY(int max
) { m_maximumPaneSizeY
= max
; }
122 virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX
; }
123 virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY
; }
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
);
137 #if defined(__WXMSW__) || defined(__WXMAC__)
138 // Handle cursor correctly
139 void OnSetCursor(wxSetCursorEvent
& event
);
143 void DrawBorders(wxDC
& dc
);
146 void DrawSash(wxSashEdgePosition edge
, wxDC
& dc
);
149 void DrawSashes(wxDC
& dc
);
151 // Draws the sash tracker (for whilst moving the sash)
152 void DrawSashTracker(wxSashEdgePosition edge
, int x
, int y
);
154 // Tests for x, y over sash
155 wxSashEdgePosition
SashHitTest(int x
, int y
, int tolerance
= 2);
157 // Resizes subwindows
160 // Initialize colours
166 wxSashEdge m_sashes
[4];
168 wxSashEdgePosition m_draggingEdge
;
172 int m_extraBorderSize
;
175 int m_minimumPaneSizeX
;
176 int m_minimumPaneSizeY
;
177 int m_maximumPaneSizeX
;
178 int m_maximumPaneSizeY
;
179 wxCursor
* m_sashCursorWE
;
180 wxCursor
* m_sashCursorNS
;
181 wxColour m_lightShadowColour
;
182 wxColour m_mediumShadowColour
;
183 wxColour m_darkShadowColour
;
184 wxColour m_hilightColour
;
185 wxColour m_faceColour
;
186 bool m_mouseCaptured
;
187 wxCursor
* m_currentCursor
;
190 DECLARE_DYNAMIC_CLASS(wxSashWindow
)
191 DECLARE_EVENT_TABLE()
192 DECLARE_NO_COPY_CLASS(wxSashWindow
)
195 BEGIN_DECLARE_EVENT_TYPES()
196 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
,
197 wxEVT_SASH_DRAGGED
, wxEVT_FIRST
+ 1200)
198 END_DECLARE_EVENT_TYPES()
200 enum wxSashDragStatus
203 wxSASH_STATUS_OUT_OF_RANGE
206 class WXDLLIMPEXP_ADV wxSashEvent
: public wxCommandEvent
209 wxSashEvent(int id
= 0, wxSashEdgePosition edge
= wxSASH_NONE
)
211 m_eventType
= (wxEventType
) wxEVT_SASH_DRAGGED
;
216 void SetEdge(wxSashEdgePosition edge
) { m_edge
= edge
; }
217 wxSashEdgePosition
GetEdge() const { return m_edge
; }
219 //// The rectangle formed by the drag operation
220 void SetDragRect(const wxRect
& rect
) { m_dragRect
= rect
; }
221 wxRect
GetDragRect() const { return m_dragRect
; }
223 //// Whether the drag caused the rectangle to be reversed (e.g.
224 //// dragging the top below the bottom)
225 void SetDragStatus(wxSashDragStatus status
) { m_dragStatus
= status
; }
226 wxSashDragStatus
GetDragStatus() const { return m_dragStatus
; }
229 wxSashEdgePosition m_edge
;
231 wxSashDragStatus m_dragStatus
;
234 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSashEvent
)
237 typedef void (wxEvtHandler::*wxSashEventFunction
)(wxSashEvent
&);
239 #define wxSashEventHandler(func) \
240 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSashEventFunction, &func)
242 #define EVT_SASH_DRAGGED(id, fn) \
243 wx__DECLARE_EVT1(wxEVT_SASH_DRAGGED, id, wxSashEventHandler(fn))
244 #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) \
245 wx__DECLARE_EVT2(wxEVT_SASH_DRAGGED, id1, id2, wxSashEventHandler(fn))