1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/IEnumFE.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef IEnumeFE_h__ 1.10 +#define IEnumeFE_h__ 1.11 + 1.12 +/* 1.13 + * CEnumFormatEtc - implements IEnumFORMATETC 1.14 + */ 1.15 + 1.16 +#include <ole2.h> 1.17 + 1.18 +#include "nsTArray.h" 1.19 +#include "mozilla/Attributes.h" 1.20 + 1.21 +// FORMATETC container 1.22 +class FormatEtc 1.23 +{ 1.24 +public: 1.25 + FormatEtc() { memset(&mFormat, 0, sizeof(FORMATETC)); } 1.26 + FormatEtc(const FormatEtc& copy) { CopyIn(©.mFormat); } 1.27 + ~FormatEtc() { if (mFormat.ptd) CoTaskMemFree(mFormat.ptd); } 1.28 + 1.29 + void CopyIn(const FORMATETC *aSrc) { 1.30 + if (!aSrc) { 1.31 + memset(&mFormat, 0, sizeof(FORMATETC)); 1.32 + return; 1.33 + } 1.34 + mFormat = *aSrc; 1.35 + if (aSrc->ptd) { 1.36 + mFormat.ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); 1.37 + *(mFormat.ptd) = *(aSrc->ptd); 1.38 + } 1.39 + } 1.40 + 1.41 + void CopyOut(LPFORMATETC aDest) { 1.42 + if (!aDest) 1.43 + return; 1.44 + *aDest = mFormat; 1.45 + if (mFormat.ptd) { 1.46 + aDest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); 1.47 + *(aDest->ptd) = *(mFormat.ptd); 1.48 + } 1.49 + } 1.50 + 1.51 +private: 1.52 + FORMATETC mFormat; 1.53 +}; 1.54 + 1.55 +/* 1.56 + * CEnumFormatEtc is created within IDataObject::EnumFormatEtc. This object lives 1.57 + * on its own, that is, QueryInterface only knows IUnknown and IEnumFormatEtc, 1.58 + * nothing more. We still use an outer unknown for reference counting, because as 1.59 + * long as this enumerator lives, the data object should live, thereby keeping the 1.60 + * application up. 1.61 + */ 1.62 + 1.63 +class CEnumFormatEtc MOZ_FINAL : public IEnumFORMATETC 1.64 +{ 1.65 +public: 1.66 + CEnumFormatEtc(nsTArray<FormatEtc>& aArray); 1.67 + CEnumFormatEtc(); 1.68 + ~CEnumFormatEtc(); 1.69 + 1.70 + // IUnknown impl. 1.71 + STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv); 1.72 + STDMETHODIMP_(ULONG) AddRef(); 1.73 + STDMETHODIMP_(ULONG) Release(); 1.74 + 1.75 + // IEnumFORMATETC impl. 1.76 + STDMETHODIMP Next(ULONG aMaxToFetch, FORMATETC *aResult, ULONG *aNumFetched); 1.77 + STDMETHODIMP Skip(ULONG aSkipNum); 1.78 + STDMETHODIMP Reset(); 1.79 + STDMETHODIMP Clone(LPENUMFORMATETC *aResult); // Addrefs 1.80 + 1.81 + // Utils 1.82 + void AddFormatEtc(LPFORMATETC aFormat); 1.83 + 1.84 +private: 1.85 + nsTArray<FormatEtc> mFormatList; // Formats 1.86 + ULONG mRefCnt; // Object reference count 1.87 + ULONG mCurrentIdx; // Current element 1.88 + 1.89 + void SetIndex(uint32_t aIdx); 1.90 +}; 1.91 + 1.92 + 1.93 +#endif //_IENUMFE_H_