1 /***************************************************************************************
2 * ItemMonikers implementation
4 * Copyright 1999 Noomen Hamza
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************************/
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
34 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
39 const CLSID CLSID_ItemMoniker
= {
40 0x304, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
43 /* ItemMoniker data structure */
44 typedef struct ItemMonikerImpl
{
46 ICOM_VTABLE(IMoniker
)* lpvtbl1
; /* VTable relative to the IMoniker interface.*/
48 /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
49 * two monikers are equal. That's whay IROTData interface is implemented by monikers.
51 ICOM_VTABLE(IROTData
)* lpvtbl2
; /* VTable relative to the IROTData interface.*/
53 ULONG ref
; /* reference counter for this object */
55 LPOLESTR itemName
; /* item name identified by this ItemMoniker */
57 LPOLESTR itemDelimiter
; /* Delimiter string */
61 /********************************************************************************/
62 /* ItemMoniker prototype functions : */
64 /* IUnknown prototype functions */
65 static HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
);
66 static ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
);
67 static ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
);
69 /* IPersist prototype functions */
70 static HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
, CLSID
*pClassID
);
72 /* IPersistStream prototype functions */
73 static HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
);
74 static HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
, IStream
* pStm
);
75 static HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
, IStream
* pStm
, BOOL fClearDirty
);
76 static HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
* pcbSize
);
78 /* IMoniker prototype functions */
79 static HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
80 static HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, REFIID riid
, VOID
** ppvResult
);
81 static HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,IBindCtx
* pbc
, DWORD dwReduceHowFar
,IMoniker
** ppmkToLeft
, IMoniker
** ppmkReduced
);
82 static HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,IMoniker
* pmkRight
,BOOL fOnlyIfNotGeneric
, IMoniker
** ppmkComposite
);
83 static HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
);
84 static HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
);
85 static HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
);
86 static HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, IMoniker
* pmkNewlyRunning
);
87 static HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
, IBindCtx
* pbc
, IMoniker
* pmkToLeft
, FILETIME
* pItemTime
);
88 static HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
);
89 static HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
, IMoniker
** ppmkPrefix
);
90 static HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
);
91 static HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR
*ppszDisplayName
);
92 static HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,IBindCtx
* pbc
, IMoniker
* pmkToLeft
, LPOLESTR pszDisplayName
, ULONG
* pchEaten
, IMoniker
** ppmkOut
);
93 static HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
);
95 /* Local function used by ItemMoniker implementation */
96 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* iface
, LPCOLESTR lpszDelim
,LPCOLESTR lpszPathName
);
97 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* iface
);
99 /********************************************************************************/
100 /* IROTData prototype functions */
102 /* IUnknown prototype functions */
103 static HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
* iface
,REFIID riid
,VOID
** ppvObject
);
104 static ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
* iface
);
105 static ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
);
107 /* IROTData prototype function */
108 static HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,BYTE
* pbData
,ULONG cbMax
,ULONG
* pcbData
);
110 /********************************************************************************/
111 /* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
112 /* IPersistStream and IMoniker functions. */
113 static ICOM_VTABLE(IMoniker
) VT_ItemMonikerImpl
=
115 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
116 ItemMonikerImpl_QueryInterface
,
117 ItemMonikerImpl_AddRef
,
118 ItemMonikerImpl_Release
,
119 ItemMonikerImpl_GetClassID
,
120 ItemMonikerImpl_IsDirty
,
121 ItemMonikerImpl_Load
,
122 ItemMonikerImpl_Save
,
123 ItemMonikerImpl_GetSizeMax
,
124 ItemMonikerImpl_BindToObject
,
125 ItemMonikerImpl_BindToStorage
,
126 ItemMonikerImpl_Reduce
,
127 ItemMonikerImpl_ComposeWith
,
128 ItemMonikerImpl_Enum
,
129 ItemMonikerImpl_IsEqual
,
130 ItemMonikerImpl_Hash
,
131 ItemMonikerImpl_IsRunning
,
132 ItemMonikerImpl_GetTimeOfLastChange
,
133 ItemMonikerImpl_Inverse
,
134 ItemMonikerImpl_CommonPrefixWith
,
135 ItemMonikerImpl_RelativePathTo
,
136 ItemMonikerImpl_GetDisplayName
,
137 ItemMonikerImpl_ParseDisplayName
,
138 ItemMonikerImpl_IsSystemMoniker
141 /********************************************************************************/
142 /* Virtual function table for the IROTData class. */
143 static ICOM_VTABLE(IROTData
) VT_ROTDataImpl
=
145 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
146 ItemMonikerROTDataImpl_QueryInterface
,
147 ItemMonikerROTDataImpl_AddRef
,
148 ItemMonikerROTDataImpl_Release
,
149 ItemMonikerROTDataImpl_GetComparaisonData
152 /*******************************************************************************
153 * ItemMoniker_QueryInterface
154 *******************************************************************************/
155 HRESULT WINAPI
ItemMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
157 ICOM_THIS(ItemMonikerImpl
,iface
);
159 TRACE("(%p,%p,%p)\n",This
,riid
,ppvObject
);
161 /* Perform a sanity check on the parameters.*/
162 if ( (This
==0) || (ppvObject
==0) )
165 /* Initialize the return parameter */
168 /* Compare the riid with the interface IDs implemented by this object.*/
169 if (IsEqualIID(&IID_IUnknown
, riid
) ||
170 IsEqualIID(&IID_IPersist
, riid
) ||
171 IsEqualIID(&IID_IPersistStream
, riid
) ||
172 IsEqualIID(&IID_IMoniker
, riid
)
176 else if (IsEqualIID(&IID_IROTData
, riid
))
177 *ppvObject
= (IROTData
*)&(This
->lpvtbl2
);
179 /* Check that we obtained an interface.*/
181 return E_NOINTERFACE
;
183 /* Query Interface always increases the reference count by one when it is successful */
184 ItemMonikerImpl_AddRef(iface
);
189 /******************************************************************************
191 ******************************************************************************/
192 ULONG WINAPI
ItemMonikerImpl_AddRef(IMoniker
* iface
)
194 ICOM_THIS(ItemMonikerImpl
,iface
);
196 TRACE("(%p)\n",This
);
198 return ++(This
->ref
);
201 /******************************************************************************
202 * ItemMoniker_Release
203 ******************************************************************************/
204 ULONG WINAPI
ItemMonikerImpl_Release(IMoniker
* iface
)
206 ICOM_THIS(ItemMonikerImpl
,iface
);
208 TRACE("(%p)\n",This
);
212 /* destroy the object if there's no more reference on it */
215 ItemMonikerImpl_Destroy(This
);
222 /******************************************************************************
223 * ItemMoniker_GetClassID
224 ******************************************************************************/
225 HRESULT WINAPI
ItemMonikerImpl_GetClassID(IMoniker
* iface
,CLSID
*pClassID
)
227 TRACE("(%p,%p),stub!\n",iface
,pClassID
);
232 *pClassID
= CLSID_ItemMoniker
;
237 /******************************************************************************
238 * ItemMoniker_IsDirty
239 ******************************************************************************/
240 HRESULT WINAPI
ItemMonikerImpl_IsDirty(IMoniker
* iface
)
242 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
243 method in the OLE-provided moniker interfaces always return S_FALSE because
244 their internal state never changes. */
246 TRACE("(%p)\n",iface
);
251 /******************************************************************************
253 ******************************************************************************/
254 HRESULT WINAPI
ItemMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
257 ICOM_THIS(ItemMonikerImpl
,iface
);
259 DWORD delimiterLength
,nameLength
,lenW
;
260 CHAR
*itemNameA
,*itemDelimiterA
;
263 /* for more details about data read by this function see coments of ItemMonikerImpl_Save function */
265 /* read item delimiter string length + 1 */
266 res
=IStream_Read(pStm
,&delimiterLength
,sizeof(DWORD
),&bread
);
267 if (bread
!= sizeof(DWORD
))
270 /* read item delimiter string */
271 if (!(itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
)))
272 return E_OUTOFMEMORY
;
273 res
=IStream_Read(pStm
,itemDelimiterA
,delimiterLength
,&bread
);
274 if (bread
!= delimiterLength
)
276 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
280 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, NULL
, 0 );
281 This
->itemDelimiter
=HeapReAlloc(GetProcessHeap(),0,This
->itemDelimiter
,lenW
*sizeof(WCHAR
));
282 if (!This
->itemDelimiter
)
284 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
285 return E_OUTOFMEMORY
;
287 MultiByteToWideChar( CP_ACP
, 0, itemDelimiterA
, -1, This
->itemDelimiter
, lenW
);
288 HeapFree( GetProcessHeap(), 0, itemDelimiterA
);
290 /* read item name string length + 1*/
291 res
=IStream_Read(pStm
,&nameLength
,sizeof(DWORD
),&bread
);
292 if (bread
!= sizeof(DWORD
))
295 /* read item name string */
296 if (!(itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
)))
297 return E_OUTOFMEMORY
;
298 res
=IStream_Read(pStm
,itemNameA
,nameLength
,&bread
);
299 if (bread
!= nameLength
)
301 HeapFree( GetProcessHeap(), 0, itemNameA
);
305 lenW
= MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, NULL
, 0 );
306 This
->itemName
=HeapReAlloc(GetProcessHeap(),0,This
->itemName
,lenW
*sizeof(WCHAR
));
309 HeapFree( GetProcessHeap(), 0, itemNameA
);
310 return E_OUTOFMEMORY
;
312 MultiByteToWideChar( CP_ACP
, 0, itemNameA
, -1, This
->itemName
, lenW
);
313 HeapFree( GetProcessHeap(), 0, itemNameA
);
318 /******************************************************************************
320 ******************************************************************************/
321 HRESULT WINAPI
ItemMonikerImpl_Save(IMoniker
* iface
,
322 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
323 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
325 ICOM_THIS(ItemMonikerImpl
,iface
);
327 CHAR
*itemNameA
,*itemDelimiterA
;
329 /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
330 /* 2) String (type A): item delimiter string ('\0' included) */
331 /* 3) DWORD : size of item name string ('\0' included) */
332 /* 4) String (type A): item name string ('\0' included) */
334 DWORD nameLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, NULL
, 0, NULL
, NULL
);
335 DWORD delimiterLength
= WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, NULL
, 0, NULL
, NULL
);
336 itemNameA
=HeapAlloc(GetProcessHeap(),0,nameLength
);
337 itemDelimiterA
=HeapAlloc(GetProcessHeap(),0,delimiterLength
);
338 WideCharToMultiByte( CP_ACP
, 0, This
->itemName
, -1, itemNameA
, nameLength
, NULL
, NULL
);
339 WideCharToMultiByte( CP_ACP
, 0, This
->itemDelimiter
, -1, itemDelimiterA
, delimiterLength
, NULL
, NULL
);
341 res
=IStream_Write(pStm
,&delimiterLength
,sizeof(DWORD
),NULL
);
342 res
=IStream_Write(pStm
,itemDelimiterA
,delimiterLength
* sizeof(CHAR
),NULL
);
343 res
=IStream_Write(pStm
,&nameLength
,sizeof(DWORD
),NULL
);
344 res
=IStream_Write(pStm
,itemNameA
,nameLength
* sizeof(CHAR
),NULL
);
349 /******************************************************************************
350 * ItemMoniker_GetSizeMax
351 ******************************************************************************/
352 HRESULT WINAPI
ItemMonikerImpl_GetSizeMax(IMoniker
* iface
,
353 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
355 ICOM_THIS(ItemMonikerImpl
,iface
);
356 DWORD delimiterLength
=lstrlenW(This
->itemDelimiter
)+1;
357 DWORD nameLength
=lstrlenW(This
->itemName
)+1;
359 TRACE("(%p,%p)\n",iface
,pcbSize
);
364 /* for more details see ItemMonikerImpl_Save coments */
366 pcbSize
->u
.LowPart
= sizeof(DWORD
) + /* DWORD which contains delimiter length */
367 delimiterLength
+ /* item delimiter string */
368 sizeof(DWORD
) + /* DWORD which contains item name length */
369 nameLength
+ /* item name string */
370 34; /* this constant was added ! because when I tested this function it usually */
371 /* returns 34 bytes more than the number of bytes used by IMoniker::Save function */
372 pcbSize
->u
.HighPart
=0;
377 /******************************************************************************
378 * ItemMoniker_Construct (local function)
379 *******************************************************************************/
380 HRESULT WINAPI
ItemMonikerImpl_Construct(ItemMonikerImpl
* This
, LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
)
383 int sizeStr1
=lstrlenW(lpszItem
), sizeStr2
;
384 static const OLECHAR emptystr
[1];
387 TRACE("(%p,%p)\n",This
,lpszItem
);
389 /* Initialize the virtual fgunction table. */
390 This
->lpvtbl1
= &VT_ItemMonikerImpl
;
391 This
->lpvtbl2
= &VT_ROTDataImpl
;
394 This
->itemName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr1
+1));
396 return E_OUTOFMEMORY
;
397 lstrcpyW(This
->itemName
,lpszItem
);
400 FIXME("lpszDelim is NULL. Using empty string which is possibly wrong.\n");
402 delim
= lpszDelim
? lpszDelim
: emptystr
;
404 sizeStr2
=lstrlenW(delim
);
405 This
->itemDelimiter
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr2
+1));
406 if (!This
->itemDelimiter
) {
407 HeapFree(GetProcessHeap(),0,This
->itemName
);
408 return E_OUTOFMEMORY
;
410 lstrcpyW(This
->itemDelimiter
,delim
);
414 /******************************************************************************
415 * ItemMoniker_Destroy (local function)
416 *******************************************************************************/
417 HRESULT WINAPI
ItemMonikerImpl_Destroy(ItemMonikerImpl
* This
)
419 TRACE("(%p)\n",This
);
422 HeapFree(GetProcessHeap(),0,This
->itemName
);
424 if (This
->itemDelimiter
)
425 HeapFree(GetProcessHeap(),0,This
->itemDelimiter
);
427 HeapFree(GetProcessHeap(),0,This
);
432 /******************************************************************************
433 * ItemMoniker_BindToObject
434 ******************************************************************************/
435 HRESULT WINAPI
ItemMonikerImpl_BindToObject(IMoniker
* iface
,
441 ICOM_THIS(ItemMonikerImpl
,iface
);
444 IID refid
=IID_IOleItemContainer
;
445 IOleItemContainer
*poic
=0;
447 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
457 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&refid
,(void**)&poic
);
461 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,riid
,ppvResult
);
463 IOleItemContainer_Release(poic
);
469 /******************************************************************************
470 * ItemMoniker_BindToStorage
471 ******************************************************************************/
472 HRESULT WINAPI
ItemMonikerImpl_BindToStorage(IMoniker
* iface
,
478 ICOM_THIS(ItemMonikerImpl
,iface
);
481 IOleItemContainer
*poic
=0;
483 TRACE("(%p,%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,riid
,ppvResult
);
490 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
494 res
=IOleItemContainer_GetObjectStorage(poic
,This
->itemName
,pbc
,riid
,ppvResult
);
496 IOleItemContainer_Release(poic
);
502 /******************************************************************************
504 ******************************************************************************/
505 HRESULT WINAPI
ItemMonikerImpl_Reduce(IMoniker
* iface
,
507 DWORD dwReduceHowFar
,
508 IMoniker
** ppmkToLeft
,
509 IMoniker
** ppmkReduced
)
511 TRACE("(%p,%p,%ld,%p,%p)\n",iface
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
513 if (ppmkReduced
==NULL
)
516 ItemMonikerImpl_AddRef(iface
);
520 return MK_S_REDUCED_TO_SELF
;
522 /******************************************************************************
523 * ItemMoniker_ComposeWith
524 ******************************************************************************/
525 HRESULT WINAPI
ItemMonikerImpl_ComposeWith(IMoniker
* iface
,
527 BOOL fOnlyIfNotGeneric
,
528 IMoniker
** ppmkComposite
)
532 IEnumMoniker
* penumMk
=0;
533 IMoniker
*pmostLeftMk
=0;
534 IMoniker
* tempMkComposite
=0;
536 TRACE("(%p,%p,%d,%p)\n",iface
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
538 if ((ppmkComposite
==NULL
)||(pmkRight
==NULL
))
543 IMoniker_IsSystemMoniker(pmkRight
,&mkSys
);
545 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
546 if(mkSys
==MKSYS_ANTIMONIKER
)
550 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
551 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
553 if(mkSys
==MKSYS_GENERICCOMPOSITE
){
555 res
=IMoniker_Enum(pmkRight
,TRUE
,&penumMk
);
560 res
=IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
);
562 IMoniker_IsSystemMoniker(pmostLeftMk
,&mkSys2
);
564 if(mkSys2
==MKSYS_ANTIMONIKER
){
566 IMoniker_Release(pmostLeftMk
);
568 tempMkComposite
=iface
;
569 IMoniker_AddRef(iface
);
571 while(IEnumMoniker_Next(penumMk
,1,&pmostLeftMk
,NULL
)==S_OK
){
573 res
=CreateGenericComposite(tempMkComposite
,pmostLeftMk
,ppmkComposite
);
575 IMoniker_Release(tempMkComposite
);
576 IMoniker_Release(pmostLeftMk
);
578 tempMkComposite
=*ppmkComposite
;
579 IMoniker_AddRef(tempMkComposite
);
584 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
586 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
587 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
588 a NULL moniker and a return value of MK_E_NEEDGENERIC */
590 if (!fOnlyIfNotGeneric
)
591 return CreateGenericComposite(iface
,pmkRight
,ppmkComposite
);
594 return MK_E_NEEDGENERIC
;
597 /******************************************************************************
599 ******************************************************************************/
600 HRESULT WINAPI
ItemMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
602 TRACE("(%p,%d,%p)\n",iface
,fForward
,ppenumMoniker
);
604 if (ppenumMoniker
== NULL
)
607 *ppenumMoniker
= NULL
;
612 /******************************************************************************
613 * ItemMoniker_IsEqual
614 ******************************************************************************/
615 HRESULT WINAPI
ItemMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
619 LPOLESTR dispName1
,dispName2
;
621 HRESULT res
= S_FALSE
;
623 TRACE("(%p,%p)\n",iface
,pmkOtherMoniker
);
625 if (!pmkOtherMoniker
) return S_FALSE
;
628 /* check if both are ItemMoniker */
629 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker
,&clsid
))) return S_FALSE
;
630 if(!IsEqualCLSID(&clsid
,&CLSID_ItemMoniker
)) return S_FALSE
;
632 /* check if both displaynames are the same */
633 if(SUCCEEDED ((res
= CreateBindCtx(0,&bind
)))) {
634 if(SUCCEEDED (IMoniker_GetDisplayName(iface
,bind
,NULL
,&dispName1
))) {
635 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&dispName2
))) {
636 if(lstrcmpW(dispName1
,dispName2
)==0) res
= S_OK
;
637 CoTaskMemFree(dispName2
);
639 CoTaskMemFree(dispName1
);
645 /******************************************************************************
647 ******************************************************************************/
648 HRESULT WINAPI
ItemMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
650 ICOM_THIS(ItemMonikerImpl
,iface
);
652 int h
= 0,i
,skip
,len
;
659 val
= This
->itemName
;
663 for (i
= len
; i
> 0; i
--) {
664 h
= (h
* 37) + val
[off
++];
667 /* only sample some characters */
669 for (i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
670 h
= (h
* 39) + val
[off
];
679 /******************************************************************************
680 * ItemMoniker_IsRunning
681 ******************************************************************************/
682 HRESULT WINAPI
ItemMonikerImpl_IsRunning(IMoniker
* iface
,
685 IMoniker
* pmkNewlyRunning
)
687 IRunningObjectTable
* rot
;
689 IOleItemContainer
*poic
=0;
690 ICOM_THIS(ItemMonikerImpl
,iface
);
692 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pmkNewlyRunning
);
694 /* If pmkToLeft is NULL, this method returns TRUE if pmkNewlyRunning is non-NULL and is equal to this */
695 /* moniker. Otherwise, the method checks the ROT to see whether this moniker is running. */
697 if ((pmkNewlyRunning
!=NULL
)&&(IMoniker_IsEqual(pmkNewlyRunning
,iface
)==S_OK
))
703 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
708 res
= IRunningObjectTable_IsRunning(rot
,iface
);
710 IRunningObjectTable_Release(rot
);
714 /* If pmkToLeft is non-NULL, the method calls IMoniker::BindToObject on the pmkToLeft parameter, */
715 /* requesting an IOleItemContainer interface pointer. The method then calls IOleItemContainer::IsRunning,*/
716 /* passing the string contained within this moniker. */
718 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
722 res
=IOleItemContainer_IsRunning(poic
,This
->itemName
);
724 IOleItemContainer_Release(poic
);
731 /******************************************************************************
732 * ItemMoniker_GetTimeOfLastChange
733 ******************************************************************************/
734 HRESULT WINAPI
ItemMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
739 IRunningObjectTable
* rot
;
741 IMoniker
*compositeMk
;
743 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,pItemTime
);
748 /* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
751 return MK_E_NOTBINDABLE
;
754 /* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
755 /* the time of last change. If the object is not in the ROT, the method calls */
756 /* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
758 res
=CreateGenericComposite(pmkToLeft
,iface
,&compositeMk
);
760 res
=IBindCtx_GetRunningObjectTable(pbc
,&rot
);
762 if (IRunningObjectTable_GetTimeOfLastChange(rot
,compositeMk
,pItemTime
)!=S_OK
)
764 res
=IMoniker_GetTimeOfLastChange(pmkToLeft
,pbc
,NULL
,pItemTime
);
766 IMoniker_Release(compositeMk
);
772 /******************************************************************************
773 * ItemMoniker_Inverse
774 ******************************************************************************/
775 HRESULT WINAPI
ItemMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
777 TRACE("(%p,%p)\n",iface
,ppmk
);
782 return CreateAntiMoniker(ppmk
);
785 /******************************************************************************
786 * ItemMoniker_CommonPrefixWith
787 ******************************************************************************/
788 HRESULT WINAPI
ItemMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
791 IMoniker_IsSystemMoniker(pmkOther
,&mkSys
);
792 /* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
793 /* to this moniker and returns MK_S_US */
795 if((mkSys
==MKSYS_ITEMMONIKER
) && (IMoniker_IsEqual(iface
,pmkOther
)==S_OK
) ){
799 IMoniker_AddRef(iface
);
804 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
805 /* the case where the other moniker is a generic composite. */
806 return MonikerCommonPrefixWith(iface
,pmkOther
,ppmkPrefix
);
809 /******************************************************************************
810 * ItemMoniker_RelativePathTo
811 ******************************************************************************/
812 HRESULT WINAPI
ItemMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
814 TRACE("(%p,%p,%p)\n",iface
,pmOther
,ppmkRelPath
);
816 if (ppmkRelPath
==NULL
)
821 return MK_E_NOTBINDABLE
;
824 /******************************************************************************
825 * ItemMoniker_GetDisplayName
826 ******************************************************************************/
827 HRESULT WINAPI
ItemMonikerImpl_GetDisplayName(IMoniker
* iface
,
830 LPOLESTR
*ppszDisplayName
)
832 ICOM_THIS(ItemMonikerImpl
,iface
);
834 TRACE("(%p,%p,%p,%p)\n",iface
,pbc
,pmkToLeft
,ppszDisplayName
);
836 if (ppszDisplayName
==NULL
)
839 if (pmkToLeft
!=NULL
){
843 *ppszDisplayName
=CoTaskMemAlloc(sizeof(WCHAR
)*(lstrlenW(This
->itemDelimiter
)+lstrlenW(This
->itemName
)+1));
845 if (*ppszDisplayName
==NULL
)
846 return E_OUTOFMEMORY
;
848 lstrcpyW(*ppszDisplayName
,This
->itemDelimiter
);
849 lstrcatW(*ppszDisplayName
,This
->itemName
);
854 /******************************************************************************
855 * ItemMoniker_ParseDisplayName
856 ******************************************************************************/
857 HRESULT WINAPI
ItemMonikerImpl_ParseDisplayName(IMoniker
* iface
,
860 LPOLESTR pszDisplayName
,
864 IOleItemContainer
* poic
=0;
865 IParseDisplayName
* ppdn
=0;
866 LPOLESTR displayName
;
868 ICOM_THIS(ItemMonikerImpl
,iface
);
870 /* If pmkToLeft is NULL, this method returns MK_E_SYNTAX */
876 /* Otherwise, the method calls IMoniker::BindToObject on the pmkToLeft parameter, requesting an */
877 /* IParseDisplayName interface pointer to the object identified by the moniker, and passes the display */
878 /* name to IParseDisplayName::ParseDisplayName */
879 res
=IMoniker_BindToObject(pmkToLeft
,pbc
,NULL
,&IID_IOleItemContainer
,(void**)&poic
);
883 res
=IOleItemContainer_GetObject(poic
,This
->itemName
,BINDSPEED_MODERATE
,pbc
,&IID_IParseDisplayName
,(void**)&ppdn
);
885 res
=IMoniker_GetDisplayName(iface
,pbc
,NULL
,&displayName
);
887 res
=IParseDisplayName_ParseDisplayName(ppdn
,pbc
,displayName
,pchEaten
,ppmkOut
);
889 IOleItemContainer_Release(poic
);
890 IParseDisplayName_Release(ppdn
);
896 /******************************************************************************
897 * ItemMoniker_IsSystemMoniker
898 ******************************************************************************/
899 HRESULT WINAPI
ItemMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
901 TRACE("(%p,%p)\n",iface
,pwdMksys
);
906 (*pwdMksys
)=MKSYS_ITEMMONIKER
;
911 /*******************************************************************************
912 * ItemMonikerIROTData_QueryInterface
913 *******************************************************************************/
914 HRESULT WINAPI
ItemMonikerROTDataImpl_QueryInterface(IROTData
*iface
,REFIID riid
,VOID
** ppvObject
)
917 ICOM_THIS_From_IROTData(IMoniker
, iface
);
919 TRACE("(%p,%p,%p)\n",iface
,riid
,ppvObject
);
921 return ItemMonikerImpl_QueryInterface(This
, riid
, ppvObject
);
924 /***********************************************************************
925 * ItemMonikerIROTData_AddRef
927 ULONG WINAPI
ItemMonikerROTDataImpl_AddRef(IROTData
*iface
)
929 ICOM_THIS_From_IROTData(IMoniker
, iface
);
931 TRACE("(%p)\n",iface
);
933 return ItemMonikerImpl_AddRef(This
);
936 /***********************************************************************
937 * ItemMonikerIROTData_Release
939 ULONG WINAPI
ItemMonikerROTDataImpl_Release(IROTData
* iface
)
941 ICOM_THIS_From_IROTData(IMoniker
, iface
);
943 TRACE("(%p)\n",iface
);
945 return ItemMonikerImpl_Release(This
);
948 /******************************************************************************
949 * ItemMonikerIROTData_GetComparaisonData
950 ******************************************************************************/
951 HRESULT WINAPI
ItemMonikerROTDataImpl_GetComparaisonData(IROTData
* iface
,
960 /******************************************************************************
961 * CreateItemMoniker [OLE32.@]
962 ******************************************************************************/
963 HRESULT WINAPI
CreateItemMoniker(LPCOLESTR lpszDelim
,LPCOLESTR lpszItem
, LPMONIKER
* ppmk
)
965 ItemMonikerImpl
* newItemMoniker
= 0;
967 IID riid
=IID_IMoniker
;
969 TRACE("(%p,%p,%p)\n",lpszDelim
,lpszItem
,ppmk
);
971 newItemMoniker
= HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl
));
973 if (newItemMoniker
== 0)
974 return STG_E_INSUFFICIENTMEMORY
;
976 hr
= ItemMonikerImpl_Construct(newItemMoniker
,lpszDelim
,lpszItem
);
980 HeapFree(GetProcessHeap(),0,newItemMoniker
);
984 return ItemMonikerImpl_QueryInterface((IMoniker
*)newItemMoniker
,&riid
,(void**)ppmk
);