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