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