]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/metafile.cpp
applied patch #1356901 "Yet another removal of extra semicolons", also fixed remainin...
[wxWidgets.git] / src / mac / classic / 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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/setup.h"
21 #endif
22
23 #if wxUSE_METAFILE
24
25 #ifndef WX_PRECOMP
26 #include "wx/utils.h"
27 #include "wx/app.h"
28 #endif
29
30 #include "wx/metafile.h"
31 #include "wx/clipbrd.h"
32
33 #include "wx/mac/private.h"
34
35 #include <stdio.h>
36 #include <string.h>
37
38 extern bool wxClipboardIsOpen;
39
40 IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
41 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
42
43 /*
44 * Metafiles
45 * Currently, the only purpose for making a metafile is to put
46 * it on the clipboard.
47 */
48
49 wxMetafileRefData::wxMetafileRefData(void)
50 {
51 m_metafile = 0;
52 }
53
54 wxMetafileRefData::~wxMetafileRefData(void)
55 {
56 if (m_metafile)
57 {
58 KillPicture( (PicHandle) m_metafile ) ;
59 m_metafile = 0;
60 }
61 }
62
63 wxMetaFile::wxMetaFile(const wxString& file)
64 {
65 m_refData = new wxMetafileRefData;
66
67
68 M_METAFILEDATA->m_metafile = 0;
69 wxASSERT_MSG( file.IsEmpty() , wxT("no file based metafile support yet") ) ;
70 /*
71 if (!file.IsNull() && (file.Cmp("") == 0))
72 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
73 */
74 }
75
76 wxMetaFile::~wxMetaFile()
77 {
78 }
79
80 bool wxMetaFile::SetClipboard(int width, int height)
81 {
82 #if wxUSE_DRAG_AND_DROP
83 //TODO finishi this port , we need the data obj first
84 if (!m_refData)
85 return FALSE;
86
87 bool alreadyOpen=wxTheClipboard->IsOpened() ;
88 if (!alreadyOpen)
89 {
90 wxTheClipboard->Open();
91 wxTheClipboard->Clear();
92 }
93 wxDataObject *data =
94 new wxMetafileDataObject( *this) ;
95 bool success = wxTheClipboard->SetData(data);
96 if (!alreadyOpen)
97 wxTheClipboard->Close();
98 return (bool) success;
99 #endif
100 return TRUE ;
101 }
102
103 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
104 {
105 if (!m_refData)
106 m_refData = new wxMetafileRefData;
107 if ( M_METAFILEDATA->m_metafile )
108 KillPicture( (PicHandle) M_METAFILEDATA->m_metafile ) ;
109
110 M_METAFILEDATA->m_metafile = mf;
111 }
112
113 bool wxMetaFile::Play(wxDC *dc)
114 {
115 if (!m_refData)
116 return FALSE;
117
118 if (!dc->Ok() )
119 return FALSE;
120
121 {
122 wxMacPortSetter helper( dc ) ;
123 PicHandle pict = (PicHandle) GetHMETAFILE() ;
124 DrawPicture( pict , &(**pict).picFrame ) ;
125 }
126 return TRUE;
127 }
128
129 wxSize wxMetaFile::GetSize() const
130 {
131 wxSize size = wxDefaultSize ;
132 if ( Ok() )
133 {
134 PicHandle pict = (PicHandle) GetHMETAFILE() ;
135 Rect &r = (**pict).picFrame ;
136 size.x = r.right - r.left ;
137 size.y = r.bottom - r.top ;
138 }
139
140 return size;
141 }
142
143 /*
144 * Metafile device context
145 *
146 */
147
148 // New constructor that takes origin and extent. If you use this, don't
149 // give origin/extent arguments to wxMakeMetaFilePlaceable.
150
151 wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
152 int width , int height ,
153 const wxString& WXUNUSED(description) )
154 {
155 wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
156 wxASSERT_MSG( filename.IsEmpty() , _T("no file based metafile support yet")) ;
157
158 m_metaFile = new wxMetaFile(filename) ;
159 Rect r={0,0,height,width} ;
160
161 RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
162 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
163
164 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
165 ::GetPort( (GrafPtr*) &m_macPort ) ;
166 m_ok = TRUE ;
167
168 SetMapMode(wxMM_TEXT);
169 }
170
171 wxMetaFileDC::~wxMetaFileDC()
172 {
173 }
174
175 void wxMetaFileDC::DoGetSize(int *width, int *height) const
176 {
177 wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
178
179 wxSize sz = m_metaFile->GetSize() ;
180 if (width) (*width) = sz.x;
181 if (height) (*height) = sz.y;
182 }
183
184 wxMetaFile *wxMetaFileDC::Close()
185 {
186 ClosePicture() ;
187 return m_metaFile;
188 }
189
190 #if wxUSE_DATAOBJ
191 size_t wxMetafileDataObject::GetDataSize() const
192 {
193 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
194 }
195
196 bool wxMetafileDataObject::GetDataHere(void *buf) const
197 {
198 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
199 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
200 return true ;
201 }
202
203 bool wxMetafileDataObject::SetData(size_t len, const void *buf)
204 {
205 Handle handle = NewHandle( len ) ;
206 SetHandleSize( handle , len ) ;
207 memcpy( *handle , buf , len ) ;
208 m_metafile.SetHMETAFILE( handle ) ;
209 return true ;
210 }
211 #endif
212
213 #endif