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
21 FormatEtc() { memset(&mFormat
, 0, sizeof(FORMATETC
)); }
22 FormatEtc(const FormatEtc
& copy
) { CopyIn(©
.mFormat
); }
24 if (mFormat
.ptd
) CoTaskMemFree(mFormat
.ptd
);
27 void CopyIn(const FORMATETC
* aSrc
) {
29 memset(&mFormat
, 0, sizeof(FORMATETC
));
34 mFormat
.ptd
= (DVTARGETDEVICE
*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE
));
35 *(mFormat
.ptd
) = *(aSrc
->ptd
);
39 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
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
{
62 explicit CEnumFormatEtc(nsTArray
<FormatEtc
>& aArray
);
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
);
75 STDMETHODIMP
Clone(LPENUMFORMATETC
* aResult
); // Addrefs
78 void AddFormatEtc(LPFORMATETC aFormat
);
81 nsTArray
<FormatEtc
> mFormatList
; // Formats
82 ULONG mRefCnt
; // Object reference count
83 ULONG mCurrentIdx
; // Current element
85 void SetIndex(uint32_t aIdx
);