Backed out changeset 8517afe50156 (bug 540456) for reftest failures.
[gecko.git] / widget / windows / IEnumFE.h
blob8f6e11da6352dd899e60a8014515e54013145bb1
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 IEnumeFE_h__
7 #define IEnumeFE_h__
9 /*
10 * CEnumFormatEtc - implements IEnumFORMATETC
13 #include <ole2.h>
15 #include "nsTArray.h"
16 #include "mozilla/Attributes.h"
18 // FORMATETC container
19 class FormatEtc
21 public:
22 FormatEtc() { memset(&mFormat, 0, sizeof(FORMATETC)); }
23 FormatEtc(const FormatEtc& copy) { CopyIn(&copy.mFormat); }
24 ~FormatEtc() { if (mFormat.ptd) CoTaskMemFree(mFormat.ptd); }
26 void CopyIn(const FORMATETC *aSrc) {
27 if (!aSrc) {
28 memset(&mFormat, 0, sizeof(FORMATETC));
29 return;
31 mFormat = *aSrc;
32 if (aSrc->ptd) {
33 mFormat.ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
34 *(mFormat.ptd) = *(aSrc->ptd);
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);
48 private:
49 FORMATETC mFormat;
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.
60 class CEnumFormatEtc MOZ_FINAL : public IEnumFORMATETC
62 public:
63 CEnumFormatEtc(nsTArray<FormatEtc>& aArray);
64 CEnumFormatEtc();
65 ~CEnumFormatEtc();
67 // IUnknown impl.
68 STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
69 STDMETHODIMP_(ULONG) AddRef();
70 STDMETHODIMP_(ULONG) Release();
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
78 // Utils
79 void AddFormatEtc(LPFORMATETC aFormat);
81 private:
82 nsTArray<FormatEtc> mFormatList; // Formats
83 ULONG mRefCnt; // Object reference count
84 ULONG mCurrentIdx; // Current element
86 void SetIndex(uint32_t aIdx);
90 #endif //_IENUMFE_H_