metafile.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/os2/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: David Webster
  7. // Modified by:
  8. // Created: 10/10/99
  9. // Copyright: (c) David Webster
  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. #include "wx/os2/dc.h"
  17. #if wxUSE_DRAG_AND_DROP
  18. #include "wx/dataobj.h"
  19. #endif
  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 WXDLLIMPEXP_CORE wxMetafileRefData: public wxGDIRefData
  28. {
  29. friend class WXDLLIMPEXP_FWD_CORE wxMetafile;
  30. public:
  31. wxMetafileRefData(void);
  32. virtual ~wxMetafileRefData(void);
  33. virtual bool IsOk() const { return m_metafile != 0; }
  34. public:
  35. WXHANDLE m_metafile;
  36. int m_windowsMappingMode;
  37. };
  38. #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
  39. class WXDLLIMPEXP_CORE wxMetafile: public wxGDIObject
  40. {
  41. DECLARE_DYNAMIC_CLASS(wxMetafile)
  42. public:
  43. wxMetafile(const wxString& file = wxEmptyString);
  44. virtual ~wxMetafile(void);
  45. // After this is called, the metafile cannot be used for anything
  46. // since it is now owned by the clipboard.
  47. virtual bool SetClipboard(int width = 0, int height = 0);
  48. virtual bool Play(wxDC *dc);
  49. // Implementation
  50. inline WXHANDLE GetHMETAFILE(void) { return M_METAFILEDATA->m_metafile; }
  51. void SetHMETAFILE(WXHANDLE mf) ;
  52. inline int GetWindowsMappingMode(void) { return M_METAFILEDATA->m_windowsMappingMode; }
  53. void SetWindowsMappingMode(int mm);
  54. protected:
  55. virtual wxGDIRefData *CreateGDIRefData() const;
  56. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  57. };
  58. class WXDLLIMPEXP_CORE wxMetafileDCImpl: public wxPMDCImpl
  59. {
  60. public:
  61. wxMetafileDCImpl(wxDC *owner, const wxString& file = wxEmptyString);
  62. wxMetafileDCImpl(wxDC *owner, const wxString& file,
  63. int xext, int yext, int xorg, int yorg);
  64. virtual ~wxMetafileDCImpl();
  65. virtual wxMetafile *Close();
  66. virtual void SetMapMode(wxMappingMode mode);
  67. virtual void DoGetTextExtent(const wxString& string,
  68. wxCoord *x, wxCoord *y,
  69. wxCoord *descent = NULL,
  70. wxCoord *externalLeading = NULL,
  71. const wxFont *theFont = NULL) const;
  72. // Implementation
  73. wxMetafile *GetMetaFile() const { return m_metaFile; }
  74. void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
  75. int GetWindowsMappingMode() const { return m_windowsMappingMode; }
  76. void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
  77. protected:
  78. virtual void DoGetSize(int *width, int *height) const;
  79. int m_windowsMappingMode;
  80. wxMetafile* m_metaFile;
  81. private:
  82. DECLARE_CLASS(wxMetafileDCImpl)
  83. wxDECLARE_NO_COPY_CLASS(wxMetafileDCImpl);
  84. };
  85. class WXDLLIMPEXP_CORE wxMetafileDC: public wxDC
  86. {
  87. public:
  88. // Don't supply origin and extent
  89. // Supply them to wxMakeMetaFilePlaceable instead.
  90. wxMetafileDC(const wxString& file = wxEmptyString)
  91. :wxDC(new wxMetafileDCImpl( this, file ))
  92. { }
  93. // Supply origin and extent (recommended).
  94. // Then don't need to supply them to wxMakeMetaFilePlaceable.
  95. wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
  96. : wxDC(new wxMetafileDCImpl( this, file, xext, yext, xorg, yorg ))
  97. { }
  98. wxMetafile *GetMetafile() const
  99. { return ((wxMetafileDCImpl*)m_pimpl)->GetMetaFile(); }
  100. virtual ~wxMetafileDC(void)
  101. { delete m_pimpl; }
  102. // Should be called at end of drawing
  103. virtual wxMetafile *Close(void)
  104. { return ((wxMetafileDCImpl*)m_pimpl)->Close(); }
  105. inline void SetMetaFile(wxMetafile *mf)
  106. { ((wxMetafileDCImpl*)m_pimpl)->SetMetaFile(mf); }
  107. private:
  108. DECLARE_CLASS(wxMetafileDC)
  109. wxDECLARE_NO_COPY_CLASS(wxMetafileDC);
  110. };
  111. /*
  112. * Pass filename of existing non-placeable metafile, and bounding box.
  113. * Adds a placeable metafile header, sets the mapping mode to anisotropic,
  114. * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
  115. *
  116. */
  117. // No origin or extent
  118. #define wxMakeMetaFilePlaceable wxMakeMetafilePlaceable
  119. bool WXDLLIMPEXP_CORE wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
  120. // Optional origin and extent
  121. bool WXDLLIMPEXP_CORE wxMakeMetaFilePlaceable( const wxString& filename
  122. ,int x1
  123. ,int y1
  124. ,int x2
  125. ,int y2
  126. ,float scale = 1.0
  127. ,bool useOriginAndExtent = true
  128. );
  129. // ----------------------------------------------------------------------------
  130. // wxMetafileDataObject is a specialization of wxDataObject for metafile data
  131. // ----------------------------------------------------------------------------
  132. // TODO: implement OLE side of things. At present, it's just for clipboard
  133. // use.
  134. #if wxUSE_DRAG_AND_DROP
  135. class WXDLLIMPEXP_CORE wxMetafileDataObject : public wxDataObject
  136. {
  137. public:
  138. // ctors
  139. wxMetafileDataObject() { m_width = 0; m_height = 0; }
  140. wxMetafileDataObject(const wxMetafile& metafile, int width = 0,int height = 0)
  141. :m_metafile(metafile)
  142. ,m_width(width)
  143. ,m_height(height) { }
  144. void SetMetafile(const wxMetafile& metafile, int w = 0, int h = 0)
  145. { m_metafile = metafile; m_width = w; m_height = h; }
  146. wxMetafile GetMetafile() const { return m_metafile; }
  147. int GetWidth() const { return m_width; }
  148. int GetHeight() const { return m_height; }
  149. virtual wxDataFormat GetFormat() const { return wxDF_METAFILE; }
  150. /* ??
  151. // implement base class pure virtuals
  152. virtual wxDataFormat GetPreferredFormat() const
  153. { return (wxDataFormat) wxDataObject::Text; }
  154. virtual bool IsSupportedFormat(wxDataFormat format) const
  155. { return format == wxDataObject::Text || format == wxDataObject::Locale; }
  156. virtual size_t GetDataSize() const
  157. { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
  158. virtual void GetDataHere(void *pBuf) const
  159. { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
  160. */
  161. private:
  162. wxMetafile m_metafile;
  163. int m_width;
  164. int m_height;
  165. };
  166. #endif
  167. #endif
  168. // _WX_METAFIILE_H_