]>
Commit | Line | Data |
---|---|---|
a6d70308 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | |
7 | // Modified by: | |
8 | // Created: 01/02/97 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) Julian Smart | |
11 | // Licence: wxWindows license | |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | #ifndef _WX_SASHWIN_H_G_ | |
15 | #define _WX_SASHWIN_H_G_ | |
16 | ||
17 | #ifdef __GNUG__ | |
18 | #pragma interface "sashwin.h" | |
19 | #endif | |
20 | ||
21 | #include "wx/defs.h" | |
22 | #include "wx/window.h" | |
23 | #include "wx/string.h" | |
24 | ||
25 | #define wxSASH_DRAG_NONE 0 | |
26 | #define wxSASH_DRAG_DRAGGING 1 | |
27 | #define wxSASH_DRAG_LEFT_DOWN 2 | |
28 | ||
29 | enum wxSashEdgePosition { | |
30 | wxSASH_TOP = 0, | |
31 | wxSASH_RIGHT, | |
32 | wxSASH_BOTTOM, | |
33 | wxSASH_LEFT, | |
34 | wxSASH_NONE = 100 | |
35 | }; | |
36 | ||
37 | /* | |
38 | * wxSashEdge represents one of the four edges of a window. | |
39 | */ | |
40 | ||
41 | class WXDLLEXPORT wxSashEdge | |
42 | { | |
43 | public: | |
44 | wxSashEdge() { m_show = FALSE; m_border = FALSE; m_margin = 0; } | |
45 | ||
46 | bool m_show; // Is the sash showing? | |
47 | bool m_border; // Do we draw a border? | |
48 | int m_margin; // The margin size | |
49 | }; | |
50 | ||
51 | /* | |
52 | * wxSashWindow flags | |
53 | */ | |
54 | ||
55 | #define wxSW_3D 0x0004 | |
56 | ||
57 | /* | |
58 | * wxSashWindow allows any of its edges to have a sash which can be dragged | |
59 | * to resize the window. The actual content window will be created as a child | |
60 | * of wxSashWindow. | |
61 | */ | |
62 | ||
63 | class WXDLLEXPORT wxSashWindow: public wxWindow | |
64 | { | |
65 | DECLARE_DYNAMIC_CLASS(wxSashWindow) | |
66 | ||
67 | public: | |
68 | ||
69 | //////////////////////////////////////////////////////////////////////////// | |
70 | // Public API | |
71 | ||
72 | // Default constructor | |
73 | wxSashWindow(); | |
74 | ||
75 | // Normal constructor | |
76 | wxSashWindow(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, | |
2243eed5 | 77 | const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = "sashWindow"); |
a6d70308 JS |
78 | ~wxSashWindow(); |
79 | ||
80 | // Set whether there's a sash in this position | |
81 | void SetSashVisible(wxSashEdgePosition edge, bool sash); | |
82 | ||
83 | // Get whether there's a sash in this position | |
2243eed5 | 84 | inline bool GetSashVisible(wxSashEdgePosition edge) const { return m_sashes[edge].m_show; } |
a6d70308 JS |
85 | |
86 | // Set whether there's a border in this position | |
87 | inline void SetSashBorder(wxSashEdgePosition edge, bool border) { m_sashes[edge].m_border = border; } | |
88 | ||
89 | // Get whether there's a border in this position | |
2243eed5 | 90 | inline bool HasBorder(wxSashEdgePosition edge) const { return m_sashes[edge].m_border; } |
a6d70308 JS |
91 | |
92 | // Get border size | |
2243eed5 | 93 | inline int GetEdgeMargin(wxSashEdgePosition edge) const { return m_sashes[edge].m_margin; } |
a6d70308 JS |
94 | |
95 | // Sets the default sash border size | |
96 | inline void SetDefaultBorderSize(int width) { m_borderSize = width; } | |
97 | ||
98 | // Gets the default sash border size | |
99 | inline int GetDefaultBorderSize() const { return m_borderSize; } | |
100 | ||
101 | // Sets the addition border size between child and sash window | |
102 | inline void SetExtraBorderSize(int width) { m_extraBorderSize = width; } | |
103 | ||
104 | // Gets the addition border size between child and sash window | |
105 | inline int GetExtraBorderSize() const { return m_extraBorderSize; } | |
106 | ||
107 | virtual void SetMinimumSizeX(int min) { m_minimumPaneSizeX = min; } | |
108 | virtual void SetMinimumSizeY(int min) { m_minimumPaneSizeY = min; } | |
109 | virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX; } | |
110 | virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY; } | |
111 | ||
112 | virtual void SetMaximumSizeX(int max) { m_maximumPaneSizeX = max; } | |
113 | virtual void SetMaximumSizeY(int max) { m_maximumPaneSizeY = max; } | |
114 | virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX; } | |
115 | virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY; } | |
116 | ||
117 | //////////////////////////////////////////////////////////////////////////// | |
118 | // Implementation | |
119 | ||
120 | // Paints the border and sash | |
121 | void OnPaint(wxPaintEvent& event); | |
122 | ||
123 | // Handles mouse events | |
124 | void OnMouseEvent(wxMouseEvent& ev); | |
125 | ||
126 | // Adjusts the panes | |
127 | void OnSize(wxSizeEvent& event); | |
128 | ||
129 | // Draws borders | |
130 | void DrawBorders(wxDC& dc); | |
131 | ||
132 | // Draws the sashes | |
133 | void DrawSash(wxSashEdgePosition edge, wxDC& dc); | |
134 | ||
135 | // Draws the sashes | |
136 | void DrawSashes(wxDC& dc); | |
137 | ||
138 | // Draws the sash tracker (for whilst moving the sash) | |
139 | void DrawSashTracker(wxSashEdgePosition edge, int x, int y); | |
140 | ||
141 | // Tests for x, y over sash | |
142 | wxSashEdgePosition SashHitTest(int x, int y, int tolerance = 2); | |
143 | ||
144 | // Resizes subwindows | |
145 | void SizeWindows(); | |
146 | ||
147 | // Initialize colours | |
148 | void InitColours(); | |
149 | ||
150 | protected: | |
151 | wxSashEdge m_sashes[4]; | |
152 | int m_dragMode; | |
153 | wxSashEdgePosition m_draggingEdge; | |
154 | int m_oldX; | |
155 | int m_oldY; | |
156 | int m_borderSize; | |
157 | int m_extraBorderSize; | |
158 | int m_firstX; | |
159 | int m_firstY; | |
160 | int m_minimumPaneSizeX; | |
161 | int m_minimumPaneSizeY; | |
162 | int m_maximumPaneSizeX; | |
163 | int m_maximumPaneSizeY; | |
164 | wxCursor* m_sashCursorWE; | |
165 | wxCursor* m_sashCursorNS; | |
166 | wxColour m_lightShadowColour; | |
167 | wxColour m_mediumShadowColour; | |
168 | wxColour m_darkShadowColour; | |
169 | wxColour m_hilightColour; | |
170 | wxColour m_faceColour; | |
171 | ||
172 | DECLARE_EVENT_TABLE() | |
173 | }; | |
174 | ||
175 | #define wxEVT_SASH_DRAGGED (wxEVT_FIRST + 1200) | |
176 | ||
177 | enum wxSashDragStatus | |
178 | { | |
179 | wxSASH_STATUS_OK, | |
180 | wxSASH_STATUS_OUT_OF_RANGE | |
181 | }; | |
182 | ||
183 | class WXDLLEXPORT wxSashEvent: public wxCommandEvent | |
184 | { | |
185 | DECLARE_DYNAMIC_CLASS(wxSashEvent) | |
186 | ||
187 | public: | |
188 | inline wxSashEvent(int id = 0, wxSashEdgePosition edge = wxSASH_NONE) { | |
189 | m_eventType = (wxEventType) wxEVT_SASH_DRAGGED; m_id = id; m_edge = edge; } | |
190 | ||
191 | inline void SetEdge(wxSashEdgePosition edge) { m_edge = edge; } | |
192 | inline wxSashEdgePosition GetEdge() const { return m_edge; } | |
193 | ||
194 | //// The rectangle formed by the drag operation | |
195 | inline void SetDragRect(const wxRect& rect) { m_dragRect = rect; } | |
196 | inline wxRect GetDragRect() const { return m_dragRect; } | |
197 | ||
198 | //// Whether the drag caused the rectangle to be reversed (e.g. | |
199 | //// dragging the top below the bottom) | |
200 | inline void SetDragStatus(wxSashDragStatus status) { m_dragStatus = status; } | |
201 | inline wxSashDragStatus GetDragStatus() const { return m_dragStatus; } | |
202 | private: | |
203 | wxSashEdgePosition m_edge; | |
204 | wxRect m_dragRect; | |
205 | wxSashDragStatus m_dragStatus; | |
206 | }; | |
207 | ||
208 | typedef void (wxEvtHandler::*wxSashEventFunction)(wxSashEvent&); | |
209 | ||
210 | #define EVT_SASH_DRAGGED(id, fn) { wxEVT_SASH_DRAGGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL }, | |
211 | #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) { wxEVT_SASH_DRAGGED, id1, id2, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL }, | |
212 | ||
213 | #endif | |
214 | // _WX_SASHWIN_H_G_ |