]>
Commit | Line | Data |
---|---|---|
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 |
da80ae71 | 9 | // Licence: wxWidgets licence |
a24aff65 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
449c5673 | 12 | #include "wx/wxprec.h" |
da80ae71 | 13 | |
938156b2 | 14 | #include "wx/cocoa/dc.h" |
da80ae71 | 15 | |
449c5673 DE |
16 | #ifndef WX_PRECOMP |
17 | #include "wx/log.h" | |
18680f86 | 18 | #include "wx/math.h" //math constants |
449c5673 | 19 | #endif //WX_PRECOMP |
a24aff65 | 20 | |
7fc77f30 | 21 | #include "wx/cocoa/autorelease.h" |
b0c0a393 | 22 | #include "wx/cocoa/string.h" |
7fc77f30 | 23 | |
891d0563 DE |
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> | |
f910a887 | 31 | #import <AppKit/NSTypesetter.h> |
1fd17880 | 32 | #import <AppKit/NSImage.h> |
891d0563 | 33 | |
d8418952 | 34 | #include "wx/listimpl.cpp" |
fe8f7943 DE |
35 | WX_DEFINE_LIST(wxCocoaDCStack); |
36 | ||
938156b2 DE |
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; | |
891d0563 | 43 | |
5eb5a0ac DE |
44 | inline void CocoaSetPenForNSBezierPath(wxPen &pen, NSBezierPath *bezpath) |
45 | { | |
46 | [pen.GetNSColor() set]; | |
4799f3ba | 47 | const CGFloat *pattern; |
5eb5a0ac DE |
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 | ||
938156b2 | 76 | void wxCocoaDCImpl::CocoaInitializeTextSystem() |
891d0563 | 77 | { |
2b030203 | 78 | wxASSERT_MSG(!sm_cocoaNSTextStorage && !sm_cocoaNSLayoutManager && !sm_cocoaNSTextContainer,wxT("Text system already initalized! BAD PROGRAMMER!")); |
891d0563 DE |
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 | ||
938156b2 | 96 | void wxCocoaDCImpl::CocoaShutdownTextSystem() |
891d0563 DE |
97 | { |
98 | [sm_cocoaNSTextContainer release]; sm_cocoaNSTextContainer = nil; | |
99 | [sm_cocoaNSLayoutManager release]; sm_cocoaNSLayoutManager = nil; | |
100 | [sm_cocoaNSTextStorage release]; sm_cocoaNSTextStorage = nil; | |
101 | } | |
102 | ||
938156b2 | 103 | void wxCocoaDCImpl::CocoaUnwindStackAndLoseFocus() |
fe8f7943 | 104 | { |
7ce8248b | 105 | wxCocoaDCStack::compatibility_iterator ourNode=sm_cocoaDCStack.Find(this); |
fe8f7943 DE |
106 | if(ourNode) |
107 | { | |
7ce8248b | 108 | wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst(); |
fe8f7943 DE |
109 | for(;node!=ourNode; node=sm_cocoaDCStack.GetFirst()) |
110 | { | |
938156b2 | 111 | wxCocoaDCImpl *dc = node->GetData(); |
fe8f7943 DE |
112 | wxASSERT(dc); |
113 | wxASSERT(dc!=this); | |
114 | if(!dc->CocoaUnlockFocus()) | |
115 | { | |
2b030203 | 116 | wxFAIL_MSG(wxT("Unable to unlock focus on higher-level DC!")); |
fe8f7943 | 117 | } |
7ce8248b | 118 | sm_cocoaDCStack.Erase(node); |
fe8f7943 DE |
119 | } |
120 | wxASSERT(node==ourNode); | |
121 | wxASSERT(ourNode->GetData() == this); | |
122 | ourNode->GetData()->CocoaUnlockFocus(); | |
7ce8248b | 123 | sm_cocoaDCStack.Erase(ourNode); |
fe8f7943 DE |
124 | } |
125 | } | |
126 | ||
938156b2 | 127 | bool wxCocoaDCImpl::CocoaUnwindStackAndTakeFocus() |
fe8f7943 | 128 | { |
7ce8248b | 129 | wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst(); |
fe8f7943 DE |
130 | for(;node;node = sm_cocoaDCStack.GetFirst()) |
131 | { | |
938156b2 | 132 | wxCocoaDCImpl *dc = node->GetData(); |
fe8f7943 DE |
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; | |
7ce8248b | 140 | sm_cocoaDCStack.Erase(node); |
fe8f7943 DE |
141 | } |
142 | return CocoaLockFocus(); | |
143 | } | |
144 | ||
938156b2 DE |
145 | wxCocoaDCImpl::wxCocoaDCImpl(wxDC *owner) |
146 | : wxDCImpl(owner) | |
891d0563 | 147 | { |
db8512fe | 148 | m_cocoaWxToBoundsTransform = nil; |
5eb5a0ac | 149 | m_pen = *wxBLACK_PEN; |
891d0563 DE |
150 | } |
151 | ||
938156b2 | 152 | wxCocoaDCImpl::~wxDC(void) |
891d0563 | 153 | { |
1a1e9ff1 | 154 | [m_cocoaWxToBoundsTransform release]; |
891d0563 DE |
155 | } |
156 | ||
938156b2 | 157 | bool wxCocoaDCImpl::CocoaLockFocus() |
fe8f7943 DE |
158 | { |
159 | return false; | |
160 | } | |
161 | ||
938156b2 | 162 | bool wxCocoaDCImpl::CocoaUnlockFocus() |
fe8f7943 DE |
163 | { |
164 | return false; | |
165 | } | |
166 | ||
938156b2 | 167 | /*static*/ WX_NSAffineTransform wxCocoaDCImpl::CocoaGetWxToBoundsTransform(bool isFlipped, float height) |
fe8f7943 | 168 | { |
4db3c8ac | 169 | NSAffineTransform *transform = nil; |
fe8f7943 | 170 | // This transform flips the graphics since wxDC uses top-left origin |
4db3c8ac | 171 | if(!isFlipped) |
fe8f7943 DE |
172 | { |
173 | // The transform is auto released | |
4db3c8ac | 174 | transform = [NSAffineTransform transform]; |
fe8f7943 DE |
175 | /* x' = 1x + 0y + 0 |
176 | y' = 0x + -1y + window's height | |
177 | */ | |
178 | NSAffineTransformStruct matrix = { | |
179 | 1, 0 | |
180 | , 0, -1 | |
4db3c8ac | 181 | , 0, height |
fe8f7943 DE |
182 | }; |
183 | [transform setTransformStruct: matrix]; | |
fe8f7943 | 184 | } |
4db3c8ac DE |
185 | return transform; |
186 | } | |
187 | ||
938156b2 | 188 | void wxCocoaDCImpl::CocoaApplyTransformations() |
4db3c8ac DE |
189 | { |
190 | [m_cocoaWxToBoundsTransform concat]; | |
191 | // TODO: Apply device/logical/user position/scaling transformations | |
fe8f7943 DE |
192 | } |
193 | ||
938156b2 | 194 | void wxCocoaDCImpl::CocoaUnapplyTransformations() |
3e21fc05 DE |
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]; | |
f48ab29b | 203 | [invertTransform release]; |
3e21fc05 DE |
204 | } |
205 | ||
938156b2 | 206 | bool wxCocoaDCImpl::CocoaGetBounds(void *rectData) |
3e21fc05 DE |
207 | { |
208 | // We don't know what we are so we can't return anything. | |
209 | return false; | |
210 | } | |
211 | ||
938156b2 | 212 | void wxCocoaDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
891d0563 | 213 | { |
1b1f8b2d | 214 | wxAutoNSAutoreleasePool pool; |
fe8f7943 | 215 | if(!CocoaTakeFocus()) return; |
891d0563 | 216 | NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,width,height)]; |
5eb5a0ac | 217 | CocoaSetPenForNSBezierPath(m_pen,bezpath); |
891d0563 | 218 | [bezpath stroke]; |
c3b0c2c3 DE |
219 | [m_brush.GetNSColor() set]; |
220 | [bezpath fill]; | |
891d0563 DE |
221 | } |
222 | ||
938156b2 | 223 | void wxCocoaDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
891d0563 | 224 | { |
1b1f8b2d | 225 | wxAutoNSAutoreleasePool pool; |
fe8f7943 | 226 | if(!CocoaTakeFocus()) return; |
891d0563 DE |
227 | NSBezierPath *bezpath = [NSBezierPath bezierPath]; |
228 | [bezpath moveToPoint:NSMakePoint(x1,y1)]; | |
229 | [bezpath lineToPoint:NSMakePoint(x2,y2)]; | |
c3b0c2c3 | 230 | |
5eb5a0ac | 231 | CocoaSetPenForNSBezierPath(m_pen,bezpath); |
891d0563 DE |
232 | [bezpath stroke]; |
233 | } | |
234 | ||
938156b2 | 235 | void wxCocoaDCImpl::DoGetTextExtent(const wxString& text, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, const wxFont *theFont) const |
891d0563 | 236 | { |
7fc77f30 | 237 | wxAutoNSAutoreleasePool pool; |
891d0563 | 238 | // FIXME: Cache this so it can be used for DoDrawText |
2b030203 | 239 | wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!")); |
891d0563 | 240 | NSAttributedString *attributedString = [[NSAttributedString alloc] |
b0c0a393 | 241 | initWithString:wxNSStringWithWxString(text.c_str())]; |
891d0563 DE |
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) | |
dc483f61 | 248 | *x=(int)usedRect.size.width; |
891d0563 | 249 | if(y) |
dc483f61 | 250 | *y=(int)usedRect.size.height; |
891d0563 DE |
251 | if(descent) |
252 | *descent=0; | |
253 | if(externalLeading) | |
254 | *externalLeading=0; | |
255 | } | |
256 | ||
938156b2 | 257 | void wxCocoaDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y) |
891d0563 | 258 | { |
1b1f8b2d | 259 | wxAutoNSAutoreleasePool pool; |
fe8f7943 | 260 | if(!CocoaTakeFocus()) return; |
2b030203 | 261 | wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!")); |
891d0563 | 262 | NSAttributedString *attributedString = [[NSAttributedString alloc] |
b0c0a393 | 263 | initWithString:wxNSStringWithWxString(text.c_str())]; |
891d0563 DE |
264 | [sm_cocoaNSTextStorage setAttributedString:attributedString]; |
265 | [attributedString release]; | |
266 | ||
c0440c78 DE |
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 | ||
891d0563 DE |
281 | NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer]; |
282 | NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer]; | |
13fc3db4 DE |
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; | |
2b030203 | 287 | wxASSERT_MSG(glyphRange.location==0,wxT("glyphRange must begin at zero")); |
891d0563 DE |
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]; | |
c3b0c2c3 | 307 | #if 0 |
891d0563 | 308 | // Draw+fill a rectangle so we can see where the shit is supposed to be. |
48580976 | 309 | wxLogTrace(wxTRACE_COCOA,wxT("(%f,%f) (%fx%f)"),usedRect.origin.x,usedRect.origin.y,usedRect.size.width,usedRect.size.height); |
891d0563 DE |
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]; | |
c3b0c2c3 | 315 | #endif |
891d0563 DE |
316 | |
317 | NSPoint layoutLocation = [sm_cocoaNSLayoutManager locationForGlyphAtIndex:0]; | |
318 | layoutLocation.x = 0.0; | |
319 | layoutLocation.y *= -1.0; | |
e7e97a59 DE |
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. | |
891d0563 | 325 | layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0]; |
e7e97a59 | 326 | |
c0440c78 DE |
327 | if(m_backgroundMode==wxSOLID) |
328 | [sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint]; | |
891d0563 DE |
329 | [sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation]; |
330 | ||
e7e97a59 DE |
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 | ||
891d0563 DE |
339 | [context restoreGraphicsState]; |
340 | } | |
341 | ||
342 | /////////////////////////////////////////////////////////////////////////// | |
343 | // cut here, the rest is stubs | |
344 | /////////////////////////////////////////////////////////////////////////// | |
a24aff65 | 345 | |
a24aff65 DE |
346 | //----------------------------------------------------------------------------- |
347 | // wxDC | |
348 | //----------------------------------------------------------------------------- | |
349 | ||
938156b2 | 350 | void wxCocoaDCImpl::DoDrawIcon( const wxIcon &WXUNUSED(icon), int WXUNUSED(x), int WXUNUSED(y) ) |
a24aff65 DE |
351 | { |
352 | }; | |
353 | ||
938156b2 | 354 | void wxCocoaDCImpl::DoDrawPoint( int x, int y ) |
da80ae71 | 355 | { |
a24aff65 DE |
356 | }; |
357 | ||
938156b2 | 358 | void wxCocoaDCImpl::DoDrawPolygon( int, wxPoint *, int, int, int) |
a24aff65 DE |
359 | { |
360 | }; | |
361 | ||
938156b2 | 362 | void wxCocoaDCImpl::DoDrawLines( int, wxPoint *, int, int ) |
a24aff65 DE |
363 | { |
364 | } | |
365 | ||
938156b2 | 366 | int wxCocoaDCImpl::GetDepth() const |
a24aff65 DE |
367 | { |
368 | return 0; | |
369 | } | |
370 | ||
938156b2 | 371 | wxSize wxCocoaDCImpl::GetPPI() const |
a24aff65 DE |
372 | { |
373 | return wxSize(0,0); | |
374 | } | |
375 | ||
938156b2 | 376 | bool wxCocoaDCImpl::CanGetTextExtent() const |
a24aff65 DE |
377 | { |
378 | return false; | |
379 | } | |
380 | ||
938156b2 | 381 | wxCoord wxCocoaDCImpl::GetCharHeight() const |
a24aff65 DE |
382 | { |
383 | return 0; | |
384 | } | |
385 | ||
938156b2 | 386 | wxCoord wxCocoaDCImpl::GetCharWidth() const |
a24aff65 DE |
387 | { |
388 | return 0; | |
389 | } | |
390 | ||
938156b2 | 391 | bool wxCocoaDCImpl::CanDrawBitmap() const |
a24aff65 | 392 | { |
1fd17880 | 393 | return true; |
a24aff65 DE |
394 | } |
395 | ||
938156b2 | 396 | bool wxCocoaDCImpl::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const |
a24aff65 DE |
397 | { |
398 | return false; | |
399 | } | |
400 | ||
938156b2 | 401 | void wxCocoaDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc) |
a24aff65 DE |
402 | { |
403 | } | |
da80ae71 | 404 | |
938156b2 | 405 | void wxCocoaDCImpl::SetFont(const wxFont& font) |
e7e97a59 DE |
406 | { |
407 | m_font = font; | |
408 | } | |
409 | ||
938156b2 | 410 | void wxCocoaDCImpl::SetPen(const wxPen& pen) |
a24aff65 | 411 | { |
5eb5a0ac | 412 | m_pen = pen; |
a24aff65 DE |
413 | } |
414 | ||
938156b2 | 415 | void wxCocoaDCImpl::SetBrush(const wxBrush& brush) |
a24aff65 | 416 | { |
c3b0c2c3 | 417 | m_brush = brush; |
a24aff65 DE |
418 | } |
419 | ||
938156b2 | 420 | void wxCocoaDCImpl::DoSetClippingRegionAsRegion(const wxRegion& region) |
a24aff65 DE |
421 | { |
422 | } | |
423 | ||
938156b2 | 424 | void wxCocoaDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a24aff65 DE |
425 | { |
426 | } | |
427 | ||
938156b2 | 428 | void wxCocoaDCImpl::DestroyClippingRegion() |
a24aff65 DE |
429 | { |
430 | } | |
431 | ||
938156b2 | 432 | void wxCocoaDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) |
a24aff65 DE |
433 | { |
434 | } | |
435 | ||
938156b2 | 436 | void wxCocoaDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) |
a24aff65 DE |
437 | { |
438 | } | |
439 | ||
938156b2 | 440 | void wxCocoaDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea) |
a24aff65 DE |
441 | { |
442 | } | |
443 | ||
938156b2 | 444 | void wxCocoaDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a24aff65 DE |
445 | { |
446 | } | |
447 | ||
938156b2 | 448 | void wxCocoaDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) |
a24aff65 | 449 | { |
1b1f8b2d | 450 | wxAutoNSAutoreleasePool pool; |
fe8f7943 | 451 | if(!CocoaTakeFocus()) return; |
1fd17880 DE |
452 | if(!bmp.Ok()) |
453 | return; | |
454 | ||
455 | #if 0 | |
456 | // Draw a rect so we can see where it's supposed to be | |
48580976 | 457 | wxLogTrace(wxTRACE_COCOA,wxT("image at (%d,%d) size %dx%d"),x,y,bmp.GetWidth(),bmp.GetHeight()); |
1fd17880 DE |
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 | ||
a00daa65 DE |
484 | NSImage *nsimage = [bmp.GetNSImage(useMask) retain]; |
485 | ||
1fd17880 DE |
486 | [nsimage drawAtPoint: NSMakePoint(0,0) |
487 | fromRect: NSMakeRect(0.0,0.0,bmp.GetWidth(),bmp.GetHeight()) | |
a00daa65 | 488 | operation: NSCompositeSourceOver |
1fd17880 | 489 | fraction: 1.0]; |
da80ae71 | 490 | |
1fd17880 DE |
491 | [nsimage release]; |
492 | [context restoreGraphicsState]; | |
a24aff65 DE |
493 | } |
494 | ||
938156b2 | 495 | bool wxCocoaDCImpl::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) |
a24aff65 DE |
496 | { |
497 | return false; | |
498 | } | |
499 | ||
938156b2 | 500 | void wxCocoaDCImpl::DoCrossHair(wxCoord x, wxCoord y) |
a24aff65 DE |
501 | { |
502 | } | |
503 | ||
a24aff65 | 504 | |
938156b2 | 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) |
2c23fe91 DE |
506 | { |
507 | if(!CocoaTakeFocus()) return false; | |
508 | if(!source) return false; | |
938156b2 DE |
509 | wxCocoaDCImpl *sourceImpl = static_cast<wxCocoaDCImpl*>(source->GetImpl()); |
510 | return sourceImpl->CocoaDoBlitOnFocusedDC(xdest,ydest,width,height, | |
2c23fe91 DE |
511 | xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask); |
512 | } | |
513 | ||
938156b2 | 514 | bool wxCocoaDCImpl::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, |
2c23fe91 DE |
515 | wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, |
516 | int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) | |
a24aff65 DE |
517 | { |
518 | return false; | |
519 | } | |
520 | ||
938156b2 | 521 | void wxCocoaDCImpl::DoGetSize( int* width, int* height ) const |
a24aff65 DE |
522 | { |
523 | *width = m_maxX-m_minX; | |
524 | *height = m_maxY-m_minY; | |
525 | }; | |
526 | ||
938156b2 | 527 | void wxCocoaDCImpl::DoGetSizeMM( int* width, int* height ) const |
a24aff65 DE |
528 | { |
529 | int w = 0; | |
530 | int h = 0; | |
938156b2 | 531 | DoGetSize( &w, &h ); |
a24aff65 DE |
532 | }; |
533 | ||
938156b2 | 534 | void wxCocoaDCImpl::SetTextForeground( const wxColour &col ) |
a24aff65 | 535 | { |
938156b2 | 536 | // if (!Ok()) return; |
a24aff65 DE |
537 | m_textForegroundColour = col; |
538 | }; | |
539 | ||
938156b2 | 540 | void wxCocoaDCImpl::SetTextBackground( const wxColour &col ) |
a24aff65 | 541 | { |
938156b2 | 542 | // if (!Ok()) return; |
a24aff65 DE |
543 | m_textBackgroundColour = col; |
544 | }; | |
545 | ||
938156b2 | 546 | void wxCocoaDCImpl::Clear() |
a24aff65 | 547 | { |
3e21fc05 DE |
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]; | |
a24aff65 DE |
564 | } |
565 | ||
938156b2 | 566 | void wxCocoaDCImpl::SetBackground(const wxBrush& brush) |
a24aff65 | 567 | { |
7bc429ef | 568 | m_backgroundBrush = brush; |
a24aff65 DE |
569 | } |
570 | ||
938156b2 | 571 | void wxCocoaDCImpl::SetPalette(const wxPalette&) |
a24aff65 DE |
572 | { |
573 | } | |
574 | ||
938156b2 | 575 | void wxCocoaDCImpl::SetLogicalFunction(int) |
a24aff65 DE |
576 | { |
577 | } | |
578 | ||
579 | ||
938156b2 | 580 | void wxCocoaDCImpl::SetMapMode( int mode ) |
a24aff65 | 581 | { |
da80ae71 | 582 | switch (mode) |
a24aff65 DE |
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 | ||
938156b2 | 602 | void wxCocoaDCImpl::SetUserScale( double x, double y ) |
a24aff65 DE |
603 | { |
604 | // allow negative ? -> no | |
605 | m_userScaleX = x; | |
606 | m_userScaleY = y; | |
607 | ComputeScaleAndOrigin(); | |
608 | }; | |
609 | ||
938156b2 | 610 | void wxCocoaDCImpl::SetLogicalScale( double x, double y ) |
a24aff65 DE |
611 | { |
612 | // allow negative ? | |
613 | m_logicalScaleX = x; | |
614 | m_logicalScaleY = y; | |
615 | ComputeScaleAndOrigin(); | |
616 | }; | |
617 | ||
938156b2 | 618 | void wxCocoaDCImpl::SetLogicalOrigin( wxCoord x, wxCoord y ) |
a24aff65 DE |
619 | { |
620 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
621 | m_logicalOriginY = y * m_signY; | |
622 | ComputeScaleAndOrigin(); | |
623 | }; | |
624 | ||
938156b2 | 625 | void wxCocoaDCImpl::SetDeviceOrigin( wxCoord x, wxCoord y ) |
a24aff65 DE |
626 | { |
627 | ComputeScaleAndOrigin(); | |
628 | }; | |
629 | ||
938156b2 | 630 | void wxCocoaDCImpl::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
a24aff65 DE |
631 | { |
632 | m_signX = (xLeftRight ? 1 : -1); | |
633 | m_signY = (yBottomUp ? -1 : 1); | |
634 | ComputeScaleAndOrigin(); | |
635 | }; | |
636 | ||
938156b2 | 637 | void wxCocoaDCImpl::ComputeScaleAndOrigin(void) |
a24aff65 DE |
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 | ||
da80ae71 | 646 | // CMB: if scale has changed call SetPen to recalulate the line width |
a24aff65 DE |
647 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) |
648 | { | |
938156b2 | 649 | #if 0 |
a24aff65 DE |
650 | // this is a bit artificial, but we need to force wxDC to think |
651 | // the pen has changed | |
10c5f652 | 652 | const wxPen* pen = & GetPen(); |
a24aff65 DE |
653 | wxPen tempPen; |
654 | m_pen = tempPen; | |
655 | SetPen(* pen); | |
938156b2 | 656 | #endif |
a24aff65 DE |
657 | } |
658 | }; |