compositemoniker.c 53.1 KB
Newer Older
1
/*
2
 * CompositeMonikers implementation
Noomen Hamza's avatar
Noomen Hamza committed
3
 *
4
 * Copyright 1999  Noomen Hamza
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 20
 */

Noomen Hamza's avatar
Noomen Hamza committed
21
#include <assert.h>
22
#include <stdarg.h>
23
#include <string.h>
24

25
#define COBJMACROS
26 27
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
28

29
#include "windef.h"
30
#include "winbase.h"
31
#include "winuser.h"
Noomen Hamza's avatar
Noomen Hamza committed
32
#include "winerror.h"
33
#include "wine/debug.h"
34
#include "wine/unicode.h"
Noomen Hamza's avatar
Noomen Hamza committed
35
#include "ole2.h"
36
#include "moniker.h"
Noomen Hamza's avatar
Noomen Hamza committed
37

38
WINE_DEFAULT_DEBUG_CHANNEL(ole);
39

40
static const CLSID CLSID_CompositeMoniker = {
41 42 43
  0x309, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}
};

Noomen Hamza's avatar
Noomen Hamza committed
44 45 46 47 48
#define  BLOCK_TAB_SIZE 5 /* represent the first size table and it's increment block size */

/* CompositeMoniker data structure */
typedef struct CompositeMonikerImpl{

49
    const IMonikerVtbl*  lpvtbl1;  /* VTable relative to the IMoniker interface.*/
Noomen Hamza's avatar
Noomen Hamza committed
50

51 52
    /* The ROT (RunningObjectTable implementation) uses the IROTData
     * interface to test whether two monikers are equal. That's why IROTData
53
     * interface is implemented by monikers.
Noomen Hamza's avatar
Noomen Hamza committed
54
     */
55
    const IROTDataVtbl*  lpvtbl2;  /* VTable relative to the IROTData interface.*/
Noomen Hamza's avatar
Noomen Hamza committed
56

57
    LONG ref; /* reference counter for this object */
Noomen Hamza's avatar
Noomen Hamza committed
58 59 60 61 62 63 64 65 66 67 68 69 70

    IMoniker** tabMoniker; /* dynamaic table containing all components (monikers) of this composite moniker */

    ULONG    tabSize;      /* size of tabMoniker */

    ULONG    tabLastIndex;  /* first free index in tabMoniker */

} CompositeMonikerImpl;


/* EnumMoniker data structure */
typedef struct EnumMonikerImpl{

71
    const IEnumMonikerVtbl *lpVtbl;  /* VTable relative to the IEnumMoniker interface.*/
Noomen Hamza's avatar
Noomen Hamza committed
72

73
    LONG ref; /* reference counter for this object */
Noomen Hamza's avatar
Noomen Hamza committed
74 75 76 77 78 79 80 81 82

    IMoniker** tabMoniker; /* dynamic table containing the enumerated monikers */

    ULONG      tabSize; /* size of tabMoniker */

    ULONG      currentPos;  /* index pointer on the current moniker */

} EnumMonikerImpl;

83 84 85 86
static inline IMoniker *impl_from_IROTData( IROTData *iface )
{
    return (IMoniker *)((char*)iface - FIELD_OFFSET(CompositeMonikerImpl, lpvtbl2));
}
Noomen Hamza's avatar
Noomen Hamza committed
87

88
static HRESULT EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker,ULONG tabSize,ULONG currentPos,BOOL leftToRigth,IEnumMoniker ** ppmk);
Noomen Hamza's avatar
Noomen Hamza committed
89 90 91 92

/*******************************************************************************
 *        CompositeMoniker_QueryInterface
 *******************************************************************************/
93 94
static HRESULT WINAPI
CompositeMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
Noomen Hamza's avatar
Noomen Hamza committed
95
{
96
    CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
97

98
    TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
99 100 101 102

    /* Perform a sanity check on the parameters.*/
    if ( (This==0) || (ppvObject==0) )
	return E_INVALIDARG;
103

Noomen Hamza's avatar
Noomen Hamza committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    /* Initialize the return parameter */
    *ppvObject = 0;

    /* Compare the riid with the interface IDs implemented by this object.*/
    if (IsEqualIID(&IID_IUnknown, riid) ||
        IsEqualIID(&IID_IPersist, riid) ||
        IsEqualIID(&IID_IPersistStream, riid) ||
        IsEqualIID(&IID_IMoniker, riid)
       )
        *ppvObject = iface;
    else if (IsEqualIID(&IID_IROTData, riid))
        *ppvObject = (IROTData*)&(This->lpvtbl2);

    /* Check that we obtained an interface.*/
    if ((*ppvObject)==0)
        return E_NOINTERFACE;

    /* Query Interface always increases the reference count by one when it is successful */
122
    IMoniker_AddRef(iface);
Noomen Hamza's avatar
Noomen Hamza committed
123 124 125 126 127 128 129

    return S_OK;
}

/******************************************************************************
 *        CompositeMoniker_AddRef
 ******************************************************************************/
