]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/renderg.cpp
wxUSE_EXTENDED_RTTI as name
[wxWidgets.git] / src / generic / renderg.cpp
... / ...
CommitLineData
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
45class WXDLLEXPORT wxRendererGeneric : public wxRendererNative
46{
47public:
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
74protected:
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 */
96wxRendererNative& wxRendererNative::GetGeneric()
97{
98 static wxRendererGeneric s_rendererGeneric;
99
100 return s_rendererGeneric;
101}
102
103// some platforms have their own renderers
104#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__)
105
106/* static */
107wxRendererNative& wxRendererNative::Get()
108{
109 return GetGeneric();
110}
111
112#endif // platforms using their own renderers
113
114wxRendererGeneric::wxRendererGeneric()
115 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)),
116 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)),
117 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)),
118 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT))
119{
120}
121
122// ----------------------------------------------------------------------------
123// wxRendererGeneric helpers
124// ----------------------------------------------------------------------------
125
126void
127wxRendererGeneric::DrawShadedRect(wxDC& dc,
128 wxRect *rect,
129 const wxPen& pen1,
130 const wxPen& pen2)
131{
132 // draw the rectangle
133 dc.SetPen(pen1);
134 dc.DrawLine(rect->GetLeft(), rect->GetTop(),
135 rect->GetLeft(), rect->GetBottom());
136 dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(),
137 rect->GetRight(), rect->GetTop());
138 dc.SetPen(pen2);
139 dc.DrawLine(rect->GetRight(), rect->GetTop(),
140 rect->GetRight(), rect->GetBottom());
141 dc.DrawLine(rect->GetLeft(), rect->GetBottom(),
142 rect->GetRight() + 1, rect->GetBottom());
143
144 // adjust the rect
145 rect->Inflate(-1);
146}
147
148// ----------------------------------------------------------------------------
149// tree/list ctrl drawing
150// ----------------------------------------------------------------------------
151
152void
153wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win),
154 wxDC& dc,
155 const wxRect& rect,
156 int WXUNUSED(flags))
157{
158 const int CORNER = 1;
159
160 const wxCoord x = rect.x,
161 y = rect.y,
162 w = rect.width,
163 h = rect.height;
164
165 dc.SetBrush(*wxTRANSPARENT_BRUSH);
166
167 dc.SetPen(m_penBlack);
168 dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
169 dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
170
171 dc.SetPen(m_penDarkGrey);
172 dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
173 dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
174
175 dc.SetPen(m_penHighlight);
176 dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
177 dc.DrawRectangle( x, y, 1, h ); // left (outer)
178 dc.DrawLine( x, y+h-1, x+1, y+h-1 );
179 dc.DrawLine( x+w-1, y, x+w-1, y+1 );
180}
181
182// draw the plus or minus sign
183void
184wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
185 wxDC& dc,
186 const wxRect& rect,
187 int flags)
188{
189 // white background
190 dc.SetPen(*wxGREY_PEN);
191 dc.SetBrush(*wxWHITE_BRUSH);
192 dc.DrawRectangle(rect.Deflate(1, 2));
193
194 // black lines
195 const wxCoord xMiddle = rect.x + rect.width/2;
196 const wxCoord yMiddle = rect.y + rect.height/2;
197
198 dc.SetPen(*wxBLACK_PEN);
199 dc.DrawLine(xMiddle - 2, yMiddle, xMiddle + 3, yMiddle);
200 if ( !(flags & wxCONTROL_EXPANDED) )
201 {
202 // turn "-" into "+"
203 dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3);
204 }
205}
206
207// ----------------------------------------------------------------------------
208// sash drawing
209// ----------------------------------------------------------------------------
210
211wxPoint
212wxRendererGeneric::GetSplitterSashAndBorder(const wxWindow *win)
213{
214 // see below
215 return win->HasFlag(wxSP_3D) ? wxPoint(7, 2) : wxPoint(3, 0);
216}
217
218void
219wxRendererGeneric::DrawSplitterBorder(wxWindow *win,
220 wxDC& dc,
221 const wxRect& rectOrig)
222{
223 if ( win->HasFlag(wxSP_3D) )
224 {
225 wxRect rect = rectOrig;
226 DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
227 DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
228 }
229}
230
231void
232wxRendererGeneric::DrawSplitterSash(wxWindow *win,
233 wxDC& dcReal,
234 const wxSize& sizeReal,
235 wxCoord position,
236 wxOrientation orient)
237{
238 // to avoid duplicating the same code for horizontal and vertical sashes,
239 // simply mirror the DC instead if needed (i.e. if horz splitter)
240 wxMirrorDC dc(dcReal, orient != wxVERTICAL);
241 wxSize size = dc.Reflect(sizeReal);
242
243
244 // we draw a Win32-like grey sash with possible 3D border here:
245 //
246 // ---- this is position
247 // /
248 // v
249 // dWGGGDd
250 // GWGGGDB
251 // GWGGGDB where G is light grey (face)
252 // GWGGGDB W white (light)
253 // GWGGGDB D dark grey (shadow)
254 // GWGGGDB B black (dark shadow)
255 // GWGGGDB
256 // GWGGGDB and lower letters are our border (already drawn)
257 // GWGGGDB
258 // wWGGGDd
259 //
260 // only the middle 3 columns are drawn unless wxSP_3D is specified
261
262 const wxCoord h = size.y;
263
264 // from left to right
265 if ( win->HasFlag(wxSP_3D) )
266 {
267 dc.SetPen(m_penLightGrey);
268 dc.DrawLine(position, 1, position, h - 1);
269
270 dc.SetPen(m_penHighlight);
271 dc.DrawLine(position + 1, 0, position + 1, h);
272 }
273
274 dc.SetPen(*wxTRANSPARENT_PEN);
275 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
276 dc.DrawRectangle(position + 2, 0, 3, h);
277
278 if ( win->HasFlag(wxSP_3D) )
279 {
280 dc.SetPen(m_penDarkGrey);
281 dc.DrawLine(position + 5, 0, position + 5, h);
282
283 dc.SetPen(m_penBlack);
284 dc.DrawLine(position + 6, 1, position + 6, h - 1);
285 }
286}
287