~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/widget/src/windows/nsDataObjCollection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include "nsDataObjCollection.h"
 
39
//#include "nsString.h"
 
40
#include "nsVoidArray.h"
 
41
#include "nsITransferable.h"
 
42
#include "nsClipboard.h"
 
43
#include "IENUMFE.H"
 
44
 
 
45
#include <ole2.h>
 
46
#ifndef __MINGW32__
 
47
#include <urlmon.h>
 
48
#endif
 
49
 
 
50
#if 0
 
51
#define PRNTDEBUG(_x) printf(_x);
 
52
#define PRNTDEBUG2(_x1, _x2) printf(_x1, _x2);
 
53
#define PRNTDEBUG3(_x1, _x2, _x3) printf(_x1, _x2, _x3);
 
54
#else
 
55
#define PRNTDEBUG(_x) // printf(_x);
 
56
#define PRNTDEBUG2(_x1, _x2) // printf(_x1, _x2);
 
57
#define PRNTDEBUG3(_x1, _x2, _x3) // printf(_x1, _x2, _x3);
 
58
#endif
 
59
 
 
60
ULONG nsDataObjCollection::g_cRef = 0;
 
61
 
 
62
EXTERN_C GUID CDECL CLSID_nsDataObjCollection =
 
63
{ 0x2d851b91, 0xd4c, 0x11d3, { 0x96, 0xd4, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } };
 
64
 
 
65
/*
 
66
 * Class nsDataObjCollection
 
67
 */
 
68
 
 
69
//-----------------------------------------------------
 
70
// construction 
 
71
//-----------------------------------------------------
 
72
nsDataObjCollection::nsDataObjCollection()
 
73
{
 
74
        m_cRef          = 0;
 
75
  mTransferable   = nsnull;
 
76
  mDataFlavors    = new nsVoidArray();
 
77
  mDataObjects    = new nsVoidArray();
 
78
 
 
79
  m_enumFE = new CEnumFormatEtc(32);
 
80
  m_enumFE->AddRef();
 
81
 
 
82
}
 
83
 
 
84
//-----------------------------------------------------
 
85
// destruction
 
86
//-----------------------------------------------------
 
87
nsDataObjCollection::~nsDataObjCollection()
 
88
{
 
89
  NS_IF_RELEASE(mTransferable);
 
90
  PRInt32 i;
 
91
  for (i=0;i<mDataFlavors->Count();i++) {
 
92
    nsString * df = (nsString *)mDataFlavors->ElementAt(i);
 
93
    delete df;
 
94
  }
 
95
  delete mDataFlavors;
 
96
 
 
97
  for (i=0;i<mDataObjects->Count();i++) {
 
98
    IDataObject * dataObj = (IDataObject *)mDataObjects->ElementAt(i);
 
99
    NS_RELEASE(dataObj);
 
100
  }
 
101
  delete mDataObjects;
 
102
 
 
103
        m_cRef = 0;
 
104
  m_enumFE->Release();
 
105
 
 
106
}
 
107
 
 
108
 
 
109
//-----------------------------------------------------
 
110
// IUnknown interface methods - see inknown.h for documentation
 
111
//-----------------------------------------------------
 
112
STDMETHODIMP nsDataObjCollection::QueryInterface(REFIID riid, void** ppv)
 
113
{
 
114
        *ppv=NULL;
 
115
 
 
116
        if ( (IID_IUnknown == riid) || (IID_IDataObject == riid) ) {
 
117
                *ppv = static_cast<IDataObject*>(this); 
 
118
                AddRef();
 
119
                return NOERROR;
 
120
        }
 
121
 
 
122
        if ( IID_IDataObjCollection     == riid ) {
 
123
                *ppv = static_cast<nsIDataObjCollection*>(this); 
 
124
                AddRef();
 
125
                return NOERROR;
 
126
        }
 
127
 
 
128
        return ResultFromScode(E_NOINTERFACE);
 
129
}
 
130
 
 
131
//-----------------------------------------------------
 
132
STDMETHODIMP_(ULONG) nsDataObjCollection::AddRef()
 
133
{
 
134
        ++g_cRef;
 
135
  //PRNTDEBUG3("nsDataObjCollection::AddRef  >>>>>>>>>>>>>>>>>> %d on %p\n", (m_cRef+1), this);
 
136
        return ++m_cRef;
 
137
}
 
138
 
 
139
 
 
140
//-----------------------------------------------------
 
141
STDMETHODIMP_(ULONG) nsDataObjCollection::Release()
 
142
{
 
143
  //PRNTDEBUG3("nsDataObjCollection::Release >>>>>>>>>>>>>>>>>> %d on %p\n", (m_cRef-1), this);
 
144
        if (0 < g_cRef)
 
145
                --g_cRef;
 
146
 
 
147
        if (0 != --m_cRef)
 
148
                return m_cRef;
 
149
 
 
150
        delete this;
 
151
 
 
152
        return 0;
 
153
}
 
