]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/metafile.cpp
corrected path splitting for mac relative paths
[wxWidgets.git] / src / mac / carbon / metafile.cpp
... / ...
CommitLineData
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 "wx/mac/private.h"
38
39#include <stdio.h>
40#include <string.h>
41
42extern bool wxClipboardIsOpen;
43
44#if !USE_SHARED_LIBRARY
45IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
46IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
47#endif
48
49/*
50 * Metafiles
51 * Currently, the only purpose for making a metafile is to put
52 * it on the clipboard.
53 */
54
55wxMetafileRefData::wxMetafileRefData(void)
56{
57 m_metafile = 0;
58}
59
60wxMetafileRefData::~wxMetafileRefData(void)
61{
62 if (m_metafile)
63 {
64 KillPicture( (PicHandle) m_metafile ) ;
65 m_metafile = 0;
66 }
67}
68
69wxMetaFile::wxMetaFile(const wxString& file)
70{
71 m_refData = new wxMetafileRefData;
72
73
74 M_METAFILEDATA->m_metafile = 0;
75 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
76/*
77 if (!file.IsNull() && (file.Cmp("") == 0))
78 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
79*/
80}
81
82wxMetaFile::~wxMetaFile()
83{
84}
85
86bool wxMetaFile::SetClipboard(int width, int height)
87{
88#if wxUSE_DRAG_AND_DROP
89//TODO finishi this port , we need the data obj first
90 if (!m_refData)
91 return FALSE;
92
93 bool alreadyOpen=wxTheClipboard->IsOpened() ;
94 if (!alreadyOpen)
95 {
96 wxTheClipboard->Open();
97 wxTheClipboard->Clear();
98 }
99 wxDataObject *data =
100 new wxMetafileDataObject( *this) ;
101 bool success = wxTheClipboard->SetData(data);
102 if (!alreadyOpen)
103 wxTheClipboard->Close();
104 return (bool) success;
105#endif
106 return TRUE ;
107}
108
109void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
110{
111 if (!m_refData)
112 m_refData = new wxMetafileRefData;
113
114 M_METAFILEDATA->m_metafile = mf;
115}
116
117bool wxMetaFile::Play(wxDC *dc)
118{
119 if (!m_refData)
120 return FALSE;
121
122 if (!dc->Ok() )
123 return FALSE;
124
125 {
126 wxMacPortSetter helper( dc ) ;
127 PicHandle pict = (PicHandle) GetHMETAFILE() ;
128 DrawPicture( pict , &(**pict).picFrame ) ;
129 }
130 return TRUE;
131}
132
133/*
134 * Metafile device context
135 *
136 */
137
138// Original constructor that does not takes origin and extent. If you use this,
139// *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
140wxMetaFileDC::wxMetaFileDC(const wxString& file)
141{
142 m_metaFile = NULL;
143 m_minX = 10000;
144 m_minY = 10000;
145 m_maxX = -10000;
146 m_maxY = -10000;
147
148 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
149
150 m_metaFile = new wxMetaFile("") ;
151 Rect r={0,0,1000,1000} ;
152
153 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
154 ::GetPort( (GrafPtr*) &m_macPort ) ;
155 m_ok = TRUE ;
156
157 SetMapMode(wxMM_TEXT);
158}
159
160// New constructor that takes origin and extent. If you use this, don't
161// give origin/extent arguments to wxMakeMetaFilePlaceable.
162
163wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
164{
165 m_minX = 10000;
166 m_minY = 10000;
167 m_maxX = -10000;
168 m_maxY = -10000;
169
170 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
171
172 m_metaFile = new wxMetaFile("") ;
173 Rect r={yorg,xorg,yorg+yext,xorg+xext} ;
174
175 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
176 ::GetPort( (GrafPtr*) &m_macPort ) ;
177 m_ok = TRUE ;
178
179 SetMapMode(wxMM_TEXT);
180}
181
182wxMetaFileDC::~wxMetaFileDC()
183{
184}
185
186wxMetaFile *wxMetaFileDC::Close()
187{
188 ClosePicture() ;
189 return m_metaFile;
190}
191
192#if wxUSE_DATAOBJ
193size_t wxMetafileDataObject::GetDataSize() const
194{
195 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
196}
197
198bool wxMetafileDataObject::GetDataHere(void *buf) const
199{
200 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
201 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
202 return true ;
203}
204
205bool wxMetafileDataObject::SetData(size_t len, const void *buf)
206{
207 Handle handle = (Handle) m_metafile.GetHMETAFILE() ;
208 SetHandleSize( handle , len ) ;
209 memcpy( *handle , buf , len ) ;
210 return true ;
211}
212#endif
213
214#endif