+#include "wx/dynarray.h"
+#include "wx/math.h"
+#include "wx/image.h"
+#include "wx/region.h"
+#include "wx/affinematrix2d.h"
+
+#define wxUSE_NEW_DC 1
+
+class WXDLLIMPEXP_FWD_CORE wxDC;
+class WXDLLIMPEXP_FWD_CORE wxClientDC;
+class WXDLLIMPEXP_FWD_CORE wxPaintDC;
+class WXDLLIMPEXP_FWD_CORE wxWindowDC;
+class WXDLLIMPEXP_FWD_CORE wxScreenDC;
+class WXDLLIMPEXP_FWD_CORE wxMemoryDC;
+class WXDLLIMPEXP_FWD_CORE wxPrinterDC;
+class WXDLLIMPEXP_FWD_CORE wxPrintData;
+
+#if wxUSE_GRAPHICS_CONTEXT
+class WXDLLIMPEXP_FWD_CORE wxGraphicsContext;
+#endif
+
+// Logical ops
+enum wxRasterOperationMode
+{
+ wxCLEAR, // 0
+ wxXOR, // src XOR dst
+ wxINVERT, // NOT dst
+ wxOR_REVERSE, // src OR (NOT dst)
+ wxAND_REVERSE, // src AND (NOT dst)
+ wxCOPY, // src
+ wxAND, // src AND dst
+ wxAND_INVERT, // (NOT src) AND dst
+ wxNO_OP, // dst
+ wxNOR, // (NOT src) AND (NOT dst)
+ wxEQUIV, // (NOT src) XOR dst
+ wxSRC_INVERT, // (NOT src)
+ wxOR_INVERT, // (NOT src) OR dst
+ wxNAND, // (NOT src) OR (NOT dst)
+ wxOR, // src OR dst
+ wxSET // 1
+#if WXWIN_COMPATIBILITY_2_8
+ ,wxROP_BLACK = wxCLEAR,
+ wxBLIT_BLACKNESS = wxCLEAR,
+ wxROP_XORPEN = wxXOR,
+ wxBLIT_SRCINVERT = wxXOR,
+ wxROP_NOT = wxINVERT,
+ wxBLIT_DSTINVERT = wxINVERT,
+ wxROP_MERGEPENNOT = wxOR_REVERSE,
+ wxBLIT_00DD0228 = wxOR_REVERSE,
+ wxROP_MASKPENNOT = wxAND_REVERSE,
+ wxBLIT_SRCERASE = wxAND_REVERSE,
+ wxROP_COPYPEN = wxCOPY,
+ wxBLIT_SRCCOPY = wxCOPY,
+ wxROP_MASKPEN = wxAND,
+ wxBLIT_SRCAND = wxAND,
+ wxROP_MASKNOTPEN = wxAND_INVERT,
+ wxBLIT_00220326 = wxAND_INVERT,
+ wxROP_NOP = wxNO_OP,
+ wxBLIT_00AA0029 = wxNO_OP,
+ wxROP_NOTMERGEPEN = wxNOR,
+ wxBLIT_NOTSRCERASE = wxNOR,
+ wxROP_NOTXORPEN = wxEQUIV,
+ wxBLIT_00990066 = wxEQUIV,
+ wxROP_NOTCOPYPEN = wxSRC_INVERT,
+ wxBLIT_NOTSCRCOPY = wxSRC_INVERT,
+ wxROP_MERGENOTPEN = wxOR_INVERT,
+ wxBLIT_MERGEPAINT = wxOR_INVERT,
+ wxROP_NOTMASKPEN = wxNAND,
+ wxBLIT_007700E6 = wxNAND,
+ wxROP_MERGEPEN = wxOR,
+ wxBLIT_SRCPAINT = wxOR,
+ wxROP_WHITE = wxSET,
+ wxBLIT_WHITENESS = wxSET
+#endif //WXWIN_COMPATIBILITY_2_8
+};
+
+// Flood styles
+enum wxFloodFillStyle
+{
+ wxFLOOD_SURFACE = 1,
+ wxFLOOD_BORDER
+};
+
+// Mapping modes
+enum wxMappingMode
+{
+ wxMM_TEXT = 1,
+ wxMM_METRIC,
+ wxMM_LOMETRIC,
+ wxMM_TWIPS,
+ wxMM_POINTS
+};
+
+// Description of text characteristics.
+struct wxFontMetrics
+{
+ wxFontMetrics()
+ {
+ height =
+ ascent =
+ descent =
+ internalLeading =
+ externalLeading =
+ averageWidth = 0;
+ }
+
+ int height, // Total character height.
+ ascent, // Part of the height above the baseline.
+ descent, // Part of the height below the baseline.
+ internalLeading, // Intra-line spacing.
+ externalLeading, // Inter-line spacing.
+ averageWidth; // Average font width, a.k.a. "x-width".
+};
+
+#if WXWIN_COMPATIBILITY_2_8
+
+//-----------------------------------------------------------------------------
+// wxDrawObject helper class
+//-----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxDrawObject
+{
+public:
+ wxDEPRECATED_CONSTRUCTOR(wxDrawObject)()
+ : m_isBBoxValid(false)
+ , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
+ { }
+
+ virtual ~wxDrawObject() { }
+
+ virtual void Draw(wxDC&) const { }
+
+ virtual void CalcBoundingBox(wxCoord x, wxCoord y)
+ {
+ if ( m_isBBoxValid )
+ {
+ if ( x < m_minX ) m_minX = x;
+ if ( y < m_minY ) m_minY = y;
+ if ( x > m_maxX ) m_maxX = x;
+ if ( y > m_maxY ) m_maxY = y;
+ }
+ else
+ {
+ m_isBBoxValid = true;
+
+ m_minX = x;
+ m_minY = y;
+ m_maxX = x;
+ m_maxY = y;
+ }
+ }
+
+ void ResetBoundingBox()
+ {
+ m_isBBoxValid = false;
+
+ m_minX = m_maxX = m_minY = m_maxY = 0;
+ }
+
+ // Get the final bounding box of the PostScript or Metafile picture.
+
+ wxCoord MinX() const { return m_minX; }
+ wxCoord MaxX() const { return m_maxX; }
+ wxCoord MinY() const { return m_minY; }
+ wxCoord MaxY() const { return m_maxY; }
+
+ //to define the type of object for derived objects
+ virtual int GetType()=0;
+
+protected:
+ //for boundingbox calculation
+ bool m_isBBoxValid:1;
+ //for boundingbox calculation
+ wxCoord m_minX, m_minY, m_maxX, m_maxY;
+};
+
+#endif // WXWIN_COMPATIBILITY_2_8
+
+
+//-----------------------------------------------------------------------------
+// wxDCFactory
+//-----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_FWD_CORE wxDCImpl;
+
+class WXDLLIMPEXP_CORE wxDCFactory
+{
+public:
+ wxDCFactory() {}
+ virtual ~wxDCFactory() {}
+
+ virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window ) = 0;
+ virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window ) = 0;
+ virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window ) = 0;
+ virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner ) = 0;
+ virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ) = 0;
+ virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ) = 0;
+ virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner ) = 0;
+#if wxUSE_PRINTING_ARCHITECTURE
+ virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data ) = 0;
+#endif
+
+ static void Set(wxDCFactory *factory);
+ static wxDCFactory *Get();
+
+private:
+ static wxDCFactory *m_factory;
+};
+
+//-----------------------------------------------------------------------------
+// wxNativeDCFactory
+//-----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxNativeDCFactory: public wxDCFactory
+{
+public:
+ wxNativeDCFactory() {}
+
+ virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window );
+ virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window );
+ virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window );
+ virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner );
+ virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap );
+ virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc );
+ virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner );
+#if wxUSE_PRINTING_ARCHITECTURE
+ virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data );
+#endif
+};
+
+//-----------------------------------------------------------------------------
+// wxDCImpl
+//-----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxDCImpl: public wxObject
+{
+public:
+ wxDCImpl( wxDC *owner );
+ virtual ~wxDCImpl();
+
+ wxDC *GetOwner() const { return m_owner; }
+
+ wxWindow* GetWindow() const { return m_window; }
+
+ virtual bool IsOk() const { return m_ok; }
+
+ // query capabilities
+
+ virtual bool CanDrawBitmap() const = 0;
+ virtual bool CanGetTextExtent() const = 0;
+
+ // get Cairo context
+ virtual void* GetCairoContext() const
+ {
+ return NULL;
+ }
+
+ // query dimension, colour deps, resolution
+
+ virtual void DoGetSize(int *width, int *height) const = 0;
+ void GetSize(int *width, int *height) const
+ {
+ DoGetSize(width, height);
+ return ;
+ }
+
+ wxSize GetSize() const
+ {
+ int w, h;
+ DoGetSize(&w, &h);
+ return wxSize(w, h);
+ }
+
+ virtual void DoGetSizeMM(int* width, int* height) const = 0;
+
+ virtual int GetDepth() const = 0;
+ virtual wxSize GetPPI() const = 0;
+
+ // Right-To-Left (RTL) modes
+
+ virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir)) { }
+ virtual wxLayoutDirection GetLayoutDirection() const { return wxLayout_Default; }
+
+ // page and document
+
+ virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; }
+ virtual void EndDoc() { }
+
+ virtual void StartPage() { }
+ virtual void EndPage() { }
+
+ // flushing the content of this dc immediately eg onto screen
+ virtual void Flush() { }
+
+ // bounding box
+
+ virtual void CalcBoundingBox(wxCoord x, wxCoord y)
+ {
+ if ( m_isBBoxValid )
+ {
+ if ( x < m_minX ) m_minX = x;
+ if ( y < m_minY ) m_minY = y;
+ if ( x > m_maxX ) m_maxX = x;
+ if ( y > m_maxY ) m_maxY = y;
+ }
+ else
+ {
+ m_isBBoxValid = true;
+
+ m_minX = x;
+ m_minY = y;
+ m_maxX = x;
+ m_maxY = y;
+ }
+ }
+ void ResetBoundingBox()
+ {
+ m_isBBoxValid = false;
+
+ m_minX = m_maxX = m_minY = m_maxY = 0;
+ }
+
+ wxCoord MinX() const { return m_minX; }
+ wxCoord MaxX() const { return m_maxX; }
+ wxCoord MinY() const { return m_minY; }
+ wxCoord MaxY() const { return m_maxY; }
+
+ // setters and getters
+
+ virtual void SetFont(const wxFont& font) = 0;
+ virtual const wxFont& GetFont() const { return m_font; }
+
+ virtual void SetPen(const wxPen& pen) = 0;
+ virtual const wxPen& GetPen() const { return m_pen; }
+
+ virtual void SetBrush(const wxBrush& brush) = 0;
+ virtual const wxBrush& GetBrush() const { return m_brush; }
+
+ virtual void SetBackground(const wxBrush& brush) = 0;
+ virtual const wxBrush& GetBackground() const { return m_backgroundBrush; }
+
+ virtual void SetBackgroundMode(int mode) = 0;
+ virtual int GetBackgroundMode() const { return m_backgroundMode; }
+
+ virtual void SetTextForeground(const wxColour& colour)
+ { m_textForegroundColour = colour; }
+ virtual const wxColour& GetTextForeground() const
+ { return m_textForegroundColour; }
+
+ virtual void SetTextBackground(const wxColour& colour)
+ { m_textBackgroundColour = colour; }
+ virtual const wxColour& GetTextBackground() const
+ { return m_textBackgroundColour; }
+
+#if wxUSE_PALETTE
+ virtual void SetPalette(const wxPalette& palette) = 0;
+#endif // wxUSE_PALETTE
+
+ // inherit the DC attributes (font and colours) from the given window
+ //
+ // this is called automatically when a window, client or paint DC is
+ // created
+ virtual void InheritAttributes(wxWindow *win);
+
+
+ // logical functions
+
+ virtual void SetLogicalFunction(wxRasterOperationMode function) = 0;
+ virtual wxRasterOperationMode GetLogicalFunction() const
+ { return m_logicalFunction; }
+
+ // text measurement
+
+ virtual wxCoord GetCharHeight() const = 0;
+ virtual wxCoord GetCharWidth() const = 0;
+
+ // The derived classes should really override DoGetFontMetrics() to return
+ // the correct values in the future but for now provide a default
+ // implementation in terms of DoGetTextExtent() to avoid breaking the
+ // compilation of all other ports as wxMSW is the only one to implement it.
+ virtual void DoGetFontMetrics(int *height,
+ int *ascent,
+ int *descent,
+ int *internalLeading,
+ int *externalLeading,
+ int *averageWidth) const;
+
+ virtual void DoGetTextExtent(const wxString& string,
+ wxCoord *x, wxCoord *y,
+ wxCoord *descent = NULL,
+ wxCoord *externalLeading = NULL,
+ const wxFont *theFont = NULL) const = 0;
+ virtual void GetMultiLineTextExtent(const wxString& string,
+ wxCoord *width,
+ wxCoord *height,
+ wxCoord *heightLine = NULL,
+ const wxFont *font = NULL) const;
+ virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
+
+ // clearing
+
+ virtual void Clear() = 0;
+
+ // clipping
+
+ virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
+ wxCoord width, wxCoord height) = 0;
+
+ // NB: this function works with device coordinates, not the logical ones!
+ virtual void DoSetDeviceClippingRegion(const wxRegion& region) = 0;
+
+ virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
+ wxCoord *w, wxCoord *h) const
+ {
+ if ( x )
+ *x = m_clipX1;
+ if ( y )
+ *y = m_clipY1;
+ if ( w )
+ *w = m_clipX2 - m_clipX1;
+ if ( h )
+ *h = m_clipY2 - m_clipY1;
+ }
+
+ virtual void DestroyClippingRegion() { ResetClipping(); }
+
+
+ // coordinates conversions and transforms
+
+ virtual wxCoord DeviceToLogicalX(wxCoord x) const;
+ virtual wxCoord DeviceToLogicalY(wxCoord y) const;
+ virtual wxCoord DeviceToLogicalXRel(wxCoord x) const;
+ virtual wxCoord DeviceToLogicalYRel(wxCoord y) const;
+ virtual wxCoord LogicalToDeviceX(wxCoord x) const;
+ virtual wxCoord LogicalToDeviceY(wxCoord y) const;
+ virtual wxCoord LogicalToDeviceXRel(wxCoord x) const;
+ virtual wxCoord LogicalToDeviceYRel(wxCoord y) const;
+
+ virtual void SetMapMode(wxMappingMode mode);
+ virtual wxMappingMode GetMapMode() const { return m_mappingMode; }
+
+ virtual void SetUserScale(double x, double y);
+ virtual void GetUserScale(double *x, double *y) const
+ {
+ if ( x ) *x = m_userScaleX;
+ if ( y ) *y = m_userScaleY;
+ }
+
+ virtual void SetLogicalScale(double x, double y);
+ virtual void GetLogicalScale(double *x, double *y) const
+ {
+ if ( x ) *x = m_logicalScaleX;
+ if ( y ) *y = m_logicalScaleY;
+ }
+
+ virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
+ virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
+ {
+ if ( x ) *x = m_logicalOriginX;
+ if ( y ) *y = m_logicalOriginY;
+ }
+
+ virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
+ virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
+ {
+ if ( x ) *x = m_deviceOriginX;
+ if ( y ) *y = m_deviceOriginY;
+ }
+
+#if wxUSE_DC_TRANSFORM_MATRIX
+ // Transform matrix support is not available in most ports right now
+ // (currently only wxMSW provides it) so do nothing in these methods by
+ // default.
+ virtual bool CanUseTransformMatrix() const
+ { return false; }
+ virtual bool SetTransformMatrix(const wxAffineMatrix2D& WXUNUSED(matrix))
+ { return false; }
+ virtual wxAffineMatrix2D GetTransformMatrix() const
+ { return wxAffineMatrix2D(); }
+ virtual void ResetTransformMatrix()
+ { }
+#endif // wxUSE_DC_TRANSFORM_MATRIX
+
+ virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y );
+
+ virtual void ComputeScaleAndOrigin();
+
+ // this needs to overidden if the axis is inverted
+ virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
+
+#ifdef __WXMSW__
+ // Native Windows functions using the underlying HDC don't honour GDI+
+ // transformations which may be applied to it. Using this function we can
+ // transform the coordinates manually before passing them to such functions
+ // (as in e.g. wxRendererMSW code). It doesn't do anything if this is not a
+ // wxGCDC.
+ virtual wxRect MSWApplyGDIPlusTransform(const wxRect& r) const
+ {
+ return r;
+ }
+#endif // __WXMSW__
+
+
+ // ---------------------------------------------------------
+ // the actual drawing API
+
+ virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
+ wxFloodFillStyle style = wxFLOOD_SURFACE) = 0;
+
+ virtual void DoGradientFillLinear(const wxRect& rect,
+ const wxColour& initialColour,
+ const wxColour& destColour,
+ wxDirection nDirection = wxEAST);
+
+ virtual void DoGradientFillConcentric(const wxRect& rect,
+ const wxColour& initialColour,
+ const wxColour& destColour,
+ const wxPoint& circleCenter);
+
+ virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
+
+ virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
+ virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
+
+ virtual void DoDrawArc(wxCoord x1, wxCoord y1,
+ wxCoord x2, wxCoord y2,
+ wxCoord xc, wxCoord yc) = 0;
+ virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
+ wxCoord width, wxCoord height);
+ virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
+ double sa, double ea) = 0;
+
+ virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
+ virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
+ wxCoord width, wxCoord height,
+ double radius) = 0;
+ virtual void DoDrawEllipse(wxCoord x, wxCoord y,
+ wxCoord width, wxCoord height) = 0;
+
+ virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
+
+ virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
+ virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
+ bool useMask = false) = 0;
+
+ virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
+ virtual void DoDrawRotatedText(const wxString& text,
+ wxCoord x, wxCoord y, double angle) = 0;
+
+ virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
+ wxCoord width, wxCoord height,
+ wxDC *source,
+ wxCoord xsrc, wxCoord ysrc,
+ wxRasterOperationMode rop = wxCOPY,
+ bool useMask = false,
+ wxCoord xsrcMask = wxDefaultCoord,
+ wxCoord ysrcMask = wxDefaultCoord) = 0;
+
+ virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
+ wxCoord dstWidth, wxCoord dstHeight,
+ wxDC *source,
+ wxCoord xsrc, wxCoord ysrc,
+ wxCoord srcWidth, wxCoord srcHeight,
+ wxRasterOperationMode rop = wxCOPY,
+ bool useMask = false,
+ wxCoord xsrcMask = wxDefaultCoord,
+ wxCoord ysrcMask = wxDefaultCoord);
+
+ virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const
+ { return wxNullBitmap; }
+
+
+ virtual void DoDrawLines(int n, wxPoint points[],
+ wxCoord xoffset, wxCoord yoffset ) = 0;
+ virtual void DrawLines(const wxPointList *list,
+ wxCoord xoffset, wxCoord yoffset );
+
+ virtual void DoDrawPolygon(int n, wxPoint points[],
+ wxCoord xoffset, wxCoord yoffset,
+ wxPolygonFillMode fillStyle = wxODDEVEN_RULE) = 0;
+ virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
+ wxCoord xoffset, wxCoord yoffset,
+ wxPolygonFillMode fillStyle);
+ void DrawPolygon(const wxPointList *list,
+ wxCoord xoffset, wxCoord yoffset,
+ wxPolygonFillMode fillStyle );
+
+
+#if wxUSE_SPLINES
+ void DrawSpline(wxCoord x1, wxCoord y1,
+ wxCoord x2, wxCoord y2,
+ wxCoord x3, wxCoord y3);
+ void DrawSpline(int n, wxPoint points[]);
+ void DrawSpline(const wxPointList *points) { DoDrawSpline(points); }
+
+ virtual void DoDrawSpline(const wxPointList *points);
+#endif
+
+ // ---------------------------------------------------------
+ // wxMemoryDC Impl API