130 131
static ULONG WINAPI
CompositeMonikerImpl_AddRef(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
132
{
133
    CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
134

135
    TRACE("(%p)\n",This);
Noomen Hamza's avatar
Noomen Hamza committed
136

137
    return InterlockedIncrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
138 139 140 141 142
}

/******************************************************************************
 *        CompositeMoniker_Release
 ******************************************************************************/
143 144
static ULONG WINAPI
CompositeMonikerImpl_Release(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
145
{
146
    CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
147
    ULONG i;
148
    ULONG ref;
149

150
    TRACE("(%p)\n",This);
Noomen Hamza's avatar
Noomen Hamza committed
151

152
    ref = InterlockedDecrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
153 154

    /* destroy the object if there's no more reference on it */
155
    if (ref == 0){
Noomen Hamza's avatar
Noomen Hamza committed
156 157 158 159

        /* release all the components before destroying this object */
        for (i=0;i<This->tabLastIndex;i++)
            IMoniker_Release(This->tabMoniker[i]);
160

161 162
        HeapFree(GetProcessHeap(),0,This->tabMoniker);
        HeapFree(GetProcessHeap(),0,This);
Noomen Hamza's avatar
Noomen Hamza committed
163
    }
164
    return ref;
Noomen Hamza's avatar
Noomen Hamza committed
165 166 167 168 169
}

/******************************************************************************
 *        CompositeMoniker_GetClassID
 ******************************************************************************/
170 171
static HRESULT WINAPI
CompositeMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
Noomen Hamza's avatar
Noomen Hamza committed
172
{
173
    TRACE("(%p,%p),stub!\n",iface,pClassID);
Noomen Hamza's avatar
Noomen Hamza committed
174 175 176

    if (pClassID==NULL)
        return E_POINTER;
177

Noomen Hamza's avatar
Noomen Hamza committed
178
    *pClassID = CLSID_CompositeMoniker;
179

Noomen Hamza's avatar
Noomen Hamza committed
180 181 182 183 184 185
    return S_OK;
}

/******************************************************************************
 *        CompositeMoniker_IsDirty
 ******************************************************************************/
186 187
static HRESULT WINAPI
CompositeMonikerImpl_IsDirty(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
188 189 190 191 192
{
    /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
       method in the OLE-provided moniker interfaces always return S_FALSE because
       their internal state never changes. */

193
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
194 195 196 197 198 199 200

    return S_FALSE;
}

/******************************************************************************
 *        CompositeMoniker_Load
 ******************************************************************************/
201 202
static HRESULT WINAPI
CompositeMonikerImpl_Load(IMoniker* iface,IStream* pStm)
Noomen Hamza's avatar
Noomen Hamza committed
203 204 205 206 207
{
    HRESULT res;
    DWORD constant;
    CLSID clsid;
    WCHAR string[1]={0};
208

209
    CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
210

211
    TRACE("(%p,%p)\n",iface,pStm);
Noomen Hamza's avatar
Noomen Hamza committed
212 213 214

    /* this function call OleLoadFromStream function for each moniker within this object */

Francois Gouget's avatar
Francois Gouget committed
215
    /* read the a constant written by CompositeMonikerImpl_Save (see CompositeMonikerImpl_Save for more details)*/
Noomen Hamza's avatar
Noomen Hamza committed
216 217 218 219 220 221
    res=IStream_Read(pStm,&constant,sizeof(DWORD),NULL);

    if (SUCCEEDED(res)&& constant!=3)
        return E_FAIL;

    while(1){
222 223 224
#if 0
        res=OleLoadFromStream(pStm,&IID_IMoniker,(void**)&This->tabMoniker[This->tabLastIndex]);
#endif
Noomen Hamza's avatar
Noomen Hamza committed
225
        res=ReadClassStm(pStm,&clsid);
226
        DPRINTF("res=%ld",res);
Noomen Hamza's avatar
Noomen Hamza committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
        if (FAILED(res))
            break;

        if (IsEqualIID(&clsid,&CLSID_FileMoniker)){
            res=CreateFileMoniker(string,&This->tabMoniker[This->tabLastIndex]);
            if (FAILED(res))
                break;
            res=IMoniker_Load(This->tabMoniker[This->tabLastIndex],pStm);
            if (FAILED(res))
                break;
        }
        else if (IsEqualIID(&clsid,&CLSID_ItemMoniker)){
            CreateItemMoniker(string,string,&This->tabMoniker[This->tabLastIndex]);
            if (res!=S_OK)
                break;
            IMoniker_Load(This->tabMoniker[This->tabLastIndex],pStm);
            if (FAILED(res))
                break;
        }
        else if (IsEqualIID(&clsid,&CLSID_AntiMoniker)){
            CreateAntiMoniker(&This->tabMoniker[This->tabLastIndex]);
            if (FAILED(res))
                break;
            IMoniker_Load(This->tabMoniker[This->tabLastIndex],pStm);
            if (FAILED(res))
                break;
        }
        else if (IsEqualIID(&clsid,&CLSID_CompositeMoniker))
            return E_FAIL;

257 258 259 260
        else
        {
            FIXME("()\n");
            /* FIXME: To whoever wrote this code: It's either return or break. it cannot be both! */
Noomen Hamza's avatar
Noomen Hamza committed
261 262 263 264 265 266
            break;
            return E_NOTIMPL;
        }

        /* resize the table if needed */
        if (++This->tabLastIndex==This->tabSize){
267

Noomen Hamza's avatar
Noomen Hamza committed
268
            This->tabSize+=BLOCK_TAB_SIZE;
269
            This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));
Noomen Hamza's avatar
Noomen Hamza committed
270 271 272 273 274 275 276 277 278 279 280 281

            if (This->tabMoniker==NULL)
            return E_OUTOFMEMORY;
        }
    }

    return res;
}

/******************************************************************************
 *        CompositeMoniker_Save
 ******************************************************************************/
282 283
static HRESULT WINAPI
CompositeMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
Noomen Hamza's avatar
Noomen Hamza committed
284 285 286 287 288
{
    HRESULT res;
    IEnumMoniker *enumMk;
    IMoniker *pmk;
    DWORD constant=3;
289

290
    TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
Noomen Hamza's avatar
Noomen Hamza committed
291

292
    /* This function calls OleSaveToStream function for each moniker within
293
     * this object.
294 295
     * When I tested this function in windows, I usually found this constant
     * at the beginning of the stream. I don't known why (there's no
296 297
     * indication in the specification) !
     */
Noomen Hamza's avatar
Noomen Hamza committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
    res=IStream_Write(pStm,&constant,sizeof(constant),NULL);

    IMoniker_Enum(iface,TRUE,&enumMk);

    while(IEnumMoniker_Next(enumMk,1,&pmk,NULL)==S_OK){

        res=OleSaveToStream((IPersistStream*)pmk,pStm);

        IMoniker_Release(pmk);

        if (FAILED(res)){

            IEnumMoniker_Release(pmk);
            return res;
        }
    }

    IEnumMoniker_Release(enumMk);

    return S_OK;
}

/******************************************************************************
 *        CompositeMoniker_GetSizeMax
 ******************************************************************************/
323 324
static HRESULT WINAPI
CompositeMonikerImpl_GetSizeMax(IMoniker* iface,ULARGE_INTEGER* pcbSize)
Noomen Hamza's avatar
Noomen Hamza committed
325 326 327 328 329
{
    IEnumMoniker *enumMk;
    IMoniker *pmk;
    ULARGE_INTEGER ptmpSize;

330
    /* The sizeMax of this object is calculated by calling  GetSizeMax on
331 332
     * each moniker within this object then summing all returned values
     */
Noomen Hamza's avatar
Noomen Hamza committed
333

334
    TRACE("(%p,%p)\n",iface,pcbSize);
Noomen Hamza's avatar
Noomen Hamza committed
335 336 337 338

    if (pcbSize!=NULL)
        return E_POINTER;

339 340
    pcbSize->u.LowPart =0;
    pcbSize->u.HighPart=0;
Noomen Hamza's avatar
Noomen Hamza committed
341 342 343

    IMoniker_Enum(iface,TRUE,&enumMk);

344
    while(IEnumMoniker_Next(enumMk,1,&pmk,NULL)){
Noomen Hamza's avatar
Noomen Hamza committed
345 346 347 348 349

        IMoniker_GetSizeMax(pmk,&ptmpSize);

        IMoniker_Release(pmk);

350 351
        pcbSize->u.LowPart +=ptmpSize.u.LowPart;
        pcbSize->u.HighPart+=ptmpSize.u.HighPart;
Noomen Hamza's avatar
Noomen Hamza committed
352 353 354 355 356 357 358 359 360 361
    }

    IEnumMoniker_Release(enumMk);

    return S_OK;
}

/******************************************************************************
 *                  CompositeMoniker_BindToObject
 ******************************************************************************/
362 363 364
static HRESULT WINAPI
CompositeMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc,
               IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult)
Noomen Hamza's avatar
Noomen Hamza committed
365 366 367 368 369
{
    HRESULT   res;
    IRunningObjectTable *prot;
    IMoniker *tempMk,*antiMk,*mostRigthMk;
    IEnumMoniker *enumMoniker;
370

371
    TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
Noomen Hamza's avatar
Noomen Hamza committed
372 373 374

    if (ppvResult==NULL)
        return E_POINTER;
375

Noomen Hamza's avatar
Noomen Hamza committed
376 377 378 379 380 381 382 383 384
    *ppvResult=0;
    /* If pmkToLeft is NULL, this method looks for the moniker in the ROT, and if found, queries the retrieved */
    /* object for the requested interface pointer. */
    if(pmkToLeft==NULL){

        res=IBindCtx_GetRunningObjectTable(pbc,&prot);

        if (SUCCEEDED(res)){

385
            /* if the requested class was loaded before ! we don't need to reload it */
Noomen Hamza's avatar
Noomen Hamza committed
386 387 388 389 390 391 392 393 394 395 396 397 398
            res = IRunningObjectTable_GetObject(prot,iface,(IUnknown**)ppvResult);

            if (res==S_OK)
                return res;
        }
    }
    else{
        /* If pmkToLeft is not NULL, the method recursively calls IMoniker::BindToObject on the rightmost */
        /* component of the composite, passing the rest of the composite as the pmkToLeft parameter for that call */

        IMoniker_Enum(iface,FALSE,&enumMoniker);
        IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
        IEnumMoniker_Release(enumMoniker);
399

Noomen Hamza's avatar
Noomen Hamza committed
400 401 402
        res=CreateAntiMoniker(&antiMk);
        res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
        IMoniker_Release(antiMk);
403

Noomen Hamza's avatar
Noomen Hamza committed
404 405 406 407 408 409 410 411 412 413 414 415
        res=CompositeMonikerImpl_BindToObject(mostRigthMk,pbc,tempMk,riid,ppvResult);

        IMoniker_Release(tempMk);
        IMoniker_Release(mostRigthMk);
    }

    return res;
}

/******************************************************************************
 *        CompositeMoniker_BindToStorage
 ******************************************************************************/
416 417 418
static HRESULT WINAPI
CompositeMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc,
               IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult)
