metafile.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/metafile.h
  3. // Purpose: wxMetaFile, wxMetaFileDC and wxMetaFileDataObject classes
  4. // Author: Julian Smart
  5. // Modified by: VZ 07.01.00: implemented wxMetaFileDataObject
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_METAFIILE_H_
  11. #define _WX_METAFIILE_H_
  12. #include "wx/dc.h"
  13. #include "wx/gdiobj.h"
  14. #if wxUSE_DRAG_AND_DROP
  15. #include "wx/dataobj.h"
  16. #endif
  17. // ----------------------------------------------------------------------------
  18. // Metafile and metafile device context classes
  19. // ----------------------------------------------------------------------------
  20. class WXDLLIMPEXP_FWD_CORE wxMetafile;
  21. class WXDLLIMPEXP_CORE wxMetafileRefData: public wxGDIRefData
  22. {
  23. public:
  24. wxMetafileRefData();
  25. virtual ~wxMetafileRefData();
  26. virtual bool IsOk() const { return m_metafile != 0; }
  27. public:
  28. WXHANDLE m_metafile;
  29. int m_windowsMappingMode;
  30. int m_width, m_height;
  31. friend class WXDLLIMPEXP_FWD_CORE wxMetafile;
  32. };
  33. #define M_METAFILEDATA ((wxMetafileRefData *)m_refData)
  34. class WXDLLIMPEXP_CORE wxMetafile: public wxGDIObject
  35. {
  36. public:
  37. wxMetafile(const wxString& file = wxEmptyString);
  38. virtual ~wxMetafile();
  39. // After this is called, the metafile cannot be used for anything
  40. // since it is now owned by the clipboard.
  41. virtual bool SetClipboard(int width = 0, int height = 0);
  42. virtual bool Play(wxDC *dc);
  43. // set/get the size of metafile for clipboard operations
  44. wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); }
  45. int GetWidth() const { return M_METAFILEDATA->m_width; }
  46. int GetHeight() const { return M_METAFILEDATA->m_height; }
  47. void SetWidth(int width) { M_METAFILEDATA->m_width = width; }
  48. void SetHeight(int height) { M_METAFILEDATA->m_height = height; }
  49. // Implementation
  50. WXHANDLE GetHMETAFILE() const { return M_METAFILEDATA->m_metafile; }
  51. void SetHMETAFILE(WXHANDLE mf) ;
  52. int GetWindowsMappingMode() const { 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. private:
  58. DECLARE_DYNAMIC_CLASS(wxMetafile)
  59. };
  60. class WXDLLIMPEXP_CORE wxMetafileDCImpl: public wxMSWDCImpl
  61. {
  62. public:
  63. wxMetafileDCImpl(wxDC *owner, const wxString& file = wxEmptyString);
  64. wxMetafileDCImpl(wxDC *owner, const wxString& file,
  65. int xext, int yext, int xorg, int yorg);
  66. virtual ~wxMetafileDCImpl();
  67. virtual wxMetafile *Close();
  68. virtual void SetMapMode(wxMappingMode mode);
  69. virtual void DoGetTextExtent(const wxString& string,
  70. wxCoord *x, wxCoord *y,
  71. wxCoord *descent = NULL,
  72. wxCoord *externalLeading = NULL,
  73. const wxFont *theFont = NULL) const;
  74. // Implementation
  75. wxMetafile *GetMetaFile() const { return m_metaFile; }
  76. void SetMetaFile(wxMetafile *mf) { m_metaFile = mf; }
  77. int GetWindowsMappingMode() const { return m_windowsMappingMode; }
  78. void SetWindowsMappingMode(int mm) { m_windowsMappingMode = mm; }
  79. protected:
  80. virtual void DoGetSize(int *width, int *height) const;
  81. int m_windowsMappingMode;
  82. wxMetafile* m_metaFile;
  83. private:
  84. DECLARE_CLASS(wxMetafileDCImpl)
  85. wxDECLARE_NO_COPY_CLASS(wxMetafileDCImpl);
  86. };
  87. class WXDLLIMPEXP_CORE wxMetafileDC: public wxDC
  88. {
  89. public:
  90. // Don't supply origin and extent
  91. // Supply them to wxMakeMetaFilePlaceable instead.
  92. wxMetafileDC(const wxString& file)
  93. : wxDC(new wxMetafileDCImpl( this, file ))
  94. { }
  95. // Supply origin and extent (recommended).
  96. // Then don't need to supply them to wxMakeMetaFilePlaceable.
  97. wxMetafileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
  98. : wxDC(new wxMetafileDCImpl( this, file, xext, yext, xorg, yorg ))
  99. { }
  100. wxMetafile *GetMetafile() const
  101. { return ((wxMetafileDCImpl*)m_pimpl)->GetMetaFile(); }
  102. wxMetafile *Close()
  103. { return ((wxMetafileDCImpl*)m_pimpl)->Close(); }
  104. private:
  105. DECLARE_CLASS(wxMetafileDC)
  106. wxDECLARE_NO_COPY_CLASS(wxMetafileDC);
  107. };
  108. /*
  109. * Pass filename of existing non-placeable metafile, and bounding box.
  110. * Adds a placeable metafile header, sets the mapping mode to anisotropic,
  111. * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
  112. *
  113. */
  114. // No origin or extent
  115. bool WXDLLIMPEXP_CORE wxMakeMetafilePlaceable(const wxString& filename, float scale = 1.0);
  116. // Optional origin and extent
  117. bool WXDLLIMPEXP_CORE wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale = 1.0, bool useOriginAndExtent = true);
  118. // ----------------------------------------------------------------------------
  119. // wxMetafileDataObject is a specialization of wxDataObject for metafile data
  120. // ----------------------------------------------------------------------------
  121. #if wxUSE_DRAG_AND_DROP
  122. class WXDLLIMPEXP_CORE wxMetafileDataObject : public wxDataObjectSimple
  123. {
  124. public:
  125. // ctors
  126. wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE)
  127. { }
  128. wxMetafileDataObject(const wxMetafile& metafile)
  129. : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { }
  130. // virtual functions which you may override if you want to provide data on
  131. // demand only - otherwise, the trivial default versions will be used
  132. virtual void SetMetafile(const wxMetafile& metafile)
  133. { m_metafile = metafile; }
  134. virtual wxMetafile GetMetafile() const
  135. { return m_metafile; }
  136. // implement base class pure virtuals
  137. virtual size_t GetDataSize() const;
  138. virtual bool GetDataHere(void *buf) const;
  139. virtual bool SetData(size_t len, const void *buf);
  140. protected:
  141. wxMetafile m_metafile;
  142. };
  143. #endif // wxUSE_DRAG_AND_DROP
  144. #endif
  145. // _WX_METAFIILE_H_