]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/metafile.cpp
Patch by David Brinegar to fix menubar updating after modal dialog shown
[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 {
20b69855
SC
124#if wxMAC_USE_CORE_GRAPHICS
125#else
e40298d5
JS
126 wxMacPortSetter helper( dc ) ;
127 PicHandle pict = (PicHandle) GetHMETAFILE() ;
128 DrawPicture( pict , &(**pict).picFrame ) ;
20b69855 129#endif
e40298d5 130 }
519cb848 131 return TRUE;
e9576ca5
SC
132}
133
48de597b
SC
134wxSize wxMetaFile::GetSize() const
135{
136 wxSize size = wxDefaultSize ;
137 if ( Ok() )
138 {
139 PicHandle pict = (PicHandle) GetHMETAFILE() ;
140 Rect &r = (**pict).picFrame ;
141 size.x = r.right - r.left ;
142 size.y = r.bottom - r.top ;
143 }
144
145 return size;
146}
147
e9576ca5
SC
148/*
149 * Metafile device context
150 *
151 */
152
e9576ca5
SC
153// New constructor that takes origin and extent. If you use this, don't
154// give origin/extent arguments to wxMakeMetaFilePlaceable.
519cb848 155
48de597b
SC
156wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
157 int width , int height ,
158 const wxString& WXUNUSED(description) )
e9576ca5 159{
48de597b
SC
160 wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
161 wxASSERT_MSG( filename.IsEmpty() , _T("no file based metafile support yet")) ;
e40298d5 162
48de597b 163 m_metaFile = new wxMetaFile(filename) ;
20b69855
SC
164#if wxMAC_USE_CORE_GRAPHICS
165#else
48de597b 166 Rect r={0,0,height,width} ;
e40298d5 167
48de597b
SC
168 RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
169 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
170
20b69855 171 m_metaFile->SetHMETAFILE( (WXHMETAFILE) OpenPicture( &r ) ) ;
e40298d5
JS
172 ::GetPort( (GrafPtr*) &m_macPort ) ;
173 m_ok = TRUE ;
20b69855 174#endif
e40298d5 175 SetMapMode(wxMM_TEXT);
e9576ca5
SC
176}
177
519cb848 178wxMetaFileDC::~wxMetaFileDC()
e9576ca5 179{
e9576ca5
SC
180}
181
48de597b
SC
182void wxMetaFileDC::DoGetSize(int *width, int *height) const
183{
184 wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
185
186 wxSize sz = m_metaFile->GetSize() ;
187 if (width) (*width) = sz.x;
188 if (height) (*height) = sz.y;
189}
190
519cb848 191wxMetaFile *wxMetaFileDC::Close()
e9576ca5 192{
e40298d5
JS
193 ClosePicture() ;
194 return m_metaFile;
e9576ca5
SC
195}
196
a07c1212
SC
197#if wxUSE_DATAOBJ
198size_t wxMetafileDataObject::GetDataSize() const
199{
e40298d5 200 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
a07c1212
SC
201}
202
203bool wxMetafileDataObject::GetDataHere(void *buf) const
204{
e40298d5
JS
205 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
206 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
207 return true ;
a07c1212
SC
208}
209
210bool wxMetafileDataObject::SetData(size_t len, const void *buf)
211{
48de597b 212 Handle handle = NewHandle( len ) ;
e40298d5
JS
213 SetHandleSize( handle , len ) ;
214 memcpy( *handle , buf , len ) ;
20b69855 215 m_metafile.SetHMETAFILE( (WXHMETAFILE) handle ) ;
e40298d5 216 return true ;
a07c1212
SC
217}
218#endif
219
e9576ca5 220#endif