]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.h | |
3 | // Purpose: wxDC class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __DCH__ | |
13 | #define __DCH__ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "dc.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/pen.h" | |
20 | #include "wx/brush.h" | |
21 | #include "wx/icon.h" | |
22 | #include "wx/font.h" | |
23 | #include "wx/gdicmn.h" | |
24 | ||
25 | class WXDLLEXPORT wxDC: public wxObject | |
26 | { | |
27 | DECLARE_ABSTRACT_CLASS(wxDC) | |
28 | protected: | |
29 | public: | |
30 | wxDC(void); | |
31 | ~wxDC(void); | |
32 | ||
33 | inline void wxDC::BeginDrawing(void) {} | |
34 | inline void wxDC::EndDrawing(void) {} | |
35 | ||
36 | virtual void FloodFill(long x1, long y1, wxColour *col, int style=wxFLOOD_SURFACE) ; | |
37 | virtual bool GetPixel(long x1, long y1, wxColour *col) const ; | |
38 | ||
39 | virtual void DrawLine(long x1, long y1, long x2, long y2); | |
40 | virtual void CrossHair(long x, long y) ; | |
41 | virtual void DrawArc(long x1,long y1,long x2,long y2,double xc, double yc); | |
42 | virtual void DrawEllipticArc (long x, long y, long w, long h, double sa, double ea); | |
43 | virtual void DrawPoint(long x, long y); | |
44 | ||
45 | virtual void DrawLines(int n, wxPoint points[], long xoffset = 0, long yoffset = 0); | |
46 | ||
47 | virtual void DrawPolygon(int n, wxPoint points[], long xoffset = 0, long yoffset = 0, int fillStyle=wxODDEVEN_RULE); | |
48 | ||
49 | virtual void DrawRectangle(long x, long y, long width, long height); | |
50 | virtual void DrawRoundedRectangle(long x, long y, long width, long height, double radius = 20.0); | |
51 | virtual void DrawEllipse(long x, long y, long width, long height); | |
52 | ||
53 | virtual void DrawIcon(const wxIcon& icon, long x, long y); | |
54 | ||
55 | virtual void Clear(void); | |
56 | virtual void SetFont(const wxFont& font); | |
57 | virtual void SetPen(const wxPen& pen); | |
58 | virtual void SetBrush(const wxBrush& brush); | |
59 | virtual void SetLogicalFunction(int function); | |
60 | virtual void SetBackground(const wxBrush& brush); | |
61 | virtual void SetBackgroundMode(int mode); | |
62 | virtual void SetClippingRegion(long x, long y, long width, long height); | |
63 | virtual void SetPalette(const wxPalette& palette); | |
64 | #if WXWIN_COMPATIBILITY | |
65 | virtual inline void SetColourMap(const wxPalette& palette) { SetPalette(palette); }; | |
66 | #endif | |
67 | virtual void DestroyClippingRegion(void); | |
68 | virtual void DrawText(const wxString& text, long x, long y, bool use16bit = FALSE); | |
69 | ||
70 | virtual long GetCharHeight(void) const; | |
71 | virtual long GetCharWidth(void) const; | |
72 | virtual void GetTextExtent(const wxString& string, long *x, long *y, | |
73 | long *descent = NULL, long *externalLeading = NULL, | |
74 | wxFont *theFont = NULL, bool use16bit = FALSE) const; | |
75 | #if WXWIN_COMPATIBILITY | |
76 | void GetTextExtent(const wxString& string, float *x, float *y, | |
77 | float *descent = NULL, float *externalLeading = NULL, | |
78 | wxFont *theFont = NULL, bool use16bit = FALSE) const ; | |
79 | #endif | |
80 | ||
81 | // Size in device units | |
82 | virtual void GetSize(int* width, int* height) const; | |
83 | inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); } | |
84 | ||
85 | // Size in mm | |
86 | virtual void GetSizeMM(long* width, long* height) const ; | |
87 | ||
88 | // Compatibility | |
89 | #if WXWIN_COMPATIBILITY | |
90 | inline void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; } | |
91 | inline void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; } | |
92 | #endif | |
93 | ||
94 | virtual bool StartDoc(const wxString& message); | |
95 | virtual void EndDoc(void); | |
96 | virtual void StartPage(void); | |
97 | virtual void EndPage(void); | |
98 | virtual void SetMapMode(int mode); | |
99 | virtual void SetUserScale(double x, double y); | |
100 | virtual void SetSystemScale(double x, double y); | |
101 | virtual void SetLogicalOrigin(long x, long y); | |
102 | virtual void SetDeviceOrigin(long x, long y); | |
103 | ||
104 | // This group of functions does actual conversion | |
105 | // of the input, as you'd expect. | |
106 | ||
107 | long DeviceToLogicalX(long x) const; | |
108 | long DeviceToLogicalY(long y) const; | |
109 | long DeviceToLogicalXRel(long x) const; | |
110 | long DeviceToLogicalYRel(long y) const; | |
111 | long LogicalToDeviceX(long x) const; | |
112 | long LogicalToDeviceY(long y) const; | |
113 | long LogicalToDeviceXRel(long x) const; | |
114 | long LogicalToDeviceYRel(long y) const; | |
115 | ||
116 | // This group of functions may not do any conversion | |
117 | // if m_scaleGDI is TRUE, since the HDC does the | |
118 | // conversion automatically. | |
119 | // m_scaleGDI NOW OBSOLETE | |
120 | long ImplDeviceToLogicalX(long x) const; | |
121 | long ImplDeviceToLogicalY(long y) const; | |
122 | long ImplDeviceToLogicalXRel(long x) const; | |
123 | long ImplDeviceToLogicalYRel(long y) const; | |
124 | long ImplLogicalToDeviceX(long x) const; | |
125 | long ImplLogicalToDeviceY(long y) const; | |
126 | long ImplLogicalToDeviceXRel(long x) const; | |
127 | long ImplLogicalToDeviceYRel(long y) const; | |
128 | ||
129 | virtual bool Blit(long xdest, long ydest, long width, long height, | |
130 | wxDC *source, long xsrc, long ysrc, int rop = wxCOPY, bool useMask = FALSE); | |
131 | ||
132 | virtual bool CanDrawBitmap(void) const; | |
133 | virtual bool CanGetTextExtent(void) const; | |
134 | ||
135 | // | |
136 | // This function is intended to improves drawing, by avoiding to | |
137 | // repeatly call ::SetPen/::SetBrush. If set to FALSE, these functions | |
138 | // aren't called when calling ::DrawLine(),... | |
139 | // Please note that this is YOUR responsability to use it, and do it | |
140 | // only when you KNOWN that pen/brush isn't changed between 2 calls to | |
141 | // DrawLine,... !!! | |
142 | // Note also that in X, we don't test m_autoSetting on brushes, because they | |
143 | // modify Foreground, as pens. So, convention is: | |
144 | // - call your SetBrush(), THEN your SetPen, THEN AutoSetTools(FALSE) | |
145 | // - call DrawLine,... | |
146 | // [mainly coded for Windows] | |
147 | inline virtual void AutoSetTools(bool auto_setting) { m_autoSetting = auto_setting ; } | |
148 | inline virtual void DrawPoint(wxPoint& point) { DrawPoint(point.x, point.y); } | |
149 | virtual void DrawLines(wxList *list, long xoffset = 0, long yoffset = 0); | |
150 | virtual void DrawPolygon(wxList *list, long xoffset = 0, long yoffset = 0, int fillStyle=wxODDEVEN_RULE); | |
151 | #if USE_SPLINES | |
152 | // Splines | |
153 | // 3-point spline | |
154 | virtual void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3); | |
155 | // Any number of control points - a list of pointers to wxPoints | |
156 | virtual void DrawSpline(wxList *points); | |
157 | virtual void DrawSpline(int n, wxPoint points[]); | |
158 | #endif | |
159 | virtual void SetTextForeground(const wxColour& colour); | |
160 | virtual void SetTextBackground(const wxColour& colour); | |
161 | inline virtual bool Ok(void) const {return m_ok;}; | |
162 | inline virtual int GetMapMode(void) const {return m_mappingMode;}; | |
163 | ||
164 | inline virtual wxBrush *GetBackground(void) const { return (wxBrush*) &m_backgroundBrush ;} | |
165 | inline virtual wxBrush *GetBrush(void) const { return (wxBrush*) &m_brush ;} | |
166 | inline virtual wxFont *GetFont(void) const { return (wxFont*) &m_font ;} | |
167 | inline virtual int GetLogicalFunction(void) const { return m_logicalFunction ;} | |
168 | inline virtual wxPen *GetPen(void) const { return (wxPen*) &m_pen ;} | |
169 | inline virtual wxColour&GetTextBackground(void) const { return (wxColour&) m_textBackgroundColour ;} | |
170 | inline virtual wxColour&GetTextForeground(void) const { return (wxColour&) m_textForegroundColour ;} | |
171 | ||
172 | virtual void SetLogicalScale(double x, double y); | |
173 | virtual inline void GetUserScale(double* x, double *y) const { *x = m_userScaleX; *y = m_userScaleY; } | |
174 | virtual void CalcBoundingBox(long x, long y); | |
175 | // Get the final bounding box of the PostScript or Metafile picture. | |
176 | virtual inline long MinX(void) const { return m_minX; } | |
177 | virtual inline long MaxX(void) const { return m_maxX; } | |
178 | virtual inline long MinY(void) const { return m_minY; } | |
179 | virtual inline long MaxY(void) const { return m_maxY; } | |
180 | // Sometimes we need to override optimization, e.g. | |
181 | // if other software is drawing onto our surface and we | |
182 | // can't be sure of who's done what. | |
183 | virtual inline void SetOptimization(bool WXUNUSED(opt)) { } | |
184 | virtual inline bool GetOptimization(void) { return FALSE; } | |
185 | ||
186 | virtual void GetClippingBox(long *x,long *y,long *w,long *h) const ; | |
187 | ||
188 | virtual void SetRop(WXHDC cdc); | |
189 | virtual void DoClipping(WXHDC cdc); | |
190 | virtual void SelectOldObjects(WXHDC dc); | |
191 | ||
192 | inline wxWindow *GetWindow(void) const { return m_canvas; } | |
193 | inline void SetWindow(wxWindow *win) { m_canvas = win; } | |
194 | inline WXHDC GetHDC(void) const { return m_hDC; } | |
195 | inline void SetHDC(WXHDC dc, bool bOwnsDC = FALSE) { m_hDC = dc; m_bOwnsDC = bOwnsDC; } | |
196 | inline bool GetAutoSetting(void) const { return m_autoSetting; } | |
197 | ||
198 | // inline bool GetScaleGDI(void) const { return m_scaleGDI; } | |
199 | // inline void SetScaleGDI(bool flag) { m_scaleGDI = flag; } | |
200 | ||
201 | protected: | |
202 | bool m_colour; | |
203 | bool m_ok; | |
204 | bool m_clipping; | |
205 | bool m_isInteractive; | |
206 | ||
207 | // Coordinate system variables | |
208 | long m_logicalOriginX; | |
209 | long m_logicalOriginY; | |
210 | ||
211 | long m_deviceOriginX; | |
212 | long m_deviceOriginY; | |
213 | ||
214 | double m_logicalScaleX; | |
215 | double m_logicalScaleY; | |
216 | ||
217 | double m_userScaleX; | |
218 | double m_userScaleY; | |
219 | ||
220 | int m_mappingMode; | |
221 | ||
222 | long m_minX; // bounding box | |
223 | long m_minY; | |
224 | long m_maxX; | |
225 | long m_maxY; | |
226 | ||
227 | int m_logicalFunction; | |
228 | int m_backgroundMode; | |
229 | ||
230 | wxPen m_pen; | |
231 | wxBrush m_brush; | |
232 | wxBrush m_backgroundBrush; | |
233 | wxColour m_textForegroundColour; | |
234 | wxColour m_textBackgroundColour; | |
235 | wxFont m_font; | |
236 | wxPalette m_palette; | |
237 | bool m_autoSetting ; | |
238 | int m_clipX1; | |
239 | int m_clipY1; | |
240 | int m_clipX2; | |
241 | int m_clipY2; | |
242 | // bool m_dontDelete; | |
243 | int m_windowExtX; | |
244 | int m_windowExtY; | |
245 | double m_systemScaleX; | |
246 | double m_systemScaleY; | |
247 | ||
248 | wxWindow * m_canvas; | |
249 | wxBitmap m_selectedBitmap; | |
250 | wxString m_filename; | |
251 | ||
252 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it | |
253 | bool m_bOwnsDC; | |
254 | ||
255 | WXHDC m_hDC; | |
256 | int m_hDCCount; | |
257 | ||
258 | // Store all old GDI objects when do a SelectObject, | |
259 | // so we can select them back in (this unselecting user's | |
260 | // objects) so we can safely delete the DC. | |
261 | WXHBITMAP m_oldBitmap; | |
262 | WXHPEN m_oldPen; | |
263 | WXHBRUSH m_oldBrush; | |
264 | WXHFONT m_oldFont; | |
265 | WXHPALETTE m_oldPalette; | |
266 | ||
267 | // Stores scaling, translation, rotation | |
268 | // wxTransformMatrix m_transformMatrix; | |
269 | ||
270 | // Do we wish to scale GDI objects too, e.g. pen width? | |
271 | // bool m_scaleGDI; | |
272 | }; | |
273 | ||
274 | // Logical to device | |
275 | // Absolute | |
276 | #define XLOG2DEV(x) ImplLogicalToDeviceX(x) | |
277 | ||
278 | #define YLOG2DEV(y) ImplLogicalToDeviceY(y) | |
279 | ||
280 | // Relative | |
281 | #define XLOG2DEVREL(x) ImplLogicalToDeviceXRel(x) | |
282 | #define YLOG2DEVREL(y) ImplLogicalToDeviceYRel(y) | |
283 | ||
284 | // Device to logical | |
285 | // Absolute | |
286 | #define XDEV2LOG(x) ImplDeviceToLogicalX(x) | |
287 | ||
288 | #define YDEV2LOG(y) ImplDeviceToLogicalY(y) | |
289 | ||
290 | // Relative | |
291 | #define XDEV2LOGREL(x) ImplDeviceToLogicalXRel(x) | |
292 | #define YDEV2LOGREL(y) ImplDeviceToLogicalYRel(y) | |
293 | ||
294 | /* | |
295 | * Have the same macros as for XView but not for every operation: | |
296 | * just for calculating window/viewport extent (a better way of scaling). | |
297 | */ | |
298 | ||
299 | // Logical to device | |
300 | // Absolute | |
301 | #define MS_XLOG2DEV(x) LogicalToDevice(x) | |
302 | ||
303 | #define MS_YLOG2DEV(y) LogicalToDevice(y) | |
304 | ||
305 | // Relative | |
306 | #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
307 | #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y) | |
308 | ||
309 | // Device to logical | |
310 | // Absolute | |
311 | #define MS_XDEV2LOG(x) DeviceToLogicalX(x) | |
312 | ||
313 | #define MS_YDEV2LOG(y) DeviceToLogicalY(y) | |
314 | ||
315 | // Relative | |
316 | #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x) | |
317 | #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y) | |
318 | ||
319 | #define MM_POINTS 7 | |
320 | #define MM_METRIC 8 | |
321 | ||
322 | extern int wxPageNumber; | |
323 | ||
324 | // Conversion | |
325 | #define METRIC_CONVERSION_CONSTANT 0.0393700787 | |
326 | ||
327 | // Scaling factors for various unit conversions | |
328 | #define mm2inches (METRIC_CONVERSION_CONSTANT) | |
329 | #define inches2mm (1/METRIC_CONVERSION_CONSTANT) | |
330 | ||
331 | #define mm2twips (METRIC_CONVERSION_CONSTANT*1440) | |
332 | #define twips2mm (1/(METRIC_CONVERSION_CONSTANT*1440)) | |
333 | ||
334 | #define mm2pt (METRIC_CONVERSION_CONSTANT*72) | |
335 | #define pt2mm (1/(METRIC_CONVERSION_CONSTANT*72)) | |
336 | ||
337 | #define wx_round(a) (int)((a)+.5) | |
338 | ||
339 | ||
340 | #endif | |
341 | // __DCH__ |