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