]> git.saurik.com Git - wxWidgets.git/blob - src/mac/renderer.cpp
Fixed DDE memory leaks.
[wxWidgets.git] / src / mac / renderer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/renderer.cpp
3 // Purpose: implementation of wxRendererNative for Mac
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 #include "wx/dc.h"
30 #include "wx/bitmap.h"
31 #include "wx/settings.h"
32 #endif //WX_PRECOMP
33
34 #include "wx/renderer.h"
35
36 // ----------------------------------------------------------------------------
37 // wxRendererMac: our wxRendererNative implementation
38 // ----------------------------------------------------------------------------
39
40 class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
41 {
42 public:
43 // draw the header control button (used by wxListCtrl)
44 virtual void DrawHeaderButton(wxWindow *win,
45 wxDC& dc,
46 const wxRect& rect,
47 int flags = 0);
48
49 // draw the expanded/collapsed icon for a tree control item
50 virtual void DrawTreeItemButton(wxWindow *win,
51 wxDC& dc,
52 const wxRect& rect,
53 int flags = 0);
54
55 // draw a (vertical) sash
56 virtual void DrawSplitterSash(wxWindow *win,
57 wxDC& dc,
58 const wxSize& size,
59 wxCoord position,
60 wxOrientation orient,
61 int flags = 0);
62
63 private:
64 // the tree buttons
65 wxBitmap m_bmpTreeExpanded,
66 m_bmpTreeCollapsed;
67 };
68
69 // ----------------------------------------------------------------------------
70 // Aqua arrows
71 // ----------------------------------------------------------------------------
72
73 /* XPM */
74 static const char *aqua_arrow_right_xpm[] = {
75 /* columns rows colors chars-per-pixel */
76 "13 11 4 1",
77 " c None",
78 "b c #C0C0C0",
79 "c c #707070",
80 "d c #A0A0A0",
81 /* pixels */
82 " b ",
83 " ddb ",
84 " cccdb ",
85 " cccccd ",
86 " ccccccdb ",
87 " ccccccccd",
88 " ccccccdb ",
89 " cccccb ",
90 " cccdb ",
91 " ddb ",
92 " b "
93 };
94
95 /* XPM */
96 static const char *aqua_arrow_down_xpm[] = {
97 /* columns rows colors chars-per-pixel */
98 "13 11 4 1",
99 " c None",
100 "b c #C0C0C0",
101 "c c #707070",
102 "d c #A0A0A0",
103 /* pixels */
104 " ",
105 " ",
106 " bdcccccccdb ",
107 " dcccccccd ",
108 " bcccccccb ",
109 " dcccccd ",
110 " bcccccb ",
111 " bcccd ",
112 " dcd ",
113 " bcb ",
114 " d "
115 };
116
117 // ============================================================================
118 // implementation
119 // ============================================================================
120
121 /* static */
122 wxRendererNative& wxRendererNative::GetDefault()
123 {
124 static wxRendererMac s_rendererMac;
125
126 return s_rendererMac;
127 }
128
129 void
130 wxRendererMac::DrawHeaderButton(wxWindow *win,
131 wxDC& dc,
132 const wxRect& rect,
133 int WXUNUSED(flags))
134 {
135 const int CORNER = 1;
136
137 const wxCoord x = rect.x,
138 y = rect.y,
139 w = rect.width,
140 h = rect.height;
141
142 dc.SetBrush( *wxTRANSPARENT_BRUSH );
143
144 dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
145 dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
146 dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
147
148 wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
149
150 dc.SetPen( pen );
151 dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
152 dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
153
154 dc.SetPen( *wxWHITE_PEN );
155 dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
156 dc.DrawRectangle( x, y, 1, h ); // left (outer)
157 dc.DrawLine( x, y+h-1, x+1, y+h-1 );
158 dc.DrawLine( x+w-1, y, x+w-1, y+1 );
159 }
160
161 void
162 wxRendererMac::DrawTreeItemButton(wxWindow *win,
163 wxDC& dc,
164 const wxRect& rect,
165 int flags)
166 {
167 // init the buttons on demand
168 if ( !m_bmpTreeExpanded.Ok() )
169 {
170 m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
171 m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
172 }
173
174 // draw them
175
176 // VZ: this is the old code from treectlg.cpp which apparently doesn't work
177 // but I kept it here just in case it is needed -- if not, please
178 // remove it
179 #if 0 // def __WXMAC__
180 wxMacPortSetter helper(&dc) ;
181 wxMacWindowClipper clipper(this) ;
182 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
183
184 int loc_x = x - 5 ;
185 int loc_y = y_mid - 6 ;
186 MacWindowToRootWindow( & loc_x , & loc_y ) ;
187 Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
188 ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
189 kThemeAdornmentNone };
190 DrawThemeButton( &bounds, kThemeDisclosureButton ,
191 &info , NULL , NULL , NULL , NULL ) ;
192 #else // 1
193 dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded
194 : m_bmpTreeCollapsed,
195 rect.x, rect.y, true /* use mask */);
196 #endif // 0/1
197 }
198
199 void
200 wxRendererMac::DrawSplitterSash(wxWindow *win,
201 wxDC& dc,
202 const wxSize& size,
203 wxCoord position,
204 wxOrientation orient,
205 int WXUNUSED(flags))
206 {
207 // VZ: we have to somehow determine if we're drawing a normal sash or
208 // a brushed metal one as they look quite differently... this is
209 // completely bogus anyhow, of course (TODO)
210
211 dc.SetPen(*wxLIGHT_GREY_PEN);
212 dc.SetBrush(*wxWHITE_BRUSH);
213 if ( orient == wxVERTICAL )
214 dc.DrawRectangle(position, 0, 7, size.y);
215 else
216 dc.DrawRectangle(0, position, size.x, 7);
217 }
218