]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/metafile.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
8 // Copyright: (c) AUTHOR
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"
40 extern bool wxClipboardIsOpen
;
42 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxMetafile
, wxObject
)
44 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC
, wxDC
)
49 * Currently, the only purpose for making a metafile is to put
50 * it on the clipboard.
53 wxMetafileRefData::wxMetafileRefData(void)
58 wxMetafileRefData::~wxMetafileRefData(void)
62 KillPicture( m_metafile
) ;
67 wxMetaFile::wxMetaFile(const wxString
& file
)
69 m_refData
= new wxMetafileRefData
;
72 M_METAFILEDATA
->m_metafile
= 0;
73 wxASSERT_MSG( file
.IsEmpty() , "no file based metafile support yet") ;
75 if (!file.IsNull() && (file.Cmp("") == 0))
76 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
80 wxMetaFile::~wxMetaFile()
84 bool wxMetaFile::SetClipboard(int width
, int height
)
86 #if wxUSE_DRAG_AND_DROP
87 //TODO finishi this port , we need the data obj first
91 bool alreadyOpen
=wxTheClipboard
->IsOpened() ;
94 wxTheClipboard
->Open();
95 wxTheClipboard
->Clear();
98 new wxMetafileDataObject( *this) ;
99 bool success
= wxTheClipboard
->SetData(data
);
101 wxTheClipboard
->Close();
102 return (bool) success
;
107 void wxMetafile::SetHMETAFILE(PicHandle mf
)
110 m_refData
= new wxMetafileRefData
;
112 M_METAFILEDATA
->m_metafile
= mf
;
115 bool wxMetaFile::Play(wxDC
*dc
)
124 wxMacPortSetter
helper( dc
) ;
125 PicHandle pict
= GetHMETAFILE() ;
126 DrawPicture( pict
, &(**pict
).picFrame
) ;
132 * Metafile device context
136 // Original constructor that does not takes origin and extent. If you use this,
137 // *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
138 wxMetaFileDC::wxMetaFileDC(const wxString
& file
)
146 wxASSERT_MSG( file
.IsEmpty() , "no file based metafile support yet") ;
148 m_metaFile
= new wxMetaFile("") ;
149 Rect r
={0,0,1000,1000} ;
151 m_metaFile
->SetHMETAFILE( OpenPicture( &r
) ) ;
152 ::GetPort( &m_macPort
) ;
155 SetMapMode(wxMM_TEXT
);
158 // New constructor that takes origin and extent. If you use this, don't
159 // give origin/extent arguments to wxMakeMetaFilePlaceable.
161 wxMetaFileDC::wxMetaFileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
)
168 wxASSERT_MSG( file
.IsEmpty() , "no file based metafile support yet") ;
170 m_metaFile
= new wxMetaFile("") ;
171 Rect r
={yorg
,xorg
,yorg
+yext
,xorg
+xext
} ;
173 m_metaFile
->SetHMETAFILE( OpenPicture( &r
) ) ;
174 ::GetPort( &m_macPort
) ;
177 SetMapMode(wxMM_TEXT
);
180 wxMetaFileDC::~wxMetaFileDC()
184 wxMetaFile
*wxMetaFileDC::Close()
191 size_t wxMetafileDataObject::GetDataSize() const
193 return GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ;
196 bool wxMetafileDataObject::GetDataHere(void *buf
) const
198 memcpy( buf
, (*(*((wxMetafile
*)&m_metafile
)).GetHMETAFILE()) ,
199 GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ) ;
203 bool wxMetafileDataObject::SetData(size_t len
, const void *buf
)
205 Handle handle
= (Handle
) m_metafile
.GetHMETAFILE() ;
206 SetHandleSize( handle
, len
) ;
207 memcpy( *handle
, buf
, len
) ;