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/renderer.h"
39 // ----------------------------------------------------------------------------
40 // wxRendererGeneric: our wxRendererNative implementation
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxRendererGeneric
: public wxRendererNative
48 virtual void DrawHeaderButton(wxWindow
*win
,
53 virtual void DrawTreeItemButton(wxWindow
*win
,
58 virtual void DrawSplitterBorder(wxWindow
*win
,
62 virtual void DrawSplitterSash(wxWindow
*win
,
68 virtual wxPoint
GetSplitterSashAndBorder(const wxWindow
*win
);
72 // draw the rectange using the first pen for the left and top sides and
73 // the second one for the bottom and right ones
74 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
75 const wxPen
& pen1
, const wxPen
& pen2
);
84 // ============================================================================
85 // wxRendererGeneric implementation
86 // ============================================================================
88 // ----------------------------------------------------------------------------
89 // wxRendererGeneric creation
90 // ----------------------------------------------------------------------------
93 wxRendererNative
& wxRendererNative::GetGeneric()
95 static wxRendererGeneric s_rendererGeneric
;
97 return s_rendererGeneric
;
100 // some platforms have their own renderers
101 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__)
104 wxRendererNative
& wxRendererNative::Get()
109 #endif // platforms using their own renderers
111 wxRendererGeneric::wxRendererGeneric()
112 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
)),
113 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)),
114 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)),
115 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
))
119 // ----------------------------------------------------------------------------
120 // wxRendererGeneric helpers
121 // ----------------------------------------------------------------------------
124 wxRendererGeneric::DrawShadedRect(wxDC
& dc
,
129 // draw the rectangle
131 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
132 rect
->GetLeft(), rect
->GetBottom());
133 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
134 rect
->GetRight(), rect
->GetTop());
136 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
137 rect
->GetRight(), rect
->GetBottom());
138 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
139 rect
->GetRight() + 1, rect
->GetBottom());
145 // ----------------------------------------------------------------------------
146 // tree/list ctrl drawing
147 // ----------------------------------------------------------------------------
150 wxRendererGeneric::DrawHeaderButton(wxWindow
* WXUNUSED(win
),
155 const int CORNER
= 1;
157 const wxCoord x
= rect
.x
,
162 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
164 dc
.SetPen(m_penBlack
);
165 dc
.DrawLine( x
+w
-CORNER
+1, y
, x
+w
, y
+h
); // right (outer)
166 dc
.DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
168 dc
.SetPen(m_penDarkGrey
);
169 dc
.DrawLine( x
+w
-CORNER
, y
, x
+w
-1, y
+h
); // right (inner)
170 dc
.DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
172 dc
.SetPen(m_penHighlight
);
173 dc
.DrawRectangle( x
, y
, w
-CORNER
+1, 1 ); // top (outer)
174 dc
.DrawRectangle( x
, y
, 1, h
); // left (outer)
175 dc
.DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
176 dc
.DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
179 // draw the plus or minus sign
181 wxRendererGeneric::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
187 dc
.SetPen(*wxGREY_PEN
);
188 dc
.SetBrush(*wxWHITE_BRUSH
);
189 dc
.DrawRectangle(rect
.Deflate(1, 2));
192 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
193 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
195 dc
.SetPen(*wxBLACK_PEN
);
196 dc
.DrawLine(xMiddle
- 2, yMiddle
, xMiddle
+ 3, yMiddle
);
197 if ( !(flags
& wxCONTROL_EXPANDED
) )
200 dc
.DrawLine(xMiddle
, yMiddle
- 2, xMiddle
, yMiddle
+ 3);
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
209 wxRendererGeneric::GetSplitterSashAndBorder(const wxWindow
*win
)
212 return win
->HasFlag(wxSP_3D
) ? wxPoint(7, 2) : wxPoint(3, 0);
216 wxRendererGeneric::DrawSplitterBorder(wxWindow
*win
,
218 const wxRect
& rectOrig
)
220 if ( win
->HasFlag(wxSP_3D
) )
222 wxRect rect
= rectOrig
;
223 DrawShadedRect(dc
, &rect
, m_penDarkGrey
, m_penHighlight
);
224 DrawShadedRect(dc
, &rect
, m_penBlack
, m_penLightGrey
);
229 wxRendererGeneric::DrawSplitterSash(wxWindow
*win
,
234 // we draw a Win32-like grey sash with possible 3D border here:
236 // ---- this is position
241 // GWGGGDB where G is light grey (face)
242 // GWGGGDB W white (light)
243 // GWGGGDB D dark grey (shadow)
244 // GWGGGDB B black (dark shadow)
246 // GWGGGDB and lower letters are our border (already drawn)
250 // only the middle 3 columns are drawn unless wxSP_3D is specified
252 const wxCoord h
= size
.y
;
254 // from left to right
255 if ( win
->HasFlag(wxSP_3D
) )
257 dc
.SetPen(m_penLightGrey
);
258 dc
.DrawLine(position
, 1, position
, h
- 1);
260 dc
.SetPen(m_penHighlight
);
261 dc
.DrawLine(position
+ 1, 0, position
+ 1, h
);
264 dc
.SetPen(*wxTRANSPARENT_PEN
);
265 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)));
266 dc
.DrawRectangle(position
+ 2, 0, 3, h
);
268 if ( win
->HasFlag(wxSP_3D
) )
270 dc
.SetPen(m_penDarkGrey
);
271 dc
.DrawLine(position
+ 5, 0, position
+ 5, h
);
273 dc
.SetPen(m_penBlack
);
274 dc
.DrawLine(position
+ 6, 1, position
+ 6, h
- 1);