| 1 | /*
|
|---|
| 2 | * Implementation of IEnumUnknown (for internal use).
|
|---|
| 3 | *
|
|---|
| 4 | * hidenori@a2.ctktv.ne.jp
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #include "config.h"
|
|---|
| 8 |
|
|---|
| 9 | #include "windef.h"
|
|---|
| 10 | #include "winbase.h"
|
|---|
| 11 | #include "wingdi.h"
|
|---|
| 12 | #include "winerror.h"
|
|---|
| 13 | #include "wine/obj_base.h"
|
|---|
| 14 | #include "wine/obj_oleaut.h"
|
|---|
| 15 | #include "strmif.h"
|
|---|
| 16 | #include "control.h"
|
|---|
| 17 | #include "uuids.h"
|
|---|
| 18 |
|
|---|
| 19 | #include "debugtools.h"
|
|---|
| 20 | DEFAULT_DEBUG_CHANNEL(quartz);
|
|---|
| 21 |
|
|---|
| 22 | #include "quartz_private.h"
|
|---|
| 23 | #include "enumunk.h"
|
|---|
| 24 | #include "iunk.h"
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | typedef struct IEnumUnknownImpl
|
|---|
| 29 | {
|
|---|
| 30 | ICOM_VFIELD(IEnumUnknown);
|
|---|
| 31 | } IEnumUnknownImpl;
|
|---|
| 32 |
|
|---|
| 33 | typedef struct
|
|---|
| 34 | {
|
|---|
| 35 | QUARTZ_IUnkImpl unk;
|
|---|
| 36 | IEnumUnknownImpl enumunk;
|
|---|
| 37 | struct QUARTZ_IFEntry IFEntries[1];
|
|---|
| 38 | QUARTZ_CompList* pCompList;
|
|---|
| 39 | QUARTZ_CompListItem* pItemCur;
|
|---|
| 40 | } CEnumUnknown;
|
|---|
| 41 |
|
|---|
| 42 | #define CEnumUnknown_THIS(iface,member) CEnumUnknown* This = ((CEnumUnknown*)(((char*)iface)-offsetof(CEnumUnknown,member)))
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | static HRESULT WINAPI
|
|---|
| 48 | IEnumUnknown_fnQueryInterface(IEnumUnknown* iface,REFIID riid,void** ppobj)
|
|---|
| 49 | {
|
|---|
| 50 | CEnumUnknown_THIS(iface,enumunk);
|
|---|
| 51 |
|
|---|
| 52 | TRACE("(%p)->()\n",This);
|
|---|
| 53 |
|
|---|
| 54 | return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | static ULONG WINAPI
|
|---|
| 58 | IEnumUnknown_fnAddRef(IEnumUnknown* iface)
|
|---|
| 59 | {
|
|---|
| 60 | CEnumUnknown_THIS(iface,enumunk);
|
|---|
| 61 |
|
|---|
| 62 | TRACE("(%p)->()\n",This);
|
|---|
| 63 |
|
|---|
| 64 | return IUnknown_AddRef(This->unk.punkControl);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | static ULONG WINAPI
|
|---|
| 68 | IEnumUnknown_fnRelease(IEnumUnknown* iface)
|
|---|
| 69 | {
|
|---|
| 70 | CEnumUnknown_THIS(iface,enumunk);
|
|---|
| 71 |
|
|---|
| 72 | TRACE("(%p)->()\n",This);
|
|---|
| 73 |
|
|---|
| 74 | return IUnknown_Release(This->unk.punkControl);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | static HRESULT WINAPI
|
|---|
| 78 | IEnumUnknown_fnNext(IEnumUnknown* iface,ULONG cReq,IUnknown** ppunk,ULONG* pcFetched)
|
|---|
| 79 | {
|
|---|
| 80 | CEnumUnknown_THIS(iface,enumunk);
|
|---|
| 81 | HRESULT hr;
|
|---|
| 82 | ULONG cFetched;
|
|---|
| 83 |
|
|---|
| 84 | TRACE("(%p)->(%lu,%p,%p)\n",This,cReq,ppunk,pcFetched);
|
|---|
| 85 |
|
|---|
| 86 | if ( pcFetched == NULL && cReq > 1 )
|
|---|
| 87 | return E_INVALIDARG;
|
|---|
| 88 | if ( ppunk == NULL )
|
|---|
| 89 | return E_POINTER;
|
|---|
| 90 |
|
|---|
| 91 | QUARTZ_CompList_Lock( This->pCompList );
|
|---|
| 92 |
|
|---|
| 93 | hr = NOERROR;
|
|---|
| 94 | cFetched = 0;
|
|---|
| 95 | while ( cReq > 0 )
|
|---|
| 96 | {
|
|---|
| 97 | if ( This->pItemCur == NULL )
|
|---|
| 98 | {
|
|---|
| 99 | hr = S_FALSE;
|
|---|
| 100 | break;
|
|---|
| 101 | }
|
|---|
| 102 | ppunk[ cFetched ++ ] = QUARTZ_CompList_GetItemPtr( This->pItemCur );
|
|---|
| 103 | IUnknown_AddRef( *ppunk );
|
|---|
| 104 |
|
|---|
| 105 | This->pItemCur =
|
|---|
| 106 | QUARTZ_CompList_GetNext( This->pCompList, This->pItemCur );
|
|---|
| 107 | cReq --;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | QUARTZ_CompList_Unlock( This->pCompList );
|
|---|
| 111 |
|
|---|
| 112 | if ( pcFetched != NULL )
|
|---|
| 113 | *pcFetched = cFetched;
|
|---|
| 114 |
|
|---|
| 115 | return hr;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | static HRESULT WINAPI
|
|---|
| 119 | IEnumUnknown_fnSkip(IEnumUnknown* iface,ULONG cSkip)
|
|---|
| 120 | {
|
|---|
| 121 | CEnumUnknown_THIS(iface,enumunk);
|
|---|
| 122 | HRESULT hr;
|
|---|
| 123 |
|
|---|
| 124 | TRACE("(%p)->()\n",This);
|
|---|
| 125 |
|
|---|
| 126 | QUARTZ_CompList_Lock( This->pCompList );
|
|---|
| 127 |
|
|---|
| 128 | hr = NOERROR;
|
|---|
| 129 | while ( cSkip > 0 )
|
|---|
| 130 | {
|
|---|
| 131 | if ( This->pItemCur == NULL )
|
|---|
| 132 | {
|
|---|
| 133 | hr = S_FALSE;
|
|---|
| 134 | break;
|
|---|
| 135 | }
|
|---|
| 136 | This->pItemCur =
|
|---|
| 137 | QUARTZ_CompList_GetNext( This->pCompList, This->pItemCur );
|
|---|
| 138 | cSkip --;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | QUARTZ_CompList_Unlock( This->pCompList );
|
|---|
| 142 |
|
|---|
| 143 | return hr;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | static HRESULT WINAPI
|
|---|
| 147 | IEnumUnknown_fnReset(IEnumUnknown* iface)
|
|---|
| 148 | {
|
|---|
| 149 | CEnumUnknown_THIS(iface,enumunk);
|
|---|
| 150 |
|
|---|
| 151 | TRACE("(%p)->()\n",This);
|
|---|
| 152 |
|
|---|
| 153 | QUARTZ_CompList_Lock( This->pCompList );
|
|---|
| 154 |
|
|---|
| 155 | This->pItemCur = QUARTZ_CompList_GetFirst( This->pCompList );
|
|---|
| 156 |
|
|---|
| 157 | QUARTZ_CompList_Unlock( This->pCompList );
|
|---|
| 158 |
|
|---|
| 159 | return NOERROR;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | static HRESULT WINAPI
|
|---|
| 163 | IEnumUnknown_fnClone(IEnumUnknown* iface,IEnumUnknown** ppunk)
|
|---|
| 164 | {
|
|---|
| 165 | CEnumUnknown_THIS(iface,enumunk);
|
|---|
| 166 | HRESULT hr;
|
|---|
| 167 |
|
|---|
| 168 | TRACE("(%p)->()\n",This);
|
|---|
| 169 |
|
|---|
| 170 | if ( ppunk == NULL )
|
|---|
| 171 | return E_POINTER;
|
|---|
| 172 |
|
|---|
| 173 | QUARTZ_CompList_Lock( This->pCompList );
|
|---|
| 174 |
|
|---|
| 175 | hr = QUARTZ_CreateEnumUnknown(
|
|---|
| 176 | This->IFEntries[0].piid,
|
|---|
| 177 | (void**)ppunk,
|
|---|
| 178 | This->pCompList );
|
|---|
| 179 |
|
|---|
| 180 | QUARTZ_CompList_Unlock( This->pCompList );
|
|---|
| 181 |
|
|---|
| 182 | return hr;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 | static ICOM_VTABLE(IEnumUnknown) ienumunk =
|
|---|
| 187 | {
|
|---|
| 188 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 189 | /* IUnknown fields */
|
|---|
| 190 | IEnumUnknown_fnQueryInterface,
|
|---|
| 191 | IEnumUnknown_fnAddRef,
|
|---|
| 192 | IEnumUnknown_fnRelease,
|
|---|
| 193 | /* IEnumUnknown fields */
|
|---|
| 194 | IEnumUnknown_fnNext,
|
|---|
| 195 | IEnumUnknown_fnSkip,
|
|---|
| 196 | IEnumUnknown_fnReset,
|
|---|
| 197 | IEnumUnknown_fnClone,
|
|---|
| 198 | };
|
|---|
| 199 |
|
|---|
| 200 | void QUARTZ_DestroyEnumUnknown(IUnknown* punk)
|
|---|
| 201 | {
|
|---|
| 202 | CEnumUnknown_THIS(punk,unk);
|
|---|
| 203 |
|
|---|
| 204 | if ( This->pCompList != NULL )
|
|---|
| 205 | QUARTZ_CompList_Free( This->pCompList );
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | HRESULT QUARTZ_CreateEnumUnknown(
|
|---|
| 209 | REFIID riidEnum, void** ppobj, const QUARTZ_CompList* pCompList )
|
|---|
| 210 | {
|
|---|
| 211 | CEnumUnknown* penum;
|
|---|
| 212 | QUARTZ_CompList* pCompListDup;
|
|---|
| 213 |
|
|---|
| 214 | TRACE("(%s,%p,%p)\n",debugstr_guid(riidEnum),ppobj,pCompList);
|
|---|
| 215 |
|
|---|
| 216 | pCompListDup = QUARTZ_CompList_Dup( pCompList, FALSE );
|
|---|
| 217 | if ( pCompListDup == NULL )
|
|---|
| 218 | return E_OUTOFMEMORY;
|
|---|
| 219 |
|
|---|
| 220 | penum = (CEnumUnknown*)QUARTZ_AllocObj( sizeof(CEnumUnknown) );
|
|---|
| 221 | if ( penum == NULL )
|
|---|
| 222 | {
|
|---|
| 223 | QUARTZ_CompList_Free( pCompListDup );
|
|---|
| 224 | return E_OUTOFMEMORY;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | QUARTZ_IUnkInit( &penum->unk, NULL );
|
|---|
| 228 | ICOM_VTBL(&penum->enumunk) = &ienumunk;
|
|---|
| 229 |
|
|---|
| 230 | penum->IFEntries[0].piid = riidEnum;
|
|---|
| 231 | penum->IFEntries[0].ofsVTPtr =
|
|---|
| 232 | offsetof(CEnumUnknown,enumunk)-offsetof(CEnumUnknown,unk);
|
|---|
| 233 | penum->pCompList = pCompListDup;
|
|---|
| 234 | penum->pItemCur = QUARTZ_CompList_GetFirst( pCompListDup );
|
|---|
| 235 |
|
|---|
| 236 | penum->unk.pEntries = penum->IFEntries;
|
|---|
| 237 | penum->unk.dwEntries = 1;
|
|---|
| 238 | penum->unk.pOnFinalRelease = QUARTZ_DestroyEnumUnknown;
|
|---|
| 239 |
|
|---|
| 240 | *ppobj = (void*)(&penum->enumunk);
|
|---|
| 241 |
|
|---|
| 242 | return S_OK;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|