]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "metafile.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #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 #if !USE_SHARED_LIBRARY
41 IMPLEMENT_DYNAMIC_CLASS(wxMetafile
, wxObject
)
42 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC
, wxDC
)
47 * Currently, the only purpose for making a metafile is to put
48 * it on the clipboard.
51 wxMetafileRefData::wxMetafileRefData(void)
56 wxMetafileRefData::~wxMetafileRefData(void)
60 KillPicture( (PicHandle
) m_metafile
) ;
65 wxMetaFile::wxMetaFile(const wxString
& file
)
67 m_refData
= new wxMetafileRefData
;
70 M_METAFILEDATA
->m_metafile
= 0;
71 wxASSERT_MSG( file
.IsEmpty() , wxT("no file based metafile support yet") ) ;
73 if (!file.IsNull() && (file.Cmp("") == 0))
74 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
78 wxMetaFile::~wxMetaFile()
82 bool wxMetaFile::SetClipboard(int width
, int height
)
84 #if wxUSE_DRAG_AND_DROP
85 //TODO finishi this port , we need the data obj first
89 bool alreadyOpen
=wxTheClipboard
->IsOpened() ;
92 wxTheClipboard
->Open();
93 wxTheClipboard
->Clear();
96 new wxMetafileDataObject( *this) ;
97 bool success
= wxTheClipboard
->SetData(data
);
99 wxTheClipboard
->Close();
100 return (bool) success
;
105 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf
)
108 m_refData
= new wxMetafileRefData
;
109 if ( M_METAFILEDATA
->m_metafile
)
110 KillPicture( (PicHandle
) M_METAFILEDATA
->m_metafile
) ;
112 M_METAFILEDATA
->m_metafile
= mf
;
115 bool wxMetaFile::Play(wxDC
*dc
)
124 wxMacPortSetter
helper( dc
) ;
125 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
126 DrawPicture( pict
, &(**pict
).picFrame
) ;
131 wxSize
wxMetaFile::GetSize() const
133 wxSize size
= wxDefaultSize
;
136 PicHandle pict
= (PicHandle
) GetHMETAFILE() ;
137 Rect
&r
= (**pict
).picFrame
;
138 size
.x
= r
.right
- r
.left
;
139 size
.y
= r
.bottom
- r
.top
;
146 * Metafile device context
150 // New constructor that takes origin and extent. If you use this, don't
151 // give origin/extent arguments to wxMakeMetaFilePlaceable.
153 wxMetaFileDC::wxMetaFileDC(const wxString
& filename
,
154 int width
, int height
,
155 const wxString
& WXUNUSED(description
) )
157 wxASSERT_MSG( width
== 0 || height
== 0 , _T("no arbitration of metafilesize supported") ) ;
158 wxASSERT_MSG( filename
.IsEmpty() , _T("no file based metafile support yet")) ;
160 m_metaFile
= new wxMetaFile(filename
) ;
161 Rect r
={0,0,height
,width
} ;
163 RectRgn( (RgnHandle
) m_macBoundaryClipRgn
, &r
) ;
164 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
166 m_metaFile
->SetHMETAFILE( OpenPicture( &r
) ) ;
167 ::GetPort( (GrafPtr
*) &m_macPort
) ;
170 SetMapMode(wxMM_TEXT
);
173 wxMetaFileDC::~wxMetaFileDC()
177 void wxMetaFileDC::DoGetSize(int *width
, int *height
) const
179 wxCHECK_RET( m_metaFile
, _T("GetSize() doesn't work without a metafile") );
181 wxSize sz
= m_metaFile
->GetSize() ;
182 if (width
) (*width
) = sz
.x
;
183 if (height
) (*height
) = sz
.y
;
186 wxMetaFile
*wxMetaFileDC::Close()
193 size_t wxMetafileDataObject::GetDataSize() const
195 return GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ;
198 bool wxMetafileDataObject::GetDataHere(void *buf
) const
200 memcpy( buf
, (*(PicHandle
)(*((wxMetafile
*)&m_metafile
)).GetHMETAFILE()) ,
201 GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ) ;
205 bool wxMetafileDataObject::SetData(size_t len
, const void *buf
)
207 Handle handle
= NewHandle( len
) ;
208 SetHandleSize( handle
, len
) ;
209 memcpy( *handle
, buf
, len
) ;
210 m_metafile
.SetHMETAFILE( handle
) ;