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