1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Elliott
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __WX_COCOA_DC_H__
12 #define __WX_COCOA_DC_H__
14 DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform
);
18 class WXDLLIMPEXP_FWD_CORE wxCocoaDCImpl
;
19 WX_DECLARE_LIST(wxCocoaDCImpl
, wxCocoaDCStack
);
21 //=========================================================================
23 //=========================================================================
24 class WXDLLIMPEXP_CORE wxCocoaDCImpl
: public wxDCImpl
26 DECLARE_ABSTRACT_CLASS(wxCocoaDCImpl
)
27 wxDECLARE_NO_COPY_CLASS(wxCocoaDCImpl
);
28 //-------------------------------------------------------------------------
30 //-------------------------------------------------------------------------
32 wxCocoaDCImpl(wxDC
*owner
);
33 virtual ~wxCocoaDCImpl();
35 //-------------------------------------------------------------------------
37 //-------------------------------------------------------------------------
39 static void CocoaInitializeTextSystem();
40 static void CocoaShutdownTextSystem();
41 static WX_NSTextStorage sm_cocoaNSTextStorage
;
42 static WX_NSLayoutManager sm_cocoaNSLayoutManager
;
43 static WX_NSTextContainer sm_cocoaNSTextContainer
;
44 // Create a simple Wx to Bounds transform (just flip the coordinate system)
45 static WX_NSAffineTransform
CocoaGetWxToBoundsTransform(bool isFlipped
, float height
);
48 static wxCocoaDCStack sm_cocoaDCStack
;
49 virtual bool CocoaLockFocus();
50 virtual bool CocoaUnlockFocus();
51 bool CocoaUnwindStackAndTakeFocus();
52 inline bool CocoaTakeFocus()
54 wxCocoaDCStack::compatibility_iterator node
= sm_cocoaDCStack
.GetFirst();
55 if(node
&& (node
->GetData() == this))
57 return CocoaUnwindStackAndTakeFocus();
59 void CocoaUnwindStackAndLoseFocus();
60 // DC flipping/transformation
61 void CocoaApplyTransformations();
62 void CocoaUnapplyTransformations();
63 WX_NSAffineTransform m_cocoaWxToBoundsTransform
;
64 // Get bounds rect (for Clear())
65 // note: we use void * to mean NSRect * so that we can avoid
66 // putting NSRect in the headers.
67 virtual bool CocoaGetBounds(void *rectData
);
69 virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest
, wxCoord ydest
,
70 wxCoord width
, wxCoord height
, wxCoord xsrc
, wxCoord ysrc
,
71 wxRasterOperationMode logicalFunc
, bool useMask
, wxCoord xsrcMask
, wxCoord ysrcMask
);
72 //-------------------------------------------------------------------------
74 //-------------------------------------------------------------------------
76 // implement base class pure virtuals
77 // ----------------------------------
81 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return true; }
82 virtual void EndDoc(void) {}
84 virtual void StartPage(void) {}
85 virtual void EndPage(void) {}
87 virtual void SetFont(const wxFont
& font
);
88 virtual void SetPen(const wxPen
& pen
);
89 virtual void SetBrush(const wxBrush
& brush
);
90 virtual void SetBackground(const wxBrush
& brush
);
91 virtual void SetBackgroundMode(int mode
) { m_backgroundMode
= mode
; }
92 virtual void SetPalette(const wxPalette
& palette
);
94 virtual void DestroyClippingRegion();
96 virtual wxCoord
GetCharHeight() const;
97 virtual wxCoord
GetCharWidth() const;
98 virtual void DoGetTextExtent(const wxString
& string
,
99 wxCoord
*x
, wxCoord
*y
,
100 wxCoord
*descent
= NULL
,
101 wxCoord
*externalLeading
= NULL
,
102 const wxFont
*theFont
= NULL
) const;
104 virtual bool CanDrawBitmap() const;
105 virtual bool CanGetTextExtent() const;
106 virtual int GetDepth() const;
107 virtual wxSize
GetPPI() const;
109 virtual void SetMapMode(wxMappingMode mode
);
110 virtual void SetUserScale(double x
, double y
);
112 virtual void SetLogicalScale(double x
, double y
);
113 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
114 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
115 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
116 virtual void SetLogicalFunction(wxRasterOperationMode function
);
118 virtual void SetTextForeground(const wxColour
& colour
) ;
119 virtual void SetTextBackground(const wxColour
& colour
) ;
121 virtual void ComputeScaleAndOrigin();
123 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
124 wxFloodFillStyle style
= wxFLOOD_SURFACE
);
126 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
128 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
129 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
131 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
132 wxCoord x2
, wxCoord y2
,
133 wxCoord xc
, wxCoord yc
);
135 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
136 double sa
, double ea
);
138 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
139 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
140 wxCoord width
, wxCoord height
,
142 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
144 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
146 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
147 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
148 bool useMask
= false);
150 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
151 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
154 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
155 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
156 int rop
= wxCOPY
, bool useMask
= false, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
158 // this is gnarly - we can't even call this function DoSetClippingRegion()
159 // because of virtual function hiding
160 virtual void DoSetDeviceClippingRegion(const wxRegion
& region
);
161 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
162 wxCoord width
, wxCoord height
);
164 virtual void DoGetSize(int *width
, int *height
) const;
165 virtual void DoGetSizeMM(int* width
, int* height
) const;
167 virtual void DoDrawLines(int n
, const wxPoint points
[],
168 wxCoord xoffset
, wxCoord yoffset
);
169 virtual void DoDrawPolygon(int n
, const wxPoint points
[],
170 wxCoord xoffset
, wxCoord yoffset
,
171 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
174 #endif // __WX_COCOA_DC_H__