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