]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/metafile.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/metafile.cpp
3 // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
26 #include "wx/metafile.h"
27 #include "wx/clipbrd.h"
29 #include "wx/mac/private.h"
34 extern bool wxClipboardIsOpen
;
36 IMPLEMENT_DYNAMIC_CLASS(wxMetafile
, wxObject
)
37 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC
, wxDC
)
41 * Currently, the only purpose for making a metafile is to put
42 * it on the clipboard.
45 wxMetafileRefData::wxMetafileRefData(void)
50 wxMetafileRefData::~wxMetafileRefData(void)
54 KillPicture( (PicHandle
) m_metafile
) ;
59 wxMetaFile::wxMetaFile(const wxString
& file
)
61 m_refData
= new wxMetafileRefData
;
64 M_METAFILEDATA
->m_metafile
= 0;
65 wxASSERT_MSG( file
.IsEmpty() , wxT("no file based metafile support yet") ) ;
68 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
72 wxMetaFile::~wxMetaFile()
76 bool wxMetaFile::SetClipboard(int width
, int height
)
78 #if wxUSE_DRAG_AND_DROP
79 //TODO finishi this port , we need the data obj first
83 bool alreadyOpen
=wxTheClipboard
->IsOpened() ;
86 wxTheClipboard
->Open();
87 wxTheClipboard
->Clear();
90 new wxMetafileDataObject( *this) ;
91 bool success
= wxTheClipboard
->SetData(data
);
93 wxTheClipboard
->Close();
94 return (bool) success
;
99 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf
)
102 m_refData
= new wxMetafileRefData
;
103 if ( M_METAFILEDATA
->m_metafile
)
104 KillPicture( (PicHandle
) M_METAFILEDATA
->m_metafile
) ;
106 M_METAFILEDATA
->m_metafile
= mf
;
109 bool wxMetaFile::Play(wxDC
*dc
)
118 wxMacPortSetter
helper( dc
) ;
119 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
120 DrawPicture( pict
, &(**pict
).picFrame
) ;
125 wxSize
wxMetaFile::GetSize() const
127 wxSize size
= wxDefaultSize
;
130 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
131 Rect
&r
= (**pict
).picFrame
;
132 size
.x
= r
.right
- r
.left
;
133 size
.y
= r
.bottom
- r
.top
;
140 * Metafile device context
144 // New constructor that takes origin and extent. If you use this, don't
145 // give origin/extent arguments to wxMakeMetaFilePlaceable.
147 wxMetaFileDC::wxMetaFileDC(const wxString
& filename
,
148 int width
, int height
,
149 const wxString
& WXUNUSED(description
) )
151 wxASSERT_MSG( width
== 0 || height
== 0 , _T("no arbitration of metafilesize supported") ) ;
152 wxASSERT_MSG( filename
.empty() , _T("no file based metafile support yet")) ;
154 m_metaFile
= new wxMetaFile(filename
) ;
155 Rect r
={0,0,height
,width
} ;
157 RectRgn( (RgnHandle
) m_macBoundaryClipRgn
, &r
) ;
158 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
160 m_metaFile
->SetHMETAFILE( OpenPicture( &r
) ) ;
161 ::GetPort( (GrafPtr
*) &m_macPort
) ;
164 SetMapMode(wxMM_TEXT
);
167 wxMetaFileDC::~wxMetaFileDC()
171 void wxMetaFileDC::DoGetSize(int *width
, int *height
) const
173 wxCHECK_RET( m_metaFile
, _T("GetSize() doesn't work without a metafile") );
175 wxSize sz
= m_metaFile
->GetSize() ;
176 if (width
) (*width
) = sz
.x
;
177 if (height
) (*height
) = sz
.y
;
180 wxMetaFile
*wxMetaFileDC::Close()
187 size_t wxMetafileDataObject::GetDataSize() const
189 return GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ;
192 bool wxMetafileDataObject::GetDataHere(void *buf
) const
194 memcpy( buf
, (*(PicHandle
)(*((wxMetafile
*)&m_metafile
)).GetHMETAFILE()) ,
195 GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ) ;
199 bool wxMetafileDataObject::SetData(size_t len
, const void *buf
)
201 Handle handle
= NewHandle( len
) ;
202 SetHandleSize( handle
, len
) ;
203 memcpy( *handle
, buf
, len
) ;
204 m_metafile
.SetHMETAFILE( handle
) ;