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