]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/classic/dc.h
check the item id validity in SetItem()
[wxWidgets.git] / include / wx / mac / classic / dc.h
CommitLineData
52479aef
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.h
3// Purpose: wxDC class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
52479aef
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DC_H_
13#define _WX_DC_H_
14
52479aef
SC
15#include "wx/pen.h"
16#include "wx/brush.h"
17#include "wx/icon.h"
18#include "wx/font.h"
19#include "wx/gdicmn.h"
20
21//-----------------------------------------------------------------------------
22// constants
23//-----------------------------------------------------------------------------
24
25#ifndef MM_TEXT
26#define MM_TEXT 0
27#define MM_ISOTROPIC 1
28#define MM_ANISOTROPIC 2
29#define MM_LOMETRIC 3
30#define MM_HIMETRIC 4
31#define MM_TWIPS 5
32#define MM_POINTS 6
33#define MM_METRIC 7
34#endif
35
36//-----------------------------------------------------------------------------
37// global variables
38//-----------------------------------------------------------------------------
39
40extern int wxPageNumber;
41
42class wxMacPortStateHelper ;
43//-----------------------------------------------------------------------------
44// wxDC
45//-----------------------------------------------------------------------------
46
47class WXDLLEXPORT wxDC: public wxDCBase
48{
49 DECLARE_DYNAMIC_CLASS(wxDC)
50 DECLARE_NO_COPY_CLASS(wxDC)
51
52 public:
53
54 wxDC();
55 ~wxDC();
c5789d15 56
52479aef
SC
57
58 // implement base class pure virtuals
59 // ----------------------------------
60
61 virtual void Clear();
62
b1263dcf 63 virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return true; }
52479aef 64 virtual void EndDoc(void) {};
c5789d15 65
52479aef
SC
66 virtual void StartPage(void) {};
67 virtual void EndPage(void) {};
68
69 virtual void SetFont(const wxFont& font);
70 virtual void SetPen(const wxPen& pen);
71 virtual void SetBrush(const wxBrush& brush);
72 virtual void SetBackground(const wxBrush& brush);
73 virtual void SetBackgroundMode(int mode);
74 virtual void SetPalette(const wxPalette& palette);
75
76 virtual void DestroyClippingRegion();
77
78 virtual wxCoord GetCharHeight() const;
79 virtual wxCoord GetCharWidth() const;
80 virtual void DoGetTextExtent(const wxString& string,
81 wxCoord *x, wxCoord *y,
82 wxCoord *descent = NULL,
83 wxCoord *externalLeading = NULL,
84 wxFont *theFont = NULL) const;
85 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
86
87 virtual bool CanDrawBitmap() const;
88 virtual bool CanGetTextExtent() const;
89 virtual int GetDepth() const;
90 virtual wxSize GetPPI() const;
91
92 virtual void SetMapMode(int mode);
93 virtual void SetUserScale(double x, double y);
94
95 virtual void SetLogicalScale(double x, double y);
96 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
97 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
98 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
99 virtual void SetLogicalFunction(int function);
100
101 virtual void SetTextForeground(const wxColour& colour) ;
102 virtual void SetTextBackground(const wxColour& colour) ;
103
b1263dcf 104 virtual void ComputeScaleAndOrigin();
c5789d15 105
b1263dcf 106 public:
c5789d15 107
52479aef
SC
108 wxCoord XDEV2LOG(wxCoord x) const
109 {
110 long new_x = x - m_deviceOriginX ;
111 if (new_x > 0)
112 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
113 else
114 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
115 }
116 wxCoord XDEV2LOGREL(wxCoord x) const
c5789d15 117 {
52479aef
SC
118 if (x > 0)
119 return (wxCoord)((double)(x) / m_scaleX + 0.5);
120 else
121 return (wxCoord)((double)(x) / m_scaleX - 0.5);
122 }
123 wxCoord YDEV2LOG(wxCoord y) const
124 {
125 long new_y = y - m_deviceOriginY ;
126 if (new_y > 0)
127 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
128 else
129 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
130 }
131 wxCoord YDEV2LOGREL(wxCoord y) const
c5789d15 132 {
52479aef
SC
133 if (y > 0)
134 return (wxCoord)((double)(y) / m_scaleY + 0.5);
135 else
136 return (wxCoord)((double)(y) / m_scaleY - 0.5);
137 }
138 wxCoord XLOG2DEV(wxCoord x) const
c5789d15 139 {
52479aef
SC
140 long new_x = x - m_logicalOriginX;
141 if (new_x > 0)
142 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX ;
143 else
144 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX ;
145 }
146 wxCoord XLOG2DEVREL(wxCoord x) const
c5789d15 147 {
52479aef
SC
148 if (x > 0)
149 return (wxCoord)((double)(x) * m_scaleX + 0.5);
150 else
151 return (wxCoord)((double)(x) * m_scaleX - 0.5);
152 }
153 wxCoord YLOG2DEV(wxCoord y) const
154 {
155 long new_y = y - m_logicalOriginY ;
156 if (new_y > 0)
157 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY ;
158 else
159 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY ;
160 }
161 wxCoord YLOG2DEVREL(wxCoord y) const
c5789d15 162 {
52479aef
SC
163 if (y > 0)
164 return (wxCoord)((double)(y) * m_scaleY + 0.5);
165 else
166 return (wxCoord)((double)(y) * m_scaleY - 0.5);
167 }
168 wxCoord XLOG2DEVMAC(wxCoord x) const
c5789d15 169 {
52479aef
SC
170 long new_x = x - m_logicalOriginX;
171 if (new_x > 0)
172 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ;
173 else
174 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ;
175 }
176 wxCoord YLOG2DEVMAC(wxCoord y) const
177 {
178 long new_y = y - m_logicalOriginY ;
179 if (new_y > 0)
180 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ;
181 else
182 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ;
183 }
184
185 WXHRGN MacGetCurrentClipRgn() { return m_macCurrentClipRgn ; }
186 static void MacSetupBackgroundForCurrentPort(const wxBrush& background ) ;
187//
188
189protected:
190 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
191 int style = wxFLOOD_SURFACE);
192
193 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
194
195 virtual void DoDrawPoint(wxCoord x, wxCoord y);
196 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
197
198 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
199 wxCoord x2, wxCoord y2,
200 wxCoord xc, wxCoord yc);
c5789d15 201
52479aef
SC
202 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
203 double sa, double ea);
204
205 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
206 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
207 wxCoord width, wxCoord height,
208 double radius);
209 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
210
211 virtual void DoCrossHair(wxCoord x, wxCoord y);
212
213 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
214 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
b1263dcf 215 bool useMask = false);
52479aef
SC
216
217 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
218 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
219 double angle);
220
221 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
222 wxDC *source, wxCoord xsrc, wxCoord ysrc,
b1263dcf 223 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
52479aef
SC
224
225 // this is gnarly - we can't even call this function DoSetClippingRegion()
226 // because of virtual function hiding
227 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
228 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
229 wxCoord width, wxCoord height);
52479aef
SC
230
231 virtual void DoGetSizeMM(int* width, int* height) const;
232
233 virtual void DoDrawLines(int n, wxPoint points[],
234 wxCoord xoffset, wxCoord yoffset);
235 virtual void DoDrawPolygon(int n, wxPoint points[],
236 wxCoord xoffset, wxCoord yoffset,
237 int fillStyle = wxODDEVEN_RULE);
238
239 protected:
240 //begin wxmac
241 // Variables used for scaling
c5789d15 242 double m_mm_to_pix_x,m_mm_to_pix_y;
52479aef 243 // not yet used
c5789d15 244 bool m_needComputeScaleX,m_needComputeScaleY;
52479aef
SC
245 // If un-scrolled is non-zero or d.o. changes with scrolling.
246 // Set using SetInternalDeviceOrigin().
247 long m_internalDeviceOriginX,m_internalDeviceOriginY;
248 // To be set by external classes such as wxScrolledWindow
249 // using SetDeviceOrigin()
250 long m_externalDeviceOriginX,m_externalDeviceOriginY;
c5789d15 251
52479aef
SC
252 // Begin implementation for Mac
253 public:
c5789d15 254
52479aef
SC
255 WXHDC m_macPort ;
256 WXHBITMAP m_macMask ;
257
c5789d15 258 // in order to preserve the const inheritance of the virtual functions, we have to
52479aef
SC
259 // use mutable variables starting from CWPro 5
260
261 void MacInstallFont() const ;
262 void MacInstallPen() const ;
263 void MacInstallBrush() const ;
264
265 mutable bool m_macFontInstalled ;
266 mutable bool m_macPenInstalled ;
267 mutable bool m_macBrushInstalled ;
268
269 WXHRGN m_macBoundaryClipRgn ;
270 WXHRGN m_macCurrentClipRgn ;
271 wxPoint m_macLocalOrigin ;
272 void MacSetupPort( wxMacPortStateHelper* ph ) const ;
273 void MacCleanupPort( wxMacPortStateHelper* ph ) const ;
274 mutable void* m_macATSUIStyle ;
275 mutable wxMacPortStateHelper* m_macCurrentPortStateHelper ;
276 mutable bool m_macFormerAliasState ;
277 mutable short m_macFormerAliasSize ;
278 mutable bool m_macAliasWasEnabled ;
279 mutable void* m_macForegroundPixMap ;
280 mutable void* m_macBackgroundPixMap ;
281};
282
283#endif
284 // _WX_DC_H_