1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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
,
76 virtual void DrawDropArrow(wxWindow
*win
,
81 virtual void DrawCheckButton(wxWindow
*win
,
86 virtual void DrawPushButton(wxWindow
*win
,
91 virtual void DrawItemSelectionRect(wxWindow
*win
,
96 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
98 virtual wxRendererVersion
GetVersion() const
100 return wxRendererVersion(wxRendererVersion::Current_Version
,
101 wxRendererVersion::Current_Age
);
105 // Cleanup by deleting standard renderer
106 static void Cleanup();
108 // Get the generic object
109 static wxRendererGeneric
* DoGetGeneric();
112 // draw the rectange using the first pen for the left and top sides and
113 // the second one for the bottom and right ones
114 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
115 const wxPen
& pen1
, const wxPen
& pen2
);
123 static wxRendererGeneric
* sm_rendererGeneric
;
126 // ============================================================================
127 // wxRendererGeneric implementation
128 // ============================================================================
130 // Get the generic object
131 wxRendererGeneric
* wxRendererGeneric::DoGetGeneric()
133 if (!sm_rendererGeneric
)
134 sm_rendererGeneric
= new wxRendererGeneric
;
135 return sm_rendererGeneric
;
138 // ----------------------------------------------------------------------------
139 // wxRendererGeneric creation
140 // ----------------------------------------------------------------------------
143 wxRendererNative
& wxRendererNative::GetGeneric()
145 return * wxRendererGeneric::DoGetGeneric();
148 void wxRendererGeneric::Cleanup()
150 if (sm_rendererGeneric
)
151 delete sm_rendererGeneric
;
153 sm_rendererGeneric
= NULL
;
156 wxRendererGeneric
* wxRendererGeneric::sm_rendererGeneric
= NULL
;
158 wxRendererGeneric::wxRendererGeneric()
159 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
)),
160 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)),
161 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)),
162 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
))
166 // ----------------------------------------------------------------------------
167 // wxRendererGeneric helpers
168 // ----------------------------------------------------------------------------
171 wxRendererGeneric::DrawShadedRect(wxDC
& dc
,
176 // draw the rectangle
178 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
179 rect
->GetLeft(), rect
->GetBottom());
180 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
181 rect
->GetRight(), rect
->GetTop());
183 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
184 rect
->GetRight(), rect
->GetBottom());
185 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
186 rect
->GetRight() + 1, rect
->GetBottom());
192 // ----------------------------------------------------------------------------
193 // tree/list ctrl drawing
194 // ----------------------------------------------------------------------------
197 wxRendererGeneric::DrawHeaderButton(wxWindow
* WXUNUSED(win
),
202 const int CORNER
= 1;
204 const wxCoord x
= rect
.x
,
209 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
211 dc
.SetPen(m_penBlack
);
212 dc
.DrawLine( x
+w
-CORNER
+1, y
, x
+w
, y
+h
); // right (outer)
213 dc
.DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
215 dc
.SetPen(m_penDarkGrey
);
216 dc
.DrawLine( x
+w
-CORNER
, y
, x
+w
-1, y
+h
); // right (inner)
217 dc
.DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
219 dc
.SetPen(m_penHighlight
);
220 dc
.DrawRectangle( x
, y
, w
-CORNER
+1, 1 ); // top (outer)
221 dc
.DrawRectangle( x
, y
, 1, h
); // left (outer)
222 dc
.DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
223 dc
.DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
226 // draw the plus or minus sign
228 wxRendererGeneric::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
234 dc
.SetPen(*wxGREY_PEN
);
235 dc
.SetBrush(*wxWHITE_BRUSH
);
236 dc
.DrawRectangle(rect
);
239 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
240 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
242 // half of the length of the horz lines in "-" and "+"
243 const wxCoord halfWidth
= rect
.width
/2 - 2;
244 dc
.SetPen(*wxBLACK_PEN
);
245 dc
.DrawLine(xMiddle
- halfWidth
, yMiddle
,
246 xMiddle
+ halfWidth
+ 1, yMiddle
);
248 if ( !(flags
& wxCONTROL_EXPANDED
) )
251 const wxCoord halfHeight
= rect
.height
/2 - 2;
252 dc
.DrawLine(xMiddle
, yMiddle
- halfHeight
,
253 xMiddle
, yMiddle
+ halfHeight
+ 1);
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
261 wxSplitterRenderParams
262 wxRendererGeneric::GetSplitterParams(const wxWindow
*win
)
268 if ( win
->HasFlag(wxSP_3DSASH
) )
270 else if ( win
->HasFlag(wxSP_NOSASH
) )
275 if ( win
->HasFlag(wxSP_3DBORDER
) )
280 return wxSplitterRenderParams(sashWidth
, border
, false);
284 wxRendererGeneric::DrawSplitterBorder(wxWindow
*win
,
286 const wxRect
& rectOrig
,
289 if ( win
->HasFlag(wxSP_3DBORDER
) )
291 wxRect rect
= rectOrig
;
292 DrawShadedRect(dc
, &rect
, m_penDarkGrey
, m_penHighlight
);
293 DrawShadedRect(dc
, &rect
, m_penBlack
, m_penLightGrey
);
298 wxRendererGeneric::DrawSplitterSash(wxWindow
*win
,
300 const wxSize
& sizeReal
,
302 wxOrientation orient
,
305 // to avoid duplicating the same code for horizontal and vertical sashes,
306 // simply mirror the DC instead if needed (i.e. if horz splitter)
307 wxMirrorDC
dc(dcReal
, orient
!= wxVERTICAL
);
308 wxSize size
= dc
.Reflect(sizeReal
);
311 // we draw a Win32-like grey sash with possible 3D border here:
313 // ---- this is position
318 // GWGGGDB where G is light grey (face)
319 // GWGGGDB W white (light)
320 // GWGGGDB D dark grey (shadow)
321 // GWGGGDB B black (dark shadow)
323 // GWGGGDB and lower letters are our border (already drawn)
327 // only the middle 3 columns are drawn unless wxSP_3D is specified
329 const wxCoord h
= size
.y
;
332 // If we're drawing the border, draw the sash 3d lines shorter
333 if ( win
->HasFlag(wxSP_3DBORDER
) )
338 dc
.SetPen(*wxTRANSPARENT_PEN
);
339 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)));
341 if ( win
->HasFlag(wxSP_3DSASH
) )
344 dc
.DrawRectangle(position
+ 2, 0, 3, h
);
346 dc
.SetPen(m_penLightGrey
);
347 dc
.DrawLine(position
, offset
, position
, h
- offset
);
349 dc
.SetPen(m_penHighlight
);
350 dc
.DrawLine(position
+ 1, 0, position
+ 1, h
);
352 dc
.SetPen(m_penDarkGrey
);
353 dc
.DrawLine(position
+ 5, 0, position
+ 5, h
);
355 dc
.SetPen(m_penBlack
);
356 dc
.DrawLine(position
+ 6, offset
, position
+ 6, h
- offset
);
361 dc
.DrawRectangle(position
, 0, 3, h
);
365 // ----------------------------------------------------------------------------
367 // ----------------------------------------------------------------------------
370 wxRendererGeneric::DrawComboBoxDropButton(wxWindow
*win
,
375 DrawPushButton(win
,dc
,rect
,flags
);
376 DrawDropArrow(win
,dc
,rect
,flags
);
380 wxRendererGeneric::DrawDropArrow(wxWindow
*win
,
385 // This generic implementation should be good
386 // enough for Windows platforms (including XP).
388 int arrowHalf
= rect
.width
/5;
389 int rectMid
= rect
.width
/ 2;
390 int arrowTopY
= (rect
.height
/2) - (arrowHalf
/2);
392 // This should always result in arrow with odd width.
395 wxPoint(rectMid
- arrowHalf
, arrowTopY
),
396 wxPoint(rectMid
+ arrowHalf
, arrowTopY
),
397 wxPoint(rectMid
, arrowTopY
+ arrowHalf
)
399 dc
.SetBrush(wxBrush(win
->GetForegroundColour()));
400 dc
.SetPen(wxPen(win
->GetForegroundColour()));
401 dc
.DrawPolygon(WXSIZEOF(pt
), pt
, rect
.x
, rect
.y
);
405 wxRendererGeneric::DrawCheckButton(wxWindow
*WXUNUSED(win
),
410 dc
.SetPen(*(flags
& wxCONTROL_DISABLED
? wxGREY_PEN
: wxBLACK_PEN
));
411 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
412 dc
.DrawRectangle(rect
);
414 if ( flags
& wxCONTROL_CHECKED
)
416 dc
.DrawCheckMark(rect
.Deflate(2, 2));
421 wxRendererGeneric::DrawPushButton(wxWindow
*win
,
426 // Don't try anything too fancy. It'll just turn out looking
427 // out-of-place on most platforms.
428 wxColour bgCol
= flags
& wxCONTROL_DISABLED
?
429 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
) :
430 win
->GetBackgroundColour();
431 dc
.SetBrush(wxBrush(bgCol
));
432 dc
.SetPen(wxPen(bgCol
));
433 dc
.DrawRectangle(rect
);
437 wxRendererGeneric::DrawItemSelectionRect(wxWindow
* WXUNUSED(win
),
443 if ( flags
& wxCONTROL_SELECTED
)
445 if ( flags
& wxCONTROL_FOCUSED
)
447 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
451 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
456 brush
= *wxTRANSPARENT_BRUSH
;
460 dc
.SetPen(flags
& wxCONTROL_CURRENT
? *wxBLACK_PEN
: *wxTRANSPARENT_PEN
);
462 dc
.DrawRectangle( rect
);
466 // ----------------------------------------------------------------------------
467 // A module to allow cleanup of generic renderer.
468 // ----------------------------------------------------------------------------
470 class wxGenericRendererModule
: public wxModule
472 DECLARE_DYNAMIC_CLASS(wxGenericRendererModule
)
474 wxGenericRendererModule() {}
475 bool OnInit() { return true; };
476 void OnExit() { wxRendererGeneric::Cleanup(); };
479 IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule
, wxModule
)