widget/windows/IEnumFE.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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
    11  */
    13 #include <ole2.h>
    15 #include "nsTArray.h"
    16 #include "mozilla/Attributes.h"
    18 // FORMATETC container
    19 class FormatEtc
    20 {
    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;
    30     }
    31     mFormat = *aSrc;
    32     if (aSrc->ptd) {
    33         mFormat.ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
    34         *(mFormat.ptd) = *(aSrc->ptd);
    35     }
    36   }
    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);
    45     }
    46   }
    48 private:
    49   FORMATETC mFormat;
    50 };
    52 /*
    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.
    58  */
    60 class CEnumFormatEtc MOZ_FINAL : public IEnumFORMATETC
    61 {
    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);
    87 };
    90 #endif //_IENUMFE_H_

mercurial