]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: generic/renderg.cpp | |
3 | // Purpose: generic implementation of wxRendererNative (for any platform) | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 20.07.2003 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> | |
9 | // License: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/string.h" | |
29 | #endif //WX_PRECOMP | |
30 | ||
31 | #include "wx/gdicmn.h" | |
32 | #include "wx/dc.h" | |
33 | ||
34 | #include "wx/settings.h" | |
35 | #include "wx/splitter.h" | |
36 | #include "wx/dcmirror.h" | |
37 | #include "wx/module.h" | |
38 | #include "wx/renderer.h" | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // wxRendererGeneric: our wxRendererNative implementation | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | class WXDLLEXPORT wxRendererGeneric : public wxRendererNative | |
45 | { | |
46 | public: | |
47 | wxRendererGeneric(); | |
48 | ||
49 | virtual void DrawHeaderButton(wxWindow *win, | |
50 | wxDC& dc, | |
51 | const wxRect& rect, | |
52 | int flags = 0); | |
53 | ||
54 | virtual void DrawTreeItemButton(wxWindow *win, | |
55 | wxDC& dc, | |
56 | const wxRect& rect, | |
57 | int flags = 0); | |
58 | ||
59 | virtual void DrawSplitterBorder(wxWindow *win, | |
60 | wxDC& dc, | |
61 | const wxRect& rect, | |
62 | int flags = 0); | |
63 | ||
64 | virtual void DrawSplitterSash(wxWindow *win, | |
65 | wxDC& dc, | |
66 | const wxSize& size, | |
67 | wxCoord position, | |
68 | wxOrientation orient, | |
69 | int flags = 0); | |
70 | ||
71 | ||
72 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); | |
73 | ||
74 | virtual wxRendererVersion GetVersion() const | |
75 | { | |
76 | return wxRendererVersion(wxRendererVersion::Current_Version, | |
77 | wxRendererVersion::Current_Age); | |
78 | } | |
79 | ||
80 | ||
81 | // Cleanup by deleting standard renderer | |
82 | static void Cleanup(); | |
83 | ||
84 | // Get the generic object | |
85 | static wxRendererGeneric* DoGetGeneric(); | |
86 | ||
87 | protected: | |
88 | // draw the rectange using the first pen for the left and top sides and | |
89 | // the second one for the bottom and right ones | |
90 | void DrawShadedRect(wxDC& dc, wxRect *rect, | |
91 | const wxPen& pen1, const wxPen& pen2); | |
92 | ||
93 | // the standard pens | |
94 | wxPen m_penBlack, | |
95 | m_penDarkGrey, | |
96 | m_penLightGrey, | |
97 | m_penHighlight; | |
98 | ||
99 | static wxRendererGeneric* sm_rendererGeneric; | |
100 | }; | |
101 | ||
102 | // ============================================================================ | |
103 | // wxRendererGeneric implementation | |
104 | // ============================================================================ | |
105 | ||
106 | // Get the generic object | |
107 | wxRendererGeneric* wxRendererGeneric::DoGetGeneric() | |
108 | { | |
109 | if (!sm_rendererGeneric) | |
110 | sm_rendererGeneric = new wxRendererGeneric; | |
111 | return sm_rendererGeneric; | |
112 | } | |
113 | ||
114 | // ---------------------------------------------------------------------------- | |
115 | // wxRendererGeneric creation | |
116 | // ---------------------------------------------------------------------------- | |
117 | ||
118 | /* static */ | |
119 | wxRendererNative& wxRendererNative::GetGeneric() | |
120 | { | |
121 | return * wxRendererGeneric::DoGetGeneric(); | |
122 | } | |
123 | ||
124 | void wxRendererGeneric::Cleanup() | |
125 | { | |
126 | if (sm_rendererGeneric) | |
127 | delete sm_rendererGeneric; | |
128 | ||
129 | sm_rendererGeneric = NULL; | |
130 | } | |
131 | ||
132 | wxRendererGeneric* wxRendererGeneric::sm_rendererGeneric = NULL; | |
133 | ||
134 | wxRendererGeneric::wxRendererGeneric() | |
135 | : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)), | |
136 | m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)), | |
137 | m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)), | |
138 | m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)) | |
139 | { | |
140 | } | |
141 | ||
142 | // ---------------------------------------------------------------------------- | |
143 | // wxRendererGeneric helpers | |
144 | // ---------------------------------------------------------------------------- | |
145 | ||
146 | void | |
147 | wxRendererGeneric::DrawShadedRect(wxDC& dc, | |
148 | wxRect *rect, | |
149 | const wxPen& pen1, | |
150 | const wxPen& pen2) | |
151 | { | |
152 | // draw the rectangle | |
153 | dc.SetPen(pen1); | |
154 | dc.DrawLine(rect->GetLeft(), rect->GetTop(), | |
155 | rect->GetLeft(), rect->GetBottom()); | |
156 | dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(), | |
157 | rect->GetRight(), rect->GetTop()); | |
158 | dc.SetPen(pen2); | |
159 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
160 | rect->GetRight(), rect->GetBottom()); | |
161 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
162 | rect->GetRight() + 1, rect->GetBottom()); | |
163 | ||
164 | // adjust the rect | |
165 | rect->Inflate(-1); | |
166 | } | |
167 | ||
168 | // ---------------------------------------------------------------------------- | |
169 | // tree/list ctrl drawing | |
170 | // ---------------------------------------------------------------------------- | |
171 | ||
172 | void | |
173 | wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win), | |
174 | wxDC& dc, | |
175 | const wxRect& rect, | |
176 | int WXUNUSED(flags)) | |
177 | { | |
178 | const int CORNER = 1; | |
179 | ||
180 | const wxCoord x = rect.x, | |
181 | y = rect.y, | |
182 | w = rect.width, | |
183 | h = rect.height; | |
184 | ||
185 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
186 | ||
187 | dc.SetPen(m_penBlack); | |
188 | dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer) | |
189 | dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
190 | ||
191 | dc.SetPen(m_penDarkGrey); | |
192 | dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner) | |
193 | dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
194 | ||
195 | dc.SetPen(m_penHighlight); | |
196 | dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer) | |
197 | dc.DrawRectangle( x, y, 1, h ); // left (outer) | |
198 | dc.DrawLine( x, y+h-1, x+1, y+h-1 ); | |
199 | dc.DrawLine( x+w-1, y, x+w-1, y+1 ); | |
200 | } | |
201 | ||
202 | // draw the plus or minus sign | |
203 | void | |
204 | wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win), | |
205 | wxDC& dc, | |
206 | const wxRect& rect, | |
207 | int flags) | |
208 | { | |
209 | // white background | |
210 | dc.SetPen(*wxGREY_PEN); | |
211 | dc.SetBrush(*wxWHITE_BRUSH); | |
212 | dc.DrawRectangle(rect); | |
213 | ||
214 | // black lines | |
215 | const wxCoord xMiddle = rect.x + rect.width/2; | |
216 | const wxCoord yMiddle = rect.y + rect.height/2; | |
217 | ||
218 | // half of the length of the horz lines in "-" and "+" | |
219 | const wxCoord halfWidth = rect.width/2 - 2; | |
220 | dc.SetPen(*wxBLACK_PEN); | |
221 | dc.DrawLine(xMiddle - halfWidth, yMiddle, | |
222 | xMiddle + halfWidth + 1, yMiddle); | |
223 | ||
224 | if ( !(flags & wxCONTROL_EXPANDED) ) | |
225 | { | |
226 | // turn "-" into "+" | |
227 | const wxCoord halfHeight = rect.height/2 - 2; | |
228 | dc.DrawLine(xMiddle, yMiddle - halfHeight, | |
229 | xMiddle, yMiddle + halfHeight + 1); | |
230 | } | |
231 | } | |
232 | ||
233 | // ---------------------------------------------------------------------------- | |
234 | // sash drawing | |
235 | // ---------------------------------------------------------------------------- | |
236 | ||
237 | wxSplitterRenderParams | |
238 | wxRendererGeneric::GetSplitterParams(const wxWindow *win) | |
239 | { | |
240 | // see below | |
241 | wxCoord sashWidth, | |
242 | border; | |
243 | ||
244 | if ( win->HasFlag(wxSP_3D) ) | |
245 | { | |
246 | sashWidth = 7; | |
247 | border = 2; | |
248 | } | |
249 | else // no 3D effect | |
250 | { | |
251 | sashWidth = 3; | |
252 | border = 0; | |
253 | } | |
254 | ||
255 | return wxSplitterRenderParams(sashWidth, border, false); | |
256 | } | |
257 | ||
258 | void | |
259 | wxRendererGeneric::DrawSplitterBorder(wxWindow *win, | |
260 | wxDC& dc, | |
261 | const wxRect& rectOrig, | |
262 | int WXUNUSED(falgs)) | |
263 | { | |
264 | if ( win->HasFlag(wxSP_3D) ) | |
265 | { | |
266 | wxRect rect = rectOrig; | |
267 | DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight); | |
268 | DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey); | |
269 | } | |
270 | } | |
271 | ||
272 | void | |
273 | wxRendererGeneric::DrawSplitterSash(wxWindow *win, | |
274 | wxDC& dcReal, | |
275 | const wxSize& sizeReal, | |
276 | wxCoord position, | |
277 | wxOrientation orient, | |
278 | int WXUNUSED(flags)) | |
279 | { | |
280 | // to avoid duplicating the same code for horizontal and vertical sashes, | |
281 | // simply mirror the DC instead if needed (i.e. if horz splitter) | |
282 | wxMirrorDC dc(dcReal, orient != wxVERTICAL); | |
283 | wxSize size = dc.Reflect(sizeReal); | |
284 | ||
285 | ||
286 | // we draw a Win32-like grey sash with possible 3D border here: | |
287 | // | |
288 | // ---- this is position | |
289 | // / | |
290 | // v | |
291 | // dWGGGDd | |
292 | // GWGGGDB | |
293 | // GWGGGDB where G is light grey (face) | |
294 | // GWGGGDB W white (light) | |
295 | // GWGGGDB D dark grey (shadow) | |
296 | // GWGGGDB B black (dark shadow) | |
297 | // GWGGGDB | |
298 | // GWGGGDB and lower letters are our border (already drawn) | |
299 | // GWGGGDB | |
300 | // wWGGGDd | |
301 | // | |
302 | // only the middle 3 columns are drawn unless wxSP_3D is specified | |
303 | ||
304 | const wxCoord h = size.y; | |
305 | wxCoord offset = 0; | |
306 | ||
307 | // If we're not drawing the border, droppings will | |
308 | // be left unless we make the sash shorter | |
309 | if ( !win->HasFlag(wxSP_3DBORDER) ) | |
310 | { | |
311 | offset = 3; | |
312 | } | |
313 | ||
314 | // from left to right | |
315 | if ( win->HasFlag(wxSP_3D) ) | |
316 | { | |
317 | dc.SetPen(m_penLightGrey); | |
318 | dc.DrawLine(position, 1 + offset, position, h - 1 - offset); | |
319 | ||
320 | dc.SetPen(m_penHighlight); | |
321 | dc.DrawLine(position + 1, offset, position + 1, h - offset); | |
322 | } | |
323 | ||
324 | dc.SetPen(*wxTRANSPARENT_PEN); | |
325 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); | |
326 | dc.DrawRectangle(position + 2, offset, 3, h - 2*offset); | |
327 | ||
328 | if ( win->HasFlag(wxSP_3D) ) | |
329 | { | |
330 | dc.SetPen(m_penDarkGrey); | |
331 | dc.DrawLine(position + 5, offset, position + 5, h - offset); | |
332 | ||
333 | dc.SetPen(m_penBlack); | |
334 | dc.DrawLine(position + 6, offset, position + 6, h - 1 - offset); | |
335 | } | |
336 | } | |
337 | ||
338 | // A module to allow cleanup of generic renderer. | |
339 | class wxGenericRendererModule: public wxModule | |
340 | { | |
341 | DECLARE_DYNAMIC_CLASS(wxGenericRendererModule) | |
342 | public: | |
343 | wxGenericRendererModule() {} | |
344 | bool OnInit() { return true; }; | |
345 | void OnExit() { wxRendererGeneric::Cleanup(); }; | |
346 | }; | |
347 | ||
348 | IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule) | |
349 |