]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/dc.mm
Minor corrections to XRC format description.
[wxWidgets.git] / src / cocoa / dc.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dc.mm
3 // Purpose: wxDC
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/04/01
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #include "wx/cocoa/dc.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/log.h"
17 #include "wx/math.h" //math constants
18 #endif //WX_PRECOMP
19
20 #include "wx/cocoa/autorelease.h"
21 #include "wx/cocoa/string.h"
22 #include "wx/cocoa/ObjcRef.h"
23
24 #import <AppKit/NSBezierPath.h>
25 #import <AppKit/NSTextStorage.h>
26 #import <AppKit/NSLayoutManager.h>
27 #import <AppKit/NSTextContainer.h>
28 #import <AppKit/NSGraphicsContext.h>
29 #import <AppKit/NSAffineTransform.h>
30 #import <AppKit/NSColor.h>
31 #import <AppKit/NSTypesetter.h>
32 #import <AppKit/NSImage.h>
33
34 #include "wx/listimpl.cpp"
35 WX_DEFINE_LIST(wxCocoaDCStack);
36
37 IMPLEMENT_ABSTRACT_CLASS(wxCocoaDCImpl, wxDCImpl)
38
39 WX_NSTextStorage wxCocoaDCImpl::sm_cocoaNSTextStorage = nil;
40 WX_NSLayoutManager wxCocoaDCImpl::sm_cocoaNSLayoutManager = nil;
41 WX_NSTextContainer wxCocoaDCImpl::sm_cocoaNSTextContainer = nil;
42 wxCocoaDCStack wxCocoaDCImpl::sm_cocoaDCStack;
43
44 inline void CocoaSetPenForNSBezierPath(wxPen &pen, NSBezierPath *bezpath)
45 {
46 [pen.GetNSColor() set];
47 const CGFloat *pattern;
48 [bezpath setLineDash:pattern count:pen.GetCocoaLineDash(&pattern) phase:0.0];
49 [bezpath setLineWidth:pen.GetWidth()];
50 switch(pen.GetJoin())
51 {
52 case wxJOIN_BEVEL:
53 [bezpath setLineJoinStyle:NSBevelLineJoinStyle];
54 break;
55 case wxJOIN_ROUND:
56 [bezpath setLineJoinStyle:NSRoundLineJoinStyle];
57 break;
58 case wxJOIN_MITER:
59 [bezpath setLineJoinStyle:NSMiterLineJoinStyle];
60 break;
61 }
62 switch(pen.GetCap())
63 {
64 case wxCAP_ROUND:
65 [bezpath setLineCapStyle:NSRoundLineCapStyle];
66 break;
67 case wxCAP_PROJECTING:
68 [bezpath setLineCapStyle:NSSquareLineCapStyle];
69 break;
70 case wxCAP_BUTT:
71 [bezpath setLineCapStyle:NSButtLineCapStyle];
72 break;
73 }
74 }
75
76 void wxCocoaDCImpl::CocoaInitializeTextSystem()
77 {
78 wxAutoNSAutoreleasePool pool;
79
80 wxASSERT_MSG(!sm_cocoaNSTextStorage && !sm_cocoaNSLayoutManager && !sm_cocoaNSTextContainer,wxT("Text system already initalized! BAD PROGRAMMER!"));
81
82 // FIXME: Never released
83 sm_cocoaNSTextStorage = wxGCSafeRetain([[[NSTextStorage alloc] init] autorelease]);
84
85 // FIXME: Never released
86 sm_cocoaNSLayoutManager = wxGCSafeRetain([[[NSLayoutManager alloc] init] autorelease]);
87
88 [sm_cocoaNSTextStorage addLayoutManager:sm_cocoaNSLayoutManager];
89 // NSTextStorage retains NSLayoutManager, but so do we
90 // [sm_cocoaNSLayoutManager release]; [sm_cocoaNSLayoutManager retain];
91
92 // NOTE: initWithContainerSize is the designated initializer, but the
93 // Apple CircleView sample gets away with just calling init, which
94 // is all we really need for our purposes.
95 // FIXME: Never released
96 sm_cocoaNSTextContainer = wxGCSafeRetain([[[NSTextContainer alloc] init] autorelease]);
97 [sm_cocoaNSLayoutManager addTextContainer:sm_cocoaNSTextContainer];
98 // NSLayoutManager retains NSTextContainer, but so do we
99 // [sm_cocoaNSTextContainer release]; [sm_cocoaNSTextContainer retain];
100 }
101
102 void wxCocoaDCImpl::CocoaShutdownTextSystem()
103 {
104 [sm_cocoaNSTextContainer release]; sm_cocoaNSTextContainer = nil;
105 [sm_cocoaNSLayoutManager release]; sm_cocoaNSLayoutManager = nil;
106 [sm_cocoaNSTextStorage release]; sm_cocoaNSTextStorage = nil;
107 }
108
109 void wxCocoaDCImpl::CocoaUnwindStackAndLoseFocus()
110 {
111 wxCocoaDCStack::compatibility_iterator ourNode=sm_cocoaDCStack.Find(this);
112 if(ourNode)
113 {
114 wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst();
115 for(;node!=ourNode; node=sm_cocoaDCStack.GetFirst())
116 {
117 wxCocoaDCImpl *dc = node->GetData();
118 wxASSERT(dc);
119 wxASSERT(dc!=this);
120 if(!dc->CocoaUnlockFocus())
121 {
122 wxFAIL_MSG(wxT("Unable to unlock focus on higher-level DC!"));
123 }
124 sm_cocoaDCStack.Erase(node);
125 }
126 wxASSERT(node==ourNode);
127 wxASSERT(ourNode->GetData() == this);
128 ourNode->GetData()->CocoaUnlockFocus();
129 sm_cocoaDCStack.Erase(ourNode);
130 }
131 }
132
133 bool wxCocoaDCImpl::CocoaUnwindStackAndTakeFocus()
134 {
135 wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst();
136 for(;node;node = sm_cocoaDCStack.GetFirst())
137 {
138 wxCocoaDCImpl *dc = node->GetData();
139 wxASSERT(dc);
140 // If we're on the stack, then it's unwound enough and we have focus
141 if(dc==this)
142 return true;
143 // If unable to unlockFocus (e.g. wxPaintDC) stop here
144 if(!dc->CocoaUnlockFocus())
145 break;
146 sm_cocoaDCStack.Erase(node);
147 }
148 return CocoaLockFocus();
149 }
150
151 wxCocoaDCImpl::wxCocoaDCImpl(wxDC *owner)
152 : wxDCImpl(owner)
153 {
154 m_cocoaWxToBoundsTransform = nil;
155 m_pen = *wxBLACK_PEN;
156 }
157
158 wxCocoaDCImpl::~wxDC(void)
159 {
160 [m_cocoaWxToBoundsTransform release];
161 }
162
163 bool wxCocoaDCImpl::CocoaLockFocus()
164 {
165 return false;
166 }
167
168 bool wxCocoaDCImpl::CocoaUnlockFocus()
169 {
170 return false;
171 }
172
173 /*static*/ WX_NSAffineTransform wxCocoaDCImpl::CocoaGetWxToBoundsTransform(bool isFlipped, float height)
174 {
175 NSAffineTransform *transform = nil;
176 // This transform flips the graphics since wxDC uses top-left origin
177 if(!isFlipped)
178 {
179 // The transform is auto released
180 transform = [NSAffineTransform transform];
181 /* x' = 1x + 0y + 0
182 y' = 0x + -1y + window's height
183 */
184 NSAffineTransformStruct matrix = {
185 1, 0
186 , 0, -1
187 , 0, height
188 };
189 [transform setTransformStruct: matrix];
190 }
191 return transform;
192 }
193
194 void wxCocoaDCImpl::CocoaApplyTransformations()
195 {
196 [m_cocoaWxToBoundsTransform concat];
197 // TODO: Apply device/logical/user position/scaling transformations
198 }
199
200 void wxCocoaDCImpl::CocoaUnapplyTransformations()
201 {
202 // NOTE: You *must* call this with focus held.
203 // Undo all transforms so we're back in true Cocoa coords with
204 // no scaling or flipping.
205 NSAffineTransform *invertTransform;
206 invertTransform = [m_cocoaWxToBoundsTransform copy];
207 [invertTransform invert];
208 [invertTransform concat];
209 [invertTransform release];
210 }
211
212 bool wxCocoaDCImpl::CocoaGetBounds(void *rectData)
213 {
214 // We don't know what we are so we can't return anything.
215 return false;
216 }
217
218 void wxCocoaDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
219 {
220 wxAutoNSAutoreleasePool pool;
221 if(!CocoaTakeFocus()) return;
222 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,width,height)];
223 CocoaSetPenForNSBezierPath(m_pen,bezpath);
224 [bezpath stroke];
225 [m_brush.GetNSColor() set];
226 [bezpath fill];
227 }
228
229 void wxCocoaDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
230 {
231 wxAutoNSAutoreleasePool pool;
232 if(!CocoaTakeFocus()) return;
233 NSBezierPath *bezpath = [NSBezierPath bezierPath];
234 [bezpath moveToPoint:NSMakePoint(x1,y1)];
235 [bezpath lineToPoint:NSMakePoint(x2,y2)];
236
237 CocoaSetPenForNSBezierPath(m_pen,bezpath);
238 [bezpath stroke];
239 }
240
241 void wxCocoaDCImpl::DoGetTextExtent(const wxString& text, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, const wxFont *theFont) const
242 {
243 wxAutoNSAutoreleasePool pool;
244 // FIXME: Cache this so it can be used for DoDrawText
245 wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!"));
246 NSAttributedString *attributedString = [[NSAttributedString alloc]
247 initWithString:wxNSStringWithWxString(text.c_str())];
248 [sm_cocoaNSTextStorage setAttributedString:attributedString];
249 [attributedString release];
250
251 NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer];
252 NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer];
253 if(x)
254 *x=(int)usedRect.size.width;
255 if(y)
256 *y=(int)usedRect.size.height;
257 if(descent)
258 *descent=0;
259 if(externalLeading)
260 *externalLeading=0;
261 }
262
263 void wxCocoaDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
264 {
265 wxAutoNSAutoreleasePool pool;
266 if(!CocoaTakeFocus()) return;
267 wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!"));
268 NSAttributedString *attributedString = [[NSAttributedString alloc]
269 initWithString:wxNSStringWithWxString(text.c_str())];
270 [sm_cocoaNSTextStorage setAttributedString:attributedString];
271 [attributedString release];
272
273 // Set the color (and later font) attributes
274 NSColor *fgColor = m_textForegroundColour.GetNSColor();
275 NSColor *bgColor = m_textBackgroundColour.GetNSColor();
276 if(!fgColor)
277 fgColor = [NSColor clearColor];
278 if(!bgColor)
279 bgColor = [NSColor clearColor];
280 NSDictionary *attrDict = [[NSDictionary alloc] initWithObjectsAndKeys:
281 fgColor, NSForegroundColorAttributeName,
282 bgColor, NSBackgroundColorAttributeName,
283 nil];
284 [sm_cocoaNSTextStorage addAttributes: attrDict range:NSMakeRange(0,[sm_cocoaNSTextStorage length])];
285 [attrDict release];
286
287 NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer];
288 NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer];
289 // NOTE: We'll crash trying to get the location of glyphAtIndex:0 if
290 // there is no length or we don't start at zero
291 if(!glyphRange.length)
292 return;
293 wxASSERT_MSG(glyphRange.location==0,wxT("glyphRange must begin at zero"));
294
295 NSAffineTransform *transform = [NSAffineTransform transform];
296 [transform translateXBy:x yBy:y];
297
298 NSAffineTransform *flipTransform = [NSAffineTransform transform];
299 /* x' = 1x + 0y + 0
300 y' = 0x + -1y + window's height
301 */
302 NSAffineTransformStruct matrix = {
303 1, 0
304 , 0, -1
305 , 0, usedRect.size.height
306 };
307 [flipTransform setTransformStruct: matrix];
308
309 NSGraphicsContext *context = [NSGraphicsContext currentContext];
310 [context saveGraphicsState];
311 [transform concat];
312 [flipTransform concat];
313 #if 0
314 // Draw+fill a rectangle so we can see where the shit is supposed to be.
315 wxLogTrace(wxTRACE_COCOA,wxT("(%f,%f) (%fx%f)"),usedRect.origin.x,usedRect.origin.y,usedRect.size.width,usedRect.size.height);
316 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(0,0,usedRect.size.width,usedRect.size.height)];
317 [[NSColor blackColor] set];
318 [bezpath stroke];
319 [[NSColor blueColor] set];
320 [bezpath fill];
321 #endif
322
323 NSPoint layoutLocation = [sm_cocoaNSLayoutManager locationForGlyphAtIndex:0];
324 layoutLocation.x = 0.0;
325 layoutLocation.y *= -1.0;
326
327 // Save the location as is for underlining
328 NSPoint underlineLocation = layoutLocation;
329
330 // Offset the location by the baseline for drawing the glyphs.
331 layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0];
332
333 if(m_backgroundMode==wxSOLID)
334 [sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint];
335 [sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation];
336
337 int underlineStyle = GetFont().GetUnderlined() ? NSUnderlineStyleSingle : NSUnderlineStyleNone;
338 NSRange lineGlyphRange;
339 NSRect lineRect = [sm_cocoaNSLayoutManager lineFragmentRectForGlyphAtIndex:0 effectiveRange:&lineGlyphRange];
340
341 [sm_cocoaNSLayoutManager underlineGlyphRange:glyphRange underlineType:underlineStyle
342 lineFragmentRect:lineRect lineFragmentGlyphRange:lineGlyphRange
343 containerOrigin:underlineLocation];
344
345 [context restoreGraphicsState];
346 }
347
348 ///////////////////////////////////////////////////////////////////////////
349 // cut here, the rest is stubs
350 ///////////////////////////////////////////////////////////////////////////
351
352 //-----------------------------------------------------------------------------
353 // wxDC
354 //-----------------------------------------------------------------------------
355
356 void wxCocoaDCImpl::DoDrawIcon( const wxIcon &WXUNUSED(icon), int WXUNUSED(x), int WXUNUSED(y) )
357 {
358 };
359
360 void wxCocoaDCImpl::DoDrawPoint( int x, int y )
361 {
362 };
363
364 void wxCocoaDCImpl::DoDrawPolygon( int, const wxPoint *, int, int, wxPolygonFillMode)
365 {
366 };
367
368 void wxCocoaDCImpl::DoDrawLines( int, const wxPoint *, int, int )
369 {
370 }
371
372 int wxCocoaDCImpl::GetDepth() const
373 {
374 return 0;
375 }
376
377 wxSize wxCocoaDCImpl::GetPPI() const
378 {
379 return wxSize(0,0);
380 }
381
382 bool wxCocoaDCImpl::CanGetTextExtent() const
383 {
384 return false;
385 }
386
387 wxCoord wxCocoaDCImpl::GetCharHeight() const
388 {
389 return 0;
390 }
391
392 wxCoord wxCocoaDCImpl::GetCharWidth() const
393 {
394 return 0;
395 }
396
397 bool wxCocoaDCImpl::CanDrawBitmap() const
398 {
399 return true;
400 }
401
402 bool wxCocoaDCImpl::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
403 {
404 return false;
405 }
406
407 void wxCocoaDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
408 {
409 }
410
411 void wxCocoaDCImpl::SetFont(const wxFont& font)
412 {
413 m_font = font;
414 }
415
416 void wxCocoaDCImpl::SetPen(const wxPen& pen)
417 {
418 m_pen = pen;
419 }
420
421 void wxCocoaDCImpl::SetBrush(const wxBrush& brush)
422 {
423 m_brush = brush;
424 }
425
426 void wxCocoaDCImpl::DoSetClippingRegionAsRegion(const wxRegion& region)
427 {
428 }
429
430 void wxCocoaDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
431 {
432 }
433
434 void wxCocoaDCImpl::DestroyClippingRegion()
435 {
436 }
437
438 void wxCocoaDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
439 {
440 }
441
442 void wxCocoaDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
443 {
444 }
445
446 void wxCocoaDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea)
447 {
448 }
449
450 void wxCocoaDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
451 {
452 }
453
454 void wxCocoaDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
455 {
456 wxAutoNSAutoreleasePool pool;
457 if(!CocoaTakeFocus()) return;
458 if(!bmp.IsOk())
459 return;
460
461 #if 0
462 // Draw a rect so we can see where it's supposed to be
463 wxLogTrace(wxTRACE_COCOA,wxT("image at (%d,%d) size %dx%d"),x,y,bmp.GetWidth(),bmp.GetHeight());
464 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,bmp.GetWidth(),bmp.GetHeight())];
465 [[NSColor blackColor] set];
466 [bezpath stroke];
467 [[NSColor blueColor] set];
468 [bezpath fill];
469 #endif // 0
470
471 NSAffineTransform *transform = [NSAffineTransform transform];
472 [transform translateXBy:x yBy:y];
473
474 NSAffineTransform *flipTransform = [NSAffineTransform transform];
475 /* x' = 1x + 0y + 0
476 y' = 0x + -1y + window's height
477 */
478 NSAffineTransformStruct matrix = {
479 1, 0
480 , 0, -1
481 , 0, bmp.GetHeight()
482 };
483 [flipTransform setTransformStruct: matrix];
484
485 NSGraphicsContext *context = [NSGraphicsContext currentContext];
486 [context saveGraphicsState];
487 [transform concat];
488 [flipTransform concat];
489
490 NSImage *nsimage = [bmp.GetNSImage(useMask) retain];
491
492 [nsimage drawAtPoint: NSMakePoint(0,0)
493 fromRect: NSMakeRect(0.0,0.0,bmp.GetWidth(),bmp.GetHeight())
494 operation: NSCompositeSourceOver
495 fraction: 1.0];
496
497 [nsimage release];
498 [context restoreGraphicsState];
499 }
500
501 bool wxCocoaDCImpl::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, wxFloodFillStyle style)
502 {
503 return false;
504 }
505
506 void wxCocoaDCImpl::DoCrossHair(wxCoord x, wxCoord y)
507 {
508 }
509
510
511 bool wxCocoaDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, wxRasterOperationMode rop, bool useMask , wxCoord xsrcMask, wxCoord ysrcMask)
512 {
513 if(!CocoaTakeFocus()) return false;
514 if(!source) return false;
515 wxCocoaDCImpl *sourceImpl = static_cast<wxCocoaDCImpl*>(source->GetImpl());
516 return sourceImpl->CocoaDoBlitOnFocusedDC(xdest,ydest,width,height,
517 xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
518 }
519
520 bool wxCocoaDCImpl::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
521 wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc,
522 int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask)
523 {
524 return false;
525 }
526
527 void wxCocoaDCImpl::DoGetSize( int* width, int* height ) const
528 {
529 *width = m_maxX-m_minX;
530 *height = m_maxY-m_minY;
531 };
532
533 void wxCocoaDCImpl::DoGetSizeMM( int* width, int* height ) const
534 {
535 int w = 0;
536 int h = 0;
537 DoGetSize( &w, &h );
538 };
539
540 void wxCocoaDCImpl::SetTextForeground( const wxColour &col )
541 {
542 // if (!IsOk()) return;
543 m_textForegroundColour = col;
544 };
545
546 void wxCocoaDCImpl::SetTextBackground( const wxColour &col )
547 {
548 // if (!IsOk()) return;
549 m_textBackgroundColour = col;
550 };
551
552 void wxCocoaDCImpl::Clear()
553 {
554 if(!CocoaTakeFocus()) return;
555
556 NSRect boundsRect;
557 if(!CocoaGetBounds(&boundsRect)) return;
558
559 NSGraphicsContext *context = [NSGraphicsContext currentContext];
560 [context saveGraphicsState];
561
562 // Undo all transforms so when we draw our bounds rect we
563 // really overwrite our bounds rect.
564 CocoaUnapplyTransformations();
565
566 [m_backgroundBrush.GetNSColor() set];
567 [NSBezierPath fillRect:boundsRect];
568
569 [context restoreGraphicsState];
570 }
571
572 void wxCocoaDCImpl::SetBackground(const wxBrush& brush)
573 {
574 m_backgroundBrush = brush;
575 }
576
577 void wxCocoaDCImpl::SetPalette(const wxPalette&)
578 {
579 }
580
581 void wxCocoaDCImpl::SetLogicalFunction(wxRasterOperationMode)
582 {
583 }
584
585
586 void wxCocoaDCImpl::SetMapMode( wxMappingMode mode )
587 {
588 switch (mode)
589 {
590 case wxMM_TWIPS:
591 break;
592 case wxMM_POINTS:
593 break;
594 case wxMM_METRIC:
595 break;
596 case wxMM_LOMETRIC:
597 break;
598 default:
599 case wxMM_TEXT:
600 SetLogicalScale( 1.0, 1.0 );
601 break;
602 };
603 if (mode != wxMM_TEXT)
604 {
605 };
606 };
607
608 void wxCocoaDCImpl::SetUserScale( double x, double y )
609 {
610 // allow negative ? -> no
611 m_userScaleX = x;
612 m_userScaleY = y;
613 ComputeScaleAndOrigin();
614 };
615
616 void wxCocoaDCImpl::SetLogicalScale( double x, double y )
617 {
618 // allow negative ?
619 m_logicalScaleX = x;
620 m_logicalScaleY = y;
621 ComputeScaleAndOrigin();
622 };
623
624 void wxCocoaDCImpl::SetLogicalOrigin( wxCoord x, wxCoord y )
625 {
626 m_logicalOriginX = x * m_signX; // is this still correct ?
627 m_logicalOriginY = y * m_signY;
628 ComputeScaleAndOrigin();
629 };
630
631 void wxCocoaDCImpl::SetDeviceOrigin( wxCoord x, wxCoord y )
632 {
633 ComputeScaleAndOrigin();
634 };
635
636 void wxCocoaDCImpl::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
637 {
638 m_signX = (xLeftRight ? 1 : -1);
639 m_signY = (yBottomUp ? -1 : 1);
640 ComputeScaleAndOrigin();
641 };
642
643 void wxCocoaDCImpl::ComputeScaleAndOrigin(void)
644 {
645 // CMB: copy scale to see if it changes
646 double origScaleX = m_scaleX;
647 double origScaleY = m_scaleY;
648
649 m_scaleX = m_logicalScaleX * m_userScaleX;
650 m_scaleY = m_logicalScaleY * m_userScaleY;
651
652 // CMB: if scale has changed call SetPen to recalulate the line width
653 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
654 {
655 #if 0
656 // this is a bit artificial, but we need to force wxDC to think
657 // the pen has changed
658 const wxPen* pen = & GetPen();
659 wxPen tempPen;
660 m_pen = tempPen;
661 SetPen(* pen);
662 #endif
663 }
664 };