154
 
 
155
//-----------------------------------------------------
 
156
BOOL nsDataObjCollection::FormatsMatch(const FORMATETC& source, const FORMATETC& target) const
 
157
{
 
158
        if ((source.cfFormat == target.cfFormat) &&
 
159
                 (source.dwAspect  & target.dwAspect)  &&
 
160
                 (source.tymed     & target.tymed))       {
 
161
                return TRUE;
 
162
        } else {
 
163
                return FALSE;
 
164
        }
 
165
}
 
166
 
 
167
//-----------------------------------------------------
 
168
// IDataObject methods
 
169
//-----------------------------------------------------
 
170
STDMETHODIMP nsDataObjCollection::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
 
171
{
 
172
  PRNTDEBUG("nsDataObjCollection::GetData\n");
 
173
  PRNTDEBUG3("  format: %d  Text: %d\n", pFE->cfFormat, CF_TEXT);
 
174
 
 
175
  for (PRInt32 i=0;i<mDataObjects->Count();i++) {
 
176
    IDataObject * dataObj = (IDataObject *)mDataObjects->ElementAt(i);
 
177
    if (S_OK == dataObj->GetData(pFE, pSTM)) {
 
178
      return S_OK;
 
179
    }
 
180
  }
 
181
 
 
182
        return ResultFromScode(DATA_E_FORMATETC);
 
183
}
 
184
 
 
185
 
 
186
//-----------------------------------------------------
 
187
STDMETHODIMP nsDataObjCollection::GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
 
188
{
 
189
  PRNTDEBUG("nsDataObjCollection::GetDataHere\n");
 
190
                return ResultFromScode(E_FAIL);
 
191
}
 
192
 
 
193
 
 
194
//-----------------------------------------------------
 
195
// Other objects querying to see if we support a 
 
196
// particular format
 
197
//-----------------------------------------------------
 
198
STDMETHODIMP nsDataObjCollection::QueryGetData(LPFORMATETC pFE)
 
199
{
 
200
  UINT format = nsClipboard::GetFormat(MULTI_MIME);
 
201
  PRNTDEBUG("nsDataObjCollection::QueryGetData  ");
 
202
 
 
203
  PRNTDEBUG3("format: %d  Mulitple: %d\n", pFE->cfFormat, format);
 
204
 
 
205
  if (format == pFE->cfFormat) {
 
206
    return S_OK;
 
207
  }
 
208
 
 
209
 
 
210
  for (PRInt32 i=0;i<mDataObjects->Count();i++) {
 
211
    IDataObject * dataObj = (IDataObject *)mDataObjects->ElementAt(i);
 
212
    if (S_OK == dataObj->QueryGetData(pFE)) {
 
213
      return S_OK;
 
214
    }
 
215
  }
 
216
 
 
217
  PRNTDEBUG2("***** nsDataObjCollection::QueryGetData - Unknown format %d\n", pFE->cfFormat);
 
218
        return ResultFromScode(E_FAIL);
 
219
}
 
220
 
 
221
//-----------------------------------------------------
 
222
STDMETHODIMP nsDataObjCollection::GetCanonicalFormatEtc
 
223
         (LPFORMATETC pFEIn, LPFORMATETC pFEOut)
 
224
{
 
225
  PRNTDEBUG("nsDataObjCollection::GetCanonicalFormatEtc\n");
 
226
                return ResultFromScode(E_FAIL);
 
227
}
 
228
 
 
229
 
 
230
//-----------------------------------------------------
 
231
STDMETHODIMP nsDataObjCollection::SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL fRelease)
 
232
{
 
233
  PRNTDEBUG("nsDataObjCollection::SetData\n");
 
234
 
 
235
  return ResultFromScode(E_FAIL);
 
236
}
 
237
 
 
238
 
 
239
//-----------------------------------------------------
 
240
STDMETHODIMP nsDataObjCollection::EnumFormatEtc(DWORD dwDir, LPENUMFORMATETC *ppEnum)
 
241
{
 
242
  PRNTDEBUG("nsDataObjCollection::EnumFormatEtc\n");
 
243
 
 
244
  switch (dwDir) {
 
245
    case DATADIR_GET: {
 
246
       m_enumFE->Clone(ppEnum);
 
247
    } break;
 
248
    case DATADIR_SET:
 
249
        *ppEnum=NULL;
 
250
        break;
 
251
    default:
 
252
        *ppEnum=NULL;
 
253
        break;
 
254
  } // switch
 
255
 
 
256
  // Since a new one has been created, 
 
257
  // we will ref count the new clone here 
 
258
  // before giving it back
 
259
  if (NULL == *ppEnum)
 
260
    return ResultFromScode(E_FAIL);
 
261
  else
 
262
    (*ppEnum)->AddRef();
 
263
 
 
264
  return NOERROR;
 
265
 
 
266
}
 
267
 
 
268
//-----------------------------------------------------
 
