|
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 IEnumeFE_h__ |
|
7 #define IEnumeFE_h__ |
|
8 |
|
9 /* |
|
10 * CEnumFormatEtc - implements IEnumFORMATETC |
|
11 */ |
|
12 |
|
13 #include <ole2.h> |
|
14 |
|
15 #include "nsTArray.h" |
|
16 #include "mozilla/Attributes.h" |
|
17 |
|
18 // FORMATETC container |
|
19 class FormatEtc |
|
20 { |
|
21 public: |
|
22 FormatEtc() { memset(&mFormat, 0, sizeof(FORMATETC)); } |
|
23 FormatEtc(const FormatEtc& copy) { CopyIn(©.mFormat); } |
|
24 ~FormatEtc() { if (mFormat.ptd) CoTaskMemFree(mFormat.ptd); } |
|
25 |
|
26 void CopyIn(const FORMATETC *aSrc) { |
|
27 if (!aSrc) { |
|
28 memset(&mFormat, 0, sizeof(FORMATETC)); |
|
29 return; |
|
30 } |
|
31 mFormat = *aSrc; |
|
32 if (aSrc->ptd) { |
|
33 mFormat.ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); |
|
34 *(mFormat.ptd) = *(aSrc->ptd); |
|
35 } |
|
36 } |
|
37 |
|
38 void CopyOut(LPFORMATETC aDest) { |
|
39 if (!aDest) |
|
40 return; |
|
41 *aDest = mFormat; |
|
42 if (mFormat.ptd) { |
|
43 aDest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); |
|
44 *(aDest->ptd) = *(mFormat.ptd); |
|
45 } |
|
46 } |
|
47 |
|
48 private: |
|
49 FORMATETC mFormat; |
|
50 }; |
|
51 |
|
52 /* |
|
53 * CEnumFormatEtc is created within IDataObject::EnumFormatEtc. This object lives |
|
54 * on its own, that is, QueryInterface only knows IUnknown and IEnumFormatEtc, |
|
55 * nothing more. We still use an outer unknown for reference counting, because as |
|
56 * long as this enumerator lives, the data object should live, thereby keeping the |
|
57 * application up. |
|
58 */ |
|
59 |
|
60 class CEnumFormatEtc MOZ_FINAL : public IEnumFORMATETC |
|
61 { |
|
62 public: |
|
63 CEnumFormatEtc(nsTArray<FormatEtc>& aArray); |
|
64 CEnumFormatEtc(); |
|
65 ~CEnumFormatEtc(); |
|
66 |
|
67 // IUnknown impl. |
|
68 STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv); |
|
69 STDMETHODIMP_(ULONG) AddRef(); |
|
70 STDMETHODIMP_(ULONG) Release(); |
|
71 |
|
72 // IEnumFORMATETC impl. |
|
73 STDMETHODIMP Next(ULONG aMaxToFetch, FORMATETC *aResult, ULONG *aNumFetched); |
|
74 STDMETHODIMP Skip(ULONG aSkipNum); |
|
75 STDMETHODIMP Reset(); |
|
76 STDMETHODIMP Clone(LPENUMFORMATETC *aResult); // Addrefs |
|
77 |
|
78 // Utils |
|
79 void AddFormatEtc(LPFORMATETC aFormat); |
|
80 |
|
81 private: |
|
82 nsTArray<FormatEtc> mFormatList; // Formats |
|
83 ULONG mRefCnt; // Object reference count |
|
84 ULONG mCurrentIdx; // Current element |
|
85 |
|
86 void SetIndex(uint32_t aIdx); |
|
87 }; |
|
88 |
|
89 |
|
90 #endif //_IENUMFE_H_ |