]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/metafile.cpp
7a2e5d18154d492d9dde6eba7370fa7b23c5ee20
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 IMPLEMENT_DYNAMIC_CLASS(wxMetafile
, wxObject
)
45 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( (PicHandle
) m_metafile
) ;
67 wxMetaFile::wxMetaFile(const wxString
& file
)
69 m_refData
= new wxMetafileRefData
;
72 M_METAFILEDATA
->m_metafile
= 0;
73 wxASSERT_MSG( file
.IsEmpty() , wxT("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(WXHMETAFILE mf
)
110 m_refData
= new wxMetafileRefData
;
111 if ( M_METAFILEDATA
->m_metafile
)
112 KillPicture( (PicHandle
) M_METAFILEDATA
->m_metafile
) ;
114 M_METAFILEDATA
->m_metafile
= mf
;
117 bool wxMetaFile::Play(wxDC
*dc
)
126 wxMacPortSetter
helper( dc
) ;
127 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
128 DrawPicture( pict
, &(**pict
).picFrame
) ;
133 wxSize
wxMetaFile::GetSize() const
135 wxSize size
= wxDefaultSize
;
138 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
139 Rect
&r
= (**pict
).picFrame
;
140 size
.x
= r
.right
- r
.left
;
141 size
.y
= r
.bottom
- r
.top
;
148 * Metafile device context
152 // New constructor that takes origin and extent. If you use this, don't
153 // give origin/extent arguments to wxMakeMetaFilePlaceable.
155 wxMetaFileDC::wxMetaFileDC(const wxString
& filename
,
156 int width
, int height
,
157 const wxString
& WXUNUSED(description
) )
159 wxASSERT_MSG( width
== 0 || height
== 0 , _T("no arbitration of metafilesize supported") ) ;
160 wxASSERT_MSG( filename
.IsEmpty() , _T("no file based metafile support yet")) ;
162 m_metaFile
= new wxMetaFile(filename
) ;
163 Rect r
={0,0,height
,width
} ;
165 RectRgn( (RgnHandle
) m_macBoundaryClipRgn
, &r
) ;
166 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
168 m_metaFile
->SetHMETAFILE( OpenPicture( &r
) ) ;
169 ::GetPort( (GrafPtr
*) &m_macPort
) ;
172 SetMapMode(wxMM_TEXT
);
175 wxMetaFileDC::~wxMetaFileDC()
179 void wxMetaFileDC::DoGetSize(int *width
, int *height
) const
181 wxCHECK_RET( m_metaFile
, _T("GetSize() doesn't work without a metafile") );
183 wxSize sz
= m_metaFile
->GetSize() ;
184 if (width
) (*width
) = sz
.x
;
185 if (height
) (*height
) = sz
.y
;
188 wxMetaFile
*wxMetaFileDC::Close()
195 size_t wxMetafileDataObject::GetDataSize() const
197 return GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ;
200 bool wxMetafileDataObject::GetDataHere(void *buf
) const
202 memcpy( buf
, (*(PicHandle
)(*((wxMetafile
*)&m_metafile
)).GetHMETAFILE()) ,
203 GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ) ;
207 bool wxMetafileDataObject::SetData(size_t len
, const void *buf
)
209 Handle handle
= NewHandle( len
) ;
210 SetHandleSize( handle
, len
) ;
211 memcpy( *handle
, buf
, len
) ;
212 m_metafile
.SetHMETAFILE( handle
) ;