1 /*
2 * PROJECT: ReactOS Font Shell Extension
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: CEnumFonts implementation
5 * COPYRIGHT: Copyright 2019 Mark Jansen <mark.jansen@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 WINE_DEFAULT_DEBUG_CHANNEL(fontext);
11
12
13
14 class CEnumFonts :
15 public CComObjectRootEx<CComMultiThreadModelNoCS>,
16 public IEnumIDList
17 {
18 private:
19 DWORD m_dwFlags;
20 ULONG m_Index;
21
22 public:
CEnumFonts()23 CEnumFonts()
24 :m_dwFlags(0)
25 ,m_Index(0)
26 {
27 }
28
Initialize(CFontExt * folder,DWORD flags)29 STDMETHODIMP Initialize(CFontExt* folder, DWORD flags)
30 {
31 m_dwFlags = flags;
32 m_Index = 0;
33 return S_OK;
34 }
35
36 // *** IEnumIDList methods ***
Next(ULONG celt,LPITEMIDLIST * rgelt,ULONG * pceltFetched)37 STDMETHODIMP Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched)
38 {
39 if (!rgelt || (!pceltFetched && celt != 1))
40 return E_POINTER;
41
42 HRESULT hr = S_OK;
43 ULONG Fetched = 0;
44
45 while (celt)
46 {
47 celt--;
48
49 if (m_Index < g_FontCache->Size())
50 {
51 CStringW Name = g_FontCache->Name(m_Index);
52 LPITEMIDLIST item = _ILCreate(Name, m_Index);
53 if (!item)
54 {
55 hr = Fetched ? S_FALSE : E_OUTOFMEMORY;
56 break;
57 }
58 rgelt[Fetched] = item;
59 m_Index++;
60 Fetched++;
61 }
62 else
63 {
64 hr = S_FALSE;
65 }
66 }
67
68 if (pceltFetched)
69 *pceltFetched = Fetched;
70 return hr;
71 }
Skip(ULONG celt)72 STDMETHODIMP Skip(ULONG celt)
73 {
74 m_Index += celt;
75 return S_OK;
76 }
Reset()77 STDMETHODIMP Reset()
78 {
79 m_Index = 0;
80 return S_OK;
81 }
Clone(IEnumIDList ** ppenum)82 STDMETHODIMP Clone(IEnumIDList **ppenum)
83 {
84 return E_NOTIMPL;
85 }
86
87
88 public:
89 DECLARE_NOT_AGGREGATABLE(CEnumFonts)
90 DECLARE_PROTECT_FINAL_CONSTRUCT()
91
92 BEGIN_COM_MAP(CEnumFonts)
93 COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList)
94 END_COM_MAP()
95 };
96
97
_CEnumFonts_CreateInstance(CFontExt * zip,DWORD flags,REFIID riid,LPVOID * ppvOut)98 HRESULT _CEnumFonts_CreateInstance(CFontExt* zip, DWORD flags, REFIID riid, LPVOID * ppvOut)
99 {
100 return ShellObjectCreatorInit<CEnumFonts>(zip, flags, riid, ppvOut);
101 }
102
103