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