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"
36 #include "wx/renderer.h"
38 // ----------------------------------------------------------------------------
39 // wxRendererGeneric: our wxRendererNative implementation
40 // ----------------------------------------------------------------------------
42 class WXDLLEXPORT wxRendererGeneric
: public wxRendererNative
47 virtual void DrawHeaderButton(wxWindow
*win
,
52 virtual void DrawTreeItemButton(wxWindow
*win
,
57 virtual void DrawSplitterBorder(wxWindow
*win
,
61 virtual void DrawSplitterSash(wxWindow
*win
,
67 virtual wxPoint
GetSplitterSashAndBorder(const wxWindow
*win
);
71 // draw the rectange using the first pen for the left and top sides and
72 // the second one for the bottom and right ones
73 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
74 const wxPen
& pen1
, const wxPen
& pen2
);
83 // ============================================================================
84 // wxRendererGeneric implementation
85 // ============================================================================
87 // ----------------------------------------------------------------------------
88 // wxRendererGeneric creation
89 // ----------------------------------------------------------------------------
92 wxRendererNative
& wxRendererNative::GetGeneric()
94 static wxRendererGeneric s_rendererGeneric
;
96 return s_rendererGeneric
;
99 // some platforms have their own renderers
100 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__)
103 wxRendererNative
& wxRendererNative::Get()
108 #endif // platforms using their own renderers
110 wxRendererGeneric::wxRendererGeneric()
111 : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
)),
112 m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
)),
113 m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)),
114 m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT
))
118 // ----------------------------------------------------------------------------
119 // wxRendererGeneric helpers
120 // ----------------------------------------------------------------------------
123 wxRendererGeneric::DrawShadedRect(wxDC
& dc
,
128 // draw the rectangle
130 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
131 rect
->GetLeft(), rect
->GetBottom());
132 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
133 rect
->GetRight(), rect
->GetTop());
135 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
136 rect
->GetRight(), rect
->GetBottom());
137 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
138 rect
->GetRight() + 1, rect
->GetBottom());
144 // ----------------------------------------------------------------------------
145 // tree/list ctrl drawing
146 // ----------------------------------------------------------------------------
149 wxRendererGeneric::DrawHeaderButton(wxWindow
* WXUNUSED(win
),
154 const int CORNER
= 1;
156 const wxCoord x
= rect
.x
,
161 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
163 dc
.SetPen(m_penBlack
);
164 dc
.DrawLine( x
+w
-CORNER
+1, y
, x
+w
, y
+h
); // right (outer)
165 dc
.DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
167 dc
.SetPen(m_penDarkGrey
);
168 dc
.DrawLine( x
+w
-CORNER
, y
, x
+w
-1, y
+h
); // right (inner)
169 dc
.DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
171 dc
.SetPen(m_penHighlight
);
172 dc
.DrawRectangle( x
, y
, w
-CORNER
+1, 1 ); // top (outer)
173 dc
.DrawRectangle( x
, y
, 1, h
); // left (outer)
174 dc
.DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
175 dc
.DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
178 // draw the plus or minus sign
180 wxRendererGeneric::DrawTreeItemButton(wxWindow
* WXUNUSED(win
),
186 dc
.SetPen(*wxGREY_PEN
);
187 dc
.SetBrush(*wxWHITE_BRUSH
);
188 dc
.DrawRectangle(rect
.Deflate(1, 2));
191 const wxCoord xMiddle
= rect
.x
+ rect
.width
/2;
192 const wxCoord yMiddle
= rect
.y
+ rect
.height
/2;
194 dc
.SetPen(*wxBLACK_PEN
);
195 dc
.DrawLine(xMiddle
- 2, yMiddle
, xMiddle
+ 3, yMiddle
);
196 if ( !(flags
& wxCONTROL_EXPANDED
) )
199 dc
.DrawLine(xMiddle
, yMiddle
- 2, xMiddle
, yMiddle
+ 3);
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
208 wxRendererGeneric::GetSplitterSashAndBorder(const wxWindow
* WXUNUSED(win
))
211 return wxPoint(7, 2);
215 wxRendererGeneric::DrawSplitterBorder(wxWindow
* WXUNUSED(win
),
217 const wxRect
& rectOrig
)
219 wxRect rect
= rectOrig
;
220 DrawShadedRect(dc
, &rect
, m_penDarkGrey
, m_penHighlight
);
221 DrawShadedRect(dc
, &rect
, m_penBlack
, m_penLightGrey
);
225 wxRendererGeneric::DrawSplitterSash(wxWindow
* WXUNUSED(win
),
230 // we draw a Win32-like sash here:
232 // ---- this is position
237 // GWGGGDB where G is light grey (face)
238 // GWGGGDB W white (light)
239 // GWGGGDB D dark grey (shadow)
240 // GWGGGDB B black (dark shadow)
242 // GWGGGDB and lower letters are our border (already drawn)
246 const wxCoord h
= size
.y
;
248 // from left to right
249 dc
.SetPen(m_penLightGrey
);
250 dc
.DrawLine(position
, 1, position
, h
- 1);
252 dc
.SetPen(m_penHighlight
);
253 dc
.DrawLine(position
+ 1, 0, position
+ 1, h
);
255 dc
.SetPen(*wxTRANSPARENT_PEN
);
256 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)));
257 dc
.DrawRectangle(position
+ 2, 0, 3, h
);
259 dc
.SetPen(m_penDarkGrey
);
260 dc
.DrawLine(position
+ 5, 0, position
+ 5, h
);
262 dc
.SetPen(m_penBlack
);
263 dc
.DrawLine(position
+ 6, 1, position
+ 6, h
- 1);