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