]>
Commit | Line | Data |
---|---|---|
9c7f49f5 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: generic/renderg.cpp | |
38c4cb6a | 3 | // Purpose: generic implementation of wxRendererNative (for any platform) |
9c7f49f5 VZ |
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 | ||
38c4cb6a VZ |
31 | #include "wx/gdicmn.h" |
32 | #include "wx/dc.h" | |
33 | ||
34 | #include "wx/settings.h" | |
52c14774 | 35 | #include "wx/splitter.h" |
38c4cb6a | 36 | |
9c7f49f5 VZ |
37 | #include "wx/renderer.h" |
38 | ||
39 | // ---------------------------------------------------------------------------- | |
38c4cb6a | 40 | // wxRendererGeneric: our wxRendererNative implementation |
9c7f49f5 VZ |
41 | // ---------------------------------------------------------------------------- |
42 | ||
38c4cb6a | 43 | class WXDLLEXPORT wxRendererGeneric : public wxRendererNative |
9c7f49f5 VZ |
44 | { |
45 | public: | |
b3208e11 VZ |
46 | wxRendererGeneric(); |
47 | ||
9c7f49f5 VZ |
48 | virtual void DrawHeaderButton(wxWindow *win, |
49 | wxDC& dc, | |
50 | const wxRect& rect, | |
51 | int flags = 0); | |
52 | ||
9c7f49f5 VZ |
53 | virtual void DrawTreeItemButton(wxWindow *win, |
54 | wxDC& dc, | |
55 | const wxRect& rect, | |
56 | int flags = 0); | |
b3208e11 VZ |
57 | |
58 | virtual void DrawSplitterBorder(wxWindow *win, | |
59 | wxDC& dc, | |
60 | const wxRect& rect); | |
61 | ||
62 | virtual void DrawSplitterSash(wxWindow *win, | |
63 | wxDC& dc, | |
64 | const wxSize& size, | |
65 | wxCoord position); | |
66 | ||
67 | ||
68 | virtual wxPoint GetSplitterSashAndBorder(const wxWindow *win); | |
69 | ||
70 | ||
71 | protected: | |
72 | // draw the rectange using the first pen for the left and top sides and | |
73 | // the second one for the bottom and right ones | |
74 | void DrawShadedRect(wxDC& dc, wxRect *rect, | |
75 | const wxPen& pen1, const wxPen& pen2); | |
76 | ||
77 | // the standard pens | |
78 | wxPen m_penBlack, | |
79 | m_penDarkGrey, | |
80 | m_penLightGrey, | |
81 | m_penHighlight; | |
9c7f49f5 VZ |
82 | }; |
83 | ||
84 | // ============================================================================ | |
b3208e11 | 85 | // wxRendererGeneric implementation |
9c7f49f5 VZ |
86 | // ============================================================================ |
87 | ||
88 | // ---------------------------------------------------------------------------- | |
89 | // wxRendererGeneric creation | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | /* static */ | |
38c4cb6a | 93 | wxRendererNative& wxRendererNative::GetGeneric() |
9c7f49f5 VZ |
94 | { |
95 | static wxRendererGeneric s_rendererGeneric; | |
96 | ||
97 | return s_rendererGeneric; | |
98 | } | |
99 | ||
100 | // some platforms have their own renderers | |
101 | #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__) | |
102 | ||
103 | /* static */ | |
9d999619 | 104 | wxRendererNative& wxRendererNative::Get() |
9c7f49f5 VZ |
105 | { |
106 | return GetGeneric(); | |
107 | } | |
108 | ||
109 | #endif // platforms using their own renderers | |
110 | ||
b3208e11 VZ |
111 | wxRendererGeneric::wxRendererGeneric() |
112 | : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)), | |
113 | m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)), | |
114 | m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)), | |
115 | m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)) | |
116 | { | |
117 | } | |
118 | ||
9c7f49f5 | 119 | // ---------------------------------------------------------------------------- |
b3208e11 VZ |
120 | // wxRendererGeneric helpers |
121 | // ---------------------------------------------------------------------------- | |
122 | ||
123 | void | |
124 | wxRendererGeneric::DrawShadedRect(wxDC& dc, | |
125 | wxRect *rect, | |
126 | const wxPen& pen1, | |
127 | const wxPen& pen2) | |
128 | { | |
129 | // draw the rectangle | |
130 | dc.SetPen(pen1); | |
131 | dc.DrawLine(rect->GetLeft(), rect->GetTop(), | |
132 | rect->GetLeft(), rect->GetBottom()); | |
133 | dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(), | |
134 | rect->GetRight(), rect->GetTop()); | |
135 | dc.SetPen(pen2); | |
136 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
137 | rect->GetRight(), rect->GetBottom()); | |
138 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
139 | rect->GetRight() + 1, rect->GetBottom()); | |
140 | ||
141 | // adjust the rect | |
142 | rect->Inflate(-1); | |
143 | } | |
144 | ||
145 | // ---------------------------------------------------------------------------- | |
146 | // tree/list ctrl drawing | |
9c7f49f5 VZ |
147 | // ---------------------------------------------------------------------------- |
148 | ||
149 | void | |
2eb10e2a | 150 | wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
151 | wxDC& dc, |
152 | const wxRect& rect, | |
2eb10e2a | 153 | int WXUNUSED(flags)) |
9c7f49f5 | 154 | { |
38c4cb6a VZ |
155 | const int CORNER = 1; |
156 | ||
157 | const wxCoord x = rect.x, | |
158 | y = rect.y, | |
159 | w = rect.width, | |
160 | h = rect.height; | |
9c7f49f5 | 161 | |
b3208e11 | 162 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
9c7f49f5 | 163 | |
b3208e11 | 164 | dc.SetPen(m_penBlack); |
38c4cb6a VZ |
165 | dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer) |
166 | dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
9c7f49f5 | 167 | |
b3208e11 | 168 | dc.SetPen(m_penDarkGrey); |
38c4cb6a VZ |
169 | dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner) |
170 | dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
9c7f49f5 | 171 | |
b3208e11 | 172 | dc.SetPen(m_penHighlight); |
38c4cb6a VZ |
173 | dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer) |
174 | dc.DrawRectangle( x, y, 1, h ); // left (outer) | |
175 | dc.DrawLine( x, y+h-1, x+1, y+h-1 ); | |
176 | dc.DrawLine( x+w-1, y, x+w-1, y+1 ); | |
9c7f49f5 VZ |
177 | } |
178 | ||
179 | // draw the plus or minus sign | |
180 | void | |
2eb10e2a | 181 | wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
182 | wxDC& dc, |
183 | const wxRect& rect, | |
184 | int flags) | |
185 | { | |
186 | // white background | |
187 | dc.SetPen(*wxGREY_PEN); | |
188 | dc.SetBrush(*wxWHITE_BRUSH); | |
189 | dc.DrawRectangle(rect.Deflate(1, 2)); | |
190 | ||
191 | // black lines | |
192 | const wxCoord xMiddle = rect.x + rect.width/2; | |
193 | const wxCoord yMiddle = rect.y + rect.height/2; | |
194 | ||
195 | dc.SetPen(*wxBLACK_PEN); | |
196 | dc.DrawLine(xMiddle - 2, yMiddle, xMiddle + 3, yMiddle); | |
e8448b79 | 197 | if ( !(flags & wxCONTROL_EXPANDED) ) |
9c7f49f5 VZ |
198 | { |
199 | // turn "-" into "+" | |
200 | dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3); | |
201 | } | |
202 | } | |
203 | ||
b3208e11 VZ |
204 | // ---------------------------------------------------------------------------- |
205 | // sash drawing | |
206 | // ---------------------------------------------------------------------------- | |
207 | ||
208 | wxPoint | |
52c14774 | 209 | wxRendererGeneric::GetSplitterSashAndBorder(const wxWindow *win) |
b3208e11 VZ |
210 | { |
211 | // see below | |
52c14774 | 212 | return win->HasFlag(wxSP_3D) ? wxPoint(7, 2) : wxPoint(3, 0); |
b3208e11 VZ |
213 | } |
214 | ||
215 | void | |
52c14774 | 216 | wxRendererGeneric::DrawSplitterBorder(wxWindow *win, |
b3208e11 VZ |
217 | wxDC& dc, |
218 | const wxRect& rectOrig) | |
219 | { | |
52c14774 VZ |
220 | if ( win->HasFlag(wxSP_3D) ) |
221 | { | |
222 | wxRect rect = rectOrig; | |
223 | DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight); | |
224 | DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey); | |
225 | } | |
b3208e11 VZ |
226 | } |
227 | ||
228 | void | |
52c14774 | 229 | wxRendererGeneric::DrawSplitterSash(wxWindow *win, |
b3208e11 VZ |
230 | wxDC& dc, |
231 | const wxSize& size, | |
232 | wxCoord position) | |
233 | { | |
52c14774 | 234 | // we draw a Win32-like grey sash with possible 3D border here: |
b3208e11 VZ |
235 | // |
236 | // ---- this is position | |
237 | // / | |
238 | // v | |
239 | // dWGGGDd | |
240 | // GWGGGDB | |
241 | // GWGGGDB where G is light grey (face) | |
242 | // GWGGGDB W white (light) | |
243 | // GWGGGDB D dark grey (shadow) | |
244 | // GWGGGDB B black (dark shadow) | |
245 | // GWGGGDB | |
246 | // GWGGGDB and lower letters are our border (already drawn) | |
247 | // GWGGGDB | |
248 | // wWGGGDd | |
52c14774 VZ |
249 | // |
250 | // only the middle 3 columns are drawn unless wxSP_3D is specified | |
b3208e11 VZ |
251 | |
252 | const wxCoord h = size.y; | |
253 | ||
254 | // from left to right | |
52c14774 VZ |
255 | if ( win->HasFlag(wxSP_3D) ) |
256 | { | |
257 | dc.SetPen(m_penLightGrey); | |
258 | dc.DrawLine(position, 1, position, h - 1); | |
b3208e11 | 259 | |
52c14774 VZ |
260 | dc.SetPen(m_penHighlight); |
261 | dc.DrawLine(position + 1, 0, position + 1, h); | |
262 | } | |
b3208e11 VZ |
263 | |
264 | dc.SetPen(*wxTRANSPARENT_PEN); | |
265 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); | |
266 | dc.DrawRectangle(position + 2, 0, 3, h); | |
267 | ||
52c14774 VZ |
268 | if ( win->HasFlag(wxSP_3D) ) |
269 | { | |
270 | dc.SetPen(m_penDarkGrey); | |
271 | dc.DrawLine(position + 5, 0, position + 5, h); | |
b3208e11 | 272 | |
52c14774 VZ |
273 | dc.SetPen(m_penBlack); |
274 | dc.DrawLine(position + 6, 1, position + 6, h - 1); | |
275 | } | |
b3208e11 | 276 | } |
9c7f49f5 | 277 |