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