metafile.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/osx/metafile.h
  3. // Purpose: wxMetaFile, wxMetaFileDC classes.
  4. // This probably should be restricted to Windows platforms,
  5. // but if there is an equivalent on your platform, great.
  6. // Author: Stefan Csomor
  7. // Modified by:
  8. // Created: 1998-01-01
  9. // Copyright: (c) Stefan Csomor
  10. // Licence: wxWindows licence
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef _WX_METAFIILE_H_
  13. #define _WX_METAFIILE_H_
  14. #include "wx/dc.h"
  15. #include "wx/gdiobj.h"
  16. #if wxUSE_DATAOBJ
  17. #include "wx/dataobj.h"
  18. #endif
  19. #include "wx/osx/dcclient.h"
  20. /*
  21. * Metafile and metafile device context classes
  22. *
  23. */
  24. #define wxMetaFile wxMetafile
  25. #define wxMetaFileDC wxMetafileDC
  26. class WXDLLIMPEXP_FWD_CORE wxMetafile;
  27. class wxMetafileRefData ;
  28. #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
  29. class WXDLLIMPEXP_CORE wxMetafile : public wxGDIObject
  30. {
  31. public:
  32. wxMetafile(const wxString& file = wxEmptyString);
  33. virtual ~wxMetafile(void);
  34. // After this is called, the metafile cannot be used for anything
  35. // since it is now owned by the clipboard.
  36. virtual bool SetClipboard(int width = 0, int height = 0);
  37. virtual bool Play(wxDC *dc);
  38. wxSize GetSize() const;
  39. int GetWidth() const { return GetSize().x; }
  40. int GetHeight() const { return GetSize().y; }
  41. // Implementation
  42. WXHMETAFILE GetHMETAFILE() const ;
  43. void SetHMETAFILE(WXHMETAFILE mf) ;
  44. protected:
  45. virtual wxGDIRefData *CreateGDIRefData() const;
  46. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  47. DECLARE_DYNAMIC_CLASS(wxMetafile)
  48. };
  49. class WXDLLIMPEXP_CORE wxMetafileDCImpl: public wxGCDCImpl
  50. {
  51. public:
  52. wxMetafileDCImpl( wxDC *owner,
  53. const wxString& filename,
  54. int width, int height,
  55. const wxString& description );
  56. virtual ~wxMetafileDCImpl();
  57. // Should be called at end of drawing
  58. virtual wxMetafile *Close();
  59. // Implementation
  60. wxMetafile *GetMetaFile(void) const { return m_metaFile; }
  61. void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
  62. protected:
  63. virtual void DoGetSize(int *width, int *height) const;
  64. wxMetafile* m_metaFile;
  65. private:
  66. DECLARE_CLASS(wxMetafileDCImpl)
  67. wxDECLARE_NO_COPY_CLASS(wxMetafileDCImpl);
  68. };
  69. class WXDLLIMPEXP_CORE wxMetafileDC: public wxDC
  70. {
  71. public:
  72. // the ctor parameters specify the filename (empty for memory metafiles),
  73. // the metafile picture size and the optional description/comment
  74. wxMetafileDC( const wxString& filename = wxEmptyString,
  75. int width = 0, int height = 0,
  76. const wxString& description = wxEmptyString ) :
  77. wxDC( new wxMetafileDCImpl( this, filename, width, height, description) )
  78. { }
  79. wxMetafile *GetMetafile() const
  80. { return ((wxMetafileDCImpl*)m_pimpl)->GetMetaFile(); }
  81. wxMetafile *Close()
  82. { return ((wxMetafileDCImpl*)m_pimpl)->Close(); }
  83. private:
  84. DECLARE_CLASS(wxMetafileDC)
  85. wxDECLARE_NO_COPY_CLASS(wxMetafileDC);
  86. };
  87. /*
  88. * Pass filename of existing non-placeable metafile, and bounding box.
  89. * Adds a placeable metafile header, sets the mapping mode to anisotropic,
  90. * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
  91. *
  92. */
  93. // No origin or extent
  94. #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
  95. bool WXDLLIMPEXP_CORE wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
  96. // Optional origin and extent
  97. bool WXDLLIMPEXP_CORE wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = true);
  98. // ----------------------------------------------------------------------------
  99. // wxMetafileDataObject is a specialization of wxDataObject for metafile data
  100. // ----------------------------------------------------------------------------
  101. #if wxUSE_DATAOBJ
  102. class WXDLLIMPEXP_CORE wxMetafileDataObject : public wxDataObjectSimple
  103. {
  104. public:
  105. // ctors
  106. wxMetafileDataObject()
  107. : wxDataObjectSimple(wxDF_METAFILE) { }
  108. wxMetafileDataObject(const wxMetafile& metafile)
  109. : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { }
  110. // virtual functions which you may override if you want to provide data on
  111. // demand only - otherwise, the trivial default versions will be used
  112. virtual void SetMetafile(const wxMetafile& metafile)
  113. { m_metafile = metafile; }
  114. virtual wxMetafile GetMetafile() const
  115. { return m_metafile; }
  116. // implement base class pure virtuals
  117. virtual size_t GetDataSize() const;
  118. virtual bool GetDataHere(void *buf) const;
  119. virtual bool SetData(size_t len, const void *buf);
  120. virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const
  121. { return GetDataSize(); }
  122. virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
  123. void *buf) const
  124. { return GetDataHere(buf); }
  125. virtual bool SetData(const wxDataFormat& WXUNUSED(format),
  126. size_t len, const void *buf)
  127. { return SetData(len, buf); }
  128. protected:
  129. wxMetafile m_metafile;
  130. };
  131. #endif
  132. #endif
  133. // _WX_METAFIILE_H_