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