]>
Commit | Line | Data |
---|---|---|
a6d70308 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/generic/sashwin.h |
a6d70308 JS |
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 | |
7 | // Modified by: | |
8 | // Created: 01/02/97 | |
a6d70308 | 9 | // Copyright: (c) Julian Smart |
65571936 | 10 | // Licence: wxWindows licence |
a6d70308 JS |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | #ifndef _WX_SASHWIN_H_G_ | |
14 | #define _WX_SASHWIN_H_G_ | |
15 | ||
88ac883a VZ |
16 | #if wxUSE_SASH |
17 | ||
a6d70308 JS |
18 | #include "wx/defs.h" |
19 | #include "wx/window.h" | |
20 | #include "wx/string.h" | |
21 | ||
22 | #define wxSASH_DRAG_NONE 0 | |
23 | #define wxSASH_DRAG_DRAGGING 1 | |
24 | #define wxSASH_DRAG_LEFT_DOWN 2 | |
25 | ||
26 | enum wxSashEdgePosition { | |
27 | wxSASH_TOP = 0, | |
28 | wxSASH_RIGHT, | |
29 | wxSASH_BOTTOM, | |
30 | wxSASH_LEFT, | |
31 | wxSASH_NONE = 100 | |
32 | }; | |
33 | ||
34 | /* | |
35 | * wxSashEdge represents one of the four edges of a window. | |
36 | */ | |
37 | ||
12f190b0 | 38 | class WXDLLIMPEXP_ADV wxSashEdge |
a6d70308 JS |
39 | { |
40 | public: | |
8cd96c6b JS |
41 | wxSashEdge() |
42 | { m_show = false; | |
43 | #if WXWIN_COMPATIBILITY_2_6 | |
44 | m_border = false; | |
45 | #endif | |
46 | m_margin = 0; } | |
a6d70308 JS |
47 | |
48 | bool m_show; // Is the sash showing? | |
8cd96c6b | 49 | #if WXWIN_COMPATIBILITY_2_6 |
a6d70308 | 50 | bool m_border; // Do we draw a border? |
8cd96c6b | 51 | #endif |
a6d70308 JS |
52 | int m_margin; // The margin size |
53 | }; | |
54 | ||
55 | /* | |
56 | * wxSashWindow flags | |
57 | */ | |
58 | ||
448af9a4 | 59 | #define wxSW_NOBORDER 0x0000 |
f6bcfd97 | 60 | //#define wxSW_3D 0x0010 |
448af9a4 | 61 | #define wxSW_BORDER 0x0020 |
f6bcfd97 BP |
62 | #define wxSW_3DSASH 0x0040 |
63 | #define wxSW_3DBORDER 0x0080 | |
64 | #define wxSW_3D (wxSW_3DSASH | wxSW_3DBORDER) | |
a6d70308 JS |
65 | |
66 | /* | |
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 | |
69 | * of wxSashWindow. | |
70 | */ | |
71 | ||
12f190b0 | 72 | class WXDLLIMPEXP_ADV wxSashWindow: public wxWindow |
a6d70308 | 73 | { |
a6d70308 | 74 | public: |
a6d70308 | 75 | // Default constructor |
f6bcfd97 BP |
76 | wxSashWindow() |
77 | { | |
78 | Init(); | |
79 | } | |
a6d70308 JS |
80 | |
81 | // Normal constructor | |
ca65c044 | 82 | wxSashWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
2b5f62a0 | 83 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("sashWindow")) |
f6bcfd97 BP |
84 | { |
85 | Init(); | |
86 | Create(parent, id, pos, size, style, name); | |
87 | } | |
88 | ||
d3c7fc99 | 89 | virtual ~wxSashWindow(); |
a6d70308 | 90 | |
ca65c044 | 91 | bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, |
2b5f62a0 | 92 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("sashWindow")); |
f6bcfd97 | 93 | |
a6d70308 JS |
94 | // Set whether there's a sash in this position |
95 | void SetSashVisible(wxSashEdgePosition edge, bool sash); | |
96 | ||
97 | // Get whether there's a sash in this position | |
40717c90 | 98 | bool GetSashVisible(wxSashEdgePosition edge) const { return m_sashes[edge].m_show; } |
a6d70308 | 99 | |
8cd96c6b | 100 | #if WXWIN_COMPATIBILITY_2_6 |
a6d70308 | 101 | // Set whether there's a border in this position |
8cd96c6b | 102 | // This value is unused in wxSashWindow. |
40717c90 | 103 | void SetSashBorder(wxSashEdgePosition edge, bool border) { m_sashes[edge].m_border = border; } |
a6d70308 JS |
104 | |
105 | // Get whether there's a border in this position | |
8cd96c6b | 106 | // This value is unused in wxSashWindow. |
40717c90 | 107 | bool HasBorder(wxSashEdgePosition edge) const { return m_sashes[edge].m_border; } |
8cd96c6b | 108 | #endif |
a6d70308 JS |
109 | |
110 | // Get border size | |
40717c90 | 111 | int GetEdgeMargin(wxSashEdgePosition edge) const { return m_sashes[edge].m_margin; } |
a6d70308 JS |
112 | |
113 | // Sets the default sash border size | |
40717c90 | 114 | void SetDefaultBorderSize(int width) { m_borderSize = width; } |
a6d70308 JS |
115 | |
116 | // Gets the default sash border size | |
40717c90 | 117 | int GetDefaultBorderSize() const { return m_borderSize; } |
a6d70308 JS |
118 | |
119 | // Sets the addition border size between child and sash window | |
40717c90 | 120 | void SetExtraBorderSize(int width) { m_extraBorderSize = width; } |
a6d70308 JS |
121 | |
122 | // Gets the addition border size between child and sash window | |
40717c90 | 123 | int GetExtraBorderSize() const { return m_extraBorderSize; } |
a6d70308 JS |
124 | |
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; } | |
129 | ||
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; } | |
134 | ||
135 | //////////////////////////////////////////////////////////////////////////// | |
136 | // Implementation | |
137 | ||
138 | // Paints the border and sash | |
139 | void OnPaint(wxPaintEvent& event); | |
140 | ||
141 | // Handles mouse events | |
142 | void OnMouseEvent(wxMouseEvent& ev); | |
143 | ||
144 | // Adjusts the panes | |
145 | void OnSize(wxSizeEvent& event); | |
146 | ||
91ce04cf | 147 | #if defined(__WXMSW__) || defined(__WXMAC__) |
2b5f62a0 VZ |
148 | // Handle cursor correctly |
149 | void OnSetCursor(wxSetCursorEvent& event); | |
150 | #endif // wxMSW | |
151 | ||
a6d70308 JS |
152 | // Draws borders |
153 | void DrawBorders(wxDC& dc); | |
154 | ||
155 | // Draws the sashes | |
156 | void DrawSash(wxSashEdgePosition edge, wxDC& dc); | |
157 | ||
158 | // Draws the sashes | |
159 | void DrawSashes(wxDC& dc); | |
160 | ||
161 | // Draws the sash tracker (for whilst moving the sash) | |
162 | void DrawSashTracker(wxSashEdgePosition edge, int x, int y); | |
163 | ||
164 | // Tests for x, y over sash | |
165 | wxSashEdgePosition SashHitTest(int x, int y, int tolerance = 2); | |
166 | ||
167 | // Resizes subwindows | |
168 | void SizeWindows(); | |
169 | ||
170 | // Initialize colours | |
171 | void InitColours(); | |
172 | ||
f6bcfd97 BP |
173 | private: |
174 | void Init(); | |
175 | ||
a6d70308 JS |
176 | wxSashEdge m_sashes[4]; |
177 | int m_dragMode; | |
178 | wxSashEdgePosition m_draggingEdge; | |
179 | int m_oldX; | |
180 | int m_oldY; | |
181 | int m_borderSize; | |
182 | int m_extraBorderSize; | |
183 | int m_firstX; | |
184 | int m_firstY; | |
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; | |
621f9767 | 196 | bool m_mouseCaptured; |
2b5f62a0 | 197 | wxCursor* m_currentCursor; |
a6d70308 | 198 | |
2b5f62a0 VZ |
199 | private: |
200 | DECLARE_DYNAMIC_CLASS(wxSashWindow) | |
201 | DECLARE_EVENT_TABLE() | |
c0c133e1 | 202 | wxDECLARE_NO_COPY_CLASS(wxSashWindow); |
a6d70308 JS |
203 | }; |
204 | ||
3c778901 VZ |
205 | class WXDLLIMPEXP_FWD_ADV wxSashEvent; |
206 | ||
9b11752c | 207 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_SASH_DRAGGED, wxSashEvent ); |
32956769 | 208 | |
a6d70308 JS |
209 | enum wxSashDragStatus |
210 | { | |
211 | wxSASH_STATUS_OK, | |
212 | wxSASH_STATUS_OUT_OF_RANGE | |
213 | }; | |
214 | ||
12f190b0 | 215 | class WXDLLIMPEXP_ADV wxSashEvent: public wxCommandEvent |
a6d70308 | 216 | { |
2b5f62a0 | 217 | public: |
40717c90 VZ |
218 | wxSashEvent(int id = 0, wxSashEdgePosition edge = wxSASH_NONE) |
219 | { | |
220 | m_eventType = (wxEventType) wxEVT_SASH_DRAGGED; | |
221 | m_id = id; | |
222 | m_edge = edge; | |
223 | } | |
a6d70308 | 224 | |
f8a5d9da FM |
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) { } | |
230 | ||
40717c90 VZ |
231 | void SetEdge(wxSashEdgePosition edge) { m_edge = edge; } |
232 | wxSashEdgePosition GetEdge() const { return m_edge; } | |
a6d70308 JS |
233 | |
234 | //// The rectangle formed by the drag operation | |
40717c90 VZ |
235 | void SetDragRect(const wxRect& rect) { m_dragRect = rect; } |
236 | wxRect GetDragRect() const { return m_dragRect; } | |
a6d70308 JS |
237 | |
238 | //// Whether the drag caused the rectangle to be reversed (e.g. | |
239 | //// dragging the top below the bottom) | |
40717c90 VZ |
240 | void SetDragStatus(wxSashDragStatus status) { m_dragStatus = status; } |
241 | wxSashDragStatus GetDragStatus() const { return m_dragStatus; } | |
ca65c044 | 242 | |
f8a5d9da FM |
243 | virtual wxEvent *Clone() const { return new wxSashEvent(*this); } |
244 | ||
2b5f62a0 | 245 | private: |
a6d70308 JS |
246 | wxSashEdgePosition m_edge; |
247 | wxRect m_dragRect; | |
248 | wxSashDragStatus m_dragStatus; | |
2b5f62a0 VZ |
249 | |
250 | private: | |
f8a5d9da | 251 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSashEvent) |
a6d70308 JS |
252 | }; |
253 | ||
254 | typedef void (wxEvtHandler::*wxSashEventFunction)(wxSashEvent&); | |
255 | ||
40717c90 | 256 | #define wxSashEventHandler(func) \ |
3c778901 | 257 | wxEVENT_HANDLER_CAST(wxSashEventFunction, func) |
40717c90 | 258 | |
82a5f02c | 259 | #define EVT_SASH_DRAGGED(id, fn) \ |
40717c90 | 260 | wx__DECLARE_EVT1(wxEVT_SASH_DRAGGED, id, wxSashEventHandler(fn)) |
82a5f02c | 261 | #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) \ |
40717c90 | 262 | wx__DECLARE_EVT2(wxEVT_SASH_DRAGGED, id1, id2, wxSashEventHandler(fn)) |
a6d70308 | 263 | |
88ac883a VZ |
264 | #endif // wxUSE_SASH |
265 | ||
a6d70308 JS |
266 | #endif |
267 | // _WX_SASHWIN_H_G_ |