import "oaidl.idl";
import "shtypes.idl";
import "shobjidl.idl";

typedef [v1_enum] enum WTS_FLAGS
{
    WTS_EXTRACT           = 0x00000000,
    WTS_INCACHEONLY       = 0x00000001,
    WTS_FASTEXTRACT       = 0x00000002,
    WTS_FORCEEXTRACTION   = 0x00000004,
    WTS_SLOWRECLAIM       = 0x00000008,
    WTS_EXTRACTDONOTCACHE = 0x00000020,
    WTS_SCALETOREQUESTEDSIZE = 0x00000040,
    WTS_SKIPFASTEXTRACT   = 0x00000080,
    WTS_EXTRACTINPROC     = 0x00000100,
} WTS_FLAGS;

cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(WTS_FLAGS)")

typedef [v1_enum] enum WTS_CACHEFLAGS
{
    WTS_DEFAULT     = 0x00000000,
    WTS_LOWQUALITY  = 0x00000001,
    WTS_CACHED      = 0x00000002,
} WTS_CACHEFLAGS;

cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(WTS_CACHEFLAGS)")

typedef [v1_enum] enum WTS_ALPHATYPE
{
    WTSAT_UNKNOWN = 0,
    WTSAT_RGB = 1,
    WTSAT_ARGB = 2,
} WTS_ALPHATYPE;

typedef struct WTS_THUMBNAILID
{
    BYTE rgbKey[16];
} WTS_THUMBNAILID;

// Custom error code
cpp_quote("#define WTS_E_FAILEDEXTRACTION MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xB200)")

// This interface is used as a thin wrapper around HBITMAP objects.  It allows an
// HBITMAP to be ref-counted and protected from having its underlying data be changed
[
    uuid(091162a4-bc96-411f-aae8-c5122cd03363),
    pointer_default(unique),
]
interface ISharedBitmap : IUnknown
{
    HRESULT GetSharedBitmap([out] HBITMAP *phbm);
    HRESULT GetSize([out] SIZE *pSize);
    HRESULT GetFormat([out] WTS_ALPHATYPE *pat);
    HRESULT InitializeBitmap([in] HBITMAP hbm, [in] WTS_ALPHATYPE wtsAT);
    HRESULT Detach([out] HBITMAP *phbm);
};


// Interface for the system thumbnail cache.  GetThumbnail is used to extract and return
// thumbnails for IShellItems.  The cache behavior can be specified using one or more of
// the WTS_FLAGS.  GetThumbnailID allows the caller to retrieve an image known to be in
// the cache via its ID (which was returned by GetThumbnail).

[
    object,
    uuid(F676C15D-596A-4ce2-8234-33996F445DB1),
]
interface IThumbnailCache : IUnknown
{
    [local]
    HRESULT GetThumbnail([in]                                   IShellItem *pShellItem,
                         [in]                                   UINT cxyRequestedThumbSize,
                         [in]                                   WTS_FLAGS flags,
                         [out]                                  ISharedBitmap **ppvThumb,
                         [out, unique, annotation("__out_opt")] WTS_CACHEFLAGS *pOutFlags,
                         [out, unique, annotation("__out_opt")] WTS_THUMBNAILID *pThumbnailID);

    [call_as(GetThumbnail)]
    HRESULT RemoteGetThumbnail([in]  IShellItem *pShellItem,
                               [in]  UINT cxyRequestedThumbSize,
                               [in]  WTS_FLAGS flags,
                               [out] ISharedBitmap **ppvThumb,
                               [out] WTS_CACHEFLAGS *pOutFlags,
                               [out] WTS_THUMBNAILID *pThumbnailID);

    [local]
    HRESULT GetThumbnailByID([in]                                   WTS_THUMBNAILID thumbnailID,
                             [in]                                   UINT cxyRequestedThumbSize,
                             [out]                                  ISharedBitmap **ppvThumb,
                             [out, unique, annotation("__out_opt")] WTS_CACHEFLAGS *pOutFlags);

    [call_as(GetThumbnailByID)]
    HRESULT RemoteGetThumbnailByID([in]  WTS_THUMBNAILID thumbnailID,
                                   [in]  UINT cxyRequestedThumbSize,
                                   [out] ISharedBitmap **ppvThumb,
                                   [out] WTS_CACHEFLAGS *pOutFlags);
};

[
    uuid(e357fccd-a995-4576-b01f-234630154e96),
]
interface IThumbnailProvider : IUnknown
{
    HRESULT GetThumbnail([in] UINT cx, [out] HBITMAP *phbmp, [out] WTS_ALPHATYPE *pdwAlpha);
};

[ 
    uuid(4c857096-0514-4d4d-abd5-dfaaa3c326d2)
] 
library ThumbCacheLib
{
    // Local Thumbnail Cache
    [ uuid(50EF4544-AC9F-4A8E-B21B-8A26180DB13F) ] coclass LocalThumbnailCache { interface IThumbnailCache; }

    // Shared Bitmap Object
    [ uuid(4db26476-6787-4046-b836-e8412a9e8a27) ] coclass SharedBitmap { interface ISharedBitmap; }    
};

