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
);
19 class WXDLLIMPEXP_FWD_CORE wxCocoaDCImpl
;
20 WX_DECLARE_LIST(wxCocoaDCImpl
, wxCocoaDCStack
);
22 //=========================================================================
24 //=========================================================================
25 class WXDLLIMPEXP_CORE wxCocoaDCImpl
: public wxDCImpl
27 DECLARE_ABSTRACT_CLASS(wxCocoaDCImpl
)
28 wxDECLARE_NO_COPY_CLASS(wxCocoaDCImpl
);
29 //-------------------------------------------------------------------------
31 //-------------------------------------------------------------------------
33 wxCocoaDCImpl(wxDC
*owner
);
34 virtual ~wxCocoaDCImpl();
36 //-------------------------------------------------------------------------
38 //-------------------------------------------------------------------------
40 static void CocoaInitializeTextSystem();
41 static void CocoaShutdownTextSystem();
42 static WX_NSTextStorage sm_cocoaNSTextStorage
;
43 static WX_NSLayoutManager sm_cocoaNSLayoutManager
;
44 static WX_NSTextContainer sm_cocoaNSTextContainer
;
45 // Create a simple Wx to Bounds transform (just flip the coordinate system)
46 static WX_NSAffineTransform
CocoaGetWxToBoundsTransform(bool isFlipped
, float height
);
49 static wxCocoaDCStack sm_cocoaDCStack
;
50 virtual bool CocoaLockFocus();
51 virtual bool CocoaUnlockFocus();
52 bool CocoaUnwindStackAndTakeFocus();
53 inline bool CocoaTakeFocus()
55 wxCocoaDCStack::compatibility_iterator node
= sm_cocoaDCStack
.GetFirst();
56 if(node
&& (node
->GetData() == this))
58 return CocoaUnwindStackAndTakeFocus();
60 void CocoaUnwindStackAndLoseFocus();
61 // DC flipping/transformation
62 void CocoaApplyTransformations();
63 void CocoaUnapplyTransformations();
64 WX_NSAffineTransform m_cocoaWxToBoundsTransform
;
65 // Get bounds rect (for Clear())
66 // note: we use void * to mean NSRect * so that we can avoid
67 // putting NSRect in the headers.
68 virtual bool CocoaGetBounds(void *rectData
);
70 virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest
, wxCoord ydest
,
71 wxCoord width
, wxCoord height
, wxCoord xsrc
, wxCoord ysrc
,
72 wxRasterOperationMode logicalFunc
, bool useMask
, wxCoord xsrcMask
, wxCoord ysrcMask
);
73 //-------------------------------------------------------------------------
75 //-------------------------------------------------------------------------
77 // implement base class pure virtuals
78 // ----------------------------------
82 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
83 virtual void EndDoc(void) {}
85 virtual void StartPage(void) {}
86 virtual void EndPage(void) {}
88 virtual void SetFont(const wxFont
& font
);
89 virtual void SetPen(const wxPen
& pen
);
90 virtual void SetBrush(const wxBrush
& brush
);
91 virtual void SetBackground(const wxBrush
& brush
);
92 virtual void SetBackgroundMode(int mode
) { m_backgroundMode
= mode
; }
93 virtual void SetPalette(const wxPalette
& palette
);
95 virtual void DestroyClippingRegion();
97 virtual wxCoord
GetCharHeight() const;
98 virtual wxCoord
GetCharWidth() const;
99 virtual void DoGetTextExtent(const wxString
& string
,
100 wxCoord
*x
, wxCoord
*y
,
101 wxCoord
*descent
= NULL
,
102 wxCoord
*externalLeading
= NULL
,
103 const wxFont
*theFont
= NULL
) const;
105 virtual bool CanDrawBitmap() const;
106 virtual bool CanGetTextExtent() const;
107 virtual int GetDepth() const;
108 virtual wxSize
GetPPI() const;
110 virtual void SetMapMode(wxMappingMode mode
);
111 virtual void SetUserScale(double x
, double y
);
113 virtual void SetLogicalScale(double x
, double y
);
114 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
115 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
116 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
117 virtual void SetLogicalFunction(wxRasterOperationMode function
);
119 virtual void SetTextForeground(const wxColour
& colour
) ;
120 virtual void SetTextBackground(const wxColour
& colour
) ;
122 virtual void ComputeScaleAndOrigin();
124 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
125 wxFloodFillStyle style
= wxFLOOD_SURFACE
);
127 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
129 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
130 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
132 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
133 wxCoord x2
, wxCoord y2
,
134 wxCoord xc
, wxCoord yc
);
136 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
137 double sa
, double ea
);
139 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
140 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
141 wxCoord width
, wxCoord height
,
143 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
145 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
147 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
148 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
149 bool useMask
= false);
151 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
152 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
155 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
156 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
157 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
159 // this is gnarly - we can't even call this function DoSetClippingRegion()
160 // because of virtual function hiding
161 virtual void DoSetDeviceClippingRegion(const wxRegion
& region
);
162 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
163 wxCoord width
, wxCoord height
);
165 virtual void DoGetSize(int *width
, int *height
) const;
166 virtual void DoGetSizeMM(int* width
, int* height
) const;
168 virtual void DoDrawLines(int n
, const wxPoint points
[],
169 wxCoord xoffset
, wxCoord yoffset
);
170 virtual void DoDrawPolygon(int n
, const wxPoint points
[],
171 wxCoord xoffset
, wxCoord yoffset
,
172 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
175 #endif // __WX_COCOA_DC_H__