]> git.saurik.com Git - wxWidgets.git/blame - src/generic/renderg.cpp
wxUSE_EXTENDED_RTTI as name
[wxWidgets.git] / src / generic / renderg.cpp
CommitLineData
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
62dc9cb4
VZ
37#include "wx/dcmirror.h"
38
9c7f49f5
VZ
39#include "wx/renderer.h"
40
41// ----------------------------------------------------------------------------
38c4cb6a 42// wxRendererGeneric: our wxRendererNative implementation
9c7f49f5
VZ
43// ----------------------------------------------------------------------------
44
38c4cb6a 45class WXDLLEXPORT wxRendererGeneric : public wxRendererNative
9c7f49f5
VZ
46{
47public:
b3208e11
VZ
48 wxRendererGeneric();
49
9c7f49f5
VZ
50 virtual void DrawHeaderButton(wxWindow *win,
51 wxDC& dc,
52 const wxRect& rect,
53 int flags = 0);
54
9c7f49f5
VZ
55 virtual void DrawTreeItemButton(wxWindow *win,
56 wxDC& dc,
57 const wxRect& rect,
58 int flags = 0);
b3208e11
VZ
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,
62dc9cb4
VZ
67 wxCoord position,
68 wxOrientation orient);
b3208e11
VZ
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;
9c7f49f5
VZ
85};
86
87// ============================================================================
b3208e11 88// wxRendererGeneric implementation
9c7f49f5
VZ
89// ============================================================================
90
91// ----------------------------------------------------------------------------
92// wxRendererGeneric creation
93// ----------------------------------------------------------------------------
94
95/* static */
38c4cb6a 96wxRendererNative& wxRendererNative::GetGeneric()
9c7f49f5
VZ
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 */
9d999619 107wxRendererNative& wxRendererNative::Get()
9c7f49f5
VZ
108{
109 return GetGeneric();
110}
111
112#endif // platforms using their own renderers
113
b3208e11
VZ
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
9c7f49f5 122// ----------------------------------------------------------------------------
b3208e11
VZ
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
9c7f49f5
VZ
150// ----------------------------------------------------------------------------
151
152void
2eb10e2a 153wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win),
9c7f49f5
VZ
154 wxDC& dc,
155 const wxRect& rect,
2eb10e2a 156 int WXUNUSED(flags))
9c7f49f5 157{
38c4cb6a
VZ
158 const int CORNER = 1;
159
160 const wxCoord x = rect.x,
161 y = rect.y,
162 w = rect.width,
163 h = rect.height;
9c7f49f5 164
b3208e11 165 dc.SetBrush(*wxTRANSPARENT_BRUSH);
9c7f49f5 166
b3208e11 167 dc.SetPen(m_penBlack);
38c4cb6a
VZ
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)
9c7f49f5 170
b3208e11 171 dc.SetPen(m_penDarkGrey);
38c4cb6a
VZ
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)
9c7f49f5 174
b3208e11 175 dc.SetPen(m_penHighlight);
38c4cb6a
VZ
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 );
9c7f49f5
VZ
180}
181
182// draw the plus or minus sign
183void
2eb10e2a 184wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
9c7f49f5
VZ
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);
e8448b79 200 if ( !(flags & wxCONTROL_EXPANDED) )
9c7f49f5
VZ
201 {
202 // turn "-" into "+"
203 dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3);
204 }
205}
206
b3208e11
VZ
207// ----------------------------------------------------------------------------
208// sash drawing
209// ----------------------------------------------------------------------------
210
211wxPoint
52c14774 212wxRendererGeneric::GetSplitterSashAndBorder(const wxWindow *win)
b3208e11
VZ
213{
214 // see below
52c14774 215 return win->HasFlag(wxSP_3D) ? wxPoint(7, 2) : wxPoint(3, 0);
b3208e11
VZ
216}
217
218void
52c14774 219wxRendererGeneric::DrawSplitterBorder(wxWindow *win,
b3208e11
VZ
220 wxDC& dc,
221 const wxRect& rectOrig)
222{
52c14774
VZ
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 }
b3208e11
VZ
229}
230
231void
52c14774 232wxRendererGeneric::DrawSplitterSash(wxWindow *win,
62dc9cb4
VZ
233 wxDC& dcReal,
234 const wxSize& sizeReal,
235 wxCoord position,
236 wxOrientation orient)
b3208e11 237{
62dc9cb4
VZ
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
52c14774 244 // we draw a Win32-like grey sash with possible 3D border here:
b3208e11
VZ
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
52c14774
VZ
259 //
260 // only the middle 3 columns are drawn unless wxSP_3D is specified
b3208e11
VZ
261
262 const wxCoord h = size.y;
263
264 // from left to right
52c14774
VZ
265 if ( win->HasFlag(wxSP_3D) )
266 {
267 dc.SetPen(m_penLightGrey);
268 dc.DrawLine(position, 1, position, h - 1);
b3208e11 269
52c14774
VZ
270 dc.SetPen(m_penHighlight);
271 dc.DrawLine(position + 1, 0, position + 1, h);
272 }
b3208e11
VZ
273
274 dc.SetPen(*wxTRANSPARENT_PEN);
275 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
276 dc.DrawRectangle(position + 2, 0, 3, h);
277
52c14774
VZ
278 if ( win->HasFlag(wxSP_3D) )
279 {
280 dc.SetPen(m_penDarkGrey);
281 dc.DrawLine(position + 5, 0, position + 5, h);
b3208e11 282
52c14774
VZ
283 dc.SetPen(m_penBlack);
284 dc.DrawLine(position + 6, 1, position + 6, h - 1);
285 }
b3208e11 286}
9c7f49f5 287