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