]>
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 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
30 #include "wx/metafile.h"
31 #include "wx/clipbrd.h"
33 #include "wx/mac/private.h"
38 extern bool wxClipboardIsOpen
;
40 IMPLEMENT_DYNAMIC_CLASS(wxMetafile
, wxObject
)
41 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC
, wxDC
)
45 * Currently, the only purpose for making a metafile is to put
46 * it on the clipboard.
49 wxMetafileRefData::wxMetafileRefData(void)
54 wxMetafileRefData::~wxMetafileRefData(void)
58 KillPicture( (PicHandle
) m_metafile
) ;
63 wxMetaFile::wxMetaFile(const wxString
& file
)
65 m_refData
= new wxMetafileRefData
;
68 M_METAFILEDATA
->m_metafile
= 0;
69 wxASSERT_MSG( file
.IsEmpty() , wxT("no file based metafile support yet") ) ;
71 if (!file.IsNull() && (file.Cmp("") == 0))
72 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
76 wxMetaFile::~wxMetaFile()
80 bool wxMetaFile::SetClipboard(int width
, int height
)
82 #if wxUSE_DRAG_AND_DROP
83 //TODO finishi this port , we need the data obj first
87 bool alreadyOpen
=wxTheClipboard
->IsOpened() ;
90 wxTheClipboard
->Open();
91 wxTheClipboard
->Clear();
94 new wxMetafileDataObject( *this) ;
95 bool success
= wxTheClipboard
->SetData(data
);
97 wxTheClipboard
->Close();
98 return (bool) success
;
103 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf
)
106 m_refData
= new wxMetafileRefData
;
107 if ( M_METAFILEDATA
->m_metafile
)
108 KillPicture( (PicHandle
) M_METAFILEDATA
->m_metafile
) ;
110 M_METAFILEDATA
->m_metafile
= mf
;
113 bool wxMetaFile::Play(wxDC
*dc
)
122 wxMacPortSetter
helper( dc
) ;
123 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
124 DrawPicture( pict
, &(**pict
).picFrame
) ;
129 wxSize
wxMetaFile::GetSize() const
131 wxSize size
= wxDefaultSize
;
134 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
135 Rect
&r
= (**pict
).picFrame
;
136 size
.x
= r
.right
- r
.left
;
137 size
.y
= r
.bottom
- r
.top
;
144 * Metafile device context
148 // New constructor that takes origin and extent. If you use this, don't
149 // give origin/extent arguments to wxMakeMetaFilePlaceable.
151 wxMetaFileDC::wxMetaFileDC(const wxString
& filename
,
152 int width
, int height
,
153 const wxString
& WXUNUSED(description
) )
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")) ;
158 m_metaFile
= new wxMetaFile(filename
) ;
159 Rect r
={0,0,height
,width
} ;
161 RectRgn( (RgnHandle
) m_macBoundaryClipRgn
, &r
) ;
162 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
164 m_metaFile
->SetHMETAFILE( OpenPicture( &r
) ) ;
165 ::GetPort( (GrafPtr
*) &m_macPort
) ;
168 SetMapMode(wxMM_TEXT
);
171 wxMetaFileDC::~wxMetaFileDC()
175 void wxMetaFileDC::DoGetSize(int *width
, int *height
) const
177 wxCHECK_RET( m_metaFile
, _T("GetSize() doesn't work without a metafile") );
179 wxSize sz
= m_metaFile
->GetSize() ;
180 if (width
) (*width
) = sz
.x
;
181 if (height
) (*height
) = sz
.y
;
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
, (*(PicHandle
)(*((wxMetafile
*)&m_metafile
)).GetHMETAFILE()) ,
199 GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ) ;
203 bool wxMetafileDataObject::SetData(size_t len
, const void *buf
)
205 Handle handle
= NewHandle( len
) ;
206 SetHandleSize( handle
, len
) ;
207 memcpy( *handle
, buf
, len
) ;
208 m_metafile
.SetHMETAFILE( handle
) ;