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
,
65 virtual void DrawSplitterSash(wxWindow
*win
,
73 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
77 // draw the rectange using the first pen for the left and top sides and
78 // the second one for the bottom and right ones
79 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
80 const wxPen
& pen1
, const wxPen
& pen2
);
89 // ============================================================================
90 // wxRendererGeneric implementation
91 // ============================================================================
93 // ----------------------------------------------------------------------------
94 // wxRendererGeneric creation
95 // ----------------------------------------------------------------------------
98 wxRendererNative
& wxRendererNative::GetGeneric()
100 static wxRendererGeneric s_rendererGeneric
;
102 return s_rendererGeneric
;
105 wxRendererGeneric::wxRendererGeneric()
106 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
)),
107 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)),
108 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)),
109 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
))
113 // ----------------------------------------------------------------------------
114 // wxRendererGeneric helpers
115 // ----------------------------------------------------------------------------
118 wxRendererGeneric::DrawShadedRect(wxDC
& dc
,
123 // draw the rectangle
125 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
126 rect
->GetLeft(), rect
->GetBottom());
127 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
128 rect
->GetRight(), rect
->GetTop());
130 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
131 rect
->GetRight(), rect
->GetBottom());
132 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
133 rect
->GetRight() + 1, rect
->GetBottom());
139 // ----------------------------------------------------------------------------
140 // tree/list ctrl drawing
141 // ----------------------------------------------------------------------------
144 wxRendererGeneric::DrawHeaderButton(wxWindow
* WXUNUSED(win
),
149 const int CORNER
= 1;
151 const wxCoord x
= rect
.x
,
156 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
158 dc
.SetPen(m_penBlack
);
159 dc
.DrawLine( x
+w
-CORNER
+1, y
, x
+w
, y
+h
); // right (outer)
160 dc
.DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
162 dc
.SetPen(m_penDarkGrey
);
163 dc
.DrawLine( x
+w
-CORNER
, y
, x
+w
-1, y
+h
); // right (inner)
164 dc
.DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
166 dc
.SetPen(m_penHighlight
);
167 dc
.DrawRectangle( x
, y
, w
-CORNER
+1, 1 ); // top (outer)
168 dc
.DrawRectangle( x
, y
, 1, h
); // left (outer)
169 dc
.DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
170 dc
.DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
173 // draw the plus or minus sign
175 wxRendererGeneric::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
181 dc
.SetPen(*wxGREY_PEN
);
182 dc
.SetBrush(*wxWHITE_BRUSH
);
183 dc
.DrawRectangle(rect
.Deflate(1, 2));
186 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
187 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
189 dc
.SetPen(*wxBLACK_PEN
);
190 dc
.DrawLine(xMiddle
- 2, yMiddle
, xMiddle
+ 3, yMiddle
);
191 if ( !(flags
& wxCONTROL_EXPANDED
) )
194 dc
.DrawLine(xMiddle
, yMiddle
- 2, xMiddle
, yMiddle
+ 3);
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 wxSplitterRenderParams
203 wxRendererGeneric::GetSplitterParams(const wxWindow
*win
)
209 if ( win
->HasFlag(wxSP_3D
) )
220 return wxSplitterRenderParams(sashWidth
, border
, false);
224 wxRendererGeneric::DrawSplitterBorder(wxWindow
*win
,
226 const wxRect
& rectOrig
,
229 if ( win
->HasFlag(wxSP_3D
) )
231 wxRect rect
= rectOrig
;
232 DrawShadedRect(dc
, &rect
, m_penDarkGrey
, m_penHighlight
);
233 DrawShadedRect(dc
, &rect
, m_penBlack
, m_penLightGrey
);
238 wxRendererGeneric::DrawSplitterSash(wxWindow
*win
,
240 const wxSize
& sizeReal
,
242 wxOrientation orient
,
245 // to avoid duplicating the same code for horizontal and vertical sashes,
246 // simply mirror the DC instead if needed (i.e. if horz splitter)
247 wxMirrorDC
dc(dcReal
, orient
!= wxVERTICAL
);
248 wxSize size
= dc
.Reflect(sizeReal
);
251 // we draw a Win32-like grey sash with possible 3D border here:
253 // ---- this is position
258 // GWGGGDB where G is light grey (face)
259 // GWGGGDB W white (light)
260 // GWGGGDB D dark grey (shadow)
261 // GWGGGDB B black (dark shadow)
263 // GWGGGDB and lower letters are our border (already drawn)
267 // only the middle 3 columns are drawn unless wxSP_3D is specified
269 const wxCoord h
= size
.y
;
272 // If we're not drawing the border, droppings will
273 // be left unless we make the sash shorter
274 if ( !win
->HasFlag(wxSP_3DBORDER
) )
279 // from left to right
280 if ( win
->HasFlag(wxSP_3D
) )
282 dc
.SetPen(m_penLightGrey
);
283 dc
.DrawLine(position
, 1 + offset
, position
, h
- 1 - offset
);
285 dc
.SetPen(m_penHighlight
);
286 dc
.DrawLine(position
+ 1, offset
, position
+ 1, h
- offset
);
289 dc
.SetPen(*wxTRANSPARENT_PEN
);
290 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)));
291 dc
.DrawRectangle(position
+ 2, offset
, 3, h
- 2*offset
);
293 if ( win
->HasFlag(wxSP_3D
) )
295 dc
.SetPen(m_penDarkGrey
);
296 dc
.DrawLine(position
+ 5, offset
, position
+ 5, h
- offset
);
298 dc
.SetPen(m_penBlack
);
299 dc
.DrawLine(position
+ 6, offset
, position
+ 6, h
- 1 - offset
);