]>
Commit | Line | Data |
---|---|---|
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 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/setup.h" | |
25 | #endif | |
26 | ||
27 | #if wxUSE_METAFILE | |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/utils.h" | |
31 | #include "wx/app.h" | |
32 | #endif | |
33 | ||
34 | #include "wx/metafile.h" | |
35 | #include "wx/clipbrd.h" | |
36 | ||
37 | #include <stdio.h> | |
38 | #include <string.h> | |
39 | ||
40 | extern bool wxClipboardIsOpen; | |
41 | ||
42 | IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject) | |
43 | IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC) | |
44 | ||
45 | /* | |
46 | * Metafiles | |
47 | * Currently, the only purpose for making a metafile is to put | |
48 | * it on the clipboard. | |
49 | */ | |
50 | ||
51 | wxMetafileRefData::wxMetafileRefData(void) | |
52 | { | |
53 | m_metafile = 0; | |
54 | } | |
55 | ||
56 | wxMetafileRefData::~wxMetafileRefData(void) | |
57 | { | |
58 | if (m_metafile) | |
59 | { | |
60 | KillPicture( m_metafile ) ; | |
61 | m_metafile = 0; | |
62 | } | |
63 | } | |
64 | ||
65 | wxMetaFile::wxMetaFile(const wxString& file) | |
66 | { | |
67 | m_refData = new wxMetafileRefData; | |
68 | ||
69 | ||
70 | M_METAFILEDATA->m_metafile = 0; | |
71 | wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; | |
72 | /* | |
73 | if (!file.IsNull() && (file.Cmp("") == 0)) | |
74 | M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file); | |
75 | */ | |
76 | } | |
77 | ||
78 | wxMetaFile::~wxMetaFile() | |
79 | { | |
80 | } | |
81 | ||
82 | bool wxMetaFile::SetClipboard(int width, int height) | |
83 | { | |
84 | if (!m_refData) | |
85 | return FALSE; | |
86 | /* | |
87 | bool alreadyOpen=wxClipboardOpen(); | |
88 | if (!alreadyOpen) | |
89 | { | |
90 | wxOpenClipboard(); | |
91 | if (!wxEmptyClipboard()) return FALSE; | |
92 | } | |
93 | bool success = wxSetClipboardData(wxDF_METAFILE, this, width,height); | |
94 | if (!alreadyOpen) wxCloseClipboard(); | |
95 | return (bool) success; | |
96 | */ | |
97 | return TRUE ; | |
98 | } | |
99 | ||
100 | bool wxMetaFile::Play(wxDC *dc) | |
101 | { | |
102 | if (!m_refData) | |
103 | return FALSE; | |
104 | ||
105 | if (!dc->Ok() ) | |
106 | return FALSE; | |
107 | ||
108 | dc->MacVerifySetup() ; | |
109 | ||
110 | { | |
111 | PicHandle pict = GetHMETAFILE() ; | |
112 | DrawPicture( pict , &(**pict).picFrame ) ; | |
113 | } | |
114 | /* | |
115 | if (!m_refData) | |
116 | return FALSE; | |
117 | ||
118 | dc->BeginDrawing(); | |
119 | ||
120 | if (dc->GetHDC() && M_METAFILEDATA->m_metafile) | |
121 | PlayMetaFile((HDC) dc->GetHDC(), (HMETAFILE) M_METAFILEDATA->m_metafile); | |
122 | ||
123 | dc->EndDrawing(); | |
124 | */ | |
125 | return TRUE; | |
126 | } | |
127 | ||
128 | /* | |
129 | * Metafile device context | |
130 | * | |
131 | */ | |
132 | ||
133 | // Original constructor that does not takes origin and extent. If you use this, | |
134 | // *DO* give origin/extent arguments to wxMakeMetaFilePlaceable. | |
135 | wxMetaFileDC::wxMetaFileDC(const wxString& file) | |
136 | { | |
137 | m_metaFile = NULL; | |
138 | m_minX = 10000; | |
139 | m_minY = 10000; | |
140 | m_maxX = -10000; | |
141 | m_maxY = -10000; | |
142 | ||
143 | wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; | |
144 | ||
145 | m_metaFile = new wxMetaFile("") ; | |
146 | Rect r={0,0,100,100} ; | |
147 | ||
148 | m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; | |
149 | ::GetPort( &m_macPort ) ; | |
150 | m_ok = TRUE ; | |
151 | ||
152 | SetMapMode(wxMM_TEXT); | |
153 | } | |
154 | ||
155 | // New constructor that takes origin and extent. If you use this, don't | |
156 | // give origin/extent arguments to wxMakeMetaFilePlaceable. | |
157 | ||
158 | wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg) | |
159 | { | |
160 | m_minX = 10000; | |
161 | m_minY = 10000; | |
162 | m_maxX = -10000; | |
163 | m_maxY = -10000; | |
164 | ||
165 | wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; | |
166 | ||
167 | m_metaFile = new wxMetaFile("") ; | |
168 | Rect r={yorg,xorg,yorg+yext,xorg+xext} ; | |
169 | ||
170 | m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; | |
171 | ::GetPort( &m_macPort ) ; | |
172 | m_ok = TRUE ; | |
173 | ||
174 | SetMapMode(wxMM_TEXT); | |
175 | } | |
176 | ||
177 | wxMetaFileDC::~wxMetaFileDC() | |
178 | { | |
179 | } | |
180 | ||
181 | wxMetaFile *wxMetaFileDC::Close() | |
182 | { | |
183 | ClosePicture() ; | |
184 | return m_metaFile; | |
185 | } | |
186 | ||
187 | ||
188 | #endif |