1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef _NSDATAOBJCOLLECTION_H_
7 #define _NSDATAOBJCOLLECTION_H_
8 
9 #include <oleidl.h>
10 
11 #include "mozilla/RefPtr.h"
12 #include "nsString.h"
13 #include "nsTArray.h"
14 #include "nsDataObj.h"
15 #include "mozilla/Attributes.h"
16 
17 #define MULTI_MIME "Mozilla/IDataObjectCollectionFormat"
18 
19 EXTERN_C const IID IID_IDataObjCollection;
20 
21 // An interface to make sure we have the right kind of object for D&D
22 // this way we can filter out collection objects that aren't ours
23 class nsIDataObjCollection : public IUnknown {
24  public:
25 };
26 
27 /*
28  * This ole registered class is used to facilitate drag-drop of objects which
29  * can be adapted by an object derived from CfDragDrop. The CfDragDrop is
30  * associated with instances via SetDragDrop().
31  */
32 
33 class nsDataObjCollection final : public nsIDataObjCollection,
34                                   public nsDataObj {
35  public:
36   nsDataObjCollection();
37 
38  private:
39   ~nsDataObjCollection() final;
40 
41  public:  // IUnknown methods - see iunknown.h for documentation
42   STDMETHODIMP_(ULONG) AddRef() final;
43   STDMETHODIMP QueryInterface(REFIID, void**) final;
44   STDMETHODIMP_(ULONG) Release() final;
45 
46  private:  // DataGet and DataSet helper methods
47   HRESULT GetFile(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
48   HRESULT GetText(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
49   HRESULT GetFileDescriptors(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
50   HRESULT GetFileContents(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
51   HRESULT GetFirstSupporting(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
52 
53   using nsDataObj::GetFile;
54   using nsDataObj::GetFileContents;
55   using nsDataObj::GetText;
56 
57   // support for clipboard
58   void AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE) final;
59 
60  public:  // from nsPIDataObjCollection
61   void AddDataObject(IDataObject* aDataObj);
GetNumDataObjects()62   int32_t GetNumDataObjects() { return mDataObjects.Length(); }
GetDataObjectAt(uint32_t aItem)63   nsDataObj* GetDataObjectAt(uint32_t aItem) {
64     return mDataObjects.SafeElementAt(aItem, RefPtr<nsDataObj>());
65   }
66 
67  public:
68   // Store data in pSTM according to the format specified by pFE, if the
69   // format is supported (supported formats are specified in CfDragDrop::
70   // GetFormats) and return NOERROR; otherwise return DATA_E_FORMATETC. It
71   // is the callers responsibility to free pSTM if NOERROR is returned.
72   STDMETHODIMP GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM) final;
73 
74   // Similar to GetData except that the caller allocates the structure
75   // referenced by pSTM.
76   STDMETHODIMP GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM) final;
77 
78   // Returns S_TRUE if this object supports the format specified by pSTM,
79   // S_FALSE otherwise.
80   STDMETHODIMP QueryGetData(LPFORMATETC pFE) final;
81 
82   // Set this objects data according to the format specified by pFE and
83   // the storage medium specified by pSTM and return NOERROR, if the format
84   // is supported. If release is TRUE this object must release the storage
85   // associated with pSTM.
86   STDMETHODIMP SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL release) final;
87 
88  private:
89   nsTArray<RefPtr<nsDataObj> > mDataObjects;
90 };
91 
92 #endif  //
93