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"
37 #include "wx/dcmirror.h"
39 #include "wx/renderer.h"
41 // ----------------------------------------------------------------------------
42 // wxRendererGeneric: our wxRendererNative implementation
43 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxRendererGeneric
: public wxRendererNative
50 virtual void DrawHeaderButton(wxWindow
*win
,
55 virtual void DrawTreeItemButton(wxWindow
*win
,
60 virtual void DrawSplitterBorder(wxWindow
*win
,
64 virtual void DrawSplitterSash(wxWindow
*win
,
68 wxOrientation orient
);
71 virtual wxPoint
GetSplitterSashAndBorder(const wxWindow
*win
);
75 // draw the rectange using the first pen for the left and top sides and
76 // the second one for the bottom and right ones
77 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
78 const wxPen
& pen1
, const wxPen
& pen2
);
87 // ============================================================================
88 // wxRendererGeneric implementation
89 // ============================================================================
91 // ----------------------------------------------------------------------------
92 // wxRendererGeneric creation
93 // ----------------------------------------------------------------------------
96 wxRendererNative
& wxRendererNative::GetGeneric()
98 static wxRendererGeneric s_rendererGeneric
;
100 return s_rendererGeneric
;
103 // some platforms have their own renderers
104 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__)
107 wxRendererNative
& wxRendererNative::Get()
112 #endif // platforms using their own renderers
114 wxRendererGeneric::wxRendererGeneric()
115 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
)),
116 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)),
117 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)),
118 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
))
122 // ----------------------------------------------------------------------------
123 // wxRendererGeneric helpers
124 // ----------------------------------------------------------------------------
127 wxRendererGeneric::DrawShadedRect(wxDC
& dc
,
132 // draw the rectangle
134 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
135 rect
->GetLeft(), rect
->GetBottom());
136 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
137 rect
->GetRight(), rect
->GetTop());
139 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
140 rect
->GetRight(), rect
->GetBottom());
141 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
142 rect
->GetRight() + 1, rect
->GetBottom());
148 // ----------------------------------------------------------------------------
149 // tree/list ctrl drawing
150 // ----------------------------------------------------------------------------
153 wxRendererGeneric::DrawHeaderButton(wxWindow
* WXUNUSED(win
),
158 const int CORNER
= 1;
160 const wxCoord x
= rect
.x
,
165 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
167 dc
.SetPen(m_penBlack
);
168 dc
.DrawLine( x
+w
-CORNER
+1, y
, x
+w
, y
+h
); // right (outer)
169 dc
.DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
171 dc
.SetPen(m_penDarkGrey
);
172 dc
.DrawLine( x
+w
-CORNER
, y
, x
+w
-1, y
+h
); // right (inner)
173 dc
.DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
175 dc
.SetPen(m_penHighlight
);
176 dc
.DrawRectangle( x
, y
, w
-CORNER
+1, 1 ); // top (outer)
177 dc
.DrawRectangle( x
, y
, 1, h
); // left (outer)
178 dc
.DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
179 dc
.DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
182 // draw the plus or minus sign
184 wxRendererGeneric::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
190 dc
.SetPen(*wxGREY_PEN
);
191 dc
.SetBrush(*wxWHITE_BRUSH
);
192 dc
.DrawRectangle(rect
.Deflate(1, 2));
195 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
196 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
198 dc
.SetPen(*wxBLACK_PEN
);
199 dc
.DrawLine(xMiddle
- 2, yMiddle
, xMiddle
+ 3, yMiddle
);
200 if ( !(flags
& wxCONTROL_EXPANDED
) )
203 dc
.DrawLine(xMiddle
, yMiddle
- 2, xMiddle
, yMiddle
+ 3);
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
212 wxRendererGeneric::GetSplitterSashAndBorder(const wxWindow
*win
)
215 return win
->HasFlag(wxSP_3D
) ? wxPoint(7, 2) : wxPoint(3, 0);
219 wxRendererGeneric::DrawSplitterBorder(wxWindow
*win
,
221 const wxRect
& rectOrig
)
223 if ( win
->HasFlag(wxSP_3D
) )
225 wxRect rect
= rectOrig
;
226 DrawShadedRect(dc
, &rect
, m_penDarkGrey
, m_penHighlight
);
227 DrawShadedRect(dc
, &rect
, m_penBlack
, m_penLightGrey
);
232 wxRendererGeneric::DrawSplitterSash(wxWindow
*win
,
234 const wxSize
& sizeReal
,
236 wxOrientation orient
)
238 // to avoid duplicating the same code for horizontal and vertical sashes,
239 // simply mirror the DC instead if needed (i.e. if horz splitter)
240 wxMirrorDC
dc(dcReal
, orient
!= wxVERTICAL
);
241 wxSize size
= dc
.Reflect(sizeReal
);
244 // we draw a Win32-like grey sash with possible 3D border here:
246 // ---- this is position
251 // GWGGGDB where G is light grey (face)
252 // GWGGGDB W white (light)
253 // GWGGGDB D dark grey (shadow)
254 // GWGGGDB B black (dark shadow)
256 // GWGGGDB and lower letters are our border (already drawn)
260 // only the middle 3 columns are drawn unless wxSP_3D is specified
262 const wxCoord h
= size
.y
;
264 // from left to right
265 if ( win
->HasFlag(wxSP_3D
) )
267 dc
.SetPen(m_penLightGrey
);
268 dc
.DrawLine(position
, 1, position
, h
- 1);
270 dc
.SetPen(m_penHighlight
);
271 dc
.DrawLine(position
+ 1, 0, position
+ 1, h
);
274 dc
.SetPen(*wxTRANSPARENT_PEN
);
275 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)));
276 dc
.DrawRectangle(position
+ 2, 0, 3, h
);
278 if ( win
->HasFlag(wxSP_3D
) )
280 dc
.SetPen(m_penDarkGrey
);
281 dc
.DrawLine(position
+ 5, 0, position
+ 5, h
);
283 dc
.SetPen(m_penBlack
);
284 dc
.DrawLine(position
+ 6, 1, position
+ 6, h
- 1);