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