Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / widget / windows / nsDataObjCollection.h
blob02ec7e89167022280f0407daa5ee0a1db74390e9
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 "mozilla/RefPtr.h"
12 #include "nsString.h"
13 #include "nsTArray.h"
14 #include "nsDataObj.h"
15 #include "mozilla/Attributes.h"
17 #define MULTI_MIME "Mozilla/IDataObjectCollectionFormat"
19 EXTERN_C const IID IID_IDataObjCollection;
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:
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().
33 class nsDataObjCollection final : public nsIDataObjCollection,
34 public nsDataObj {
35 public:
36 nsDataObjCollection();
38 private:
39 ~nsDataObjCollection() final;
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;
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);
53 using nsDataObj::GetFile;
54 using nsDataObj::GetFileContents;
55 using nsDataObj::GetText;
57 // support for clipboard
58 void AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE) final;
60 public: // 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, RefPtr<nsDataObj>());
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;
74 // Similar to GetData except that the caller allocates the structure
75 // referenced by pSTM.
76 STDMETHODIMP GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM) final;
78 // Returns S_TRUE if this object supports the format specified by pSTM,
79 // S_FALSE otherwise.
80 STDMETHODIMP QueryGetData(LPFORMATETC pFE) final;
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;
88 private:
89 nsTArray<RefPtr<nsDataObj> > mDataObjects;
92 #endif //