]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.cpp | |
3 | // Purpose: wxDC class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dc.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/dc.h" | |
03e11df5 | 17 | #include "wx/app.h" |
2f1ae414 | 18 | #include "wx/mac/uma.h" |
3dec57ad SC |
19 | #include "wx/dcmemory.h" |
20 | #include "wx/region.h" | |
21 | #include "wx/image.h" | |
b1699cd3 | 22 | #include "wx/log.h" |
e9576ca5 | 23 | |
76a5e5d2 | 24 | |
5b781a67 SC |
25 | #if __MSL__ >= 0x6000 |
26 | #include "math.h" | |
b34039cf | 27 | using namespace std ; |
5b781a67 SC |
28 | #endif |
29 | ||
b34039cf | 30 | #include "wx/mac/private.h" |
66a09d47 SC |
31 | #include "ATSUnicode.h" |
32 | #include "TextCommon.h" | |
33 | #include "TextEncodingConverter.h" | |
b34039cf | 34 | |
2f1ae414 | 35 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 36 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
2f1ae414 | 37 | #endif |
e9576ca5 SC |
38 | |
39 | //----------------------------------------------------------------------------- | |
40 | // constants | |
41 | //----------------------------------------------------------------------------- | |
42 | ||
43 | #define mm2inches 0.0393700787402 | |
44 | #define inches2mm 25.4 | |
45 | #define mm2twips 56.6929133859 | |
46 | #define twips2mm 0.0176388888889 | |
47 | #define mm2pt 2.83464566929 | |
48 | #define pt2mm 0.352777777778 | |
f5c6eb5c | 49 | #ifndef __DARWIN__ |
3dec57ad | 50 | const double M_PI = 3.14159265358979 ; |
2461b2e7 | 51 | #endif |
3dec57ad | 52 | const double RAD2DEG = 180.0 / M_PI; |
76a5e5d2 SC |
53 | const short kEmulatedMode = -1 ; |
54 | const short kUnsupportedMode = -2 ; | |
55 | ||
66a09d47 | 56 | wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : |
99030bdf | 57 | m_ph( (GrafPtr) dc->m_macPort ) |
66a09d47 SC |
58 | { |
59 | wxASSERT( dc->Ok() ) ; | |
60 | m_dc = dc ; | |
61 | dc->MacSetupPort(&m_ph) ; | |
62 | } | |
63 | ||
99030bdf | 64 | wxMacPortSetter::~wxMacPortSetter() |
66a09d47 SC |
65 | { |
66 | m_dc->MacCleanupPort(&m_ph) ; | |
67 | } | |
68 | ||
3dec57ad SC |
69 | //----------------------------------------------------------------------------- |
70 | // Local functions | |
71 | //----------------------------------------------------------------------------- | |
72 | ||
73 | static inline double dmin(double a, double b) { return a < b ? a : b; } | |
74 | static inline double dmax(double a, double b) { return a > b ? a : b; } | |
75 | static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } | |
e9576ca5 SC |
76 | |
77 | //----------------------------------------------------------------------------- | |
78 | // wxDC | |
79 | //----------------------------------------------------------------------------- | |
80 | ||
76a5e5d2 SC |
81 | // this function emulates all wx colour manipulations, used to verify the implementation |
82 | // by setting the mode in the blitting functions to kEmulatedMode | |
83 | ||
84 | void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor ) ; | |
85 | void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor ) | |
86 | { | |
87 | switch ( logical_func ) | |
88 | { | |
89 | case wxAND: // src AND dst | |
90 | dstColor.red = dstColor.red & srcColor.red ; | |
91 | dstColor.green = dstColor.green & srcColor.green ; | |
92 | dstColor.blue = dstColor.blue & srcColor.blue ; | |
93 | break ; | |
94 | case wxAND_INVERT: // (NOT src) AND dst | |
95 | dstColor.red = dstColor.red & ~srcColor.red ; | |
96 | dstColor.green = dstColor.green & ~srcColor.green ; | |
97 | dstColor.blue = dstColor.blue & ~srcColor.blue ; | |
98 | break ; | |
99 | case wxAND_REVERSE:// src AND (NOT dst) | |
100 | dstColor.red = ~dstColor.red & srcColor.red ; | |
101 | dstColor.green = ~dstColor.green & srcColor.green ; | |
102 | dstColor.blue = ~dstColor.blue & srcColor.blue ; | |
103 | break ; | |
104 | case wxCLEAR: // 0 | |
105 | dstColor.red = 0 ; | |
106 | dstColor.green = 0 ; | |
107 | dstColor.blue = 0 ; | |
108 | break ; | |
109 | case wxCOPY: // src | |
110 | dstColor.red = srcColor.red ; | |
111 | dstColor.green = srcColor.green ; | |
112 | dstColor.blue = srcColor.blue ; | |
113 | break ; | |
114 | case wxEQUIV: // (NOT src) XOR dst | |
115 | dstColor.red = dstColor.red ^ ~srcColor.red ; | |
116 | dstColor.green = dstColor.green ^ ~srcColor.green ; | |
117 | dstColor.blue = dstColor.blue ^ ~srcColor.blue ; | |
118 | break ; | |
119 | case wxINVERT: // NOT dst | |
120 | dstColor.red = ~dstColor.red ; | |
121 | dstColor.green = ~dstColor.green ; | |
122 | dstColor.blue = ~dstColor.blue ; | |
123 | break ; | |
124 | case wxNAND: // (NOT src) OR (NOT dst) | |
125 | dstColor.red = ~dstColor.red | ~srcColor.red ; | |
126 | dstColor.green = ~dstColor.green | ~srcColor.green ; | |
127 | dstColor.blue = ~dstColor.blue | ~srcColor.blue ; | |
128 | break ; | |
129 | case wxNOR: // (NOT src) AND (NOT dst) | |
130 | dstColor.red = ~dstColor.red & ~srcColor.red ; | |
131 | dstColor.green = ~dstColor.green & ~srcColor.green ; | |
132 | dstColor.blue = ~dstColor.blue & ~srcColor.blue ; | |
133 | break ; | |
134 | case wxNO_OP: // dst | |
135 | break ; | |
136 | case wxOR: // src OR dst | |
137 | dstColor.red = dstColor.red | srcColor.red ; | |
138 | dstColor.green = dstColor.green | srcColor.green ; | |
139 | dstColor.blue = dstColor.blue | srcColor.blue ; | |
140 | break ; | |
141 | case wxOR_INVERT: // (NOT src) OR dst | |
142 | dstColor.red = dstColor.red | ~srcColor.red ; | |
143 | dstColor.green = dstColor.green | ~srcColor.green ; | |
144 | dstColor.blue = dstColor.blue | ~srcColor.blue ; | |
145 | break ; | |
146 | case wxOR_REVERSE: // src OR (NOT dst) | |
147 | dstColor.red = ~dstColor.red | srcColor.red ; | |
148 | dstColor.green = ~dstColor.green | srcColor.green ; | |
149 | dstColor.blue = ~dstColor.blue | srcColor.blue ; | |
150 | break ; | |
151 | case wxSET: // 1 | |
152 | dstColor.red = 0xFFFF ; | |
153 | dstColor.green = 0xFFFF ; | |
154 | dstColor.blue = 0xFFFF ; | |
155 | break ; | |
156 | case wxSRC_INVERT: // (NOT src) | |
157 | dstColor.red = ~srcColor.red ; | |
158 | dstColor.green = ~srcColor.green ; | |
159 | dstColor.blue = ~srcColor.blue ; | |
160 | break ; | |
161 | case wxXOR: // src XOR dst | |
162 | dstColor.red = dstColor.red ^ srcColor.red ; | |
163 | dstColor.green = dstColor.green ^ srcColor.green ; | |
164 | dstColor.blue = dstColor.blue ^ srcColor.blue ; | |
165 | break ; | |
166 | } | |
167 | ||
168 | } | |
169 | ||
2f1ae414 | 170 | wxDC::wxDC() |
e9576ca5 SC |
171 | { |
172 | m_ok = FALSE; | |
e9576ca5 | 173 | m_colour = TRUE; |
99030bdf | 174 | |
2f1ae414 SC |
175 | m_mm_to_pix_x = mm2pt; |
176 | m_mm_to_pix_y = mm2pt; | |
99030bdf | 177 | |
e9576ca5 SC |
178 | m_internalDeviceOriginX = 0; |
179 | m_internalDeviceOriginY = 0; | |
180 | m_externalDeviceOriginX = 0; | |
181 | m_externalDeviceOriginY = 0; | |
99030bdf | 182 | |
e9576ca5 SC |
183 | m_logicalScaleX = 1.0; |
184 | m_logicalScaleY = 1.0; | |
185 | m_userScaleX = 1.0; | |
186 | m_userScaleY = 1.0; | |
187 | m_scaleX = 1.0; | |
188 | m_scaleY = 1.0; | |
99030bdf | 189 | |
e9576ca5 SC |
190 | m_needComputeScaleX = FALSE; |
191 | m_needComputeScaleY = FALSE; | |
99030bdf | 192 | |
519cb848 | 193 | m_macPort = NULL ; |
8208e181 | 194 | m_macMask = NULL ; |
519cb848 | 195 | m_ok = FALSE ; |
99030bdf | 196 | |
519cb848 SC |
197 | m_macFontInstalled = false ; |
198 | m_macBrushInstalled = false ; | |
199 | m_macPenInstalled = false ; | |
99030bdf | 200 | |
76a5e5d2 | 201 | m_macLocalOrigin.x = m_macLocalOrigin.y = 0 ; |
ffba56ed SC |
202 | m_macBoundaryClipRgn = NewRgn() ; |
203 | m_macCurrentClipRgn = NewRgn() ; | |
204 | ||
76a5e5d2 SC |
205 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ; |
206 | SetRectRgn( (RgnHandle) m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ; | |
9ff647cf SC |
207 | |
208 | m_pen = *wxBLACK_PEN; | |
209 | m_font = *wxNORMAL_FONT; | |
210 | m_brush = *wxWHITE_BRUSH; | |
66a09d47 SC |
211 | m_macCurrentPortStateHelper = NULL ; |
212 | m_macATSUIStyle = NULL ; | |
213 | m_macAliasWasEnabled = false; | |
214 | m_macForegroundPixMap = NULL ; | |
215 | m_macBackgroundPixMap = NULL ; | |
0eaa1d68 SC |
216 | } |
217 | ||
e9576ca5 SC |
218 | wxDC::~wxDC(void) |
219 | { | |
76a5e5d2 SC |
220 | DisposeRgn( (RgnHandle) m_macBoundaryClipRgn ) ; |
221 | DisposeRgn( (RgnHandle) m_macCurrentClipRgn ) ; | |
3dec57ad | 222 | } |
76a5e5d2 | 223 | void wxDC::MacSetupPort(wxMacPortStateHelper* help) const |
519cb848 | 224 | { |
66a09d47 SC |
225 | wxASSERT( m_macCurrentPortStateHelper == NULL ) ; |
226 | m_macCurrentPortStateHelper = help ; | |
76a5e5d2 | 227 | SetClip( (RgnHandle) m_macCurrentClipRgn); |
519cb848 SC |
228 | |
229 | m_macFontInstalled = false ; | |
230 | m_macBrushInstalled = false ; | |
99030bdf | 231 | m_macPenInstalled = false ; |
519cb848 SC |
232 | } |
233 | ||
66a09d47 SC |
234 | void wxDC::MacCleanupPort(wxMacPortStateHelper* help) const |
235 | { | |
236 | wxASSERT( m_macCurrentPortStateHelper == help ) ; | |
237 | m_macCurrentPortStateHelper = NULL ; | |
238 | if( m_macATSUIStyle ) | |
239 | { | |
240 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); | |
241 | m_macATSUIStyle = NULL ; | |
242 | } | |
243 | if ( m_macAliasWasEnabled ) | |
244 | { | |
245 | SetAntiAliasedTextEnabled(m_macFormerAliasState, m_macFormerAliasSize); | |
246 | m_macAliasWasEnabled = false ; | |
247 | } | |
248 | if ( m_macForegroundPixMap ) | |
249 | { | |
250 | Pattern blackColor ; | |
251 | ::PenPat(GetQDGlobalsBlack(&blackColor)); | |
c99d6f99 | 252 | DisposePixPat( (PixPatHandle) m_macForegroundPixMap ) ; |
66a09d47 SC |
253 | m_macForegroundPixMap = NULL ; |
254 | } | |
255 | if ( m_macBackgroundPixMap ) | |
256 | { | |
257 | Pattern whiteColor ; | |
258 | ::BackPat(GetQDGlobalsWhite(&whiteColor)); | |
c99d6f99 | 259 | DisposePixPat( (PixPatHandle) m_macBackgroundPixMap ) ; |
66a09d47 SC |
260 | m_macBackgroundPixMap = NULL ; |
261 | } | |
262 | } | |
263 | ||
2f1ae414 | 264 | void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) |
519cb848 | 265 | { |
3dec57ad | 266 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
99030bdf | 267 | |
3dec57ad | 268 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); |
99030bdf | 269 | |
3dec57ad | 270 | wxMacPortSetter helper(this) ; |
99030bdf | 271 | |
7d9d1fd7 SC |
272 | wxCoord xx = XLOG2DEVMAC(x); |
273 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
274 | wxCoord w = bmp.GetWidth(); |
275 | wxCoord h = bmp.GetHeight(); | |
276 | wxCoord ww = XLOG2DEVREL(w); | |
277 | wxCoord hh = YLOG2DEVREL(h); | |
99030bdf | 278 | |
3dec57ad SC |
279 | // Set up drawing mode |
280 | short mode = (m_logicalFunction == wxCOPY ? srcCopy : | |
281 | //m_logicalFunction == wxCLEAR ? WHITENESS : | |
282 | //m_logicalFunction == wxSET ? BLACKNESS : | |
283 | m_logicalFunction == wxINVERT ? hilite : | |
284 | //m_logicalFunction == wxAND ? MERGECOPY : | |
285 | m_logicalFunction == wxOR ? srcOr : | |
286 | m_logicalFunction == wxSRC_INVERT ? notSrcCopy : | |
287 | m_logicalFunction == wxXOR ? srcXor : | |
288 | m_logicalFunction == wxOR_REVERSE ? notSrcOr : | |
289 | //m_logicalFunction == wxAND_REVERSE ? SRCERASE : | |
290 | //m_logicalFunction == wxSRC_OR ? srcOr : | |
291 | //m_logicalFunction == wxSRC_AND ? SRCAND : | |
292 | srcCopy ); | |
99030bdf | 293 | |
3dec57ad SC |
294 | if ( bmp.GetBitmapType() == kMacBitmapTypePict ) { |
295 | Rect bitmaprect = { 0 , 0 , hh, ww }; | |
296 | ::OffsetRect( &bitmaprect, xx, yy ) ; | |
76a5e5d2 | 297 | ::DrawPicture( (PicHandle) bmp.GetPict(), &bitmaprect ) ; |
519cb848 | 298 | } |
3dec57ad SC |
299 | else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld ) |
300 | { | |
76a5e5d2 | 301 | GWorldPtr bmapworld = MAC_WXHBITMAP( bmp.GetHBITMAP() ); |
3dec57ad | 302 | PixMapHandle bmappixels ; |
99030bdf | 303 | |
3dec57ad SC |
304 | // Set foreground and background colours (for bitmaps depth = 1) |
305 | if(bmp.GetDepth() == 1) | |
306 | { | |
76a5e5d2 SC |
307 | RGBColor fore = MAC_WXCOLORREF(m_textForegroundColour.GetPixel()); |
308 | RGBColor back = MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()); | |
3dec57ad SC |
309 | RGBForeColor(&fore); |
310 | RGBBackColor(&back); | |
311 | } | |
312 | else | |
313 | { | |
314 | RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ; | |
315 | RGBColor black = { 0,0,0} ; | |
316 | RGBForeColor( &black ) ; | |
317 | RGBBackColor( &white ) ; | |
318 | } | |
99030bdf | 319 | |
3dec57ad | 320 | bmappixels = GetGWorldPixMap( bmapworld ) ; |
99030bdf | 321 | |
3dec57ad SC |
322 | wxCHECK_RET(LockPixels(bmappixels), |
323 | wxT("DoDrawBitmap: Unable to lock pixels")); | |
99030bdf | 324 | |
3dec57ad SC |
325 | Rect source = { 0, 0, h, w }; |
326 | Rect dest = { yy, xx, yy + hh, xx + ww }; | |
99030bdf | 327 | |
3dec57ad SC |
328 | if ( useMask && bmp.GetMask() ) |
329 | { | |
76a5e5d2 | 330 | if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())))) |
3dec57ad SC |
331 | { |
332 | CopyDeepMask | |
333 | ( | |
334 | GetPortBitMapForCopyBits(bmapworld), | |
76a5e5d2 SC |
335 | GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())), |
336 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ), | |
3dec57ad SC |
337 | &source, &source, &dest, mode, NULL |
338 | ); | |
76a5e5d2 | 339 | UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap()))); |
3dec57ad SC |
340 | } |
341 | } | |
342 | else { | |
343 | CopyBits( GetPortBitMapForCopyBits( bmapworld ), | |
76a5e5d2 | 344 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ), |
3dec57ad SC |
345 | &source, &dest, mode, NULL ) ; |
346 | } | |
347 | UnlockPixels( bmappixels ) ; | |
348 | } | |
349 | else if ( bmp.GetBitmapType() == kMacBitmapTypeIcon ) | |
350 | { | |
351 | Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ; | |
352 | OffsetRect( &bitmaprect, xx, yy ) ; | |
76a5e5d2 | 353 | PlotCIconHandle( &bitmaprect , atNone , ttNone , MAC_WXHICON(bmp.GetHICON()) ) ; |
3dec57ad SC |
354 | } |
355 | m_macPenInstalled = false ; | |
356 | m_macBrushInstalled = false ; | |
357 | m_macFontInstalled = false ; | |
358 | ||
519cb848 SC |
359 | } |
360 | ||
2f1ae414 | 361 | void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) |
e9576ca5 | 362 | { |
3dec57ad | 363 | wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon")); |
99030bdf | 364 | |
3dec57ad | 365 | wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon")); |
99030bdf | 366 | |
a2f94f40 | 367 | DoDrawBitmap( icon , x , y , icon.GetMask() != NULL ) ; |
3dec57ad | 368 | } |
2f1ae414 | 369 | void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
e9576ca5 | 370 | { |
3dec57ad SC |
371 | wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC")); |
372 | wxCoord xx, yy, ww, hh; | |
373 | ||
7d9d1fd7 SC |
374 | xx = XLOG2DEVMAC(x); |
375 | yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
376 | ww = XLOG2DEVREL(width); |
377 | hh = YLOG2DEVREL(height); | |
e9576ca5 | 378 | |
76a5e5d2 SC |
379 | SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ; |
380 | SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
99030bdf | 381 | |
3dec57ad SC |
382 | if( m_clipping ) |
383 | { | |
384 | m_clipX1 = wxMax( m_clipX1 , xx ); | |
385 | m_clipY1 = wxMax( m_clipY1 , yy ); | |
386 | m_clipX2 = wxMin( m_clipX2, (xx + ww)); | |
387 | m_clipY2 = wxMin( m_clipY2, (yy + hh)); | |
388 | } | |
389 | else | |
390 | { | |
391 | m_clipping = TRUE; | |
392 | m_clipX1 = xx; | |
393 | m_clipY1 = yy; | |
394 | m_clipX2 = xx + ww; | |
395 | m_clipY2 = yy + hh; | |
396 | } | |
397 | ||
398 | } | |
2f1ae414 SC |
399 | void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) |
400 | { | |
3dec57ad | 401 | wxCHECK_RET( Ok(), wxT("invalid window dc") ) ; |
2f1ae414 | 402 | |
0eaa1d68 | 403 | wxMacPortSetter helper(this) ; |
2f1ae414 SC |
404 | if (region.Empty()) |
405 | { | |
406 | DestroyClippingRegion(); | |
407 | return; | |
408 | } | |
409 | ||
ffba56ed SC |
410 | wxCoord x, y, w, h; |
411 | region.GetBox( x, y, w, h ); | |
2f1ae414 | 412 | wxCoord xx, yy, ww, hh; |
ffba56ed | 413 | |
7d9d1fd7 SC |
414 | xx = XLOG2DEVMAC(x); |
415 | yy = YLOG2DEVMAC(y); | |
ffba56ed SC |
416 | ww = XLOG2DEVREL(w); |
417 | hh = YLOG2DEVREL(h); | |
418 | ||
419 | // if we have a scaling that we cannot map onto native regions | |
420 | // we must use the box | |
421 | ||
422 | if ( ww != w || hh != h ) | |
423 | { | |
424 | wxDC::DoSetClippingRegion( x, y, w, h ); | |
425 | } | |
426 | else | |
427 | { | |
76a5e5d2 | 428 | CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ; |
ffba56ed SC |
429 | if ( xx != x || yy != y ) |
430 | { | |
76a5e5d2 | 431 | OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ; |
ffba56ed | 432 | } |
76a5e5d2 | 433 | SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; |
ffba56ed SC |
434 | if( m_clipping ) |
435 | { | |
436 | m_clipX1 = wxMax( m_clipX1 , xx ); | |
437 | m_clipY1 = wxMax( m_clipY1 , yy ); | |
438 | m_clipX2 = wxMin( m_clipX2, (xx + ww)); | |
439 | m_clipY2 = wxMin( m_clipY2, (yy + hh)); | |
440 | } | |
441 | else | |
442 | { | |
443 | m_clipping = TRUE; | |
444 | m_clipX1 = xx; | |
445 | m_clipY1 = yy; | |
446 | m_clipX2 = xx + ww; | |
447 | m_clipY2 = yy + hh; | |
448 | } | |
449 | } | |
450 | ||
ee41971c UJ |
451 | } |
452 | ||
3dec57ad | 453 | void wxDC::DestroyClippingRegion() |
e9576ca5 | 454 | { |
0eaa1d68 | 455 | wxMacPortSetter helper(this) ; |
76a5e5d2 | 456 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; |
e9576ca5 | 457 | m_clipping = FALSE; |
99030bdf | 458 | } |
2f1ae414 | 459 | void wxDC::DoGetSize( int* width, int* height ) const |
e9576ca5 SC |
460 | { |
461 | *width = m_maxX-m_minX; | |
462 | *height = m_maxY-m_minY; | |
3dec57ad | 463 | } |
2f1ae414 | 464 | void wxDC::DoGetSizeMM( int* width, int* height ) const |
e9576ca5 SC |
465 | { |
466 | int w = 0; | |
467 | int h = 0; | |
468 | GetSize( &w, &h ); | |
469 | *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); | |
470 | *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); | |
3dec57ad | 471 | } |
e9576ca5 SC |
472 | void wxDC::SetTextForeground( const wxColour &col ) |
473 | { | |
3dec57ad SC |
474 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
475 | m_textForegroundColour = col; | |
476 | m_macFontInstalled = false ; | |
477 | } | |
e9576ca5 SC |
478 | void wxDC::SetTextBackground( const wxColour &col ) |
479 | { | |
3dec57ad SC |
480 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
481 | m_textBackgroundColour = col; | |
482 | m_macFontInstalled = false ; | |
483 | } | |
e9576ca5 SC |
484 | void wxDC::SetMapMode( int mode ) |
485 | { | |
99030bdf | 486 | switch (mode) |
e9576ca5 | 487 | { |
e3065973 | 488 | case wxMM_TWIPS: |
e9576ca5 SC |
489 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); |
490 | break; | |
e3065973 | 491 | case wxMM_POINTS: |
e9576ca5 SC |
492 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); |
493 | break; | |
e3065973 | 494 | case wxMM_METRIC: |
e9576ca5 SC |
495 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); |
496 | break; | |
e3065973 | 497 | case wxMM_LOMETRIC: |
e9576ca5 SC |
498 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); |
499 | break; | |
500 | default: | |
e3065973 | 501 | case wxMM_TEXT: |
e9576ca5 SC |
502 | SetLogicalScale( 1.0, 1.0 ); |
503 | break; | |
3dec57ad | 504 | } |
e3065973 | 505 | if (mode != wxMM_TEXT) |
e9576ca5 SC |
506 | { |
507 | m_needComputeScaleX = TRUE; | |
508 | m_needComputeScaleY = TRUE; | |
3dec57ad SC |
509 | } |
510 | } | |
e9576ca5 SC |
511 | void wxDC::SetUserScale( double x, double y ) |
512 | { | |
513 | // allow negative ? -> no | |
514 | m_userScaleX = x; | |
515 | m_userScaleY = y; | |
516 | ComputeScaleAndOrigin(); | |
3dec57ad | 517 | } |
e9576ca5 SC |
518 | void wxDC::SetLogicalScale( double x, double y ) |
519 | { | |
520 | // allow negative ? | |
521 | m_logicalScaleX = x; | |
522 | m_logicalScaleY = y; | |
523 | ComputeScaleAndOrigin(); | |
3dec57ad | 524 | } |
2f1ae414 | 525 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) |
e9576ca5 SC |
526 | { |
527 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
528 | m_logicalOriginY = y * m_signY; | |
529 | ComputeScaleAndOrigin(); | |
3dec57ad | 530 | } |
2f1ae414 | 531 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) |
e9576ca5 SC |
532 | { |
533 | m_externalDeviceOriginX = x; | |
534 | m_externalDeviceOriginY = y; | |
535 | ComputeScaleAndOrigin(); | |
3dec57ad SC |
536 | } |
537 | ||
538 | #if 0 | |
e9576ca5 SC |
539 | void wxDC::SetInternalDeviceOrigin( long x, long y ) |
540 | { | |
541 | m_internalDeviceOriginX = x; | |
542 | m_internalDeviceOriginY = y; | |
543 | ComputeScaleAndOrigin(); | |
3dec57ad | 544 | } |
e9576ca5 SC |
545 | void wxDC::GetInternalDeviceOrigin( long *x, long *y ) |
546 | { | |
547 | if (x) *x = m_internalDeviceOriginX; | |
548 | if (y) *y = m_internalDeviceOriginY; | |
3dec57ad SC |
549 | } |
550 | #endif | |
e9576ca5 SC |
551 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
552 | { | |
553 | m_signX = (xLeftRight ? 1 : -1); | |
554 | m_signY = (yBottomUp ? -1 : 1); | |
555 | ComputeScaleAndOrigin(); | |
76a5e5d2 SC |
556 | } |
557 | ||
2f1ae414 SC |
558 | wxSize wxDC::GetPPI() const |
559 | { | |
560 | return wxSize(72, 72); | |
561 | } | |
562 | ||
563 | int wxDC::GetDepth() const | |
564 | { | |
c99d6f99 SC |
565 | if ( IsPortColor( (CGrafPtr) m_macPort ) ) |
566 | { | |
567 | return ( (**GetPortPixMap( (CGrafPtr) m_macPort)).pixelSize ) ; | |
568 | } | |
569 | return 1 ; | |
2f1ae414 | 570 | } |
e9576ca5 | 571 | |
3dec57ad | 572 | void wxDC::ComputeScaleAndOrigin() |
e9576ca5 SC |
573 | { |
574 | // CMB: copy scale to see if it changes | |
575 | double origScaleX = m_scaleX; | |
576 | double origScaleY = m_scaleY; | |
577 | ||
578 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
579 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
580 | ||
581 | m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; | |
582 | m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; | |
583 | ||
99030bdf | 584 | // CMB: if scale has changed call SetPen to recalulate the line width |
e9576ca5 SC |
585 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) |
586 | { | |
5b781a67 SC |
587 | // this is a bit artificial, but we need to force wxDC to think |
588 | // the pen has changed | |
589 | wxPen* pen = & GetPen(); | |
590 | wxPen tempPen; | |
591 | m_pen = tempPen; | |
592 | SetPen(* pen); | |
e9576ca5 | 593 | } |
3dec57ad | 594 | } |
519cb848 SC |
595 | void wxDC::SetPalette( const wxPalette& palette ) |
596 | { | |
597 | } | |
598 | ||
599 | void wxDC::SetBackgroundMode( int mode ) | |
600 | { | |
601 | m_backgroundMode = mode ; | |
602 | } | |
603 | ||
604 | void wxDC::SetFont( const wxFont &font ) | |
605 | { | |
3dec57ad SC |
606 | m_font = font; |
607 | m_macFontInstalled = false ; | |
519cb848 SC |
608 | } |
609 | ||
610 | void wxDC::SetPen( const wxPen &pen ) | |
611 | { | |
519cb848 SC |
612 | if ( m_pen == pen ) |
613 | return ; | |
99030bdf | 614 | |
519cb848 | 615 | m_pen = pen; |
3dec57ad | 616 | |
519cb848 SC |
617 | m_macPenInstalled = false ; |
618 | } | |
619 | ||
620 | void wxDC::SetBrush( const wxBrush &brush ) | |
621 | { | |
99030bdf | 622 | if (m_brush == brush) |
519cb848 | 623 | return; |
99030bdf | 624 | |
519cb848 SC |
625 | m_brush = brush; |
626 | m_macBrushInstalled = false ; | |
627 | } | |
628 | ||
629 | void wxDC::SetBackground( const wxBrush &brush ) | |
630 | { | |
99030bdf | 631 | if (m_backgroundBrush == brush) |
519cb848 | 632 | return; |
99030bdf | 633 | |
519cb848 | 634 | m_backgroundBrush = brush; |
99030bdf RD |
635 | |
636 | if (!m_backgroundBrush.Ok()) | |
519cb848 SC |
637 | return; |
638 | m_macBrushInstalled = false ; | |
639 | } | |
640 | ||
641 | void wxDC::SetLogicalFunction( int function ) | |
642 | { | |
99030bdf | 643 | if (m_logicalFunction == function) |
519cb848 SC |
644 | return; |
645 | ||
646 | m_logicalFunction = function ; | |
647 | m_macFontInstalled = false ; | |
648 | m_macBrushInstalled = false ; | |
649 | m_macPenInstalled = false ; | |
650 | } | |
651 | ||
99030bdf | 652 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, |
3a0a5ada | 653 | const wxColour & col, int style); |
b1699cd3 | 654 | |
387ebd3e | 655 | bool wxDC::DoFloodFill(wxCoord x, wxCoord y, |
3a0a5ada VS |
656 | const wxColour& col, int style) |
657 | { | |
387ebd3e | 658 | return wxDoFloodFill(this, x, y, col, style); |
71110b40 SC |
659 | } |
660 | ||
99030bdf | 661 | bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const |
519cb848 | 662 | { |
3dec57ad SC |
663 | wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); |
664 | wxMacPortSetter helper(this) ; | |
665 | ||
666 | RGBColor colour; | |
667 | ||
7d9d1fd7 | 668 | GetCPixel( XLOG2DEVMAC(x), YLOG2DEVMAC(y), &colour ); |
3dec57ad SC |
669 | |
670 | // Convert from Mac colour to wx | |
671 | col->Set( colour.red >> 8, | |
672 | colour.green >> 8, | |
673 | colour.blue >> 8); | |
674 | ||
675 | return true ; | |
519cb848 SC |
676 | } |
677 | ||
2f1ae414 | 678 | void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
519cb848 | 679 | { |
3dec57ad | 680 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
99030bdf | 681 | |
0eaa1d68 | 682 | wxMacPortSetter helper(this) ; |
99030bdf | 683 | |
519cb848 SC |
684 | if (m_pen.GetStyle() != wxTRANSPARENT) |
685 | { | |
686 | MacInstallPen() ; | |
3dec57ad SC |
687 | wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 : |
688 | m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2; | |
689 | ||
7d9d1fd7 SC |
690 | wxCoord xx1 = XLOG2DEVMAC(x1) - offset; |
691 | wxCoord yy1 = YLOG2DEVMAC(y1) - offset; | |
692 | wxCoord xx2 = XLOG2DEVMAC(x2) - offset; | |
693 | wxCoord yy2 = YLOG2DEVMAC(y2) - offset; | |
2301e281 RR |
694 | |
695 | if ((m_pen.GetCap() == wxCAP_ROUND) && | |
696 | (m_pen.GetWidth() <= 1)) | |
697 | { | |
698 | // Implement LAST_NOT for MAC at least for | |
699 | // orthogonal lines. RR. | |
700 | if (xx1 == xx2) | |
701 | { | |
702 | if (yy1 < yy2) | |
703 | yy2--; | |
704 | if (yy1 > yy2) | |
705 | yy2++; | |
706 | } | |
707 | if (yy1 == yy2) | |
708 | { | |
709 | if (xx1 < xx2) | |
710 | xx2--; | |
711 | if (xx1 > xx2) | |
712 | xx2++; | |
713 | } | |
714 | } | |
99030bdf | 715 | |
2301e281 RR |
716 | ::MoveTo(xx1, yy1); |
717 | ::LineTo(xx2, yy2); | |
3dec57ad | 718 | } |
519cb848 SC |
719 | } |
720 | ||
2f1ae414 | 721 | void wxDC::DoCrossHair( wxCoord x, wxCoord y ) |
519cb848 | 722 | { |
3dec57ad SC |
723 | wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") ); |
724 | ||
725 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
726 | { | |
727 | int w = 0; | |
728 | int h = 0; | |
729 | GetSize( &w, &h ); | |
7d9d1fd7 SC |
730 | wxCoord xx = XLOG2DEVMAC(x); |
731 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
732 | |
733 | MacInstallPen(); | |
7d9d1fd7 SC |
734 | ::MoveTo( XLOG2DEVMAC(0), yy ); |
735 | ::LineTo( XLOG2DEVMAC(w), yy ); | |
736 | ::MoveTo( xx, YLOG2DEVMAC(0) ); | |
737 | ::LineTo( xx, YLOG2DEVMAC(h) ); | |
66a09d47 SC |
738 | |
739 | CalcBoundingBox(x, y); | |
740 | CalcBoundingBox(x+w, y+h); | |
741 | ||
3dec57ad SC |
742 | } |
743 | } | |
744 | ||
745 | /* | |
746 | * To draw arcs properly the angles need to be converted from the WX style: | |
747 | * Angles start on the +ve X axis and go anti-clockwise (As you would draw on | |
748 | * a normal axis on paper). | |
749 | * TO | |
750 | * the Mac style: | |
751 | * Angles start on the +ve y axis and go clockwise. | |
752 | * To achive this I work out which quadrant the angle lies in then map this to | |
753 | * the equivalent quadrant on the Mac. (Sin and Cos values reveal which | |
754 | * quadrant you are in). | |
755 | */ | |
756 | static double wxConvertWXangleToMACangle(double angle) | |
757 | { | |
758 | double sin_a, cos_a; | |
759 | ||
760 | sin_a = sin(angle / RAD2DEG); | |
761 | cos_a = cos(angle / RAD2DEG); | |
762 | ||
763 | if( (sin_a >= 0.0) && (cos_a >= 0.0) ) { | |
764 | angle = acos(sin_a) * RAD2DEG; | |
765 | } | |
766 | else if( (sin_a >= 0.0) && (cos_a <= 0.0) ) { | |
767 | sin_a *= -1; | |
768 | angle = acos(sin_a) * RAD2DEG + 180; | |
769 | } | |
770 | else if( (sin_a <= 0.0) && (cos_a >= 0.0) ) { | |
771 | angle = acos(sin_a) * RAD2DEG + 180; | |
772 | } | |
773 | else if( (sin_a < 0.0) && (cos_a < 0.0) ) { | |
774 | sin_a *= -1; | |
775 | angle = acos(sin_a) * RAD2DEG + 180; | |
776 | } | |
777 | return angle; | |
519cb848 SC |
778 | } |
779 | ||
2f1ae414 SC |
780 | void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, |
781 | wxCoord x2, wxCoord y2, | |
782 | wxCoord xc, wxCoord yc ) | |
519cb848 | 783 | { |
3dec57ad SC |
784 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC")); |
785 | ||
7d9d1fd7 SC |
786 | wxCoord xx1 = XLOG2DEVMAC(x1); |
787 | wxCoord yy1 = YLOG2DEVMAC(y1); | |
788 | wxCoord xx2 = XLOG2DEVMAC(x2); | |
789 | wxCoord yy2 = YLOG2DEVMAC(y2); | |
790 | wxCoord xxc = XLOG2DEVMAC(xc); | |
791 | wxCoord yyc = YLOG2DEVMAC(yc); | |
3dec57ad SC |
792 | double dx = xx1 - xxc; |
793 | double dy = yy1 - yyc; | |
794 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
795 | wxCoord rad = (wxCoord)radius; | |
796 | double radius1, radius2; | |
797 | ||
798 | if (xx1 == xx2 && yy1 == yy2) | |
799 | { | |
800 | radius1 = 0.0; | |
801 | radius2 = 360.0; | |
802 | } | |
803 | else if (radius == 0.0) | |
804 | { | |
805 | radius1 = radius2 = 0.0; | |
806 | } | |
807 | else | |
808 | { | |
809 | radius1 = (xx1 - xxc == 0) ? | |
810 | (yy1 - yyc < 0) ? 90.0 : -90.0 : | |
811 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
812 | radius2 = (xx2 - xxc == 0) ? | |
813 | (yy2 - yyc < 0) ? 90.0 : -90.0 : | |
814 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
815 | } | |
816 | wxCoord alpha2 = wxCoord(radius2 - radius1); | |
817 | wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1)); | |
818 | if( (xx1 > xx2) || (yy1 > yy2) ) { | |
819 | alpha2 *= -1; | |
820 | } | |
821 | ||
822 | Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad }; | |
823 | ||
824 | if(m_brush.GetStyle() != wxTRANSPARENT) { | |
825 | MacInstallBrush(); | |
826 | PaintArc(&r, alpha1, alpha2); | |
827 | } | |
828 | if(m_pen.GetStyle() != wxTRANSPARENT) { | |
829 | MacInstallPen(); | |
830 | FrameArc(&r, alpha1, alpha2); | |
831 | } | |
519cb848 SC |
832 | } |
833 | ||
2f1ae414 SC |
834 | void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
835 | double sa, double ea ) | |
519cb848 | 836 | { |
3dec57ad SC |
837 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC")); |
838 | ||
839 | Rect r; | |
840 | double angle = sa - ea; // Order important Mac in opposite direction to wx | |
99030bdf | 841 | |
7d9d1fd7 SC |
842 | wxCoord xx = XLOG2DEVMAC(x); |
843 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
844 | wxCoord ww = m_signX * XLOG2DEVREL(w); |
845 | wxCoord hh = m_signY * YLOG2DEVREL(h); | |
846 | ||
847 | // handle -ve width and/or height | |
848 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
849 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
850 | ||
851 | sa = wxConvertWXangleToMACangle(sa); | |
852 | ||
853 | r.top = yy; | |
854 | r.left = xx; | |
855 | r.bottom = yy + hh; | |
856 | r.right = xx + ww; | |
857 | ||
858 | if(m_brush.GetStyle() != wxTRANSPARENT) { | |
859 | MacInstallBrush(); | |
860 | PaintArc(&r, (short)sa, (short)angle); | |
861 | } | |
862 | if(m_pen.GetStyle() != wxTRANSPARENT) { | |
863 | MacInstallPen(); | |
864 | FrameArc(&r, (short)sa, (short)angle); | |
865 | } | |
519cb848 SC |
866 | } |
867 | ||
2f1ae414 | 868 | void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) |
519cb848 | 869 | { |
3dec57ad | 870 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
99030bdf | 871 | |
0eaa1d68 | 872 | wxMacPortSetter helper(this) ; |
99030bdf RD |
873 | |
874 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
519cb848 | 875 | { |
99030bdf | 876 | wxCoord xx1 = XLOG2DEVMAC(x); |
7d9d1fd7 | 877 | wxCoord yy1 = YLOG2DEVMAC(y); |
5e420341 SC |
878 | RGBColor pencolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel()); |
879 | ::SetCPixel( xx1,yy1,&pencolor) ; | |
880 | CalcBoundingBox(x, y); | |
3dec57ad | 881 | } |
519cb848 SC |
882 | } |
883 | ||
2f1ae414 SC |
884 | void wxDC::DoDrawLines(int n, wxPoint points[], |
885 | wxCoord xoffset, wxCoord yoffset) | |
519cb848 | 886 | { |
3dec57ad | 887 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 888 | wxMacPortSetter helper(this) ; |
99030bdf RD |
889 | |
890 | if (m_pen.GetStyle() == wxTRANSPARENT) | |
519cb848 SC |
891 | return; |
892 | ||
03e11df5 | 893 | MacInstallPen() ; |
99030bdf | 894 | |
3dec57ad SC |
895 | wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 : |
896 | m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2 ; | |
897 | ||
898 | wxCoord x1, x2 , y1 , y2 ; | |
7d9d1fd7 | 899 | x1 = XLOG2DEVMAC(points[0].x + xoffset); |
99030bdf | 900 | y1 = YLOG2DEVMAC(points[0].y + yoffset); |
3dec57ad | 901 | ::MoveTo(x1 - offset, y1 - offset ); |
99030bdf | 902 | |
519cb848 SC |
903 | for (int i = 0; i < n-1; i++) |
904 | { | |
7d9d1fd7 SC |
905 | x2 = XLOG2DEVMAC(points[i+1].x + xoffset); |
906 | y2 = YLOG2DEVMAC(points[i+1].y + yoffset); | |
3dec57ad | 907 | ::LineTo( x2 - offset, y2 - offset ); |
519cb848 SC |
908 | } |
909 | } | |
910 | ||
2f1ae414 | 911 | void wxDC::DoDrawPolygon(int n, wxPoint points[], |
d84afea9 GD |
912 | wxCoord xoffset, wxCoord yoffset, |
913 | int fillStyle ) | |
519cb848 | 914 | { |
32ea1f98 RR |
915 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
916 | wxMacPortSetter helper(this) ; | |
99030bdf | 917 | |
32ea1f98 | 918 | wxCoord x1, x2 , y1 , y2 ; |
99030bdf | 919 | |
75f7bc3b SC |
920 | if ( m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) |
921 | return ; | |
99030bdf | 922 | |
75f7bc3b | 923 | PolyHandle polygon = OpenPoly(); |
99030bdf | 924 | |
75f7bc3b | 925 | x1 = XLOG2DEVMAC(points[0].x + xoffset); |
99030bdf | 926 | y1 = YLOG2DEVMAC(points[0].y + yoffset); |
75f7bc3b SC |
927 | ::MoveTo(x1,y1); |
928 | ||
76a5e5d2 | 929 | for (int i = 1; i < n; i++) |
75f7bc3b | 930 | { |
76a5e5d2 SC |
931 | x2 = XLOG2DEVMAC(points[i].x + xoffset); |
932 | y2 = YLOG2DEVMAC(points[i].y + yoffset); | |
75f7bc3b SC |
933 | ::LineTo(x2, y2); |
934 | } | |
935 | ||
76a5e5d2 SC |
936 | // close the polyline if necessary |
937 | if ( x1 != x2 || y1 != y2 ) | |
938 | { | |
939 | ::LineTo(x1,y1 ) ; | |
940 | } | |
99030bdf | 941 | |
75f7bc3b SC |
942 | ClosePoly(); |
943 | ||
32ea1f98 RR |
944 | if (m_brush.GetStyle() != wxTRANSPARENT) |
945 | { | |
32ea1f98 RR |
946 | |
947 | MacInstallBrush(); | |
948 | ::PaintPoly( polygon ); | |
99030bdf | 949 | |
3dec57ad | 950 | } |
99030bdf RD |
951 | |
952 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
519cb848 | 953 | { |
99030bdf | 954 | |
519cb848 SC |
955 | MacInstallPen() ; |
956 | ::FramePoly( polygon ) ; | |
99030bdf | 957 | |
3dec57ad | 958 | } |
75f7bc3b | 959 | KillPoly( polygon ); |
519cb848 SC |
960 | } |
961 | ||
3dec57ad | 962 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
519cb848 | 963 | { |
3dec57ad SC |
964 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
965 | wxMacPortSetter helper(this) ; | |
966 | ||
7d9d1fd7 SC |
967 | wxCoord xx = XLOG2DEVMAC(x); |
968 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
969 | wxCoord ww = m_signX * XLOG2DEVREL(width); |
970 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
99030bdf | 971 | |
519cb848 | 972 | // CMB: draw nothing if transformed w or h is 0 |
99030bdf | 973 | if (ww == 0 || hh == 0) |
519cb848 | 974 | return; |
99030bdf | 975 | |
519cb848 | 976 | // CMB: handle -ve width and/or height |
99030bdf RD |
977 | if (ww < 0) |
978 | { | |
979 | ww = -ww; | |
980 | xx = xx - ww; | |
519cb848 | 981 | } |
99030bdf RD |
982 | |
983 | if (hh < 0) | |
984 | { | |
985 | hh = -hh; | |
986 | yy = yy - hh; | |
519cb848 | 987 | } |
99030bdf | 988 | |
519cb848 | 989 | Rect rect = { yy , xx , yy + hh , xx + ww } ; |
99030bdf RD |
990 | |
991 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
519cb848 SC |
992 | { |
993 | MacInstallBrush() ; | |
994 | ::PaintRect( &rect ) ; | |
3dec57ad | 995 | } |
99030bdf RD |
996 | |
997 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
519cb848 SC |
998 | { |
999 | MacInstallPen() ; | |
1000 | ::FrameRect( &rect ) ; | |
3dec57ad | 1001 | } |
519cb848 SC |
1002 | } |
1003 | ||
2f1ae414 SC |
1004 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, |
1005 | wxCoord width, wxCoord height, | |
1006 | double radius) | |
519cb848 | 1007 | { |
3dec57ad SC |
1008 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
1009 | wxMacPortSetter helper(this) ; | |
99030bdf RD |
1010 | |
1011 | if (radius < 0.0) | |
3dec57ad | 1012 | radius = - radius * ((width < height) ? width : height); |
99030bdf | 1013 | |
7d9d1fd7 SC |
1014 | wxCoord xx = XLOG2DEVMAC(x); |
1015 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
1016 | wxCoord ww = m_signX * XLOG2DEVREL(width); |
1017 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
99030bdf | 1018 | |
519cb848 | 1019 | // CMB: draw nothing if transformed w or h is 0 |
99030bdf | 1020 | if (ww == 0 || hh == 0) |
519cb848 | 1021 | return; |
99030bdf | 1022 | |
519cb848 | 1023 | // CMB: handle -ve width and/or height |
99030bdf RD |
1024 | if (ww < 0) |
1025 | { | |
1026 | ww = -ww; | |
1027 | xx = xx - ww; | |
519cb848 | 1028 | } |
99030bdf RD |
1029 | |
1030 | if (hh < 0) | |
1031 | { | |
1032 | hh = -hh; | |
1033 | yy = yy - hh; | |
519cb848 | 1034 | } |
99030bdf | 1035 | |
519cb848 | 1036 | Rect rect = { yy , xx , yy + hh , xx + ww } ; |
99030bdf RD |
1037 | |
1038 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
519cb848 SC |
1039 | { |
1040 | MacInstallBrush() ; | |
03e11df5 | 1041 | ::PaintRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ; |
3dec57ad | 1042 | } |
99030bdf RD |
1043 | |
1044 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
519cb848 SC |
1045 | { |
1046 | MacInstallPen() ; | |
03e11df5 | 1047 | ::FrameRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ; |
3dec57ad | 1048 | } |
519cb848 SC |
1049 | } |
1050 | ||
2f1ae414 | 1051 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
519cb848 | 1052 | { |
3dec57ad SC |
1053 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
1054 | wxMacPortSetter helper(this) ; | |
519cb848 | 1055 | |
7d9d1fd7 SC |
1056 | wxCoord xx = XLOG2DEVMAC(x); |
1057 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
1058 | wxCoord ww = m_signX * XLOG2DEVREL(width); |
1059 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
519cb848 SC |
1060 | |
1061 | // CMB: draw nothing if transformed w or h is 0 | |
1062 | if (ww == 0 || hh == 0) | |
1063 | return; | |
1064 | ||
1065 | // CMB: handle -ve width and/or height | |
1066 | if (ww < 0) | |
1067 | { | |
1068 | ww = -ww; | |
1069 | xx = xx - ww; | |
1070 | } | |
1071 | ||
1072 | if (hh < 0) | |
1073 | { | |
1074 | hh = -hh; | |
1075 | yy = yy - hh; | |
1076 | } | |
1077 | ||
1078 | Rect rect = { yy , xx , yy + hh , xx + ww } ; | |
1079 | ||
1080 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1081 | { | |
1082 | MacInstallBrush() ; | |
1083 | ::PaintOval( &rect ) ; | |
3dec57ad | 1084 | } |
519cb848 SC |
1085 | |
1086 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
1087 | { | |
1088 | MacInstallPen() ; | |
1089 | ::FrameOval( &rect ) ; | |
3dec57ad | 1090 | } |
519cb848 SC |
1091 | } |
1092 | ||
519cb848 | 1093 | |
99030bdf RD |
1094 | |
1095 | bool wxDC::CanDrawBitmap(void) const | |
519cb848 SC |
1096 | { |
1097 | return true ; | |
1098 | } | |
1099 | ||
1100 | ||
2f1ae414 | 1101 | bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
0cbff120 JS |
1102 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask, |
1103 | wxCoord xsrcMask, wxCoord ysrcMask ) | |
519cb848 | 1104 | { |
3dec57ad SC |
1105 | wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc")); |
1106 | wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC")); | |
99030bdf | 1107 | |
76a5e5d2 SC |
1108 | if ( logical_func == wxNO_OP ) |
1109 | return TRUE ; | |
519cb848 | 1110 | |
0cbff120 JS |
1111 | if (xsrcMask == -1 && ysrcMask == -1) |
1112 | { | |
1113 | xsrcMask = xsrc; ysrcMask = ysrc; | |
1114 | } | |
1115 | ||
76a5e5d2 | 1116 | // correct the parameter in case this dc does not have a mask at all |
99030bdf | 1117 | |
76a5e5d2 SC |
1118 | if ( useMask && !source->m_macMask ) |
1119 | useMask = false ; | |
99030bdf | 1120 | |
76a5e5d2 SC |
1121 | Rect srcrect , dstrect ; |
1122 | srcrect.top = source->YLOG2DEVMAC(ysrc) ; | |
1123 | srcrect.left = source->XLOG2DEVMAC(xsrc) ; | |
1124 | srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ; | |
1125 | srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ; | |
1126 | dstrect.top = YLOG2DEVMAC(ydest) ; | |
1127 | dstrect.left = XLOG2DEVMAC(xdest) ; | |
1128 | dstrect.bottom = YLOG2DEVMAC(ydest + height ) ; | |
1129 | dstrect.right = XLOG2DEVMAC(xdest + width ) ; | |
1130 | ||
1131 | short mode = kUnsupportedMode ; | |
1132 | bool invertDestinationFirst = false ; | |
1133 | switch ( logical_func ) | |
1134 | { | |
1135 | case wxAND: // src AND dst | |
1136 | mode = srcOr ; // ok | |
1137 | break ; | |
1138 | case wxAND_INVERT: // (NOT src) AND dst | |
1139 | mode = notSrcOr ; // ok | |
1140 | break ; | |
1141 | case wxAND_REVERSE:// src AND (NOT dst) | |
1142 | invertDestinationFirst = true ; | |
99030bdf | 1143 | mode = srcOr ; |
76a5e5d2 SC |
1144 | break ; |
1145 | case wxCLEAR: // 0 | |
99030bdf | 1146 | mode = kEmulatedMode ; |
76a5e5d2 SC |
1147 | break ; |
1148 | case wxCOPY: // src | |
1149 | mode = srcCopy ; // ok | |
1150 | break ; | |
1151 | case wxEQUIV: // (NOT src) XOR dst | |
1152 | mode = srcXor ; // ok | |
1153 | break ; | |
1154 | case wxINVERT: // NOT dst | |
1155 | mode = kEmulatedMode ; //or hilite ; | |
1156 | break ; | |
1157 | case wxNAND: // (NOT src) OR (NOT dst) | |
1158 | invertDestinationFirst = true ; | |
99030bdf | 1159 | mode = srcBic ; |
76a5e5d2 SC |
1160 | break ; |
1161 | case wxNOR: // (NOT src) AND (NOT dst) | |
1162 | invertDestinationFirst = true ; | |
99030bdf | 1163 | mode = notSrcOr ; |
76a5e5d2 SC |
1164 | break ; |
1165 | case wxNO_OP: // dst | |
1166 | mode = kEmulatedMode ; // this has already been handled upon entry | |
1167 | break ; | |
1168 | case wxOR: // src OR dst | |
1169 | mode = notSrcBic ; | |
1170 | break ; | |
1171 | case wxOR_INVERT: // (NOT src) OR dst | |
99030bdf | 1172 | mode = srcBic ; |
76a5e5d2 SC |
1173 | break ; |
1174 | case wxOR_REVERSE: // src OR (NOT dst) | |
1175 | invertDestinationFirst = true ; | |
1176 | mode = notSrcBic ; | |
1177 | break ; | |
1178 | case wxSET: // 1 | |
99030bdf | 1179 | mode = kEmulatedMode ; |
76a5e5d2 SC |
1180 | break ; |
1181 | case wxSRC_INVERT: // (NOT src) | |
1182 | mode = notSrcCopy ; // ok | |
1183 | break ; | |
1184 | case wxXOR: // src XOR dst | |
1185 | mode = notSrcXor ; // ok | |
1186 | break ; | |
1187 | ||
1188 | default : | |
1189 | break ; | |
1190 | ||
1191 | } | |
1192 | ||
1193 | if ( mode == kUnsupportedMode ) | |
1194 | { | |
99030bdf | 1195 | wxFAIL_MSG("unsupported blitting mode" ); |
76a5e5d2 SC |
1196 | return FALSE ; |
1197 | } | |
99030bdf | 1198 | |
519cb848 | 1199 | CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ; |
99030bdf | 1200 | PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; |
519cb848 SC |
1201 | if ( LockPixels(bmappixels) ) |
1202 | { | |
76a5e5d2 | 1203 | wxMacPortSetter helper(this) ; |
99030bdf | 1204 | |
76a5e5d2 SC |
1205 | if ( source->GetDepth() == 1 ) |
1206 | { | |
1207 | RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ; | |
1208 | RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ; | |
1209 | } | |
1210 | else | |
1211 | { | |
1212 | // the modes need this, otherwise we'll end up having really nice colors... | |
1213 | RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ; | |
1214 | RGBColor black = { 0,0,0} ; | |
1215 | RGBForeColor( &black ) ; | |
1216 | RGBBackColor( &white ) ; | |
1217 | } | |
8208e181 SC |
1218 | |
1219 | if ( useMask && source->m_macMask ) | |
1220 | { | |
1dcbbdcf SC |
1221 | if ( mode == srcCopy ) |
1222 | { | |
76a5e5d2 | 1223 | if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ) |
1dcbbdcf | 1224 | { |
99030bdf RD |
1225 | CopyMask( GetPortBitMapForCopyBits( sourcePort ) , |
1226 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) , | |
76a5e5d2 | 1227 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) , |
1dcbbdcf | 1228 | &srcrect, &srcrect , &dstrect ) ; |
76a5e5d2 | 1229 | UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; |
1dcbbdcf SC |
1230 | } |
1231 | } | |
1232 | else | |
1233 | { | |
1234 | RgnHandle clipRgn = NewRgn() ; | |
76a5e5d2 SC |
1235 | LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; |
1236 | BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; | |
1237 | UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; | |
1dcbbdcf | 1238 | OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top + dstrect.top ) ; |
76a5e5d2 SC |
1239 | if ( mode == kEmulatedMode ) |
1240 | { | |
1241 | Pattern pat ; | |
1242 | ::PenPat(GetQDGlobalsBlack(&pat)); | |
1243 | if ( logical_func == wxSET ) | |
1244 | { | |
1245 | RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ; | |
1246 | ::RGBForeColor( &col ) ; | |
1247 | ::PaintRgn( clipRgn ) ; | |
1248 | } | |
1249 | else if ( logical_func == wxCLEAR ) | |
1250 | { | |
1251 | RGBColor col= { 0x0000, 0x0000, 0x0000 } ; | |
1252 | ::RGBForeColor( &col ) ; | |
1253 | ::PaintRgn( clipRgn ) ; | |
1254 | } | |
1255 | else if ( logical_func == wxINVERT ) | |
1256 | { | |
1257 | MacInvertRgn( clipRgn ) ; | |
1258 | } | |
1259 | else | |
1260 | { | |
1261 | for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y ) | |
1262 | { | |
1263 | for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x ) | |
1264 | { | |
1265 | Point dstPoint = { dstrect.top + y , dstrect.left + x } ; | |
1266 | Point srcPoint = { srcrect.top + y , srcrect.left + x } ; | |
1267 | if ( PtInRgn( dstPoint , clipRgn ) ) | |
1268 | { | |
1269 | RGBColor srcColor ; | |
1270 | RGBColor dstColor ; | |
99030bdf | 1271 | |
76a5e5d2 SC |
1272 | SetPort( (GrafPtr) sourcePort ) ; |
1273 | GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ; | |
1274 | SetPort( (GrafPtr) m_macPort ) ; | |
1275 | GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
99030bdf | 1276 | |
76a5e5d2 SC |
1277 | wxMacCalculateColour( logical_func , srcColor , dstColor ) ; |
1278 | SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
1279 | } | |
1280 | } | |
1281 | } | |
76a5e5d2 SC |
1282 | } |
1283 | } | |
1284 | else | |
1285 | { | |
1286 | if ( invertDestinationFirst ) | |
1287 | { | |
1288 | MacInvertRgn( clipRgn ) ; | |
1289 | } | |
99030bdf | 1290 | CopyBits( GetPortBitMapForCopyBits( sourcePort ) , |
76a5e5d2 SC |
1291 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) , |
1292 | &srcrect, &dstrect, mode, clipRgn ) ; | |
1293 | } | |
1dcbbdcf SC |
1294 | DisposeRgn( clipRgn ) ; |
1295 | } | |
8208e181 SC |
1296 | } |
1297 | else | |
1298 | { | |
0d54461f SC |
1299 | RgnHandle clipRgn = NewRgn() ; |
1300 | SetRectRgn( clipRgn , dstrect.left , dstrect.top , dstrect.right , dstrect.bottom ) ; | |
76a5e5d2 SC |
1301 | if ( mode == kEmulatedMode ) |
1302 | { | |
0d54461f SC |
1303 | Pattern pat ; |
1304 | ::PenPat(GetQDGlobalsBlack(&pat)); | |
1305 | if ( logical_func == wxSET ) | |
1306 | { | |
1307 | RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ; | |
1308 | ::RGBForeColor( &col ) ; | |
1309 | ::PaintRgn( clipRgn ) ; | |
1310 | } | |
1311 | else if ( logical_func == wxCLEAR ) | |
1312 | { | |
1313 | RGBColor col= { 0x0000, 0x0000, 0x0000 } ; | |
1314 | ::RGBForeColor( &col ) ; | |
1315 | ::PaintRgn( clipRgn ) ; | |
1316 | } | |
1317 | else if ( logical_func == wxINVERT ) | |
1318 | { | |
1319 | MacInvertRgn( clipRgn ) ; | |
1320 | } | |
1321 | else | |
1322 | { | |
1323 | for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y ) | |
1324 | { | |
1325 | for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x ) | |
1326 | { | |
1327 | Point dstPoint = { dstrect.top + y , dstrect.left + x } ; | |
1328 | Point srcPoint = { srcrect.top + y , srcrect.left + x } ; | |
1329 | ||
1330 | { | |
1331 | RGBColor srcColor ; | |
1332 | RGBColor dstColor ; | |
99030bdf | 1333 | |
0d54461f SC |
1334 | SetPort( (GrafPtr) sourcePort ) ; |
1335 | GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ; | |
1336 | SetPort( (GrafPtr) m_macPort ) ; | |
1337 | GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
99030bdf | 1338 | |
0d54461f SC |
1339 | wxMacCalculateColour( logical_func , srcColor , dstColor ) ; |
1340 | SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
1341 | } | |
1342 | } | |
1343 | } | |
1344 | } | |
1345 | ||
76a5e5d2 SC |
1346 | } |
1347 | else | |
1348 | { | |
0d54461f SC |
1349 | if ( invertDestinationFirst ) |
1350 | { | |
1351 | MacInvertRgn( clipRgn ) ; | |
1352 | } | |
99030bdf | 1353 | CopyBits( GetPortBitMapForCopyBits( sourcePort ) , |
0d54461f SC |
1354 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) , |
1355 | &srcrect, &dstrect, mode, NULL ) ; | |
76a5e5d2 | 1356 | } |
0d54461f | 1357 | DisposeRgn( clipRgn ) ; |
8208e181 | 1358 | } |
519cb848 | 1359 | UnlockPixels( bmappixels ) ; |
99030bdf RD |
1360 | } |
1361 | ||
519cb848 SC |
1362 | m_macPenInstalled = false ; |
1363 | m_macBrushInstalled = false ; | |
1364 | m_macFontInstalled = false ; | |
99030bdf | 1365 | |
519cb848 SC |
1366 | return TRUE; |
1367 | } | |
1368 | ||
66a09d47 SC |
1369 | inline Fixed IntToFixed( int inInt ) |
1370 | { | |
1371 | return (((SInt32) inInt) << 16); | |
1372 | } | |
1373 | ||
1374 | ||
1375 | void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, | |
3dec57ad | 1376 | double angle) |
2f1ae414 | 1377 | { |
3dec57ad SC |
1378 | wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") ); |
1379 | ||
32907dbd | 1380 | if (angle == 0.0 ) |
3dec57ad | 1381 | { |
66a09d47 | 1382 | DrawText(str, x, y); |
3dec57ad SC |
1383 | return; |
1384 | } | |
1385 | ||
32907dbd SC |
1386 | if ( str.Length() == 0 ) |
1387 | return ; | |
1388 | ||
3dec57ad | 1389 | wxMacPortSetter helper(this) ; |
66a09d47 | 1390 | MacInstallFont() ; |
99030bdf | 1391 | |
66a09d47 SC |
1392 | wxString text ; |
1393 | if ( wxApp::s_macDefaultEncodingIsPC ) | |
1394 | { | |
1395 | text = wxMacMakeMacStringFromPC( str ) ; | |
1396 | } | |
1397 | else | |
1398 | { | |
1399 | text = str ; | |
1400 | } | |
3dec57ad | 1401 | |
66a09d47 SC |
1402 | wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; |
1403 | if ( 0 ) | |
3dec57ad | 1404 | { |
66a09d47 SC |
1405 | m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize); |
1406 | SetAntiAliasedTextEnabled(true, m_scaleY * font->m_macFontSize); | |
1407 | m_macAliasWasEnabled = true ; | |
3dec57ad | 1408 | } |
99030bdf | 1409 | |
66a09d47 | 1410 | OSStatus status = noErr ; |
99030bdf | 1411 | |
66a09d47 SC |
1412 | TECObjectRef ec; |
1413 | status = TECCreateConverter(&ec, kTextEncodingMacRoman, kTextEncodingUnicodeDefault); | |
1414 | wxASSERT_MSG( status == noErr , "couldn't start converter" ) ; | |
99030bdf | 1415 | |
66a09d47 SC |
1416 | ByteCount byteOutLen ; |
1417 | ByteCount byteInLen = text.Length() ; | |
1418 | ByteCount byteBufferLen = byteInLen *2 ; | |
1419 | char* buf = new char[byteBufferLen] ; | |
99030bdf RD |
1420 | |
1421 | status = TECConvertText(ec, (ConstTextPtr)text.c_str() , byteInLen, &byteInLen, | |
66a09d47 | 1422 | (TextPtr)buf, byteBufferLen, &byteOutLen); |
99030bdf | 1423 | |
66a09d47 SC |
1424 | wxASSERT_MSG( status == noErr , "couldn't convert text" ) ; |
1425 | status = TECDisposeConverter(ec); | |
1426 | wxASSERT_MSG( status == noErr , "couldn't dispose converter" ) ; | |
99030bdf | 1427 | |
66a09d47 SC |
1428 | ATSUTextLayout atsuLayout ; |
1429 | UniCharCount chars = byteOutLen / 2 ; | |
1430 | status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 , | |
1431 | &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; | |
1432 | wxASSERT_MSG( status == noErr , "couldn't create the layout of the rotated text" ); | |
1433 | ||
32907dbd SC |
1434 | if ( abs(angle) > 0 ) |
1435 | { | |
1436 | Fixed atsuAngle = IntToFixed( angle ) ; | |
1437 | ByteCount angleSize = sizeof(Fixed) ; | |
1438 | ATSUAttributeTag rotationTag = kATSULineRotationTag ; | |
1439 | ATSUAttributeValuePtr angleValue = &atsuAngle ; | |
1440 | status = ::ATSUSetLayoutControls(atsuLayout , 1 , &rotationTag , &angleSize , &angleValue ) ; | |
1441 | } | |
66a09d47 | 1442 | |
32907dbd SC |
1443 | status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, |
1444 | IntToFixed(XLOG2DEVMAC(x) ) , IntToFixed(YLOG2DEVMAC(y) ) ); | |
66a09d47 SC |
1445 | wxASSERT_MSG( status == noErr , "couldn't draw the rotated text" ); |
1446 | Rect rect ; | |
1447 | status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, | |
1448 | IntToFixed(XLOG2DEVMAC(x) ) , IntToFixed(YLOG2DEVMAC(y) ) , &rect ); | |
1449 | wxASSERT_MSG( status == noErr , "couldn't measure the rotated text" ); | |
99030bdf | 1450 | |
66a09d47 SC |
1451 | OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ; |
1452 | CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) ); | |
1453 | CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) ); | |
1454 | ::ATSUDisposeTextLayout(atsuLayout); | |
1455 | delete[] buf ; | |
2f1ae414 | 1456 | } |
66a09d47 | 1457 | |
2f1ae414 | 1458 | void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) |
99030bdf | 1459 | { |
3dec57ad SC |
1460 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC")); |
1461 | wxMacPortSetter helper(this) ; | |
519cb848 | 1462 | |
7d9d1fd7 SC |
1463 | long xx = XLOG2DEVMAC(x); |
1464 | long yy = YLOG2DEVMAC(y); | |
99030bdf | 1465 | #if TARGET_CARBON |
32907dbd | 1466 | bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ; |
6606ecac | 1467 | #endif |
66a09d47 | 1468 | MacInstallFont() ; |
99030bdf | 1469 | if ( 0 ) |
66a09d47 SC |
1470 | { |
1471 | m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize); | |
1472 | SetAntiAliasedTextEnabled(true, 8); | |
1473 | m_macAliasWasEnabled = true ; | |
1474 | } | |
99030bdf | 1475 | |
66a09d47 SC |
1476 | FontInfo fi ; |
1477 | ::GetFontInfo( &fi ) ; | |
99030bdf RD |
1478 | |
1479 | #if TARGET_CARBON | |
32907dbd | 1480 | if ( !useDrawThemeText ) |
6606ecac | 1481 | #endif |
32907dbd | 1482 | yy += fi.ascent ; |
99030bdf | 1483 | |
66a09d47 SC |
1484 | ::MoveTo( xx , yy ); |
1485 | if ( m_backgroundMode == wxTRANSPARENT ) | |
519cb848 | 1486 | { |
66a09d47 SC |
1487 | ::TextMode( srcOr) ; |
1488 | } | |
1489 | else | |
1490 | { | |
1491 | ::TextMode( srcCopy ) ; | |
1492 | } | |
519cb848 | 1493 | |
66a09d47 SC |
1494 | const char *text = NULL ; |
1495 | int length = 0 ; | |
1496 | wxString macText ; | |
519cb848 | 1497 | |
66a09d47 SC |
1498 | if ( wxApp::s_macDefaultEncodingIsPC ) |
1499 | { | |
1500 | macText = wxMacMakeMacStringFromPC( strtext ) ; | |
1501 | text = macText ; | |
1502 | length = macText.Length() ; | |
1503 | } | |
1504 | else | |
1505 | { | |
1506 | text = strtext ; | |
1507 | length = strtext.Length() ; | |
1508 | } | |
99030bdf | 1509 | |
66a09d47 SC |
1510 | int laststop = 0 ; |
1511 | int i = 0 ; | |
1512 | int line = 0 ; | |
99030bdf | 1513 | |
32907dbd | 1514 | { |
99030bdf | 1515 | |
32907dbd SC |
1516 | while( i < length ) |
1517 | { | |
1518 | if( text[i] == 13 || text[i] == 10) | |
1519 | { | |
6606ecac | 1520 | #if TARGET_CARBON |
32907dbd SC |
1521 | if ( useDrawThemeText ) |
1522 | { | |
1523 | Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 1000 } ; | |
1524 | CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; | |
1525 | ::DrawThemeTextBox( mString, | |
1526 | kThemeCurrentPortFont, | |
1527 | kThemeStateActive, | |
1528 | true, | |
1529 | &frame, | |
1530 | teJustLeft, | |
1531 | nil ); | |
1532 | CFRelease( mString ) ; | |
1533 | line++ ; | |
1534 | } | |
1535 | else | |
6606ecac | 1536 | #endif |
32907dbd SC |
1537 | { |
1538 | ::DrawText( text , laststop , i - laststop ) ; | |
1539 | line++ ; | |
1540 | ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); | |
1541 | } | |
1542 | laststop = i+1 ; | |
1543 | } | |
1544 | i++ ; | |
1545 | } | |
6606ecac | 1546 | #if TARGET_CARBON |
32907dbd SC |
1547 | if ( useDrawThemeText ) |
1548 | { | |
1549 | Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 1000 } ; | |
1550 | CFStringRef mString = CFStringCreateWithCString( NULL , text + laststop , kCFStringEncodingMacRoman ) ; | |
1551 | ::DrawThemeTextBox( mString, | |
1552 | kThemeCurrentPortFont, | |
1553 | kThemeStateActive, | |
1554 | true, | |
1555 | &frame, | |
1556 | teJustLeft, | |
1557 | nil ); | |
1558 | CFRelease( mString ) ; | |
1559 | } | |
1560 | else | |
6606ecac | 1561 | #endif |
99030bdf | 1562 | { |
32907dbd SC |
1563 | ::DrawText( text , laststop , i - laststop ) ; |
1564 | } | |
519cb848 | 1565 | } |
66a09d47 | 1566 | ::TextMode( srcOr ) ; |
519cb848 SC |
1567 | } |
1568 | ||
99030bdf | 1569 | bool wxDC::CanGetTextExtent() const |
519cb848 | 1570 | { |
3dec57ad | 1571 | wxCHECK_MSG(Ok(), false, wxT("Invalid DC")); |
99030bdf | 1572 | |
519cb848 SC |
1573 | return true ; |
1574 | } | |
1575 | ||
2f1ae414 SC |
1576 | void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height, |
1577 | wxCoord *descent, wxCoord *externalLeading , | |
1578 | wxFont *theFont ) const | |
519cb848 | 1579 | { |
3dec57ad | 1580 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 1581 | wxMacPortSetter helper(this) ; |
519cb848 | 1582 | |
99030bdf RD |
1583 | wxFont formerFont = m_font ; |
1584 | ||
519cb848 SC |
1585 | if ( theFont ) |
1586 | { | |
f52640f3 SC |
1587 | // work around the constness |
1588 | *((wxFont*)(&m_font)) = *theFont ; | |
519cb848 SC |
1589 | } |
1590 | ||
f52640f3 SC |
1591 | MacInstallFont() ; |
1592 | ||
519cb848 SC |
1593 | FontInfo fi ; |
1594 | ::GetFontInfo( &fi ) ; | |
f52640f3 SC |
1595 | #if TARGET_CARBON |
1596 | bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; | |
1597 | #endif | |
519cb848 | 1598 | |
2f1ae414 SC |
1599 | if ( height ) |
1600 | *height = YDEV2LOGREL( fi.descent + fi.ascent ) ; | |
1601 | if ( descent ) | |
1602 | *descent =YDEV2LOGREL( fi.descent ); | |
1603 | if ( externalLeading ) | |
1604 | *externalLeading = YDEV2LOGREL( fi.leading ) ; | |
99030bdf | 1605 | |
519cb848 SC |
1606 | const char *text = NULL ; |
1607 | int length = 0 ; | |
1608 | wxString macText ; | |
1609 | if ( wxApp::s_macDefaultEncodingIsPC ) | |
1610 | { | |
1611 | macText = wxMacMakeMacStringFromPC( string ) ; | |
1612 | text = macText ; | |
1613 | length = macText.Length() ; | |
1614 | } | |
1615 | else | |
1616 | { | |
1617 | text = string ; | |
1618 | length = string.Length() ; | |
1619 | } | |
99030bdf | 1620 | |
519cb848 SC |
1621 | int laststop = 0 ; |
1622 | int i = 0 ; | |
1623 | int curwidth = 0 ; | |
2f1ae414 | 1624 | if ( width ) |
519cb848 | 1625 | { |
2f1ae414 | 1626 | *width = 0 ; |
99030bdf | 1627 | |
2f1ae414 | 1628 | while( i < length ) |
519cb848 | 1629 | { |
2f1ae414 SC |
1630 | if( text[i] == 13 || text[i] == 10) |
1631 | { | |
1632 | if ( height ) | |
1633 | *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; | |
f52640f3 SC |
1634 | #if TARGET_CARBON |
1635 | if ( useGetThemeText ) | |
1636 | { | |
1637 | Point bounds={0,0} ; | |
aee9fe73 | 1638 | SInt16 baseline ; |
f52640f3 SC |
1639 | CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; |
1640 | ::GetThemeTextDimensions( mString, | |
1641 | kThemeCurrentPortFont, | |
1642 | kThemeStateActive, | |
aee9fe73 | 1643 | false, |
f52640f3 | 1644 | &bounds, |
aee9fe73 | 1645 | &baseline ); |
f52640f3 SC |
1646 | CFRelease( mString ) ; |
1647 | curwidth = bounds.h ; | |
1648 | } | |
1649 | else | |
1650 | #endif | |
1651 | { | |
1652 | curwidth = ::TextWidth( text , laststop , i - laststop ) ; | |
1653 | } | |
2f1ae414 SC |
1654 | if ( curwidth > *width ) |
1655 | *width = XDEV2LOGREL( curwidth ) ; | |
1656 | laststop = i+1 ; | |
1657 | } | |
1658 | i++ ; | |
519cb848 | 1659 | } |
f52640f3 SC |
1660 | |
1661 | #if TARGET_CARBON | |
1662 | if ( useGetThemeText ) | |
1663 | { | |
1664 | Point bounds={0,0} ; | |
aee9fe73 | 1665 | SInt16 baseline ; |
f52640f3 SC |
1666 | CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; |
1667 | ::GetThemeTextDimensions( mString, | |
1668 | kThemeCurrentPortFont, | |
1669 | kThemeStateActive, | |
aee9fe73 | 1670 | false, |
f52640f3 | 1671 | &bounds, |
aee9fe73 | 1672 | &baseline ); |
f52640f3 SC |
1673 | CFRelease( mString ) ; |
1674 | curwidth = bounds.h ; | |
1675 | } | |
1676 | else | |
1677 | #endif | |
1678 | { | |
1679 | curwidth = ::TextWidth( text , laststop , i - laststop ) ; | |
1680 | } | |
2f1ae414 SC |
1681 | if ( curwidth > *width ) |
1682 | *width = XDEV2LOGREL( curwidth ) ; | |
519cb848 | 1683 | } |
519cb848 SC |
1684 | |
1685 | if ( theFont ) | |
1686 | { | |
f52640f3 SC |
1687 | // work around the constness |
1688 | *((wxFont*)(&m_font)) = formerFont ; | |
519cb848 SC |
1689 | m_macFontInstalled = false ; |
1690 | } | |
1691 | } | |
1692 | ||
ee41971c | 1693 | wxCoord wxDC::GetCharWidth(void) const |
519cb848 | 1694 | { |
3dec57ad | 1695 | wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); |
99030bdf | 1696 | |
0eaa1d68 | 1697 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1698 | |
1699 | MacInstallFont() ; | |
1700 | ||
c257d44d | 1701 | int width = ::TextWidth( "n" , 0 , 1 ) ; |
519cb848 | 1702 | |
c257d44d | 1703 | return YDEV2LOGREL(width) ; |
519cb848 SC |
1704 | } |
1705 | ||
ee41971c | 1706 | wxCoord wxDC::GetCharHeight(void) const |
519cb848 | 1707 | { |
3dec57ad | 1708 | wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); |
99030bdf | 1709 | |
3dec57ad | 1710 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1711 | |
1712 | MacInstallFont() ; | |
1713 | ||
1714 | FontInfo fi ; | |
1715 | ::GetFontInfo( &fi ) ; | |
1716 | ||
2f1ae414 | 1717 | return YDEV2LOGREL( fi.descent + fi.ascent ); |
519cb848 SC |
1718 | } |
1719 | ||
1720 | void wxDC::Clear(void) | |
1721 | { | |
99030bdf | 1722 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
3dec57ad | 1723 | wxMacPortSetter helper(this) ; |
32907dbd | 1724 | Rect rect = { -31000 , -31000 , 31000 , 31000 } ; |
99030bdf RD |
1725 | |
1726 | if (m_backgroundBrush.GetStyle() != wxTRANSPARENT) | |
519cb848 | 1727 | { |
66a09d47 SC |
1728 | ::PenNormal() ; |
1729 | //MacInstallBrush() ; | |
76a5e5d2 | 1730 | MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ; |
519cb848 | 1731 | ::EraseRect( &rect ) ; |
3dec57ad | 1732 | } |
519cb848 SC |
1733 | } |
1734 | ||
1735 | void wxDC::MacInstallFont() const | |
1736 | { | |
3dec57ad | 1737 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 SC |
1738 | // if ( m_macFontInstalled ) |
1739 | // return ; | |
2f1ae414 | 1740 | Pattern blackColor ; |
99030bdf | 1741 | |
32907dbd | 1742 | MacSetupBackgroundForCurrentPort(m_backgroundBrush) ; |
99030bdf | 1743 | |
519cb848 SC |
1744 | wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; |
1745 | ||
1746 | if ( font ) | |
1747 | { | |
1748 | ::TextFont( font->m_macFontNum ) ; | |
03e11df5 | 1749 | ::TextSize( short(m_scaleY * font->m_macFontSize) ) ; |
519cb848 | 1750 | ::TextFace( font->m_macFontStyle ) ; |
99030bdf | 1751 | |
519cb848 SC |
1752 | m_macFontInstalled = true ; |
1753 | m_macBrushInstalled = false ; | |
1754 | m_macPenInstalled = false ; | |
03e11df5 | 1755 | |
76a5e5d2 SC |
1756 | RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()); |
1757 | RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()); | |
03e11df5 GD |
1758 | ::RGBForeColor( &forecolor ); |
1759 | ::RGBBackColor( &backcolor ); | |
519cb848 SC |
1760 | } |
1761 | else | |
1762 | { | |
32907dbd SC |
1763 | FontFamilyID fontId ; |
1764 | Str255 fontName ; | |
1765 | SInt16 fontSize ; | |
1766 | Style fontStyle ; | |
1767 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; | |
1768 | GetFNum( fontName, &fontId ); | |
99030bdf | 1769 | |
32907dbd SC |
1770 | ::TextFont( fontId ) ; |
1771 | ::TextSize( short(m_scaleY * fontSize) ) ; | |
1772 | ::TextFace( fontStyle ) ; | |
99030bdf | 1773 | |
519cb848 | 1774 | // todo reset after spacing changes - or store the current spacing somewhere |
99030bdf | 1775 | |
519cb848 SC |
1776 | m_macFontInstalled = true ; |
1777 | m_macBrushInstalled = false ; | |
1778 | m_macPenInstalled = false ; | |
519cb848 | 1779 | |
76a5e5d2 SC |
1780 | RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()); |
1781 | RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()); | |
03e11df5 GD |
1782 | ::RGBForeColor( &forecolor ); |
1783 | ::RGBBackColor( &backcolor ); | |
1784 | } | |
519cb848 SC |
1785 | |
1786 | short mode = patCopy ; | |
1787 | ||
1788 | // todo : | |
99030bdf | 1789 | |
519cb848 SC |
1790 | switch( m_logicalFunction ) |
1791 | { | |
1792 | case wxCOPY: // src | |
1793 | mode = patCopy ; | |
1794 | break ; | |
1795 | case wxINVERT: // NOT dst | |
2f1ae414 | 1796 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1797 | mode = patXor ; |
1798 | break ; | |
1799 | case wxXOR: // src XOR dst | |
1800 | mode = patXor ; | |
1801 | break ; | |
1802 | case wxOR_REVERSE: // src OR (NOT dst) | |
1803 | mode = notPatOr ; | |
1804 | break ; | |
1805 | case wxSRC_INVERT: // (NOT src) | |
1806 | mode = notPatCopy ; | |
1807 | break ; | |
1808 | ||
1809 | // unsupported TODO | |
1810 | ||
1811 | case wxCLEAR: // 0 | |
1812 | case wxAND_REVERSE:// src AND (NOT dst) | |
1813 | case wxAND: // src AND dst | |
1814 | case wxAND_INVERT: // (NOT src) AND dst | |
1815 | case wxNO_OP: // dst | |
1816 | case wxNOR: // (NOT src) AND (NOT dst) | |
1817 | case wxEQUIV: // (NOT src) XOR dst | |
1818 | case wxOR_INVERT: // (NOT src) OR dst | |
1819 | case wxNAND: // (NOT src) OR (NOT dst) | |
1820 | case wxOR: // src OR dst | |
1821 | case wxSET: // 1 | |
2f1ae414 SC |
1822 | // case wxSRC_OR: // source _bitmap_ OR destination |
1823 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
1824 | break ; |
1825 | } | |
1826 | ::PenMode( mode ) ; | |
66a09d47 SC |
1827 | |
1828 | OSStatus status = noErr ; | |
99030bdf | 1829 | |
66a09d47 SC |
1830 | Fixed atsuSize = IntToFixed(m_scaleY * font->m_macFontSize) ; |
1831 | ||
1832 | Style qdStyle = font->m_macFontStyle ; | |
1833 | ATSUFontID atsuFont = font->m_macATSUFontID ; | |
1834 | ||
1835 | status = ::ATSUCreateStyle(&(ATSUStyle)m_macATSUIStyle) ; | |
1836 | wxASSERT_MSG( status == noErr , "couldn't create ATSU style" ) ; | |
99030bdf | 1837 | |
66a09d47 SC |
1838 | ATSUAttributeTag atsuTags[] = |
1839 | { | |
1840 | kATSUFontTag , | |
1841 | kATSUSizeTag , | |
32907dbd SC |
1842 | // kATSUColorTag , |
1843 | kATSUBaselineClassTag , | |
1844 | kATSUVerticalCharacterTag, | |
1845 | ||
66a09d47 SC |
1846 | kATSUQDBoldfaceTag , |
1847 | kATSUQDItalicTag , | |
1848 | kATSUQDUnderlineTag , | |
1849 | kATSUQDCondensedTag , | |
1850 | kATSUQDExtendedTag , | |
32907dbd | 1851 | |
66a09d47 | 1852 | } ; |
99030bdf | 1853 | |
66a09d47 SC |
1854 | ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = |
1855 | { | |
1856 | sizeof( ATSUFontID ) , | |
1857 | sizeof( Fixed ) , | |
32907dbd SC |
1858 | // sizeof( RGBColor ) , |
1859 | sizeof( BslnBaselineClass ) , | |
1860 | sizeof( ATSUVerticalCharacterType), | |
99030bdf | 1861 | |
66a09d47 SC |
1862 | sizeof( Boolean ) , |
1863 | sizeof( Boolean ) , | |
1864 | sizeof( Boolean ) , | |
1865 | sizeof( Boolean ) , | |
1866 | sizeof( Boolean ) , | |
32907dbd | 1867 | |
66a09d47 | 1868 | } ; |
99030bdf | 1869 | |
66a09d47 SC |
1870 | Boolean kTrue = true ; |
1871 | Boolean kFalse = false ; | |
32907dbd SC |
1872 | BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ; |
1873 | ||
1874 | ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; | |
66a09d47 SC |
1875 | |
1876 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = | |
1877 | { | |
1878 | &atsuFont , | |
1879 | &atsuSize , | |
32907dbd SC |
1880 | // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) , |
1881 | &kBaselineDefault , | |
1882 | &kHorizontal, | |
1883 | ||
66a09d47 SC |
1884 | (qdStyle & bold) ? &kTrue : &kFalse , |
1885 | (qdStyle & italic) ? &kTrue : &kFalse , | |
1886 | (qdStyle & underline) ? &kTrue : &kFalse , | |
1887 | (qdStyle & condense) ? &kTrue : &kFalse , | |
1888 | (qdStyle & extend) ? &kTrue : &kFalse , | |
1889 | } ; | |
99030bdf RD |
1890 | |
1891 | status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag), | |
66a09d47 SC |
1892 | atsuTags, atsuSizes, atsuValues); |
1893 | wxASSERT_MSG( status == noErr , "couldn't set create ATSU style" ) ; | |
1894 | ||
519cb848 SC |
1895 | } |
1896 | ||
ffd67837 | 1897 | Pattern gHatchPatterns[] = |
99030bdf | 1898 | { |
ffd67837 SC |
1899 | { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } , |
1900 | { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } , | |
1901 | { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } , | |
1902 | { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } , | |
1903 | { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } , | |
1904 | { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } , | |
1905 | { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } , | |
1906 | } ; | |
1907 | ||
519cb848 SC |
1908 | static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern) |
1909 | { | |
ffd67837 | 1910 | int theIndex = 1 ; |
99030bdf | 1911 | |
519cb848 SC |
1912 | switch(hatchStyle) |
1913 | { | |
1914 | case wxBDIAGONAL_HATCH: | |
99030bdf | 1915 | theIndex = 2; |
519cb848 SC |
1916 | break; |
1917 | case wxFDIAGONAL_HATCH: | |
75f7bc3b | 1918 | theIndex = 3; |
519cb848 SC |
1919 | break; |
1920 | case wxCROSS_HATCH: | |
75f7bc3b | 1921 | theIndex = 4; |
519cb848 SC |
1922 | break; |
1923 | case wxHORIZONTAL_HATCH: | |
75f7bc3b | 1924 | theIndex = 5; |
519cb848 SC |
1925 | break; |
1926 | case wxVERTICAL_HATCH: | |
1927 | theIndex = 6; | |
1928 | break; | |
1929 | case wxCROSSDIAG_HATCH: | |
99030bdf | 1930 | theIndex = 7; |
519cb848 SC |
1931 | break; |
1932 | default: | |
1933 | theIndex = 1; // solid pattern | |
1934 | break; | |
1935 | } | |
99030bdf | 1936 | *pattern = gHatchPatterns[theIndex-1] ; |
519cb848 SC |
1937 | } |
1938 | ||
1939 | void wxDC::MacInstallPen() const | |
1940 | { | |
3dec57ad | 1941 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 | 1942 | |
2f1ae414 SC |
1943 | Pattern blackColor; |
1944 | ||
0eaa1d68 SC |
1945 | // if ( m_macPenInstalled ) |
1946 | // return ; | |
519cb848 | 1947 | |
76a5e5d2 SC |
1948 | RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel()); |
1949 | RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()); | |
03e11df5 GD |
1950 | ::RGBForeColor( &forecolor ); |
1951 | ::RGBBackColor( &backcolor ); | |
99030bdf | 1952 | |
519cb848 | 1953 | ::PenNormal() ; |
3dec57ad | 1954 | int penWidth = m_pen.GetWidth() * (int) m_scaleX ; |
0b014ec7 SC |
1955 | |
1956 | // null means only one pixel, at whatever resolution | |
1957 | if ( penWidth == 0 ) | |
99030bdf | 1958 | penWidth = 1 ; |
519cb848 SC |
1959 | ::PenSize(penWidth, penWidth); |
1960 | ||
1961 | int penStyle = m_pen.GetStyle(); | |
99030bdf | 1962 | |
519cb848 | 1963 | if (penStyle == wxSOLID) |
03e11df5 | 1964 | { |
2f1ae414 | 1965 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
03e11df5 | 1966 | } |
519cb848 SC |
1967 | else if (IS_HATCH(penStyle)) |
1968 | { | |
1969 | Pattern pat ; | |
1970 | wxMacGetHatchPattern(penStyle, &pat); | |
1971 | ::PenPat(&pat); | |
1972 | } | |
1973 | else | |
1974 | { | |
1ff301c4 SC |
1975 | Pattern pat = *GetQDGlobalsBlack(&blackColor) ; |
1976 | switch( penStyle ) | |
1977 | { | |
1978 | case wxDOT : | |
1979 | for ( int i = 0 ; i < 8 ; ++i ) | |
1980 | { | |
1981 | pat.pat[i] = 0xCC ; | |
1982 | } | |
1983 | break ; | |
1984 | case wxLONG_DASH : | |
1985 | for ( int i = 0 ; i < 8 ; ++i ) | |
1986 | { | |
1987 | pat.pat[i] = 0xFE ; | |
1988 | } | |
1989 | break ; | |
1990 | case wxSHORT_DASH : | |
1991 | for ( int i = 0 ; i < 8 ; ++i ) | |
1992 | { | |
1993 | pat.pat[i] = 0xEE ; | |
1994 | } | |
1995 | break ; | |
1996 | case wxDOT_DASH : | |
1997 | for ( int i = 0 ; i < 8 ; ++i ) | |
1998 | { | |
1999 | pat.pat[i] = 0x6F ; | |
2000 | } | |
2001 | break ; | |
2002 | case wxUSER_DASH : | |
2003 | { | |
2004 | wxDash* dash ; | |
2005 | int number = m_pen.GetDashes(&dash) ; | |
2006 | // right now we don't allocate larger pixmaps | |
2007 | for ( int i = 0 ; i < 8 ; ++i ) | |
2008 | { | |
2009 | pat.pat[i] = dash[0] ; | |
2010 | } | |
2011 | } | |
2012 | break ; | |
2013 | } | |
2014 | ::PenPat(&pat); | |
519cb848 SC |
2015 | } |
2016 | ||
2017 | short mode = patCopy ; | |
99030bdf | 2018 | |
519cb848 | 2019 | // todo : |
99030bdf | 2020 | |
519cb848 SC |
2021 | switch( m_logicalFunction ) |
2022 | { | |
1ff301c4 SC |
2023 | case wxCOPY: // only foreground color, leave background (thus not patCopy) |
2024 | mode = patOr ; | |
519cb848 SC |
2025 | break ; |
2026 | case wxINVERT: // NOT dst | |
1ff301c4 | 2027 | // ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
2028 | mode = patXor ; |
2029 | break ; | |
2030 | case wxXOR: // src XOR dst | |
2031 | mode = patXor ; | |
2032 | break ; | |
2033 | case wxOR_REVERSE: // src OR (NOT dst) | |
2034 | mode = notPatOr ; | |
2035 | break ; | |
2036 | case wxSRC_INVERT: // (NOT src) | |
2037 | mode = notPatCopy ; | |
2038 | break ; | |
2039 | ||
2040 | // unsupported TODO | |
2041 | ||
2042 | case wxCLEAR: // 0 | |
2043 | case wxAND_REVERSE:// src AND (NOT dst) | |
2044 | case wxAND: // src AND dst | |
2045 | case wxAND_INVERT: // (NOT src) AND dst | |
2046 | case wxNO_OP: // dst | |
2047 | case wxNOR: // (NOT src) AND (NOT dst) | |
2048 | case wxEQUIV: // (NOT src) XOR dst | |
2049 | case wxOR_INVERT: // (NOT src) OR dst | |
2050 | case wxNAND: // (NOT src) OR (NOT dst) | |
2051 | case wxOR: // src OR dst | |
2052 | case wxSET: // 1 | |
2f1ae414 SC |
2053 | // case wxSRC_OR: // source _bitmap_ OR destination |
2054 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
2055 | break ; |
2056 | } | |
2057 | ::PenMode( mode ) ; | |
2058 | m_macPenInstalled = true ; | |
2059 | m_macBrushInstalled = false ; | |
2060 | m_macFontInstalled = false ; | |
2061 | } | |
2062 | ||
99030bdf | 2063 | void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background ) |
1dcbbdcf SC |
2064 | { |
2065 | Pattern whiteColor ; | |
7d9d1fd7 SC |
2066 | switch( background.MacGetBrushKind() ) |
2067 | { | |
2068 | case kwxMacBrushTheme : | |
2069 | { | |
2070 | ::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ; | |
2071 | break ; | |
2072 | } | |
2073 | case kwxMacBrushThemeBackground : | |
2074 | { | |
2075 | Rect extent ; | |
2076 | ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ; | |
2077 | ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ; | |
2078 | break ; | |
2079 | } | |
2080 | case kwxMacBrushColour : | |
2081 | { | |
66a09d47 | 2082 | ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) ); |
7d9d1fd7 SC |
2083 | int brushStyle = background.GetStyle(); |
2084 | if (brushStyle == wxSOLID) | |
2085 | ::BackPat(GetQDGlobalsWhite(&whiteColor)); | |
2086 | else if (IS_HATCH(brushStyle)) | |
2087 | { | |
2088 | Pattern pat ; | |
2089 | wxMacGetHatchPattern(brushStyle, &pat); | |
2090 | ::BackPat(&pat); | |
2091 | } | |
2092 | else | |
2093 | { | |
2094 | ::BackPat(GetQDGlobalsWhite(&whiteColor)); | |
2095 | } | |
2096 | break ; | |
2097 | } | |
2098 | } | |
1dcbbdcf SC |
2099 | } |
2100 | ||
519cb848 SC |
2101 | void wxDC::MacInstallBrush() const |
2102 | { | |
3dec57ad | 2103 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 2104 | |
1dcbbdcf | 2105 | Pattern blackColor ; |
0eaa1d68 SC |
2106 | // if ( m_macBrushInstalled ) |
2107 | // return ; | |
519cb848 SC |
2108 | |
2109 | // foreground | |
99030bdf | 2110 | |
76a5e5d2 | 2111 | bool backgroundTransparent = (GetBackgroundMode() == wxTRANSPARENT) ; |
519cb848 | 2112 | |
76a5e5d2 | 2113 | ::RGBForeColor( &MAC_WXCOLORREF( m_brush.GetColour().GetPixel()) ); |
0d54461f | 2114 | ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) ); |
519cb848 SC |
2115 | |
2116 | int brushStyle = m_brush.GetStyle(); | |
2117 | if (brushStyle == wxSOLID) | |
0d54461f | 2118 | { |
2f1ae414 | 2119 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
0d54461f | 2120 | } |
519cb848 SC |
2121 | else if (IS_HATCH(brushStyle)) |
2122 | { | |
2123 | Pattern pat ; | |
2124 | wxMacGetHatchPattern(brushStyle, &pat); | |
2125 | ::PenPat(&pat); | |
2126 | } | |
1ff301c4 | 2127 | else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE ) |
519cb848 | 2128 | { |
76a5e5d2 SC |
2129 | // we force this in order to be compliant with wxMSW |
2130 | backgroundTransparent = false ; | |
1ff301c4 SC |
2131 | // for these the text fore (and back for MASK_OPAQUE) colors are used |
2132 | wxBitmap* bitmap = m_brush.GetStipple() ; | |
2133 | int width = bitmap->GetWidth() ; | |
2134 | int height = bitmap->GetHeight() ; | |
76a5e5d2 SC |
2135 | GWorldPtr gw = NULL ; |
2136 | ||
1ff301c4 | 2137 | if ( m_brush.GetStyle() == wxSTIPPLE ) |
76a5e5d2 | 2138 | gw = MAC_WXHBITMAP(bitmap->GetHBITMAP()) ; |
99030bdf | 2139 | else |
76a5e5d2 | 2140 | gw = MAC_WXHBITMAP(bitmap->GetMask()->GetMaskBitmap()) ; |
99030bdf | 2141 | |
76a5e5d2 SC |
2142 | PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ; |
2143 | LockPixels( gwpixmaphandle ) ; | |
2144 | ||
2145 | bool isMonochrome = !IsPortColor( gw ) ; | |
2146 | ||
2147 | if ( !isMonochrome ) | |
2148 | { | |
2149 | if ( (**gwpixmaphandle).pixelSize == 1 ) | |
2150 | isMonochrome = true ; | |
2151 | } | |
2152 | ||
66a09d47 | 2153 | if ( isMonochrome && width == 8 && height == 8 ) |
1ff301c4 | 2154 | { |
76a5e5d2 | 2155 | ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ); |
0d54461f | 2156 | ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ); |
76a5e5d2 SC |
2157 | BitMap* gwbitmap = (BitMap*) *gwpixmaphandle ; // since the color depth is 1 it is a BitMap |
2158 | UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ; | |
2159 | int alignment = gwbitmap->rowBytes & 0x7FFF ; | |
66a09d47 SC |
2160 | Pattern pat ; |
2161 | for ( int i = 0 ; i < 8 ; ++i ) | |
2162 | { | |
2163 | pat.pat[i] = gwbits[i*alignment+0] ; | |
2164 | } | |
2165 | UnlockPixels( GetGWorldPixMap( gw ) ) ; | |
2166 | ::PenPat( &pat ) ; | |
2167 | } | |
2168 | else | |
2169 | { | |
76a5e5d2 SC |
2170 | // this will be the code to handle power of 2 patterns, we will have to arrive at a nice |
2171 | // caching scheme before putting this into production | |
66a09d47 SC |
2172 | Handle image; |
2173 | long imageSize; | |
2174 | PixPatHandle pixpat = NewPixPat() ; | |
2175 | ||
2176 | CopyPixMap(gwpixmaphandle, (**pixpat).patMap); | |
2177 | imageSize = GetPixRowBytes((**pixpat).patMap) * | |
2178 | ((**(**pixpat).patMap).bounds.bottom - | |
2179 | (**(**pixpat).patMap).bounds.top); | |
99030bdf | 2180 | |
66a09d47 SC |
2181 | PtrToHand( (**gwpixmaphandle).baseAddr, &image, imageSize ); |
2182 | (**pixpat).patData = image; | |
2183 | if ( isMonochrome ) | |
2184 | { | |
76a5e5d2 SC |
2185 | CTabHandle ctable = ((**((**pixpat).patMap)).pmTable) ; |
2186 | ColorSpecPtr ctspec = (ColorSpecPtr) &(**ctable).ctTable ; | |
2187 | if ( ctspec[0].rgb.red == 0x0000 ) | |
2188 | { | |
2189 | ctspec[1].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ; | |
2190 | ctspec[0].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ; | |
2191 | } | |
2192 | else | |
2193 | { | |
2194 | ctspec[0].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ; | |
2195 | ctspec[1].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ; | |
2196 | } | |
2197 | ::CTabChanged( ctable ) ; | |
66a09d47 SC |
2198 | } |
2199 | ::PenPixPat(pixpat); | |
2200 | m_macForegroundPixMap = pixpat ; | |
1ff301c4 | 2201 | } |
76a5e5d2 | 2202 | UnlockPixels( gwpixmaphandle ) ; |
1ff301c4 SC |
2203 | } |
2204 | else | |
2205 | { | |
2206 | ::PenPat(GetQDGlobalsBlack(&blackColor)); | |
519cb848 | 2207 | } |
99030bdf | 2208 | |
1dcbbdcf | 2209 | short mode = patCopy ; |
519cb848 SC |
2210 | switch( m_logicalFunction ) |
2211 | { | |
2212 | case wxCOPY: // src | |
76a5e5d2 SC |
2213 | if ( backgroundTransparent ) |
2214 | mode = patOr ; | |
2215 | else | |
2216 | mode = patCopy ; | |
519cb848 SC |
2217 | break ; |
2218 | case wxINVERT: // NOT dst | |
76a5e5d2 SC |
2219 | if ( !backgroundTransparent ) |
2220 | { | |
2221 | ::PenPat(GetQDGlobalsBlack(&blackColor)); | |
2222 | } | |
519cb848 SC |
2223 | mode = patXor ; |
2224 | break ; | |
2225 | case wxXOR: // src XOR dst | |
2226 | mode = patXor ; | |
2227 | break ; | |
2228 | case wxOR_REVERSE: // src OR (NOT dst) | |
2229 | mode = notPatOr ; | |
2230 | break ; | |
2231 | case wxSRC_INVERT: // (NOT src) | |
2232 | mode = notPatCopy ; | |
2233 | break ; | |
2234 | ||
2235 | // unsupported TODO | |
2236 | ||
2237 | case wxCLEAR: // 0 | |
2238 | case wxAND_REVERSE:// src AND (NOT dst) | |
2239 | case wxAND: // src AND dst | |
2240 | case wxAND_INVERT: // (NOT src) AND dst | |
2241 | case wxNO_OP: // dst | |
2242 | case wxNOR: // (NOT src) AND (NOT dst) | |
2243 | case wxEQUIV: // (NOT src) XOR dst | |
2244 | case wxOR_INVERT: // (NOT src) OR dst | |
2245 | case wxNAND: // (NOT src) OR (NOT dst) | |
2246 | case wxOR: // src OR dst | |
2247 | case wxSET: // 1 | |
2f1ae414 SC |
2248 | // case wxSRC_OR: // source _bitmap_ OR destination |
2249 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
2250 | break ; |
2251 | } | |
2252 | ::PenMode( mode ) ; | |
2253 | m_macBrushInstalled = true ; | |
2254 | m_macPenInstalled = false ; | |
2255 | m_macFontInstalled = false ; | |
2256 | } | |
2257 | ||
2f1ae414 SC |
2258 | // --------------------------------------------------------------------------- |
2259 | // coordinates transformations | |
2260 | // --------------------------------------------------------------------------- | |
519cb848 | 2261 | |
2f1ae414 SC |
2262 | |
2263 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
2264 | { | |
2265 | return ((wxDC *)this)->XDEV2LOG(x); | |
2266 | } | |
2267 | ||
2268 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
2269 | { | |
2270 | return ((wxDC *)this)->YDEV2LOG(y); | |
2271 | } | |
2272 | ||
2273 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
2274 | { | |
2275 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
2276 | } | |
2277 | ||
2278 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
2279 | { | |
2280 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
2281 | } | |
2282 | ||
2283 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
2284 | { | |
2285 | return ((wxDC *)this)->XLOG2DEV(x); | |
2286 | } | |
2287 | ||
2288 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
2289 | { | |
2290 | return ((wxDC *)this)->YLOG2DEV(y); | |
2291 | } | |
2292 | ||
2293 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
2294 | { | |
2295 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
2296 | } | |
2297 | ||
2298 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
2299 | { | |
2300 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
2301 | } |