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/. */
10 * CEnumFormatEtc - implements IEnumFORMATETC
16 #include "mozilla/Attributes.h"
18 // FORMATETC container
22 FormatEtc() { memset(&mFormat
, 0, sizeof(FORMATETC
)); }
23 FormatEtc(const FormatEtc
& copy
) { CopyIn(©
.mFormat
); }
24 ~FormatEtc() { if (mFormat
.ptd
) CoTaskMemFree(mFormat
.ptd
); }
26 void CopyIn(const FORMATETC
*aSrc
) {
28 memset(&mFormat
, 0, sizeof(FORMATETC
));
33 mFormat
.ptd
= (DVTARGETDEVICE
*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE
));
34 *(mFormat
.ptd
) = *(aSrc
->ptd
);
38 void CopyOut(LPFORMATETC aDest
) {
43 aDest
->ptd
= (DVTARGETDEVICE
*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE
));
44 *(aDest
->ptd
) = *(mFormat
.ptd
);
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
60 class CEnumFormatEtc MOZ_FINAL
: public IEnumFORMATETC
63 CEnumFormatEtc(nsTArray
<FormatEtc
>& aArray
);
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
);
76 STDMETHODIMP
Clone(LPENUMFORMATETC
*aResult
); // Addrefs
79 void AddFormatEtc(LPFORMATETC aFormat
);
82 nsTArray
<FormatEtc
> mFormatList
; // Formats
83 ULONG mRefCnt
; // Object reference count
84 ULONG mCurrentIdx
; // Current element
86 void SetIndex(uint32_t aIdx
);