]> git.saurik.com Git - wxWidgets.git/blame - src/generic/renderg.cpp
some compilers (Watcom) don't like it if wxBase library PCH file contains
[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,
af99040c
VZ
62 const wxRect& rect,
63 int flags = 0);
b3208e11
VZ
64
65 virtual void DrawSplitterSash(wxWindow *win,
66 wxDC& dc,
67 const wxSize& size,
62dc9cb4 68 wxCoord position,
af99040c
VZ
69 wxOrientation orient,
70 int flags = 0);
b3208e11
VZ
71
72
af99040c 73 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
b3208e11
VZ
74
75
76protected:
77 // draw the rectange using the first pen for the left and top sides and
78 // the second one for the bottom and right ones
79 void DrawShadedRect(wxDC& dc, wxRect *rect,
80 const wxPen& pen1, const wxPen& pen2);
81
82 // the standard pens
83 wxPen m_penBlack,
84 m_penDarkGrey,
85 m_penLightGrey,
86 m_penHighlight;
9c7f49f5
VZ
87};
88
89// ============================================================================
b3208e11 90// wxRendererGeneric implementation
9c7f49f5
VZ
91// ============================================================================
92
93// ----------------------------------------------------------------------------
94// wxRendererGeneric creation
95// ----------------------------------------------------------------------------
96
97/* static */
38c4cb6a 98wxRendererNative& wxRendererNative::GetGeneric()
9c7f49f5
VZ
99{
100 static wxRendererGeneric s_rendererGeneric;
101
102 return s_rendererGeneric;
103}
104
b3208e11
VZ
105wxRendererGeneric::wxRendererGeneric()
106 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)),
107 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)),
108 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)),
109 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT))
110{
111}
112
9c7f49f5 113// ----------------------------------------------------------------------------
b3208e11
VZ
114// wxRendererGeneric helpers
115// ----------------------------------------------------------------------------
116
117void
118wxRendererGeneric::DrawShadedRect(wxDC& dc,
119 wxRect *rect,
120 const wxPen& pen1,
121 const wxPen& pen2)
122{
123 // draw the rectangle
124 dc.SetPen(pen1);
125 dc.DrawLine(rect->GetLeft(), rect->GetTop(),
126 rect->GetLeft(), rect->GetBottom());
127 dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(),
128 rect->GetRight(), rect->GetTop());
129 dc.SetPen(pen2);
130 dc.DrawLine(rect->GetRight(), rect->GetTop(),
131 rect->GetRight(), rect->GetBottom());
132 dc.DrawLine(rect->GetLeft(), rect->GetBottom(),
133 rect->GetRight() + 1, rect->GetBottom());
134
135 // adjust the rect
136 rect->Inflate(-1);
137}
138
139// ----------------------------------------------------------------------------
140// tree/list ctrl drawing
9c7f49f5
VZ
141// ----------------------------------------------------------------------------
142
143void
2eb10e2a 144wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win),
9c7f49f5
VZ
145 wxDC& dc,
146 const wxRect& rect,
2eb10e2a 147 int WXUNUSED(flags))
9c7f49f5 148{
38c4cb6a
VZ
149 const int CORNER = 1;
150
151 const wxCoord x = rect.x,
152 y = rect.y,
153 w = rect.width,
154 h = rect.height;
9c7f49f5 155
b3208e11 156 dc.SetBrush(*wxTRANSPARENT_BRUSH);
9c7f49f5 157
b3208e11 158 dc.SetPen(m_penBlack);
38c4cb6a
VZ
159 dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
160 dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
9c7f49f5 161
b3208e11 162 dc.SetPen(m_penDarkGrey);
38c4cb6a
VZ
163 dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
164 dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
9c7f49f5 165
b3208e11 166 dc.SetPen(m_penHighlight);
38c4cb6a
VZ
167 dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
168 dc.DrawRectangle( x, y, 1, h ); // left (outer)
169 dc.DrawLine( x, y+h-1, x+1, y+h-1 );
170 dc.DrawLine( x+w-1, y, x+w-1, y+1 );
9c7f49f5
VZ
171}
172
173// draw the plus or minus sign
174void
2eb10e2a 175wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
9c7f49f5
VZ
176 wxDC& dc,
177 const wxRect& rect,
178 int flags)
179{
180 // white background
181 dc.SetPen(*wxGREY_PEN);
182 dc.SetBrush(*wxWHITE_BRUSH);
183 dc.DrawRectangle(rect.Deflate(1, 2));
184
185 // black lines
186 const wxCoord xMiddle = rect.x + rect.width/2;
187 const wxCoord yMiddle = rect.y + rect.height/2;
188
189 dc.SetPen(*wxBLACK_PEN);
190 dc.DrawLine(xMiddle - 2, yMiddle, xMiddle + 3, yMiddle);
e8448b79 191 if ( !(flags & wxCONTROL_EXPANDED) )
9c7f49f5
VZ
192 {
193 // turn "-" into "+"
194 dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3);
195 }
196}
197
b3208e11
VZ
198// ----------------------------------------------------------------------------
199// sash drawing
200// ----------------------------------------------------------------------------
201
af99040c
VZ
202wxSplitterRenderParams
203wxRendererGeneric::GetSplitterParams(const wxWindow *win)
b3208e11
VZ
204{
205 // see below
af99040c
VZ
206 wxCoord sashWidth,
207 border;
208
209 if ( win->HasFlag(wxSP_3D) )
210 {
211 sashWidth = 7;
28f9eac4 212 border = 2;
af99040c
VZ
213 }
214 else // no 3D effect
215 {
28f9eac4 216 sashWidth = 3;
af99040c
VZ
217 border = 0;
218 }
219
220 return wxSplitterRenderParams(sashWidth, border, false);
b3208e11
VZ
221}
222
223void
52c14774 224wxRendererGeneric::DrawSplitterBorder(wxWindow *win,
b3208e11 225 wxDC& dc,
af99040c
VZ
226 const wxRect& rectOrig,
227 int WXUNUSED(falgs))
b3208e11 228{
52c14774
VZ
229 if ( win->HasFlag(wxSP_3D) )
230 {
231 wxRect rect = rectOrig;
232 DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
233 DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
234 }
b3208e11
VZ
235}
236
237void
52c14774 238wxRendererGeneric::DrawSplitterSash(wxWindow *win,
62dc9cb4
VZ
239 wxDC& dcReal,
240 const wxSize& sizeReal,
241 wxCoord position,
af99040c
VZ
242 wxOrientation orient,
243 int WXUNUSED(flags))
b3208e11 244{
62dc9cb4
VZ
245 // to avoid duplicating the same code for horizontal and vertical sashes,
246 // simply mirror the DC instead if needed (i.e. if horz splitter)
247 wxMirrorDC dc(dcReal, orient != wxVERTICAL);
248 wxSize size = dc.Reflect(sizeReal);
249
250
52c14774 251 // we draw a Win32-like grey sash with possible 3D border here:
b3208e11
VZ
252 //
253 // ---- this is position
254 // /
255 // v
256 // dWGGGDd
257 // GWGGGDB
258 // GWGGGDB where G is light grey (face)
259 // GWGGGDB W white (light)
260 // GWGGGDB D dark grey (shadow)
261 // GWGGGDB B black (dark shadow)
262 // GWGGGDB
263 // GWGGGDB and lower letters are our border (already drawn)
264 // GWGGGDB
265 // wWGGGDd
52c14774
VZ
266 //
267 // only the middle 3 columns are drawn unless wxSP_3D is specified
b3208e11
VZ
268
269 const wxCoord h = size.y;
8aa528db
JS
270 wxCoord offset = 0;
271
272 // If we're not drawing the border, droppings will
273 // be left unless we make the sash shorter
274 if ( !win->HasFlag(wxSP_3DBORDER) )
275 {
276 offset = 3;
277 }
b3208e11
VZ
278
279 // from left to right
52c14774
VZ
280 if ( win->HasFlag(wxSP_3D) )
281 {
282 dc.SetPen(m_penLightGrey);
8aa528db 283 dc.DrawLine(position, 1 + offset, position, h - 1 - offset);
b3208e11 284
52c14774 285 dc.SetPen(m_penHighlight);
8aa528db 286 dc.DrawLine(position + 1, offset, position + 1, h - offset);
52c14774 287 }
b3208e11
VZ
288
289 dc.SetPen(*wxTRANSPARENT_PEN);
290 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
8aa528db 291 dc.DrawRectangle(position + 2, offset, 3, h - 2*offset);
b3208e11 292
52c14774
VZ
293 if ( win->HasFlag(wxSP_3D) )
294 {
295 dc.SetPen(m_penDarkGrey);
8aa528db 296 dc.DrawLine(position + 5, offset, position + 5, h - offset);
b3208e11 297
52c14774 298 dc.SetPen(m_penBlack);
8aa528db 299 dc.DrawLine(position + 6, offset, position + 6, h - 1 - offset);
52c14774 300 }
b3208e11 301}
9c7f49f5 302