Noomen Hamza's avatar
Noomen Hamza committed
419 420 421 422 423
{
    HRESULT   res;
    IMoniker *tempMk,*antiMk,*mostRigthMk;
    IEnumMoniker *enumMoniker;

424
    TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
Noomen Hamza's avatar
Noomen Hamza committed
425 426 427 428 429 430 431

    *ppvResult=0;

    /* This method recursively calls BindToStorage on the rightmost component of the composite, */
    /* passing the rest of the composite as the pmkToLeft parameter for that call. */

    if (pmkToLeft!=NULL){
432

Noomen Hamza's avatar
Noomen Hamza committed
433 434 435
        IMoniker_Enum(iface,FALSE,&enumMoniker);
        IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
        IEnumMoniker_Release(enumMoniker);
436

Noomen Hamza's avatar
Noomen Hamza committed
437 438 439
        res=CreateAntiMoniker(&antiMk);
        res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
        IMoniker_Release(antiMk);
440

Noomen Hamza's avatar
Noomen Hamza committed
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
        res=CompositeMonikerImpl_BindToStorage(mostRigthMk,pbc,tempMk,riid,ppvResult);

        IMoniker_Release(tempMk);

        IMoniker_Release(mostRigthMk);

        return res;
    }
    else
        return IMoniker_BindToStorage(iface,pbc,NULL,riid,ppvResult);
}

/******************************************************************************
 *        CompositeMoniker_Reduce
 ******************************************************************************/
456 457 458
static HRESULT WINAPI
CompositeMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
               IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
Noomen Hamza's avatar
Noomen Hamza committed
459 460 461 462 463
{
    HRESULT   res;
    IMoniker *tempMk,*antiMk,*mostRigthMk,*leftReducedComposedMk,*mostRigthReducedMk;
    IEnumMoniker *enumMoniker;

464
    TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
Noomen Hamza's avatar
Noomen Hamza committed
465 466 467 468 469 470 471 472 473 474 475

    if (ppmkReduced==NULL)
        return E_POINTER;

    /* This method recursively calls Reduce for each of its component monikers. */

    if (ppmkToLeft==NULL){

        IMoniker_Enum(iface,FALSE,&enumMoniker);
        IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
        IEnumMoniker_Release(enumMoniker);
476

Noomen Hamza's avatar
Noomen Hamza committed
477 478 479 480 481 482 483 484 485 486 487 488
        res=CreateAntiMoniker(&antiMk);
        res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
        IMoniker_Release(antiMk);

        return CompositeMonikerImpl_Reduce(mostRigthMk,pbc,dwReduceHowFar,&tempMk, ppmkReduced);
    }
    else if (*ppmkToLeft==NULL)

        return IMoniker_Reduce(iface,pbc,dwReduceHowFar,NULL,ppmkReduced);

    else{

Andreas Mohr's avatar
Andreas Mohr committed
489
        /* separate the composite moniker in to left and right moniker */
Noomen Hamza's avatar
Noomen Hamza committed
490 491 492
        IMoniker_Enum(iface,FALSE,&enumMoniker);
        IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
        IEnumMoniker_Release(enumMoniker);
493

Noomen Hamza's avatar
Noomen Hamza committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
        res=CreateAntiMoniker(&antiMk);
        res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
        IMoniker_Release(antiMk);

        /* If any of the components  reduces itself, the method returns S_OK and passes back a composite */
        /* of the reduced components */
        if (IMoniker_Reduce(mostRigthMk,pbc,dwReduceHowFar,NULL,&mostRigthReducedMk) &&
            CompositeMonikerImpl_Reduce(mostRigthMk,pbc,dwReduceHowFar,&tempMk,&leftReducedComposedMk)
           )

            return CreateGenericComposite(leftReducedComposedMk,mostRigthReducedMk,ppmkReduced);

        else{
            /* If no reduction occurred, the method passes back the same moniker and returns MK_S_REDUCED_TO_SELF.*/

            IMoniker_AddRef(iface);

            *ppmkReduced=iface;

            return MK_S_REDUCED_TO_SELF;
        }
    }
}

/******************************************************************************
 *        CompositeMoniker_ComposeWith
 ******************************************************************************/
521 522 523
static HRESULT WINAPI
CompositeMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
               BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite)
Noomen Hamza's avatar
Noomen Hamza committed
524
{
525
    TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
Noomen Hamza's avatar
Noomen Hamza committed
526 527 528 529 530 531 532 533 534

    if ((ppmkComposite==NULL)||(pmkRight==NULL))
	return E_POINTER;

    *ppmkComposite=0;

    /* If fOnlyIfNotGeneric is TRUE, this method sets *pmkComposite to NULL and returns MK_E_NEEDGENERIC; */
    /* otherwise, the method returns the result of combining the two monikers by calling the */
    /* CreateGenericComposite function */
535

Noomen Hamza's avatar
Noomen Hamza committed
536 537
    if (fOnlyIfNotGeneric)
        return MK_E_NEEDGENERIC;
538

Noomen Hamza's avatar
Noomen Hamza committed
539 540 541 542 543 544
    return CreateGenericComposite(iface,pmkRight,ppmkComposite);
}

/******************************************************************************
 *        CompositeMoniker_Enum
 ******************************************************************************/
545 546
static HRESULT WINAPI
CompositeMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
Noomen Hamza's avatar
Noomen Hamza committed
547
{
548
    CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
549

550
    TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
551 552 553

    if (ppenumMoniker == NULL)
        return E_POINTER;
554

Noomen Hamza's avatar
Noomen Hamza committed
555 556 557 558 559 560
    return EnumMonikerImpl_CreateEnumMoniker(This->tabMoniker,This->tabLastIndex,0,fForward,ppenumMoniker);
}

/******************************************************************************
 *        CompositeMoniker_IsEqual
 ******************************************************************************/
561 562
static HRESULT WINAPI
CompositeMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
Noomen Hamza's avatar
Noomen Hamza committed
563 564 565 566
{
    IEnumMoniker *enumMoniker1,*enumMoniker2;
    IMoniker *tempMk1,*tempMk2;
    HRESULT res1,res2,res;
567

568
    TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
569 570 571 572 573 574 575 576 577 578

    if (pmkOtherMoniker==NULL)
        return S_FALSE;

    /* This method returns S_OK if the components of both monikers are equal when compared in the */
    /* left-to-right order.*/
    IMoniker_Enum(pmkOtherMoniker,TRUE,&enumMoniker1);

    if (enumMoniker1==NULL)
        return S_FALSE;
579

Noomen Hamza's avatar
Noomen Hamza committed
580 581 582 583 584 585
    IMoniker_Enum(iface,TRUE,&enumMoniker2);

    while(1){

        res1=IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
        res2=IEnumMoniker_Next(enumMoniker2,1,&tempMk2,NULL);
586

Noomen Hamza's avatar
Noomen Hamza committed
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
        if((res1==S_OK)&&(res2==S_OK)){

            if(IMoniker_IsEqual(tempMk1,tempMk2)==S_FALSE){
                res= S_FALSE;
                break;
            }
            else
                continue;
        }
        else if ( (res1==S_FALSE) && (res2==S_FALSE) ){
                res = S_OK;
                break;
        }
        else{
            res = S_FALSE;
            break;
        }

        if (res1==S_OK)
            IMoniker_Release(tempMk1);

        if (res2==S_OK)
            IMoniker_Release(tempMk2);
    }

    IEnumMoniker_Release(enumMoniker1);
    IEnumMoniker_Release(enumMoniker2);

    return res;
}
/******************************************************************************
 *        CompositeMoniker_Hash
 ******************************************************************************/
620 621
static HRESULT WINAPI
CompositeMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
Noomen Hamza's avatar
Noomen Hamza committed
622
{
623 624 625 626 627 628 629 630 631 632 633 634 635
    IEnumMoniker *enumMoniker;
    IMoniker *tempMk;
    HRESULT res;
    DWORD tempHash;

    TRACE("(%p,%p)\n",iface,pdwHash);

    if (pdwHash==NULL)
        return E_POINTER;

    res = IMoniker_Enum(iface,TRUE,&enumMoniker);
    if(FAILED(res))
        return res;
Noomen Hamza's avatar
Noomen Hamza committed
636

637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
    while(1){
        res=IEnumMoniker_Next(enumMoniker,1,&tempMk,NULL);
        if(FAILED(res))
            break;
            
        res = IMoniker_Hash(tempMk, &tempHash);
        if(FAILED(res))
            break;
        *pdwHash = (*pdwHash * 37) + tempHash;
        
        IMoniker_Release(tempMk);
    }

    IEnumMoniker_Release(enumMoniker);

    return res;
Noomen Hamza's avatar
Noomen Hamza committed
653 654 655 656 657
}

