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