]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/metafile.cpp
don't generate wxEVT_CONTEXT_MENU messages for right clicks in the list control header
[wxWidgets.git] / src / mac / classic / metafile.cpp
CommitLineData
2646f485 1/////////////////////////////////////////////////////////////////////////////
0ba6a836 2// Name: src/mac/classic/metafile.cpp
2646f485
SC
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
2646f485
SC
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
2646f485
SC
19#if wxUSE_METAFILE
20
21#ifndef WX_PRECOMP
22#include "wx/utils.h"
23#include "wx/app.h"
24#endif
25
26#include "wx/metafile.h"
27#include "wx/clipbrd.h"
28
29#include "wx/mac/private.h"
30
31#include <stdio.h>
32#include <string.h>
33
34extern bool wxClipboardIsOpen;
35
2646f485
SC
36IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject)
37IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC)
2646f485
SC
38
39/*
40 * Metafiles
41 * Currently, the only purpose for making a metafile is to put
42 * it on the clipboard.
43 */
44
45wxMetafileRefData::wxMetafileRefData(void)
46{
47 m_metafile = 0;
48}
49
50wxMetafileRefData::~wxMetafileRefData(void)
51{
52 if (m_metafile)
53 {
54 KillPicture( (PicHandle) m_metafile ) ;
55 m_metafile = 0;
56 }
57}
58
59wxMetaFile::wxMetaFile(const wxString& file)
60{
61 m_refData = new wxMetafileRefData;
62
63
64 M_METAFILEDATA->m_metafile = 0;
65 wxASSERT_MSG( file.IsEmpty() , wxT("no file based metafile support yet") ) ;
66/*
0ba6a836 67 if (!file.empty())
2646f485
SC
68 M_METAFILEDATA->m_metafile = (WXHANDLE) GetMetaFile(file);
69*/
70}
71
72wxMetaFile::~wxMetaFile()
73{
74}
75
76bool wxMetaFile::SetClipboard(int width, int height)
77{
78#if wxUSE_DRAG_AND_DROP
79 //TODO finishi this port , we need the data obj first
80 if (!m_refData)
0ba6a836
WS
81 return false;
82
2646f485
SC
83 bool alreadyOpen=wxTheClipboard->IsOpened() ;
84 if (!alreadyOpen)
85 {
86 wxTheClipboard->Open();
87 wxTheClipboard->Clear();
88 }
89 wxDataObject *data =
90 new wxMetafileDataObject( *this) ;
91 bool success = wxTheClipboard->SetData(data);
0ba6a836 92 if (!alreadyOpen)
2646f485
SC
93 wxTheClipboard->Close();
94 return (bool) success;
95#endif
0ba6a836 96 return true ;
2646f485
SC
97}
98
99void wxMetafile::SetHMETAFILE(WXHMETAFILE mf)
100{
101 if (!m_refData)
102 m_refData = new wxMetafileRefData;
103 if ( M_METAFILEDATA->m_metafile )
104 KillPicture( (PicHandle) M_METAFILEDATA->m_metafile ) ;
105
106 M_METAFILEDATA->m_metafile = mf;
107}
108
109bool wxMetaFile::Play(wxDC *dc)
110{
111 if (!m_refData)
0ba6a836
WS
112 return false;
113
2646f485 114 if (!dc->Ok() )
0ba6a836
WS
115 return false;
116
2646f485
SC
117 {
118 wxMacPortSetter helper( dc ) ;
119 PicHandle pict = (PicHandle) GetHMETAFILE() ;
120 DrawPicture( pict , &(**pict).picFrame ) ;
121 }
0ba6a836 122 return true;
2646f485
SC
123}
124
125wxSize wxMetaFile::GetSize() const
126{
127 wxSize size = wxDefaultSize ;
128 if ( Ok() )
129 {
130 PicHandle pict = (PicHandle) GetHMETAFILE() ;
131 Rect &r = (**pict).picFrame ;
132 size.x = r.right - r.left ;
133 size.y = r.bottom - r.top ;
134 }
135
136 return size;
137}
138
139/*
140 * Metafile device context
141 *
142 */
143
144// New constructor that takes origin and extent. If you use this, don't
145// give origin/extent arguments to wxMakeMetaFilePlaceable.
146
147wxMetaFileDC::wxMetaFileDC(const wxString& filename ,
0ba6a836
WS
148 int width , int height ,
149 const wxString& WXUNUSED(description) )
2646f485
SC
150{
151 wxASSERT_MSG( width == 0 || height == 0 , _T("no arbitration of metafilesize supported") ) ;
0ba6a836
WS
152 wxASSERT_MSG( filename.empty() , _T("no file based metafile support yet")) ;
153
2646f485
SC
154 m_metaFile = new wxMetaFile(filename) ;
155 Rect r={0,0,height,width} ;
0ba6a836 156
2646f485
SC
157 RectRgn( (RgnHandle) m_macBoundaryClipRgn , &r ) ;
158 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
159
160 m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ;
0ba6a836
WS
161 ::GetPort( (GrafPtr*) &m_macPort ) ;
162 m_ok = true ;
163
164 SetMapMode(wxMM_TEXT);
2646f485
SC
165}
166
167wxMetaFileDC::~wxMetaFileDC()
168{
169}
170
171void wxMetaFileDC::DoGetSize(int *width, int *height) const
172{
173 wxCHECK_RET( m_metaFile , _T("GetSize() doesn't work without a metafile") );
174
175 wxSize sz = m_metaFile->GetSize() ;
176 if (width) (*width) = sz.x;
177 if (height) (*height) = sz.y;
178}
179
180wxMetaFile *wxMetaFileDC::Close()
181{
182 ClosePicture() ;
183 return m_metaFile;
184}
185
186#if wxUSE_DATAOBJ
187size_t wxMetafileDataObject::GetDataSize() const
188{
189 return GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ;
190}
191
192bool wxMetafileDataObject::GetDataHere(void *buf) const
193{
194 memcpy( buf , (*(PicHandle)(*((wxMetafile*)&m_metafile)).GetHMETAFILE()) ,
195 GetHandleSize( (Handle) (*((wxMetafile*)&m_metafile)).GetHMETAFILE() ) ) ;
196 return true ;
197}
198
199bool wxMetafileDataObject::SetData(size_t len, const void *buf)
200{
201 Handle handle = NewHandle( len ) ;
202 SetHandleSize( handle , len ) ;
203 memcpy( *handle , buf , len ) ;
204 m_metafile.SetHMETAFILE( handle ) ;
205 return true ;
206}
207#endif
208
209#endif