]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/metafile.cpp
better handling of empty MDI parent frame visibility: show it only when there are...
[wxWidgets.git] / src / mac / classic / metafile.cpp
CommitLineData
2646f485
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: metafile.cpp
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
65571936 9// Licence: wxWindows licence
2646f485
SC
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
2646f485
SC
44IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
45IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
2646f485
SC
46
47/*
48 * Metafiles
49 * Currently, the only purpose for making a metafile is to put
50 * it on the clipboard.
51 */
52
53wxMetafileRefData::wxMetafileRefData(void)
54{
55 m_metafile = 0;
56}
57
58wxMetafileRefData::~wxMetafileRefData(void)
59{
60 if (m_metafile)
61 {
62 KillPicture( (PicHandle) m_metafile ) ;
63 m_metafile = 0;
64 }
65}
66
67wxMetaFile::wxMetaFile(const wxString& file)
68{
69 m_refData = new wxMetafileRefData;
70
71
72 M_METAFILEDATA->m_metafile = 0;
73 wxASSERT_MSG( file.IsEmpty() , wxT("no file based metafile support yet") ) ;
74/*
75 if (!file.IsNull() && (file.Cmp("") == 0))
76 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
77*/
78}
79
80wxMetaFile::~wxMetaFile()
81{
82}
83
84bool wxMetaFile::SetClipboard(int width, int height)
85{
86#if wxUSE_DRAG_AND_DROP
87 //TODO finishi this port , we need the data obj first
88 if (!m_refData)
89 return FALSE;
90
91 bool alreadyOpen=wxTheClipboard->IsOpened() ;
92 if (!alreadyOpen)
93 {
94 wxTheClipboard->Open();
95 wxTheClipboard->Clear();
96 }
97 wxDataObject *data =
98 new wxMetafileDataObject( *this) ;
99 bool success = wxTheClipboard->SetData(data);
100 if (!alreadyOpen)
101 wxTheClipboard->Close();
102 return (bool) success;
103#endif
104 return TRUE ;
105}
106
107void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
108{
109 if (!m_refData)
110 m_refData = new wxMetafileRefData;
111 if ( M_METAFILEDATA->m_metafile )
112 KillPicture( (PicHandle) M_METAFILEDATA->m_metafile ) ;
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
133wxSize wxMetaFile::GetSize() const
134{
135 wxSize size = wxDefaultSize ;
136 if ( Ok() )
137 {
138 PicHandle pict = (PicHandle) GetHMETAFILE() ;
139 Rect &r = (**pict).picFrame ;
140 size.x = r.right - r.left ;
141 size.y = r.bottom - r.top ;
142 }
143
144 return size;
145}
146
147/*
148 * Metafile device context
149 *
150 */
151
152// New constructor that takes origin and extent. If you use this, don't
153// give origin/extent arguments to wxMakeMetaFilePlaceable.
154
155wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
156 int width , int height ,
157 const wxString& WXUNUSED(description) )
158{
159 wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
160 wxASSERT_MSG( filename.IsEmpty() , _T("no file based metafile support yet")) ;
161
162 m_metaFile = new wxMetaFile(filename) ;
163 Rect r={0,0,height,width} ;
164
165 RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
166 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
167
168 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
169 ::GetPort( (GrafPtr*) &m_macPort ) ;
170 m_ok = TRUE ;
171
172 SetMapMode(wxMM_TEXT);
173}
174
175wxMetaFileDC::~wxMetaFileDC()
176{
177}
178
179void wxMetaFileDC::DoGetSize(int *width, int *height) const
180{
181 wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
182
183 wxSize sz = m_metaFile->GetSize() ;
184 if (width) (*width) = sz.x;
185 if (height) (*height) = sz.y;
186}
187
188wxMetaFile *wxMetaFileDC::Close()
189{
190 ClosePicture() ;
191 return m_metaFile;
192}
193
194#if wxUSE_DATAOBJ
195size_t wxMetafileDataObject::GetDataSize() const
196{
197 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
198}
199
200bool wxMetafileDataObject::GetDataHere(void *buf) const
201{
202 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
203 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
204 return true ;
205}
206
207bool wxMetafileDataObject::SetData(size_t len, const void *buf)
208{
209 Handle handle = NewHandle( len ) ;
210 SetHandleSize( handle , len ) ;
211 memcpy( *handle , buf , len ) ;
212 m_metafile.SetHMETAFILE( handle ) ;
213 return true ;
214}
215#endif
216
217#endif