]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/metafile.cpp
Fix centering of top-level children of wxMDIParentFrame on Mac
[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
12#ifdef __GNUG__
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
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"
e9576ca5
SC
35#include "wx/clipbrd.h"
36
76a5e5d2
SC
37#include "wx/mac/private.h"
38
519cb848
SC
39#include <stdio.h>
40#include <string.h>
41
e9576ca5
SC
42extern bool wxClipboardIsOpen;
43
2f1ae414 44#if !USE_SHARED_LIBRARY
519cb848
SC
45IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
46IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
2f1ae414 47#endif
e9576ca5 48
519cb848
SC
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 {
e40298d5 64 KillPicture( (PicHandle) m_metafile ) ;
519cb848
SC
65 m_metafile = 0;
66 }
67}
68
e9576ca5
SC
69wxMetaFile::wxMetaFile(const wxString& file)
70{
519cb848
SC
71 m_refData = new wxMetafileRefData;
72
73
74 M_METAFILEDATA->m_metafile = 0;
427ff662 75 wxASSERT_MSG( file.IsEmpty() , wxT("no file based metafile support yet") ) ;
519cb848
SC
76/*
77 if (!file.IsNull() && (file.Cmp("") == 0))
78 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
79*/
e9576ca5
SC
80}
81
82wxMetaFile::~wxMetaFile()
83{
e9576ca5
SC
84}
85
86bool wxMetaFile::SetClipboard(int width, int height)
87{
f0822896 88#if wxUSE_DRAG_AND_DROP
e40298d5 89 //TODO finishi this port , we need the data obj first
519cb848
SC
90 if (!m_refData)
91 return FALSE;
e40298d5 92
f0822896 93 bool alreadyOpen=wxTheClipboard->IsOpened() ;
e9576ca5
SC
94 if (!alreadyOpen)
95 {
f0822896 96 wxTheClipboard->Open();
a07c1212 97 wxTheClipboard->Clear();
e9576ca5 98 }
a07c1212 99 wxDataObject *data =
e40298d5 100 new wxMetafileDataObject( *this) ;
a07c1212
SC
101 bool success = wxTheClipboard->SetData(data);
102 if (!alreadyOpen)
e40298d5
JS
103 wxTheClipboard->Close();
104 return (bool) success;
f0822896 105#endif
519cb848 106 return TRUE ;
e9576ca5
SC
107}
108
76a5e5d2 109void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
2f1ae414
SC
110{
111 if (!m_refData)
112 m_refData = new wxMetafileRefData;
48de597b
SC
113 if ( M_METAFILEDATA->m_metafile )
114 KillPicture( (PicHandle) M_METAFILEDATA->m_metafile ) ;
2f1ae414
SC
115
116 M_METAFILEDATA->m_metafile = mf;
117}
118
e9576ca5
SC
119bool wxMetaFile::Play(wxDC *dc)
120{
e40298d5
JS
121 if (!m_refData)
122 return FALSE;
123
124 if (!dc->Ok() )
125 return FALSE;
126
127 {
128 wxMacPortSetter helper( dc ) ;
129 PicHandle pict = (PicHandle) GetHMETAFILE() ;
130 DrawPicture( pict , &(**pict).picFrame ) ;
131 }
519cb848 132 return TRUE;
e9576ca5
SC
133}
134
48de597b
SC
135wxSize wxMetaFile::GetSize() const
136{
137 wxSize size = wxDefaultSize ;
138 if ( Ok() )
139 {
140 PicHandle pict = (PicHandle) GetHMETAFILE() ;
141 Rect &r = (**pict).picFrame ;
142 size.x = r.right - r.left ;
143 size.y = r.bottom - r.top ;
144 }
145
146 return size;
147}
148
e9576ca5
SC
149/*
150 * Metafile device context
151 *
152 */
153
e9576ca5
SC
154// New constructor that takes origin and extent. If you use this, don't
155// give origin/extent arguments to wxMakeMetaFilePlaceable.
519cb848 156
48de597b
SC
157wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
158 int width , int height ,
159 const wxString& WXUNUSED(description) )
e9576ca5 160{
48de597b
SC
161 wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
162 wxASSERT_MSG( filename.IsEmpty() , _T("no file based metafile support yet")) ;
e40298d5 163
48de597b
SC
164 m_metaFile = new wxMetaFile(filename) ;
165 Rect r={0,0,height,width} ;
e40298d5 166
48de597b
SC
167 RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
168 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
169
e40298d5
JS
170 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
171 ::GetPort( (GrafPtr*) &m_macPort ) ;
172 m_ok = TRUE ;
173
174 SetMapMode(wxMM_TEXT);
e9576ca5
SC
175}
176
519cb848 177wxMetaFileDC::~wxMetaFileDC()
e9576ca5 178{
e9576ca5
SC
179}
180
48de597b
SC
181void wxMetaFileDC::DoGetSize(int *width, int *height) const
182{
183 wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
184
185 wxSize sz = m_metaFile->GetSize() ;
186 if (width) (*width) = sz.x;
187 if (height) (*height) = sz.y;
188}
189
519cb848 190wxMetaFile *wxMetaFileDC::Close()
e9576ca5 191{
e40298d5
JS
192 ClosePicture() ;
193 return m_metaFile;
e9576ca5
SC
194}
195
a07c1212
SC
196#if wxUSE_DATAOBJ
197size_t wxMetafileDataObject::GetDataSize() const
198{
e40298d5 199 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
a07c1212
SC
200}
201
202bool wxMetafileDataObject::GetDataHere(void *buf) const
203{
e40298d5
JS
204 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
205 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
206 return true ;
a07c1212
SC
207}
208
209bool wxMetafileDataObject::SetData(size_t len, const void *buf)
210{
48de597b 211 Handle handle = NewHandle( len ) ;
e40298d5
JS
212 SetHandleSize( handle , len ) ;
213 memcpy( *handle , buf , len ) ;
48de597b 214 m_metafile.SetHMETAFILE( handle ) ;
e40298d5 215 return true ;
a07c1212
SC
216}
217#endif
218
e9576ca5 219#endif