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