dc.h 53 KB

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