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