Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / windows / IEnumFE.h
blobb8cb6ad9d0379b8e8a96861bd0f13ddf3ff4b93a
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 {
20 public:
21 FormatEtc() { memset(&mFormat, 0, sizeof(FORMATETC)); }
22 FormatEtc(const FormatEtc& copy) { CopyIn(&copy.mFormat); }
23 ~FormatEtc() {
24 if (mFormat.ptd) CoTaskMemFree(mFormat.ptd);
27 void CopyIn(const FORMATETC* aSrc) {
28 if (!aSrc) {
29 memset(&mFormat, 0, sizeof(FORMATETC));
30 return;
32 mFormat = *aSrc;
33 if (aSrc->ptd) {
34 mFormat.ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
35 *(mFormat.ptd) = *(aSrc->ptd);
39 void CopyOut(LPFORMATETC aDest) {
40 if (!aDest) 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
54 * lives on its own, that is, QueryInterface only knows IUnknown and
55 * IEnumFormatEtc, nothing more. We still use an outer unknown for reference
56 * counting, because as long as this enumerator lives, the data object should
57 * live, thereby keeping the application up.
60 class CEnumFormatEtc final : public IEnumFORMATETC {
61 public:
62 explicit CEnumFormatEtc(nsTArray<FormatEtc>& aArray);
63 CEnumFormatEtc();
64 ~CEnumFormatEtc();
66 // IUnknown impl.
67 STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppv);
68 STDMETHODIMP_(ULONG) AddRef();
69 STDMETHODIMP_(ULONG) Release();
71 // IEnumFORMATETC impl.
72 STDMETHODIMP Next(ULONG aMaxToFetch, FORMATETC* aResult, ULONG* aNumFetched);
73 STDMETHODIMP Skip(ULONG aSkipNum);
74 STDMETHODIMP Reset();
75 STDMETHODIMP Clone(LPENUMFORMATETC* aResult); // Addrefs
77 // Utils
78 void AddFormatEtc(LPFORMATETC aFormat);
80 private:
81 nsTArray<FormatEtc> mFormatList; // Formats
82 ULONG mRefCnt; // Object reference count
83 ULONG mCurrentIdx; // Current element
85 void SetIndex(uint32_t aIdx);
88 #endif //_IENUMFE_H_