]>
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 SC |
56 | wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : |
57 | m_ph( (GrafPtr) dc->m_macPort ) | |
58 | { | |
59 | wxASSERT( dc->Ok() ) ; | |
60 | m_dc = dc ; | |
61 | dc->MacSetupPort(&m_ph) ; | |
62 | } | |
63 | ||
64 | wxMacPortSetter::~wxMacPortSetter() | |
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; |
e9576ca5 | 174 | |
2f1ae414 SC |
175 | m_mm_to_pix_x = mm2pt; |
176 | m_mm_to_pix_y = mm2pt; | |
e9576ca5 | 177 | |
e9576ca5 SC |
178 | m_internalDeviceOriginX = 0; |
179 | m_internalDeviceOriginY = 0; | |
180 | m_externalDeviceOriginX = 0; | |
181 | m_externalDeviceOriginY = 0; | |
182 | ||
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; | |
189 | ||
e9576ca5 SC |
190 | m_needComputeScaleX = FALSE; |
191 | m_needComputeScaleY = FALSE; | |
192 | ||
519cb848 | 193 | m_macPort = NULL ; |
8208e181 | 194 | m_macMask = NULL ; |
519cb848 SC |
195 | m_ok = FALSE ; |
196 | ||
197 | m_macFontInstalled = false ; | |
198 | m_macBrushInstalled = false ; | |
199 | m_macPenInstalled = false ; | |
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 ; | |
231 | m_macPenInstalled = false ; | |
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 SC |
266 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
267 | ||
268 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
269 | ||
270 | wxMacPortSetter helper(this) ; | |
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); | |
278 | ||
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 ); | |
293 | ||
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 SC |
302 | PixMapHandle bmappixels ; |
303 | ||
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 | } | |
319 | ||
320 | bmappixels = GetGWorldPixMap( bmapworld ) ; | |
321 | ||
322 | wxCHECK_RET(LockPixels(bmappixels), | |
323 | wxT("DoDrawBitmap: Unable to lock pixels")); | |
324 | ||
325 | Rect source = { 0, 0, h, w }; | |
326 | Rect dest = { yy, xx, yy + hh, xx + ww }; | |
327 | ||
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 SC |
363 | wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon")); |
364 | ||
365 | wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon")); | |
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 ) ; | |
ffba56ed | 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; |
3dec57ad | 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 | { | |
486 | switch (mode) | |
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 | ||
584 | // CMB: if scale has changed call SetPen to recalulate the line width | |
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 ; | |
614 | ||
615 | m_pen = pen; | |
3dec57ad | 616 | |
519cb848 SC |
617 | m_macPenInstalled = false ; |
618 | } | |
619 | ||
620 | void wxDC::SetBrush( const wxBrush &brush ) | |
621 | { | |
519cb848 SC |
622 | if (m_brush == brush) |
623 | return; | |
624 | ||
625 | m_brush = brush; | |
626 | m_macBrushInstalled = false ; | |
627 | } | |
628 | ||
629 | void wxDC::SetBackground( const wxBrush &brush ) | |
630 | { | |
519cb848 SC |
631 | if (m_backgroundBrush == brush) |
632 | return; | |
633 | ||
634 | m_backgroundBrush = brush; | |
635 | ||
636 | if (!m_backgroundBrush.Ok()) | |
637 | return; | |
638 | m_macBrushInstalled = false ; | |
639 | } | |
640 | ||
641 | void wxDC::SetLogicalFunction( int function ) | |
642 | { | |
643 | if (m_logicalFunction == function) | |
644 | return; | |
645 | ||
646 | m_logicalFunction = function ; | |
647 | m_macFontInstalled = false ; | |
648 | m_macBrushInstalled = false ; | |
649 | m_macPenInstalled = false ; | |
650 | } | |
651 | ||
2f1ae414 SC |
652 | void wxDC::DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, |
653 | int style ) | |
519cb848 | 654 | { |
b1699cd3 JS |
655 | if (GetBrush().GetStyle() == wxTRANSPARENT) |
656 | { | |
657 | wxLogDebug(wxT("In FloodFill, Current Brush is transparent, no filling done")); | |
658 | return ; | |
659 | } | |
660 | int height = 0; | |
661 | int width = 0; | |
662 | this->GetSize(&width, &height); | |
663 | //it would be nice to fail if we don't get a sensible size... | |
664 | if (width < 1 || height < 1) | |
665 | { | |
666 | wxLogError(wxT("In FloodFill, dc.GetSize routine failed, method not supported by this DC")); | |
667 | return ; | |
668 | } | |
669 | ||
670 | //this is much faster than doing the individual pixels | |
671 | wxMemoryDC memdc; | |
672 | wxBitmap bitmap(width, height); | |
673 | memdc.SelectObject(bitmap); | |
674 | memdc.Blit(0, 0, width, height, (wxDC*) this, 0, 0); | |
675 | memdc.SelectObject(wxNullBitmap); | |
676 | ||
71110b40 | 677 | wxImage image = bitmap.ConvertToImage() ; |
b1699cd3 JS |
678 | image.DoFloodFill (x,y, GetBrush(), col, style, GetLogicalFunction()); |
679 | bitmap = wxBitmap(image); | |
680 | memdc.SelectObject(bitmap); | |
681 | this->Blit(0, 0, width, height, &memdc, 0, 0); | |
682 | memdc.SelectObject(wxNullBitmap); | |
71110b40 SC |
683 | } |
684 | ||
685 | ||
2f1ae414 | 686 | bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const |
519cb848 | 687 | { |
3dec57ad SC |
688 | wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); |
689 | wxMacPortSetter helper(this) ; | |
690 | ||
691 | RGBColor colour; | |
692 | ||
7d9d1fd7 | 693 | GetCPixel( XLOG2DEVMAC(x), YLOG2DEVMAC(y), &colour ); |
3dec57ad SC |
694 | |
695 | // Convert from Mac colour to wx | |
696 | col->Set( colour.red >> 8, | |
697 | colour.green >> 8, | |
698 | colour.blue >> 8); | |
699 | ||
700 | return true ; | |
519cb848 SC |
701 | } |
702 | ||
2f1ae414 | 703 | void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
519cb848 | 704 | { |
3dec57ad | 705 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 | 706 | |
0eaa1d68 | 707 | wxMacPortSetter helper(this) ; |
519cb848 SC |
708 | |
709 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
710 | { | |
711 | MacInstallPen() ; | |
3dec57ad SC |
712 | wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 : |
713 | m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2; | |
714 | ||
7d9d1fd7 SC |
715 | wxCoord xx1 = XLOG2DEVMAC(x1) - offset; |
716 | wxCoord yy1 = YLOG2DEVMAC(y1) - offset; | |
717 | wxCoord xx2 = XLOG2DEVMAC(x2) - offset; | |
718 | wxCoord yy2 = YLOG2DEVMAC(y2) - offset; | |
2301e281 RR |
719 | |
720 | if ((m_pen.GetCap() == wxCAP_ROUND) && | |
721 | (m_pen.GetWidth() <= 1)) | |
722 | { | |
723 | // Implement LAST_NOT for MAC at least for | |
724 | // orthogonal lines. RR. | |
725 | if (xx1 == xx2) | |
726 | { | |
727 | if (yy1 < yy2) | |
728 | yy2--; | |
729 | if (yy1 > yy2) | |
730 | yy2++; | |
731 | } | |
732 | if (yy1 == yy2) | |
733 | { | |
734 | if (xx1 < xx2) | |
735 | xx2--; | |
736 | if (xx1 > xx2) | |
737 | xx2++; | |
738 | } | |
739 | } | |
740 | ||
741 | ::MoveTo(xx1, yy1); | |
742 | ::LineTo(xx2, yy2); | |
3dec57ad | 743 | } |
519cb848 SC |
744 | } |
745 | ||
2f1ae414 | 746 | void wxDC::DoCrossHair( wxCoord x, wxCoord y ) |
519cb848 | 747 | { |
3dec57ad SC |
748 | wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") ); |
749 | ||
750 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
751 | { | |
752 | int w = 0; | |
753 | int h = 0; | |
754 | GetSize( &w, &h ); | |
7d9d1fd7 SC |
755 | wxCoord xx = XLOG2DEVMAC(x); |
756 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
757 | |
758 | MacInstallPen(); | |
7d9d1fd7 SC |
759 | ::MoveTo( XLOG2DEVMAC(0), yy ); |
760 | ::LineTo( XLOG2DEVMAC(w), yy ); | |
761 | ::MoveTo( xx, YLOG2DEVMAC(0) ); | |
762 | ::LineTo( xx, YLOG2DEVMAC(h) ); | |
66a09d47 SC |
763 | |
764 | CalcBoundingBox(x, y); | |
765 | CalcBoundingBox(x+w, y+h); | |
766 | ||
3dec57ad SC |
767 | } |
768 | } | |
769 | ||
770 | /* | |
771 | * To draw arcs properly the angles need to be converted from the WX style: | |
772 | * Angles start on the +ve X axis and go anti-clockwise (As you would draw on | |
773 | * a normal axis on paper). | |
774 | * TO | |
775 | * the Mac style: | |
776 | * Angles start on the +ve y axis and go clockwise. | |
777 | * To achive this I work out which quadrant the angle lies in then map this to | |
778 | * the equivalent quadrant on the Mac. (Sin and Cos values reveal which | |
779 | * quadrant you are in). | |
780 | */ | |
781 | static double wxConvertWXangleToMACangle(double angle) | |
782 | { | |
783 | double sin_a, cos_a; | |
784 | ||
785 | sin_a = sin(angle / RAD2DEG); | |
786 | cos_a = cos(angle / RAD2DEG); | |
787 | ||
788 | if( (sin_a >= 0.0) && (cos_a >= 0.0) ) { | |
789 | angle = acos(sin_a) * RAD2DEG; | |
790 | } | |
791 | else if( (sin_a >= 0.0) && (cos_a <= 0.0) ) { | |
792 | sin_a *= -1; | |
793 | angle = acos(sin_a) * RAD2DEG + 180; | |
794 | } | |
795 | else if( (sin_a <= 0.0) && (cos_a >= 0.0) ) { | |
796 | angle = acos(sin_a) * RAD2DEG + 180; | |
797 | } | |
798 | else if( (sin_a < 0.0) && (cos_a < 0.0) ) { | |
799 | sin_a *= -1; | |
800 | angle = acos(sin_a) * RAD2DEG + 180; | |
801 | } | |
802 | return angle; | |
519cb848 SC |
803 | } |
804 | ||
2f1ae414 SC |
805 | void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, |
806 | wxCoord x2, wxCoord y2, | |
807 | wxCoord xc, wxCoord yc ) | |
519cb848 | 808 | { |
3dec57ad SC |
809 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC")); |
810 | ||
7d9d1fd7 SC |
811 | wxCoord xx1 = XLOG2DEVMAC(x1); |
812 | wxCoord yy1 = YLOG2DEVMAC(y1); | |
813 | wxCoord xx2 = XLOG2DEVMAC(x2); | |
814 | wxCoord yy2 = YLOG2DEVMAC(y2); | |
815 | wxCoord xxc = XLOG2DEVMAC(xc); | |
816 | wxCoord yyc = YLOG2DEVMAC(yc); | |
3dec57ad SC |
817 | double dx = xx1 - xxc; |
818 | double dy = yy1 - yyc; | |
819 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
820 | wxCoord rad = (wxCoord)radius; | |
821 | double radius1, radius2; | |
822 | ||
823 | if (xx1 == xx2 && yy1 == yy2) | |
824 | { | |
825 | radius1 = 0.0; | |
826 | radius2 = 360.0; | |
827 | } | |
828 | else if (radius == 0.0) | |
829 | { | |
830 | radius1 = radius2 = 0.0; | |
831 | } | |
832 | else | |
833 | { | |
834 | radius1 = (xx1 - xxc == 0) ? | |
835 | (yy1 - yyc < 0) ? 90.0 : -90.0 : | |
836 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
837 | radius2 = (xx2 - xxc == 0) ? | |
838 | (yy2 - yyc < 0) ? 90.0 : -90.0 : | |
839 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
840 | } | |
841 | wxCoord alpha2 = wxCoord(radius2 - radius1); | |
842 | wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1)); | |
843 | if( (xx1 > xx2) || (yy1 > yy2) ) { | |
844 | alpha2 *= -1; | |
845 | } | |
846 | ||
847 | Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad }; | |
848 | ||
849 | if(m_brush.GetStyle() != wxTRANSPARENT) { | |
850 | MacInstallBrush(); | |
851 | PaintArc(&r, alpha1, alpha2); | |
852 | } | |
853 | if(m_pen.GetStyle() != wxTRANSPARENT) { | |
854 | MacInstallPen(); | |
855 | FrameArc(&r, alpha1, alpha2); | |
856 | } | |
519cb848 SC |
857 | } |
858 | ||
2f1ae414 SC |
859 | void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
860 | double sa, double ea ) | |
519cb848 | 861 | { |
3dec57ad SC |
862 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC")); |
863 | ||
864 | Rect r; | |
865 | double angle = sa - ea; // Order important Mac in opposite direction to wx | |
866 | ||
7d9d1fd7 SC |
867 | wxCoord xx = XLOG2DEVMAC(x); |
868 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
869 | wxCoord ww = m_signX * XLOG2DEVREL(w); |
870 | wxCoord hh = m_signY * YLOG2DEVREL(h); | |
871 | ||
872 | // handle -ve width and/or height | |
873 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
874 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
875 | ||
876 | sa = wxConvertWXangleToMACangle(sa); | |
877 | ||
878 | r.top = yy; | |
879 | r.left = xx; | |
880 | r.bottom = yy + hh; | |
881 | r.right = xx + ww; | |
882 | ||
883 | if(m_brush.GetStyle() != wxTRANSPARENT) { | |
884 | MacInstallBrush(); | |
885 | PaintArc(&r, (short)sa, (short)angle); | |
886 | } | |
887 | if(m_pen.GetStyle() != wxTRANSPARENT) { | |
888 | MacInstallPen(); | |
889 | FrameArc(&r, (short)sa, (short)angle); | |
890 | } | |
519cb848 SC |
891 | } |
892 | ||
2f1ae414 | 893 | void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) |
519cb848 | 894 | { |
3dec57ad | 895 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 | 896 | |
0eaa1d68 | 897 | wxMacPortSetter helper(this) ; |
519cb848 SC |
898 | |
899 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
900 | { | |
901 | MacInstallPen() ; | |
7d9d1fd7 SC |
902 | wxCoord xx1 = XLOG2DEVMAC(x); |
903 | wxCoord yy1 = YLOG2DEVMAC(y); | |
519cb848 SC |
904 | |
905 | ::MoveTo(xx1,yy1); | |
906 | ::LineTo(xx1+1, yy1+1); | |
3dec57ad | 907 | } |
519cb848 SC |
908 | } |
909 | ||
2f1ae414 SC |
910 | void wxDC::DoDrawLines(int n, wxPoint points[], |
911 | wxCoord xoffset, wxCoord yoffset) | |
519cb848 | 912 | { |
3dec57ad | 913 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 914 | wxMacPortSetter helper(this) ; |
519cb848 SC |
915 | |
916 | if (m_pen.GetStyle() == wxTRANSPARENT) | |
917 | return; | |
918 | ||
03e11df5 | 919 | MacInstallPen() ; |
519cb848 | 920 | |
3dec57ad SC |
921 | wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 : |
922 | m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2 ; | |
923 | ||
924 | wxCoord x1, x2 , y1 , y2 ; | |
7d9d1fd7 SC |
925 | x1 = XLOG2DEVMAC(points[0].x + xoffset); |
926 | y1 = YLOG2DEVMAC(points[0].y + yoffset); | |
3dec57ad | 927 | ::MoveTo(x1 - offset, y1 - offset ); |
519cb848 SC |
928 | |
929 | for (int i = 0; i < n-1; i++) | |
930 | { | |
7d9d1fd7 SC |
931 | x2 = XLOG2DEVMAC(points[i+1].x + xoffset); |
932 | y2 = YLOG2DEVMAC(points[i+1].y + yoffset); | |
3dec57ad | 933 | ::LineTo( x2 - offset, y2 - offset ); |
519cb848 SC |
934 | } |
935 | } | |
936 | ||
2f1ae414 SC |
937 | void wxDC::DoDrawPolygon(int n, wxPoint points[], |
938 | wxCoord xoffset, wxCoord yoffset, | |
939 | int fillStyle ) | |
519cb848 | 940 | { |
32ea1f98 RR |
941 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
942 | wxMacPortSetter helper(this) ; | |
943 | ||
944 | wxCoord x1, x2 , y1 , y2 ; | |
519cb848 | 945 | |
75f7bc3b SC |
946 | if ( m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) |
947 | return ; | |
948 | ||
949 | PolyHandle polygon = OpenPoly(); | |
950 | ||
951 | x1 = XLOG2DEVMAC(points[0].x + xoffset); | |
952 | y1 = YLOG2DEVMAC(points[0].y + yoffset); | |
953 | ::MoveTo(x1,y1); | |
954 | ||
76a5e5d2 | 955 | for (int i = 1; i < n; i++) |
75f7bc3b | 956 | { |
76a5e5d2 SC |
957 | x2 = XLOG2DEVMAC(points[i].x + xoffset); |
958 | y2 = YLOG2DEVMAC(points[i].y + yoffset); | |
75f7bc3b SC |
959 | ::LineTo(x2, y2); |
960 | } | |
961 | ||
76a5e5d2 SC |
962 | // close the polyline if necessary |
963 | if ( x1 != x2 || y1 != y2 ) | |
964 | { | |
965 | ::LineTo(x1,y1 ) ; | |
966 | } | |
967 | ||
75f7bc3b SC |
968 | ClosePoly(); |
969 | ||
32ea1f98 RR |
970 | if (m_brush.GetStyle() != wxTRANSPARENT) |
971 | { | |
32ea1f98 RR |
972 | |
973 | MacInstallBrush(); | |
974 | ::PaintPoly( polygon ); | |
975 | ||
3dec57ad | 976 | } |
519cb848 SC |
977 | |
978 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
979 | { | |
32ea1f98 | 980 | |
519cb848 SC |
981 | MacInstallPen() ; |
982 | ::FramePoly( polygon ) ; | |
32ea1f98 | 983 | |
3dec57ad | 984 | } |
75f7bc3b | 985 | KillPoly( polygon ); |
519cb848 SC |
986 | } |
987 | ||
3dec57ad | 988 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
519cb848 | 989 | { |
3dec57ad SC |
990 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
991 | wxMacPortSetter helper(this) ; | |
992 | ||
7d9d1fd7 SC |
993 | wxCoord xx = XLOG2DEVMAC(x); |
994 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
995 | wxCoord ww = m_signX * XLOG2DEVREL(width); |
996 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
519cb848 SC |
997 | |
998 | // CMB: draw nothing if transformed w or h is 0 | |
999 | if (ww == 0 || hh == 0) | |
1000 | return; | |
1001 | ||
1002 | // CMB: handle -ve width and/or height | |
1003 | if (ww < 0) | |
1004 | { | |
1005 | ww = -ww; | |
1006 | xx = xx - ww; | |
1007 | } | |
1008 | ||
1009 | if (hh < 0) | |
1010 | { | |
1011 | hh = -hh; | |
1012 | yy = yy - hh; | |
1013 | } | |
1014 | ||
1015 | Rect rect = { yy , xx , yy + hh , xx + ww } ; | |
1016 | ||
1017 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1018 | { | |
1019 | MacInstallBrush() ; | |
1020 | ::PaintRect( &rect ) ; | |
3dec57ad | 1021 | } |
519cb848 SC |
1022 | |
1023 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
1024 | { | |
1025 | MacInstallPen() ; | |
1026 | ::FrameRect( &rect ) ; | |
3dec57ad | 1027 | } |
519cb848 SC |
1028 | } |
1029 | ||
2f1ae414 SC |
1030 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, |
1031 | wxCoord width, wxCoord height, | |
1032 | double radius) | |
519cb848 | 1033 | { |
3dec57ad SC |
1034 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
1035 | wxMacPortSetter helper(this) ; | |
519cb848 | 1036 | |
3dec57ad SC |
1037 | if (radius < 0.0) |
1038 | radius = - radius * ((width < height) ? width : height); | |
519cb848 | 1039 | |
7d9d1fd7 SC |
1040 | wxCoord xx = XLOG2DEVMAC(x); |
1041 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
1042 | wxCoord ww = m_signX * XLOG2DEVREL(width); |
1043 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
519cb848 SC |
1044 | |
1045 | // CMB: draw nothing if transformed w or h is 0 | |
1046 | if (ww == 0 || hh == 0) | |
1047 | return; | |
1048 | ||
1049 | // CMB: handle -ve width and/or height | |
1050 | if (ww < 0) | |
1051 | { | |
1052 | ww = -ww; | |
1053 | xx = xx - ww; | |
1054 | } | |
1055 | ||
1056 | if (hh < 0) | |
1057 | { | |
1058 | hh = -hh; | |
1059 | yy = yy - hh; | |
1060 | } | |
1061 | ||
1062 | Rect rect = { yy , xx , yy + hh , xx + ww } ; | |
1063 | ||
1064 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1065 | { | |
1066 | MacInstallBrush() ; | |
03e11df5 | 1067 | ::PaintRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ; |
3dec57ad | 1068 | } |
519cb848 SC |
1069 | |
1070 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
1071 | { | |
1072 | MacInstallPen() ; | |
03e11df5 | 1073 | ::FrameRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ; |
3dec57ad | 1074 | } |
519cb848 SC |
1075 | } |
1076 | ||
2f1ae414 | 1077 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
519cb848 | 1078 | { |
3dec57ad SC |
1079 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
1080 | wxMacPortSetter helper(this) ; | |
519cb848 | 1081 | |
7d9d1fd7 SC |
1082 | wxCoord xx = XLOG2DEVMAC(x); |
1083 | wxCoord yy = YLOG2DEVMAC(y); | |
3dec57ad SC |
1084 | wxCoord ww = m_signX * XLOG2DEVREL(width); |
1085 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
519cb848 SC |
1086 | |
1087 | // CMB: draw nothing if transformed w or h is 0 | |
1088 | if (ww == 0 || hh == 0) | |
1089 | return; | |
1090 | ||
1091 | // CMB: handle -ve width and/or height | |
1092 | if (ww < 0) | |
1093 | { | |
1094 | ww = -ww; | |
1095 | xx = xx - ww; | |
1096 | } | |
1097 | ||
1098 | if (hh < 0) | |
1099 | { | |
1100 | hh = -hh; | |
1101 | yy = yy - hh; | |
1102 | } | |
1103 | ||
1104 | Rect rect = { yy , xx , yy + hh , xx + ww } ; | |
1105 | ||
1106 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
1107 | { | |
1108 | MacInstallBrush() ; | |
1109 | ::PaintOval( &rect ) ; | |
3dec57ad | 1110 | } |
519cb848 SC |
1111 | |
1112 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
1113 | { | |
1114 | MacInstallPen() ; | |
1115 | ::FrameOval( &rect ) ; | |
3dec57ad | 1116 | } |
519cb848 SC |
1117 | } |
1118 | ||
519cb848 SC |
1119 | |
1120 | ||
1121 | bool wxDC::CanDrawBitmap(void) const | |
1122 | { | |
1123 | return true ; | |
1124 | } | |
1125 | ||
1126 | ||
2f1ae414 | 1127 | bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
0cbff120 JS |
1128 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask, |
1129 | wxCoord xsrcMask, wxCoord ysrcMask ) | |
519cb848 | 1130 | { |
3dec57ad SC |
1131 | wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc")); |
1132 | wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC")); | |
76a5e5d2 SC |
1133 | |
1134 | if ( logical_func == wxNO_OP ) | |
1135 | return TRUE ; | |
519cb848 | 1136 | |
0cbff120 JS |
1137 | if (xsrcMask == -1 && ysrcMask == -1) |
1138 | { | |
1139 | xsrcMask = xsrc; ysrcMask = ysrc; | |
1140 | } | |
1141 | ||
76a5e5d2 SC |
1142 | // correct the parameter in case this dc does not have a mask at all |
1143 | ||
1144 | if ( useMask && !source->m_macMask ) | |
1145 | useMask = false ; | |
1146 | ||
1147 | Rect srcrect , dstrect ; | |
1148 | srcrect.top = source->YLOG2DEVMAC(ysrc) ; | |
1149 | srcrect.left = source->XLOG2DEVMAC(xsrc) ; | |
1150 | srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ; | |
1151 | srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ; | |
1152 | dstrect.top = YLOG2DEVMAC(ydest) ; | |
1153 | dstrect.left = XLOG2DEVMAC(xdest) ; | |
1154 | dstrect.bottom = YLOG2DEVMAC(ydest + height ) ; | |
1155 | dstrect.right = XLOG2DEVMAC(xdest + width ) ; | |
1156 | ||
1157 | short mode = kUnsupportedMode ; | |
1158 | bool invertDestinationFirst = false ; | |
1159 | switch ( logical_func ) | |
1160 | { | |
1161 | case wxAND: // src AND dst | |
1162 | mode = srcOr ; // ok | |
1163 | break ; | |
1164 | case wxAND_INVERT: // (NOT src) AND dst | |
1165 | mode = notSrcOr ; // ok | |
1166 | break ; | |
1167 | case wxAND_REVERSE:// src AND (NOT dst) | |
1168 | invertDestinationFirst = true ; | |
1169 | mode = srcOr ; | |
1170 | break ; | |
1171 | case wxCLEAR: // 0 | |
1172 | mode = kEmulatedMode ; | |
1173 | break ; | |
1174 | case wxCOPY: // src | |
1175 | mode = srcCopy ; // ok | |
1176 | break ; | |
1177 | case wxEQUIV: // (NOT src) XOR dst | |
1178 | mode = srcXor ; // ok | |
1179 | break ; | |
1180 | case wxINVERT: // NOT dst | |
1181 | mode = kEmulatedMode ; //or hilite ; | |
1182 | break ; | |
1183 | case wxNAND: // (NOT src) OR (NOT dst) | |
1184 | invertDestinationFirst = true ; | |
1185 | mode = srcBic ; | |
1186 | break ; | |
1187 | case wxNOR: // (NOT src) AND (NOT dst) | |
1188 | invertDestinationFirst = true ; | |
1189 | mode = notSrcOr ; | |
1190 | break ; | |
1191 | case wxNO_OP: // dst | |
1192 | mode = kEmulatedMode ; // this has already been handled upon entry | |
1193 | break ; | |
1194 | case wxOR: // src OR dst | |
1195 | mode = notSrcBic ; | |
1196 | break ; | |
1197 | case wxOR_INVERT: // (NOT src) OR dst | |
1198 | mode = srcBic ; | |
1199 | break ; | |
1200 | case wxOR_REVERSE: // src OR (NOT dst) | |
1201 | invertDestinationFirst = true ; | |
1202 | mode = notSrcBic ; | |
1203 | break ; | |
1204 | case wxSET: // 1 | |
1205 | mode = kEmulatedMode ; | |
1206 | break ; | |
1207 | case wxSRC_INVERT: // (NOT src) | |
1208 | mode = notSrcCopy ; // ok | |
1209 | break ; | |
1210 | case wxXOR: // src XOR dst | |
1211 | mode = notSrcXor ; // ok | |
1212 | break ; | |
1213 | ||
1214 | default : | |
1215 | break ; | |
1216 | ||
1217 | } | |
1218 | ||
1219 | if ( mode == kUnsupportedMode ) | |
1220 | { | |
1221 | wxFAIL_MSG("unsupported blitting mode" ) | |
1222 | return FALSE ; | |
1223 | } | |
1224 | ||
519cb848 SC |
1225 | CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ; |
1226 | PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; | |
519cb848 SC |
1227 | if ( LockPixels(bmappixels) ) |
1228 | { | |
76a5e5d2 SC |
1229 | wxMacPortSetter helper(this) ; |
1230 | RGBColor tempColor ; | |
1231 | ||
1232 | if ( source->GetDepth() == 1 ) | |
1233 | { | |
1234 | RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ; | |
1235 | RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ; | |
1236 | } | |
1237 | else | |
1238 | { | |
1239 | // the modes need this, otherwise we'll end up having really nice colors... | |
1240 | RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ; | |
1241 | RGBColor black = { 0,0,0} ; | |
1242 | RGBForeColor( &black ) ; | |
1243 | RGBBackColor( &white ) ; | |
1244 | } | |
8208e181 SC |
1245 | |
1246 | if ( useMask && source->m_macMask ) | |
1247 | { | |
1dcbbdcf SC |
1248 | if ( mode == srcCopy ) |
1249 | { | |
76a5e5d2 | 1250 | if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ) |
1dcbbdcf SC |
1251 | { |
1252 | CopyMask( GetPortBitMapForCopyBits( sourcePort ) , | |
76a5e5d2 SC |
1253 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) , |
1254 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) , | |
1dcbbdcf | 1255 | &srcrect, &srcrect , &dstrect ) ; |
76a5e5d2 | 1256 | UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; |
1dcbbdcf SC |
1257 | } |
1258 | } | |
1259 | else | |
1260 | { | |
1261 | RgnHandle clipRgn = NewRgn() ; | |
76a5e5d2 SC |
1262 | LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; |
1263 | BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; | |
1264 | UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ; | |
1dcbbdcf | 1265 | OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top + dstrect.top ) ; |
76a5e5d2 SC |
1266 | if ( mode == kEmulatedMode ) |
1267 | { | |
1268 | Pattern pat ; | |
1269 | ::PenPat(GetQDGlobalsBlack(&pat)); | |
1270 | if ( logical_func == wxSET ) | |
1271 | { | |
1272 | RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ; | |
1273 | ::RGBForeColor( &col ) ; | |
1274 | ::PaintRgn( clipRgn ) ; | |
1275 | } | |
1276 | else if ( logical_func == wxCLEAR ) | |
1277 | { | |
1278 | RGBColor col= { 0x0000, 0x0000, 0x0000 } ; | |
1279 | ::RGBForeColor( &col ) ; | |
1280 | ::PaintRgn( clipRgn ) ; | |
1281 | } | |
1282 | else if ( logical_func == wxINVERT ) | |
1283 | { | |
1284 | MacInvertRgn( clipRgn ) ; | |
1285 | } | |
1286 | else | |
1287 | { | |
1288 | for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y ) | |
1289 | { | |
1290 | for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x ) | |
1291 | { | |
1292 | Point dstPoint = { dstrect.top + y , dstrect.left + x } ; | |
1293 | Point srcPoint = { srcrect.top + y , srcrect.left + x } ; | |
1294 | if ( PtInRgn( dstPoint , clipRgn ) ) | |
1295 | { | |
1296 | RGBColor srcColor ; | |
1297 | RGBColor dstColor ; | |
1298 | ||
1299 | SetPort( (GrafPtr) sourcePort ) ; | |
1300 | GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ; | |
1301 | SetPort( (GrafPtr) m_macPort ) ; | |
1302 | GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
1303 | ||
1304 | wxMacCalculateColour( logical_func , srcColor , dstColor ) ; | |
1305 | SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
1306 | } | |
1307 | } | |
1308 | } | |
76a5e5d2 SC |
1309 | } |
1310 | } | |
1311 | else | |
1312 | { | |
1313 | if ( invertDestinationFirst ) | |
1314 | { | |
1315 | MacInvertRgn( clipRgn ) ; | |
1316 | } | |
1317 | CopyBits( GetPortBitMapForCopyBits( sourcePort ) , | |
1318 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) , | |
1319 | &srcrect, &dstrect, mode, clipRgn ) ; | |
1320 | } | |
1dcbbdcf SC |
1321 | DisposeRgn( clipRgn ) ; |
1322 | } | |
8208e181 SC |
1323 | } |
1324 | else | |
1325 | { | |
0d54461f SC |
1326 | RgnHandle clipRgn = NewRgn() ; |
1327 | SetRectRgn( clipRgn , dstrect.left , dstrect.top , dstrect.right , dstrect.bottom ) ; | |
76a5e5d2 SC |
1328 | if ( mode == kEmulatedMode ) |
1329 | { | |
0d54461f SC |
1330 | Pattern pat ; |
1331 | ::PenPat(GetQDGlobalsBlack(&pat)); | |
1332 | if ( logical_func == wxSET ) | |
1333 | { | |
1334 | RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ; | |
1335 | ::RGBForeColor( &col ) ; | |
1336 | ::PaintRgn( clipRgn ) ; | |
1337 | } | |
1338 | else if ( logical_func == wxCLEAR ) | |
1339 | { | |
1340 | RGBColor col= { 0x0000, 0x0000, 0x0000 } ; | |
1341 | ::RGBForeColor( &col ) ; | |
1342 | ::PaintRgn( clipRgn ) ; | |
1343 | } | |
1344 | else if ( logical_func == wxINVERT ) | |
1345 | { | |
1346 | MacInvertRgn( clipRgn ) ; | |
1347 | } | |
1348 | else | |
1349 | { | |
1350 | for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y ) | |
1351 | { | |
1352 | for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x ) | |
1353 | { | |
1354 | Point dstPoint = { dstrect.top + y , dstrect.left + x } ; | |
1355 | Point srcPoint = { srcrect.top + y , srcrect.left + x } ; | |
1356 | ||
1357 | { | |
1358 | RGBColor srcColor ; | |
1359 | RGBColor dstColor ; | |
1360 | ||
1361 | SetPort( (GrafPtr) sourcePort ) ; | |
1362 | GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ; | |
1363 | SetPort( (GrafPtr) m_macPort ) ; | |
1364 | GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
1365 | ||
1366 | wxMacCalculateColour( logical_func , srcColor , dstColor ) ; | |
1367 | SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ; | |
1368 | } | |
1369 | } | |
1370 | } | |
1371 | } | |
1372 | ||
76a5e5d2 SC |
1373 | } |
1374 | else | |
1375 | { | |
0d54461f SC |
1376 | if ( invertDestinationFirst ) |
1377 | { | |
1378 | MacInvertRgn( clipRgn ) ; | |
1379 | } | |
1380 | CopyBits( GetPortBitMapForCopyBits( sourcePort ) , | |
1381 | GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) , | |
1382 | &srcrect, &dstrect, mode, NULL ) ; | |
76a5e5d2 | 1383 | } |
0d54461f | 1384 | DisposeRgn( clipRgn ) ; |
8208e181 | 1385 | } |
519cb848 SC |
1386 | UnlockPixels( bmappixels ) ; |
1387 | } | |
1388 | ||
1389 | m_macPenInstalled = false ; | |
1390 | m_macBrushInstalled = false ; | |
1391 | m_macFontInstalled = false ; | |
1392 | ||
1393 | return TRUE; | |
1394 | } | |
1395 | ||
66a09d47 SC |
1396 | inline Fixed IntToFixed( int inInt ) |
1397 | { | |
1398 | return (((SInt32) inInt) << 16); | |
1399 | } | |
1400 | ||
1401 | ||
1402 | void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, | |
3dec57ad | 1403 | double angle) |
2f1ae414 | 1404 | { |
3dec57ad SC |
1405 | wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") ); |
1406 | ||
1407 | if (angle == 0.0) | |
1408 | { | |
66a09d47 | 1409 | DrawText(str, x, y); |
3dec57ad SC |
1410 | return; |
1411 | } | |
1412 | ||
3dec57ad | 1413 | wxMacPortSetter helper(this) ; |
66a09d47 SC |
1414 | MacInstallFont() ; |
1415 | ||
1416 | wxString text ; | |
1417 | if ( wxApp::s_macDefaultEncodingIsPC ) | |
1418 | { | |
1419 | text = wxMacMakeMacStringFromPC( str ) ; | |
1420 | } | |
1421 | else | |
1422 | { | |
1423 | text = str ; | |
1424 | } | |
3dec57ad | 1425 | |
66a09d47 SC |
1426 | wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; |
1427 | if ( 0 ) | |
3dec57ad | 1428 | { |
66a09d47 SC |
1429 | m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize); |
1430 | SetAntiAliasedTextEnabled(true, m_scaleY * font->m_macFontSize); | |
1431 | m_macAliasWasEnabled = true ; | |
3dec57ad | 1432 | } |
66a09d47 SC |
1433 | |
1434 | OSStatus status = noErr ; | |
1435 | ||
1436 | TECObjectRef ec; | |
1437 | status = TECCreateConverter(&ec, kTextEncodingMacRoman, kTextEncodingUnicodeDefault); | |
1438 | wxASSERT_MSG( status == noErr , "couldn't start converter" ) ; | |
1439 | ||
1440 | ByteCount byteOutLen ; | |
1441 | ByteCount byteInLen = text.Length() ; | |
1442 | ByteCount byteBufferLen = byteInLen *2 ; | |
1443 | char* buf = new char[byteBufferLen] ; | |
1444 | ||
1445 | status = TECConvertText(ec, (ConstTextPtr)text.c_str() , byteInLen, &byteInLen, | |
1446 | (TextPtr)buf, byteBufferLen, &byteOutLen); | |
1447 | ||
1448 | wxASSERT_MSG( status == noErr , "couldn't convert text" ) ; | |
1449 | status = TECDisposeConverter(ec); | |
1450 | wxASSERT_MSG( status == noErr , "couldn't dispose converter" ) ; | |
1451 | ||
1452 | ATSUTextLayout atsuLayout ; | |
1453 | UniCharCount chars = byteOutLen / 2 ; | |
1454 | status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 , | |
1455 | &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; | |
1456 | wxASSERT_MSG( status == noErr , "couldn't create the layout of the rotated text" ); | |
1457 | ||
1458 | Fixed atsuAngle = IntToFixed( angle ) ; | |
1459 | ByteCount angleSize = sizeof(Fixed) ; | |
1460 | ATSUAttributeTag rotationTag = kATSULineRotationTag ; | |
1461 | ATSUAttributeValuePtr angleValue = &atsuAngle ; | |
1462 | status = ::ATSUSetLayoutControls(atsuLayout , 1 , &rotationTag , &angleSize , &angleValue ) ; | |
1463 | ||
1464 | status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, | |
1465 | IntToFixed(XLOG2DEVMAC(x) ) , IntToFixed(YLOG2DEVMAC(y) ) ); | |
1466 | wxASSERT_MSG( status == noErr , "couldn't draw the rotated text" ); | |
1467 | Rect rect ; | |
1468 | status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, | |
1469 | IntToFixed(XLOG2DEVMAC(x) ) , IntToFixed(YLOG2DEVMAC(y) ) , &rect ); | |
1470 | wxASSERT_MSG( status == noErr , "couldn't measure the rotated text" ); | |
1471 | ||
1472 | OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ; | |
1473 | CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) ); | |
1474 | CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) ); | |
1475 | ::ATSUDisposeTextLayout(atsuLayout); | |
1476 | delete[] buf ; | |
2f1ae414 | 1477 | } |
66a09d47 | 1478 | |
2f1ae414 | 1479 | void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) |
519cb848 | 1480 | { |
3dec57ad SC |
1481 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC")); |
1482 | wxMacPortSetter helper(this) ; | |
519cb848 | 1483 | |
7d9d1fd7 SC |
1484 | long xx = XLOG2DEVMAC(x); |
1485 | long yy = YLOG2DEVMAC(y); | |
519cb848 | 1486 | |
66a09d47 SC |
1487 | MacInstallFont() ; |
1488 | if ( 0 ) | |
1489 | { | |
1490 | m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize); | |
1491 | SetAntiAliasedTextEnabled(true, 8); | |
1492 | m_macAliasWasEnabled = true ; | |
1493 | } | |
1494 | ||
1495 | FontInfo fi ; | |
1496 | ::GetFontInfo( &fi ) ; | |
1497 | ||
1498 | yy += fi.ascent ; | |
1499 | ::MoveTo( xx , yy ); | |
1500 | if ( m_backgroundMode == wxTRANSPARENT ) | |
519cb848 | 1501 | { |
66a09d47 SC |
1502 | ::TextMode( srcOr) ; |
1503 | } | |
1504 | else | |
1505 | { | |
1506 | ::TextMode( srcCopy ) ; | |
1507 | } | |
519cb848 | 1508 | |
66a09d47 SC |
1509 | const char *text = NULL ; |
1510 | int length = 0 ; | |
1511 | wxString macText ; | |
519cb848 | 1512 | |
66a09d47 SC |
1513 | if ( wxApp::s_macDefaultEncodingIsPC ) |
1514 | { | |
1515 | macText = wxMacMakeMacStringFromPC( strtext ) ; | |
1516 | text = macText ; | |
1517 | length = macText.Length() ; | |
1518 | } | |
1519 | else | |
1520 | { | |
1521 | text = strtext ; | |
1522 | length = strtext.Length() ; | |
1523 | } | |
1524 | ||
1525 | int laststop = 0 ; | |
1526 | int i = 0 ; | |
1527 | int line = 0 ; | |
1528 | ||
1529 | while( i < length ) | |
1530 | { | |
1531 | if( text[i] == 13 || text[i] == 10) | |
519cb848 | 1532 | { |
66a09d47 SC |
1533 | ::DrawText( text , laststop , i - laststop ) ; |
1534 | line++ ; | |
1535 | ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); | |
1536 | laststop = i+1 ; | |
519cb848 | 1537 | } |
66a09d47 | 1538 | i++ ; |
519cb848 | 1539 | } |
66a09d47 SC |
1540 | |
1541 | ::DrawText( text , laststop , i - laststop ) ; | |
1542 | ::TextMode( srcOr ) ; | |
519cb848 SC |
1543 | } |
1544 | ||
3dec57ad | 1545 | bool wxDC::CanGetTextExtent() const |
519cb848 | 1546 | { |
3dec57ad | 1547 | wxCHECK_MSG(Ok(), false, wxT("Invalid DC")); |
519cb848 SC |
1548 | |
1549 | return true ; | |
1550 | } | |
1551 | ||
2f1ae414 SC |
1552 | void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height, |
1553 | wxCoord *descent, wxCoord *externalLeading , | |
1554 | wxFont *theFont ) const | |
519cb848 | 1555 | { |
3dec57ad | 1556 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 1557 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1558 | |
1559 | wxFont formerFont = m_font ; | |
1560 | ||
1561 | if ( theFont ) | |
1562 | { | |
1563 | wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; | |
1564 | ||
1565 | if ( font ) | |
1566 | { | |
519cb848 | 1567 | ::TextFont( font->m_macFontNum ) ; |
2f1ae414 | 1568 | ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ; |
519cb848 SC |
1569 | ::TextFace( font->m_macFontStyle ) ; |
1570 | } | |
1571 | } | |
1572 | else | |
1573 | { | |
1574 | MacInstallFont() ; | |
1575 | } | |
1576 | ||
1577 | FontInfo fi ; | |
1578 | ::GetFontInfo( &fi ) ; | |
1579 | ||
2f1ae414 SC |
1580 | if ( height ) |
1581 | *height = YDEV2LOGREL( fi.descent + fi.ascent ) ; | |
1582 | if ( descent ) | |
1583 | *descent =YDEV2LOGREL( fi.descent ); | |
1584 | if ( externalLeading ) | |
1585 | *externalLeading = YDEV2LOGREL( fi.leading ) ; | |
519cb848 SC |
1586 | |
1587 | const char *text = NULL ; | |
1588 | int length = 0 ; | |
1589 | wxString macText ; | |
1590 | if ( wxApp::s_macDefaultEncodingIsPC ) | |
1591 | { | |
1592 | macText = wxMacMakeMacStringFromPC( string ) ; | |
1593 | text = macText ; | |
1594 | length = macText.Length() ; | |
1595 | } | |
1596 | else | |
1597 | { | |
1598 | text = string ; | |
1599 | length = string.Length() ; | |
1600 | } | |
1601 | ||
1602 | int laststop = 0 ; | |
1603 | int i = 0 ; | |
1604 | int curwidth = 0 ; | |
2f1ae414 | 1605 | if ( width ) |
519cb848 | 1606 | { |
2f1ae414 SC |
1607 | *width = 0 ; |
1608 | ||
1609 | while( i < length ) | |
519cb848 | 1610 | { |
2f1ae414 SC |
1611 | if( text[i] == 13 || text[i] == 10) |
1612 | { | |
1613 | if ( height ) | |
1614 | *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; | |
1615 | curwidth = ::TextWidth( text , laststop , i - laststop ) ; | |
1616 | if ( curwidth > *width ) | |
1617 | *width = XDEV2LOGREL( curwidth ) ; | |
1618 | laststop = i+1 ; | |
1619 | } | |
1620 | i++ ; | |
519cb848 | 1621 | } |
2f1ae414 SC |
1622 | |
1623 | curwidth = ::TextWidth( text , laststop , i - laststop ) ; | |
1624 | if ( curwidth > *width ) | |
1625 | *width = XDEV2LOGREL( curwidth ) ; | |
519cb848 | 1626 | } |
519cb848 SC |
1627 | |
1628 | if ( theFont ) | |
1629 | { | |
1630 | m_macFontInstalled = false ; | |
1631 | } | |
1632 | } | |
1633 | ||
ee41971c | 1634 | wxCoord wxDC::GetCharWidth(void) const |
519cb848 | 1635 | { |
3dec57ad | 1636 | wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); |
519cb848 | 1637 | |
0eaa1d68 | 1638 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1639 | |
1640 | MacInstallFont() ; | |
1641 | ||
c257d44d | 1642 | int width = ::TextWidth( "n" , 0 , 1 ) ; |
519cb848 | 1643 | |
c257d44d | 1644 | return YDEV2LOGREL(width) ; |
519cb848 SC |
1645 | } |
1646 | ||
ee41971c | 1647 | wxCoord wxDC::GetCharHeight(void) const |
519cb848 | 1648 | { |
3dec57ad | 1649 | wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); |
519cb848 | 1650 | |
3dec57ad | 1651 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1652 | |
1653 | MacInstallFont() ; | |
1654 | ||
1655 | FontInfo fi ; | |
1656 | ::GetFontInfo( &fi ) ; | |
1657 | ||
2f1ae414 | 1658 | return YDEV2LOGREL( fi.descent + fi.ascent ); |
519cb848 SC |
1659 | } |
1660 | ||
1661 | void wxDC::Clear(void) | |
1662 | { | |
3dec57ad SC |
1663 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
1664 | wxMacPortSetter helper(this) ; | |
66a09d47 | 1665 | Rect rect = { -32000 , -32000 , 32000 , 32000 } ; |
519cb848 SC |
1666 | |
1667 | if (m_backgroundBrush.GetStyle() != wxTRANSPARENT) | |
1668 | { | |
66a09d47 SC |
1669 | ::PenNormal() ; |
1670 | //MacInstallBrush() ; | |
76a5e5d2 | 1671 | MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ; |
519cb848 | 1672 | ::EraseRect( &rect ) ; |
3dec57ad | 1673 | } |
519cb848 SC |
1674 | } |
1675 | ||
1676 | void wxDC::MacInstallFont() const | |
1677 | { | |
3dec57ad | 1678 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 SC |
1679 | // if ( m_macFontInstalled ) |
1680 | // return ; | |
2f1ae414 SC |
1681 | Pattern blackColor ; |
1682 | ||
519cb848 SC |
1683 | wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; |
1684 | ||
1685 | if ( font ) | |
1686 | { | |
1687 | ::TextFont( font->m_macFontNum ) ; | |
03e11df5 | 1688 | ::TextSize( short(m_scaleY * font->m_macFontSize) ) ; |
519cb848 SC |
1689 | ::TextFace( font->m_macFontStyle ) ; |
1690 | ||
1691 | m_macFontInstalled = true ; | |
1692 | m_macBrushInstalled = false ; | |
1693 | m_macPenInstalled = false ; | |
03e11df5 | 1694 | |
76a5e5d2 SC |
1695 | RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()); |
1696 | RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()); | |
03e11df5 GD |
1697 | ::RGBForeColor( &forecolor ); |
1698 | ::RGBBackColor( &backcolor ); | |
519cb848 SC |
1699 | } |
1700 | else | |
1701 | { | |
1702 | short fontnum ; | |
1703 | ||
1704 | GetFNum( "\pGeneva" , &fontnum ) ; | |
1705 | ::TextFont( fontnum ) ; | |
03e11df5 | 1706 | ::TextSize( short(m_scaleY * 10) ) ; |
519cb848 SC |
1707 | ::TextFace( 0 ) ; |
1708 | ||
1709 | // todo reset after spacing changes - or store the current spacing somewhere | |
1710 | ||
1711 | m_macFontInstalled = true ; | |
1712 | m_macBrushInstalled = false ; | |
1713 | m_macPenInstalled = false ; | |
519cb848 | 1714 | |
76a5e5d2 SC |
1715 | RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()); |
1716 | RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()); | |
03e11df5 GD |
1717 | ::RGBForeColor( &forecolor ); |
1718 | ::RGBBackColor( &backcolor ); | |
1719 | } | |
519cb848 SC |
1720 | |
1721 | short mode = patCopy ; | |
1722 | ||
1723 | // todo : | |
1724 | ||
1725 | switch( m_logicalFunction ) | |
1726 | { | |
1727 | case wxCOPY: // src | |
1728 | mode = patCopy ; | |
1729 | break ; | |
1730 | case wxINVERT: // NOT dst | |
2f1ae414 | 1731 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1732 | mode = patXor ; |
1733 | break ; | |
1734 | case wxXOR: // src XOR dst | |
1735 | mode = patXor ; | |
1736 | break ; | |
1737 | case wxOR_REVERSE: // src OR (NOT dst) | |
1738 | mode = notPatOr ; | |
1739 | break ; | |
1740 | case wxSRC_INVERT: // (NOT src) | |
1741 | mode = notPatCopy ; | |
1742 | break ; | |
1743 | ||
1744 | // unsupported TODO | |
1745 | ||
1746 | case wxCLEAR: // 0 | |
1747 | case wxAND_REVERSE:// src AND (NOT dst) | |
1748 | case wxAND: // src AND dst | |
1749 | case wxAND_INVERT: // (NOT src) AND dst | |
1750 | case wxNO_OP: // dst | |
1751 | case wxNOR: // (NOT src) AND (NOT dst) | |
1752 | case wxEQUIV: // (NOT src) XOR dst | |
1753 | case wxOR_INVERT: // (NOT src) OR dst | |
1754 | case wxNAND: // (NOT src) OR (NOT dst) | |
1755 | case wxOR: // src OR dst | |
1756 | case wxSET: // 1 | |
2f1ae414 SC |
1757 | // case wxSRC_OR: // source _bitmap_ OR destination |
1758 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
1759 | break ; |
1760 | } | |
1761 | ::PenMode( mode ) ; | |
66a09d47 SC |
1762 | |
1763 | OSStatus status = noErr ; | |
1764 | ||
1765 | Fixed atsuSize = IntToFixed(m_scaleY * font->m_macFontSize) ; | |
1766 | ||
1767 | Style qdStyle = font->m_macFontStyle ; | |
1768 | ATSUFontID atsuFont = font->m_macATSUFontID ; | |
1769 | ||
1770 | status = ::ATSUCreateStyle(&(ATSUStyle)m_macATSUIStyle) ; | |
1771 | wxASSERT_MSG( status == noErr , "couldn't create ATSU style" ) ; | |
1772 | ||
1773 | ATSUAttributeTag atsuTags[] = | |
1774 | { | |
1775 | kATSUFontTag , | |
1776 | kATSUSizeTag , | |
1777 | kATSUColorTag , | |
1778 | ||
1779 | kATSUQDBoldfaceTag , | |
1780 | kATSUQDItalicTag , | |
1781 | kATSUQDUnderlineTag , | |
1782 | kATSUQDCondensedTag , | |
1783 | kATSUQDExtendedTag , | |
1784 | ||
1785 | } ; | |
1786 | ||
1787 | ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = | |
1788 | { | |
1789 | sizeof( ATSUFontID ) , | |
1790 | sizeof( Fixed ) , | |
1791 | sizeof( RGBColor ) , | |
1792 | sizeof( Boolean ) , | |
1793 | sizeof( Boolean ) , | |
1794 | sizeof( Boolean ) , | |
1795 | sizeof( Boolean ) , | |
1796 | sizeof( Boolean ) , | |
1797 | } ; | |
1798 | ||
1799 | Boolean kTrue = true ; | |
1800 | Boolean kFalse = false ; | |
1801 | ||
1802 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = | |
1803 | { | |
1804 | &atsuFont , | |
1805 | &atsuSize , | |
1806 | &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) , | |
1807 | ||
1808 | (qdStyle & bold) ? &kTrue : &kFalse , | |
1809 | (qdStyle & italic) ? &kTrue : &kFalse , | |
1810 | (qdStyle & underline) ? &kTrue : &kFalse , | |
1811 | (qdStyle & condense) ? &kTrue : &kFalse , | |
1812 | (qdStyle & extend) ? &kTrue : &kFalse , | |
1813 | } ; | |
1814 | ||
1815 | status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag), | |
1816 | atsuTags, atsuSizes, atsuValues); | |
1817 | wxASSERT_MSG( status == noErr , "couldn't set create ATSU style" ) ; | |
1818 | ||
519cb848 SC |
1819 | } |
1820 | ||
ffd67837 SC |
1821 | Pattern gHatchPatterns[] = |
1822 | { | |
1823 | { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } , | |
1824 | { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } , | |
1825 | { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } , | |
1826 | { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } , | |
1827 | { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } , | |
1828 | { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } , | |
1829 | { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } , | |
1830 | } ; | |
1831 | ||
519cb848 SC |
1832 | static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern) |
1833 | { | |
ffd67837 SC |
1834 | int theIndex = 1 ; |
1835 | ||
519cb848 SC |
1836 | switch(hatchStyle) |
1837 | { | |
1838 | case wxBDIAGONAL_HATCH: | |
75f7bc3b | 1839 | theIndex = 2; |
519cb848 SC |
1840 | break; |
1841 | case wxFDIAGONAL_HATCH: | |
75f7bc3b | 1842 | theIndex = 3; |
519cb848 SC |
1843 | break; |
1844 | case wxCROSS_HATCH: | |
75f7bc3b | 1845 | theIndex = 4; |
519cb848 SC |
1846 | break; |
1847 | case wxHORIZONTAL_HATCH: | |
75f7bc3b | 1848 | theIndex = 5; |
519cb848 SC |
1849 | break; |
1850 | case wxVERTICAL_HATCH: | |
1851 | theIndex = 6; | |
1852 | break; | |
1853 | case wxCROSSDIAG_HATCH: | |
75f7bc3b | 1854 | theIndex = 7; |
519cb848 SC |
1855 | break; |
1856 | default: | |
1857 | theIndex = 1; // solid pattern | |
1858 | break; | |
1859 | } | |
ffd67837 | 1860 | *pattern = gHatchPatterns[theIndex-1] ; |
519cb848 SC |
1861 | } |
1862 | ||
1863 | void wxDC::MacInstallPen() const | |
1864 | { | |
3dec57ad | 1865 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 | 1866 | |
2f1ae414 SC |
1867 | Pattern blackColor; |
1868 | ||
0eaa1d68 SC |
1869 | // if ( m_macPenInstalled ) |
1870 | // return ; | |
519cb848 | 1871 | |
76a5e5d2 SC |
1872 | RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel()); |
1873 | RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()); | |
03e11df5 GD |
1874 | ::RGBForeColor( &forecolor ); |
1875 | ::RGBBackColor( &backcolor ); | |
519cb848 SC |
1876 | |
1877 | ::PenNormal() ; | |
3dec57ad | 1878 | int penWidth = m_pen.GetWidth() * (int) m_scaleX ; |
0b014ec7 SC |
1879 | |
1880 | // null means only one pixel, at whatever resolution | |
1881 | if ( penWidth == 0 ) | |
1882 | penWidth = 1 ; | |
519cb848 SC |
1883 | ::PenSize(penWidth, penWidth); |
1884 | ||
1885 | int penStyle = m_pen.GetStyle(); | |
1886 | ||
1887 | if (penStyle == wxSOLID) | |
03e11df5 | 1888 | { |
2f1ae414 | 1889 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
03e11df5 | 1890 | } |
519cb848 SC |
1891 | else if (IS_HATCH(penStyle)) |
1892 | { | |
1893 | Pattern pat ; | |
1894 | wxMacGetHatchPattern(penStyle, &pat); | |
1895 | ::PenPat(&pat); | |
1896 | } | |
1897 | else | |
1898 | { | |
1ff301c4 SC |
1899 | Pattern pat = *GetQDGlobalsBlack(&blackColor) ; |
1900 | switch( penStyle ) | |
1901 | { | |
1902 | case wxDOT : | |
1903 | for ( int i = 0 ; i < 8 ; ++i ) | |
1904 | { | |
1905 | pat.pat[i] = 0xCC ; | |
1906 | } | |
1907 | break ; | |
1908 | case wxLONG_DASH : | |
1909 | for ( int i = 0 ; i < 8 ; ++i ) | |
1910 | { | |
1911 | pat.pat[i] = 0xFE ; | |
1912 | } | |
1913 | break ; | |
1914 | case wxSHORT_DASH : | |
1915 | for ( int i = 0 ; i < 8 ; ++i ) | |
1916 | { | |
1917 | pat.pat[i] = 0xEE ; | |
1918 | } | |
1919 | break ; | |
1920 | case wxDOT_DASH : | |
1921 | for ( int i = 0 ; i < 8 ; ++i ) | |
1922 | { | |
1923 | pat.pat[i] = 0x6F ; | |
1924 | } | |
1925 | break ; | |
1926 | case wxUSER_DASH : | |
1927 | { | |
1928 | wxDash* dash ; | |
1929 | int number = m_pen.GetDashes(&dash) ; | |
1930 | // right now we don't allocate larger pixmaps | |
1931 | for ( int i = 0 ; i < 8 ; ++i ) | |
1932 | { | |
1933 | pat.pat[i] = dash[0] ; | |
1934 | } | |
1935 | } | |
1936 | break ; | |
1937 | } | |
1938 | ::PenPat(&pat); | |
519cb848 SC |
1939 | } |
1940 | ||
1941 | short mode = patCopy ; | |
1942 | ||
1943 | // todo : | |
1944 | ||
1945 | switch( m_logicalFunction ) | |
1946 | { | |
1ff301c4 SC |
1947 | case wxCOPY: // only foreground color, leave background (thus not patCopy) |
1948 | mode = patOr ; | |
519cb848 SC |
1949 | break ; |
1950 | case wxINVERT: // NOT dst | |
1ff301c4 | 1951 | // ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1952 | mode = patXor ; |
1953 | break ; | |
1954 | case wxXOR: // src XOR dst | |
1955 | mode = patXor ; | |
1956 | break ; | |
1957 | case wxOR_REVERSE: // src OR (NOT dst) | |
1958 | mode = notPatOr ; | |
1959 | break ; | |
1960 | case wxSRC_INVERT: // (NOT src) | |
1961 | mode = notPatCopy ; | |
1962 | break ; | |
1963 | ||
1964 | // unsupported TODO | |
1965 | ||
1966 | case wxCLEAR: // 0 | |
1967 | case wxAND_REVERSE:// src AND (NOT dst) | |
1968 | case wxAND: // src AND dst | |
1969 | case wxAND_INVERT: // (NOT src) AND dst | |
1970 | case wxNO_OP: // dst | |
1971 | case wxNOR: // (NOT src) AND (NOT dst) | |
1972 | case wxEQUIV: // (NOT src) XOR dst | |
1973 | case wxOR_INVERT: // (NOT src) OR dst | |
1974 | case wxNAND: // (NOT src) OR (NOT dst) | |
1975 | case wxOR: // src OR dst | |
1976 | case wxSET: // 1 | |
2f1ae414 SC |
1977 | // case wxSRC_OR: // source _bitmap_ OR destination |
1978 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
1979 | break ; |
1980 | } | |
1981 | ::PenMode( mode ) ; | |
1982 | m_macPenInstalled = true ; | |
1983 | m_macBrushInstalled = false ; | |
1984 | m_macFontInstalled = false ; | |
1985 | } | |
1986 | ||
7d9d1fd7 | 1987 | void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background ) |
1dcbbdcf SC |
1988 | { |
1989 | Pattern whiteColor ; | |
7d9d1fd7 SC |
1990 | switch( background.MacGetBrushKind() ) |
1991 | { | |
1992 | case kwxMacBrushTheme : | |
1993 | { | |
1994 | ::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ; | |
1995 | break ; | |
1996 | } | |
1997 | case kwxMacBrushThemeBackground : | |
1998 | { | |
1999 | Rect extent ; | |
2000 | ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ; | |
2001 | ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ; | |
2002 | break ; | |
2003 | } | |
2004 | case kwxMacBrushColour : | |
2005 | { | |
66a09d47 | 2006 | ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) ); |
7d9d1fd7 SC |
2007 | int brushStyle = background.GetStyle(); |
2008 | if (brushStyle == wxSOLID) | |
2009 | ::BackPat(GetQDGlobalsWhite(&whiteColor)); | |
2010 | else if (IS_HATCH(brushStyle)) | |
2011 | { | |
2012 | Pattern pat ; | |
2013 | wxMacGetHatchPattern(brushStyle, &pat); | |
2014 | ::BackPat(&pat); | |
2015 | } | |
2016 | else | |
2017 | { | |
2018 | ::BackPat(GetQDGlobalsWhite(&whiteColor)); | |
2019 | } | |
2020 | break ; | |
2021 | } | |
2022 | } | |
1dcbbdcf SC |
2023 | } |
2024 | ||
519cb848 SC |
2025 | void wxDC::MacInstallBrush() const |
2026 | { | |
3dec57ad | 2027 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 2028 | |
1dcbbdcf | 2029 | Pattern blackColor ; |
0eaa1d68 SC |
2030 | // if ( m_macBrushInstalled ) |
2031 | // return ; | |
519cb848 SC |
2032 | |
2033 | // foreground | |
76a5e5d2 SC |
2034 | |
2035 | bool backgroundTransparent = (GetBackgroundMode() == wxTRANSPARENT) ; | |
519cb848 | 2036 | |
76a5e5d2 | 2037 | ::RGBForeColor( &MAC_WXCOLORREF( m_brush.GetColour().GetPixel()) ); |
0d54461f | 2038 | ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) ); |
519cb848 SC |
2039 | |
2040 | int brushStyle = m_brush.GetStyle(); | |
2041 | if (brushStyle == wxSOLID) | |
0d54461f | 2042 | { |
2f1ae414 | 2043 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
0d54461f | 2044 | } |
519cb848 SC |
2045 | else if (IS_HATCH(brushStyle)) |
2046 | { | |
2047 | Pattern pat ; | |
2048 | wxMacGetHatchPattern(brushStyle, &pat); | |
2049 | ::PenPat(&pat); | |
2050 | } | |
1ff301c4 | 2051 | else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE ) |
519cb848 | 2052 | { |
76a5e5d2 SC |
2053 | // we force this in order to be compliant with wxMSW |
2054 | backgroundTransparent = false ; | |
1ff301c4 SC |
2055 | // for these the text fore (and back for MASK_OPAQUE) colors are used |
2056 | wxBitmap* bitmap = m_brush.GetStipple() ; | |
2057 | int width = bitmap->GetWidth() ; | |
2058 | int height = bitmap->GetHeight() ; | |
76a5e5d2 SC |
2059 | GWorldPtr gw = NULL ; |
2060 | ||
1ff301c4 | 2061 | if ( m_brush.GetStyle() == wxSTIPPLE ) |
76a5e5d2 SC |
2062 | gw = MAC_WXHBITMAP(bitmap->GetHBITMAP()) ; |
2063 | else | |
2064 | gw = MAC_WXHBITMAP(bitmap->GetMask()->GetMaskBitmap()) ; | |
2065 | ||
2066 | PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ; | |
2067 | LockPixels( gwpixmaphandle ) ; | |
2068 | ||
2069 | bool isMonochrome = !IsPortColor( gw ) ; | |
2070 | ||
2071 | if ( !isMonochrome ) | |
2072 | { | |
2073 | if ( (**gwpixmaphandle).pixelSize == 1 ) | |
2074 | isMonochrome = true ; | |
2075 | } | |
2076 | ||
66a09d47 | 2077 | if ( isMonochrome && width == 8 && height == 8 ) |
1ff301c4 | 2078 | { |
76a5e5d2 | 2079 | ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ); |
0d54461f | 2080 | ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ); |
76a5e5d2 SC |
2081 | BitMap* gwbitmap = (BitMap*) *gwpixmaphandle ; // since the color depth is 1 it is a BitMap |
2082 | UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ; | |
2083 | int alignment = gwbitmap->rowBytes & 0x7FFF ; | |
66a09d47 SC |
2084 | Pattern pat ; |
2085 | for ( int i = 0 ; i < 8 ; ++i ) | |
2086 | { | |
2087 | pat.pat[i] = gwbits[i*alignment+0] ; | |
2088 | } | |
2089 | UnlockPixels( GetGWorldPixMap( gw ) ) ; | |
2090 | ::PenPat( &pat ) ; | |
2091 | } | |
2092 | else | |
2093 | { | |
76a5e5d2 SC |
2094 | // this will be the code to handle power of 2 patterns, we will have to arrive at a nice |
2095 | // caching scheme before putting this into production | |
66a09d47 SC |
2096 | Handle image; |
2097 | long imageSize; | |
2098 | PixPatHandle pixpat = NewPixPat() ; | |
2099 | ||
2100 | CopyPixMap(gwpixmaphandle, (**pixpat).patMap); | |
2101 | imageSize = GetPixRowBytes((**pixpat).patMap) * | |
2102 | ((**(**pixpat).patMap).bounds.bottom - | |
2103 | (**(**pixpat).patMap).bounds.top); | |
2104 | ||
2105 | PtrToHand( (**gwpixmaphandle).baseAddr, &image, imageSize ); | |
2106 | (**pixpat).patData = image; | |
2107 | if ( isMonochrome ) | |
2108 | { | |
76a5e5d2 SC |
2109 | CTabHandle ctable = ((**((**pixpat).patMap)).pmTable) ; |
2110 | ColorSpecPtr ctspec = (ColorSpecPtr) &(**ctable).ctTable ; | |
2111 | if ( ctspec[0].rgb.red == 0x0000 ) | |
2112 | { | |
2113 | ctspec[1].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ; | |
2114 | ctspec[0].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ; | |
2115 | } | |
2116 | else | |
2117 | { | |
2118 | ctspec[0].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ; | |
2119 | ctspec[1].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ; | |
2120 | } | |
2121 | ::CTabChanged( ctable ) ; | |
66a09d47 SC |
2122 | } |
2123 | ::PenPixPat(pixpat); | |
2124 | m_macForegroundPixMap = pixpat ; | |
1ff301c4 | 2125 | } |
76a5e5d2 | 2126 | UnlockPixels( gwpixmaphandle ) ; |
1ff301c4 SC |
2127 | } |
2128 | else | |
2129 | { | |
2130 | ::PenPat(GetQDGlobalsBlack(&blackColor)); | |
519cb848 | 2131 | } |
0d54461f | 2132 | |
1dcbbdcf | 2133 | short mode = patCopy ; |
519cb848 SC |
2134 | switch( m_logicalFunction ) |
2135 | { | |
2136 | case wxCOPY: // src | |
76a5e5d2 SC |
2137 | if ( backgroundTransparent ) |
2138 | mode = patOr ; | |
2139 | else | |
2140 | mode = patCopy ; | |
519cb848 SC |
2141 | break ; |
2142 | case wxINVERT: // NOT dst | |
76a5e5d2 SC |
2143 | if ( !backgroundTransparent ) |
2144 | { | |
2145 | ::PenPat(GetQDGlobalsBlack(&blackColor)); | |
2146 | } | |
519cb848 SC |
2147 | mode = patXor ; |
2148 | break ; | |
2149 | case wxXOR: // src XOR dst | |
2150 | mode = patXor ; | |
2151 | break ; | |
2152 | case wxOR_REVERSE: // src OR (NOT dst) | |
2153 | mode = notPatOr ; | |
2154 | break ; | |
2155 | case wxSRC_INVERT: // (NOT src) | |
2156 | mode = notPatCopy ; | |
2157 | break ; | |
2158 | ||
2159 | // unsupported TODO | |
2160 | ||
2161 | case wxCLEAR: // 0 | |
2162 | case wxAND_REVERSE:// src AND (NOT dst) | |
2163 | case wxAND: // src AND dst | |
2164 | case wxAND_INVERT: // (NOT src) AND dst | |
2165 | case wxNO_OP: // dst | |
2166 | case wxNOR: // (NOT src) AND (NOT dst) | |
2167 | case wxEQUIV: // (NOT src) XOR dst | |
2168 | case wxOR_INVERT: // (NOT src) OR dst | |
2169 | case wxNAND: // (NOT src) OR (NOT dst) | |
2170 | case wxOR: // src OR dst | |
2171 | case wxSET: // 1 | |
2f1ae414 SC |
2172 | // case wxSRC_OR: // source _bitmap_ OR destination |
2173 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
2174 | break ; |
2175 | } | |
2176 | ::PenMode( mode ) ; | |
2177 | m_macBrushInstalled = true ; | |
2178 | m_macPenInstalled = false ; | |
2179 | m_macFontInstalled = false ; | |
2180 | } | |
2181 | ||
2f1ae414 SC |
2182 | // --------------------------------------------------------------------------- |
2183 | // coordinates transformations | |
2184 | // --------------------------------------------------------------------------- | |
519cb848 | 2185 | |
2f1ae414 SC |
2186 | |
2187 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
2188 | { | |
2189 | return ((wxDC *)this)->XDEV2LOG(x); | |
2190 | } | |
2191 | ||
2192 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
2193 | { | |
2194 | return ((wxDC *)this)->YDEV2LOG(y); | |
2195 | } | |
2196 | ||
2197 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
2198 | { | |
2199 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
2200 | } | |
2201 | ||
2202 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
2203 | { | |
2204 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
2205 | } | |
2206 | ||
2207 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
2208 | { | |
2209 | return ((wxDC *)this)->XLOG2DEV(x); | |
2210 | } | |
2211 | ||
2212 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
2213 | { | |
2214 | return ((wxDC *)this)->YLOG2DEV(y); | |
2215 | } | |
2216 | ||
2217 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
2218 | { | |
2219 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
2220 | } | |
2221 | ||
2222 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
2223 | { | |
2224 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
2225 | } |