~ubuntu-installer/wubi/trunk

« back to all changes in this revision

Viewing changes to src/7z/CPP/7zip/UI/FileManager/EnumFormatEtc.cpp

  • Committer: Agostino Russo
  • Date: 2008-12-04 00:37:30 UTC
  • Revision ID: agostino.russo@gmail.com-20081204003730-3o051yp78d6ujckl
* Bumped version to 9.04
* Added required binaries (will be compiled at a later stage)
* Added uninstallation page
* Added BitTorrent source
* Added documentation and licenses
* Connected download managers
* Fixed download status updates
* Added more information to the README
* Made the tasklist thread daemonic so that it does not prevent the
  main application from quitting

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// EnumFormatEtc.cpp
 
2
 
 
3
#include "StdAfx.h"
 
4
 
 
5
#include "EnumFormatEtc.h"
 
6
#include "MyCom2.h"
 
7
 
 
8
class CEnumFormatEtc : 
 
9
public IEnumFORMATETC,
 
10
public CMyUnknownImp
 
11
{
 
12
public:
 
13
  MY_UNKNOWN_IMP1_MT(IEnumFORMATETC)
 
14
    
 
15
  STDMETHOD(Next)(ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched);
 
16
  STDMETHOD(Skip)(ULONG celt); 
 
17
  STDMETHOD(Reset)(void);
 
18
  STDMETHOD(Clone)(IEnumFORMATETC **ppEnumFormatEtc);
 
19
  
 
20
  CEnumFormatEtc(const FORMATETC *pFormatEtc, ULONG numFormats);
 
21
  ~CEnumFormatEtc();
 
22
  
 
23
private:
 
24
  LONG m_RefCount;
 
25
  ULONG m_NumFormats;
 
26
  FORMATETC *m_Formats;
 
27
  ULONG m_Index;
 
28
};
 
29
 
 
30
static void DeepCopyFormatEtc(FORMATETC *dest, const FORMATETC *src)
 
31
{
 
32
  *dest = *src;
 
33
  if(src->ptd)
 
34
  {
 
35
    dest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
 
36
    *(dest->ptd) = *(src->ptd);
 
37
  }
 
38
}
 
39
 
 
40
CEnumFormatEtc::CEnumFormatEtc(const FORMATETC *pFormatEtc, ULONG numFormats)
 
41
{
 
42
  m_RefCount = 1;
 
43
  m_Index = 0;
 
44
  m_NumFormats = 0;
 
45
  m_Formats = new FORMATETC[numFormats];
 
46
  if(m_Formats)
 
47
  {
 
48
    m_NumFormats = numFormats;
 
49
    for(ULONG i = 0; i < numFormats; i++)
 
50
      DeepCopyFormatEtc(&m_Formats[i], &pFormatEtc[i]);
 
51
  }
 
52
}
 
53
 
 
54
CEnumFormatEtc::~CEnumFormatEtc()
 
55
{
 
56
  if(m_Formats)
 
57
  {
 
58
    for(ULONG i = 0; i < m_NumFormats; i++)
 
59
      if(m_Formats[i].ptd)
 
60
        CoTaskMemFree(m_Formats[i].ptd);
 
61
      delete[]m_Formats;
 
62
  }
 
63
}
 
64
 
 
65
STDMETHODIMP CEnumFormatEtc::Next(ULONG celt, FORMATETC *pFormatEtc, ULONG *pceltFetched)
 
66
{
 
67
  ULONG copied  = 0;
 
68
  if(celt == 0 || pFormatEtc == 0)
 
69
    return E_INVALIDARG;
 
70
  while(m_Index < m_NumFormats && copied < celt)
 
71
  {
 
72
    DeepCopyFormatEtc(&pFormatEtc[copied], &m_Formats[m_Index]);
 
73
    copied++;
 
74
    m_Index++;
 
75
  }
 
76
  if(pceltFetched != 0) 
 
77
    *pceltFetched = copied;
 
78
  return (copied == celt) ? S_OK : S_FALSE;
 
79
}
 
80
 
 
81
STDMETHODIMP CEnumFormatEtc::Skip(ULONG celt)
 
82
{
 
83
  m_Index += celt;
 
84
  return (m_Index <= m_NumFormats) ? S_OK : S_FALSE;
 
85
}
 
86
 
 
87
STDMETHODIMP CEnumFormatEtc::Reset(void)
 
88
{
 
89
  m_Index = 0;
 
90
  return S_OK;
 
91
}
 
92
 
 
93
STDMETHODIMP CEnumFormatEtc::Clone(IEnumFORMATETC ** ppEnumFormatEtc)
 
94
{
 
95
  HRESULT hResult = CreateEnumFormatEtc(m_NumFormats, m_Formats, ppEnumFormatEtc);
 
96
  if(hResult == S_OK)
 
97
    ((CEnumFormatEtc *)*ppEnumFormatEtc)->m_Index = m_Index;
 
98
  return hResult;
 
99
}
 
100
 
 
101
// replacement for SHCreateStdEnumFmtEtc
 
102
HRESULT CreateEnumFormatEtc(UINT numFormats, const FORMATETC *formats, IEnumFORMATETC **enumFormat)
 
103
{
 
104
  if(numFormats == 0 || formats == 0 || enumFormat == 0)
 
105
    return E_INVALIDARG;
 
106
  *enumFormat = new CEnumFormatEtc(formats, numFormats);
 
107
  return (*enumFormat) ? S_OK : E_OUTOFMEMORY;
 
108
}