1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#include "nsDataObjCollection.h"
39
//#include "nsString.h"
40
#include "nsVoidArray.h"
41
#include "nsITransferable.h"
42
#include "nsClipboard.h"
51
#define PRNTDEBUG(_x) printf(_x);
52
#define PRNTDEBUG2(_x1, _x2) printf(_x1, _x2);
53
#define PRNTDEBUG3(_x1, _x2, _x3) printf(_x1, _x2, _x3);
55
#define PRNTDEBUG(_x) // printf(_x);
56
#define PRNTDEBUG2(_x1, _x2) // printf(_x1, _x2);
57
#define PRNTDEBUG3(_x1, _x2, _x3) // printf(_x1, _x2, _x3);
60
ULONG nsDataObjCollection::g_cRef = 0;
62
EXTERN_C GUID CDECL CLSID_nsDataObjCollection =
63
{ 0x2d851b91, 0xd4c, 0x11d3, { 0x96, 0xd4, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } };
66
* Class nsDataObjCollection
69
//-----------------------------------------------------
71
//-----------------------------------------------------
72
nsDataObjCollection::nsDataObjCollection()
75
mTransferable = nsnull;
76
mDataFlavors = new nsVoidArray();
77
mDataObjects = new nsVoidArray();
79
m_enumFE = new CEnumFormatEtc(32);
84
//-----------------------------------------------------
86
//-----------------------------------------------------
87
nsDataObjCollection::~nsDataObjCollection()
89
NS_IF_RELEASE(mTransferable);
91
for (i=0;i<mDataFlavors->Count();i++) {
92
nsString * df = (nsString *)mDataFlavors->ElementAt(i);
97
for (i=0;i<mDataObjects->Count();i++) {
98
IDataObject * dataObj = (IDataObject *)mDataObjects->ElementAt(i);
109
//-----------------------------------------------------
110
// IUnknown interface methods - see inknown.h for documentation
111
//-----------------------------------------------------
112
STDMETHODIMP nsDataObjCollection::QueryInterface(REFIID riid, void** ppv)
116
if ( (IID_IUnknown == riid) || (IID_IDataObject == riid) ) {
117
*ppv = static_cast<IDataObject*>(this);
122
if ( IID_IDataObjCollection == riid ) {
123
*ppv = static_cast<nsIDataObjCollection*>(this);
128
return ResultFromScode(E_NOINTERFACE);
131
//-----------------------------------------------------
132
STDMETHODIMP_(ULONG) nsDataObjCollection::AddRef()
135
//PRNTDEBUG3("nsDataObjCollection::AddRef >>>>>>>>>>>>>>>>>> %d on %p\n", (m_cRef+1), this);
140
//-----------------------------------------------------
141
STDMETHODIMP_(ULONG) nsDataObjCollection::Release()
143
//PRNTDEBUG3("nsDataObjCollection::Release >>>>>>>>>>>>>>>>>> %d on %p\n", (m_cRef-1), this);
155
//-----------------------------------------------------
156
BOOL nsDataObjCollection::FormatsMatch(const FORMATETC& source, const FORMATETC& target) const
158
if ((source.cfFormat == target.cfFormat) &&
159
(source.dwAspect & target.dwAspect) &&
160
(source.tymed & target.tymed)) {
167
//-----------------------------------------------------
168
// IDataObject methods
169
//-----------------------------------------------------
170
STDMETHODIMP nsDataObjCollection::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
172
PRNTDEBUG("nsDataObjCollection::GetData\n");
173
PRNTDEBUG3(" format: %d Text: %d\n", pFE->cfFormat, CF_TEXT);
175
for (PRInt32 i=0;i<mDataObjects->Count();i++) {
176
IDataObject * dataObj = (IDataObject *)mDataObjects->ElementAt(i);
177
if (S_OK == dataObj->GetData(pFE, pSTM)) {
182
return ResultFromScode(DATA_E_FORMATETC);
186
//-----------------------------------------------------
187
STDMETHODIMP nsDataObjCollection::GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
189
PRNTDEBUG("nsDataObjCollection::GetDataHere\n");
190
return ResultFromScode(E_FAIL);
194
//-----------------------------------------------------
195
// Other objects querying to see if we support a
197
//-----------------------------------------------------
198
STDMETHODIMP nsDataObjCollection::QueryGetData(LPFORMATETC pFE)
200
UINT format = nsClipboard::GetFormat(MULTI_MIME);
201
PRNTDEBUG("nsDataObjCollection::QueryGetData ");
203
PRNTDEBUG3("format: %d Mulitple: %d\n", pFE->cfFormat, format);
205
if (format == pFE->cfFormat) {
210
for (PRInt32 i=0;i<mDataObjects->Count();i++) {
211
IDataObject * dataObj = (IDataObject *)mDataObjects->ElementAt(i);
212
if (S_OK == dataObj->QueryGetData(pFE)) {
217
PRNTDEBUG2("***** nsDataObjCollection::QueryGetData - Unknown format %d\n", pFE->cfFormat);
218
return ResultFromScode(E_FAIL);
221
//-----------------------------------------------------
222
STDMETHODIMP nsDataObjCollection::GetCanonicalFormatEtc
223
(LPFORMATETC pFEIn, LPFORMATETC pFEOut)
225
PRNTDEBUG("nsDataObjCollection::GetCanonicalFormatEtc\n");
226
return ResultFromScode(E_FAIL);
230
//-----------------------------------------------------
231
STDMETHODIMP nsDataObjCollection::SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL fRelease)
233
PRNTDEBUG("nsDataObjCollection::SetData\n");
235
return ResultFromScode(E_FAIL);
239
//-----------------------------------------------------
240
STDMETHODIMP nsDataObjCollection::EnumFormatEtc(DWORD dwDir, LPENUMFORMATETC *ppEnum)
242
PRNTDEBUG("nsDataObjCollection::EnumFormatEtc\n");
246
m_enumFE->Clone(ppEnum);
256
// Since a new one has been created,
257
// we will ref count the new clone here
258
// before giving it back
260
return ResultFromScode(E_FAIL);
268
//-----------------------------------------------------
269
STDMETHODIMP nsDataObjCollection::DAdvise(LPFORMATETC pFE, DWORD dwFlags,
270
LPADVISESINK pIAdviseSink, DWORD* pdwConn)
272
PRNTDEBUG("nsDataObjCollection::DAdvise\n");
273
return ResultFromScode(E_FAIL);
277
//-----------------------------------------------------
278
STDMETHODIMP nsDataObjCollection::DUnadvise(DWORD dwConn)
280
PRNTDEBUG("nsDataObjCollection::DUnadvise\n");
281
return ResultFromScode(E_FAIL);
284
//-----------------------------------------------------
285
STDMETHODIMP nsDataObjCollection::EnumDAdvise(LPENUMSTATDATA *ppEnum)
287
PRNTDEBUG("nsDataObjCollection::EnumDAdvise\n");
288
return ResultFromScode(E_FAIL);
291
//-----------------------------------------------------
293
//-----------------------------------------------------
294
ULONG nsDataObjCollection::GetCumRefCount()
299
//-----------------------------------------------------
300
ULONG nsDataObjCollection::GetRefCount() const
305
//-----------------------------------------------------
306
// GetData and SetData helper functions
307
//-----------------------------------------------------
308
HRESULT nsDataObjCollection::AddSetFormat(FORMATETC& aFE)
310
PRNTDEBUG("nsDataObjCollection::AddSetFormat\n");
311
return ResultFromScode(S_OK);
314
//-----------------------------------------------------
315
HRESULT nsDataObjCollection::AddGetFormat(FORMATETC& aFE)
317
PRNTDEBUG("nsDataObjCollection::AddGetFormat\n");
318
return ResultFromScode(S_OK);
321
//-----------------------------------------------------
322
HRESULT nsDataObjCollection::GetBitmap(FORMATETC&, STGMEDIUM&)
324
PRNTDEBUG("nsDataObjCollection::GetBitmap\n");
325
return ResultFromScode(E_NOTIMPL);
328
//-----------------------------------------------------
329
HRESULT nsDataObjCollection::GetDib(FORMATETC&, STGMEDIUM&)
331
PRNTDEBUG("nsDataObjCollection::GetDib\n");
332
return ResultFromScode(E_NOTIMPL);
335
//-----------------------------------------------------
336
HRESULT nsDataObjCollection::GetMetafilePict(FORMATETC&, STGMEDIUM&)
338
return ResultFromScode(E_NOTIMPL);
341
//-----------------------------------------------------
342
HRESULT nsDataObjCollection::SetBitmap(FORMATETC&, STGMEDIUM&)
344
return ResultFromScode(E_NOTIMPL);
347
//-----------------------------------------------------
348
HRESULT nsDataObjCollection::SetDib (FORMATETC&, STGMEDIUM&)
350
return ResultFromScode(E_FAIL);
353
//-----------------------------------------------------
354
HRESULT nsDataObjCollection::SetMetafilePict (FORMATETC&, STGMEDIUM&)
356
return ResultFromScode(E_FAIL);
359
//-----------------------------------------------------
360
//-----------------------------------------------------
361
CLSID nsDataObjCollection::GetClassID() const
363
return CLSID_nsDataObjCollection;
366
//-----------------------------------------------------
367
// Registers a the DataFlavor/FE pair
368
//-----------------------------------------------------
369
void nsDataObjCollection::AddDataFlavor(nsString * aDataFlavor, LPFORMATETC aFE)
371
// These two lists are the mapping to and from data flavors and FEs
372
// Later, OLE will tell us it's needs a certain type of FORMATETC (text, unicode, etc)
373
// so we will look up data flavor that corresponds to the FE
374
// and then ask the transferable for that type of data
375
mDataFlavors->AppendElement(new nsString(*aDataFlavor));
376
m_enumFE->AddFE(aFE);
380
//-----------------------------------------------------
381
// Registers a the DataFlavor/FE pair
382
//-----------------------------------------------------
383
void nsDataObjCollection::AddDataObject(IDataObject * aDataObj)
386
mDataObjects->AppendElement(aDataObj);