]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/dc.h | |
3 | // Purpose: wxDC class | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 05/25/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWidgets team | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_DC_H_BASE_ | |
13 | #define _WX_DC_H_BASE_ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers which we must include here | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #include "wx/object.h" // the base class | |
20 | ||
21 | #include "wx/intl.h" // for wxLayoutDirection | |
22 | #include "wx/cursor.h" // we have member variables of these classes | |
23 | #include "wx/font.h" // so we can't do without them | |
24 | #include "wx/colour.h" | |
25 | #include "wx/bitmap.h" // for wxNullBitmap | |
26 | #include "wx/brush.h" | |
27 | #include "wx/pen.h" | |
28 | #include "wx/palette.h" | |
29 | #include "wx/dynarray.h" | |
30 | #include "wx/math.h" | |
31 | #include "wx/image.h" | |
32 | #include "wx/region.h" | |
33 | ||
34 | #define wxUSE_NEW_DC 1 | |
35 | ||
36 | class WXDLLIMPEXP_FWD_CORE wxDC; | |
37 | class WXDLLIMPEXP_FWD_CORE wxClientDC; | |
38 | class WXDLLIMPEXP_FWD_CORE wxPaintDC; | |
39 | class WXDLLIMPEXP_FWD_CORE wxWindowDC; | |
40 | class WXDLLIMPEXP_FWD_CORE wxScreenDC; | |
41 | class WXDLLIMPEXP_FWD_CORE wxMemoryDC; | |
42 | class WXDLLIMPEXP_FWD_CORE wxPrinterDC; | |
43 | class WXDLLIMPEXP_FWD_CORE wxPrintData; | |
44 | ||
45 | // Logical ops | |
46 | enum wxRasterOperationMode | |
47 | { | |
48 | wxCLEAR, // 0 | |
49 | wxXOR, // src XOR dst | |
50 | wxINVERT, // NOT dst | |
51 | wxOR_REVERSE, // src OR (NOT dst) | |
52 | wxAND_REVERSE, // src AND (NOT dst) | |
53 | wxCOPY, // src | |
54 | wxAND, // src AND dst | |
55 | wxAND_INVERT, // (NOT src) AND dst | |
56 | wxNO_OP, // dst | |
57 | wxNOR, // (NOT src) AND (NOT dst) | |
58 | wxEQUIV, // (NOT src) XOR dst | |
59 | wxSRC_INVERT, // (NOT src) | |
60 | wxOR_INVERT, // (NOT src) OR dst | |
61 | wxNAND, // (NOT src) OR (NOT dst) | |
62 | wxOR, // src OR dst | |
63 | wxSET // 1 | |
64 | #if WXWIN_COMPATIBILITY_2_8 | |
65 | ,wxROP_BLACK = wxCLEAR, | |
66 | wxBLIT_BLACKNESS = wxCLEAR, | |
67 | wxROP_XORPEN = wxXOR, | |
68 | wxBLIT_SRCINVERT = wxXOR, | |
69 | wxROP_NOT = wxINVERT, | |
70 | wxBLIT_DSTINVERT = wxINVERT, | |
71 | wxROP_MERGEPENNOT = wxOR_REVERSE, | |
72 | wxBLIT_00DD0228 = wxOR_REVERSE, | |
73 | wxROP_MASKPENNOT = wxAND_REVERSE, | |
74 | wxBLIT_SRCERASE = wxAND_REVERSE, | |
75 | wxROP_COPYPEN = wxCOPY, | |
76 | wxBLIT_SRCCOPY = wxCOPY, | |
77 | wxROP_MASKPEN = wxAND, | |
78 | wxBLIT_SRCAND = wxAND, | |
79 | wxROP_MASKNOTPEN = wxAND_INVERT, | |
80 | wxBLIT_00220326 = wxAND_INVERT, | |
81 | wxROP_NOP = wxNO_OP, | |
82 | wxBLIT_00AA0029 = wxNO_OP, | |
83 | wxROP_NOTMERGEPEN = wxNOR, | |
84 | wxBLIT_NOTSRCERASE = wxNOR, | |
85 | wxROP_NOTXORPEN = wxEQUIV, | |
86 | wxBLIT_00990066 = wxEQUIV, | |
87 | wxROP_NOTCOPYPEN = wxSRC_INVERT, | |
88 | wxBLIT_NOTSCRCOPY = wxSRC_INVERT, | |
89 | wxROP_MERGENOTPEN = wxOR_INVERT, | |
90 | wxBLIT_MERGEPAINT = wxOR_INVERT, | |
91 | wxROP_NOTMASKPEN = wxNAND, | |
92 | wxBLIT_007700E6 = wxNAND, | |
93 | wxROP_MERGEPEN = wxOR, | |
94 | wxBLIT_SRCPAINT = wxOR, | |
95 | wxROP_WHITE = wxSET, | |
96 | wxBLIT_WHITENESS = wxSET | |
97 | #endif //WXWIN_COMPATIBILITY_2_8 | |
98 | }; | |
99 | ||
100 | // Flood styles | |
101 | enum wxFloodFillStyle | |
102 | { | |
103 | wxFLOOD_SURFACE = 1, | |
104 | wxFLOOD_BORDER | |
105 | }; | |
106 | ||
107 | // Mapping modes | |
108 | enum wxMappingMode | |
109 | { | |
110 | wxMM_TEXT = 1, | |
111 | wxMM_METRIC, | |
112 | wxMM_LOMETRIC, | |
113 | wxMM_TWIPS, | |
114 | wxMM_POINTS | |
115 | }; | |
116 | ||
117 | // Description of text characteristics. | |
118 | struct wxFontMetrics | |
119 | { | |
120 | wxFontMetrics() | |
121 | { | |
122 | height = | |
123 | ascent = | |
124 | descent = | |
125 | internalLeading = | |
126 | externalLeading = | |
127 | averageWidth = 0; | |
128 | } | |
129 | ||
130 | int height, // Total character height. | |
131 | ascent, // Part of the height above the baseline. | |
132 | descent, // Part of the height below the baseline. | |
133 | internalLeading, // Intra-line spacing. | |
134 | externalLeading, // Inter-line spacing. | |
135 | averageWidth; // Average font width, a.k.a. "x-width". | |
136 | }; | |
137 | ||
138 | #if WXWIN_COMPATIBILITY_2_8 | |
139 | ||
140 | //----------------------------------------------------------------------------- | |
141 | // wxDrawObject helper class | |
142 | //----------------------------------------------------------------------------- | |
143 | ||
144 | class WXDLLIMPEXP_CORE wxDrawObject | |
145 | { | |
146 | public: | |
147 | wxDEPRECATED_CONSTRUCTOR(wxDrawObject)() | |
148 | : m_isBBoxValid(false) | |
149 | , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) | |
150 | { } | |
151 | ||
152 | virtual ~wxDrawObject() { } | |
153 | ||
154 | virtual void Draw(wxDC&) const { } | |
155 | ||
156 | virtual void CalcBoundingBox(wxCoord x, wxCoord y) | |
157 | { | |
158 | if ( m_isBBoxValid ) | |
159 | { | |
160 | if ( x < m_minX ) m_minX = x; | |
161 | if ( y < m_minY ) m_minY = y; | |
162 | if ( x > m_maxX ) m_maxX = x; | |
163 | if ( y > m_maxY ) m_maxY = y; | |
164 | } | |
165 | else | |
166 | { | |
167 | m_isBBoxValid = true; | |
168 | ||
169 | m_minX = x; | |
170 | m_minY = y; | |
171 | m_maxX = x; | |
172 | m_maxY = y; | |
173 | } | |
174 | } | |
175 | ||
176 | void ResetBoundingBox() | |
177 | { | |
178 | m_isBBoxValid = false; | |
179 | ||
180 | m_minX = m_maxX = m_minY = m_maxY = 0; | |
181 | } | |
182 | ||
183 | // Get the final bounding box of the PostScript or Metafile picture. | |
184 | ||
185 | wxCoord MinX() const { return m_minX; } | |
186 | wxCoord MaxX() const { return m_maxX; } | |
187 | wxCoord MinY() const { return m_minY; } | |
188 | wxCoord MaxY() const { return m_maxY; } | |
189 | ||
190 | //to define the type of object for derived objects | |
191 | virtual int GetType()=0; | |
192 | ||
193 | protected: | |
194 | //for boundingbox calculation | |
195 | bool m_isBBoxValid:1; | |
196 | //for boundingbox calculation | |
197 | wxCoord m_minX, m_minY, m_maxX, m_maxY; | |
198 | }; | |
199 | ||
200 | #endif // WXWIN_COMPATIBILITY_2_8 | |
201 | ||
202 | ||
203 | //----------------------------------------------------------------------------- | |
204 | // wxDCFactory | |
205 | //----------------------------------------------------------------------------- | |
206 | ||
207 | class WXDLLIMPEXP_FWD_CORE wxDCImpl; | |
208 | ||
209 | class WXDLLIMPEXP_CORE wxDCFactory | |
210 | { | |
211 | public: | |
212 | wxDCFactory() {} | |
213 | virtual ~wxDCFactory() {} | |
214 | ||
215 | virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window ) = 0; | |
216 | virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window ) = 0; | |
217 | virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window ) = 0; | |
218 | virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner ) = 0; | |
219 | virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ) = 0; | |
220 | virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ) = 0; | |
221 | virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner ) = 0; | |
222 | #if wxUSE_PRINTING_ARCHITECTURE | |
223 | virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data ) = 0; | |
224 | #endif | |
225 | ||
226 | static void Set(wxDCFactory *factory); | |
227 | static wxDCFactory *Get(); | |
228 | ||
229 | private: | |
230 | static wxDCFactory *m_factory; | |
231 | }; | |
232 | ||
233 | //----------------------------------------------------------------------------- | |
234 | // wxNativeDCFactory | |
235 | //----------------------------------------------------------------------------- | |
236 | ||
237 | class WXDLLIMPEXP_CORE wxNativeDCFactory: public wxDCFactory | |
238 | { | |
239 | public: | |
240 | wxNativeDCFactory() {} | |
241 | ||
242 | virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window ); | |
243 | virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window ); | |
244 | virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window ); | |
245 | virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner ); | |
246 | virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ); | |
247 | virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ); | |
248 | virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner ); | |
249 | #if wxUSE_PRINTING_ARCHITECTURE | |
250 | virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data ); | |
251 | #endif | |
252 | }; | |
253 | ||
254 | //----------------------------------------------------------------------------- | |
255 | // wxDCImpl | |
256 | //----------------------------------------------------------------------------- | |
257 | ||
258 | class WXDLLIMPEXP_CORE wxDCImpl: public wxObject | |
259 | { | |
260 | public: | |
261 | wxDCImpl( wxDC *owner ); | |
262 | virtual ~wxDCImpl(); | |
263 | ||
264 | wxDC *GetOwner() const { return m_owner; } | |
265 | ||
266 | wxWindow* GetWindow() const { return m_window; } | |
267 | ||
268 | virtual bool IsOk() const { return m_ok; } | |
269 | ||
270 | // query capabilities | |
271 | ||
272 | virtual bool CanDrawBitmap() const = 0; | |
273 | virtual bool CanGetTextExtent() const = 0; | |
274 | ||
275 | // get Cairo context | |
276 | virtual void* GetCairoContext() const | |
277 | { | |
278 | return NULL; | |
279 | } | |
280 | ||
281 | // query dimension, colour deps, resolution | |
282 | ||
283 | virtual void DoGetSize(int *width, int *height) const = 0; | |
284 | void GetSize(int *width, int *height) const | |
285 | { | |
286 | DoGetSize(width, height); | |
287 | return ; | |
288 | } | |
289 | ||
290 | wxSize GetSize() const | |
291 | { | |
292 | int w, h; | |
293 | DoGetSize(&w, &h); | |
294 | return wxSize(w, h); | |
295 | } | |
296 | ||
297 | virtual void DoGetSizeMM(int* width, int* height) const = 0; | |
298 | ||
299 | virtual int GetDepth() const = 0; | |
300 | virtual wxSize GetPPI() const = 0; | |
301 | ||
302 | // Right-To-Left (RTL) modes | |
303 | ||
304 | virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir)) { } | |
305 | virtual wxLayoutDirection GetLayoutDirection() const { return wxLayout_Default; } | |
306 | ||
307 | // page and document | |
308 | ||
309 | virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; } | |
310 | virtual void EndDoc() { } | |
311 | ||
312 | virtual void StartPage() { } | |
313 | virtual void EndPage() { } | |
314 | ||
315 | // flushing the content of this dc immediately eg onto screen | |
316 | virtual void Flush() { } | |
317 | ||
318 | // bounding box | |
319 | ||
320 | virtual void CalcBoundingBox(wxCoord x, wxCoord y) | |
321 | { | |
322 | if ( m_isBBoxValid ) | |
323 | { | |
324 | if ( x < m_minX ) m_minX = x; | |
325 | if ( y < m_minY ) m_minY = y; | |
326 | if ( x > m_maxX ) m_maxX = x; | |
327 | if ( y > m_maxY ) m_maxY = y; | |
328 | } | |
329 | else | |
330 | { | |
331 | m_isBBoxValid = true; | |
332 | ||
333 | m_minX = x; | |
334 | m_minY = y; | |
335 | m_maxX = x; | |
336 | m_maxY = y; | |
337 | } | |
338 | } | |
339 | void ResetBoundingBox() | |
340 | { | |
341 | m_isBBoxValid = false; | |
342 | ||
343 | m_minX = m_maxX = m_minY = m_maxY = 0; | |
344 | } | |
345 | ||
346 | wxCoord MinX() const { return m_minX; } | |
347 | wxCoord MaxX() const { return m_maxX; } | |
348 | wxCoord MinY() const { return m_minY; } | |
349 | wxCoord MaxY() const { return m_maxY; } | |
350 | ||
351 | // setters and getters | |
352 | ||
353 | virtual void SetFont(const wxFont& font) = 0; | |
354 | virtual const wxFont& GetFont() const { return m_font; } | |
355 | ||
356 | virtual void SetPen(const wxPen& pen) = 0; | |
357 | virtual const wxPen& GetPen() const { return m_pen; } | |
358 | ||
359 | virtual void SetBrush(const wxBrush& brush) = 0; | |
360 | virtual const wxBrush& GetBrush() const { return m_brush; } | |
361 | ||
362 | virtual void SetBackground(const wxBrush& brush) = 0; | |
363 | virtual const wxBrush& GetBackground() const { return m_backgroundBrush; } | |
364 | ||
365 | virtual void SetBackgroundMode(int mode) = 0; | |
366 | virtual int GetBackgroundMode() const { return m_backgroundMode; } | |
367 | ||
368 | virtual void SetTextForeground(const wxColour& colour) | |
369 | { m_textForegroundColour = colour; } | |
370 | virtual const wxColour& GetTextForeground() const | |
371 | { return m_textForegroundColour; } | |
372 | ||
373 | virtual void SetTextBackground(const wxColour& colour) | |
374 | { m_textBackgroundColour = colour; } | |
375 | virtual const wxColour& GetTextBackground() const | |
376 | { return m_textBackgroundColour; } | |
377 | ||
378 | #if wxUSE_PALETTE | |
379 | virtual void SetPalette(const wxPalette& palette) = 0; | |
380 | #endif // wxUSE_PALETTE | |
381 | ||
382 | // inherit the DC attributes (font and colours) from the given window | |
383 | // | |
384 | // this is called automatically when a window, client or paint DC is | |
385 | // created | |
386 | virtual void InheritAttributes(wxWindow *win); | |
387 | ||
388 | ||
389 | // logical functions | |
390 | ||
391 | virtual void SetLogicalFunction(wxRasterOperationMode function) = 0; | |
392 | virtual wxRasterOperationMode GetLogicalFunction() const | |
393 | { return m_logicalFunction; } | |
394 | ||
395 | // text measurement | |
396 | ||
397 | virtual wxCoord GetCharHeight() const = 0; | |
398 | virtual wxCoord GetCharWidth() const = 0; | |
399 | ||
400 | // The derived classes should really override DoGetFontMetrics() to return | |
401 | // the correct values in the future but for now provide a default | |
402 | // implementation in terms of DoGetTextExtent() to avoid breaking the | |
403 | // compilation of all other ports as wxMSW is the only one to implement it. | |
404 | virtual void DoGetFontMetrics(int *height, | |
405 | int *ascent, | |
406 | int *descent, | |
407 | int *internalLeading, | |
408 | int *externalLeading, | |
409 | int *averageWidth) const; | |
410 | ||
411 | virtual void DoGetTextExtent(const wxString& string, | |
412 | wxCoord *x, wxCoord *y, | |
413 | wxCoord *descent = NULL, | |
414 | wxCoord *externalLeading = NULL, | |
415 | const wxFont *theFont = NULL) const = 0; | |
416 | virtual void GetMultiLineTextExtent(const wxString& string, | |
417 | wxCoord *width, | |
418 | wxCoord *height, | |
419 | wxCoord *heightLine = NULL, | |
420 | const wxFont *font = NULL) const; | |
421 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; | |
422 | ||
423 | // clearing | |
424 | ||
425 | virtual void Clear() = 0; | |
426 | ||
427 | // clipping | |
428 | ||
429 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, | |
430 | wxCoord width, wxCoord height) = 0; | |
431 | ||
432 | // NB: this function works with device coordinates, not the logical ones! | |
433 | virtual void DoSetDeviceClippingRegion(const wxRegion& region) = 0; | |
434 | ||
435 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, | |
436 | wxCoord *w, wxCoord *h) const | |
437 | { | |
438 | if ( x ) | |
439 | *x = m_clipX1; | |
440 | if ( y ) | |
441 | *y = m_clipY1; | |
442 | if ( w ) | |
443 | *w = m_clipX2 - m_clipX1; | |
444 | if ( h ) | |
445 | *h = m_clipY2 - m_clipY1; | |
446 | } | |
447 | ||
448 | virtual void DestroyClippingRegion() { ResetClipping(); } | |
449 | ||
450 | ||
451 | // coordinates conversions and transforms | |
452 | ||
453 | virtual wxCoord DeviceToLogicalX(wxCoord x) const; | |
454 | virtual wxCoord DeviceToLogicalY(wxCoord y) const; | |
455 | virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; | |
456 | virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; | |
457 | virtual wxCoord LogicalToDeviceX(wxCoord x) const; | |
458 | virtual wxCoord LogicalToDeviceY(wxCoord y) const; | |
459 | virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; | |
460 | virtual wxCoord LogicalToDeviceYRel(wxCoord y) const; | |
461 | ||
462 | virtual void SetMapMode(wxMappingMode mode); | |
463 | virtual wxMappingMode GetMapMode() const { return m_mappingMode; } | |
464 | ||
465 | virtual void SetUserScale(double x, double y); | |
466 | virtual void GetUserScale(double *x, double *y) const | |
467 | { | |
468 | if ( x ) *x = m_userScaleX; | |
469 | if ( y ) *y = m_userScaleY; | |
470 | } | |
471 | ||
472 | virtual void SetLogicalScale(double x, double y); | |
473 | virtual void GetLogicalScale(double *x, double *y) | |
474 | { | |
475 | if ( x ) *x = m_logicalScaleX; | |
476 | if ( y ) *y = m_logicalScaleY; | |
477 | } | |
478 | ||
479 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); | |
480 | virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const | |
481 | { | |
482 | if ( x ) *x = m_logicalOriginX; | |
483 | if ( y ) *y = m_logicalOriginY; | |
484 | } | |
485 | ||
486 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
487 | virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const | |
488 | { | |
489 | if ( x ) *x = m_deviceOriginX; | |
490 | if ( y ) *y = m_deviceOriginY; | |
491 | } | |
492 | ||
493 | virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y ); | |
494 | ||
495 | virtual void ComputeScaleAndOrigin(); | |
496 | ||
497 | // this needs to overidden if the axis is inverted | |
498 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); | |
499 | ||
500 | // --------------------------------------------------------- | |
501 | // the actual drawing API | |
502 | ||
503 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
504 | wxFloodFillStyle style = wxFLOOD_SURFACE) = 0; | |
505 | ||
506 | virtual void DoGradientFillLinear(const wxRect& rect, | |
507 | const wxColour& initialColour, | |
508 | const wxColour& destColour, | |
509 | wxDirection nDirection = wxEAST); | |
510 | ||
511 | virtual void DoGradientFillConcentric(const wxRect& rect, | |
512 | const wxColour& initialColour, | |
513 | const wxColour& destColour, | |
514 | const wxPoint& circleCenter); | |
515 | ||
516 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0; | |
517 | ||
518 | virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0; | |
519 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0; | |
520 | ||
521 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
522 | wxCoord x2, wxCoord y2, | |
523 | wxCoord xc, wxCoord yc) = 0; | |
524 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, | |
525 | wxCoord width, wxCoord height); | |
526 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
527 | double sa, double ea) = 0; | |
528 | ||
529 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0; | |
530 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
531 | wxCoord width, wxCoord height, | |
532 | double radius) = 0; | |
533 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, | |
534 | wxCoord width, wxCoord height) = 0; | |
535 | ||
536 | virtual void DoCrossHair(wxCoord x, wxCoord y) = 0; | |
537 | ||
538 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0; | |
539 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
540 | bool useMask = false) = 0; | |
541 | ||
542 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0; | |
543 | virtual void DoDrawRotatedText(const wxString& text, | |
544 | wxCoord x, wxCoord y, double angle) = 0; | |
545 | ||
546 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, | |
547 | wxCoord width, wxCoord height, | |
548 | wxDC *source, | |
549 | wxCoord xsrc, wxCoord ysrc, | |
550 | wxRasterOperationMode rop = wxCOPY, | |
551 | bool useMask = false, | |
552 | wxCoord xsrcMask = wxDefaultCoord, | |
553 | wxCoord ysrcMask = wxDefaultCoord) = 0; | |
554 | ||
555 | virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest, | |
556 | wxCoord dstWidth, wxCoord dstHeight, | |
557 | wxDC *source, | |
558 | wxCoord xsrc, wxCoord ysrc, | |
559 | wxCoord srcWidth, wxCoord srcHeight, | |
560 | wxRasterOperationMode rop = wxCOPY, | |
561 | bool useMask = false, | |
562 | wxCoord xsrcMask = wxDefaultCoord, | |
563 | wxCoord ysrcMask = wxDefaultCoord); | |
564 | ||
565 | virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const | |
566 | { return wxNullBitmap; } | |
567 | ||
568 | ||
569 | virtual void DoDrawLines(int n, wxPoint points[], | |
570 | wxCoord xoffset, wxCoord yoffset ) = 0; | |
571 | virtual void DrawLines(const wxPointList *list, | |
572 | wxCoord xoffset, wxCoord yoffset ); | |
573 | ||
574 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
575 | wxCoord xoffset, wxCoord yoffset, | |
576 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE) = 0; | |
577 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], | |
578 | wxCoord xoffset, wxCoord yoffset, | |
579 | wxPolygonFillMode fillStyle); | |
580 | void DrawPolygon(const wxPointList *list, | |
581 | wxCoord xoffset, wxCoord yoffset, | |
582 | wxPolygonFillMode fillStyle ); | |
583 | ||
584 | ||
585 | #if wxUSE_SPLINES | |
586 | void DrawSpline(wxCoord x1, wxCoord y1, | |
587 | wxCoord x2, wxCoord y2, | |
588 | wxCoord x3, wxCoord y3); | |
589 | void DrawSpline(int n, wxPoint points[]); | |
590 | void DrawSpline(const wxPointList *points) { DoDrawSpline(points); } | |
591 | ||
592 | virtual void DoDrawSpline(const wxPointList *points); | |
593 | #endif | |
594 | ||
595 | // --------------------------------------------------------- | |
596 | // wxMemoryDC Impl API | |
597 | ||
598 | virtual void DoSelect(const wxBitmap& WXUNUSED(bmp)) | |
599 | { } | |
600 | ||
601 | virtual const wxBitmap& GetSelectedBitmap() const | |
602 | { return wxNullBitmap; } | |
603 | virtual wxBitmap& GetSelectedBitmap() | |
604 | { return wxNullBitmap; } | |
605 | ||
606 | // --------------------------------------------------------- | |
607 | // wxPrinterDC Impl API | |
608 | ||
609 | virtual wxRect GetPaperRect() const | |
610 | { int w = 0; int h = 0; DoGetSize( &w, &h ); return wxRect(0,0,w,h); } | |
611 | ||
612 | virtual int GetResolution() const | |
613 | { return -1; } | |
614 | ||
615 | private: | |
616 | wxDC *m_owner; | |
617 | ||
618 | protected: | |
619 | // unset clipping variables (after clipping region was destroyed) | |
620 | void ResetClipping() | |
621 | { | |
622 | m_clipping = false; | |
623 | ||
624 | m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0; | |
625 | } | |
626 | ||
627 | #ifdef __WXWINCE__ | |
628 | //! Generic method to draw ellipses, circles and arcs with current pen and brush. | |
629 | /*! \param x Upper left corner of bounding box. | |
630 | * \param y Upper left corner of bounding box. | |
631 | * \param w Width of bounding box. | |
632 | * \param h Height of bounding box. | |
633 | * \param sa Starting angle of arc | |
634 | * (counterclockwise, start at 3 o'clock, 360 is full circle). | |
635 | * \param ea Ending angle of arc. | |
636 | * \param angle Rotation angle, the Arc will be rotated after | |
637 | * calculating begin and end. | |
638 | */ | |
639 | void DrawEllipticArcRot( wxCoord x, wxCoord y, | |
640 | wxCoord width, wxCoord height, | |
641 | double sa = 0, double ea = 0, double angle = 0 ) | |
642 | { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); } | |
643 | ||
644 | void DrawEllipticArcRot( const wxPoint& pt, | |
645 | const wxSize& sz, | |
646 | double sa = 0, double ea = 0, double angle = 0 ) | |
647 | { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); } | |
648 | ||
649 | void DrawEllipticArcRot( const wxRect& rect, | |
650 | double sa = 0, double ea = 0, double angle = 0 ) | |
651 | { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); } | |
652 | ||
653 | virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y, | |
654 | wxCoord w, wxCoord h, | |
655 | double sa = 0, double ea = 0, double angle = 0 ); | |
656 | ||
657 | //! Rotates points around center. | |
658 | /*! This is a quite straight method, it calculates in pixels | |
659 | * and so it produces rounding errors. | |
660 | * \param points The points inside will be rotated. | |
661 | * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle). | |
662 | * \param center Center of rotation. | |
663 | */ | |
664 | void Rotate( wxPointList* points, double angle, wxPoint center = wxPoint(0,0) ); | |
665 | ||
666 | // used by DrawEllipticArcRot | |
667 | // Careful: wxList gets filled with points you have to delete later. | |
668 | void CalculateEllipticPoints( wxPointList* points, | |
669 | wxCoord xStart, wxCoord yStart, | |
670 | wxCoord w, wxCoord h, | |
671 | double sa, double ea ); | |
672 | #endif // __WXWINCE__ | |
673 | ||
674 | // returns adjustment factor for converting wxFont "point size"; in wx | |
675 | // it is point size on screen and needs to be multiplied by this value | |
676 | // for rendering on higher-resolution DCs such as printer ones | |
677 | static float GetFontPointSizeAdjustment(float dpi); | |
678 | ||
679 | // window on which the DC draws or NULL | |
680 | wxWindow *m_window; | |
681 | ||
682 | // flags | |
683 | bool m_colour:1; | |
684 | bool m_ok:1; | |
685 | bool m_clipping:1; | |
686 | bool m_isInteractive:1; | |
687 | bool m_isBBoxValid:1; | |
688 | ||
689 | // coordinate system variables | |
690 | ||
691 | wxCoord m_logicalOriginX, m_logicalOriginY; | |
692 | wxCoord m_deviceOriginX, m_deviceOriginY; // Usually 0,0, can be change by user | |
693 | ||
694 | wxCoord m_deviceLocalOriginX, m_deviceLocalOriginY; // non-zero if native top-left corner | |
695 | // is not at 0,0. This was the case under | |
696 | // Mac's GrafPorts (coordinate system | |
697 | // used toplevel window's origin) and | |
698 | // e.g. for Postscript, where the native | |
699 | // origin in the bottom left corner. | |
700 | double m_logicalScaleX, m_logicalScaleY; | |
701 | double m_userScaleX, m_userScaleY; | |
702 | double m_scaleX, m_scaleY; // calculated from logical scale and user scale | |
703 | ||
704 | int m_signX, m_signY; // Used by SetAxisOrientation() to invert the axes | |
705 | ||
706 | // what is a mm on a screen you don't know the size of? | |
707 | double m_mm_to_pix_x, | |
708 | m_mm_to_pix_y; | |
709 | ||
710 | // bounding and clipping boxes | |
711 | wxCoord m_minX, m_minY, m_maxX, m_maxY; | |
712 | wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2; | |
713 | ||
714 | wxRasterOperationMode m_logicalFunction; | |
715 | int m_backgroundMode; | |
716 | wxMappingMode m_mappingMode; | |
717 | ||
718 | wxPen m_pen; | |
719 | wxBrush m_brush; | |
720 | wxBrush m_backgroundBrush; | |
721 | wxColour m_textForegroundColour; | |
722 | wxColour m_textBackgroundColour; | |
723 | wxFont m_font; | |
724 | ||
725 | #if wxUSE_PALETTE | |
726 | wxPalette m_palette; | |
727 | bool m_hasCustomPalette; | |
728 | #endif // wxUSE_PALETTE | |
729 | ||
730 | private: | |
731 | DECLARE_ABSTRACT_CLASS(wxDCImpl) | |
732 | }; | |
733 | ||
734 | ||
735 | class WXDLLIMPEXP_CORE wxDC : public wxObject | |
736 | { | |
737 | public: | |
738 | // copy attributes (font, colours and writing direction) from another DC | |
739 | void CopyAttributes(const wxDC& dc); | |
740 | ||
741 | virtual ~wxDC() { delete m_pimpl; } | |
742 | ||
743 | wxDCImpl *GetImpl() | |
744 | { return m_pimpl; } | |
745 | const wxDCImpl *GetImpl() const | |
746 | { return m_pimpl; } | |
747 | ||
748 | wxWindow *GetWindow() const | |
749 | { return m_pimpl->GetWindow(); } | |
750 | ||
751 | bool IsOk() const | |
752 | { return m_pimpl && m_pimpl->IsOk(); } | |
753 | ||
754 | // query capabilities | |
755 | ||
756 | bool CanDrawBitmap() const | |
757 | { return m_pimpl->CanDrawBitmap(); } | |
758 | bool CanGetTextExtent() const | |
759 | { return m_pimpl->CanGetTextExtent(); } | |
760 | ||
761 | // query dimension, colour deps, resolution | |
762 | ||
763 | void GetSize(int *width, int *height) const | |
764 | { m_pimpl->DoGetSize(width, height); } | |
765 | wxSize GetSize() const | |
766 | { return m_pimpl->GetSize(); } | |
767 | ||
768 | void GetSizeMM(int* width, int* height) const | |
769 | { m_pimpl->DoGetSizeMM(width, height); } | |
770 | wxSize GetSizeMM() const | |
771 | { | |
772 | int w, h; | |
773 | m_pimpl->DoGetSizeMM(&w, &h); | |
774 | return wxSize(w, h); | |
775 | } | |
776 | ||
777 | int GetDepth() const | |
778 | { return m_pimpl->GetDepth(); } | |
779 | wxSize GetPPI() const | |
780 | { return m_pimpl->GetPPI(); } | |
781 | ||
782 | virtual int GetResolution() const | |
783 | { return m_pimpl->GetResolution(); } | |
784 | ||
785 | // Right-To-Left (RTL) modes | |
786 | ||
787 | void SetLayoutDirection(wxLayoutDirection dir) | |
788 | { m_pimpl->SetLayoutDirection( dir ); } | |
789 | wxLayoutDirection GetLayoutDirection() const | |
790 | { return m_pimpl->GetLayoutDirection(); } | |
791 | ||
792 | // page and document | |
793 | ||
794 | bool StartDoc(const wxString& message) | |
795 | { return m_pimpl->StartDoc(message); } | |
796 | void EndDoc() | |
797 | { m_pimpl->EndDoc(); } | |
798 | ||
799 | void StartPage() | |
800 | { m_pimpl->StartPage(); } | |
801 | void EndPage() | |
802 | { m_pimpl->EndPage(); } | |
803 | ||
804 | // bounding box | |
805 | ||
806 | void CalcBoundingBox(wxCoord x, wxCoord y) | |
807 | { m_pimpl->CalcBoundingBox(x,y); } | |
808 | void ResetBoundingBox() | |
809 | { m_pimpl->ResetBoundingBox(); } | |
810 | ||
811 | wxCoord MinX() const | |
812 | { return m_pimpl->MinX(); } | |
813 | wxCoord MaxX() const | |
814 | { return m_pimpl->MaxX(); } | |
815 | wxCoord MinY() const | |
816 | { return m_pimpl->MinY(); } | |
817 | wxCoord MaxY() const | |
818 | { return m_pimpl->MaxY(); } | |
819 | ||
820 | // setters and getters | |
821 | ||
822 | void SetFont(const wxFont& font) | |
823 | { m_pimpl->SetFont( font ); } | |
824 | const wxFont& GetFont() const | |
825 | { return m_pimpl->GetFont(); } | |
826 | ||
827 | void SetPen(const wxPen& pen) | |
828 | { m_pimpl->SetPen( pen ); } | |
829 | const wxPen& GetPen() const | |
830 | { return m_pimpl->GetPen(); } | |
831 | ||
832 | void SetBrush(const wxBrush& brush) | |
833 | { m_pimpl->SetBrush( brush ); } | |
834 | const wxBrush& GetBrush() const | |
835 | { return m_pimpl->GetBrush(); } | |
836 | ||
837 | void SetBackground(const wxBrush& brush) | |
838 | { m_pimpl->SetBackground( brush ); } | |
839 | const wxBrush& GetBackground() const | |
840 | { return m_pimpl->GetBackground(); } | |
841 | ||
842 | void SetBackgroundMode(int mode) | |
843 | { m_pimpl->SetBackgroundMode( mode ); } | |
844 | int GetBackgroundMode() const | |
845 | { return m_pimpl->GetBackgroundMode(); } | |
846 | ||
847 | void SetTextForeground(const wxColour& colour) | |
848 | { m_pimpl->SetTextForeground(colour); } | |
849 | const wxColour& GetTextForeground() const | |
850 | { return m_pimpl->GetTextForeground(); } | |
851 | ||
852 | void SetTextBackground(const wxColour& colour) | |
853 | { m_pimpl->SetTextBackground(colour); } | |
854 | const wxColour& GetTextBackground() const | |
855 | { return m_pimpl->GetTextBackground(); } | |
856 | ||
857 | #if wxUSE_PALETTE | |
858 | void SetPalette(const wxPalette& palette) | |
859 | { m_pimpl->SetPalette(palette); } | |
860 | #endif // wxUSE_PALETTE | |
861 | ||
862 | // logical functions | |
863 | ||
864 | void SetLogicalFunction(wxRasterOperationMode function) | |
865 | { m_pimpl->SetLogicalFunction(function); } | |
866 | wxRasterOperationMode GetLogicalFunction() const | |
867 | { return m_pimpl->GetLogicalFunction(); } | |
868 | ||
869 | // text measurement | |
870 | ||
871 | wxCoord GetCharHeight() const | |
872 | { return m_pimpl->GetCharHeight(); } | |
873 | wxCoord GetCharWidth() const | |
874 | { return m_pimpl->GetCharWidth(); } | |
875 | ||
876 | wxFontMetrics GetFontMetrics() const | |
877 | { | |
878 | wxFontMetrics fm; | |
879 | m_pimpl->DoGetFontMetrics(&fm.height, &fm.ascent, &fm.descent, | |
880 | &fm.internalLeading, &fm.externalLeading, | |
881 | &fm.averageWidth); | |
882 | return fm; | |
883 | } | |
884 | ||
885 | void GetTextExtent(const wxString& string, | |
886 | wxCoord *x, wxCoord *y, | |
887 | wxCoord *descent = NULL, | |
888 | wxCoord *externalLeading = NULL, | |
889 | const wxFont *theFont = NULL) const | |
890 | { m_pimpl->DoGetTextExtent(string, x, y, descent, externalLeading, theFont); } | |
891 | ||
892 | wxSize GetTextExtent(const wxString& string) const | |
893 | { | |
894 | wxCoord w, h; | |
895 | m_pimpl->DoGetTextExtent(string, &w, &h); | |
896 | return wxSize(w, h); | |
897 | } | |
898 | ||
899 | void GetMultiLineTextExtent(const wxString& string, | |
900 | wxCoord *width, | |
901 | wxCoord *height, | |
902 | wxCoord *heightLine = NULL, | |
903 | const wxFont *font = NULL) const | |
904 | { m_pimpl->GetMultiLineTextExtent( string, width, height, heightLine, font ); } | |
905 | ||
906 | wxSize GetMultiLineTextExtent(const wxString& string) const | |
907 | { | |
908 | wxCoord w, h; | |
909 | m_pimpl->GetMultiLineTextExtent(string, &w, &h); | |
910 | return wxSize(w, h); | |
911 | } | |
912 | ||
913 | bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const | |
914 | { return m_pimpl->DoGetPartialTextExtents(text, widths); } | |
915 | ||
916 | // clearing | |
917 | ||
918 | void Clear() | |
919 | { m_pimpl->Clear(); } | |
920 | ||
921 | // clipping | |
922 | ||
923 | void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
924 | { m_pimpl->DoSetClippingRegion(x, y, width, height); } | |
925 | void SetClippingRegion(const wxPoint& pt, const wxSize& sz) | |
926 | { m_pimpl->DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); } | |
927 | void SetClippingRegion(const wxRect& rect) | |
928 | { m_pimpl->DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); } | |
929 | ||
930 | // unlike the functions above, the coordinates of the region used in this | |
931 | // one are in device coordinates, not the logical ones | |
932 | void SetDeviceClippingRegion(const wxRegion& region) | |
933 | { m_pimpl->DoSetDeviceClippingRegion(region); } | |
934 | ||
935 | // this function is deprecated because its name is confusing: you may | |
936 | // expect it to work with logical coordinates but, in fact, it does exactly | |
937 | // the same thing as SetDeviceClippingRegion() | |
938 | // | |
939 | // please review the code using it and either replace it with calls to | |
940 | // SetDeviceClippingRegion() or correct it if it was [wrongly] passing | |
941 | // logical coordinates to this function | |
942 | wxDEPRECATED_INLINE(void SetClippingRegion(const wxRegion& region), | |
943 | SetDeviceClippingRegion(region); ) | |
944 | ||
945 | void DestroyClippingRegion() | |
946 | { m_pimpl->DestroyClippingRegion(); } | |
947 | ||
948 | void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const | |
949 | { m_pimpl->DoGetClippingBox(x, y, w, h); } | |
950 | void GetClippingBox(wxRect& rect) const | |
951 | { m_pimpl->DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); } | |
952 | ||
953 | // coordinates conversions and transforms | |
954 | ||
955 | wxCoord DeviceToLogicalX(wxCoord x) const | |
956 | { return m_pimpl->DeviceToLogicalX(x); } | |
957 | wxCoord DeviceToLogicalY(wxCoord y) const | |
958 | { return m_pimpl->DeviceToLogicalY(y); } | |
959 | wxCoord DeviceToLogicalXRel(wxCoord x) const | |
960 | { return m_pimpl->DeviceToLogicalXRel(x); } | |
961 | wxCoord DeviceToLogicalYRel(wxCoord y) const | |
962 | { return m_pimpl->DeviceToLogicalYRel(y); } | |
963 | wxCoord LogicalToDeviceX(wxCoord x) const | |
964 | { return m_pimpl->LogicalToDeviceX(x); } | |
965 | wxCoord LogicalToDeviceY(wxCoord y) const | |
966 | { return m_pimpl->LogicalToDeviceY(y); } | |
967 | wxCoord LogicalToDeviceXRel(wxCoord x) const | |
968 | { return m_pimpl->LogicalToDeviceXRel(x); } | |
969 | wxCoord LogicalToDeviceYRel(wxCoord y) const | |
970 | { return m_pimpl->LogicalToDeviceYRel(y); } | |
971 | ||
972 | void SetMapMode(wxMappingMode mode) | |
973 | { m_pimpl->SetMapMode(mode); } | |
974 | wxMappingMode GetMapMode() const | |
975 | { return m_pimpl->GetMapMode(); } | |
976 | ||
977 | void SetUserScale(double x, double y) | |
978 | { m_pimpl->SetUserScale(x,y); } | |
979 | void GetUserScale(double *x, double *y) const | |
980 | { m_pimpl->GetUserScale( x, y ); } | |
981 | ||
982 | void SetLogicalScale(double x, double y) | |
983 | { m_pimpl->SetLogicalScale( x, y ); } | |
984 | void GetLogicalScale(double *x, double *y) | |
985 | { m_pimpl->GetLogicalScale( x, y ); } | |
986 | ||
987 | void SetLogicalOrigin(wxCoord x, wxCoord y) | |
988 | { m_pimpl->SetLogicalOrigin(x,y); } | |
989 | void GetLogicalOrigin(wxCoord *x, wxCoord *y) const | |
990 | { m_pimpl->DoGetLogicalOrigin(x, y); } | |
991 | wxPoint GetLogicalOrigin() const | |
992 | { wxCoord x, y; m_pimpl->DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); } | |
993 | ||
994 | void SetDeviceOrigin(wxCoord x, wxCoord y) | |
995 | { m_pimpl->SetDeviceOrigin( x, y); } | |
996 | void GetDeviceOrigin(wxCoord *x, wxCoord *y) const | |
997 | { m_pimpl->DoGetDeviceOrigin(x, y); } | |
998 | wxPoint GetDeviceOrigin() const | |
999 | { wxCoord x, y; m_pimpl->DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); } | |
1000 | ||
1001 | void SetAxisOrientation(bool xLeftRight, bool yBottomUp) | |
1002 | { m_pimpl->SetAxisOrientation(xLeftRight, yBottomUp); } | |
1003 | ||
1004 | // mostly internal | |
1005 | void SetDeviceLocalOrigin( wxCoord x, wxCoord y ) | |
1006 | { m_pimpl->SetDeviceLocalOrigin( x, y ); } | |
1007 | ||
1008 | ||
1009 | // ----------------------------------------------- | |
1010 | // the actual drawing API | |
1011 | ||
1012 | bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
1013 | wxFloodFillStyle style = wxFLOOD_SURFACE) | |
1014 | { return m_pimpl->DoFloodFill(x, y, col, style); } | |
1015 | bool FloodFill(const wxPoint& pt, const wxColour& col, | |
1016 | wxFloodFillStyle style = wxFLOOD_SURFACE) | |
1017 | { return m_pimpl->DoFloodFill(pt.x, pt.y, col, style); } | |
1018 | ||
1019 | // fill the area specified by rect with a radial gradient, starting from | |
1020 | // initialColour in the centre of the cercle and fading to destColour. | |
1021 | void GradientFillConcentric(const wxRect& rect, | |
1022 | const wxColour& initialColour, | |
1023 | const wxColour& destColour) | |
1024 | { m_pimpl->DoGradientFillConcentric( rect, initialColour, destColour, | |
1025 | wxPoint(rect.GetWidth() / 2, | |
1026 | rect.GetHeight() / 2)); } | |
1027 | ||
1028 | void GradientFillConcentric(const wxRect& rect, | |
1029 | const wxColour& initialColour, | |
1030 | const wxColour& destColour, | |
1031 | const wxPoint& circleCenter) | |
1032 | { m_pimpl->DoGradientFillConcentric(rect, initialColour, destColour, circleCenter); } | |
1033 | ||
1034 | // fill the area specified by rect with a linear gradient | |
1035 | void GradientFillLinear(const wxRect& rect, | |
1036 | const wxColour& initialColour, | |
1037 | const wxColour& destColour, | |
1038 | wxDirection nDirection = wxEAST) | |
1039 | { m_pimpl->DoGradientFillLinear(rect, initialColour, destColour, nDirection); } | |
1040 | ||
1041 | bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const | |
1042 | { return m_pimpl->DoGetPixel(x, y, col); } | |
1043 | bool GetPixel(const wxPoint& pt, wxColour *col) const | |
1044 | { return m_pimpl->DoGetPixel(pt.x, pt.y, col); } | |
1045 | ||
1046 | void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
1047 | { m_pimpl->DoDrawLine(x1, y1, x2, y2); } | |
1048 | void DrawLine(const wxPoint& pt1, const wxPoint& pt2) | |
1049 | { m_pimpl->DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); } | |
1050 | ||
1051 | void CrossHair(wxCoord x, wxCoord y) | |
1052 | { m_pimpl->DoCrossHair(x, y); } | |
1053 | void CrossHair(const wxPoint& pt) | |
1054 | { m_pimpl->DoCrossHair(pt.x, pt.y); } | |
1055 | ||
1056 | void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, | |
1057 | wxCoord xc, wxCoord yc) | |
1058 | { m_pimpl->DoDrawArc(x1, y1, x2, y2, xc, yc); } | |
1059 | void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre) | |
1060 | { m_pimpl->DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); } | |
1061 | ||
1062 | void DrawCheckMark(wxCoord x, wxCoord y, | |
1063 | wxCoord width, wxCoord height) | |
1064 | { m_pimpl->DoDrawCheckMark(x, y, width, height); } | |
1065 | void DrawCheckMark(const wxRect& rect) | |
1066 | { m_pimpl->DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); } | |
1067 | ||
1068 | void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
1069 | double sa, double ea) | |
1070 | { m_pimpl->DoDrawEllipticArc(x, y, w, h, sa, ea); } | |
1071 | void DrawEllipticArc(const wxPoint& pt, const wxSize& sz, | |
1072 | double sa, double ea) | |
1073 | { m_pimpl->DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); } | |
1074 | ||
1075 | void DrawPoint(wxCoord x, wxCoord y) | |
1076 | { m_pimpl->DoDrawPoint(x, y); } | |
1077 | void DrawPoint(const wxPoint& pt) | |
1078 | { m_pimpl->DoDrawPoint(pt.x, pt.y); } | |
1079 | ||
1080 | void DrawLines(int n, wxPoint points[], | |
1081 | wxCoord xoffset = 0, wxCoord yoffset = 0) | |
1082 | { m_pimpl->DoDrawLines(n, points, xoffset, yoffset); } | |
1083 | void DrawLines(const wxPointList *list, | |
1084 | wxCoord xoffset = 0, wxCoord yoffset = 0) | |
1085 | { m_pimpl->DrawLines( list, xoffset, yoffset ); } | |
1086 | #if WXWIN_COMPATIBILITY_2_8 | |
1087 | wxDEPRECATED( void DrawLines(const wxList *list, | |
1088 | wxCoord xoffset = 0, wxCoord yoffset = 0) ); | |
1089 | #endif // WXWIN_COMPATIBILITY_2_8 | |
1090 | ||
1091 | void DrawPolygon(int n, wxPoint points[], | |
1092 | wxCoord xoffset = 0, wxCoord yoffset = 0, | |
1093 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE) | |
1094 | { m_pimpl->DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); } | |
1095 | void DrawPolygon(const wxPointList *list, | |
1096 | wxCoord xoffset = 0, wxCoord yoffset = 0, | |
1097 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE) | |
1098 | { m_pimpl->DrawPolygon( list, xoffset, yoffset, fillStyle ); } | |
1099 | void DrawPolyPolygon(int n, int count[], wxPoint points[], | |
1100 | wxCoord xoffset = 0, wxCoord yoffset = 0, | |
1101 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE) | |
1102 | { m_pimpl->DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); } | |
1103 | #if WXWIN_COMPATIBILITY_2_8 | |
1104 | wxDEPRECATED( void DrawPolygon(const wxList *list, | |
1105 | wxCoord xoffset = 0, wxCoord yoffset = 0, | |
1106 | wxPolygonFillMode fillStyle = wxODDEVEN_RULE) ); | |
1107 | #endif // WXWIN_COMPATIBILITY_2_8 | |
1108 | ||
1109 | void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1110 | { m_pimpl->DoDrawRectangle(x, y, width, height); } | |
1111 | void DrawRectangle(const wxPoint& pt, const wxSize& sz) | |
1112 | { m_pimpl->DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); } | |
1113 | void DrawRectangle(const wxRect& rect) | |
1114 | { m_pimpl->DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); } | |
1115 | ||
1116 | void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, | |
1117 | double radius) | |
1118 | { m_pimpl->DoDrawRoundedRectangle(x, y, width, height, radius); } | |
1119 | void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, | |
1120 | double radius) | |
1121 | { m_pimpl->DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); } | |
1122 | void DrawRoundedRectangle(const wxRect& r, double radius) | |
1123 | { m_pimpl->DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); } | |
1124 | ||
1125 | void DrawCircle(wxCoord x, wxCoord y, wxCoord radius) | |
1126 | { m_pimpl->DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); } | |
1127 | void DrawCircle(const wxPoint& pt, wxCoord radius) | |
1128 | { m_pimpl->DoDrawEllipse(pt.x - radius, pt.y - radius, 2*radius, 2*radius); } | |
1129 | ||
1130 | void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1131 | { m_pimpl->DoDrawEllipse(x, y, width, height); } | |
1132 | void DrawEllipse(const wxPoint& pt, const wxSize& sz) | |
1133 | { m_pimpl->DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); } | |
1134 | void DrawEllipse(const wxRect& rect) | |
1135 | { m_pimpl->DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); } | |
1136 | ||
1137 | void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
1138 | { m_pimpl->DoDrawIcon(icon, x, y); } | |
1139 | void DrawIcon(const wxIcon& icon, const wxPoint& pt) | |
1140 | { m_pimpl->DoDrawIcon(icon, pt.x, pt.y); } | |
1141 | ||
1142 | void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
1143 | bool useMask = false) | |
1144 | { m_pimpl->DoDrawBitmap(bmp, x, y, useMask); } | |
1145 | void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, | |
1146 | bool useMask = false) | |
1147 | { m_pimpl->DoDrawBitmap(bmp, pt.x, pt.y, useMask); } | |
1148 | ||
1149 | void DrawText(const wxString& text, wxCoord x, wxCoord y) | |
1150 | { m_pimpl->DoDrawText(text, x, y); } | |
1151 | void DrawText(const wxString& text, const wxPoint& pt) | |
1152 | { m_pimpl->DoDrawText(text, pt.x, pt.y); } | |
1153 | ||
1154 | void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) | |
1155 | { m_pimpl->DoDrawRotatedText(text, x, y, angle); } | |
1156 | void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle) | |
1157 | { m_pimpl->DoDrawRotatedText(text, pt.x, pt.y, angle); } | |
1158 | ||
1159 | // this version puts both optional bitmap and the text into the given | |
1160 | // rectangle and aligns is as specified by alignment parameter; it also | |
1161 | // will emphasize the character with the given index if it is != -1 and | |
1162 | // return the bounding rectangle if required | |
1163 | void DrawLabel(const wxString& text, | |
1164 | const wxBitmap& image, | |
1165 | const wxRect& rect, | |
1166 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
1167 | int indexAccel = -1, | |
1168 | wxRect *rectBounding = NULL); | |
1169 | ||
1170 | void DrawLabel(const wxString& text, const wxRect& rect, | |
1171 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
1172 | int indexAccel = -1) | |
1173 | { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); } | |
1174 | ||
1175 | bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
1176 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
1177 | wxRasterOperationMode rop = wxCOPY, bool useMask = false, | |
1178 | wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) | |
1179 | { | |
1180 | return m_pimpl->DoBlit(xdest, ydest, width, height, | |
1181 | source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask); | |
1182 | } | |
1183 | bool Blit(const wxPoint& destPt, const wxSize& sz, | |
1184 | wxDC *source, const wxPoint& srcPt, | |
1185 | wxRasterOperationMode rop = wxCOPY, bool useMask = false, | |
1186 | const wxPoint& srcPtMask = wxDefaultPosition) | |
1187 | { | |
1188 | return m_pimpl->DoBlit(destPt.x, destPt.y, sz.x, sz.y, | |
1189 | source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y); | |
1190 | } | |
1191 | ||
1192 | bool StretchBlit(wxCoord dstX, wxCoord dstY, | |
1193 | wxCoord dstWidth, wxCoord dstHeight, | |
1194 | wxDC *source, | |
1195 | wxCoord srcX, wxCoord srcY, | |
1196 | wxCoord srcWidth, wxCoord srcHeight, | |
1197 | wxRasterOperationMode rop = wxCOPY, bool useMask = false, | |
1198 | wxCoord srcMaskX = wxDefaultCoord, wxCoord srcMaskY = wxDefaultCoord) | |
1199 | { | |
1200 | return m_pimpl->DoStretchBlit(dstX, dstY, dstWidth, dstHeight, | |
1201 | source, srcX, srcY, srcWidth, srcHeight, rop, useMask, srcMaskX, srcMaskY); | |
1202 | } | |
1203 | bool StretchBlit(const wxPoint& dstPt, const wxSize& dstSize, | |
1204 | wxDC *source, const wxPoint& srcPt, const wxSize& srcSize, | |
1205 | wxRasterOperationMode rop = wxCOPY, bool useMask = false, | |
1206 | const wxPoint& srcMaskPt = wxDefaultPosition) | |
1207 | { | |
1208 | return m_pimpl->DoStretchBlit(dstPt.x, dstPt.y, dstSize.x, dstSize.y, | |
1209 | source, srcPt.x, srcPt.y, srcSize.x, srcSize.y, rop, useMask, srcMaskPt.x, srcMaskPt.y); | |
1210 | } | |
1211 | ||
1212 | wxBitmap GetAsBitmap(const wxRect *subrect = (const wxRect *) NULL) const | |
1213 | { | |
1214 | return m_pimpl->DoGetAsBitmap(subrect); | |
1215 | } | |
1216 | ||
1217 | #if wxUSE_SPLINES | |
1218 | void DrawSpline(wxCoord x1, wxCoord y1, | |
1219 | wxCoord x2, wxCoord y2, | |
1220 | wxCoord x3, wxCoord y3) | |
1221 | { m_pimpl->DrawSpline(x1,y1,x2,y2,x3,y3); } | |
1222 | void DrawSpline(int n, wxPoint points[]) | |
1223 | { m_pimpl->DrawSpline(n,points); } | |
1224 | void DrawSpline(const wxPointList *points) | |
1225 | { m_pimpl->DrawSpline(points); } | |
1226 | #endif // wxUSE_SPLINES | |
1227 | ||
1228 | ||
1229 | #if WXWIN_COMPATIBILITY_2_8 | |
1230 | // for compatibility with the old code when wxCoord was long everywhere | |
1231 | wxDEPRECATED( void GetTextExtent(const wxString& string, | |
1232 | long *x, long *y, | |
1233 | long *descent = NULL, | |
1234 | long *externalLeading = NULL, | |
1235 | const wxFont *theFont = NULL) const ); | |
1236 | wxDEPRECATED( void GetLogicalOrigin(long *x, long *y) const ); | |
1237 | wxDEPRECATED( void GetDeviceOrigin(long *x, long *y) const ); | |
1238 | wxDEPRECATED( void GetClippingBox(long *x, long *y, long *w, long *h) const ); | |
1239 | ||
1240 | wxDEPRECATED( void DrawObject(wxDrawObject* drawobject) ); | |
1241 | #endif // WXWIN_COMPATIBILITY_2_8 | |
1242 | ||
1243 | #ifdef __WXMSW__ | |
1244 | // GetHDC() is the simplest way to retrieve an HDC From a wxDC but only | |
1245 | // works if this wxDC is GDI-based and fails for GDI+ contexts (and | |
1246 | // anything else without HDC, e.g. wxPostScriptDC) | |
1247 | WXHDC GetHDC() const; | |
1248 | ||
1249 | // don't use these methods manually, use GetTempHDC() instead | |
1250 | virtual WXHDC AcquireHDC() { return GetHDC(); } | |
1251 | virtual void ReleaseHDC(WXHDC WXUNUSED(hdc)) { } | |
1252 | ||
1253 | // helper class holding the result of GetTempHDC() with std::auto_ptr<>-like | |
1254 | // semantics, i.e. it is moved when copied | |
1255 | class TempHDC | |
1256 | { | |
1257 | public: | |
1258 | TempHDC(wxDC& dc) | |
1259 | : m_dc(dc), | |
1260 | m_hdc(dc.AcquireHDC()) | |
1261 | { | |
1262 | } | |
1263 | ||
1264 | TempHDC(const TempHDC& thdc) | |
1265 | : m_dc(thdc.m_dc), | |
1266 | m_hdc(thdc.m_hdc) | |
1267 | { | |
1268 | const_cast<TempHDC&>(thdc).m_hdc = 0; | |
1269 | } | |
1270 | ||
1271 | ~TempHDC() | |
1272 | { | |
1273 | if ( m_hdc ) | |
1274 | m_dc.ReleaseHDC(m_hdc); | |
1275 | } | |
1276 | ||
1277 | WXHDC GetHDC() const { return m_hdc; } | |
1278 | ||
1279 | private: | |
1280 | wxDC& m_dc; | |
1281 | WXHDC m_hdc; | |
1282 | ||
1283 | wxDECLARE_NO_ASSIGN_CLASS(TempHDC); | |
1284 | }; | |
1285 | ||
1286 | // GetTempHDC() also works for wxGCDC (but still not for wxPostScriptDC &c) | |
1287 | TempHDC GetTempHDC() { return TempHDC(*this); } | |
1288 | #endif // __WXMSW__ | |
1289 | ||
1290 | protected: | |
1291 | // ctor takes ownership of the pointer | |
1292 | wxDC(wxDCImpl *pimpl) : m_pimpl(pimpl) { } | |
1293 | ||
1294 | wxDCImpl * const m_pimpl; | |
1295 | ||
1296 | private: | |
1297 | DECLARE_ABSTRACT_CLASS(wxDC) | |
1298 | wxDECLARE_NO_COPY_CLASS(wxDC); | |
1299 | }; | |
1300 | ||
1301 | // ---------------------------------------------------------------------------- | |
1302 | // helper class: you can use it to temporarily change the DC text colour and | |
1303 | // restore it automatically when the object goes out of scope | |
1304 | // ---------------------------------------------------------------------------- | |
1305 | ||
1306 | class WXDLLIMPEXP_CORE wxDCTextColourChanger | |
1307 | { | |
1308 | public: | |
1309 | wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { } | |
1310 | ||
1311 | wxDCTextColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc) | |
1312 | { | |
1313 | Set(col); | |
1314 | } | |
1315 | ||
1316 | ~wxDCTextColourChanger() | |
1317 | { | |
1318 | if ( m_colFgOld.Ok() ) | |
1319 | m_dc.SetTextForeground(m_colFgOld); | |
1320 | } | |
1321 | ||
1322 | void Set(const wxColour& col) | |
1323 | { | |
1324 | if ( !m_colFgOld.Ok() ) | |
1325 | m_colFgOld = m_dc.GetTextForeground(); | |
1326 | m_dc.SetTextForeground(col); | |
1327 | } | |
1328 | ||
1329 | private: | |
1330 | wxDC& m_dc; | |
1331 | ||
1332 | wxColour m_colFgOld; | |
1333 | ||
1334 | wxDECLARE_NO_COPY_CLASS(wxDCTextColourChanger); | |
1335 | }; | |
1336 | ||
1337 | // ---------------------------------------------------------------------------- | |
1338 | // helper class: you can use it to temporarily change the DC pen and | |
1339 | // restore it automatically when the object goes out of scope | |
1340 | // ---------------------------------------------------------------------------- | |
1341 | ||
1342 | class WXDLLIMPEXP_CORE wxDCPenChanger | |
1343 | { | |
1344 | public: | |
1345 | wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen()) | |
1346 | { | |
1347 | m_dc.SetPen(pen); | |
1348 | } | |
1349 | ||
1350 | ~wxDCPenChanger() | |
1351 | { | |
1352 | if ( m_penOld.Ok() ) | |
1353 | m_dc.SetPen(m_penOld); | |
1354 | } | |
1355 | ||
1356 | private: | |
1357 | wxDC& m_dc; | |
1358 | ||
1359 | wxPen m_penOld; | |
1360 | ||
1361 | wxDECLARE_NO_COPY_CLASS(wxDCPenChanger); | |
1362 | }; | |
1363 | ||
1364 | // ---------------------------------------------------------------------------- | |
1365 | // helper class: you can use it to temporarily change the DC brush and | |
1366 | // restore it automatically when the object goes out of scope | |
1367 | // ---------------------------------------------------------------------------- | |
1368 | ||
1369 | class WXDLLIMPEXP_CORE wxDCBrushChanger | |
1370 | { | |
1371 | public: | |
1372 | wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush()) | |
1373 | { | |
1374 | m_dc.SetBrush(brush); | |
1375 | } | |
1376 | ||
1377 | ~wxDCBrushChanger() | |
1378 | { | |
1379 | if ( m_brushOld.Ok() ) | |
1380 | m_dc.SetBrush(m_brushOld); | |
1381 | } | |
1382 | ||
1383 | private: | |
1384 | wxDC& m_dc; | |
1385 | ||
1386 | wxBrush m_brushOld; | |
1387 | ||
1388 | wxDECLARE_NO_COPY_CLASS(wxDCBrushChanger); | |
1389 | }; | |
1390 | ||
1391 | // ---------------------------------------------------------------------------- | |
1392 | // another small helper class: sets the clipping region in its ctor and | |
1393 | // destroys it in the dtor | |
1394 | // ---------------------------------------------------------------------------- | |
1395 | ||
1396 | class WXDLLIMPEXP_CORE wxDCClipper | |
1397 | { | |
1398 | public: | |
1399 | wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc) | |
1400 | { dc.SetClippingRegion(r.GetBox()); } | |
1401 | wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc) | |
1402 | { dc.SetClippingRegion(r.x, r.y, r.width, r.height); } | |
1403 | wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc) | |
1404 | { dc.SetClippingRegion(x, y, w, h); } | |
1405 | ||
1406 | ~wxDCClipper() { m_dc.DestroyClippingRegion(); } | |
1407 | ||
1408 | private: | |
1409 | wxDC& m_dc; | |
1410 | ||
1411 | wxDECLARE_NO_COPY_CLASS(wxDCClipper); | |
1412 | }; | |
1413 | ||
1414 | // ---------------------------------------------------------------------------- | |
1415 | // helper class: you can use it to temporarily change the DC font and | |
1416 | // restore it automatically when the object goes out of scope | |
1417 | // ---------------------------------------------------------------------------- | |
1418 | ||
1419 | class WXDLLIMPEXP_CORE wxDCFontChanger | |
1420 | { | |
1421 | public: | |
1422 | wxDCFontChanger(wxDC& dc) | |
1423 | : m_dc(dc), m_fontOld() | |
1424 | { | |
1425 | } | |
1426 | ||
1427 | wxDCFontChanger(wxDC& dc, const wxFont& font) | |
1428 | : m_dc(dc), m_fontOld(dc.GetFont()) | |
1429 | { | |
1430 | m_dc.SetFont(font); | |
1431 | } | |
1432 | ||
1433 | void Set(const wxFont& font) | |
1434 | { | |
1435 | if ( !m_fontOld.Ok() ) | |
1436 | m_fontOld = m_dc.GetFont(); | |
1437 | m_dc.SetFont(font); | |
1438 | } | |
1439 | ||
1440 | ~wxDCFontChanger() | |
1441 | { | |
1442 | if ( m_fontOld.Ok() ) | |
1443 | m_dc.SetFont(m_fontOld); | |
1444 | } | |
1445 | ||
1446 | private: | |
1447 | wxDC& m_dc; | |
1448 | ||
1449 | wxFont m_fontOld; | |
1450 | ||
1451 | wxDECLARE_NO_COPY_CLASS(wxDCFontChanger); | |
1452 | }; | |
1453 | ||
1454 | ||
1455 | #endif // _WX_DC_H_BASE_ |