]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/dcclient.mm
make string at least empty (instead of containing garbage) if malloc() failed
[wxWidgets.git] / src / cocoa / dcclient.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dcclient.mm
3 // Purpose: wxWindowDC, wxPaintDC, and wxClientDC classes
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/04/01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/dcclient.h"
13 #include "wx/window.h"
14
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>
20
21 /*
22 * wxWindowDC
23 */
24 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
25
26 wxWindowDC::wxWindowDC(void)
27 : m_window(NULL)
28 {
29 };
30
31 wxWindowDC::wxWindowDC( wxWindow *window )
32 : m_window(window)
33 {
34 wxFAIL_MSG("non-client window DC's are not supported");
35 };
36
37 wxWindowDC::~wxWindowDC(void)
38 {
39 };
40
41 void wxWindowDC::Clear()
42 {
43 wxASSERT(m_window);
44
45 NSGraphicsContext *context = [NSGraphicsContext currentContext];
46 [context saveGraphicsState];
47
48 [m_backgroundBrush.GetNSColor() set];
49 [NSBezierPath fillRect:[m_window->GetNSView() bounds]];
50
51 [context restoreGraphicsState];
52 }
53
54 /*
55 * wxClientDC
56 */
57 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
58
59 wxClientDC::wxClientDC(void)
60 {
61 };
62
63 wxClientDC::wxClientDC( wxWindow *window )
64 {
65 m_window = window;
66 };
67
68 wxClientDC::~wxClientDC(void)
69 {
70 };
71
72 /*
73 * wxPaintDC
74 */
75 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
76
77 wxPaintDC::wxPaintDC(void)
78 {
79 };
80
81 wxPaintDC::wxPaintDC( wxWindow *window )
82 {
83 m_window = 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])
87 {
88 // The transform is auto released
89 NSAffineTransform *transform = [NSAffineTransform transform];
90 /* x' = 1x + 0y + 0
91 y' = 0x + -1y + window's height
92 */
93 NSAffineTransformStruct matrix = {
94 1, 0
95 , 0, -1
96 , 0, [window->GetNSView() bounds].size.height
97 };
98 [transform setTransformStruct: matrix];
99 // Apply the transform
100 [transform concat];
101 }
102 // TODO: Apply scaling transformation
103 };
104
105 wxPaintDC::~wxPaintDC(void)
106 {
107 };
108