]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/metafile.cpp
resource fork not used anymore
[wxWidgets.git] / src / mac / carbon / metafile.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: metafile.cpp
3 // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
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 "wx/mac/private.h"
38
39 #include <stdio.h>
40 #include <string.h>
41
42 extern bool wxClipboardIsOpen;
43
44 #if !USE_SHARED_LIBRARY
45 IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
46 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
47 #endif
48
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 {
64 KillPicture( (PicHandle) m_metafile ) ;
65 m_metafile = 0;
66 }
67 }
68
69 wxMetaFile::wxMetaFile(const wxString& file)
70 {
71 m_refData = new wxMetafileRefData;
72
73
74 M_METAFILEDATA->m_metafile = 0;
75 wxASSERT_MSG( file.IsEmpty() , wxT("no file based metafile support yet") ) ;
76 /*
77 if (!file.IsNull() && (file.Cmp("") == 0))
78 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
79 */
80 }
81
82 wxMetaFile::~wxMetaFile()
83 {
84 }
85
86 bool wxMetaFile::SetClipboard(int width, int height)
87 {
88 #if wxUSE_DRAG_AND_DROP
89 //TODO finishi this port , we need the data obj first
90 if (!m_refData)
91 return FALSE;
92
93 bool alreadyOpen=wxTheClipboard->IsOpened() ;
94 if (!alreadyOpen)
95 {
96 wxTheClipboard->Open();
97 wxTheClipboard->Clear();
98 }
99 wxDataObject *data =
100 new wxMetafileDataObject( *this) ;
101 bool success = wxTheClipboard->SetData(data);
102 if (!alreadyOpen)
103 wxTheClipboard->Close();
104 return (bool) success;
105 #endif
106 return TRUE ;
107 }
108
109 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
110 {
111 if (!m_refData)
112 m_refData = new wxMetafileRefData;
113 if ( M_METAFILEDATA->m_metafile )
114 KillPicture( (PicHandle) M_METAFILEDATA->m_metafile ) ;
115
116 M_METAFILEDATA->m_metafile = mf;
117 }
118
119 bool wxMetaFile::Play(wxDC *dc)
120 {
121 if (!m_refData)
122 return FALSE;
123
124 if (!dc->Ok() )
125 return FALSE;
126
127 {
128 wxMacPortSetter helper( dc ) ;
129 PicHandle pict = (PicHandle) GetHMETAFILE() ;
130 DrawPicture( pict , &(**pict).picFrame ) ;
131 }
132 return TRUE;
133 }
134
135 wxSize wxMetaFile::GetSize() const
136 {
137 wxSize size = wxDefaultSize ;
138 if ( Ok() )
139 {
140 PicHandle pict = (PicHandle) GetHMETAFILE() ;
141 Rect &r = (**pict).picFrame ;
142 size.x = r.right - r.left ;
143 size.y = r.bottom - r.top ;
144 }
145
146 return size;
147 }
148
149 /*
150 * Metafile device context
151 *
152 */
153
154 // New constructor that takes origin and extent. If you use this, don't
155 // give origin/extent arguments to wxMakeMetaFilePlaceable.
156
157 wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
158 int width , int height ,
159 const wxString& WXUNUSED(description) )
160 {
161 wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
162 wxASSERT_MSG( filename.IsEmpty() , _T("no file based metafile support yet")) ;
163
164 m_metaFile = new wxMetaFile(filename) ;
165 Rect r={0,0,height,width} ;
166
167 RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
168 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
169
170 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
171 ::GetPort( (GrafPtr*) &m_macPort ) ;
172 m_ok = TRUE ;
173
174 SetMapMode(wxMM_TEXT);
175 }
176
177 wxMetaFileDC::~wxMetaFileDC()
178 {
179 }
180
181 void wxMetaFileDC::DoGetSize(int *width, int *height) const
182 {
183 wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
184
185 wxSize sz = m_metaFile->GetSize() ;
186 if (width) (*width) = sz.x;
187 if (height) (*height) = sz.y;
188 }
189
190 wxMetaFile *wxMetaFileDC::Close()
191 {
192 ClosePicture() ;
193 return m_metaFile;
194 }
195
196 #if wxUSE_DATAOBJ
197 size_t wxMetafileDataObject::GetDataSize() const
198 {
199 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
200 }
201
202 bool wxMetafileDataObject::GetDataHere(void *buf) const
203 {
204 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
205 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
206 return true ;
207 }
208
209 bool wxMetafileDataObject::SetData(size_t len, const void *buf)
210 {
211 Handle handle = NewHandle( len ) ;
212 SetHandleSize( handle , len ) ;
213 memcpy( *handle , buf , len ) ;
214 m_metafile.SetHMETAFILE( handle ) ;
215 return true ;
216 }
217 #endif
218
219 #endif