]> git.saurik.com Git - wxWidgets.git/blame - src/generic/renderg.cpp
added renderer.h/.cpp
[wxWidgets.git] / src / generic / renderg.cpp
CommitLineData
9c7f49f5
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: generic/renderg.cpp
3// Purpose: generic implementation of wxRendererBase (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/renderer.h"
32
33// ----------------------------------------------------------------------------
34// wxRendererGeneric: our wxRendererBase implementation
35// ----------------------------------------------------------------------------
36
37class WXDLLEXPORT wxRendererGeneric : public wxRendererBase
38{
39public:
40 // draw the header control button (used by wxListCtrl)
41 virtual void DrawHeaderButton(wxWindow *win,
42 wxDC& dc,
43 const wxRect& rect,
44 int flags = 0);
45
46 // draw the expanded/collapsed icon for a tree control item
47 virtual void DrawTreeItemButton(wxWindow *win,
48 wxDC& dc,
49 const wxRect& rect,
50 int flags = 0);
51};
52
53// ============================================================================
54// implementation
55// ============================================================================
56
57// ----------------------------------------------------------------------------
58// wxRendererGeneric creation
59// ----------------------------------------------------------------------------
60
61/* static */
62wxRendererNative *wxRendererGeneric::GetGeneric()
63{
64 static wxRendererGeneric s_rendererGeneric;
65
66 return s_rendererGeneric;
67}
68
69// some platforms have their own renderers
70#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXGTK__)
71
72/* static */
73wxRendererNative& wxRendererGeneric::Get()
74{
75 return GetGeneric();
76}
77
78#endif // platforms using their own renderers
79
80// ----------------------------------------------------------------------------
81// wxRendererGeneric drawing functions
82// ----------------------------------------------------------------------------
83
84void
85wxRendererGeneric::DrawHeaderButton(wxWindow *win,
86 wxDC& dc,
87 const wxRect& rect,
88 int flags)
89{
90 const int m_corner = 1;
91
92 dc->SetBrush( *wxTRANSPARENT_BRUSH );
93
94 dc->SetPen( *wxBLACK_PEN );
95 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
96 dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
97
98 wxPen pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
99
100 dc->SetPen( pen );
101 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
102 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
103
104 dc->SetPen( *wxWHITE_PEN );
105 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
106 dc->DrawRectangle( x, y, 1, h ); // left (outer)
107 dc->DrawLine( x, y+h-1, x+1, y+h-1 );
108 dc->DrawLine( x+w-1, y, x+w-1, y+1 );
109}
110
111// draw the plus or minus sign
112void
113wxRendererGeneric::DrawTreeItemButton(wxWindow *win,
114 wxDC& dc,
115 const wxRect& rect,
116 int flags)
117{
118 // white background
119 dc.SetPen(*wxGREY_PEN);
120 dc.SetBrush(*wxWHITE_BRUSH);
121 dc.DrawRectangle(rect.Deflate(1, 2));
122
123 // black lines
124 const wxCoord xMiddle = rect.x + rect.width/2;
125 const wxCoord yMiddle = rect.y + rect.height/2;
126
127 dc.SetPen(*wxBLACK_PEN);
128 dc.DrawLine(xMiddle - 2, yMiddle, xMiddle + 3, yMiddle);
129 if ( !item->IsExpanded() )
130 {
131 // turn "-" into "+"
132 dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3);
133 }
134}
135
136