]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/metafile.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "metafile.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
34 #include "wx/metafile.h"
35 #include "wx/clipbrd.h"
37 #include "wx/mac/private.h"
42 extern bool wxClipboardIsOpen
;
44 #if !USE_SHARED_LIBRARY
45 IMPLEMENT_DYNAMIC_CLASS(wxMetafile
, wxObject
)
46 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC
, wxDC
)
51 * Currently, the only purpose for making a metafile is to put
52 * it on the clipboard.
55 wxMetafileRefData::wxMetafileRefData(void)
60 wxMetafileRefData::~wxMetafileRefData(void)
64 KillPicture( (PicHandle
) m_metafile
) ;
69 wxMetaFile::wxMetaFile(const wxString
& file
)
71 m_refData
= new wxMetafileRefData
;
74 M_METAFILEDATA
->m_metafile
= 0;
75 wxASSERT_MSG( file
.IsEmpty() , wxT("no file based metafile support yet") ) ;
77 if (!file.IsNull() && (file.Cmp("") == 0))
78 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
82 wxMetaFile::~wxMetaFile()
86 bool wxMetaFile::SetClipboard(int width
, int height
)
88 #if wxUSE_DRAG_AND_DROP
89 //TODO finishi this port , we need the data obj first
93 bool alreadyOpen
=wxTheClipboard
->IsOpened() ;
96 wxTheClipboard
->Open();
97 wxTheClipboard
->Clear();
100 new wxMetafileDataObject( *this) ;
101 bool success
= wxTheClipboard
->SetData(data
);
103 wxTheClipboard
->Close();
104 return (bool) success
;
109 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf
)
112 m_refData
= new wxMetafileRefData
;
113 if ( M_METAFILEDATA
->m_metafile
)
114 KillPicture( (PicHandle
) M_METAFILEDATA
->m_metafile
) ;
116 M_METAFILEDATA
->m_metafile
= mf
;
119 bool wxMetaFile::Play(wxDC
*dc
)
128 wxMacPortSetter
helper( dc
) ;
129 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
130 DrawPicture( pict
, &(**pict
).picFrame
) ;
135 wxSize
wxMetaFile::GetSize() const
137 wxSize size
= wxDefaultSize
;
140 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
141 Rect
&r
= (**pict
).picFrame
;
142 size
.x
= r
.right
- r
.left
;
143 size
.y
= r
.bottom
- r
.top
;
150 * Metafile device context
154 // New constructor that takes origin and extent. If you use this, don't
155 // give origin/extent arguments to wxMakeMetaFilePlaceable.
157 wxMetaFileDC::wxMetaFileDC(const wxString
& filename
,
158 int width
, int height
,
159 const wxString
& WXUNUSED(description
) )
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")) ;
164 m_metaFile
= new wxMetaFile(filename
) ;
165 Rect r
={0,0,height
,width
} ;
167 RectRgn( (RgnHandle
) m_macBoundaryClipRgn
, &r
) ;
168 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
170 m_metaFile
->SetHMETAFILE( OpenPicture( &r
) ) ;
171 ::GetPort( (GrafPtr
*) &m_macPort
) ;
174 SetMapMode(wxMM_TEXT
);
177 wxMetaFileDC::~wxMetaFileDC()
181 void wxMetaFileDC::DoGetSize(int *width
, int *height
) const
183 wxCHECK_RET( m_metaFile
, _T("GetSize() doesn't work without a metafile") );
185 wxSize sz
= m_metaFile
->GetSize() ;
186 if (width
) (*width
) = sz
.x
;
187 if (height
) (*height
) = sz
.y
;
190 wxMetaFile
*wxMetaFileDC::Close()
197 size_t wxMetafileDataObject::GetDataSize() const
199 return GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ;
202 bool wxMetafileDataObject::GetDataHere(void *buf
) const
204 memcpy( buf
, (*(PicHandle
)(*((wxMetafile
*)&m_metafile
)).GetHMETAFILE()) ,
205 GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ) ;
209 bool wxMetafileDataObject::SetData(size_t len
, const void *buf
)
211 Handle handle
= NewHandle( len
) ;
212 SetHandleSize( handle
, len
) ;
213 memcpy( *handle
, buf
, len
) ;
214 m_metafile
.SetHMETAFILE( handle
) ;