/******************************************************************************
 *        CompositeMoniker_IsRunning
 ******************************************************************************/
658 659 660
static HRESULT WINAPI
CompositeMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc,
               IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning)
Noomen Hamza's avatar
Noomen Hamza committed
661 662 663 664 665 666
{
    IRunningObjectTable* rot;
    HRESULT res;
    IMoniker *tempMk,*antiMk,*mostRigthMk;
    IEnumMoniker *enumMoniker;

667
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
Noomen Hamza's avatar
Noomen Hamza committed
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682

    /* If pmkToLeft is non-NULL, this method composes pmkToLeft with this moniker and calls IsRunning on the result.*/
    if (pmkToLeft!=NULL){

        CreateGenericComposite(pmkToLeft,iface,&tempMk);

        res = IMoniker_IsRunning(tempMk,pbc,NULL,pmkNewlyRunning);

        IMoniker_Release(tempMk);

        return res;
    }
    else
        /* If pmkToLeft is NULL, this method returns S_OK if pmkNewlyRunning is non-NULL and is equal */
        /* to this moniker */
683

Noomen Hamza's avatar
Noomen Hamza committed
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
        if (pmkNewlyRunning!=NULL)

            if (IMoniker_IsEqual(iface,pmkNewlyRunning)==S_OK)
                return S_OK;

            else
                return S_FALSE;

        else{

            if (pbc==NULL)
                return E_POINTER;

            /* If pmkToLeft and pmkNewlyRunning are both NULL, this method checks the ROT to see whether */
            /* the moniker is running. If so, the method returns S_OK; otherwise, it recursively calls   */
            /* IMoniker::IsRunning on the rightmost component of the composite, passing the remainder of */
            /* the composite as the pmkToLeft parameter for that call.                                   */
701

Noomen Hamza's avatar
Noomen Hamza committed
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
             res=IBindCtx_GetRunningObjectTable(pbc,&rot);

            if (FAILED(res))
                return res;

            res = IRunningObjectTable_IsRunning(rot,iface);
            IRunningObjectTable_Release(rot);

            if(res==S_OK)
                return S_OK;

            else{

                IMoniker_Enum(iface,FALSE,&enumMoniker);
                IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
                IEnumMoniker_Release(enumMoniker);

                res=CreateAntiMoniker(&antiMk);
                res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
                IMoniker_Release(antiMk);

                res=IMoniker_IsRunning(mostRigthMk,pbc,tempMk,pmkNewlyRunning);

                IMoniker_Release(tempMk);
                IMoniker_Release(mostRigthMk);

                return res;
            }
        }
}

/******************************************************************************
 *        CompositeMoniker_GetTimeOfLastChange
 ******************************************************************************/
736 737 738
static HRESULT WINAPI
CompositeMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc,
               IMoniker* pmkToLeft, FILETIME* pCompositeTime)
Noomen Hamza's avatar
Noomen Hamza committed
739 740 741 742 743
{
    IRunningObjectTable* rot;
    HRESULT res;
    IMoniker *tempMk,*antiMk,*mostRigthMk;
    IEnumMoniker *enumMoniker;
744

745
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pCompositeTime);
Noomen Hamza's avatar
Noomen Hamza committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788

    if (pCompositeTime==NULL)
        return E_INVALIDARG;

    /* This method creates a composite of pmkToLeft (if non-NULL) and this moniker and uses the ROT to  */
    /* retrieve the time of last change. If the object is not in the ROT, the method recursively calls  */
    /* IMoniker::GetTimeOfLastChange on the rightmost component of the composite, passing the remainder */
    /* of the composite as the pmkToLeft parameter for that call.                                       */
    if (pmkToLeft!=NULL){

        res=CreateGenericComposite(pmkToLeft,iface,&tempMk);

        res=IBindCtx_GetRunningObjectTable(pbc,&rot);

        if (FAILED(res))
            return res;

        if (IRunningObjectTable_GetTimeOfLastChange(rot,tempMk,pCompositeTime)==S_OK)
            return res;
        else

            IMoniker_Enum(iface,FALSE,&enumMoniker);
            IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
            IEnumMoniker_Release(enumMoniker);

            res=CreateAntiMoniker(&antiMk);
            res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
            IMoniker_Release(antiMk);

            res=CompositeMonikerImpl_GetTimeOfLastChange(mostRigthMk,pbc,tempMk,pCompositeTime);

            IMoniker_Release(tempMk);
            IMoniker_Release(mostRigthMk);

            return res;
    }
    else
        return IMoniker_GetTimeOfLastChange(iface,pbc,NULL,pCompositeTime);
}

/******************************************************************************
 *        CompositeMoniker_Inverse
 ******************************************************************************/
789 790
static HRESULT WINAPI
CompositeMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
Noomen Hamza's avatar
Noomen Hamza committed
791 792 793 794 795
{
    HRESULT res;
    IMoniker *tempMk,*antiMk,*mostRigthMk,*tempInvMk,*mostRigthInvMk;
    IEnumMoniker *enumMoniker;

796
    TRACE("(%p,%p)\n",iface,ppmk);
Noomen Hamza's avatar
Noomen Hamza committed
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834

    if (ppmk==NULL)
        return E_POINTER;

    /* This method returns a composite moniker that consists of the inverses of each of the components */
    /* of the original composite, stored in reverse order */

    res=CreateAntiMoniker(&antiMk);
    res=IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
    IMoniker_Release(antiMk);

    if (tempMk==NULL)

        return IMoniker_Inverse(iface,ppmk);

    else{

        IMoniker_Enum(iface,FALSE,&enumMoniker);
        IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
        IEnumMoniker_Release(enumMoniker);

        IMoniker_Inverse(mostRigthMk,&mostRigthInvMk);
        CompositeMonikerImpl_Inverse(tempMk,&tempInvMk);

        res=CreateGenericComposite(mostRigthInvMk,tempInvMk,ppmk);

        IMoniker_Release(tempMk);
        IMoniker_Release(mostRigthMk);
        IMoniker_Release(tempInvMk);
        IMoniker_Release(mostRigthInvMk);

        return res;
    }
}

/******************************************************************************
 *        CompositeMoniker_CommonPrefixWith
 ******************************************************************************/
835 836 837
static HRESULT WINAPI
CompositeMonikerImpl_CommonPrefixWith(IMoniker* iface, IMoniker* pmkOther,
               IMoniker** ppmkPrefix)
