]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/metafile.cpp
Add wx.ListBox.HitTest
[wxWidgets.git] / 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
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_METAFILE
20
21 #ifndef WX_PRECOMP
22 #include "wx/utils.h"
23 #include "wx/app.h"
24 #endif
25
26 #include "wx/metafile.h"
27 #include "wx/clipbrd.h"
28
29 #include "wx/mac/private.h"
30
31 #include <stdio.h>
32 #include <string.h>
33
34 extern bool wxClipboardIsOpen;
35
36 IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
37 IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
38
39 /*
40 * Metafiles
41 * Currently, the only purpose for making a metafile is to put
42 * it on the clipboard.
43 */
44
45 wxMetafileRefData::wxMetafileRefData(void)
46 {
47 m_metafile = 0;
48 }
49
50 wxMetafileRefData::~wxMetafileRefData(void)
51 {
52 if (m_metafile)
53 {
54 KillPicture( (PicHandle) m_metafile ) ;
55 m_metafile = 0;
56 }
57 }
58
59 wxMetaFile::wxMetaFile(const wxString& file)
60 {
61 m_refData = new wxMetafileRefData;
62
63
64 M_METAFILEDATA->m_metafile = 0;
65 wxASSERT_MSG( file.IsEmpty() , wxT("no file based metafile support yet") ) ;
66 /*
67 if (!file.empty())
68 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
69 */
70 }
71
72 wxMetaFile::~wxMetaFile()
73 {
74 }
75
76 bool wxMetaFile::SetClipboard(int width, int height)
77 {
78 #if wxUSE_DRAG_AND_DROP
79 //TODO finishi this port , we need the data obj first
80 if (!m_refData)
81 return false;
82
83 bool alreadyOpen=wxTheClipboard->IsOpened() ;
84 if (!alreadyOpen)
85 {
86 wxTheClipboard->Open();
87 wxTheClipboard->Clear();
88 }
89 wxDataObject *data =
90 new wxMetafileDataObject( *this) ;
91 bool success = wxTheClipboard->SetData(data);
92 if (!alreadyOpen)
93 wxTheClipboard->Close();
94 return (bool) success;
95 #endif
96 return true ;
97 }
98
99 void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
100 {
101 if (!m_refData)
102 m_refData = new wxMetafileRefData;
103 if ( M_METAFILEDATA->m_metafile )
104 KillPicture( (PicHandle) M_METAFILEDATA->m_metafile ) ;
105
106 M_METAFILEDATA->m_metafile = mf;
107 }
108
109 bool wxMetaFile::Play(wxDC *dc)
110 {
111 if (!m_refData)
112 return false;
113
114 if (!dc->Ok() )
115 return false;
116
117 {
118 wxMacPortSetter helper( dc ) ;
119 PicHandle pict = (PicHandle) GetHMETAFILE() ;
120 DrawPicture( pict , &(**pict).picFrame ) ;
121 }
122 return true;
123 }
124
125 wxSize wxMetaFile::GetSize() const
126 {
127 wxSize size = wxDefaultSize ;
128 if ( Ok() )
129 {
130 PicHandle pict = (PicHandle) GetHMETAFILE() ;
131 Rect &r = (**pict).picFrame ;
132 size.x = r.right - r.left ;
133 size.y = r.bottom - r.top ;
134 }
135
136 return size;
137 }
138
139 /*
140 * Metafile device context
141 *
142 */
143
144 // New constructor that takes origin and extent. If you use this, don't
145 // give origin/extent arguments to wxMakeMetaFilePlaceable.
146
147 wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
148 int width , int height ,
149 const wxString& WXUNUSED(description) )
150 {
151 wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
152 wxASSERT_MSG( filename.empty() , _T("no file based metafile support yet")) ;
153
154 m_metaFile = new wxMetaFile(filename) ;
155 Rect r={0,0,height,width} ;
156
157 RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
158 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
159
160 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
161 ::GetPort( (GrafPtr*) &m_macPort ) ;
162 m_ok = true ;
163
164 SetMapMode(wxMM_TEXT);
165 }
166
167 wxMetaFileDC::~wxMetaFileDC()
168 {
169 }
170
171 void wxMetaFileDC::DoGetSize(int *width, int *height) const
172 {
173 wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
174
175 wxSize sz = m_metaFile->GetSize() ;
176 if (width) (*width) = sz.x;
177 if (height) (*height) = sz.y;
178 }
179
180 wxMetaFile *wxMetaFileDC::Close()
181 {
182 ClosePicture() ;
183 return m_metaFile;
184 }
185
186 #if wxUSE_DATAOBJ
187 size_t wxMetafileDataObject::GetDataSize() const
188 {
189 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
190 }
191
192 bool wxMetafileDataObject::GetDataHere(void *buf) const
193 {
194 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
195 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
196 return true ;
197 }
198
199 bool wxMetafileDataObject::SetData(size_t len, const void *buf)
200 {
201 Handle handle = NewHandle( len ) ;
202 SetHandleSize( handle , len ) ;
203 memcpy( *handle , buf , len ) ;
204 m_metafile.SetHMETAFILE( handle ) ;
205 return true ;
206 }
207 #endif
208
209 #endif