269
STDMETHODIMP nsDataObjCollection::DAdvise(LPFORMATETC pFE, DWORD dwFlags,
 
270
                                                                                                      LPADVISESINK pIAdviseSink, DWORD* pdwConn)
 
271
{
 
272
  PRNTDEBUG("nsDataObjCollection::DAdvise\n");
 
273
        return ResultFromScode(E_FAIL);
 
274
}
 
275
 
 
276
 
 
277
//-----------------------------------------------------
 
278
STDMETHODIMP nsDataObjCollection::DUnadvise(DWORD dwConn)
 
279
{
 
280
  PRNTDEBUG("nsDataObjCollection::DUnadvise\n");
 
281
        return ResultFromScode(E_FAIL);
 
282
}
 
283
 
 
284
//-----------------------------------------------------
 
285
STDMETHODIMP nsDataObjCollection::EnumDAdvise(LPENUMSTATDATA *ppEnum)
 
286
{
 
287
  PRNTDEBUG("nsDataObjCollection::EnumDAdvise\n");
 
288
        return ResultFromScode(E_FAIL);
 
289
}
 
290
 
 
291
//-----------------------------------------------------
 
292
// other methods
 
293
//-----------------------------------------------------
 
294
ULONG nsDataObjCollection::GetCumRefCount()
 
295
{
 
296
        return g_cRef;
 
297
}
 
298
 
 
299
//-----------------------------------------------------
 
300
ULONG nsDataObjCollection::GetRefCount() const
 
301
{
 
302
        return m_cRef;
 
303
}
 
304
 
 
305
//-----------------------------------------------------
 
306
// GetData and SetData helper functions
 
307
//-----------------------------------------------------
 
308
HRESULT nsDataObjCollection::AddSetFormat(FORMATETC& aFE)
 
309
{
 
310
  PRNTDEBUG("nsDataObjCollection::AddSetFormat\n");
 
311
        return ResultFromScode(S_OK);
 
312
}
 
313
 
 
314
//-----------------------------------------------------
 
315
HRESULT nsDataObjCollection::AddGetFormat(FORMATETC& aFE)
 
316
{
 
317
  PRNTDEBUG("nsDataObjCollection::AddGetFormat\n");
 
318
        return ResultFromScode(S_OK);
 
319
}
 
320
 
 
321
//-----------------------------------------------------
 
322
HRESULT nsDataObjCollection::GetBitmap(FORMATETC&, STGMEDIUM&)
 
323
{
 
324
  PRNTDEBUG("nsDataObjCollection::GetBitmap\n");
 
325
        return ResultFromScode(E_NOTIMPL);
 
326
}
 
327
 
 
328
//-----------------------------------------------------
 
329
HRESULT nsDataObjCollection::GetDib(FORMATETC&, STGMEDIUM&)
 
330
{
 
331
  PRNTDEBUG("nsDataObjCollection::GetDib\n");
 
332
        return ResultFromScode(E_NOTIMPL);
 
333
}
 
334
 
 
335
//-----------------------------------------------------
 
336
HRESULT nsDataObjCollection::GetMetafilePict(FORMATETC&, STGMEDIUM&)
 
337
{
 
338
        return ResultFromScode(E_NOTIMPL);
 
339
}
 
340
 
 
341
//-----------------------------------------------------
 
342
HRESULT nsDataObjCollection::SetBitmap(FORMATETC&, STGMEDIUM&)
 
343
{
 
344
        return ResultFromScode(E_NOTIMPL);
 
345
}
 
346
 
 
347
//-----------------------------------------------------
 
348
HRESULT nsDataObjCollection::SetDib   (FORMATETC&, STGMEDIUM&)
 
349
{
 
350
        return ResultFromScode(E_FAIL);
 
351
}
 
352
 
 
353
//-----------------------------------------------------
 
354
HRESULT nsDataObjCollection::SetMetafilePict (FORMATETC&, STGMEDIUM&)
 
355
{
 
356
        return ResultFromScode(E_FAIL);
 
357
}
 
358
 
 
359
//-----------------------------------------------------
 
360
//-----------------------------------------------------
 
361
CLSID nsDataObjCollection::GetClassID() const
 
362
{
 
363
        return CLSID_nsDataObjCollection;
 
364
}
 
365
 
 
366
//-----------------------------------------------------
 
367
// Registers a the DataFlavor/FE pair
 
368
//-----------------------------------------------------
 
369
void nsDataObjCollection::AddDataFlavor(nsString * aDataFlavor, LPFORMATETC aFE)
 
370
{
 
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);
 
377
 
 
378
}
 
379
 
 
380
//-----------------------------------------------------
 
381
// Registers a the DataFlavor/FE pair
 
382
//-----------------------------------------------------
 
383
void nsDataObjCollection::AddDataObject(IDataObject * aDataObj)
 
384
{
 
385
  NS_ADDREF(aDataObj);
 
386
  mDataObjects->AppendElement(aDataObj);
 
387
 
 
388
}