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_
17 #if defined(__GNUG__) && !defined(__APPLE__)
18 #pragma interface "sashwin.h"
24 #include "wx/window.h"
25 #include "wx/string.h"
27 #define wxSASH_DRAG_NONE 0
28 #define wxSASH_DRAG_DRAGGING 1
29 #define wxSASH_DRAG_LEFT_DOWN 2
31 enum wxSashEdgePosition
{
40 * wxSashEdge represents one of the four edges of a window.
43 class WXDLLEXPORT wxSashEdge
46 wxSashEdge() { m_show
= FALSE
; m_border
= FALSE
; m_margin
= 0; }
48 bool m_show
; // Is the sash showing?
49 bool m_border
; // Do we draw a border?
50 int m_margin
; // The margin size
57 #define wxSW_NOBORDER 0x0000
58 //#define wxSW_3D 0x0010
59 #define wxSW_BORDER 0x0020
60 #define wxSW_3DSASH 0x0040
61 #define wxSW_3DBORDER 0x0080
62 #define wxSW_3D (wxSW_3DSASH | wxSW_3DBORDER)
65 * wxSashWindow allows any of its edges to have a sash which can be dragged
66 * to resize the window. The actual content window will be created as a child
70 class WXDLLEXPORT wxSashWindow
: public wxWindow
73 // Default constructor
80 wxSashWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
81 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"))
84 Create(parent
, id
, pos
, size
, style
, name
);
89 bool Create(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
90 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= wxT("sashWindow"));
92 // Set whether there's a sash in this position
93 void SetSashVisible(wxSashEdgePosition edge
, bool sash
);
95 // Get whether there's a sash in this position
96 inline bool GetSashVisible(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_show
; }
98 // Set whether there's a border in this position
99 inline void SetSashBorder(wxSashEdgePosition edge
, bool border
) { m_sashes
[edge
].m_border
= border
; }
101 // Get whether there's a border in this position
102 inline bool HasBorder(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_border
; }
105 inline int GetEdgeMargin(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_margin
; }
107 // Sets the default sash border size
108 inline void SetDefaultBorderSize(int width
) { m_borderSize
= width
; }
110 // Gets the default sash border size
111 inline int GetDefaultBorderSize() const { return m_borderSize
; }
113 // Sets the addition border size between child and sash window
114 inline void SetExtraBorderSize(int width
) { m_extraBorderSize
= width
; }
116 // Gets the addition border size between child and sash window
117 inline int GetExtraBorderSize() const { return m_extraBorderSize
; }
119 virtual void SetMinimumSizeX(int min
) { m_minimumPaneSizeX
= min
; }
120 virtual void SetMinimumSizeY(int min
) { m_minimumPaneSizeY
= min
; }
121 virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX
; }
122 virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY
; }
124 virtual void SetMaximumSizeX(int max
) { m_maximumPaneSizeX
= max
; }
125 virtual void SetMaximumSizeY(int max
) { m_maximumPaneSizeY
= max
; }
126 virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX
; }
127 virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY
; }
129 ////////////////////////////////////////////////////////////////////////////
132 // Paints the border and sash
133 void OnPaint(wxPaintEvent
& event
);
135 // Handles mouse events
136 void OnMouseEvent(wxMouseEvent
& ev
);
139 void OnSize(wxSizeEvent
& event
);
141 #if defined(__WXMSW__) || defined(__WXMAC__)
142 // Handle cursor correctly
143 void OnSetCursor(wxSetCursorEvent
& event
);
147 void DrawBorders(wxDC
& dc
);
150 void DrawSash(wxSashEdgePosition edge
, wxDC
& dc
);
153 void DrawSashes(wxDC
& dc
);
155 // Draws the sash tracker (for whilst moving the sash)
156 void DrawSashTracker(wxSashEdgePosition edge
, int x
, int y
);
158 // Tests for x, y over sash
159 wxSashEdgePosition
SashHitTest(int x
, int y
, int tolerance
= 2);
161 // Resizes subwindows
164 // Initialize colours
170 wxSashEdge m_sashes
[4];
172 wxSashEdgePosition m_draggingEdge
;
176 int m_extraBorderSize
;
179 int m_minimumPaneSizeX
;
180 int m_minimumPaneSizeY
;
181 int m_maximumPaneSizeX
;
182 int m_maximumPaneSizeY
;
183 wxCursor
* m_sashCursorWE
;
184 wxCursor
* m_sashCursorNS
;
185 wxColour m_lightShadowColour
;
186 wxColour m_mediumShadowColour
;
187 wxColour m_darkShadowColour
;
188 wxColour m_hilightColour
;
189 wxColour m_faceColour
;
190 bool m_mouseCaptured
;
191 wxCursor
* m_currentCursor
;
194 DECLARE_DYNAMIC_CLASS(wxSashWindow
)
195 DECLARE_EVENT_TABLE()
196 DECLARE_NO_COPY_CLASS(wxSashWindow
)
199 BEGIN_DECLARE_EVENT_TYPES()
200 DECLARE_EVENT_TYPE(wxEVT_SASH_DRAGGED
, wxEVT_FIRST
+ 1200)
201 END_DECLARE_EVENT_TYPES()
203 // #define wxEVT_SASH_DRAGGED (wxEVT_FIRST + 1200)
205 enum wxSashDragStatus
208 wxSASH_STATUS_OUT_OF_RANGE
211 class WXDLLEXPORT wxSashEvent
: public wxCommandEvent
214 inline wxSashEvent(int id
= 0, wxSashEdgePosition edge
= wxSASH_NONE
) {
215 m_eventType
= (wxEventType
) wxEVT_SASH_DRAGGED
; m_id
= id
; m_edge
= edge
; }
217 inline void SetEdge(wxSashEdgePosition edge
) { m_edge
= edge
; }
218 inline wxSashEdgePosition
GetEdge() const { return m_edge
; }
220 //// The rectangle formed by the drag operation
221 inline void SetDragRect(const wxRect
& rect
) { m_dragRect
= rect
; }
222 inline wxRect
GetDragRect() const { return m_dragRect
; }
224 //// Whether the drag caused the rectangle to be reversed (e.g.
225 //// dragging the top below the bottom)
226 inline void SetDragStatus(wxSashDragStatus status
) { m_dragStatus
= status
; }
227 inline wxSashDragStatus
GetDragStatus() const { return m_dragStatus
; }
230 wxSashEdgePosition m_edge
;
232 wxSashDragStatus m_dragStatus
;
235 DECLARE_DYNAMIC_CLASS(wxSashEvent
)
238 typedef void (wxEvtHandler::*wxSashEventFunction
)(wxSashEvent
&);
240 #define EVT_SASH_DRAGGED(id, fn) \
241 DECLARE_EVENT_TABLE_ENTRY( wxEVT_SASH_DRAGGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL ),
242 #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) \
243 DECLARE_EVENT_TABLE_ENTRY( wxEVT_SASH_DRAGGED, id1, id2, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL ),