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
,
72 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
74 virtual wxRendererVersion
GetVersion() const
76 return wxRendererVersion(wxRendererVersion::Current_Version
,
77 wxRendererVersion::Current_Age
);
81 // Cleanup by deleting standard renderer
82 static void Cleanup();
84 // Get the generic object
85 static wxRendererGeneric
* DoGetGeneric();
88 // draw the rectange using the first pen for the left and top sides and
89 // the second one for the bottom and right ones
90 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
91 const wxPen
& pen1
, const wxPen
& pen2
);
99 static wxRendererGeneric
* sm_rendererGeneric
;
102 // ============================================================================
103 // wxRendererGeneric implementation
104 // ============================================================================
106 // Get the generic object
107 wxRendererGeneric
* wxRendererGeneric::DoGetGeneric()
109 if (!sm_rendererGeneric
)
110 sm_rendererGeneric
= new wxRendererGeneric
;
111 return sm_rendererGeneric
;
114 // ----------------------------------------------------------------------------
115 // wxRendererGeneric creation
116 // ----------------------------------------------------------------------------
119 wxRendererNative
& wxRendererNative::GetGeneric()
121 return * wxRendererGeneric::DoGetGeneric();
124 void wxRendererGeneric::Cleanup()
126 if (sm_rendererGeneric
)
127 delete sm_rendererGeneric
;
129 sm_rendererGeneric
= NULL
;
132 wxRendererGeneric
* wxRendererGeneric::sm_rendererGeneric
= NULL
;
134 wxRendererGeneric::wxRendererGeneric()
135 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
)),
136 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)),
137 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)),
138 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
))
142 // ----------------------------------------------------------------------------
143 // wxRendererGeneric helpers
144 // ----------------------------------------------------------------------------
147 wxRendererGeneric::DrawShadedRect(wxDC
& dc
,
152 // draw the rectangle
154 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
155 rect
->GetLeft(), rect
->GetBottom());
156 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
157 rect
->GetRight(), rect
->GetTop());
159 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
160 rect
->GetRight(), rect
->GetBottom());
161 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
162 rect
->GetRight() + 1, rect
->GetBottom());
168 // ----------------------------------------------------------------------------
169 // tree/list ctrl drawing
170 // ----------------------------------------------------------------------------
173 wxRendererGeneric::DrawHeaderButton(wxWindow
* WXUNUSED(win
),
178 const int CORNER
= 1;
180 const wxCoord x
= rect
.x
,
185 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
187 dc
.SetPen(m_penBlack
);
188 dc
.DrawLine( x
+w
-CORNER
+1, y
, x
+w
, y
+h
); // right (outer)
189 dc
.DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
191 dc
.SetPen(m_penDarkGrey
);
192 dc
.DrawLine( x
+w
-CORNER
, y
, x
+w
-1, y
+h
); // right (inner)
193 dc
.DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
195 dc
.SetPen(m_penHighlight
);
196 dc
.DrawRectangle( x
, y
, w
-CORNER
+1, 1 ); // top (outer)
197 dc
.DrawRectangle( x
, y
, 1, h
); // left (outer)
198 dc
.DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
199 dc
.DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
202 // draw the plus or minus sign
204 wxRendererGeneric::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
210 dc
.SetPen(*wxGREY_PEN
);
211 dc
.SetBrush(*wxWHITE_BRUSH
);
212 dc
.DrawRectangle(rect
);
215 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
216 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
218 // half of the length of the horz lines in "-" and "+"
219 const wxCoord halfWidth
= rect
.width
/2 - 2;
220 dc
.SetPen(*wxBLACK_PEN
);
221 dc
.DrawLine(xMiddle
- halfWidth
, yMiddle
,
222 xMiddle
+ halfWidth
+ 1, yMiddle
);
224 if ( !(flags
& wxCONTROL_EXPANDED
) )
227 const wxCoord halfHeight
= rect
.height
/2 - 2;
228 dc
.DrawLine(xMiddle
, yMiddle
- halfHeight
,
229 xMiddle
, yMiddle
+ halfHeight
+ 1);
233 // ----------------------------------------------------------------------------
235 // ----------------------------------------------------------------------------
237 wxSplitterRenderParams
238 wxRendererGeneric::GetSplitterParams(const wxWindow
*win
)
244 if ( win
->HasFlag(wxSP_3DSASH
) )
246 else if ( win
->HasFlag(wxSP_NOSASH
) )
251 if ( win
->HasFlag(wxSP_3DBORDER
) )
256 return wxSplitterRenderParams(sashWidth
, border
, false);
260 wxRendererGeneric::DrawSplitterBorder(wxWindow
*win
,
262 const wxRect
& rectOrig
,
265 if ( win
->HasFlag(wxSP_3DBORDER
) )
267 wxRect rect
= rectOrig
;
268 DrawShadedRect(dc
, &rect
, m_penDarkGrey
, m_penHighlight
);
269 DrawShadedRect(dc
, &rect
, m_penBlack
, m_penLightGrey
);
274 wxRendererGeneric::DrawSplitterSash(wxWindow
*win
,
276 const wxSize
& sizeReal
,
278 wxOrientation orient
,
281 // to avoid duplicating the same code for horizontal and vertical sashes,
282 // simply mirror the DC instead if needed (i.e. if horz splitter)
283 wxMirrorDC
dc(dcReal
, orient
!= wxVERTICAL
);
284 wxSize size
= dc
.Reflect(sizeReal
);
287 // we draw a Win32-like grey sash with possible 3D border here:
289 // ---- this is position
294 // GWGGGDB where G is light grey (face)
295 // GWGGGDB W white (light)
296 // GWGGGDB D dark grey (shadow)
297 // GWGGGDB B black (dark shadow)
299 // GWGGGDB and lower letters are our border (already drawn)
303 // only the middle 3 columns are drawn unless wxSP_3D is specified
305 const wxCoord h
= size
.y
;
308 // If we're drawing the border, draw the sash 3d lines shorter
309 if ( win
->HasFlag(wxSP_3DBORDER
) )
314 dc
.SetPen(*wxTRANSPARENT_PEN
);
315 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)));
317 if ( win
->HasFlag(wxSP_3DSASH
) )
320 dc
.DrawRectangle(position
+ 2, 0, 3, h
);
322 dc
.SetPen(m_penLightGrey
);
323 dc
.DrawLine(position
, offset
, position
, h
- offset
);
325 dc
.SetPen(m_penHighlight
);
326 dc
.DrawLine(position
+ 1, 0, position
+ 1, h
);
328 dc
.SetPen(m_penDarkGrey
);
329 dc
.DrawLine(position
+ 5, 0, position
+ 5, h
);
331 dc
.SetPen(m_penBlack
);
332 dc
.DrawLine(position
+ 6, offset
, position
+ 6, h
- offset
);
337 dc
.DrawRectangle(position
, 0, 3, h
);
341 // A module to allow cleanup of generic renderer.
342 class wxGenericRendererModule
: public wxModule
344 DECLARE_DYNAMIC_CLASS(wxGenericRendererModule
)
346 wxGenericRendererModule() {}
347 bool OnInit() { return true; };
348 void OnExit() { wxRendererGeneric::Cleanup(); };
351 IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule
, wxModule
)