enhmeta.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/enhmeta.h
  3. // Purpose: wxEnhMetaFile class for Win32
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 13.01.00
  7. // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_ENHMETA_H_
  11. #define _WX_MSW_ENHMETA_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. // wxEnhMetaFile: encapsulation of Win32 HENHMETAFILE
  19. // ----------------------------------------------------------------------------
  20. class WXDLLIMPEXP_CORE wxEnhMetaFile : public wxGDIObject
  21. {
  22. public:
  23. wxEnhMetaFile(const wxString& file = wxEmptyString) : m_filename(file)
  24. { Init(); }
  25. wxEnhMetaFile(const wxEnhMetaFile& metafile) : wxGDIObject()
  26. { Init(); Assign(metafile); }
  27. wxEnhMetaFile& operator=(const wxEnhMetaFile& metafile)
  28. { Free(); Assign(metafile); return *this; }
  29. virtual ~wxEnhMetaFile()
  30. { Free(); }
  31. // display the picture stored in the metafile on the given DC
  32. bool Play(wxDC *dc, wxRect *rectBound = NULL);
  33. // accessors
  34. virtual bool IsOk() const { return m_hMF != 0; }
  35. wxSize GetSize() const;
  36. int GetWidth() const { return GetSize().x; }
  37. int GetHeight() const { return GetSize().y; }
  38. const wxString& GetFileName() const { return m_filename; }
  39. // copy the metafile to the clipboard: the width and height parameters are
  40. // for backwards compatibility (with wxMetaFile) only, they are ignored by
  41. // this method
  42. bool SetClipboard(int width = 0, int height = 0);
  43. // implementation
  44. WXHANDLE GetHENHMETAFILE() const { return m_hMF; }
  45. void SetHENHMETAFILE(WXHANDLE hMF) { Free(); m_hMF = hMF; }
  46. protected:
  47. void Init();
  48. void Free();
  49. void Assign(const wxEnhMetaFile& mf);
  50. // we don't use these functions (but probably should) but have to implement
  51. // them as they're pure virtual in the base class
  52. virtual wxGDIRefData *CreateGDIRefData() const;
  53. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  54. private:
  55. wxString m_filename;
  56. WXHANDLE m_hMF;
  57. DECLARE_DYNAMIC_CLASS(wxEnhMetaFile)
  58. };
  59. // ----------------------------------------------------------------------------
  60. // wxEnhMetaFileDC: allows to create a wxEnhMetaFile
  61. // ----------------------------------------------------------------------------
  62. class WXDLLIMPEXP_CORE wxEnhMetaFileDC : public wxDC
  63. {
  64. public:
  65. // the ctor parameters specify the filename (empty for memory metafiles),
  66. // the metafile picture size and the optional description/comment
  67. wxEnhMetaFileDC(const wxString& filename = wxEmptyString,
  68. int width = 0, int height = 0,
  69. const wxString& description = wxEmptyString);
  70. // as above, but takes reference DC as first argument to take resolution,
  71. // size, font metrics etc. from
  72. wxEXPLICIT
  73. wxEnhMetaFileDC(const wxDC& referenceDC,
  74. const wxString& filename = wxEmptyString,
  75. int width = 0, int height = 0,
  76. const wxString& description = wxEmptyString);
  77. // obtain a pointer to the new metafile (caller should delete it)
  78. wxEnhMetaFile *Close();
  79. private:
  80. DECLARE_DYNAMIC_CLASS_NO_COPY(wxEnhMetaFileDC)
  81. };
  82. #if wxUSE_DRAG_AND_DROP
  83. // ----------------------------------------------------------------------------
  84. // wxEnhMetaFileDataObject is a specialization of wxDataObject for enh metafile
  85. // ----------------------------------------------------------------------------
  86. // notice that we want to support both CF_METAFILEPICT and CF_ENHMETAFILE and
  87. // so we derive from wxDataObject and not from wxDataObjectSimple
  88. class WXDLLIMPEXP_CORE wxEnhMetaFileDataObject : public wxDataObject
  89. {
  90. public:
  91. // ctors
  92. wxEnhMetaFileDataObject() { }
  93. wxEnhMetaFileDataObject(const wxEnhMetaFile& metafile)
  94. : m_metafile(metafile) { }
  95. // virtual functions which you may override if you want to provide data on
  96. // demand only - otherwise, the trivial default versions will be used
  97. virtual void SetMetafile(const wxEnhMetaFile& metafile)
  98. { m_metafile = metafile; }
  99. virtual wxEnhMetaFile GetMetafile() const
  100. { return m_metafile; }
  101. // implement base class pure virtuals
  102. virtual wxDataFormat GetPreferredFormat(Direction dir) const;
  103. virtual size_t GetFormatCount(Direction dir) const;
  104. virtual void GetAllFormats(wxDataFormat *formats, Direction dir) const;
  105. virtual size_t GetDataSize(const wxDataFormat& format) const;
  106. virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
  107. virtual bool SetData(const wxDataFormat& format, size_t len,
  108. const void *buf);
  109. protected:
  110. wxEnhMetaFile m_metafile;
  111. wxDECLARE_NO_COPY_CLASS(wxEnhMetaFileDataObject);
  112. };
  113. // ----------------------------------------------------------------------------
  114. // wxEnhMetaFileSimpleDataObject does derive from wxDataObjectSimple which
  115. // makes it more convenient to use (it can be used with wxDataObjectComposite)
  116. // at the price of not supoprting any more CF_METAFILEPICT but only
  117. // CF_ENHMETAFILE
  118. // ----------------------------------------------------------------------------
  119. class WXDLLIMPEXP_CORE wxEnhMetaFileSimpleDataObject : public wxDataObjectSimple
  120. {
  121. public:
  122. // ctors
  123. wxEnhMetaFileSimpleDataObject() : wxDataObjectSimple(wxDF_ENHMETAFILE) { }
  124. wxEnhMetaFileSimpleDataObject(const wxEnhMetaFile& metafile)
  125. : wxDataObjectSimple(wxDF_ENHMETAFILE), m_metafile(metafile) { }
  126. // virtual functions which you may override if you want to provide data on
  127. // demand only - otherwise, the trivial default versions will be used
  128. virtual void SetEnhMetafile(const wxEnhMetaFile& metafile)
  129. { m_metafile = metafile; }
  130. virtual wxEnhMetaFile GetEnhMetafile() const
  131. { return m_metafile; }
  132. // implement base class pure virtuals
  133. virtual size_t GetDataSize() const;
  134. virtual bool GetDataHere(void *buf) const;
  135. virtual bool SetData(size_t len, const void *buf);
  136. virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const
  137. { return GetDataSize(); }
  138. virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
  139. void *buf) const
  140. { return GetDataHere(buf); }
  141. virtual bool SetData(const wxDataFormat& WXUNUSED(format),
  142. size_t len, const void *buf)
  143. { return SetData(len, buf); }
  144. protected:
  145. wxEnhMetaFile m_metafile;
  146. wxDECLARE_NO_COPY_CLASS(wxEnhMetaFileSimpleDataObject);
  147. };
  148. #endif // wxUSE_DRAG_AND_DROP
  149. #endif // _WX_MSW_ENHMETA_H_