]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: metafile.cpp | |
3 | // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional. | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e40298d5 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "metafile.h" | |
14 | #endif | |
15 | ||
519cb848 SC |
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" | |
e9576ca5 SC |
35 | #include "wx/clipbrd.h" |
36 | ||
76a5e5d2 SC |
37 | #include "wx/mac/private.h" |
38 | ||
519cb848 SC |
39 | #include <stdio.h> |
40 | #include <string.h> | |
41 | ||
e9576ca5 SC |
42 | extern bool wxClipboardIsOpen; |
43 | ||
2f1ae414 | 44 | #if !USE_SHARED_LIBRARY |
519cb848 SC |
45 | IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject) |
46 | IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC) | |
2f1ae414 | 47 | #endif |
e9576ca5 | 48 | |
519cb848 SC |
49 | /* |
50 | * Metafiles | |
51 | * Currently, the only purpose for making a metafile is to put | |
52 | * it on the clipboard. | |
53 | */ | |
54 | ||
55 | wxMetafileRefData::wxMetafileRefData(void) | |
56 | { | |
57 | m_metafile = 0; | |
58 | } | |
59 | ||
60 | wxMetafileRefData::~wxMetafileRefData(void) | |
61 | { | |
62 | if (m_metafile) | |
63 | { | |
e40298d5 | 64 | KillPicture( (PicHandle) m_metafile ) ; |
519cb848 SC |
65 | m_metafile = 0; |
66 | } | |
67 | } | |
68 | ||
e9576ca5 SC |
69 | wxMetaFile::wxMetaFile(const wxString& file) |
70 | { | |
519cb848 SC |
71 | m_refData = new wxMetafileRefData; |
72 | ||
73 | ||
74 | M_METAFILEDATA->m_metafile = 0; | |
75 | wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; | |
76 | /* | |
77 | if (!file.IsNull() && (file.Cmp("") == 0)) | |
78 | M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file); | |
79 | */ | |
e9576ca5 SC |
80 | } |
81 | ||
82 | wxMetaFile::~wxMetaFile() | |
83 | { | |
e9576ca5 SC |
84 | } |
85 | ||
86 | bool wxMetaFile::SetClipboard(int width, int height) | |
87 | { | |
f0822896 | 88 | #if wxUSE_DRAG_AND_DROP |
e40298d5 | 89 | //TODO finishi this port , we need the data obj first |
519cb848 SC |
90 | if (!m_refData) |
91 | return FALSE; | |
e40298d5 | 92 | |
f0822896 | 93 | bool alreadyOpen=wxTheClipboard->IsOpened() ; |
e9576ca5 SC |
94 | if (!alreadyOpen) |
95 | { | |
f0822896 | 96 | wxTheClipboard->Open(); |
a07c1212 | 97 | wxTheClipboard->Clear(); |
e9576ca5 | 98 | } |
a07c1212 | 99 | wxDataObject *data = |
e40298d5 | 100 | new wxMetafileDataObject( *this) ; |
a07c1212 SC |
101 | bool success = wxTheClipboard->SetData(data); |
102 | if (!alreadyOpen) | |
e40298d5 JS |
103 | wxTheClipboard->Close(); |
104 | return (bool) success; | |
f0822896 | 105 | #endif |
519cb848 | 106 | return TRUE ; |
e9576ca5 SC |
107 | } |
108 | ||
76a5e5d2 | 109 | void wxMetafile::SetHMETAFILE(WXHMETAFILE mf) |
2f1ae414 SC |
110 | { |
111 | if (!m_refData) | |
112 | m_refData = new wxMetafileRefData; | |
113 | ||
114 | M_METAFILEDATA->m_metafile = mf; | |
115 | } | |
116 | ||
e9576ca5 SC |
117 | bool wxMetaFile::Play(wxDC *dc) |
118 | { | |
e40298d5 JS |
119 | if (!m_refData) |
120 | return FALSE; | |
121 | ||
122 | if (!dc->Ok() ) | |
123 | return FALSE; | |
124 | ||
125 | { | |
126 | wxMacPortSetter helper( dc ) ; | |
127 | PicHandle pict = (PicHandle) GetHMETAFILE() ; | |
128 | DrawPicture( pict , &(**pict).picFrame ) ; | |
129 | } | |
519cb848 | 130 | return TRUE; |
e9576ca5 SC |
131 | } |
132 | ||
133 | /* | |
134 | * Metafile device context | |
135 | * | |
136 | */ | |
137 | ||
138 | // Original constructor that does not takes origin and extent. If you use this, | |
139 | // *DO* give origin/extent arguments to wxMakeMetaFilePlaceable. | |
140 | wxMetaFileDC::wxMetaFileDC(const wxString& file) | |
141 | { | |
e40298d5 JS |
142 | m_metaFile = NULL; |
143 | m_minX = 10000; | |
144 | m_minY = 10000; | |
145 | m_maxX = -10000; | |
146 | m_maxY = -10000; | |
147 | ||
148 | wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; | |
149 | ||
150 | m_metaFile = new wxMetaFile("") ; | |
151 | Rect r={0,0,1000,1000} ; | |
152 | ||
153 | m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; | |
154 | ::GetPort( (GrafPtr*) &m_macPort ) ; | |
155 | m_ok = TRUE ; | |
156 | ||
157 | SetMapMode(wxMM_TEXT); | |
e9576ca5 SC |
158 | } |
159 | ||
160 | // New constructor that takes origin and extent. If you use this, don't | |
161 | // give origin/extent arguments to wxMakeMetaFilePlaceable. | |
519cb848 | 162 | |
e9576ca5 SC |
163 | wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg) |
164 | { | |
e40298d5 JS |
165 | m_minX = 10000; |
166 | m_minY = 10000; | |
167 | m_maxX = -10000; | |
168 | m_maxY = -10000; | |
169 | ||
170 | wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; | |
171 | ||
172 | m_metaFile = new wxMetaFile("") ; | |
173 | Rect r={yorg,xorg,yorg+yext,xorg+xext} ; | |
174 | ||
175 | m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; | |
176 | ::GetPort( (GrafPtr*) &m_macPort ) ; | |
177 | m_ok = TRUE ; | |
178 | ||
179 | SetMapMode(wxMM_TEXT); | |
e9576ca5 SC |
180 | } |
181 | ||
519cb848 | 182 | wxMetaFileDC::~wxMetaFileDC() |
e9576ca5 | 183 | { |
e9576ca5 SC |
184 | } |
185 | ||
519cb848 | 186 | wxMetaFile *wxMetaFileDC::Close() |
e9576ca5 | 187 | { |
e40298d5 JS |
188 | ClosePicture() ; |
189 | return m_metaFile; | |
e9576ca5 SC |
190 | } |
191 | ||
a07c1212 SC |
192 | #if wxUSE_DATAOBJ |
193 | size_t wxMetafileDataObject::GetDataSize() const | |
194 | { | |
e40298d5 | 195 | return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ; |
a07c1212 SC |
196 | } |
197 | ||
198 | bool wxMetafileDataObject::GetDataHere(void *buf) const | |
199 | { | |
e40298d5 JS |
200 | memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) , |
201 | GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ; | |
202 | return true ; | |
a07c1212 SC |
203 | } |
204 | ||
205 | bool wxMetafileDataObject::SetData(size_t len, const void *buf) | |
206 | { | |
e40298d5 JS |
207 | Handle handle = (Handle) m_metafile.GetHMETAFILE() ; |
208 | SetHandleSize( handle , len ) ; | |
209 | memcpy( *handle , buf , len ) ; | |
210 | return true ; | |
a07c1212 SC |
211 | } |
212 | #endif | |
213 | ||
e9576ca5 | 214 | #endif |