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