]> git.saurik.com Git - wxWidgets.git/blame - src/generic/renderg.cpp
"As is" means the current size (or position) not the best size.
[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>
0a53b9b8 9// License: wxWindows license
9c7f49f5
VZ
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"
62dc9cb4 36#include "wx/dcmirror.h"
0872a451 37#include "wx/module.h"
9c7f49f5
VZ
38#include "wx/renderer.h"
39
40// ----------------------------------------------------------------------------
38c4cb6a 41// wxRendererGeneric: our wxRendererNative implementation
9c7f49f5
VZ
42// ----------------------------------------------------------------------------
43
38c4cb6a 44class WXDLLEXPORT wxRendererGeneric : public wxRendererNative
9c7f49f5
VZ
45{
46public:
b3208e11
VZ
47 wxRendererGeneric();
48
9c7f49f5
VZ
49 virtual void DrawHeaderButton(wxWindow *win,
50 wxDC& dc,
51 const wxRect& rect,
52 int flags = 0);
53
9c7f49f5
VZ
54 virtual void DrawTreeItemButton(wxWindow *win,
55 wxDC& dc,
56 const wxRect& rect,
57 int flags = 0);
b3208e11
VZ
58
59 virtual void DrawSplitterBorder(wxWindow *win,
60 wxDC& dc,
af99040c
VZ
61 const wxRect& rect,
62 int flags = 0);
b3208e11
VZ
63
64 virtual void DrawSplitterSash(wxWindow *win,
65 wxDC& dc,
66 const wxSize& size,
62dc9cb4 67 wxCoord position,
af99040c
VZ
68 wxOrientation orient,
69 int flags = 0);
b3208e11 70
f33cef9f
VZ
71 virtual void DrawComboBoxDropButton(wxWindow *win,
72 wxDC& dc,
73 const wxRect& rect,
74 int flags = 0);
75
b3208e11 76
af99040c 77 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
b3208e11 78
04857cb7
VZ
79 virtual wxRendererVersion GetVersion() const
80 {
81 return wxRendererVersion(wxRendererVersion::Current_Version,
82 wxRendererVersion::Current_Age);
83 }
84
85
0872a451
JS
86 // Cleanup by deleting standard renderer
87 static void Cleanup();
88
89 // Get the generic object
90 static wxRendererGeneric* DoGetGeneric();
b3208e11
VZ
91
92protected:
93 // draw the rectange using the first pen for the left and top sides and
94 // the second one for the bottom and right ones
95 void DrawShadedRect(wxDC& dc, wxRect *rect,
96 const wxPen& pen1, const wxPen& pen2);
97
98 // the standard pens
99 wxPen m_penBlack,
100 m_penDarkGrey,
101 m_penLightGrey,
102 m_penHighlight;
0872a451
JS
103
104 static wxRendererGeneric* sm_rendererGeneric;
9c7f49f5
VZ
105};
106
107// ============================================================================
b3208e11 108// wxRendererGeneric implementation
9c7f49f5
VZ
109// ============================================================================
110
0872a451
JS
111// Get the generic object
112wxRendererGeneric* wxRendererGeneric::DoGetGeneric()
113{
114 if (!sm_rendererGeneric)
115 sm_rendererGeneric = new wxRendererGeneric;
116 return sm_rendererGeneric;
117}
118
9c7f49f5
VZ
119// ----------------------------------------------------------------------------
120// wxRendererGeneric creation
121// ----------------------------------------------------------------------------
122
123/* static */
38c4cb6a 124wxRendererNative& wxRendererNative::GetGeneric()
9c7f49f5 125{
0872a451
JS
126 return * wxRendererGeneric::DoGetGeneric();
127}
9c7f49f5 128
0872a451
JS
129void wxRendererGeneric::Cleanup()
130{
131 if (sm_rendererGeneric)
132 delete sm_rendererGeneric;
ca65c044 133
0872a451 134 sm_rendererGeneric = NULL;
9c7f49f5
VZ
135}
136
0872a451
JS
137wxRendererGeneric* wxRendererGeneric::sm_rendererGeneric = NULL;
138
b3208e11
VZ
139wxRendererGeneric::wxRendererGeneric()
140 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)),
141 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)),
142 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)),
143 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT))
144{
145}
146
9c7f49f5 147// ----------------------------------------------------------------------------
b3208e11
VZ
148// wxRendererGeneric helpers
149// ----------------------------------------------------------------------------
150
151void
152wxRendererGeneric::DrawShadedRect(wxDC& dc,
153 wxRect *rect,
154 const wxPen& pen1,
155 const wxPen& pen2)
156{
157 // draw the rectangle
158 dc.SetPen(pen1);
159 dc.DrawLine(rect->GetLeft(), rect->GetTop(),
160 rect->GetLeft(), rect->GetBottom());
161 dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(),
162 rect->GetRight(), rect->GetTop());
163 dc.SetPen(pen2);
164 dc.DrawLine(rect->GetRight(), rect->GetTop(),
165 rect->GetRight(), rect->GetBottom());
166 dc.DrawLine(rect->GetLeft(), rect->GetBottom(),
167 rect->GetRight() + 1, rect->GetBottom());
168
169 // adjust the rect
170 rect->Inflate(-1);
171}
172
173// ----------------------------------------------------------------------------
174// tree/list ctrl drawing
9c7f49f5
VZ
175// ----------------------------------------------------------------------------
176
177void
2eb10e2a 178wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win),
9c7f49f5
VZ
179 wxDC& dc,
180 const wxRect& rect,
2eb10e2a 181 int WXUNUSED(flags))
9c7f49f5 182{
38c4cb6a
VZ
183 const int CORNER = 1;
184
185 const wxCoord x = rect.x,
186 y = rect.y,
187 w = rect.width,
188 h = rect.height;
9c7f49f5 189
b3208e11 190 dc.SetBrush(*wxTRANSPARENT_BRUSH);
9c7f49f5 191
b3208e11 192 dc.SetPen(m_penBlack);
38c4cb6a
VZ
193 dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
194 dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
9c7f49f5 195
b3208e11 196 dc.SetPen(m_penDarkGrey);
38c4cb6a
VZ
197 dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
198 dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
9c7f49f5 199
b3208e11 200 dc.SetPen(m_penHighlight);
38c4cb6a
VZ
201 dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
202 dc.DrawRectangle( x, y, 1, h ); // left (outer)
203 dc.DrawLine( x, y+h-1, x+1, y+h-1 );
204 dc.DrawLine( x+w-1, y, x+w-1, y+1 );
9c7f49f5
VZ
205}
206
207// draw the plus or minus sign
208void
2eb10e2a 209wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
9c7f49f5
VZ
210 wxDC& dc,
211 const wxRect& rect,
212 int flags)
213{
214 // white background
215 dc.SetPen(*wxGREY_PEN);
216 dc.SetBrush(*wxWHITE_BRUSH);
0e7761fa 217 dc.DrawRectangle(rect);
9c7f49f5
VZ
218
219 // black lines
220 const wxCoord xMiddle = rect.x + rect.width/2;
221 const wxCoord yMiddle = rect.y + rect.height/2;
222
0e7761fa
VZ
223 // half of the length of the horz lines in "-" and "+"
224 const wxCoord halfWidth = rect.width/2 - 2;
9c7f49f5 225 dc.SetPen(*wxBLACK_PEN);
429ef4bc
VZ
226 dc.DrawLine(xMiddle - halfWidth, yMiddle,
227 xMiddle + halfWidth + 1, yMiddle);
228
e8448b79 229 if ( !(flags & wxCONTROL_EXPANDED) )
9c7f49f5
VZ
230 {
231 // turn "-" into "+"
0e7761fa
VZ
232 const wxCoord halfHeight = rect.height/2 - 2;
233 dc.DrawLine(xMiddle, yMiddle - halfHeight,
429ef4bc 234 xMiddle, yMiddle + halfHeight + 1);
9c7f49f5
VZ
235 }
236}
237
b3208e11
VZ
238// ----------------------------------------------------------------------------
239// sash drawing
240// ----------------------------------------------------------------------------
241
af99040c
VZ
242wxSplitterRenderParams
243wxRendererGeneric::GetSplitterParams(const wxWindow *win)
b3208e11
VZ
244{
245 // see below
af99040c
VZ
246 wxCoord sashWidth,
247 border;
248
4666bb5f 249 if ( win->HasFlag(wxSP_3DSASH) )
af99040c 250 sashWidth = 7;
4666bb5f
JS
251 else if ( win->HasFlag(wxSP_NOSASH) )
252 sashWidth = 0;
af99040c 253 else // no 3D effect
28f9eac4 254 sashWidth = 3;
4666bb5f
JS
255
256 if ( win->HasFlag(wxSP_3DBORDER) )
257 border = 2;
258 else // no 3D effect
af99040c 259 border = 0;
af99040c
VZ
260
261 return wxSplitterRenderParams(sashWidth, border, false);
b3208e11
VZ
262}
263
264void
52c14774 265wxRendererGeneric::DrawSplitterBorder(wxWindow *win,
b3208e11 266 wxDC& dc,
af99040c
VZ
267 const wxRect& rectOrig,
268 int WXUNUSED(falgs))
b3208e11 269{
4666bb5f 270 if ( win->HasFlag(wxSP_3DBORDER) )
52c14774
VZ
271 {
272 wxRect rect = rectOrig;
273 DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
274 DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
275 }
b3208e11
VZ
276}
277
278void
52c14774 279wxRendererGeneric::DrawSplitterSash(wxWindow *win,
62dc9cb4
VZ
280 wxDC& dcReal,
281 const wxSize& sizeReal,
282 wxCoord position,
af99040c
VZ
283 wxOrientation orient,
284 int WXUNUSED(flags))
b3208e11 285{
62dc9cb4
VZ
286 // to avoid duplicating the same code for horizontal and vertical sashes,
287 // simply mirror the DC instead if needed (i.e. if horz splitter)
288 wxMirrorDC dc(dcReal, orient != wxVERTICAL);
289 wxSize size = dc.Reflect(sizeReal);
290
291
52c14774 292 // we draw a Win32-like grey sash with possible 3D border here:
b3208e11
VZ
293 //
294 // ---- this is position
295 // /
296 // v
297 // dWGGGDd
298 // GWGGGDB
299 // GWGGGDB where G is light grey (face)
300 // GWGGGDB W white (light)
301 // GWGGGDB D dark grey (shadow)
302 // GWGGGDB B black (dark shadow)
303 // GWGGGDB
304 // GWGGGDB and lower letters are our border (already drawn)
305 // GWGGGDB
306 // wWGGGDd
52c14774
VZ
307 //
308 // only the middle 3 columns are drawn unless wxSP_3D is specified
b3208e11
VZ
309
310 const wxCoord h = size.y;
8aa528db 311 wxCoord offset = 0;
ca65c044 312
4666bb5f
JS
313 // If we're drawing the border, draw the sash 3d lines shorter
314 if ( win->HasFlag(wxSP_3DBORDER) )
8aa528db 315 {
4666bb5f 316 offset = 1;
8aa528db 317 }
b3208e11 318
4666bb5f 319 dc.SetPen(*wxTRANSPARENT_PEN);
ca65c044
WS
320 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
321
4666bb5f 322 if ( win->HasFlag(wxSP_3DSASH) )
52c14774 323 {
4666bb5f
JS
324 // Draw the 3D sash
325 dc.DrawRectangle(position + 2, 0, 3, h);
326
52c14774 327 dc.SetPen(m_penLightGrey);
4666bb5f 328 dc.DrawLine(position, offset, position, h - offset);
b3208e11 329
52c14774 330 dc.SetPen(m_penHighlight);
4666bb5f 331 dc.DrawLine(position + 1, 0, position + 1, h);
b3208e11 332
52c14774 333 dc.SetPen(m_penDarkGrey);
4666bb5f 334 dc.DrawLine(position + 5, 0, position + 5, h);
b3208e11 335
52c14774 336 dc.SetPen(m_penBlack);
4666bb5f
JS
337 dc.DrawLine(position + 6, offset, position + 6, h - offset);
338 }
339 else
340 {
341 // Draw a flat sash
342 dc.DrawRectangle(position, 0, 3, h);
52c14774 343 }
b3208e11 344}
9c7f49f5 345
f33cef9f
VZ
346void
347wxRendererGeneric::DrawComboBoxDropButton(wxWindow *win,
348 wxDC& dc,
349 const wxRect& rect,
350 int WXUNUSED(flags))
351{
352 dc.SetBrush(wxBrush(win->GetBackgroundColour()));
353 dc.SetPen(wxPen(win->GetBackgroundColour()));
e4d192ff 354 dc.DrawRectangle(rect);
f33cef9f 355
106a7999 356 wxPoint pt[] =
f33cef9f 357 {
c47addef 358 wxPoint(0,0),
f33cef9f
VZ
359 wxPoint(rect.width, 0),
360 wxPoint(rect.width/2, rect.height - 2)
361 };
362 dc.SetBrush(wxBrush(win->GetForegroundColour()));
363 dc.SetPen(wxPen(win->GetForegroundColour()));
106a7999 364 dc.DrawPolygon(WXSIZEOF(pt), pt, rect.x, rect.y);
f33cef9f
VZ
365}
366
367
368// ----------------------------------------------------------------------------
0872a451 369// A module to allow cleanup of generic renderer.
f33cef9f
VZ
370// ----------------------------------------------------------------------------
371
0872a451
JS
372class wxGenericRendererModule: public wxModule
373{
374DECLARE_DYNAMIC_CLASS(wxGenericRendererModule)
375public:
376 wxGenericRendererModule() {}
377 bool OnInit() { return true; };
378 void OnExit() { wxRendererGeneric::Cleanup(); };
379};
380
381IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule)
382