]>
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" 
  21 #include "wx/metafile.h" 
  28 #include "wx/clipbrd.h" 
  30 #include "wx/mac/private.h" 
  35 extern bool wxClipboardIsOpen
; 
  37 IMPLEMENT_DYNAMIC_CLASS(wxMetafile
, wxObject
) 
  38 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC
, wxDC
) 
  42  * Currently, the only purpose for making a metafile is to put 
  43  * it on the clipboard. 
  46 wxMetafileRefData::wxMetafileRefData(void) 
  51 wxMetafileRefData::~wxMetafileRefData(void) 
  55         KillPicture( (PicHandle
) m_metafile 
) ; 
  60 wxMetaFile::wxMetaFile(const wxString
& file
) 
  62     m_refData 
= new wxMetafileRefData
; 
  65     M_METAFILEDATA
->m_metafile 
= 0; 
  66     wxASSERT_MSG( file
.IsEmpty() , wxT("no file based metafile support yet") ) ; 
  69         M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file); 
  73 wxMetaFile::~wxMetaFile() 
  77 bool wxMetaFile::SetClipboard(int width
, int height
) 
  79 #if wxUSE_DRAG_AND_DROP 
  80     //TODO finishi this port , we need the data obj first 
  84     bool alreadyOpen
=wxTheClipboard
->IsOpened() ; 
  87         wxTheClipboard
->Open(); 
  88         wxTheClipboard
->Clear(); 
  91         new wxMetafileDataObject( *this) ; 
  92     bool success 
= wxTheClipboard
->SetData(data
); 
  94         wxTheClipboard
->Close(); 
  95     return (bool) success
; 
 100 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf
) 
 103         m_refData 
= new wxMetafileRefData
; 
 104     if ( M_METAFILEDATA
->m_metafile 
) 
 105         KillPicture( (PicHandle
) M_METAFILEDATA
->m_metafile 
) ; 
 107     M_METAFILEDATA
->m_metafile 
= mf
; 
 110 bool wxMetaFile::Play(wxDC 
*dc
) 
 119         wxMacPortSetter 
helper( dc 
) ; 
 120         PicHandle pict 
= (PicHandle
) GetHMETAFILE() ; 
 121         DrawPicture( pict 
, &(**pict
).picFrame 
) ; 
 126 wxSize 
wxMetaFile::GetSize() const 
 128     wxSize size 
= wxDefaultSize 
; 
 131         PicHandle pict 
= (PicHandle
) GetHMETAFILE() ; 
 132         Rect 
&r 
= (**pict
).picFrame 
; 
 133         size
.x 
= r
.right 
- r
.left 
; 
 134         size
.y 
= r
.bottom 
- r
.top 
; 
 141  * Metafile device context 
 145 // New constructor that takes origin and extent. If you use this, don't 
 146 // give origin/extent arguments to wxMakeMetaFilePlaceable. 
 148 wxMetaFileDC::wxMetaFileDC(const wxString
& filename 
, 
 149                            int width 
, int height 
, 
 150                            const wxString
& WXUNUSED(description
) ) 
 152     wxASSERT_MSG( width 
== 0 || height 
== 0 , _T("no arbitration of metafilesize supported") ) ; 
 153     wxASSERT_MSG( filename
.empty() , _T("no file based metafile support yet")) ; 
 155     m_metaFile 
= new wxMetaFile(filename
) ; 
 156     Rect r
={0,0,height
,width
} ; 
 158     RectRgn( (RgnHandle
) m_macBoundaryClipRgn 
, &r 
) ; 
 159     CopyRgn( (RgnHandle
) m_macBoundaryClipRgn 
, (RgnHandle
) m_macCurrentClipRgn 
) ; 
 161     m_metaFile
->SetHMETAFILE( OpenPicture( &r 
) ) ; 
 162     ::GetPort( (GrafPtr
*) &m_macPort 
) ; 
 165     SetMapMode(wxMM_TEXT
); 
 168 wxMetaFileDC::~wxMetaFileDC() 
 172 void wxMetaFileDC::DoGetSize(int *width
, int *height
) const 
 174     wxCHECK_RET( m_metaFile 
, _T("GetSize() doesn't work without a metafile") ); 
 176     wxSize sz 
= m_metaFile
->GetSize() ; 
 177     if (width
) (*width
) = sz
.x
; 
 178     if (height
) (*height
) = sz
.y
; 
 181 wxMetaFile 
*wxMetaFileDC::Close() 
 188 size_t wxMetafileDataObject::GetDataSize() const 
 190     return GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ; 
 193 bool wxMetafileDataObject::GetDataHere(void *buf
) const 
 195     memcpy( buf 
, (*(PicHandle
)(*((wxMetafile
*)&m_metafile
)).GetHMETAFILE()) , 
 196         GetHandleSize( (Handle
) (*((wxMetafile
*)&m_metafile
)).GetHMETAFILE() ) ) ; 
 200 bool wxMetafileDataObject::SetData(size_t len
, const void *buf
) 
 202     Handle handle 
= NewHandle( len 
) ; 
 203     SetHandleSize( handle 
, len 
) ; 
 204     memcpy( *handle 
, buf 
, len 
) ; 
 205     m_metafile
.SetHMETAFILE( handle 
) ;