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