Noomen Hamza's avatar
Noomen Hamza committed
838 839 840 841 842 843
{
    DWORD mkSys;
    HRESULT res1,res2;
    IMoniker *tempMk1,*tempMk2,*mostLeftMk1,*mostLeftMk2;
    IEnumMoniker *enumMoniker1,*enumMoniker2;
    ULONG i,nbCommonMk=0;
844

Noomen Hamza's avatar
Noomen Hamza committed
845 846 847 848 849 850
    /* If the other moniker is a composite, this method compares the components of each composite from left  */
    /* to right. The returned common prefix moniker might also be a composite moniker, depending on how many */
    /* of the leftmost components were common to both monikers.                                              */

    if (ppmkPrefix==NULL)
        return E_POINTER;
851

Noomen Hamza's avatar
Noomen Hamza committed
852 853 854 855
    *ppmkPrefix=0;

    if (pmkOther==NULL)
        return MK_E_NOPREFIX;
856

Noomen Hamza's avatar
Noomen Hamza committed
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
    IMoniker_IsSystemMoniker(pmkOther,&mkSys);

    if((mkSys==MKSYS_GENERICCOMPOSITE)){

        IMoniker_Enum(iface,TRUE,&enumMoniker1);
        IMoniker_Enum(pmkOther,TRUE,&enumMoniker2);

        while(1){

            res1=IEnumMoniker_Next(enumMoniker1,1,&mostLeftMk1,NULL);
            res2=IEnumMoniker_Next(enumMoniker2,1,&mostLeftMk2,NULL);

            if ((res1==S_FALSE) && (res2==S_FALSE)){

                /* If the monikers are equal, the method returns MK_S_US and sets ppmkPrefix to this moniker.*/
                *ppmkPrefix=iface;
                IMoniker_AddRef(iface);
                return  MK_S_US;
            }
            else if ((res1==S_OK) && (res2==S_OK)){

                if (IMoniker_IsEqual(mostLeftMk1,mostLeftMk2)==S_OK)

                    nbCommonMk++;

                else
                    break;

            }
            else if (res1==S_OK){

                /* If the other moniker is a prefix of this moniker, the method returns MK_S_HIM and sets */
                /* ppmkPrefix to the other moniker.                                                       */
                *ppmkPrefix=pmkOther;
                return MK_S_HIM;
            }
            else{
                /* If this moniker is a prefix of the other, this method returns MK_S_ME and sets ppmkPrefix */
                /* to this moniker.                                                                          */
                *ppmkPrefix=iface;
                return MK_S_ME;
            }
        }

        IEnumMoniker_Release(enumMoniker1);
        IEnumMoniker_Release(enumMoniker2);

        /* If there is no common prefix, this method returns MK_E_NOPREFIX and sets ppmkPrefix to NULL. */
        if (nbCommonMk==0)
            return MK_E_NOPREFIX;

        IEnumMoniker_Reset(enumMoniker1);

        IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);

        /* if we have more than one commun moniker the result will be a composite moniker */
        if (nbCommonMk>1){

            /* initialize the common prefix moniker with the composite of two first moniker (from the left)*/
            IEnumMoniker_Next(enumMoniker1,1,&tempMk2,NULL);
            CreateGenericComposite(tempMk1,tempMk2,ppmkPrefix);
            IMoniker_Release(tempMk1);
            IMoniker_Release(tempMk2);
920

Noomen Hamza's avatar
Noomen Hamza committed
921 922 923 924 925 926 927 928 929 930
            /* compose all common monikers in a composite moniker */
            for(i=0;i<nbCommonMk;i++){

                IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);

                CreateGenericComposite(*ppmkPrefix,tempMk1,&tempMk2);

                IMoniker_Release(*ppmkPrefix);

                IMoniker_Release(tempMk1);
931

Noomen Hamza's avatar
Noomen Hamza committed
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
                *ppmkPrefix=tempMk2;
            }
            return S_OK;
        }
        else{
            /* if we have only one commun moniker the result will be a simple moniker which is the most-left one*/
            *ppmkPrefix=tempMk1;

            return S_OK;
        }
    }
    else{
        /* If the other moniker is not a composite, the method simply compares it to the leftmost component
         of this moniker.*/

        IMoniker_Enum(iface,TRUE,&enumMoniker1);

        IEnumMoniker_Next(enumMoniker1,1,&mostLeftMk1,NULL);

        if (IMoniker_IsEqual(pmkOther,mostLeftMk1)==S_OK){

            *ppmkPrefix=pmkOther;

            return MK_S_HIM;
        }
        else
            return MK_E_NOPREFIX;
    }
}
961

Noomen Hamza's avatar
Noomen Hamza committed
962 963 964 965
/***************************************************************************************************
 *        GetAfterCommonPrefix (local function)
 *  This function returns a moniker that consist of the remainder when the common prefix is removed
 ***************************************************************************************************/
966
static VOID GetAfterCommonPrefix(IMoniker* pGenMk,IMoniker* commonMk,IMoniker** restMk)
Noomen Hamza's avatar
Noomen Hamza committed
967 968 969 970 971 972
{
    IMoniker *tempMk,*tempMk1,*tempMk2;
    IEnumMoniker *enumMoniker1,*enumMoniker2,*enumMoniker3;
    ULONG nbRestMk=0;
    DWORD mkSys;
    HRESULT res1,res2;
973

Noomen Hamza's avatar
Noomen Hamza committed
974 975 976
    *restMk=0;

    /* to create an enumerator for pGenMk with current position pointed on the first element after common  */
Andreas Mohr's avatar
Andreas Mohr committed
977
    /* prefix: enum the two monikers (left-right) then compare these enumerations (left-right) and stop  */
Noomen Hamza's avatar
Noomen Hamza committed
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
    /* on the first difference. */
    IMoniker_Enum(pGenMk,TRUE,&enumMoniker1);

    IMoniker_IsSystemMoniker(commonMk,&mkSys);

    if (mkSys==MKSYS_GENERICCOMPOSITE){

        IMoniker_Enum(commonMk,TRUE,&enumMoniker2);
        while(1){

            res1=IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
            res2=IEnumMoniker_Next(enumMoniker2,1,&tempMk2,NULL);

            if ((res1==S_FALSE)||(res2==S_FALSE)){

                if (res1==S_OK)

                    nbRestMk++;

                IMoniker_Release(tempMk1);
                IMoniker_Release(tempMk1);

                break;
            }
            IMoniker_Release(tempMk1);
            IMoniker_Release(tempMk1);
        }
    }
    else{
        IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);
        IMoniker_Release(tempMk1);
    }

    /* count the number of elements in the enumerator after the common prefix */
    IEnumMoniker_Clone(enumMoniker1,&enumMoniker3);

    for(;IEnumMoniker_Next(enumMoniker3,1,&tempMk,NULL)==S_OK;nbRestMk++)

1016
        IMoniker_Release(tempMk);
Noomen Hamza's avatar
Noomen Hamza committed
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

    if (nbRestMk==0)
        return;

    /* create a generic composite moniker with monikers located after the common prefix */
    IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL);

    if (nbRestMk==1){

        *restMk= tempMk1;
        return;
    }
    else {

        IEnumMoniker_Next(enumMoniker1,1,&tempMk2,NULL);

        CreateGenericComposite(tempMk1,tempMk2,restMk);

        IMoniker_Release(tempMk1);

        IMoniker_Release(tempMk2);

        while(IEnumMoniker_Next(enumMoniker1,1,&tempMk1,NULL)==S_OK){

            CreateGenericComposite(*restMk,tempMk1,&tempMk2);

            IMoniker_Release(tempMk1);

            IMoniker_Release(*restMk);

            *restMk=tempMk2;
        }
    }
}
1051

Noomen Hamza's avatar
Noomen Hamza committed
1052 1053 1054
/******************************************************************************
 *        CompositeMoniker_RelativePathTo
 ******************************************************************************/
1055 1056 1057
static HRESULT WINAPI
CompositeMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmkOther,
               IMoniker** ppmkRelPath)
Noomen Hamza's avatar
Noomen Hamza committed
1058 1059 1060 1061
{
    HRESULT res;
    IMoniker *restOtherMk=0,*restThisMk=0,*invRestThisMk=0,*commonMk=0;

1062
    TRACE("(%p,%p,%p)\n",iface,pmkOther,ppmkRelPath);
Noomen Hamza's avatar
Noomen Hamza committed
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073

    if (ppmkRelPath==NULL)
        return E_POINTER;

    *ppmkRelPath=0;

    /* This method finds the common prefix of the two monikers and creates two monikers that consist     */
    /* of the remainder when the common prefix is removed. Then it creates the inverse for the remainder */
    /* of this moniker and composes the remainder of the other moniker on the right of it.               */

    /* finds the common prefix of the two monikers */
1074
    res=IMoniker_CommonPrefixWith(iface,pmkOther,&commonMk);
Noomen Hamza's avatar
Noomen Hamza committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116

    /* if there's no common prefix or the two moniker are equal the relative is the other moniker */
    if ((res== MK_E_NOPREFIX)||(res==MK_S_US)){

        *ppmkRelPath=pmkOther;
        IMoniker_AddRef(pmkOther);
        return MK_S_HIM;
    }

    GetAfterCommonPrefix(iface,commonMk,&restThisMk);
    GetAfterCommonPrefix(pmkOther,commonMk,&restOtherMk);

    /* if other is a prefix of this moniker the relative path is the inverse of the remainder path of this */
    /* moniker when the common prefix is removed                                                           */
    if (res==MK_S_HIM){

        IMoniker_Inverse(restThisMk,ppmkRelPath);
        IMoniker_Release(restThisMk);
    }
    /* if this moniker is a prefix of other moniker the relative path is the remainder path of other moniker */
    /* when the common prefix is removed                                                                     */
    else if (res==MK_S_ME){

        *ppmkRelPath=restOtherMk;
        IMoniker_AddRef(restOtherMk);
    }
    /* the relative path is the inverse for the remainder of this moniker and the remainder of the other  */
    /* moniker on the right of it.                                                                        */
    else if (res==S_OK){

        IMoniker_Inverse(restThisMk,&invRestThisMk);
        IMoniker_Release(restThisMk);
        CreateGenericComposite(invRestThisMk,restOtherMk,ppmkRelPath);
        IMoniker_Release(invRestThisMk);
        IMoniker_Release(restOtherMk);
    }
    return S_OK;
}

