]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/clipbrd.cpp
Update to wxDataViewCtrl from Hartwig
[wxWidgets.git] / src / mac / carbon / clipbrd.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/clipbrd.cpp
3// Purpose: Clipboard functionality
4// Author: Stefan Csomor;
5// Generalized clipboard implementation by Matthew Flatt
6// Modified by:
7// Created: 1998-01-01
8// RCS-ID: $Id$
9// Copyright: (c) Stefan Csomor
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#include "wx/wxprec.h"
14
15#if wxUSE_CLIPBOARD
16
17#include "wx/clipbrd.h"
18
19#ifndef WX_PRECOMP
20 #include "wx/intl.h"
21 #include "wx/log.h"
22 #include "wx/app.h"
23 #include "wx/utils.h"
24 #include "wx/frame.h"
25 #include "wx/bitmap.h"
26#endif
27
28#include "wx/metafile.h"
29
30#include "wx/mac/uma.h"
31
32#define wxUSE_DATAOBJ 1
33
34#include <string.h>
35
36
37// the trace mask we use with wxLogTrace() - call
38// wxLog::AddTraceMask(TRACE_CLIPBOARD) to enable the trace messages from here
39// (there will be a *lot* of them!)
40static const wxChar *TRACE_CLIPBOARD = wxT("clipboard");
41
42IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
43
44wxClipboard::wxClipboard()
45{
46 m_open = false;
47 m_data = NULL ;
48 PasteboardRef clipboard = 0;
49 OSStatus err = PasteboardCreate( kPasteboardClipboard, &clipboard );
50 if (err != noErr)
51 {
52 wxLogSysError( wxT("Failed to create the clipboard.") );
53 }
54 m_pasteboard.reset(clipboard);
55}
56
57wxClipboard::~wxClipboard()
58{
59 m_pasteboard.reset((PasteboardRef)0);
60 delete m_data;
61}
62
63void wxClipboard::Clear()
64{
65 if (m_data != NULL)
66 {
67 delete m_data;
68 m_data = NULL;
69 }
70
71 OSStatus err = PasteboardClear( m_pasteboard );
72 if (err != noErr)
73 {
74 wxLogSysError( wxT("Failed to empty the clipboard.") );
75 }
76}
77
78bool wxClipboard::Flush()
79{
80 return false;
81}
82
83bool wxClipboard::Open()
84{
85 wxCHECK_MSG( !m_open, false, wxT("clipboard already open") );
86
87 m_open = true;
88
89 return true;
90}
91
92bool wxClipboard::IsOpened() const
93{
94 return m_open;
95}
96
97bool wxClipboard::SetData( wxDataObject *data )
98{
99 if ( IsUsingPrimarySelection() )
100 return false;
101
102 wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
103 wxCHECK_MSG( data, false, wxT("data is invalid") );
104
105 Clear();
106
107 // as we can only store one wxDataObject,
108 // this is the same in this implementation
109 return AddData( data );
110}
111
112bool wxClipboard::AddData( wxDataObject *data )
113{
114 if ( IsUsingPrimarySelection() )
115 return false;
116
117 wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
118 wxCHECK_MSG( data, false, wxT("data is invalid") );
119
120 // we can only store one wxDataObject
121 Clear();
122
123 PasteboardSyncFlags syncFlags = PasteboardSynchronize( m_pasteboard );
124 wxCHECK_MSG( !(syncFlags&kPasteboardModified), false, wxT("clipboard modified after clear") );
125 wxCHECK_MSG( (syncFlags&kPasteboardClientIsOwner), false, wxT("client couldn't own clipboard") );
126
127 m_data = data;
128
129 data->AddToPasteboard( m_pasteboard, 1 );
130
131 return true;
132}
133
134void wxClipboard::Close()
135{
136 wxCHECK_RET( m_open, wxT("clipboard not open") );
137
138 m_open = false;
139
140 // Get rid of cached object.
141 // If this is not done, copying data from
142 // another application will only work once
143 if (m_data)
144 {
145 delete m_data;
146 m_data = (wxDataObject*) NULL;
147 }
148}
149
150bool wxClipboard::IsSupported( const wxDataFormat &dataFormat )
151{
152 if ( m_data )
153 return m_data->IsSupported( dataFormat );
154 return wxDataObject::IsFormatInPasteboard( m_pasteboard, dataFormat );
155}
156
157bool wxClipboard::GetData( wxDataObject& data )
158{
159 if ( IsUsingPrimarySelection() )
160 return false;
161
162 wxCHECK_MSG( m_open, false, wxT("clipboard not open") );
163
164 size_t formatcount = data.GetFormatCount() + 1;
165 wxDataFormat *array = new wxDataFormat[ formatcount ];
166 array[0] = data.GetPreferredFormat();
167 data.GetAllFormats( &array[1] );
168
169 bool transferred = false;
170
171 if ( m_data )
172 {
173 for (size_t i = 0; !transferred && i < formatcount; i++)
174 {
175 wxDataFormat format = array[ i ];
176 if ( m_data->IsSupported( format ) )
177 {
178 int dataSize = m_data->GetDataSize( format );
179 transferred = true;
180
181 if (dataSize == 0)
182 {
183 data.SetData( format, 0, 0 );
184 }
185 else
186 {
187 char *d = new char[ dataSize ];
188 m_data->GetDataHere( format, (void*)d );
189 data.SetData( format, dataSize, d );
190 delete [] d;
191 }
192 }
193 }
194 }
195
196 // get formats from wxDataObjects
197 if ( !transferred )
198 {
199 transferred = data.GetFromPasteboard( m_pasteboard ) ;
200 }
201
202 delete [] array;
203
204 return transferred;
205}
206
207#endif