Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 #ifndef _NSDATAOBJCOLLECTION_H_
7 #define _NSDATAOBJCOLLECTION_H_
9 #include <oleidl.h>
11 #include "nsString.h"
12 #include "nsTArray.h"
13 #include "nsAutoPtr.h"
14 #include "nsDataObj.h"
15 #include "mozilla/Attributes.h"
17 class CEnumFormatEtc;
19 #define MULTI_MIME "Mozilla/IDataObjectCollectionFormat"
21 EXTERN_C const IID IID_IDataObjCollection;
23 // An interface to make sure we have the right kind of object for D&D
24 // this way we can filter out collection objects that aren't ours
25 class nsIDataObjCollection : public IUnknown {
26 public:
28 };
30 /*
31 * This ole registered class is used to facilitate drag-drop of objects which
32 * can be adapted by an object derived from CfDragDrop. The CfDragDrop is
33 * associated with instances via SetDragDrop().
34 */
36 class nsDataObjCollection MOZ_FINAL : public nsIDataObjCollection, public nsDataObj
37 {
38 public:
39 nsDataObjCollection();
40 ~nsDataObjCollection();
42 public: // IUnknown methods - see iunknown.h for documentation
43 STDMETHODIMP_(ULONG) AddRef ();
44 STDMETHODIMP QueryInterface(REFIID, void**);
45 STDMETHODIMP_(ULONG) Release ();
47 public: // DataGet and DataSet helper methods
48 virtual HRESULT AddSetFormat(FORMATETC& FE);
49 virtual HRESULT AddGetFormat(FORMATETC& FE);
51 virtual HRESULT GetFile(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
52 virtual HRESULT GetText(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
53 virtual HRESULT GetFileDescriptors(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
54 virtual HRESULT GetFileContents(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
55 virtual HRESULT GetFirstSupporting(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
57 // support for clipboard
58 void AddDataFlavor(const char * aDataFlavor, LPFORMATETC aFE);
60 // from nsPIDataObjCollection
61 void AddDataObject(IDataObject * aDataObj);
62 int32_t GetNumDataObjects() { return mDataObjects.Length(); }
63 nsDataObj* GetDataObjectAt(uint32_t aItem)
64 { return mDataObjects.SafeElementAt(aItem, nsRefPtr<nsDataObj>()); }
66 // Return the registered OLE class ID of this object's CfDataObj.
67 CLSID GetClassID() const;
69 public:
70 // Store data in pSTM according to the format specified by pFE, if the
71 // format is supported (supported formats are specified in CfDragDrop::
72 // GetFormats) and return NOERROR; otherwise return DATA_E_FORMATETC. It
73 // is the callers responsibility to free pSTM if NOERROR is returned.
74 STDMETHODIMP GetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM);
76 // Similar to GetData except that the caller allocates the structure
77 // referenced by pSTM.
78 STDMETHODIMP GetDataHere (LPFORMATETC pFE, LPSTGMEDIUM pSTM);
80 // Returns S_TRUE if this object supports the format specified by pSTM,
81 // S_FALSE otherwise.
82 STDMETHODIMP QueryGetData (LPFORMATETC pFE);
84 // Set pCanonFE to the canonical format of pFE if one exists and return
85 // NOERROR, otherwise return DATA_S_SAMEFORMATETC. A canonical format
86 // implies an identical rendering.
87 STDMETHODIMP GetCanonicalFormatEtc (LPFORMATETC pFE, LPFORMATETC pCanonFE);
89 // Set this objects data according to the format specified by pFE and
90 // the storage medium specified by pSTM and return NOERROR, if the format
91 // is supported. If release is TRUE this object must release the storage
92 // associated with pSTM.
93 STDMETHODIMP SetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL release);
95 // Set ppEnum to an IEnumFORMATETC object which will iterate all of the
96 // data formats that this object supports. direction is either DATADIR_GET
97 // or DATADIR_SET.
98 STDMETHODIMP EnumFormatEtc (DWORD direction, LPENUMFORMATETC* ppEnum);
100 // Set up an advisory connection to this object based on the format specified
101 // by pFE, flags, and the pAdvise. Set pConn to the established advise
102 // connection.
103 STDMETHODIMP DAdvise (LPFORMATETC pFE, DWORD flags, LPADVISESINK pAdvise,
104 DWORD* pConn);
106 // Turn off advising of a previous call to DAdvise which set pConn.
107 STDMETHODIMP DUnadvise (DWORD pConn);
109 // Set ppEnum to an IEnumSTATDATA object which will iterate over the
110 // existing objects which have established advisory connections to this
111 // object.
112 STDMETHODIMP EnumDAdvise (LPENUMSTATDATA *ppEnum);
114 public:
115 // Set the adapter to dragDrop
116 //void SetDragDrop(CfDragDrop& dragDrop);
118 // Return the adapter
119 //CfDragDrop& GetDragDrop() const;
121 protected:
122 BOOL FormatsMatch(const FORMATETC& source, const FORMATETC& target) const;
124 ULONG m_cRef; // the reference count
126 // nsDataObjCollection owns and ref counts CEnumFormatEtc
127 CEnumFormatEtc * m_enumFE;
129 nsTArray<nsRefPtr<nsDataObj> > mDataObjects;
131 BOOL mIsAsyncMode;
132 BOOL mIsInOperation;
133 };
135 #endif //