]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/metafile.cpp
use MoreFiles under Mac OS X
[wxWidgets.git] / src / mac / carbon / 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
SC
94 wxTheClipboard->Open();
95 if (!wxTheClipboard->Clear()) return FALSE;
e9576ca5 96 }
519cb848 97 bool success = wxSetClipboardData(wxDF_METAFILE, this, width,height);
e9576ca5 98 if (!alreadyOpen) wxCloseClipboard();
2f1ae414 99 return (bool) success;
f0822896 100#endif
519cb848 101 return TRUE ;
e9576ca5
SC
102}
103
2f1ae414
SC
104void wxMetafile::SetHMETAFILE(PicHandle mf)
105{
106 if (!m_refData)
107 m_refData = new wxMetafileRefData;
108
109 M_METAFILEDATA->m_metafile = mf;
110}
111
e9576ca5
SC
112bool wxMetaFile::Play(wxDC *dc)
113{
519cb848 114 if (!m_refData)
e9576ca5 115 return FALSE;
519cb848
SC
116
117 if (!dc->Ok() )
118 return FALSE;
119
519cb848 120 {
0eaa1d68 121 wxMacPortSetter helper( dc ) ;
519cb848
SC
122 PicHandle pict = GetHMETAFILE() ;
123 DrawPicture( pict , &(**pict).picFrame ) ;
124 }
519cb848 125 return TRUE;
e9576ca5
SC
126}
127
128/*
129 * Metafile device context
130 *
131 */
132
133// Original constructor that does not takes origin and extent. If you use this,
134// *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
135wxMetaFileDC::wxMetaFileDC(const wxString& file)
136{
519cb848
SC
137 m_metaFile = NULL;
138 m_minX = 10000;
139 m_minY = 10000;
140 m_maxX = -10000;
141 m_maxY = -10000;
142
143 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
144
2f1ae414
SC
145 m_metaFile = new wxMetaFile("") ;
146 Rect r={0,0,1000,1000} ;
519cb848 147
2f1ae414
SC
148 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
149 ::GetPort( &m_macPort ) ;
519cb848
SC
150 m_ok = TRUE ;
151
152 SetMapMode(wxMM_TEXT);
e9576ca5
SC
153}
154
155// New constructor that takes origin and extent. If you use this, don't
156// give origin/extent arguments to wxMakeMetaFilePlaceable.
519cb848 157
e9576ca5
SC
158wxMetaFileDC::wxMetaFileDC(const wxString& file, int xext, int yext, int xorg, int yorg)
159{
519cb848
SC
160 m_minX = 10000;
161 m_minY = 10000;
162 m_maxX = -10000;
163 m_maxY = -10000;
e9576ca5 164
519cb848 165 wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ;
e9576ca5 166
519cb848
SC
167 m_metaFile = new wxMetaFile("") ;
168 Rect r={yorg,xorg,yorg+yext,xorg+xext} ;
169
170 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
171 ::GetPort( &m_macPort ) ;
172 m_ok = TRUE ;
e9576ca5 173
519cb848 174 SetMapMode(wxMM_TEXT);
e9576ca5
SC
175}
176
519cb848 177wxMetaFileDC::~wxMetaFileDC()
e9576ca5 178{
e9576ca5
SC
179}
180
519cb848 181wxMetaFile *wxMetaFileDC::Close()
e9576ca5 182{
519cb848
SC
183 ClosePicture() ;
184 return m_metaFile;
e9576ca5
SC
185}
186
e9576ca5 187#endif