/******************************************************************************
 *        CompositeMoniker_GetDisplayName
 ******************************************************************************/
1117 1118 1119
static HRESULT WINAPI
CompositeMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc,
               IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName)
Noomen Hamza's avatar
Noomen Hamza committed
1120 1121 1122 1123 1124 1125
{
    ULONG lengthStr=1;
    IEnumMoniker *enumMoniker;
    IMoniker* tempMk;
    LPOLESTR tempStr;

1126
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
Noomen Hamza's avatar
Noomen Hamza committed
1127 1128 1129

    if (ppszDisplayName==NULL)
        return E_POINTER;
1130

Noomen Hamza's avatar
Noomen Hamza committed
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
    *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR));

    if (*ppszDisplayName==NULL)
        return E_OUTOFMEMORY;

    /* This method returns the concatenation of the display names returned by each component moniker of */
    /* the composite */

    **ppszDisplayName=0;

    IMoniker_Enum(iface,TRUE,&enumMoniker);
1142

Noomen Hamza's avatar
Noomen Hamza committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
    while(IEnumMoniker_Next(enumMoniker,1,&tempMk,NULL)==S_OK){

        IMoniker_GetDisplayName(tempMk,pbc,NULL,&tempStr);

        lengthStr+=lstrlenW(tempStr);

        *ppszDisplayName=CoTaskMemRealloc(*ppszDisplayName,lengthStr * sizeof(WCHAR));

        if (*ppszDisplayName==NULL)
            return E_OUTOFMEMORY;

1154
        strcatW(*ppszDisplayName,tempStr);
Noomen Hamza's avatar
Noomen Hamza committed
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167

        CoTaskMemFree(tempStr);
        IMoniker_Release(tempMk);
    }

    IEnumMoniker_Release(enumMoniker);

    return S_OK;
}

/******************************************************************************
 *        CompositeMoniker_ParseDisplayName
 ******************************************************************************/
1168 1169 1170 1171
static HRESULT WINAPI
CompositeMonikerImpl_ParseDisplayName(IMoniker* iface, IBindCtx* pbc,
               IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten,
               IMoniker** ppmkOut)
Noomen Hamza's avatar
Noomen Hamza committed
1172 1173 1174 1175 1176 1177
{
    IEnumMoniker *enumMoniker;
    IMoniker *tempMk,*mostRigthMk,*antiMk;
    /* This method recursively calls IMoniker::ParseDisplayName on the rightmost component of the composite,*/
    /* passing everything else as the pmkToLeft parameter for that call. */

Andreas Mohr's avatar
Andreas Mohr committed
1178
    /* get the most right moniker */
Noomen Hamza's avatar
Noomen Hamza committed
1179 1180 1181 1182
    IMoniker_Enum(iface,FALSE,&enumMoniker);
    IEnumMoniker_Next(enumMoniker,1,&mostRigthMk,NULL);
    IEnumMoniker_Release(enumMoniker);

Andreas Mohr's avatar
Andreas Mohr committed
1183
    /* get the left moniker */
Noomen Hamza's avatar
Noomen Hamza committed
1184 1185 1186 1187 1188 1189 1190 1191
    CreateAntiMoniker(&antiMk);
    IMoniker_ComposeWith(iface,antiMk,0,&tempMk);
    IMoniker_Release(antiMk);

    return IMoniker_ParseDisplayName(mostRigthMk,pbc,tempMk,pszDisplayName,pchEaten,ppmkOut);
}

/******************************************************************************
Andreas Mohr's avatar
Andreas Mohr committed
1192
 *        CompositeMoniker_IsSystemMoniker
Noomen Hamza's avatar
Noomen Hamza committed
1193
 ******************************************************************************/
1194 1195
static HRESULT WINAPI
CompositeMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
Noomen Hamza's avatar
Noomen Hamza committed
1196
{
1197
    TRACE("(%p,%p)\n",iface,pwdMksys);
Noomen Hamza's avatar
Noomen Hamza committed
1198 1199 1200

    if (!pwdMksys)
        return E_POINTER;
1201

Noomen Hamza's avatar
Noomen Hamza committed
1202 1203 1204 1205 1206 1207 1208 1209
    (*pwdMksys)=MKSYS_GENERICCOMPOSITE;

    return S_OK;
}

/*******************************************************************************
 *        CompositeMonikerIROTData_QueryInterface
 *******************************************************************************/
1210 1211 1212
static HRESULT WINAPI
CompositeMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,
               VOID** ppvObject)
Noomen Hamza's avatar
Noomen Hamza committed
1213 1214
{

1215
    IMoniker *This = impl_from_IROTData(iface);
Noomen Hamza's avatar
Noomen Hamza committed
1216

1217
    TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
1218 1219 1220 1221 1222 1223 1224

    return CompositeMonikerImpl_QueryInterface(This, riid, ppvObject);
}

/***********************************************************************
 *        CompositeMonikerIROTData_AddRef
 */
1225 1226
static ULONG WINAPI
CompositeMonikerROTDataImpl_AddRef(IROTData *iface)
Noomen Hamza's avatar
Noomen Hamza committed
1227
{
1228
    IMoniker *This = impl_from_IROTData(iface);
Noomen Hamza's avatar
Noomen Hamza committed
1229

1230
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
1231

1232
    return IMoniker_AddRef(This);
Noomen Hamza's avatar
Noomen Hamza committed
1233 1234 1235 1236 1237
}

/***********************************************************************
 *        CompositeMonikerIROTData_Release
 */
1238
static ULONG WINAPI CompositeMonikerROTDataImpl_Release(IROTData* iface)
Noomen Hamza's avatar
Noomen Hamza committed
1239
{
1240
    IMoniker *This = impl_from_IROTData(iface);
1241

1242
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
1243

1244
    return IMoniker_Release(This);
Noomen Hamza's avatar
Noomen Hamza committed
1245 1246 1247 1248 1249
}

/******************************************************************************
 *        CompositeMonikerIROTData_GetComparaisonData
 ******************************************************************************/
1250 1251 1252
static HRESULT WINAPI
CompositeMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
               BYTE* pbData, ULONG cbMax, ULONG* pcbData)
Noomen Hamza's avatar
Noomen Hamza committed
1253
{
1254
    FIXME("(),stub!\n");
Noomen Hamza's avatar
Noomen Hamza committed
1255 1256 1257 1258 1259 1260
    return E_NOTIMPL;
}

/******************************************************************************
 *        EnumMonikerImpl_QueryInterface
 ******************************************************************************/
1261 1262
static HRESULT WINAPI
EnumMonikerImpl_QueryInterface(IEnumMoniker* iface,REFIID riid,void** ppvObject)
Noomen Hamza's avatar
Noomen Hamza committed
1263
{
1264
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1265

1266
    TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
1267 1268 1269 1270

    /* Perform a sanity check on the parameters.*/
    if ( (This==0) || (ppvObject==0) )
	return E_INVALIDARG;
1271

Noomen Hamza's avatar
Noomen Hamza committed
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
    /* Initialize the return parameter */
    *ppvObject = 0;

    /* Compare the riid with the interface IDs implemented by this object.*/
    if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumMoniker, riid))
        *ppvObject = iface;

    /* Check that we obtained an interface.*/
    if ((*ppvObject)==0)
        return E_NOINTERFACE;

    /* Query Interface always increases the reference count by one when it is successful */
