]> git.saurik.com Git - wxWidgets.git/blame - src/mac/metafile.cpp
changed layout hints to proper determining aqua layout presence before
[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
519cb848
SC
37#include <stdio.h>
38#include <string.h>
39
e9576ca5
SC
40extern bool wxClipboardIsOpen;
41
2f1ae414 42#if !USE_SHARED_LIBRARY
519cb848
SC
43IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
44IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
2f1ae414 45#endif
e9576ca5 46
519cb848
SC
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 {
2f1ae414 62 KillPicture( m_metafile ) ;
519cb848
SC
63 m_metafile = 0;
64 }
65}
66
e9576ca5
SC
67wxMetaFile::wxMetaFile(const wxString& file)
68{
519cb848
SC
69 m_refData = new wxMetafileRefData;
70
71
72 M_METAFILEDATA->m_metafile = 0;
73 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
74/*
75 if (!file.IsNull() && (file.Cmp("") == 0))
76 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
77*/
e9576ca5
SC
78}
79
80wxMetaFile::~wxMetaFile()
81{
e9576ca5
SC
82}
83
84bool wxMetaFile::SetClipboard(int width, int height)
85{
f0822896
SC
86#if wxUSE_DRAG_AND_DROP
87//TODO finishi this port , we need the data obj first
519cb848
SC
88 if (!m_refData)
89 return FALSE;
2f1ae414 90
f0822896 91 bool alreadyOpen=wxTheClipboard->IsOpened() ;
e9576ca5
SC
92 if (!alreadyOpen)
93 {
f0822896 94 wxTheClipboard->Open();
a07c1212 95 wxTheClipboard->Clear();
e9576ca5 96 }
a07c1212
SC
97 wxDataObject *data =
98 new wxMetafileDataObject( *this) ;
99 bool success = wxTheClipboard->SetData(data);
100 if (!alreadyOpen)
101 wxTheClipboard->Close();
2f1ae414 102 return (bool) success;
f0822896 103#endif
519cb848 104 return TRUE ;
e9576ca5
SC
105}
106
2f1ae414
SC
107void wxMetafile::SetHMETAFILE(PicHandle mf)
108{
109 if (!m_refData)
110 m_refData = new wxMetafileRefData;
111
112 M_METAFILEDATA->m_metafile = mf;
113}
114
e9576ca5
SC
115bool wxMetaFile::Play(wxDC *dc)
116{
519cb848 117 if (!m_refData)
e9576ca5 118 return FALSE;
519cb848
SC
119
120 if (!dc->Ok() )
121 return FALSE;
122
519cb848 123 {
0eaa1d68 124 wxMacPortSetter helper( dc ) ;
519cb848
SC
125 PicHandle pict = GetHMETAFILE() ;
126 DrawPicture( pict , &(**pict).picFrame ) ;
127 }
519cb848 128 return TRUE;
e9576ca5
SC
129}
130
131/*
132 * Metafile device context
133 *
134 */
135
136// Original constructor that does not takes origin and extent. If you use this,
137// *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
138wxMetaFileDC::wxMetaFileDC(const wxString& file)
139{
519cb848
SC
140 m_metaFile = NULL;
141 m_minX = 10000;
142 m_minY = 10000;
143 m_maxX = -10000;
144 m_maxY = -10000;
145
146 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
147
2f1ae414
SC
148 m_metaFile = new wxMetaFile("") ;
149 Rect r={0,0,1000,1000} ;
519cb848 150
2f1ae414
SC
151 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
152 ::GetPort( &m_macPort ) ;
519cb848
SC
153 m_ok = TRUE ;
154
155 SetMapMode(wxMM_TEXT);
e9576ca5
SC
156}
157
158// New constructor that takes origin and extent. If you use this, don't
159// give origin/extent arguments to wxMakeMetaFilePlaceable.
519cb848 160
e9576ca5
SC
161wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
162{
519cb848
SC
163 m_minX = 10000;
164 m_minY = 10000;
165 m_maxX = -10000;
166 m_maxY = -10000;
e9576ca5 167
519cb848 168 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
e9576ca5 169
519cb848
SC
170 m_metaFile = new wxMetaFile("") ;
171 Rect r={yorg,xorg,yorg+yext,xorg+xext} ;
172
173 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
174 ::GetPort( &m_macPort ) ;
175 m_ok = TRUE ;
e9576ca5 176
519cb848 177 SetMapMode(wxMM_TEXT);
e9576ca5
SC
178}
179
519cb848 180wxMetaFileDC::~wxMetaFileDC()
e9576ca5 181{
e9576ca5
SC
182}
183
519cb848 184wxMetaFile *wxMetaFileDC::Close()
e9576ca5 185{
519cb848
SC
186 ClosePicture() ;
187 return m_metaFile;
e9576ca5
SC
188}
189
a07c1212
SC
190#if wxUSE_DATAOBJ
191size_t wxMetafileDataObject::GetDataSize() const
192{
193 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
194}
195
196bool wxMetafileDataObject::GetDataHere(void *buf) const
197{
198 memcpy( buf , (*(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
199 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
200 return true ;
201}
202
203bool wxMetafileDataObject::SetData(size_t len, const void *buf)
204{
205 Handle handle = (Handle) m_metafile.GetHMETAFILE() ;
206 SetHandleSize( handle , len ) ;
207 memcpy( *handle , buf , len ) ;
208 return true ;
209}
210#endif
211
e9576ca5 212#endif