metafile.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: metafile.h
  3. // Purpose: interface of wxMetafileDC
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxMetafileDC
  9. This is a type of device context that allows a metafile object to be
  10. created (Windows only), and has most of the characteristics of a normal
  11. @b wxDC.
  12. The wxMetafileDC::Close member must be called after drawing into the
  13. device context, to return a metafile. The only purpose for this at
  14. present is to allow the metafile to be copied to the clipboard
  15. (see wxMetafile).
  16. Adding metafile capability to an application should be easy if you
  17. already write to a wxDC; simply pass the wxMetafileDC to your drawing
  18. function instead. You may wish to conditionally compile this code so it
  19. is not compiled under X (although no harm will result if you leave it in).
  20. Note that a metafile saved to disk is in standard Windows metafile format,
  21. and cannot be imported into most applications. To make it importable,
  22. call the function ::wxMakeMetafilePlaceable after closing your disk-based
  23. metafile device context.
  24. @library{wxcore}
  25. @category{dc}
  26. @see wxMetafile, wxDC
  27. */
  28. class wxMetafileDC : public wxDC
  29. {
  30. public:
  31. /**
  32. Constructor.
  33. If no filename is passed, the metafile is created in memory.
  34. */
  35. wxMetafileDC(const wxString& filename = wxEmptyString);
  36. /**
  37. Destructor.
  38. */
  39. ~wxMetafileDC();
  40. /**
  41. This must be called after the device context is finished with.
  42. A metafile is returned, and ownership of it passes to the calling
  43. application (so it should be destroyed explicitly).
  44. */
  45. wxMetafile* Close();
  46. };
  47. /**
  48. @class wxMetafile
  49. A @b wxMetafile represents the MS Windows metafile object, so metafile
  50. operations have no effect in X. In wxWidgets, only sufficient functionality
  51. has been provided for copying a graphic to the clipboard; this may be extended
  52. in a future version.
  53. Presently, the only way of creating a metafile is to use a wxMetafileDC.
  54. @onlyfor{wxmsw}
  55. @library{wxcore}
  56. @category{gdi}
  57. @see wxMetafileDC
  58. */
  59. class wxMetafile : public wxObject
  60. {
  61. public:
  62. /**
  63. Constructor.
  64. If a filename is given, the Windows disk metafile is read in.
  65. Check whether this was performed successfully by using the IsOk() member.
  66. */
  67. wxMetafile(const wxString& filename = wxEmptyString);
  68. /**
  69. Destructor.
  70. See @ref overview_refcount_destruct for more info.
  71. */
  72. ~wxMetafile();
  73. /**
  74. Returns @true if the metafile is valid.
  75. */
  76. bool IsOk();
  77. /**
  78. Plays the metafile into the given device context, returning
  79. @true if successful.
  80. */
  81. bool Play(wxDC* dc);
  82. /**
  83. Passes the metafile data to the clipboard. The metafile can no longer be
  84. used for anything, but the wxMetafile object must still be destroyed by
  85. the application.
  86. Below is a example of metafile, metafile device context and clipboard use
  87. from the @c hello.cpp example. Note the way the metafile dimensions
  88. are passed to the clipboard, making use of the device context's ability
  89. to keep track of the maximum extent of drawing commands.
  90. @code
  91. wxMetafileDC dc;
  92. if (dc.IsOk())
  93. {
  94. Draw(dc, false);
  95. wxMetafile *mf = dc.Close();
  96. if (mf)
  97. {
  98. bool success = mf->SetClipboard((int)(dc.MaxX() + 10), (int)(dc.MaxY() + 10));
  99. delete mf;
  100. }
  101. }
  102. @endcode
  103. */
  104. bool SetClipboard(int width = 0, int height = 0);
  105. };
  106. // ============================================================================
  107. // Global functions/macros
  108. // ============================================================================
  109. /** @addtogroup group_funcmacro_gdi */
  110. //@{
  111. /**
  112. Given a filename for an existing, valid metafile (as constructed using
  113. wxMetafileDC) makes it into a placeable metafile by prepending a header
  114. containing the given bounding box. The bounding box may be obtained from a
  115. device context after drawing into it, using the functions wxDC::MinX(),
  116. wxDC::MinY(), wxDC::MaxX() and wxDC::MaxY().
  117. In addition to adding the placeable metafile header, this function adds the
  118. equivalent of the following code to the start of the metafile data:
  119. @code
  120. SetMapMode(dc, MM_ANISOTROPIC);
  121. SetWindowOrg(dc, minX, minY);
  122. SetWindowExt(dc, maxX - minX, maxY - minY);
  123. @endcode
  124. This simulates the wxMM_TEXT mapping mode, which wxWidgets assumes.
  125. Placeable metafiles may be imported by many Windows applications, and can
  126. be used in RTF (Rich Text Format) files.
  127. @a scale allows the specification of scale for the metafile.
  128. This function is only available under Windows.
  129. @header{wx/metafile.h}
  130. */
  131. bool wxMakeMetafilePlaceable(const wxString& filename,
  132. int minX, int minY,
  133. int maxX, int maxY,
  134. float scale = 1.0);
  135. //@}