]> git.saurik.com Git - wxWidgets.git/blame - src/mac/metafile.cpp
fixed compilation warnings with GTK+ 2.0
[wxWidgets.git] / src / mac / metafile.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: metafile.cpp
3// Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
4// Author: AUTHOR
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
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 {
76a5e5d2 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;
75 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
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
SC
88#if wxUSE_DRAG_AND_DROP
89//TODO finishi this port , we need the data obj first
519cb848
SC
90 if (!m_refData)
91 return FALSE;
2f1ae414 92
f0822896 93 bool alreadyOpen=wxTheClipboard->IsOpened() ;
e9576ca5
SC
94 if (!alreadyOpen)
95 {
f0822896 96 wxTheClipboard->Open();
a07c1212 97 wxTheClipboard->Clear();
e9576ca5 98 }
a07c1212
SC
99 wxDataObject *data =
100 new wxMetafileDataObject( *this) ;
101 bool success = wxTheClipboard->SetData(data);
102 if (!alreadyOpen)
103 wxTheClipboard->Close();
2f1ae414 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;
113
114 M_METAFILEDATA->m_metafile = mf;
115}
116
e9576ca5
SC
117bool wxMetaFile::Play(wxDC *dc)
118{
519cb848 119 if (!m_refData)
e9576ca5 120 return FALSE;
519cb848
SC
121
122 if (!dc->Ok() )
123 return FALSE;
124
519cb848 125 {
0eaa1d68 126 wxMacPortSetter helper( dc ) ;
76a5e5d2 127 PicHandle pict = (PicHandle) GetHMETAFILE() ;
519cb848
SC
128 DrawPicture( pict , &(**pict).picFrame ) ;
129 }
519cb848 130 return TRUE;
e9576ca5
SC
131}
132
133/*
134 * Metafile device context
135 *
136 */
137
138// Original constructor that does not takes origin and extent. If you use this,
139// *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
140wxMetaFileDC::wxMetaFileDC(const wxString& file)
141{
519cb848
SC
142 m_metaFile = NULL;
143 m_minX = 10000;
144 m_minY = 10000;
145 m_maxX = -10000;
146 m_maxY = -10000;
147
148 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
149
2f1ae414
SC
150 m_metaFile = new wxMetaFile("") ;
151 Rect r={0,0,1000,1000} ;
519cb848 152
2f1ae414 153 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
76a5e5d2 154 ::GetPort( (GrafPtr*) &m_macPort ) ;
519cb848
SC
155 m_ok = TRUE ;
156
157 SetMapMode(wxMM_TEXT);
e9576ca5
SC
158}
159
160// New constructor that takes origin and extent. If you use this, don't
161// give origin/extent arguments to wxMakeMetaFilePlaceable.
519cb848 162
e9576ca5
SC
163wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
164{
519cb848
SC
165 m_minX = 10000;
166 m_minY = 10000;
167 m_maxX = -10000;
168 m_maxY = -10000;
e9576ca5 169
519cb848 170 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
e9576ca5 171
519cb848
SC
172 m_metaFile = new wxMetaFile("") ;
173 Rect r={yorg,xorg,yorg+yext,xorg+xext} ;
174
175 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
76a5e5d2 176 ::GetPort( (GrafPtr*) &m_macPort ) ;
519cb848 177 m_ok = TRUE ;
e9576ca5 178
519cb848 179 SetMapMode(wxMM_TEXT);
e9576ca5
SC
180}
181
519cb848 182wxMetaFileDC::~wxMetaFileDC()
e9576ca5 183{
e9576ca5
SC
184}
185
519cb848 186wxMetaFile *wxMetaFileDC::Close()
e9576ca5 187{
519cb848
SC
188 ClosePicture() ;
189 return m_metaFile;
e9576ca5
SC
190}
191
a07c1212
SC
192#if wxUSE_DATAOBJ
193size_t wxMetafileDataObject::GetDataSize() const
194{
195 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
196}
197
198bool wxMetafileDataObject::GetDataHere(void *buf) const
199{
76a5e5d2 200 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
a07c1212
SC
201 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
202 return true ;
203}
204
205bool wxMetafileDataObject::SetData(size_t len, const void *buf)
206{
207 Handle handle = (Handle) m_metafile.GetHMETAFILE() ;
208 SetHandleSize( handle , len ) ;
209 memcpy( *handle , buf , len ) ;
210 return true ;
211}
212#endif
213
e9576ca5 214#endif