1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/sashwin.h
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
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_SASHWIN_H_G_
14 #define _WX_SASHWIN_H_G_
19 #include "wx/window.h"
20 #include "wx/string.h"
22 #define wxSASH_DRAG_NONE 0
23 #define wxSASH_DRAG_DRAGGING 1
24 #define wxSASH_DRAG_LEFT_DOWN 2
26 enum wxSashEdgePosition
{
35 * wxSashEdge represents one of the four edges of a window.
38 class WXDLLIMPEXP_ADV wxSashEdge
43 #if WXWIN_COMPATIBILITY_2_6
48 bool m_show
; // Is the sash showing?
49 #if WXWIN_COMPATIBILITY_2_6
50 bool m_border
; // Do we draw a border?
52 int m_margin
; // The margin size
59 #define wxSW_NOBORDER 0x0000
60 //#define wxSW_3D 0x0010
61 #define wxSW_BORDER 0x0020
62 #define wxSW_3DSASH 0x0040
63 #define wxSW_3DBORDER 0x0080
64 #define wxSW_3D (wxSW_3DSASH | wxSW_3DBORDER)
67 * wxSashWindow allows any of its edges to have a sash which can be dragged
68 * to resize the window. The actual content window will be created as a child
72 class WXDLLIMPEXP_ADV wxSashWindow
: public wxWindow
75 // Default constructor
82 wxSashWindow(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
83 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"))
86 Create(parent
, id
, pos
, size
, style
, name
);
89 virtual ~wxSashWindow();
91 bool Create(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
92 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"));
94 // Set whether there's a sash in this position
95 void SetSashVisible(wxSashEdgePosition edge
, bool sash
);
97 // Get whether there's a sash in this position
98 bool GetSashVisible(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_show
; }
100 #if WXWIN_COMPATIBILITY_2_6
101 // Set whether there's a border in this position
102 // This value is unused in wxSashWindow.
103 void SetSashBorder(wxSashEdgePosition edge
, bool border
) { m_sashes
[edge
].m_border
= border
; }
105 // Get whether there's a border in this position
106 // This value is unused in wxSashWindow.
107 bool HasBorder(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_border
; }
111 int GetEdgeMargin(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_margin
; }
113 // Sets the default sash border size
114 void SetDefaultBorderSize(int width
) { m_borderSize
= width
; }
116 // Gets the default sash border size
117 int GetDefaultBorderSize() const { return m_borderSize
; }
119 // Sets the addition border size between child and sash window
120 void SetExtraBorderSize(int width
) { m_extraBorderSize
= width
; }
122 // Gets the addition border size between child and sash window
123 int GetExtraBorderSize() const { return m_extraBorderSize
; }
125 virtual void SetMinimumSizeX(int min
) { m_minimumPaneSizeX
= min
; }
126 virtual void SetMinimumSizeY(int min
) { m_minimumPaneSizeY
= min
; }
127 virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX
; }
128 virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY
; }
130 virtual void SetMaximumSizeX(int max
) { m_maximumPaneSizeX
= max
; }
131 virtual void SetMaximumSizeY(int max
) { m_maximumPaneSizeY
= max
; }
132 virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX
; }
133 virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY
; }
135 ////////////////////////////////////////////////////////////////////////////
138 // Paints the border and sash
139 void OnPaint(wxPaintEvent
& event
);
141 // Handles mouse events
142 void OnMouseEvent(wxMouseEvent
& ev
);
145 void OnSize(wxSizeEvent
& event
);
147 #if defined(__WXMSW__) || defined(__WXMAC__)
148 // Handle cursor correctly
149 void OnSetCursor(wxSetCursorEvent
& event
);
153 void DrawBorders(wxDC
& dc
);
156 void DrawSash(wxSashEdgePosition edge
, wxDC
& dc
);
159 void DrawSashes(wxDC
& dc
);
161 // Draws the sash tracker (for whilst moving the sash)
162 void DrawSashTracker(wxSashEdgePosition edge
, int x
, int y
);
164 // Tests for x, y over sash
165 wxSashEdgePosition
SashHitTest(int x
, int y
, int tolerance
= 2);
167 // Resizes subwindows
170 // Initialize colours
176 wxSashEdge m_sashes
[4];
178 wxSashEdgePosition m_draggingEdge
;
182 int m_extraBorderSize
;
185 int m_minimumPaneSizeX
;
186 int m_minimumPaneSizeY
;
187 int m_maximumPaneSizeX
;
188 int m_maximumPaneSizeY
;
189 wxCursor
* m_sashCursorWE
;
190 wxCursor
* m_sashCursorNS
;
191 wxColour m_lightShadowColour
;
192 wxColour m_mediumShadowColour
;
193 wxColour m_darkShadowColour
;
194 wxColour m_hilightColour
;
195 wxColour m_faceColour
;
196 bool m_mouseCaptured
;
197 wxCursor
* m_currentCursor
;
200 DECLARE_DYNAMIC_CLASS(wxSashWindow
)
201 DECLARE_EVENT_TABLE()
202 wxDECLARE_NO_COPY_CLASS(wxSashWindow
);
205 class WXDLLIMPEXP_FWD_ADV wxSashEvent
;
207 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_SASH_DRAGGED
, wxSashEvent
);
209 enum wxSashDragStatus
212 wxSASH_STATUS_OUT_OF_RANGE
215 class WXDLLIMPEXP_ADV wxSashEvent
: public wxCommandEvent
218 wxSashEvent(int id
= 0, wxSashEdgePosition edge
= wxSASH_NONE
)
220 m_eventType
= (wxEventType
) wxEVT_SASH_DRAGGED
;
225 wxSashEvent(const wxSashEvent
& event
)
226 : wxCommandEvent(event
),
227 m_edge(event
.m_edge
),
228 m_dragRect(event
.m_dragRect
),
229 m_dragStatus(event
.m_dragStatus
) { }
231 void SetEdge(wxSashEdgePosition edge
) { m_edge
= edge
; }
232 wxSashEdgePosition
GetEdge() const { return m_edge
; }
234 //// The rectangle formed by the drag operation
235 void SetDragRect(const wxRect
& rect
) { m_dragRect
= rect
; }
236 wxRect
GetDragRect() const { return m_dragRect
; }
238 //// Whether the drag caused the rectangle to be reversed (e.g.
239 //// dragging the top below the bottom)
240 void SetDragStatus(wxSashDragStatus status
) { m_dragStatus
= status
; }
241 wxSashDragStatus
GetDragStatus() const { return m_dragStatus
; }
243 virtual wxEvent
*Clone() const { return new wxSashEvent(*this); }
246 wxSashEdgePosition m_edge
;
248 wxSashDragStatus m_dragStatus
;
251 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSashEvent
)
254 typedef void (wxEvtHandler::*wxSashEventFunction
)(wxSashEvent
&);
256 #define wxSashEventHandler(func) \
257 wxEVENT_HANDLER_CAST(wxSashEventFunction, func)
259 #define EVT_SASH_DRAGGED(id, fn) \
260 wx__DECLARE_EVT1(wxEVT_SASH_DRAGGED, id, wxSashEventHandler(fn))
261 #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) \
262 wx__DECLARE_EVT2(wxEVT_SASH_DRAGGED, id1, id2, wxSashEventHandler(fn))