1284
    IEnumMoniker_AddRef(iface);
Noomen Hamza's avatar
Noomen Hamza committed
1285 1286 1287 1288 1289 1290 1291

    return S_OK;
}

/******************************************************************************
 *        EnumMonikerImpl_AddRef
 ******************************************************************************/
1292 1293
static ULONG WINAPI
EnumMonikerImpl_AddRef(IEnumMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
1294
{
1295
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
1296

1297
    TRACE("(%p)\n",This);
Noomen Hamza's avatar
Noomen Hamza committed
1298

1299
    return InterlockedIncrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
1300 1301 1302 1303 1304 1305

}

/******************************************************************************
 *        EnumMonikerImpl_Release
 ******************************************************************************/
1306 1307
static ULONG WINAPI
EnumMonikerImpl_Release(IEnumMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
1308
{
1309
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
1310 1311
    ULONG i;
    ULONG ref;
1312
    TRACE("(%p)\n",This);
Noomen Hamza's avatar
Noomen Hamza committed
1313

1314
    ref = InterlockedDecrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
1315 1316

    /* destroy the object if there's no more reference on it */
1317
    if (ref == 0) {
1318

Noomen Hamza's avatar
Noomen Hamza committed
1319 1320 1321 1322 1323 1324
        for(i=0;i<This->tabSize;i++)
            IMoniker_Release(This->tabMoniker[i]);

        HeapFree(GetProcessHeap(),0,This->tabMoniker);
        HeapFree(GetProcessHeap(),0,This);
    }
1325
    return ref;
Noomen Hamza's avatar
Noomen Hamza committed
1326 1327 1328 1329 1330
}

/******************************************************************************
 *        EnumMonikerImpl_Next
 ******************************************************************************/
1331 1332 1333 1334
static HRESULT WINAPI
EnumMonikerImpl_Next(IEnumMoniker* iface,ULONG celt, IMoniker** rgelt,
               ULONG* pceltFethed)
{
1335
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
1336 1337 1338 1339 1340 1341 1342 1343 1344
    ULONG i;

    /* retrieve the requested number of moniker from the current position */
    for(i=0;((This->currentPos < This->tabSize) && (i < celt));i++)

        rgelt[i]=This->tabMoniker[This->currentPos++];

    if (pceltFethed!=NULL)
        *pceltFethed= i;
1345

Noomen Hamza's avatar
Noomen Hamza committed
1346 1347 1348 1349 1350 1351 1352 1353 1354
    if (i==celt)
        return S_OK;
    else
        return S_FALSE;
}

/******************************************************************************
 *        EnumMonikerImpl_Skip
 ******************************************************************************/
1355 1356 1357
static HRESULT WINAPI
EnumMonikerImpl_Skip(IEnumMoniker* iface,ULONG celt)
{
1358
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
1359 1360 1361 1362 1363

    if ((This->currentPos+celt) >= This->tabSize)
        return S_FALSE;

    This->currentPos+=celt;
1364

Noomen Hamza's avatar
Noomen Hamza committed
1365 1366 1367 1368 1369 1370
    return S_OK;
}

/******************************************************************************
 *        EnumMonikerImpl_Reset
 ******************************************************************************/
1371 1372 1373
static HRESULT WINAPI
EnumMonikerImpl_Reset(IEnumMoniker* iface)
{
Noomen Hamza's avatar
Noomen Hamza committed
1374

1375
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
1376 1377 1378 1379 1380 1381 1382 1383 1384

    This->currentPos=0;

    return S_OK;
}

/******************************************************************************
 *        EnumMonikerImpl_Clone
 ******************************************************************************/
1385 1386 1387
static HRESULT WINAPI
EnumMonikerImpl_Clone(IEnumMoniker* iface,IEnumMoniker** ppenum)
{
1388
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
1389 1390 1391 1392

    return EnumMonikerImpl_CreateEnumMoniker(This->tabMoniker,This->tabSize,This->currentPos,TRUE,ppenum);
}

1393 1394
/********************************************************************************/
/* Virtual function table for the IROTData class                                */
1395
static const IEnumMonikerVtbl VT_EnumMonikerImpl =
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
{
    EnumMonikerImpl_QueryInterface,
    EnumMonikerImpl_AddRef,
    EnumMonikerImpl_Release,
    EnumMonikerImpl_Next,
    EnumMonikerImpl_Skip,
    EnumMonikerImpl_Reset,
    EnumMonikerImpl_Clone
};

Noomen Hamza's avatar
Noomen Hamza committed
1406 1407 1408
/******************************************************************************
 *        EnumMonikerImpl_CreateEnumMoniker
 ******************************************************************************/
1409 1410 1411
static HRESULT
EnumMonikerImpl_CreateEnumMoniker(IMoniker** tabMoniker, ULONG tabSize,
               ULONG currentPos, BOOL leftToRigth, IEnumMoniker ** ppmk)
Noomen Hamza's avatar
Noomen Hamza committed
1412 1413 1414 1415
{
    EnumMonikerImpl* newEnumMoniker;
    int i;

1416 1417 1418
    if (currentPos > tabSize)
        return E_INVALIDARG;

Noomen Hamza's avatar
Noomen Hamza committed
1419 1420 1421 1422 1423 1424
    newEnumMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumMonikerImpl));

    if (newEnumMoniker == 0)
        return STG_E_INSUFFICIENTMEMORY;

    /* Initialize the virtual function table. */
1425
    newEnumMoniker->lpVtbl       = &VT_EnumMonikerImpl;
Noomen Hamza's avatar
Noomen Hamza committed
1426 1427 1428 1429 1430
    newEnumMoniker->ref          = 0;

    newEnumMoniker->tabSize=tabSize;
    newEnumMoniker->currentPos=currentPos;

1431
    newEnumMoniker->tabMoniker=HeapAlloc(GetProcessHeap(),0,tabSize*sizeof(IMoniker));
Noomen Hamza's avatar
Noomen Hamza committed
1432

1433 1434
    if (newEnumMoniker->tabMoniker==NULL) {
        HeapFree(GetProcessHeap(), 0, newEnumMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
1435
        return E_OUTOFMEMORY;
1436
    }
Noomen Hamza's avatar
Noomen Hamza committed
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455

    if (leftToRigth)
        for (i=0;i<tabSize;i++){

            newEnumMoniker->tabMoniker[i]=tabMoniker[i];
            IMoniker_AddRef(tabMoniker[i]);
        }
    else
        for (i=tabSize-1;i>=0;i--){

            newEnumMoniker->tabMoniker[tabSize-i-1]=tabMoniker[i];
            IMoniker_AddRef(tabMoniker[i]);
        }

    *ppmk=(IEnumMoniker*)newEnumMoniker;

    return S_OK;
}

1456 1457 1458 1459
/********************************************************************************/
/* Virtual function table for the CompositeMonikerImpl class which includes     */
/* IPersist, IPersistStream and IMoniker functions.                             */

1460
static const IMonikerVtbl VT_CompositeMonikerImpl =
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
{
    CompositeMonikerImpl_QueryInterface,
    CompositeMonikerImpl_AddRef,
    CompositeMonikerImpl_Release,
    CompositeMonikerImpl_GetClassID,
    CompositeMonikerImpl_IsDirty,
    CompositeMonikerImpl_Load,
    CompositeMonikerImpl_Save,
    CompositeMonikerImpl_GetSizeMax,
    CompositeMonikerImpl_BindToObject,
    CompositeMonikerImpl_BindToStorage,
    CompositeMonikerImpl_Reduce,
    CompositeMonikerImpl_ComposeWith,
    CompositeMonikerImpl_Enum,
    CompositeMonikerImpl_IsEqual,
    CompositeMonikerImpl_Hash,
    CompositeMonikerImpl_IsRunning,
    CompositeMonikerImpl_GetTimeOfLastChange,
    CompositeMonikerImpl_Inverse,
    CompositeMonikerImpl_CommonPrefixWith,
    CompositeMonikerImpl_RelativePathTo,
    CompositeMonikerImpl_GetDisplayName,
    CompositeMonikerImpl_ParseDisplayName,
    CompositeMonikerImpl_IsSystemMoniker
};

/********************************************************************************/
/* Virtual function table for the IROTData class.                               */
1489
static const IROTDataVtbl VT_ROTDataImpl =
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642
{
    CompositeMonikerROTDataImpl_QueryInterface,
    CompositeMonikerROTDataImpl_AddRef,
    CompositeMonikerROTDataImpl_Release,
    CompositeMonikerROTDataImpl_GetComparaisonData
};

/******************************************************************************
 *         Composite-Moniker_Construct (local function)
 *******************************************************************************/
static HRESULT
CompositeMonikerImpl_Construct(CompositeMonikerImpl* This,
               LPMONIKER pmkFirst, LPMONIKER pmkRest)
{
    DWORD mkSys;
    IEnumMoniker *enumMoniker;
    IMoniker *tempMk;
    HRESULT res;

    TRACE("(%p,%p,%p)\n",This,pmkFirst,pmkRest);

    /* Initialize the virtual function table. */
    This->lpvtbl1      = &VT_CompositeMonikerImpl;
    This->lpvtbl2      = &VT_ROTDataImpl;
    This->ref          = 0;

    This->tabSize=BLOCK_TAB_SIZE;
    This->tabLastIndex=0;

    This->tabMoniker=HeapAlloc(GetProcessHeap(),0,This->tabSize*sizeof(IMoniker));
    if (This->tabMoniker==NULL)
        return E_OUTOFMEMORY;

    IMoniker_IsSystemMoniker(pmkFirst,&mkSys);

    /* put the first moniker contents in the beginning of the table */
    if (mkSys!=MKSYS_GENERICCOMPOSITE){

        This->tabMoniker[(This->tabLastIndex)++]=pmkFirst;
        IMoniker_AddRef(pmkFirst);
    }
    else{

        IMoniker_Enum(pmkFirst,TRUE,&enumMoniker);

        while(IEnumMoniker_Next(enumMoniker,1,&This->tabMoniker[This->tabLastIndex],NULL)==S_OK){


            if (++This->tabLastIndex==This->tabSize){

                This->tabSize+=BLOCK_TAB_SIZE;
                This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));

                if (This->tabMoniker==NULL)
                    return E_OUTOFMEMORY;
            }
        }

        IEnumMoniker_Release(enumMoniker);
    }

    /* put the rest moniker contents after the first one and make simplification if needed */

    IMoniker_IsSystemMoniker(pmkRest,&mkSys);

    if (mkSys!=MKSYS_GENERICCOMPOSITE){

        /* add a simple moniker to the moniker table */

        res=IMoniker_ComposeWith(This->tabMoniker[This->tabLastIndex-1],pmkRest,TRUE,&tempMk);

        if (res==MK_E_NEEDGENERIC){

            /* there's no simplification in this case */
            This->tabMoniker[This->tabLastIndex]=pmkRest;

            This->tabLastIndex++;

            IMoniker_AddRef(pmkRest);
        }
        else if (tempMk==NULL){

            /* we have an antimoniker after a simple moniker so we can make a simplification in this case */
            IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);

            This->tabLastIndex--;
        }
        else if (SUCCEEDED(res)){

            /* the non-generic composition was successful so we can make a simplification in this case */
            IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);

            This->tabMoniker[This->tabLastIndex-1]=tempMk;
        } else
            return res;

        /* resize tabMoniker if needed */
        if (This->tabLastIndex==This->tabSize){

            This->tabSize+=BLOCK_TAB_SIZE;

            This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));

            if (This->tabMoniker==NULL)
            return E_OUTOFMEMORY;
        }
    }
    else{

        /* add a composite moniker to the moniker table (do the same thing
         * for each moniker within the composite moniker as a simple moniker
         * (see above for how to add a simple moniker case) )
         */
        IMoniker_Enum(pmkRest,TRUE,&enumMoniker);

        while(IEnumMoniker_Next(enumMoniker,1,&This->tabMoniker[This->tabLastIndex],NULL)==S_OK){

            res=IMoniker_ComposeWith(This->tabMoniker[This->tabLastIndex-1],This->tabMoniker[This->tabLastIndex],TRUE,&tempMk);

            if (res==MK_E_NEEDGENERIC){

                This->tabLastIndex++;
            }
            else if (tempMk==NULL){

                IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);
                IMoniker_Release(This->tabMoniker[This->tabLastIndex]);
                This->tabLastIndex--;
            }
            else{

                IMoniker_Release(This->tabMoniker[This->tabLastIndex-1]);

                This->tabMoniker[This->tabLastIndex-1]=tempMk;
            }

            if (This->tabLastIndex==This->tabSize){

                This->tabSize+=BLOCK_TAB_SIZE;

                This->tabMoniker=HeapReAlloc(GetProcessHeap(),0,This->tabMoniker,This->tabSize*sizeof(IMoniker));

                if (This->tabMoniker==NULL)
                    return E_OUTOFMEMORY;
            }
        }

        IEnumMoniker_Release(enumMoniker);
    }

    return S_OK;
}

