1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/renderg.cpp
3 // Purpose: generic implementation of wxRendererNative (for any platform)
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
31 #include "wx/gdicmn.h"
34 #include "wx/settings.h"
35 #include "wx/splitter.h"
36 #include "wx/dcmirror.h"
37 #include "wx/module.h"
38 #include "wx/renderer.h"
40 // ----------------------------------------------------------------------------
41 // wxRendererGeneric: our wxRendererNative implementation
42 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxRendererGeneric
: public wxRendererNative
49 virtual void DrawHeaderButton(wxWindow
*win
,
54 virtual void DrawTreeItemButton(wxWindow
*win
,
59 virtual void DrawSplitterBorder(wxWindow
*win
,
64 virtual void DrawSplitterSash(wxWindow
*win
,
71 virtual void DrawComboBoxDropButton(wxWindow
*win
,
77 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
79 virtual wxRendererVersion
GetVersion() const
81 return wxRendererVersion(wxRendererVersion::Current_Version
,
82 wxRendererVersion::Current_Age
);
86 // Cleanup by deleting standard renderer
87 static void Cleanup();
89 // Get the generic object
90 static wxRendererGeneric
* DoGetGeneric();
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
);
104 static wxRendererGeneric
* sm_rendererGeneric
;
107 // ============================================================================
108 // wxRendererGeneric implementation
109 // ============================================================================
111 // Get the generic object
112 wxRendererGeneric
* wxRendererGeneric::DoGetGeneric()
114 if (!sm_rendererGeneric
)
115 sm_rendererGeneric
= new wxRendererGeneric
;
116 return sm_rendererGeneric
;
119 // ----------------------------------------------------------------------------
120 // wxRendererGeneric creation
121 // ----------------------------------------------------------------------------
124 wxRendererNative
& wxRendererNative::GetGeneric()
126 return * wxRendererGeneric::DoGetGeneric();
129 void wxRendererGeneric::Cleanup()
131 if (sm_rendererGeneric
)
132 delete sm_rendererGeneric
;
134 sm_rendererGeneric
= NULL
;
137 wxRendererGeneric
* wxRendererGeneric::sm_rendererGeneric
= NULL
;
139 wxRendererGeneric::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
))
147 // ----------------------------------------------------------------------------
148 // wxRendererGeneric helpers
149 // ----------------------------------------------------------------------------
152 wxRendererGeneric::DrawShadedRect(wxDC
& dc
,
157 // draw the rectangle
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());
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());
173 // ----------------------------------------------------------------------------
174 // tree/list ctrl drawing
175 // ----------------------------------------------------------------------------
178 wxRendererGeneric::DrawHeaderButton(wxWindow
* WXUNUSED(win
),
183 const int CORNER
= 1;
185 const wxCoord x
= rect
.x
,
190 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
192 dc
.SetPen(m_penBlack
);
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)
196 dc
.SetPen(m_penDarkGrey
);
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)
200 dc
.SetPen(m_penHighlight
);
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 );
207 // draw the plus or minus sign
209 wxRendererGeneric::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
215 dc
.SetPen(*wxGREY_PEN
);
216 dc
.SetBrush(*wxWHITE_BRUSH
);
217 dc
.DrawRectangle(rect
);
220 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
221 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
223 // half of the length of the horz lines in "-" and "+"
224 const wxCoord halfWidth
= rect
.width
/2 - 2;
225 dc
.SetPen(*wxBLACK_PEN
);
226 dc
.DrawLine(xMiddle
- halfWidth
, yMiddle
,
227 xMiddle
+ halfWidth
+ 1, yMiddle
);
229 if ( !(flags
& wxCONTROL_EXPANDED
) )
232 const wxCoord halfHeight
= rect
.height
/2 - 2;
233 dc
.DrawLine(xMiddle
, yMiddle
- halfHeight
,
234 xMiddle
, yMiddle
+ halfHeight
+ 1);
238 // ----------------------------------------------------------------------------
240 // ----------------------------------------------------------------------------
242 wxSplitterRenderParams
243 wxRendererGeneric::GetSplitterParams(const wxWindow
*win
)
249 if ( win
->HasFlag(wxSP_3DSASH
) )
251 else if ( win
->HasFlag(wxSP_NOSASH
) )
256 if ( win
->HasFlag(wxSP_3DBORDER
) )
261 return wxSplitterRenderParams(sashWidth
, border
, false);
265 wxRendererGeneric::DrawSplitterBorder(wxWindow
*win
,
267 const wxRect
& rectOrig
,
270 if ( win
->HasFlag(wxSP_3DBORDER
) )
272 wxRect rect
= rectOrig
;
273 DrawShadedRect(dc
, &rect
, m_penDarkGrey
, m_penHighlight
);
274 DrawShadedRect(dc
, &rect
, m_penBlack
, m_penLightGrey
);
279 wxRendererGeneric::DrawSplitterSash(wxWindow
*win
,
281 const wxSize
& sizeReal
,
283 wxOrientation orient
,
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
);
292 // we draw a Win32-like grey sash with possible 3D border here:
294 // ---- this is position
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)
304 // GWGGGDB and lower letters are our border (already drawn)
308 // only the middle 3 columns are drawn unless wxSP_3D is specified
310 const wxCoord h
= size
.y
;
313 // If we're drawing the border, draw the sash 3d lines shorter
314 if ( win
->HasFlag(wxSP_3DBORDER
) )
319 dc
.SetPen(*wxTRANSPARENT_PEN
);
320 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)));
322 if ( win
->HasFlag(wxSP_3DSASH
) )
325 dc
.DrawRectangle(position
+ 2, 0, 3, h
);
327 dc
.SetPen(m_penLightGrey
);
328 dc
.DrawLine(position
, offset
, position
, h
- offset
);
330 dc
.SetPen(m_penHighlight
);
331 dc
.DrawLine(position
+ 1, 0, position
+ 1, h
);
333 dc
.SetPen(m_penDarkGrey
);
334 dc
.DrawLine(position
+ 5, 0, position
+ 5, h
);
336 dc
.SetPen(m_penBlack
);
337 dc
.DrawLine(position
+ 6, offset
, position
+ 6, h
- offset
);
342 dc
.DrawRectangle(position
, 0, 3, h
);
347 wxRendererGeneric::DrawComboBoxDropButton(wxWindow
*win
,
352 dc
.SetBrush(wxBrush(win
->GetBackgroundColour()));
353 dc
.SetPen(wxPen(win
->GetBackgroundColour()));
354 dc
.DrawRectangle(rect
);
359 wxPoint(rect
.width
, 0),
360 wxPoint(rect
.width
/2, rect
.height
- 2)
362 dc
.SetBrush(wxBrush(win
->GetForegroundColour()));
363 dc
.SetPen(wxPen(win
->GetForegroundColour()));
364 dc
.DrawPolygon(WXSIZEOF(pt
), pt
, rect
.x
, rect
.y
);
368 // ----------------------------------------------------------------------------
369 // A module to allow cleanup of generic renderer.
370 // ----------------------------------------------------------------------------
372 class wxGenericRendererModule
: public wxModule
374 DECLARE_DYNAMIC_CLASS(wxGenericRendererModule
)
376 wxGenericRendererModule() {}
377 bool OnInit() { return true; };
378 void OnExit() { wxRendererGeneric::Cleanup(); };
381 IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule
, wxModule
)