]> git.saurik.com Git - wxWidgets.git/blob - src/generic/renderg.cpp
restore some of the styles; added support for splitters without border/sash to generi...
[wxWidgets.git] / src / generic / renderg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/renderg.cpp
3 // Purpose: generic implementation of wxRendererNative (for any platform)
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 20.07.2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #endif //WX_PRECOMP
30
31 #include "wx/gdicmn.h"
32 #include "wx/dc.h"
33
34 #include "wx/settings.h"
35 #include "wx/splitter.h"
36
37 #include "wx/renderer.h"
38
39 // ----------------------------------------------------------------------------
40 // wxRendererGeneric: our wxRendererNative implementation
41 // ----------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxRendererGeneric : public wxRendererNative
44 {
45 public:
46 wxRendererGeneric();
47
48 virtual void DrawHeaderButton(wxWindow *win,
49 wxDC& dc,
50 const wxRect& rect,
51 int flags = 0);
52
53 virtual void DrawTreeItemButton(wxWindow *win,
54 wxDC& dc,
55 const wxRect& rect,
56 int flags = 0);
57
58 virtual void DrawSplitterBorder(wxWindow *win,
59 wxDC& dc,
60 const wxRect& rect);
61
62 virtual void DrawSplitterSash(wxWindow *win,
63 wxDC& dc,
64 const wxSize& size,
65 wxCoord position);
66
67
68 virtual wxPoint GetSplitterSashAndBorder(const wxWindow *win);
69
70
71 protected:
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);
76
77 // the standard pens
78 wxPen m_penBlack,
79 m_penDarkGrey,
80 m_penLightGrey,
81 m_penHighlight;
82 };
83
84 // ============================================================================
85 // wxRendererGeneric implementation
86 // ============================================================================
87
88 // ----------------------------------------------------------------------------
89 // wxRendererGeneric creation
90 // ----------------------------------------------------------------------------
91
92 /* static */
93 wxRendererNative& wxRendererNative::GetGeneric()
94 {
95 static wxRendererGeneric s_rendererGeneric;
96
97 return s_rendererGeneric;
98 }
99
100 // some platforms have their own renderers
101 #if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__)
102
103 /* static */
104 wxRendererNative& wxRendererNative::Get()
105 {
106 return GetGeneric();
107 }
108
109 #endif // platforms using their own renderers
110
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))
116 {
117 }
118
119 // ----------------------------------------------------------------------------
120 // wxRendererGeneric helpers
121 // ----------------------------------------------------------------------------
122
123 void
124 wxRendererGeneric::DrawShadedRect(wxDC& dc,
125 wxRect *rect,
126 const wxPen& pen1,
127 const wxPen& pen2)
128 {
129 // draw the rectangle
130 dc.SetPen(pen1);
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());
135 dc.SetPen(pen2);
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());
140
141 // adjust the rect
142 rect->Inflate(-1);
143 }
144
145 // ----------------------------------------------------------------------------
146 // tree/list ctrl drawing
147 // ----------------------------------------------------------------------------
148
149 void
150 wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win),
151 wxDC& dc,
152 const wxRect& rect,
153 int WXUNUSED(flags))
154 {
155 const int CORNER = 1;
156
157 const wxCoord x = rect.x,
158 y = rect.y,
159 w = rect.width,
160 h = rect.height;
161
162 dc.SetBrush(*wxTRANSPARENT_BRUSH);
163
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)
167
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)
171
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 );
177 }
178
179 // draw the plus or minus sign
180 void
181 wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
182 wxDC& dc,
183 const wxRect& rect,
184 int flags)
185 {
186 // white background
187 dc.SetPen(*wxGREY_PEN);
188 dc.SetBrush(*wxWHITE_BRUSH);
189 dc.DrawRectangle(rect.Deflate(1, 2));
190
191 // black lines
192 const wxCoord xMiddle = rect.x + rect.width/2;
193 const wxCoord yMiddle = rect.y + rect.height/2;
194
195 dc.SetPen(*wxBLACK_PEN);
196 dc.DrawLine(xMiddle - 2, yMiddle, xMiddle + 3, yMiddle);
197 if ( !(flags & wxCONTROL_EXPANDED) )
198 {
199 // turn "-" into "+"
200 dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3);
201 }
202 }
203
204 // ----------------------------------------------------------------------------
205 // sash drawing
206 // ----------------------------------------------------------------------------
207
208 wxPoint
209 wxRendererGeneric::GetSplitterSashAndBorder(const wxWindow *win)
210 {
211 // see below
212 return win->HasFlag(wxSP_3D) ? wxPoint(7, 2) : wxPoint(3, 0);
213 }
214
215 void
216 wxRendererGeneric::DrawSplitterBorder(wxWindow *win,
217 wxDC& dc,
218 const wxRect& rectOrig)
219 {
220 if ( win->HasFlag(wxSP_3D) )
221 {
222 wxRect rect = rectOrig;
223 DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
224 DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
225 }
226 }
227
228 void
229 wxRendererGeneric::DrawSplitterSash(wxWindow *win,
230 wxDC& dc,
231 const wxSize& size,
232 wxCoord position)
233 {
234 // we draw a Win32-like grey sash with possible 3D border here:
235 //
236 // ---- this is position
237 // /
238 // v
239 // dWGGGDd
240 // GWGGGDB
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)
245 // GWGGGDB
246 // GWGGGDB and lower letters are our border (already drawn)
247 // GWGGGDB
248 // wWGGGDd
249 //
250 // only the middle 3 columns are drawn unless wxSP_3D is specified
251
252 const wxCoord h = size.y;
253
254 // from left to right
255 if ( win->HasFlag(wxSP_3D) )
256 {
257 dc.SetPen(m_penLightGrey);
258 dc.DrawLine(position, 1, position, h - 1);
259
260 dc.SetPen(m_penHighlight);
261 dc.DrawLine(position + 1, 0, position + 1, h);
262 }
263
264 dc.SetPen(*wxTRANSPARENT_PEN);
265 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
266 dc.DrawRectangle(position + 2, 0, 3, h);
267
268 if ( win->HasFlag(wxSP_3D) )
269 {
270 dc.SetPen(m_penDarkGrey);
271 dc.DrawLine(position + 5, 0, position + 5, h);
272
273 dc.SetPen(m_penBlack);
274 dc.DrawLine(position + 6, 1, position + 6, h - 1);
275 }
276 }
277