]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/metafile.cpp
67850103eea9fbd0737d7cfaf11f457f7325d0b4
[wxWidgets.git] / src / stubs / metafile.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: metafile.cpp
3 // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
4 // Author: AUTHOR
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "metafile.h"
14 #endif
15
16 #include "wx/metafile.h"
17 #include "wx/clipbrd.h"
18
19 extern bool wxClipboardIsOpen;
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxMetaFile, wxObject)
23 IMPLEMENT_ABSTRACT_CLASS(wxMetaFileDC, wxDC)
24 #endif
25
26 wxMetaFile::wxMetaFile(const wxString& file)
27 {
28 // TODO
29 }
30
31 wxMetaFile::~wxMetaFile()
32 {
33 // TODO
34 }
35
36 bool wxMetaFile::SetClipboard(int width, int height)
37 {
38 bool alreadyOpen=wxClipboardOpen();
39 if (!alreadyOpen)
40 {
41 wxOpenClipboard();
42 if (!wxEmptyClipboard()) return FALSE;
43 }
44 bool success = wxSetClipboardData(wxDF_METAFILE,this, width,height);
45 if (!alreadyOpen) wxCloseClipboard();
46 return (bool) success;
47 }
48
49 bool wxMetaFile::Play(wxDC *dc)
50 {
51 // TODO
52 return false;
53 }
54
55 /*
56 * Metafile device context
57 *
58 */
59
60 // Original constructor that does not takes origin and extent. If you use this,
61 // *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
62 wxMetaFileDC::wxMetaFileDC(const wxString& file)
63 {
64 // TODO
65 }
66
67 // New constructor that takes origin and extent. If you use this, don't
68 // give origin/extent arguments to wxMakeMetaFilePlaceable.
69 wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
70 {
71 // TODO
72 }
73
74 wxMetaFileDC::~wxMetaFileDC()
75 {
76 }
77
78 void wxMetaFileDC::GetTextExtent(const wxString& string, float *x, float *y,
79 float *descent, float *externalLeading, wxFont *theFont, bool use16bit)
80 {
81 // TODO
82 }
83
84 wxMetaFile *wxMetaFileDC::Close()
85 {
86 // TODO
87 return NULL;
88 }
89
90 void wxMetaFileDC::SetMapMode(int mode)
91 {
92 // TODO
93 }
94
95 #if 0
96
97 #ifdef __WIN32__
98 struct RECT32
99 {
100 short left;
101 short top;
102 short right;
103 short bottom;
104 };
105
106 struct mfPLACEABLEHEADER {
107 DWORD key;
108 short hmf;
109 RECT32 bbox;
110 WORD inch;
111 DWORD reserved;
112 WORD checksum;
113 };
114 #else
115 struct mfPLACEABLEHEADER {
116 DWORD key;
117 HANDLE hmf;
118 RECT bbox;
119 WORD inch;
120 DWORD reserved;
121 WORD checksum;
122 };
123 #endif
124
125 /*
126 * Pass filename of existing non-placeable metafile, and bounding box.
127 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
128 * and sets the window origin and extent to mimic the MM_TEXT mapping mode.
129 *
130 */
131
132 bool wxMakeMetaFilePlaceable(const wxString& filename, float scale)
133 {
134 return wxMakeMetaFilePlaceable(filename, 0, 0, 0, 0, scale, FALSE);
135 }
136
137 bool wxMakeMetaFilePlaceable(const wxString& filename, int x1, int y1, int x2, int y2, float scale, bool useOriginAndExtent)
138 {
139 // I'm not sure if this is the correct way of suggesting a scale
140 // to the client application, but it's the only way I can find.
141 int unitsPerInch = (int)(576/scale);
142
143 mfPLACEABLEHEADER header;
144 header.key = 0x9AC6CDD7L;
145 header.hmf = 0;
146 header.bbox.left = (int)(x1);
147 header.bbox.top = (int)(y1);
148 header.bbox.right = (int)(x2);
149 header.bbox.bottom = (int)(y2);
150 header.inch = unitsPerInch;
151 header.reserved = 0;
152
153 // Calculate checksum
154 WORD *p;
155 mfPLACEABLEHEADER *pMFHead = &header;
156 for (p =(WORD *)pMFHead,pMFHead -> checksum = 0;
157 p < (WORD *)&pMFHead ->checksum; ++p)
158 pMFHead ->checksum ^= *p;
159
160 FILE *fd = fopen((char *)(const char *)filename, "rb");
161 if (!fd) return FALSE;
162
163 char tempFileBuf[256];
164 wxGetTempFileName("mf", tempFileBuf);
165 FILE *fHandle = fopen(tempFileBuf, "wb");
166 if (!fHandle)
167 return FALSE;
168 fwrite((void *)&header, sizeof(unsigned char), sizeof(mfPLACEABLEHEADER), fHandle);
169
170 // Calculate origin and extent
171 int originX = x1;
172 int originY = y1;
173 int extentX = x2 - x1;
174 int extentY = (y2 - y1);
175
176 // Read metafile header and write
177 METAHEADER metaHeader;
178 fread((void *)&metaHeader, sizeof(unsigned char), sizeof(metaHeader), fd);
179
180 if (useOriginAndExtent)
181 metaHeader.mtSize += 15;
182 else
183 metaHeader.mtSize += 5;
184
185 fwrite((void *)&metaHeader, sizeof(unsigned char), sizeof(metaHeader), fHandle);
186
187 // Write SetMapMode, SetWindowOrigin and SetWindowExt records
188 char modeBuffer[8];
189 char originBuffer[10];
190 char extentBuffer[10];
191 METARECORD *modeRecord = (METARECORD *)&modeBuffer;
192
193 METARECORD *originRecord = (METARECORD *)&originBuffer;
194 METARECORD *extentRecord = (METARECORD *)&extentBuffer;
195
196 modeRecord->rdSize = 4;
197 modeRecord->rdFunction = META_SETMAPMODE;
198 modeRecord->rdParm[0] = MM_ANISOTROPIC;
199
200 originRecord->rdSize = 5;
201 originRecord->rdFunction = META_SETWINDOWORG;
202 originRecord->rdParm[0] = originY;
203 originRecord->rdParm[1] = originX;
204
205 extentRecord->rdSize = 5;
206 extentRecord->rdFunction = META_SETWINDOWEXT;
207 extentRecord->rdParm[0] = extentY;
208 extentRecord->rdParm[1] = extentX;
209
210 fwrite((void *)modeBuffer, sizeof(char), 8, fHandle);
211
212 if (useOriginAndExtent)
213 {
214 fwrite((void *)originBuffer, sizeof(char), 10, fHandle);
215 fwrite((void *)extentBuffer, sizeof(char), 10, fHandle);
216 }
217
218 int ch = -2;
219 while (ch != EOF)
220 {
221 ch = getc(fd);
222 if (ch != EOF)
223 {
224 putc(ch, fHandle);
225 }
226 }
227 fclose(fHandle);
228 fclose(fd);
229 wxRemoveFile(filename);
230 wxCopyFile(tempFileBuf, filename);
231 wxRemoveFile(tempFileBuf);
232 return TRUE;
233 }
234
235 #endif
236