1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_DC_H__
13 #define __WX_COCOA_DC_H__
15 DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform
);
17 class WXDLLEXPORT wxDC
;
18 WX_DECLARE_LIST(wxDC
, wxCocoaDCStack
);
20 //=========================================================================
22 //=========================================================================
23 class WXDLLEXPORT wxDC
: public wxDCBase
25 DECLARE_DYNAMIC_CLASS(wxDC
)
26 DECLARE_NO_COPY_CLASS(wxDC
)
27 //-------------------------------------------------------------------------
29 //-------------------------------------------------------------------------
34 //-------------------------------------------------------------------------
36 //-------------------------------------------------------------------------
38 static void CocoaInitializeTextSystem();
39 static void CocoaShutdownTextSystem();
40 static WX_NSTextStorage sm_cocoaNSTextStorage
;
41 static WX_NSLayoutManager sm_cocoaNSLayoutManager
;
42 static WX_NSTextContainer sm_cocoaNSTextContainer
;
43 // Create a simple Wx to Bounds transform (just flip the coordinate system)
44 static WX_NSAffineTransform
CocoaGetWxToBoundsTransform(bool isFlipped
, float height
);
47 static wxCocoaDCStack sm_cocoaDCStack
;
48 virtual bool CocoaLockFocus();
49 virtual bool CocoaUnlockFocus();
50 bool CocoaUnwindStackAndTakeFocus();
51 inline bool CocoaTakeFocus()
53 wxCocoaDCStack::compatibility_iterator node
= sm_cocoaDCStack
.GetFirst();
54 if(node
&& (node
->GetData() == this))
56 return CocoaUnwindStackAndTakeFocus();
58 void CocoaUnwindStackAndLoseFocus();
59 // DC flipping/transformation
60 void CocoaApplyTransformations();
61 void CocoaUnapplyTransformations();
62 WX_NSAffineTransform m_cocoaWxToBoundsTransform
;
63 // Get bounds rect (for Clear())
64 // note: we use void * to mean NSRect * so that we can avoid
65 // putting NSRect in the headers.
66 virtual bool CocoaGetBounds(void *rectData
);
68 virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest
, wxCoord ydest
,
69 wxCoord width
, wxCoord height
, wxCoord xsrc
, wxCoord ysrc
,
70 int logicalFunc
, bool useMask
, wxCoord xsrcMask
, wxCoord ysrcMask
);
71 //-------------------------------------------------------------------------
73 //-------------------------------------------------------------------------
75 // implement base class pure virtuals
76 // ----------------------------------
80 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
81 virtual void EndDoc(void) {};
83 virtual void StartPage(void) {};
84 virtual void EndPage(void) {};
86 virtual void SetFont(const wxFont
& font
) {}
87 virtual void SetPen(const wxPen
& pen
);
88 virtual void SetBrush(const wxBrush
& brush
);
89 virtual void SetBackground(const wxBrush
& brush
);
90 virtual void SetBackgroundMode(int mode
) { m_backgroundMode
= mode
; }
91 virtual void SetPalette(const wxPalette
& palette
);
93 virtual void DestroyClippingRegion();
95 virtual wxCoord
GetCharHeight() const;
96 virtual wxCoord
GetCharWidth() const;
97 virtual void DoGetTextExtent(const wxString
& string
,
98 wxCoord
*x
, wxCoord
*y
,
99 wxCoord
*descent
= NULL
,
100 wxCoord
*externalLeading
= NULL
,
101 wxFont
*theFont
= NULL
) const;
103 virtual bool CanDrawBitmap() const;
104 virtual bool CanGetTextExtent() const;
105 virtual int GetDepth() const;
106 virtual wxSize
GetPPI() const;
108 virtual void SetMapMode(int mode
);
109 virtual void SetUserScale(double x
, double y
);
111 virtual void SetLogicalScale(double x
, double y
);
112 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
113 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
114 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
115 virtual void SetLogicalFunction(int function
);
117 virtual void SetTextForeground(const wxColour
& colour
) ;
118 virtual void SetTextBackground(const wxColour
& colour
) ;
120 virtual void ComputeScaleAndOrigin();
122 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
123 int style
= wxFLOOD_SURFACE
);
125 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
127 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
128 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
130 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
131 wxCoord x2
, wxCoord y2
,
132 wxCoord xc
, wxCoord yc
);
134 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
135 double sa
, double ea
);
137 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
138 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
139 wxCoord width
, wxCoord height
,
141 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
143 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
145 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
146 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
147 bool useMask
= false);
149 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
150 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
153 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
154 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
155 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
157 // this is gnarly - we can't even call this function DoSetClippingRegion()
158 // because of virtual function hiding
159 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
160 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
161 wxCoord width
, wxCoord height
);
163 virtual void DoGetSize(int *width
, int *height
) const;
164 virtual void DoGetSizeMM(int* width
, int* height
) const;
166 virtual void DoDrawLines(int n
, wxPoint points
[],
167 wxCoord xoffset
, wxCoord yoffset
);
168 virtual void DoDrawPolygon(int n
, wxPoint points
[],
169 wxCoord xoffset
, wxCoord yoffset
,
170 int fillStyle
= wxODDEVEN_RULE
);
173 #endif // __WX_COCOA_DC_H__