OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
metafile.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of TMetafilePict, a MetaFile wrapper class
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_METAFILE_H)
10#define OWL_METAFILE_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/gdibase.h>
18#include <owl/wsyscls.h>
19
20namespace owl {
21
22
23class _OWLCLASS TClipboard;
24class _OWLCLASS TDC;
25
26/// \addtogroup graphics
27/// @{
28
29//
30// METAFILEHEADER is used generally to create placeable metafiles
31// (Originally created by Aldus; described by Microsoft in the
32// Win 3.1 SDK; not declared in any Microsoft headers.)
33//
34// The placeable metafile header was originally a 16-bit structure, but it
35// contains two fields of types that are normally polymorphic between
36// 16 and 32 bits: RECT and HANDLE. RECT16 is a non-polymorphic 16-bit
37// RECT, needed to preserve alignment when reading mf headers into
38// 32-bit programs.
39//
40
41// Users may have defined METAFILEHEADER for themselves.
42//
43#if !defined(METAFILEHEADER)
44
45#include <pshpack1.h> // always byte packed...
46
53
54typedef struct {
55 DWORD key; ///< identifies file type
56
57 /// hmf is defined as HANDLE, but in Win16 that's an unsigned int
58 WORD hmf; ///< unused (0)
59
60 RECT16 bbox; ///< bounding rectangle
61 WORD inch; ///< units per inch
62 DWORD reserved; ///< unused (0)
63 WORD checksum; ///< XOR of previous fields
65
66#include <poppack.h> // restore previous packing
67
68#endif
69
70#include <owl/preclass.h>
71
72//
73/// \class TMetaFilePict
74// ~~~~~ ~~~~~~~~~~~~~
75/// TMetaFilePict is a support class used with TMetaFileDC to simplify metafile
76/// operations, such as playing into a device context (DC) or storing data on the
77/// Clipboard. TMetaFilePict automatically handles the conversion between a metafile
78/// and a metafilepict.
79//
81 public:
83 TMetaFilePict(const TClipboard& clipboard);
85 TMetaFilePict(uint size, void * data);
89
90 operator HMETAFILE() const;
91
92 uint32 GetMetaFileBitsEx(uint size, void* data);
93
94 // Play this metafile onto a dc
95 //
96 TSize CalcPlaySize(TDC& dc, const TSize& defSize) const;
97 bool PlayOnto(TDC& dc, const TSize& defSize) const;
98
99 // Put this MetaFilePict onto the clipboard
100 //
101 void ToClipboard(TClipboard& clipboard,
103 const TSize& extent=TSize(0,0));
104
105 // Retrieve attributes of this metafile
106 //
107 uint MappingMode() const;
108 int Width() const;
109 int Height() const;
110 TSize Size() const;
111
112 // Set attributes of this metafile
113 //
114 void SetMappingMode(uint mm);
115 void SetSize(const TSize& size);
116
117 // Methods for placeable metafiles
118 //
119 bool IsPlaceable();
120 bool GetPlaceableHeader(METAFILEHEADER& header);
121 void SetPlaceableHeader(TRect& bounds, uint16 unitsPerInch);
122
123 ///BGM consider adding these, as in TDib:
124 ///BGM Write(ostream& os, bool writeFileHeader = false);
125 ///BGM Write(TFile& file, bool writeFileHeader = false);
126
127 protected:
128 uint16 CalcHeaderChecksum(const METAFILEHEADER& mfHeader);
129
131 int Mm; // Mapping mode
132 TSize Extent;
133 bool Placeable;
134 METAFILEHEADER MFHeader;
135 static const uint32 MFHeaderKey;
136
137 private:
138 // Hidden to prevent accidental copying or assignment
139 //
140 TMetaFilePict& operator=(const TMetaFilePict&);
141};
142
143//
144/// \class TEnhMetaFilePict
145// ~~~~~ ~~~~~~~~~~~~~~~~
146/// TEnhMetaFilePict is a class that encapsulates the enhanced metafile.
147//
149 public:
154 TEnhMetaFilePict(uint bytes, const void* buffer);
156
157 operator HENHMETAFILE() const;
158
159 // Play this metafile onto a dc
160 //
161 bool PlayOnto(TDC& dc, const TRect* rect) const;
162
163 // Retrieve attributes of this metafile
164 //
165 uint GetBits(uint bytes, void* buffer);
166 uint GetDescription(uint bytes, void* buffer);
167 uint GetHeader(uint bytes, ENHMETAHEADER* record);
168 uint GetPaletteEntries(uint count, PALETTEENTRY* entries);
169
170 private:
171 // Hidden to prevent accidental copying or assignment
172 //
173 TEnhMetaFilePict& operator=(const TEnhMetaFilePict&);
174};
175
176/// @}
177
178#include <owl/posclass.h>
179
180
181//----------------------------------------------------------------------------
182// Inline implementations
183//
184
185//
186/// Inserts the metafile picture onto the clipboard.
187//
189 mfp.ToClipboard(clipboard);
190 return clipboard;
191}
192
193//
194/// Returns the associated handle for the metafile object.
195//
196inline TMetaFilePict::operator HMETAFILE() const {
197 return HMETAFILE(Handle);
198}
199
200//
201//
202//
203inline bool
205 return Placeable;
206}
207
208//
209//
210//
211inline bool
213 if (IsPlaceable()) {
214 header = MFHeader;
215 return true;
216 }
217 else
218 return false;
219}
220
221//
222/// Warning: values in the bounds rectangle will be cast to unsigned
223/// int values.
224//
225inline void
227 MFHeader.key = MFHeaderKey;
228 //MFHeader.hmf = (WORD)(uint)Handle; /*?????????????????*/
229 MFHeader.bbox.left = static_cast<int16>(bounds.left);
230 MFHeader.bbox.top = static_cast<int16>(bounds.top);
231 MFHeader.bbox.right = static_cast<int16>(bounds.right);
232 MFHeader.bbox.bottom = static_cast<int16>(bounds.bottom);
233 MFHeader.inch = unitsPerInch;
234 MFHeader.reserved = 0;
235 MFHeader.checksum = CalcHeaderChecksum(MFHeader);
236 Placeable = true;
237}
238
239//
240/// Returns the mapping mode of the metafile.
241//
243 return Mm;
244}
245
246//
247/// Returns the width of the metafile.
248//
249inline int TMetaFilePict::Width() const {
250 return Extent.cx;
251}
252
253//
254/// Returns the height of the metafile.
255//
256inline int TMetaFilePict::Height() const {
257 return Extent.cy;
258}
259
260//
261/// Returns the size of the metafile.
262//
264 return Extent;
265}
266
267//
268/// Sets the mapping mode for the metafile.
269//
271 Mm = mm;
272}
273
274//
275/// Sets the size of the metafile.
276//
277inline void TMetaFilePict::SetSize(const TSize& size) {
278 Extent = size;
279}
280
281//
282/// Returns the associated handle of the enhanced metafile.
283//
284inline TEnhMetaFilePict::operator HENHMETAFILE() const {
285 return HENHMETAFILE(Handle);
286}
287
288//
289/// Returns the bits of the metafile.
290//
292 return ::GetEnhMetaFileBits(*this, bytes, static_cast<LPBYTE>(buffer));
293}
294
295//
296/// Retrieves the description of this enhanced metafile.
297//
299 return ::GetEnhMetaFileDescription(*this, bytes, static_cast<LPTSTR>(buffer));
300}
301
302//
303/// Retrieves the header information for the enhanced metafile.
304//
306 return ::GetEnhMetaFileHeader(*this, bytes, record);
307}
308
309//
310/// Retrieves the palette entries of the enhanced metafile.
311//
313 return ::GetEnhMetaFilePaletteEntries(*this, count, entries);
314}
315
316
317
318} // OWL namespace
319
320#endif // OWL_METAFILE_H
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition clipboar.h:32
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
TEnhMetaFilePict is a class that encapsulates the enhanced metafile.
Definition metafile.h:148
uint GetDescription(uint bytes, void *buffer)
Retrieves the description of this enhanced metafile.
Definition metafile.h:298
uint GetBits(uint bytes, void *buffer)
Returns the bits of the metafile.
Definition metafile.h:291
uint GetHeader(uint bytes, ENHMETAHEADER *record)
Retrieves the header information for the enhanced metafile.
Definition metafile.h:305
uint GetPaletteEntries(uint count, PALETTEENTRY *entries)
Retrieves the palette entries of the enhanced metafile.
Definition metafile.h:312
Root and abstract class for Windows object wrappers.
Definition gdibase.h:79
TMetaFilePict is a support class used with TMetaFileDC to simplify metafile operations,...
Definition metafile.h:80
uint16 CalcHeaderChecksum(const METAFILEHEADER &mfHeader)
BGM consider adding these, as in TDib: BGM Write(ostream& os, bool writeFileHeader = false); BGM Writ...
Definition metafile.cpp:207
TSize Size() const
Returns the size of the metafile.
Definition metafile.h:263
void SetPlaceableHeader(TRect &bounds, uint16 unitsPerInch)
Warning: values in the bounds rectangle will be cast to unsigned int values.
Definition metafile.h:226
bool GetPlaceableHeader(METAFILEHEADER &header)
Definition metafile.h:212
void SetMappingMode(uint mm)
Sets the mapping mode for the metafile.
Definition metafile.h:270
int Height() const
Returns the height of the metafile.
Definition metafile.h:256
int Width() const
Returns the width of the metafile.
Definition metafile.h:249
uint MappingMode() const
Returns the mapping mode of the metafile.
Definition metafile.h:242
void SetSize(const TSize &size)
Sets the size of the metafile.
Definition metafile.h:277
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
Definition of base most abstract GDI object class, and associated exception class.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
Definition color.h:498
unsigned long uint32
Definition number.h:34
unsigned short uint16
Definition number.h:33
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define _OWLCLASS
Definition defs.h:338
WORD checksum
XOR of previous fields.
Definition metafile.h:63
DWORD reserved
unused (0)
Definition metafile.h:62
RECT16 bbox
bounding rectangle
Definition metafile.h:60
WORD inch
units per inch
Definition metafile.h:61
WORD hmf
hmf is defined as HANDLE, but in Win16 that's an unsigned int
Definition metafile.h:58
DWORD key
identifies file type
Definition metafile.h:55
int16 left
Definition metafile.h:48
int16 top
Definition metafile.h:49
int16 right
Definition metafile.h:50
int16 bottom
Definition metafile.h:51
Classes for window system structure and type encapsulation.