1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dcclient.mm
3 // Purpose: wxWindowDC, wxPaintDC, and wxClientDC classes
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/dcclient.h"
13 #include "wx/window.h"
15 #import <AppKit/NSView.h>
16 #import <AppKit/NSAffineTransform.h>
17 #import <AppKit/NSColor.h>
18 #import <AppKit/NSGraphicsContext.h>
19 #import <AppKit/NSBezierPath.h>
24 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
26 wxWindowDC::wxWindowDC(void)
31 wxWindowDC::wxWindowDC( wxWindow *window )
34 wxFAIL_MSG("non-client window DC's are not supported");
37 wxWindowDC::~wxWindowDC(void)
41 void wxWindowDC::Clear()
45 NSGraphicsContext *context = [NSGraphicsContext currentContext];
46 [context saveGraphicsState];
48 [m_backgroundBrush.GetNSColor() set];
49 [NSBezierPath fillRect:[m_window->GetNSView() bounds]];
51 [context restoreGraphicsState];
57 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
59 wxClientDC::wxClientDC(void)
63 wxClientDC::wxClientDC( wxWindow *window )
68 wxClientDC::~wxClientDC(void)
75 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
77 wxPaintDC::wxPaintDC(void)
81 wxPaintDC::wxPaintDC( wxWindow *window )
84 wxASSERT_MSG([NSView focusView]==window->GetNSView(), "PaintDC's NSView does not have focus. Please use wxPaintDC only as the first DC created in a paint handler");
85 // This transform flips the graphics since wxDC uses top-left origin
86 if(![window->GetNSView() isFlipped])
88 // The transform is auto released
89 NSAffineTransform *transform = [NSAffineTransform transform];
91 y' = 0x + -1y + window's height
93 NSAffineTransformStruct matrix = {
96 , 0, [window->GetNSView() bounds].size.height
98 [transform setTransformStruct: matrix];
99 // Apply the transform
102 // TODO: Apply scaling transformation
105 wxPaintDC::~wxPaintDC(void)