Noomen Hamza's avatar
Noomen Hamza committed
1643
/******************************************************************************
1644
 *        CreateGenericComposite	[OLE32.@]
Noomen Hamza's avatar
Noomen Hamza committed
1645
 ******************************************************************************/
1646 1647 1648
HRESULT WINAPI
CreateGenericComposite(LPMONIKER pmkFirst, LPMONIKER pmkRest,
               LPMONIKER* ppmkComposite)
Noomen Hamza's avatar
Noomen Hamza committed
1649 1650 1651 1652
{
    CompositeMonikerImpl* newCompositeMoniker = 0;
    HRESULT        hr = S_OK;

1653
    TRACE("(%p,%p,%p)\n",pmkFirst,pmkRest,ppmkComposite);
Noomen Hamza's avatar
Noomen Hamza committed
1654 1655 1656

    if (ppmkComposite==NULL)
        return E_POINTER;
1657

Noomen Hamza's avatar
Noomen Hamza committed
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
    *ppmkComposite=0;

    if (pmkFirst==NULL && pmkRest!=NULL){

        *ppmkComposite=pmkRest;
        return S_OK;
    }
    else if (pmkFirst!=NULL && pmkRest==NULL){
        *ppmkComposite=pmkFirst;
        return S_OK;
    }
    else  if (pmkFirst==NULL && pmkRest==NULL)
        return S_OK;

    newCompositeMoniker = HeapAlloc(GetProcessHeap(), 0,sizeof(CompositeMonikerImpl));

    if (newCompositeMoniker == 0)
        return STG_E_INSUFFICIENTMEMORY;

    hr = CompositeMonikerImpl_Construct(newCompositeMoniker,pmkFirst,pmkRest);

    if (FAILED(hr)){

        HeapFree(GetProcessHeap(),0,newCompositeMoniker);
        return hr;
    }
    if (newCompositeMoniker->tabLastIndex==1)

        hr = IMoniker_QueryInterface(newCompositeMoniker->tabMoniker[0],&IID_IMoniker,(void**)ppmkComposite);
    else

1689
        hr = IMoniker_QueryInterface((IMoniker*)newCompositeMoniker,&IID_IMoniker,(void**)ppmkComposite);
Noomen Hamza's avatar
Noomen Hamza committed
1690 1691 1692 1693 1694

    return hr;
}

/******************************************************************************
1695
 *        MonikerCommonPrefixWith	[OLE32.@]
Noomen Hamza's avatar
Noomen Hamza committed
1696
 ******************************************************************************/
1697 1698
HRESULT WINAPI
MonikerCommonPrefixWith(IMoniker* pmkThis,IMoniker* pmkOther,IMoniker** ppmkCommon)
Noomen Hamza's avatar
Noomen Hamza committed
1699
{
1700
    FIXME("(),stub!\n");
Noomen Hamza's avatar
Noomen Hamza committed
1701 1702
    return E_NOTIMPL;
}