1999-05-02 11:27:08 +02:00
|
|
|
/*
|
|
|
|
* OLE 2 Data cache
|
|
|
|
*
|
|
|
|
* Copyright 1999 Francis Beaudet
|
2000-05-24 01:34:40 +02:00
|
|
|
* Copyright 2000 Abey George
|
1999-05-02 11:27:08 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
1999-05-02 11:27:08 +02:00
|
|
|
* NOTES:
|
|
|
|
* The OLE2 data cache supports a whole whack of
|
|
|
|
* interfaces including:
|
|
|
|
* IDataObject, IPersistStorage, IViewObject2,
|
|
|
|
* IOleCache2 and IOleCacheControl.
|
|
|
|
*
|
1999-05-08 12:55:32 +02:00
|
|
|
* Most of the implementation details are taken from: Inside OLE
|
1999-05-02 11:27:08 +02:00
|
|
|
* second edition by Kraig Brockschmidt,
|
|
|
|
*
|
1999-05-08 12:55:32 +02:00
|
|
|
* NOTES
|
|
|
|
* - This implementation of the datacache will let your application
|
|
|
|
* load documents that have embedded OLE objects in them and it will
|
2002-06-01 01:06:46 +02:00
|
|
|
* also retrieve the metafile representation of those objects.
|
1999-05-08 12:55:32 +02:00
|
|
|
* - This implementation of the datacache will also allow your
|
|
|
|
* application to save new documents with OLE objects in them.
|
2002-06-01 01:06:46 +02:00
|
|
|
* - The main thing that it doesn't do is allow you to activate
|
1999-05-08 12:55:32 +02:00
|
|
|
* or modify the OLE objects in any way.
|
|
|
|
* - I haven't found any good documentation on the real usage of
|
|
|
|
* the streams created by the data cache. In particular, How to
|
|
|
|
* determine what the XXX stands for in the stream name
|
2000-03-19 13:42:58 +01:00
|
|
|
* "\002OlePresXXX". It appears to just be a counter.
|
1999-05-08 12:55:32 +02:00
|
|
|
* - Also, I don't know the real content of the presentation stream
|
2002-06-01 01:06:46 +02:00
|
|
|
* header. I was able to figure-out where the extent of the object
|
2000-03-19 13:42:58 +01:00
|
|
|
* was stored and the aspect, but that's about it.
|
1999-05-02 11:27:08 +02:00
|
|
|
*/
|
2015-03-16 19:07:43 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2003-01-07 21:36:20 +01:00
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2000-02-10 20:39:48 +01:00
|
|
|
#include "windef.h"
|
1999-08-18 20:35:57 +02:00
|
|
|
#include "winbase.h"
|
2000-02-10 20:39:48 +01:00
|
|
|
#include "wingdi.h"
|
2000-05-24 01:34:40 +02:00
|
|
|
#include "winuser.h"
|
1999-05-02 11:27:08 +02:00
|
|
|
#include "winerror.h"
|
2000-05-24 01:34:40 +02:00
|
|
|
#include "ole2.h"
|
2017-05-18 12:07:03 +02:00
|
|
|
#include "compobj_private.h"
|
|
|
|
#include "wine/unicode.h"
|
2006-12-01 16:01:38 +01:00
|
|
|
#include "wine/list.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
1999-05-08 12:55:32 +02:00
|
|
|
* PresentationDataHeader
|
|
|
|
*
|
|
|
|
* This structure represents the header of the \002OlePresXXX stream in
|
2008-04-09 21:33:37 +02:00
|
|
|
* the OLE object storage.
|
1999-05-02 11:27:08 +02:00
|
|
|
*/
|
1999-05-08 12:55:32 +02:00
|
|
|
typedef struct PresentationDataHeader
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2006-12-18 00:44:18 +01:00
|
|
|
/* clipformat:
|
|
|
|
* - standard clipformat:
|
|
|
|
* DWORD length = 0xffffffff;
|
|
|
|
* DWORD cfFormat;
|
|
|
|
* - or custom clipformat:
|
|
|
|
* DWORD length;
|
|
|
|
* CHAR format_name[length]; (null-terminated)
|
|
|
|
*/
|
2017-11-22 09:30:51 +01:00
|
|
|
DWORD tdSize; /* This is actually a truncated DVTARGETDEVICE, if tdSize > sizeof(DWORD)
|
|
|
|
then there are tdSize - sizeof(DWORD) more bytes before dvAspect */
|
2000-03-19 13:42:58 +01:00
|
|
|
DVASPECT dvAspect;
|
2006-12-01 16:04:04 +01:00
|
|
|
DWORD lindex;
|
2017-06-06 12:46:48 +02:00
|
|
|
DWORD advf;
|
2000-03-19 13:42:58 +01:00
|
|
|
DWORD unknown7; /* 0 */
|
2000-05-24 01:34:40 +02:00
|
|
|
DWORD dwObjectExtentX;
|
|
|
|
DWORD dwObjectExtentY;
|
|
|
|
DWORD dwSize;
|
1999-05-08 12:55:32 +02:00
|
|
|
} PresentationDataHeader;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2015-03-25 09:37:35 +01:00
|
|
|
enum stream_type
|
|
|
|
{
|
|
|
|
no_stream,
|
|
|
|
pres_stream,
|
2015-03-25 09:37:36 +01:00
|
|
|
contents_stream
|
2015-03-25 09:37:35 +01:00
|
|
|
};
|
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
typedef struct DataCacheEntry
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
/* format of this entry */
|
|
|
|
FORMATETC fmtetc;
|
2006-12-01 16:02:11 +01:00
|
|
|
/* cached data */
|
|
|
|
STGMEDIUM stgmedium;
|
2006-12-01 16:01:38 +01:00
|
|
|
/*
|
2015-03-25 09:37:34 +01:00
|
|
|
* This stream pointer is set through a call to
|
2006-12-01 16:01:38 +01:00
|
|
|
* IPersistStorage_Load. This is where the visual
|
|
|
|
* representation of the object is stored.
|
|
|
|
*/
|
2015-03-25 09:37:34 +01:00
|
|
|
IStream *stream;
|
2015-03-25 09:37:35 +01:00
|
|
|
enum stream_type stream_type;
|
2006-12-01 16:03:19 +01:00
|
|
|
/* connection ID */
|
2006-12-01 16:01:50 +01:00
|
|
|
DWORD id;
|
2006-12-01 16:03:19 +01:00
|
|
|
/* dirty flag */
|
|
|
|
BOOL dirty;
|
2006-12-01 16:04:04 +01:00
|
|
|
/* stream number (-1 if not set ) */
|
|
|
|
unsigned short stream_number;
|
2010-11-01 15:08:45 +01:00
|
|
|
/* sink id set when object is running */
|
|
|
|
DWORD sink_id;
|
|
|
|
/* Advise sink flags */
|
|
|
|
DWORD advise_flags;
|
2006-12-01 16:01:38 +01:00
|
|
|
} DataCacheEntry;
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* DataCache
|
|
|
|
*/
|
|
|
|
struct DataCache
|
|
|
|
{
|
|
|
|
/*
|
2010-12-23 02:05:04 +01:00
|
|
|
* List all interface here
|
1999-05-02 11:27:08 +02:00
|
|
|
*/
|
2016-07-06 08:49:39 +02:00
|
|
|
IUnknown IUnknown_inner;
|
2010-12-23 02:05:04 +01:00
|
|
|
IDataObject IDataObject_iface;
|
|
|
|
IPersistStorage IPersistStorage_iface;
|
|
|
|
IViewObject2 IViewObject2_iface;
|
|
|
|
IOleCache2 IOleCache2_iface;
|
|
|
|
IOleCacheControl IOleCacheControl_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2010-10-26 15:35:14 +02:00
|
|
|
/* The sink that is connected to a remote object.
|
|
|
|
The other interfaces are not available by QI'ing the sink and vice-versa */
|
2010-12-23 02:05:04 +01:00
|
|
|
IAdviseSink IAdviseSink_iface;
|
2010-10-26 15:35:14 +02:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/*
|
|
|
|
* Reference count of this object
|
|
|
|
*/
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IUnknown implementation of the outer object.
|
|
|
|
*/
|
2016-07-06 08:49:39 +02:00
|
|
|
IUnknown *outer_unk;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/*
|
|
|
|
* The user of this object can setup ONE advise sink
|
|
|
|
* connection with the object. These parameters describe
|
|
|
|
* that connection.
|
|
|
|
*/
|
|
|
|
DWORD sinkAspects;
|
|
|
|
DWORD sinkAdviseFlag;
|
2017-06-06 12:46:51 +02:00
|
|
|
IAdviseSink *sinkInterface;
|
|
|
|
|
|
|
|
CLSID clsid;
|
2006-12-01 16:01:38 +01:00
|
|
|
IStorage *presentationStorage;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-12-01 16:03:19 +01:00
|
|
|
/* list of cache entries */
|
2006-12-01 16:01:38 +01:00
|
|
|
struct list cache_list;
|
2006-12-01 16:02:11 +01:00
|
|
|
/* last id assigned to an entry */
|
2006-12-01 16:01:50 +01:00
|
|
|
DWORD last_cache_id;
|
2006-12-01 16:03:19 +01:00
|
|
|
/* dirty flag */
|
|
|
|
BOOL dirty;
|
2010-11-01 15:08:45 +01:00
|
|
|
/* running object set by OnRun */
|
|
|
|
IDataObject *running_object;
|
1999-05-02 11:27:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct DataCache DataCache;
|
|
|
|
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Here, I define utility macros to help with the casting of the
|
1999-05-02 11:27:08 +02:00
|
|
|
* "this" parameter.
|
2004-10-05 20:15:29 +02:00
|
|
|
* There is a version to accommodate all of the VTables implemented
|
1999-05-02 11:27:08 +02:00
|
|
|
* by this object.
|
|
|
|
*/
|
2005-07-27 13:10:52 +02:00
|
|
|
|
|
|
|
static inline DataCache *impl_from_IDataObject( IDataObject *iface )
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
return CONTAINING_RECORD(iface, DataCache, IDataObject_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:05:04 +01:00
|
|
|
static inline DataCache *impl_from_IUnknown( IUnknown *iface )
|
2005-07-27 13:10:52 +02:00
|
|
|
{
|
2016-07-06 08:49:39 +02:00
|
|
|
return CONTAINING_RECORD(iface, DataCache, IUnknown_inner);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline DataCache *impl_from_IPersistStorage( IPersistStorage *iface )
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
return CONTAINING_RECORD(iface, DataCache, IPersistStorage_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline DataCache *impl_from_IViewObject2( IViewObject2 *iface )
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
return CONTAINING_RECORD(iface, DataCache, IViewObject2_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline DataCache *impl_from_IOleCache2( IOleCache2 *iface )
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
return CONTAINING_RECORD(iface, DataCache, IOleCache2_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline DataCache *impl_from_IOleCacheControl( IOleCacheControl *iface )
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
return CONTAINING_RECORD(iface, DataCache, IOleCacheControl_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
2010-10-26 15:35:14 +02:00
|
|
|
static inline DataCache *impl_from_IAdviseSink( IAdviseSink *iface )
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
return CONTAINING_RECORD(iface, DataCache, IAdviseSink_iface);
|
2010-10-26 15:35:14 +02:00
|
|
|
}
|
|
|
|
|
2015-10-09 12:13:24 +02:00
|
|
|
const char *debugstr_formatetc(const FORMATETC *formatetc)
|
2006-12-01 16:04:04 +01:00
|
|
|
{
|
2006-12-06 12:05:31 +01:00
|
|
|
return wine_dbg_sprintf("{ cfFormat = 0x%x, ptd = %p, dwAspect = %d, lindex = %d, tymed = %d }",
|
|
|
|
formatetc->cfFormat, formatetc->ptd, formatetc->dwAspect,
|
|
|
|
formatetc->lindex, formatetc->tymed);
|
2006-12-01 16:04:04 +01:00
|
|
|
}
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2017-05-18 12:07:06 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* bitmap_info_size
|
|
|
|
*
|
|
|
|
* Return the size of the bitmap info structure including color table.
|
|
|
|
*/
|
2017-06-04 11:38:56 +02:00
|
|
|
static int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
|
2017-05-18 12:07:06 +02:00
|
|
|
{
|
|
|
|
unsigned int colors, size, masks = 0;
|
|
|
|
|
|
|
|
if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
|
|
|
|
{
|
|
|
|
const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
|
|
|
|
colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
|
|
|
|
return sizeof(BITMAPCOREHEADER) + colors *
|
|
|
|
((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
|
|
|
|
}
|
|
|
|
else /* assume BITMAPINFOHEADER */
|
|
|
|
{
|
|
|
|
colors = info->bmiHeader.biClrUsed;
|
|
|
|
if (colors > 256) /* buffer overflow otherwise */
|
|
|
|
colors = 256;
|
|
|
|
if (!colors && (info->bmiHeader.biBitCount <= 8))
|
|
|
|
colors = 1 << info->bmiHeader.biBitCount;
|
|
|
|
if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
|
|
|
|
size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
|
|
|
|
return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-01 15:08:45 +01:00
|
|
|
static void DataCacheEntry_Destroy(DataCache *cache, DataCacheEntry *cache_entry)
|
2006-12-01 16:01:50 +01:00
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
list_remove(&cache_entry->entry);
|
2015-03-25 09:37:34 +01:00
|
|
|
if (cache_entry->stream)
|
|
|
|
IStream_Release(cache_entry->stream);
|
2017-05-18 12:07:03 +02:00
|
|
|
CoTaskMemFree(cache_entry->fmtetc.ptd);
|
2010-11-01 13:06:27 +01:00
|
|
|
ReleaseStgMedium(&cache_entry->stgmedium);
|
2010-11-01 15:08:45 +01:00
|
|
|
if(cache_entry->sink_id)
|
|
|
|
IDataObject_DUnadvise(cache->running_object, cache_entry->sink_id);
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, cache_entry);
|
2006-12-01 16:01:50 +01:00
|
|
|
}
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
static void DataCache_Destroy(
|
|
|
|
DataCache* ptrToDestroy)
|
|
|
|
{
|
2006-12-01 16:01:38 +01:00
|
|
|
DataCacheEntry *cache_entry, *next_cache_entry;
|
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
1999-05-08 12:55:32 +02:00
|
|
|
|
|
|
|
if (ptrToDestroy->sinkInterface != NULL)
|
|
|
|
{
|
|
|
|
IAdviseSink_Release(ptrToDestroy->sinkInterface);
|
|
|
|
ptrToDestroy->sinkInterface = NULL;
|
|
|
|
}
|
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(cache_entry, next_cache_entry, &ptrToDestroy->cache_list, DataCacheEntry, entry)
|
2010-11-01 15:08:45 +01:00
|
|
|
DataCacheEntry_Destroy(ptrToDestroy, cache_entry);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2009-11-29 11:30:02 +01:00
|
|
|
if (ptrToDestroy->presentationStorage != NULL)
|
|
|
|
{
|
|
|
|
IStorage_Release(ptrToDestroy->presentationStorage);
|
|
|
|
ptrToDestroy->presentationStorage = NULL;
|
|
|
|
}
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/*
|
|
|
|
* Free the datacache pointer.
|
|
|
|
*/
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptrToDestroy);
|
|
|
|
}
|
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
static DataCacheEntry *DataCache_GetEntryForFormatEtc(DataCache *This, const FORMATETC *formatetc)
|
|
|
|
{
|
|
|
|
DataCacheEntry *cache_entry;
|
2017-05-23 14:11:42 +02:00
|
|
|
FORMATETC fmt = *formatetc;
|
|
|
|
|
|
|
|
if (fmt.cfFormat == CF_BITMAP)
|
|
|
|
{
|
|
|
|
fmt.cfFormat = CF_DIB;
|
|
|
|
fmt.tymed = TYMED_HGLOBAL;
|
|
|
|
}
|
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
/* FIXME: also compare DVTARGETDEVICEs */
|
2017-10-31 14:23:29 +01:00
|
|
|
if ((fmt.cfFormat == cache_entry->fmtetc.cfFormat) &&
|
2017-05-23 14:11:42 +02:00
|
|
|
(fmt.dwAspect == cache_entry->fmtetc.dwAspect) &&
|
|
|
|
(fmt.lindex == cache_entry->fmtetc.lindex) &&
|
2017-10-31 14:23:29 +01:00
|
|
|
((fmt.tymed == cache_entry->fmtetc.tymed) || !cache_entry->fmtetc.cfFormat)) /* tymed is ignored for view caching */
|
2006-12-01 16:01:38 +01:00
|
|
|
return cache_entry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-12-02 19:16:47 +01:00
|
|
|
/* checks that the clipformat and tymed are valid and returns an error if they
|
|
|
|
* aren't and CACHE_S_NOTSUPPORTED if they are valid, but can't be rendered by
|
|
|
|
* DataCache_Draw */
|
2017-10-31 14:23:30 +01:00
|
|
|
static HRESULT check_valid_formatetc( const FORMATETC *fmt )
|
2006-12-02 19:16:47 +01:00
|
|
|
{
|
2017-10-31 14:23:30 +01:00
|
|
|
/* DVASPECT_ICON must be CF_METAFILEPICT */
|
|
|
|
if (fmt->dwAspect == DVASPECT_ICON && fmt->cfFormat != CF_METAFILEPICT)
|
|
|
|
return DV_E_FORMATETC;
|
|
|
|
|
2017-10-31 14:23:31 +01:00
|
|
|
if (!fmt->cfFormat ||
|
2017-10-31 14:23:30 +01:00
|
|
|
(fmt->cfFormat == CF_METAFILEPICT && fmt->tymed == TYMED_MFPICT) ||
|
|
|
|
(fmt->cfFormat == CF_BITMAP && fmt->tymed == TYMED_GDI) ||
|
|
|
|
(fmt->cfFormat == CF_DIB && fmt->tymed == TYMED_HGLOBAL) ||
|
|
|
|
(fmt->cfFormat == CF_ENHMETAFILE && fmt->tymed == TYMED_ENHMF))
|
2006-12-02 19:16:47 +01:00
|
|
|
return S_OK;
|
2017-10-31 14:23:30 +01:00
|
|
|
else if (fmt->tymed == TYMED_HGLOBAL)
|
2006-12-02 19:16:47 +01:00
|
|
|
return CACHE_S_FORMATETC_NOTSUPPORTED;
|
|
|
|
else
|
|
|
|
{
|
2017-10-31 14:23:30 +01:00
|
|
|
WARN("invalid clipformat/tymed combination: %d/%d\n", fmt->cfFormat, fmt->tymed);
|
2006-12-02 19:16:47 +01:00
|
|
|
return DV_E_TYMED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 12:07:03 +02:00
|
|
|
static BOOL init_cache_entry(DataCacheEntry *entry, const FORMATETC *fmt, DWORD advf,
|
|
|
|
DWORD id)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = copy_formatetc(&entry->fmtetc, fmt);
|
|
|
|
if (FAILED(hr)) return FALSE;
|
|
|
|
|
|
|
|
entry->stgmedium.tymed = TYMED_NULL;
|
|
|
|
entry->stgmedium.pUnkForRelease = NULL;
|
|
|
|
entry->stream = NULL;
|
|
|
|
entry->stream_type = no_stream;
|
|
|
|
entry->id = id;
|
|
|
|
entry->dirty = TRUE;
|
|
|
|
entry->stream_number = -1;
|
|
|
|
entry->sink_id = 0;
|
|
|
|
entry->advise_flags = advf;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-05-18 12:07:05 +02:00
|
|
|
static HRESULT DataCache_CreateEntry(DataCache *This, const FORMATETC *formatetc, DWORD advf,
|
2017-06-06 12:46:51 +02:00
|
|
|
BOOL automatic, DataCacheEntry **cache_entry)
|
2006-12-01 16:01:38 +01:00
|
|
|
{
|
2006-12-02 19:16:47 +01:00
|
|
|
HRESULT hr;
|
2017-06-06 12:46:51 +02:00
|
|
|
DWORD id = automatic ? 1 : This->last_cache_id;
|
2017-06-06 12:46:50 +02:00
|
|
|
DataCacheEntry *entry;
|
2006-12-02 19:16:47 +01:00
|
|
|
|
2017-10-31 14:23:30 +01:00
|
|
|
hr = check_valid_formatetc( formatetc );
|
2006-12-02 19:16:47 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
if (hr == CACHE_S_FORMATETC_NOTSUPPORTED)
|
|
|
|
TRACE("creating unsupported format %d\n", formatetc->cfFormat);
|
|
|
|
|
2017-06-06 12:46:50 +02:00
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
|
|
|
|
if (!entry)
|
2006-12-01 16:02:11 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2017-06-06 12:46:51 +02:00
|
|
|
if (!init_cache_entry(entry, formatetc, advf, id))
|
2017-05-18 12:07:03 +02:00
|
|
|
goto fail;
|
|
|
|
|
2017-06-06 12:46:51 +02:00
|
|
|
if (automatic)
|
|
|
|
list_add_head(&This->cache_list, &entry->entry);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list_add_tail(&This->cache_list, &entry->entry);
|
|
|
|
This->last_cache_id++;
|
|
|
|
}
|
2017-05-18 12:07:03 +02:00
|
|
|
|
2017-06-06 12:46:50 +02:00
|
|
|
if (cache_entry) *cache_entry = entry;
|
2006-12-02 19:16:47 +01:00
|
|
|
return hr;
|
2017-05-18 12:07:03 +02:00
|
|
|
|
|
|
|
fail:
|
2017-06-06 12:46:50 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
2017-05-18 12:07:03 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2006-12-01 16:01:38 +01:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_FireOnViewChange
|
|
|
|
*
|
|
|
|
* This method will fire an OnViewChange notification to the advise
|
|
|
|
* sink registered with the datacache.
|
|
|
|
*
|
|
|
|
* See IAdviseSink::OnViewChange for more details.
|
|
|
|
*/
|
|
|
|
static void DataCache_FireOnViewChange(
|
|
|
|
DataCache* this,
|
|
|
|
DWORD aspect,
|
|
|
|
LONG lindex)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %x, %d)\n", this, aspect, lindex);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The sink supplies a filter when it registers
|
|
|
|
* we make sure we only send the notifications when that
|
|
|
|
* filter matches.
|
|
|
|
*/
|
|
|
|
if ((this->sinkAspects & aspect) != 0)
|
|
|
|
{
|
|
|
|
if (this->sinkInterface != NULL)
|
|
|
|
{
|
|
|
|
IAdviseSink_OnViewChange(this->sinkInterface,
|
|
|
|
aspect,
|
|
|
|
lindex);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some sinks want to be unregistered automatically when
|
|
|
|
* the first notification goes out.
|
|
|
|
*/
|
|
|
|
if ( (this->sinkAdviseFlag & ADVF_ONLYONCE) != 0)
|
|
|
|
{
|
|
|
|
IAdviseSink_Release(this->sinkInterface);
|
|
|
|
|
|
|
|
this->sinkInterface = NULL;
|
|
|
|
this->sinkAspects = 0;
|
|
|
|
this->sinkAdviseFlag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
/* Helper for DataCacheEntry_OpenPresStream */
|
2000-03-19 13:42:58 +01:00
|
|
|
static BOOL DataCache_IsPresentationStream(const STATSTG *elem)
|
|
|
|
{
|
|
|
|
/* The presentation streams have names of the form "\002OlePresXXX",
|
|
|
|
* where XXX goes from 000 to 999. */
|
|
|
|
static const WCHAR OlePres[] = { 2,'O','l','e','P','r','e','s' };
|
|
|
|
|
|
|
|
LPCWSTR name = elem->pwcsName;
|
|
|
|
|
|
|
|
return (elem->type == STGTY_STREAM)
|
2000-06-13 03:10:29 +02:00
|
|
|
&& (strlenW(name) == 11)
|
|
|
|
&& (strncmpW(name, OlePres, 8) == 0)
|
2000-06-23 18:13:33 +02:00
|
|
|
&& (name[8] >= '0') && (name[8] <= '9')
|
|
|
|
&& (name[9] >= '0') && (name[9] <= '9')
|
|
|
|
&& (name[10] >= '0') && (name[10] <= '9');
|
2000-03-19 13:42:58 +01:00
|
|
|
}
|
|
|
|
|
2006-12-18 00:44:18 +01:00
|
|
|
static HRESULT read_clipformat(IStream *stream, CLIPFORMAT *clipformat)
|
|
|
|
{
|
|
|
|
DWORD length;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG read;
|
|
|
|
|
|
|
|
*clipformat = 0;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, &length, sizeof(length), &read);
|
|
|
|
if (hr != S_OK || read != sizeof(length))
|
|
|
|
return DV_E_CLIPFORMAT;
|
2017-11-05 23:07:05 +01:00
|
|
|
if (!length) {
|
|
|
|
/* No clipboard format present */
|
|
|
|
return S_OK;
|
|
|
|
}
|
2006-12-18 00:44:18 +01:00
|
|
|
if (length == -1)
|
|
|
|
{
|
|
|
|
DWORD cf;
|
2015-10-21 04:51:52 +02:00
|
|
|
hr = IStream_Read(stream, &cf, sizeof(cf), &read);
|
2006-12-18 00:44:18 +01:00
|
|
|
if (hr != S_OK || read != sizeof(cf))
|
|
|
|
return DV_E_CLIPFORMAT;
|
|
|
|
*clipformat = cf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *format_name = HeapAlloc(GetProcessHeap(), 0, length);
|
|
|
|
if (!format_name)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
hr = IStream_Read(stream, format_name, length, &read);
|
|
|
|
if (hr != S_OK || read != length || format_name[length - 1] != '\0')
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, format_name);
|
|
|
|
return DV_E_CLIPFORMAT;
|
|
|
|
}
|
|
|
|
*clipformat = RegisterClipboardFormatA(format_name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, format_name);
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_clipformat(IStream *stream, CLIPFORMAT clipformat)
|
|
|
|
{
|
|
|
|
DWORD length;
|
|
|
|
HRESULT hr;
|
2017-11-05 23:07:05 +01:00
|
|
|
char format_name[256];
|
2006-12-18 00:44:18 +01:00
|
|
|
|
|
|
|
if (clipformat < 0xc000)
|
|
|
|
length = -1;
|
|
|
|
else
|
2017-11-05 23:07:05 +01:00
|
|
|
{
|
|
|
|
length = GetClipboardFormatNameA(clipformat, format_name, sizeof(format_name));
|
|
|
|
/* If there is a clipboard format name, we need to include its terminating \0 */
|
|
|
|
if (length) length++;
|
|
|
|
}
|
2006-12-18 00:44:18 +01:00
|
|
|
hr = IStream_Write(stream, &length, sizeof(length), NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
if (clipformat < 0xc000)
|
|
|
|
{
|
|
|
|
DWORD cf = clipformat;
|
|
|
|
hr = IStream_Write(stream, &cf, sizeof(cf), NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = IStream_Write(stream, format_name, length, NULL);
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
2006-12-01 16:01:38 +01:00
|
|
|
* DataCacheEntry_OpenPresStream
|
1999-05-08 12:55:32 +02:00
|
|
|
*
|
2000-03-19 13:42:58 +01:00
|
|
|
* This method will find the stream for the given presentation. It makes
|
|
|
|
* no attempt at fallback.
|
1999-05-08 12:55:32 +02:00
|
|
|
*
|
|
|
|
* Param:
|
|
|
|
* this - Pointer to the DataCache object
|
|
|
|
* drawAspect - The aspect of the object that we wish to draw.
|
2000-03-19 13:42:58 +01:00
|
|
|
* pStm - A returned stream. It points to the beginning of the
|
|
|
|
* - presentation data, including the header.
|
|
|
|
*
|
|
|
|
* Errors:
|
|
|
|
* S_OK The requested stream has been opened.
|
|
|
|
* OLE_E_BLANK The requested stream could not be found.
|
|
|
|
* Quite a few others I'm too lazy to map correctly.
|
1999-05-08 12:55:32 +02:00
|
|
|
*
|
2000-03-19 13:42:58 +01:00
|
|
|
* Notes:
|
|
|
|
* Algorithm: Scan the elements of the presentation storage, looking
|
|
|
|
* for presentation streams. For each presentation stream,
|
2006-03-21 18:24:49 +01:00
|
|
|
* load the header and check to see if the aspect matches.
|
2000-03-19 13:42:58 +01:00
|
|
|
*
|
|
|
|
* If a fallback is desired, just opening the first presentation stream
|
|
|
|
* is a possibility.
|
1999-05-08 12:55:32 +02:00
|
|
|
*/
|
2010-11-01 13:06:27 +01:00
|
|
|
static HRESULT DataCacheEntry_OpenPresStream(DataCacheEntry *cache_entry, IStream **ppStm)
|
1999-05-08 12:55:32 +02:00
|
|
|
{
|
2000-03-19 13:42:58 +01:00
|
|
|
HRESULT hr;
|
2015-03-25 09:37:34 +01:00
|
|
|
LARGE_INTEGER offset;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2015-03-25 09:37:34 +01:00
|
|
|
if (cache_entry->stream)
|
2000-03-19 13:42:58 +01:00
|
|
|
{
|
2015-03-25 09:37:34 +01:00
|
|
|
/* Rewind the stream before returning it. */
|
|
|
|
offset.QuadPart = 0;
|
2000-03-19 13:42:58 +01:00
|
|
|
|
2015-03-25 09:37:34 +01:00
|
|
|
hr = IStream_Seek( cache_entry->stream, offset, STREAM_SEEK_SET, NULL );
|
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
{
|
|
|
|
*ppStm = cache_entry->stream;
|
|
|
|
IStream_AddRef( cache_entry->stream );
|
|
|
|
}
|
2000-03-19 13:42:58 +01:00
|
|
|
}
|
2015-03-25 09:37:34 +01:00
|
|
|
else
|
|
|
|
hr = OLE_E_BLANK;
|
2000-03-19 13:42:58 +01:00
|
|
|
|
2015-03-25 09:37:34 +01:00
|
|
|
return hr;
|
1999-05-08 12:55:32 +02:00
|
|
|
}
|
|
|
|
|
2015-03-25 09:37:37 +01:00
|
|
|
|
|
|
|
static HRESULT load_mf_pict( DataCacheEntry *cache_entry, IStream *stm )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
STATSTG stat;
|
|
|
|
ULARGE_INTEGER current_pos;
|
|
|
|
void *bits;
|
|
|
|
METAFILEPICT *mfpict;
|
|
|
|
HGLOBAL hmfpict;
|
|
|
|
PresentationDataHeader header;
|
|
|
|
CLIPFORMAT clipformat;
|
|
|
|
static const LARGE_INTEGER offset_zero;
|
|
|
|
ULONG read;
|
|
|
|
|
|
|
|
if (cache_entry->stream_type != pres_stream)
|
|
|
|
{
|
|
|
|
FIXME( "Unimplemented for stream type %d\n", cache_entry->stream_type );
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IStream_Stat( stm, &stat, STATFLAG_NONAME );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
hr = read_clipformat( stm, &clipformat );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
hr = IStream_Read( stm, &header, sizeof(header), &read );
|
|
|
|
if (hr != S_OK || read != sizeof(header)) return E_FAIL;
|
|
|
|
|
|
|
|
hr = IStream_Seek( stm, offset_zero, STREAM_SEEK_CUR, ¤t_pos );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
stat.cbSize.QuadPart -= current_pos.QuadPart;
|
|
|
|
|
|
|
|
hmfpict = GlobalAlloc( GMEM_MOVEABLE, sizeof(METAFILEPICT) );
|
|
|
|
if (!hmfpict) return E_OUTOFMEMORY;
|
|
|
|
mfpict = GlobalLock( hmfpict );
|
|
|
|
|
|
|
|
bits = HeapAlloc( GetProcessHeap(), 0, stat.cbSize.u.LowPart);
|
|
|
|
if (!bits)
|
|
|
|
{
|
|
|
|
GlobalFree( hmfpict );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IStream_Read( stm, bits, stat.cbSize.u.LowPart, &read );
|
|
|
|
if (hr != S_OK || read != stat.cbSize.u.LowPart) hr = E_FAIL;
|
|
|
|
|
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
{
|
|
|
|
/* FIXME: get this from the stream */
|
|
|
|
mfpict->mm = MM_ANISOTROPIC;
|
|
|
|
mfpict->xExt = header.dwObjectExtentX;
|
|
|
|
mfpict->yExt = header.dwObjectExtentY;
|
|
|
|
mfpict->hMF = SetMetaFileBitsEx( stat.cbSize.u.LowPart, bits );
|
|
|
|
if (!mfpict->hMF)
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock( hmfpict );
|
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
{
|
|
|
|
cache_entry->stgmedium.tymed = TYMED_MFPICT;
|
|
|
|
cache_entry->stgmedium.u.hMetaFilePict = hmfpict;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GlobalFree( hmfpict );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, bits );
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-03-25 09:37:38 +01:00
|
|
|
static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
STATSTG stat;
|
|
|
|
void *dib;
|
|
|
|
HGLOBAL hglobal;
|
2017-05-18 12:07:06 +02:00
|
|
|
ULONG read, info_size, bi_size;
|
|
|
|
BITMAPFILEHEADER file;
|
2017-05-18 12:07:07 +02:00
|
|
|
BITMAPINFOHEADER *info;
|
2015-03-25 09:37:38 +01:00
|
|
|
|
|
|
|
if (cache_entry->stream_type != contents_stream)
|
|
|
|
{
|
|
|
|
FIXME( "Unimplemented for stream type %d\n", cache_entry->stream_type );
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IStream_Stat( stm, &stat, STATFLAG_NONAME );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
2017-05-18 12:07:06 +02:00
|
|
|
if (stat.cbSize.QuadPart < sizeof(file) + sizeof(DWORD)) return E_FAIL;
|
|
|
|
hr = IStream_Read( stm, &file, sizeof(file), &read );
|
|
|
|
if (hr != S_OK || read != sizeof(file)) return E_FAIL;
|
|
|
|
stat.cbSize.QuadPart -= sizeof(file);
|
|
|
|
|
2015-03-25 09:37:38 +01:00
|
|
|
hglobal = GlobalAlloc( GMEM_MOVEABLE, stat.cbSize.u.LowPart );
|
|
|
|
if (!hglobal) return E_OUTOFMEMORY;
|
|
|
|
dib = GlobalLock( hglobal );
|
|
|
|
|
2017-05-18 12:07:06 +02:00
|
|
|
hr = IStream_Read( stm, dib, sizeof(DWORD), &read );
|
|
|
|
if (hr != S_OK || read != sizeof(DWORD)) goto fail;
|
|
|
|
bi_size = *(DWORD *)dib;
|
|
|
|
if (stat.cbSize.QuadPart < bi_size) goto fail;
|
|
|
|
|
|
|
|
hr = IStream_Read( stm, (char *)dib + sizeof(DWORD), bi_size - sizeof(DWORD), &read );
|
|
|
|
if (hr != S_OK || read != bi_size - sizeof(DWORD)) goto fail;
|
2015-03-25 09:37:38 +01:00
|
|
|
|
2017-05-18 12:07:06 +02:00
|
|
|
info_size = bitmap_info_size( dib, DIB_RGB_COLORS );
|
|
|
|
if (stat.cbSize.QuadPart < info_size) goto fail;
|
|
|
|
if (info_size > bi_size)
|
2015-03-25 09:37:38 +01:00
|
|
|
{
|
2017-05-18 12:07:06 +02:00
|
|
|
hr = IStream_Read( stm, (char *)dib + bi_size, info_size - bi_size, &read );
|
|
|
|
if (hr != S_OK || read != info_size - bi_size) goto fail;
|
2015-03-25 09:37:38 +01:00
|
|
|
}
|
2017-05-18 12:07:06 +02:00
|
|
|
stat.cbSize.QuadPart -= info_size;
|
|
|
|
|
|
|
|
if (file.bfOffBits)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER skip;
|
|
|
|
|
|
|
|
skip.QuadPart = file.bfOffBits - sizeof(file) - info_size;
|
|
|
|
if (stat.cbSize.QuadPart < skip.QuadPart) goto fail;
|
|
|
|
hr = IStream_Seek( stm, skip, STREAM_SEEK_CUR, NULL );
|
|
|
|
if (hr != S_OK) goto fail;
|
|
|
|
stat.cbSize.QuadPart -= skip.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IStream_Read( stm, (char *)dib + info_size, stat.cbSize.u.LowPart, &read );
|
|
|
|
if (hr != S_OK || read != stat.cbSize.QuadPart) goto fail;
|
|
|
|
|
2017-05-18 12:07:07 +02:00
|
|
|
if (bi_size >= sizeof(*info))
|
|
|
|
{
|
|
|
|
info = (BITMAPINFOHEADER *)dib;
|
|
|
|
if (info->biXPelsPerMeter == 0 || info->biYPelsPerMeter == 0)
|
|
|
|
{
|
|
|
|
HDC hdc = GetDC( 0 );
|
|
|
|
info->biXPelsPerMeter = MulDiv( GetDeviceCaps( hdc, LOGPIXELSX ), 10000, 254 );
|
|
|
|
info->biYPelsPerMeter = MulDiv( GetDeviceCaps( hdc, LOGPIXELSY ), 10000, 254 );
|
|
|
|
ReleaseDC( 0, hdc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 12:07:06 +02:00
|
|
|
GlobalUnlock( hglobal );
|
2015-03-25 09:37:38 +01:00
|
|
|
|
|
|
|
cache_entry->stgmedium.tymed = TYMED_HGLOBAL;
|
|
|
|
cache_entry->stgmedium.u.hGlobal = hglobal;
|
|
|
|
|
|
|
|
return S_OK;
|
2017-05-18 12:07:06 +02:00
|
|
|
|
|
|
|
fail:
|
|
|
|
GlobalUnlock( hglobal );
|
|
|
|
GlobalFree( hglobal );
|
|
|
|
return E_FAIL;
|
|
|
|
|
2015-03-25 09:37:38 +01:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
2006-12-01 16:02:11 +01:00
|
|
|
* DataCacheEntry_LoadData
|
1999-05-08 12:55:32 +02:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This method will read information for the requested presentation
|
1999-05-08 12:55:32 +02:00
|
|
|
* into the given structure.
|
|
|
|
*
|
|
|
|
* Param:
|
2006-12-01 16:02:11 +01:00
|
|
|
* This - The entry to load the data from.
|
1999-05-08 12:55:32 +02:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* This method returns a metafile handle if it is successful.
|
|
|
|
* it will return 0 if not.
|
|
|
|
*/
|
2010-11-01 13:06:27 +01:00
|
|
|
static HRESULT DataCacheEntry_LoadData(DataCacheEntry *cache_entry)
|
1999-05-08 12:55:32 +02:00
|
|
|
{
|
2015-03-25 09:37:37 +01:00
|
|
|
HRESULT hr;
|
|
|
|
IStream *stm;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2015-03-25 09:37:37 +01:00
|
|
|
hr = DataCacheEntry_OpenPresStream( cache_entry, &stm );
|
|
|
|
if (FAILED(hr)) return hr;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2015-03-25 09:37:37 +01:00
|
|
|
switch (cache_entry->fmtetc.cfFormat)
|
|
|
|
{
|
|
|
|
case CF_METAFILEPICT:
|
|
|
|
hr = load_mf_pict( cache_entry, stm );
|
|
|
|
break;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2015-03-25 09:37:38 +01:00
|
|
|
case CF_DIB:
|
|
|
|
hr = load_dib( cache_entry, stm );
|
|
|
|
break;
|
|
|
|
|
2015-03-25 09:37:37 +01:00
|
|
|
default:
|
|
|
|
FIXME( "Unimplemented clip format %x\n", cache_entry->fmtetc.cfFormat );
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
}
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2015-03-25 09:37:37 +01:00
|
|
|
IStream_Release( stm );
|
|
|
|
return hr;
|
1999-05-08 12:55:32 +02:00
|
|
|
}
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
static HRESULT DataCacheEntry_CreateStream(DataCacheEntry *cache_entry,
|
2006-12-01 16:04:04 +01:00
|
|
|
IStorage *storage, IStream **stream)
|
|
|
|
{
|
|
|
|
WCHAR wszName[] = {2,'O','l','e','P','r','e','s',
|
2010-11-01 13:06:27 +01:00
|
|
|
'0' + (cache_entry->stream_number / 100) % 10,
|
|
|
|
'0' + (cache_entry->stream_number / 10) % 10,
|
|
|
|
'0' + cache_entry->stream_number % 10, 0};
|
2006-12-01 16:04:04 +01:00
|
|
|
|
|
|
|
/* FIXME: cache the created stream in This? */
|
2010-07-21 12:03:35 +02:00
|
|
|
return IStorage_CreateStream(storage, wszName,
|
|
|
|
STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
|
|
|
|
0, 0, stream);
|
2006-12-01 16:04:04 +01:00
|
|
|
}
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
static HRESULT DataCacheEntry_Save(DataCacheEntry *cache_entry, IStorage *storage,
|
2006-12-01 16:04:04 +01:00
|
|
|
BOOL same_as_load)
|
|
|
|
{
|
|
|
|
PresentationDataHeader header;
|
|
|
|
HRESULT hr;
|
|
|
|
IStream *pres_stream;
|
|
|
|
void *data = NULL;
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
TRACE("stream_number = %d, fmtetc = %s\n", cache_entry->stream_number, debugstr_formatetc(&cache_entry->fmtetc));
|
2006-12-01 16:04:04 +01:00
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
hr = DataCacheEntry_CreateStream(cache_entry, storage, &pres_stream);
|
2006-12-01 16:04:04 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2017-10-31 14:23:32 +01:00
|
|
|
hr = write_clipformat(pres_stream, cache_entry->fmtetc.cfFormat);
|
2006-12-18 00:44:18 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
if (cache_entry->fmtetc.ptd)
|
2006-12-01 16:04:04 +01:00
|
|
|
FIXME("ptd not serialized\n");
|
2017-11-22 09:30:51 +01:00
|
|
|
header.tdSize = sizeof(header.tdSize);
|
2010-11-01 13:06:27 +01:00
|
|
|
header.dvAspect = cache_entry->fmtetc.dwAspect;
|
|
|
|
header.lindex = cache_entry->fmtetc.lindex;
|
2017-06-06 12:46:48 +02:00
|
|
|
header.advf = cache_entry->advise_flags;
|
2006-12-01 16:04:04 +01:00
|
|
|
header.unknown7 = 0;
|
|
|
|
header.dwObjectExtentX = 0;
|
|
|
|
header.dwObjectExtentY = 0;
|
|
|
|
header.dwSize = 0;
|
|
|
|
|
|
|
|
/* size the data */
|
2017-10-31 14:23:32 +01:00
|
|
|
switch (cache_entry->fmtetc.cfFormat)
|
2006-12-01 16:04:04 +01:00
|
|
|
{
|
|
|
|
case CF_METAFILEPICT:
|
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
if (cache_entry->stgmedium.tymed != TYMED_NULL)
|
2006-12-01 16:04:04 +01:00
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
const METAFILEPICT *mfpict = GlobalLock(cache_entry->stgmedium.u.hMetaFilePict);
|
2006-12-01 16:04:04 +01:00
|
|
|
if (!mfpict)
|
|
|
|
{
|
|
|
|
IStream_Release(pres_stream);
|
|
|
|
return DV_E_STGMEDIUM;
|
|
|
|
}
|
|
|
|
header.dwObjectExtentX = mfpict->xExt;
|
|
|
|
header.dwObjectExtentY = mfpict->yExt;
|
|
|
|
header.dwSize = GetMetaFileBitsEx(mfpict->hMF, 0, NULL);
|
2010-11-01 13:06:27 +01:00
|
|
|
GlobalUnlock(cache_entry->stgmedium.u.hMetaFilePict);
|
2006-12-01 16:04:04 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-28 19:01:06 +01:00
|
|
|
case CF_DIB:
|
|
|
|
{
|
|
|
|
header.dwSize = GlobalSize(cache_entry->stgmedium.u.hGlobal);
|
|
|
|
if (header.dwSize)
|
|
|
|
{
|
|
|
|
const BITMAPINFO *bmi = GlobalLock(cache_entry->stgmedium.u.hGlobal);
|
|
|
|
/* Size in units of 0.01mm (ie. MM_HIMETRIC) */
|
|
|
|
if (bmi->bmiHeader.biXPelsPerMeter != 0 && bmi->bmiHeader.biYPelsPerMeter != 0)
|
|
|
|
{
|
|
|
|
header.dwObjectExtentX = MulDiv( bmi->bmiHeader.biWidth, 100000, bmi->bmiHeader.biXPelsPerMeter );
|
|
|
|
header.dwObjectExtentY = MulDiv( bmi->bmiHeader.biHeight, 100000, bmi->bmiHeader.biYPelsPerMeter );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
header.dwObjectExtentX = MulDiv( bmi->bmiHeader.biWidth, 2540, GetDeviceCaps(hdc, LOGPIXELSX) );
|
|
|
|
header.dwObjectExtentY = MulDiv( bmi->bmiHeader.biHeight, 2540, GetDeviceCaps(hdc, LOGPIXELSY) );
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
}
|
|
|
|
GlobalUnlock(cache_entry->stgmedium.u.hGlobal);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-12-01 16:04:04 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the header.
|
|
|
|
*/
|
|
|
|
hr = IStream_Write(pres_stream, &header, sizeof(PresentationDataHeader),
|
|
|
|
NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IStream_Release(pres_stream);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the data */
|
2017-10-31 14:23:32 +01:00
|
|
|
switch (cache_entry->fmtetc.cfFormat)
|
2006-12-01 16:04:04 +01:00
|
|
|
{
|
|
|
|
case CF_METAFILEPICT:
|
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
if (cache_entry->stgmedium.tymed != TYMED_NULL)
|
2006-12-01 16:04:04 +01:00
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
const METAFILEPICT *mfpict = GlobalLock(cache_entry->stgmedium.u.hMetaFilePict);
|
2006-12-01 16:04:04 +01:00
|
|
|
if (!mfpict)
|
|
|
|
{
|
|
|
|
IStream_Release(pres_stream);
|
|
|
|
return DV_E_STGMEDIUM;
|
|
|
|
}
|
2017-11-28 19:01:06 +01:00
|
|
|
if (header.dwSize)
|
|
|
|
{
|
|
|
|
data = HeapAlloc(GetProcessHeap(), 0, header.dwSize);
|
|
|
|
GetMetaFileBitsEx(mfpict->hMF, header.dwSize, data);
|
|
|
|
GlobalUnlock(cache_entry->stgmedium.u.hMetaFilePict);
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
hr = IStream_Write(pres_stream, data, header.dwSize, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
}
|
|
|
|
}
|
2006-12-01 16:04:04 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-28 19:01:06 +01:00
|
|
|
case CF_DIB:
|
|
|
|
{
|
|
|
|
data = GlobalLock(cache_entry->stgmedium.u.hGlobal);
|
|
|
|
if (header.dwSize)
|
|
|
|
hr = IStream_Write(pres_stream, data, header.dwSize, NULL);
|
|
|
|
GlobalUnlock(cache_entry->stgmedium.u.hGlobal);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-01 16:04:04 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
IStream_Release(pres_stream);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2006-12-01 16:02:26 +01:00
|
|
|
/* helper for copying STGMEDIUM of type bitmap, MF, EMF or HGLOBAL.
|
|
|
|
* does no checking of whether src_stgm has a supported tymed, so this should be
|
|
|
|
* done in the caller */
|
|
|
|
static HRESULT copy_stg_medium(CLIPFORMAT cf, STGMEDIUM *dest_stgm,
|
|
|
|
const STGMEDIUM *src_stgm)
|
|
|
|
{
|
|
|
|
if (src_stgm->tymed == TYMED_MFPICT)
|
|
|
|
{
|
|
|
|
const METAFILEPICT *src_mfpict = GlobalLock(src_stgm->u.hMetaFilePict);
|
|
|
|
METAFILEPICT *dest_mfpict;
|
|
|
|
|
|
|
|
if (!src_mfpict)
|
|
|
|
return DV_E_STGMEDIUM;
|
|
|
|
dest_stgm->u.hMetaFilePict = GlobalAlloc(GMEM_MOVEABLE, sizeof(METAFILEPICT));
|
|
|
|
dest_mfpict = GlobalLock(dest_stgm->u.hMetaFilePict);
|
|
|
|
if (!dest_mfpict)
|
|
|
|
{
|
|
|
|
GlobalUnlock(src_stgm->u.hMetaFilePict);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
*dest_mfpict = *src_mfpict;
|
|
|
|
dest_mfpict->hMF = CopyMetaFileW(src_mfpict->hMF, NULL);
|
|
|
|
GlobalUnlock(src_stgm->u.hMetaFilePict);
|
|
|
|
GlobalUnlock(dest_stgm->u.hMetaFilePict);
|
|
|
|
}
|
|
|
|
else if (src_stgm->tymed != TYMED_NULL)
|
|
|
|
{
|
|
|
|
dest_stgm->u.hGlobal = OleDuplicateData(src_stgm->u.hGlobal, cf,
|
|
|
|
GMEM_MOVEABLE);
|
|
|
|
if (!dest_stgm->u.hGlobal)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
dest_stgm->tymed = src_stgm->tymed;
|
|
|
|
dest_stgm->pUnkForRelease = src_stgm->pUnkForRelease;
|
|
|
|
if (dest_stgm->pUnkForRelease)
|
|
|
|
IUnknown_AddRef(dest_stgm->pUnkForRelease);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-29 10:28:45 +01:00
|
|
|
static HRESULT synthesize_dib( HBITMAP bm, STGMEDIUM *med )
|
2017-05-23 14:11:42 +02:00
|
|
|
{
|
|
|
|
HDC hdc = GetDC( 0 );
|
|
|
|
BITMAPINFOHEADER header;
|
|
|
|
BITMAPINFO *bmi;
|
2017-11-29 10:28:45 +01:00
|
|
|
HRESULT hr = E_FAIL;
|
2017-05-23 14:11:42 +02:00
|
|
|
DWORD header_size;
|
|
|
|
|
|
|
|
memset( &header, 0, sizeof(header) );
|
|
|
|
header.biSize = sizeof(header);
|
|
|
|
if (!GetDIBits( hdc, bm, 0, 0, NULL, (BITMAPINFO *)&header, DIB_RGB_COLORS )) goto done;
|
|
|
|
|
|
|
|
header_size = bitmap_info_size( (BITMAPINFO *)&header, DIB_RGB_COLORS );
|
2017-11-29 10:28:45 +01:00
|
|
|
if (!(med->u.hGlobal = GlobalAlloc( GMEM_MOVEABLE, header_size + header.biSizeImage ))) goto done;
|
|
|
|
bmi = GlobalLock( med->u.hGlobal );
|
2017-05-23 14:11:42 +02:00
|
|
|
memset( bmi, 0, header_size );
|
|
|
|
memcpy( bmi, &header, header.biSize );
|
|
|
|
GetDIBits( hdc, bm, 0, abs(header.biHeight), (char *)bmi + header_size, bmi, DIB_RGB_COLORS );
|
2017-11-29 10:28:45 +01:00
|
|
|
GlobalUnlock( med->u.hGlobal );
|
|
|
|
med->tymed = TYMED_HGLOBAL;
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
hr = S_OK;
|
2017-05-23 14:11:42 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
ReleaseDC( 0, hdc );
|
2017-11-29 10:28:45 +01:00
|
|
|
return hr;
|
2017-05-23 14:11:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 10:28:45 +01:00
|
|
|
static HRESULT synthesize_bitmap( HGLOBAL dib, STGMEDIUM *med )
|
2017-05-23 14:11:42 +02:00
|
|
|
{
|
2017-11-29 10:28:45 +01:00
|
|
|
HRESULT hr = E_FAIL;
|
2017-05-23 14:11:42 +02:00
|
|
|
BITMAPINFO *bmi;
|
|
|
|
HDC hdc = GetDC( 0 );
|
|
|
|
|
|
|
|
if ((bmi = GlobalLock( dib )))
|
|
|
|
{
|
|
|
|
/* FIXME: validate data size */
|
2017-11-29 10:28:45 +01:00
|
|
|
med->u.hBitmap = CreateDIBitmap( hdc, &bmi->bmiHeader, CBM_INIT,
|
|
|
|
(char *)bmi + bitmap_info_size( bmi, DIB_RGB_COLORS ),
|
|
|
|
bmi, DIB_RGB_COLORS );
|
2017-05-23 14:11:42 +02:00
|
|
|
GlobalUnlock( dib );
|
2017-11-29 10:28:45 +01:00
|
|
|
med->tymed = TYMED_GDI;
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
hr = S_OK;
|
2017-05-23 14:11:42 +02:00
|
|
|
}
|
|
|
|
ReleaseDC( 0, hdc );
|
2017-11-29 10:28:45 +01:00
|
|
|
return hr;
|
2017-05-23 14:11:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 10:28:45 +01:00
|
|
|
static HRESULT synthesize_emf( HMETAFILEPICT data, STGMEDIUM *med )
|
2017-10-31 14:23:33 +01:00
|
|
|
{
|
|
|
|
METAFILEPICT *pict;
|
2017-11-29 10:28:45 +01:00
|
|
|
HRESULT hr = E_FAIL;
|
2017-10-31 14:23:33 +01:00
|
|
|
UINT size;
|
|
|
|
void *bits;
|
|
|
|
|
2017-11-29 10:28:45 +01:00
|
|
|
if (!(pict = GlobalLock( data ))) return hr;
|
2017-10-31 14:23:33 +01:00
|
|
|
|
|
|
|
size = GetMetaFileBitsEx( pict->hMF, 0, NULL );
|
|
|
|
if ((bits = HeapAlloc( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
GetMetaFileBitsEx( pict->hMF, size, bits );
|
2017-11-29 10:28:45 +01:00
|
|
|
med->u.hEnhMetaFile = SetWinMetaFileBits( size, bits, NULL, pict );
|
2017-10-31 14:23:33 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, bits );
|
2017-11-29 10:28:45 +01:00
|
|
|
med->tymed = TYMED_ENHMF;
|
|
|
|
med->pUnkForRelease = NULL;
|
|
|
|
hr = S_OK;
|
2017-10-31 14:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock( data );
|
2017-11-29 10:28:45 +01:00
|
|
|
return hr;
|
2017-10-31 14:23:33 +01:00
|
|
|
}
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
static HRESULT DataCacheEntry_SetData(DataCacheEntry *cache_entry,
|
2006-12-02 19:16:53 +01:00
|
|
|
const FORMATETC *formatetc,
|
2017-05-23 14:11:42 +02:00
|
|
|
STGMEDIUM *stgmedium,
|
2006-12-02 19:16:53 +01:00
|
|
|
BOOL fRelease)
|
2006-12-01 16:02:26 +01:00
|
|
|
{
|
2017-10-31 14:23:33 +01:00
|
|
|
STGMEDIUM copy;
|
2017-11-29 10:28:45 +01:00
|
|
|
HRESULT hr;
|
2017-05-23 14:11:42 +02:00
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
if ((!cache_entry->fmtetc.cfFormat && !formatetc->cfFormat) ||
|
|
|
|
(cache_entry->fmtetc.tymed == TYMED_NULL && formatetc->tymed == TYMED_NULL) ||
|
2006-12-02 19:16:53 +01:00
|
|
|
stgmedium->tymed == TYMED_NULL)
|
|
|
|
{
|
|
|
|
WARN("invalid formatetc\n");
|
|
|
|
return DV_E_FORMATETC;
|
|
|
|
}
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
cache_entry->dirty = TRUE;
|
|
|
|
ReleaseStgMedium(&cache_entry->stgmedium);
|
2017-05-23 14:11:42 +02:00
|
|
|
|
|
|
|
if (formatetc->cfFormat == CF_BITMAP)
|
|
|
|
{
|
2017-11-29 10:28:45 +01:00
|
|
|
hr = synthesize_dib( stgmedium->u.hBitmap, © );
|
|
|
|
if (FAILED(hr)) return hr;
|
2017-10-31 14:23:33 +01:00
|
|
|
if (fRelease) ReleaseStgMedium(stgmedium);
|
|
|
|
stgmedium = ©
|
|
|
|
fRelease = TRUE;
|
|
|
|
}
|
|
|
|
else if (formatetc->cfFormat == CF_METAFILEPICT && cache_entry->fmtetc.cfFormat == CF_ENHMETAFILE)
|
|
|
|
{
|
2017-11-29 10:28:45 +01:00
|
|
|
hr = synthesize_emf( stgmedium->u.hMetaFilePict, © );
|
|
|
|
if (FAILED(hr)) return hr;
|
2017-05-23 14:11:42 +02:00
|
|
|
if (fRelease) ReleaseStgMedium(stgmedium);
|
2017-10-31 14:23:33 +01:00
|
|
|
stgmedium = ©
|
2017-05-23 14:11:42 +02:00
|
|
|
fRelease = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-12-01 16:02:26 +01:00
|
|
|
if (fRelease)
|
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
cache_entry->stgmedium = *stgmedium;
|
2006-12-01 16:02:26 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
2017-10-31 14:23:32 +01:00
|
|
|
return copy_stg_medium(cache_entry->fmtetc.cfFormat, &cache_entry->stgmedium, stgmedium);
|
2006-12-01 16:02:26 +01:00
|
|
|
}
|
|
|
|
|
2017-05-23 14:11:42 +02:00
|
|
|
static HRESULT DataCacheEntry_GetData(DataCacheEntry *cache_entry, FORMATETC *fmt, STGMEDIUM *stgmedium)
|
2006-12-04 16:51:20 +01:00
|
|
|
{
|
2017-05-23 14:11:39 +02:00
|
|
|
if (cache_entry->stgmedium.tymed == TYMED_NULL && cache_entry->stream)
|
2006-12-04 16:51:20 +01:00
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
HRESULT hr = DataCacheEntry_LoadData(cache_entry);
|
2006-12-04 16:51:20 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
2010-11-01 13:06:27 +01:00
|
|
|
if (cache_entry->stgmedium.tymed == TYMED_NULL)
|
2006-12-04 16:51:20 +01:00
|
|
|
return OLE_E_BLANK;
|
2017-05-23 14:11:42 +02:00
|
|
|
|
|
|
|
if (fmt->cfFormat == CF_BITMAP)
|
2017-11-29 10:28:45 +01:00
|
|
|
return synthesize_bitmap( cache_entry->stgmedium.u.hGlobal, stgmedium );
|
|
|
|
|
2017-10-31 14:23:32 +01:00
|
|
|
return copy_stg_medium(cache_entry->fmtetc.cfFormat, stgmedium, &cache_entry->stgmedium);
|
2006-12-04 16:51:20 +01:00
|
|
|
}
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
static inline HRESULT DataCacheEntry_DiscardData(DataCacheEntry *cache_entry)
|
2006-12-04 16:51:05 +01:00
|
|
|
{
|
2010-11-01 13:06:27 +01:00
|
|
|
ReleaseStgMedium(&cache_entry->stgmedium);
|
2006-12-04 16:51:05 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-01 13:06:27 +01:00
|
|
|
static inline void DataCacheEntry_HandsOffStorage(DataCacheEntry *cache_entry)
|
2006-12-04 16:51:25 +01:00
|
|
|
{
|
2015-03-25 09:37:34 +01:00
|
|
|
if (cache_entry->stream)
|
2006-12-04 16:51:25 +01:00
|
|
|
{
|
2015-03-25 09:37:34 +01:00
|
|
|
IStream_Release(cache_entry->stream);
|
|
|
|
cache_entry->stream = NULL;
|
2006-12-04 16:51:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 12:46:48 +02:00
|
|
|
static inline DWORD tymed_from_cf( DWORD cf )
|
|
|
|
{
|
|
|
|
switch( cf )
|
|
|
|
{
|
|
|
|
case CF_BITMAP: return TYMED_GDI;
|
|
|
|
case CF_METAFILEPICT: return TYMED_MFPICT;
|
|
|
|
case CF_ENHMETAFILE: return TYMED_ENHMF;
|
|
|
|
case CF_DIB:
|
|
|
|
default: return TYMED_HGLOBAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 12:46:51 +02:00
|
|
|
/****************************************************************
|
|
|
|
* create_automatic_entry
|
|
|
|
*
|
|
|
|
* Creates an appropriate cache entry for one of the CLSID_Picture_
|
|
|
|
* classes. The connection id of the entry is one. Any pre-existing
|
|
|
|
* automatic entry is re-assigned a new connection id, and moved to
|
|
|
|
* the end of the list.
|
|
|
|
*/
|
|
|
|
static HRESULT create_automatic_entry(DataCache *cache, const CLSID *clsid)
|
|
|
|
{
|
|
|
|
static const struct data
|
|
|
|
{
|
|
|
|
const CLSID *clsid;
|
|
|
|
FORMATETC fmt;
|
|
|
|
} data[] =
|
|
|
|
{
|
|
|
|
{ &CLSID_Picture_Dib, { CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL } },
|
|
|
|
{ &CLSID_Picture_Metafile, { CF_METAFILEPICT, 0, DVASPECT_CONTENT, -1, TYMED_MFPICT } },
|
|
|
|
{ &CLSID_Picture_EnhMetafile, { CF_ENHMETAFILE, 0, DVASPECT_CONTENT, -1, TYMED_ENHMF } },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
const struct data *ptr = data;
|
|
|
|
struct list *head;
|
|
|
|
DataCacheEntry *entry;
|
|
|
|
|
|
|
|
if (IsEqualCLSID( &cache->clsid, clsid )) return S_OK;
|
|
|
|
|
|
|
|
/* move and reassign any pre-existing automatic entry */
|
|
|
|
if ((head = list_head( &cache->cache_list )))
|
|
|
|
{
|
|
|
|
entry = LIST_ENTRY( head, DataCacheEntry, entry );
|
|
|
|
if (entry->id == 1)
|
|
|
|
{
|
|
|
|
list_remove( &entry->entry );
|
|
|
|
entry->id = cache->last_cache_id++;
|
|
|
|
list_add_tail( &cache->cache_list, &entry->entry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ptr->clsid)
|
|
|
|
{
|
|
|
|
if (IsEqualCLSID( clsid, ptr->clsid ))
|
|
|
|
return DataCache_CreateEntry( cache, &ptr->fmt, 0, TRUE, NULL );
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/*********************************************************
|
|
|
|
* Method implementation for the non delegating IUnknown
|
|
|
|
* part of the DataCache class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/************************************************************************
|
1999-05-08 12:55:32 +02:00
|
|
|
* DataCache_NDIUnknown_QueryInterface (IUnknown)
|
1999-05-02 11:27:08 +02:00
|
|
|
*
|
2010-11-01 14:11:37 +01:00
|
|
|
* This version of QueryInterface will not delegate its implementation
|
1999-05-02 11:27:08 +02:00
|
|
|
* to the outer unknown.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_NDIUnknown_QueryInterface(
|
|
|
|
IUnknown* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
DataCache *this = impl_from_IUnknown(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2010-07-21 12:19:51 +02:00
|
|
|
if ( ppvObject==0 )
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
*ppvObject = 0;
|
|
|
|
|
2010-07-21 12:19:51 +02:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid))
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2017-10-05 14:11:06 +02:00
|
|
|
if (this->outer_unk == iface) /* non-aggregated, return IUnknown from IOleCache2 */
|
|
|
|
*ppvObject = &this->IOleCache2_iface;
|
|
|
|
else
|
|
|
|
*ppvObject = iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
2010-07-21 12:19:51 +02:00
|
|
|
else if (IsEqualIID(&IID_IDataObject, riid))
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
*ppvObject = &this->IDataObject_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
2010-07-21 12:19:51 +02:00
|
|
|
else if ( IsEqualIID(&IID_IPersistStorage, riid) ||
|
|
|
|
IsEqualIID(&IID_IPersist, riid) )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
*ppvObject = &this->IPersistStorage_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
2010-07-21 12:19:51 +02:00
|
|
|
else if ( IsEqualIID(&IID_IViewObject, riid) ||
|
|
|
|
IsEqualIID(&IID_IViewObject2, riid) )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
*ppvObject = &this->IViewObject2_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
2010-07-21 12:19:51 +02:00
|
|
|
else if ( IsEqualIID(&IID_IOleCache, riid) ||
|
|
|
|
IsEqualIID(&IID_IOleCache2, riid) )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
*ppvObject = &this->IOleCache2_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
2010-07-21 12:19:51 +02:00
|
|
|
else if ( IsEqualIID(&IID_IOleCacheControl, riid) )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
*ppvObject = &this->IOleCacheControl_iface;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
{
|
2000-07-16 17:44:22 +02:00
|
|
|
WARN( "() : asking for unsupported interface %s\n", debugstr_guid(riid));
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppvObject);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_NDIUnknown_AddRef (IUnknown)
|
|
|
|
*
|
2010-11-01 14:11:37 +01:00
|
|
|
* This version of QueryInterface will not delegate its implementation
|
1999-05-02 11:27:08 +02:00
|
|
|
* to the outer unknown.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_NDIUnknown_AddRef(
|
1999-05-02 11:27:08 +02:00
|
|
|
IUnknown* iface)
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
DataCache *this = impl_from_IUnknown(iface);
|
2004-09-24 03:16:53 +02:00
|
|
|
return InterlockedIncrement(&this->ref);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_NDIUnknown_Release (IUnknown)
|
|
|
|
*
|
2010-11-01 14:11:37 +01:00
|
|
|
* This version of QueryInterface will not delegate its implementation
|
1999-05-02 11:27:08 +02:00
|
|
|
* to the outer unknown.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_NDIUnknown_Release(
|
1999-05-02 11:27:08 +02:00
|
|
|
IUnknown* iface)
|
|
|
|
{
|
2010-12-23 02:05:04 +01:00
|
|
|
DataCache *this = impl_from_IUnknown(iface);
|
2004-09-24 03:16:53 +02:00
|
|
|
ULONG ref;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
ref = InterlockedDecrement(&this->ref);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
if (ref == 0) DataCache_Destroy(this);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return ref;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* Method implementation for the IDataObject
|
|
|
|
* part of the DataCache class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IDataObject_QueryInterface (IUnknown)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_IDataObject_QueryInterface(
|
|
|
|
IDataObject* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IDataObject(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_QueryInterface(this->outer_unk, riid, ppvObject);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IDataObject_AddRef (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IDataObject_AddRef(
|
1999-05-02 11:27:08 +02:00
|
|
|
IDataObject* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IDataObject(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_AddRef(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IDataObject_Release (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IDataObject_Release(
|
1999-05-02 11:27:08 +02:00
|
|
|
IDataObject* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IDataObject(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_Release(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2000-05-24 01:34:40 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_GetData
|
|
|
|
*
|
|
|
|
* Get Data from a source dataobject using format pformatetcIn->cfFormat
|
|
|
|
*/
|
1999-05-02 11:27:08 +02:00
|
|
|
static HRESULT WINAPI DataCache_GetData(
|
|
|
|
IDataObject* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
LPFORMATETC pformatetcIn,
|
1999-05-02 11:27:08 +02:00
|
|
|
STGMEDIUM* pmedium)
|
|
|
|
{
|
2006-12-04 16:51:20 +01:00
|
|
|
DataCache *This = impl_from_IDataObject(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
2000-05-24 01:34:40 +02:00
|
|
|
|
2017-09-20 14:45:37 +02:00
|
|
|
TRACE("(%p, %s, %p)\n", iface, debugstr_formatetc(pformatetcIn), pmedium);
|
|
|
|
|
2006-12-04 16:51:20 +01:00
|
|
|
memset(pmedium, 0, sizeof(*pmedium));
|
2000-05-24 01:34:40 +02:00
|
|
|
|
2006-12-04 16:51:20 +01:00
|
|
|
cache_entry = DataCache_GetEntryForFormatEtc(This, pformatetcIn);
|
|
|
|
if (!cache_entry)
|
|
|
|
return OLE_E_BLANK;
|
2000-05-24 01:34:40 +02:00
|
|
|
|
2017-05-23 14:11:42 +02:00
|
|
|
return DataCacheEntry_GetData(cache_entry, pformatetcIn, pmedium);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_GetDataHere(
|
2002-06-01 01:06:46 +02:00
|
|
|
IDataObject* iface,
|
1999-05-02 11:27:08 +02:00
|
|
|
LPFORMATETC pformatetc,
|
|
|
|
STGMEDIUM* pmedium)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("stub\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2015-03-25 09:37:41 +01:00
|
|
|
static HRESULT WINAPI DataCache_QueryGetData( IDataObject *iface, FORMATETC *fmt )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2015-03-25 09:37:41 +01:00
|
|
|
DataCache *This = impl_from_IDataObject( iface );
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
|
|
|
|
TRACE( "(%p)->(%s)\n", iface, debugstr_formatetc( fmt ) );
|
|
|
|
cache_entry = DataCache_GetEntryForFormatEtc( This, fmt );
|
|
|
|
|
|
|
|
return cache_entry ? S_OK : S_FALSE;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_EnumFormatEtc (IDataObject)
|
|
|
|
*
|
|
|
|
* The data cache doesn't implement this method.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_GetCanonicalFormatEtc(
|
2002-06-01 01:06:46 +02:00
|
|
|
IDataObject* iface,
|
|
|
|
LPFORMATETC pformatectIn,
|
1999-05-02 11:27:08 +02:00
|
|
|
LPFORMATETC pformatetcOut)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IDataObject_SetData (IDataObject)
|
|
|
|
*
|
|
|
|
* This method is delegated to the IOleCache2 implementation.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_IDataObject_SetData(
|
|
|
|
IDataObject* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
LPFORMATETC pformatetc,
|
|
|
|
STGMEDIUM* pmedium,
|
1999-05-02 11:27:08 +02:00
|
|
|
BOOL fRelease)
|
|
|
|
{
|
|
|
|
IOleCache2* oleCache = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2004-05-21 22:52:57 +02:00
|
|
|
hres = IDataObject_QueryInterface(iface, &IID_IOleCache2, (void**)&oleCache);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
if (FAILED(hres))
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
hres = IOleCache2_SetData(oleCache, pformatetc, pmedium, fRelease);
|
|
|
|
|
|
|
|
IOleCache2_Release(oleCache);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return hres;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_EnumFormatEtc (IDataObject)
|
|
|
|
*
|
|
|
|
* The data cache doesn't implement this method.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_EnumFormatEtc(
|
2002-06-01 01:06:46 +02:00
|
|
|
IDataObject* iface,
|
1999-05-02 11:27:08 +02:00
|
|
|
DWORD dwDirection,
|
|
|
|
IEnumFORMATETC** ppenumFormatEtc)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_DAdvise (IDataObject)
|
|
|
|
*
|
|
|
|
* The data cache doesn't support connections.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_DAdvise(
|
2002-06-01 01:06:46 +02:00
|
|
|
IDataObject* iface,
|
|
|
|
FORMATETC* pformatetc,
|
|
|
|
DWORD advf,
|
|
|
|
IAdviseSink* pAdvSink,
|
1999-05-02 11:27:08 +02:00
|
|
|
DWORD* pdwConnection)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return OLE_E_ADVISENOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_DUnadvise (IDataObject)
|
|
|
|
*
|
|
|
|
* The data cache doesn't support connections.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_DUnadvise(
|
|
|
|
IDataObject* iface,
|
|
|
|
DWORD dwConnection)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return OLE_E_NOCONNECTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_EnumDAdvise (IDataObject)
|
|
|
|
*
|
|
|
|
* The data cache doesn't support connections.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_EnumDAdvise(
|
|
|
|
IDataObject* iface,
|
|
|
|
IEnumSTATDATA** ppenumAdvise)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return OLE_E_ADVISENOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* Method implementation for the IDataObject
|
|
|
|
* part of the DataCache class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IPersistStorage_QueryInterface (IUnknown)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_IPersistStorage_QueryInterface(
|
|
|
|
IPersistStorage* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IPersistStorage(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_QueryInterface(this->outer_unk, riid, ppvObject);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IPersistStorage_AddRef (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IPersistStorage_AddRef(
|
1999-05-02 11:27:08 +02:00
|
|
|
IPersistStorage* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IPersistStorage(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_AddRef(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IPersistStorage_Release (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IPersistStorage_Release(
|
1999-05-02 11:27:08 +02:00
|
|
|
IPersistStorage* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IPersistStorage(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_Release(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_GetClassID (IPersistStorage)
|
|
|
|
*
|
|
|
|
*/
|
2015-03-25 09:37:33 +01:00
|
|
|
static HRESULT WINAPI DataCache_GetClassID(IPersistStorage *iface, CLSID *clsid)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2015-03-25 09:37:33 +01:00
|
|
|
DataCache *This = impl_from_IPersistStorage( iface );
|
2006-12-01 16:01:27 +01:00
|
|
|
|
2017-06-06 12:46:51 +02:00
|
|
|
TRACE( "(%p, %p) returning %s\n", iface, clsid, debugstr_guid(&This->clsid) );
|
|
|
|
*clsid = This->clsid;
|
2006-12-01 16:01:38 +01:00
|
|
|
|
2015-03-25 09:37:33 +01:00
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IsDirty (IPersistStorage)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static HRESULT WINAPI DataCache_IsDirty(
|
1999-05-02 11:27:08 +02:00
|
|
|
IPersistStorage* iface)
|
|
|
|
{
|
2006-12-01 16:03:19 +01:00
|
|
|
DataCache *This = impl_from_IPersistStorage(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-12-01 16:03:19 +01:00
|
|
|
if (This->dirty)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
if (cache_entry->dirty)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return S_FALSE;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_InitNew (IPersistStorage)
|
|
|
|
*
|
|
|
|
* The data cache implementation of IPersistStorage_InitNew simply stores
|
|
|
|
* the storage pointer.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static HRESULT WINAPI DataCache_InitNew(
|
|
|
|
IPersistStorage* iface,
|
1999-05-02 11:27:08 +02:00
|
|
|
IStorage* pStg)
|
|
|
|
{
|
2006-12-01 16:03:19 +01:00
|
|
|
DataCache *This = impl_from_IPersistStorage(iface);
|
2017-06-06 12:46:51 +02:00
|
|
|
CLSID clsid;
|
|
|
|
HRESULT hr;
|
2006-12-01 16:03:19 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, pStg);
|
|
|
|
|
|
|
|
if (This->presentationStorage != NULL)
|
2017-06-06 12:46:53 +02:00
|
|
|
return CO_E_ALREADYINITIALIZED;
|
2006-12-01 16:03:19 +01:00
|
|
|
|
|
|
|
This->presentationStorage = pStg;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2006-12-01 16:03:19 +01:00
|
|
|
IStorage_AddRef(This->presentationStorage);
|
|
|
|
This->dirty = TRUE;
|
2017-06-06 12:46:51 +02:00
|
|
|
ReadClassStg( pStg, &clsid );
|
|
|
|
hr = create_automatic_entry( This, &clsid );
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IStorage_Release( pStg );
|
|
|
|
This->presentationStorage = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
This->clsid = clsid;
|
2006-12-01 16:03:19 +01:00
|
|
|
|
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2015-03-25 09:37:35 +01:00
|
|
|
|
2017-06-06 12:46:48 +02:00
|
|
|
static HRESULT add_cache_entry( DataCache *This, const FORMATETC *fmt, DWORD advf, IStream *stm,
|
2015-03-25 09:37:35 +01:00
|
|
|
enum stream_type type )
|
|
|
|
{
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE( "loading entry with formatetc: %s\n", debugstr_formatetc( fmt ) );
|
|
|
|
|
|
|
|
cache_entry = DataCache_GetEntryForFormatEtc( This, fmt );
|
|
|
|
if (!cache_entry)
|
2017-06-06 12:46:51 +02:00
|
|
|
hr = DataCache_CreateEntry( This, fmt, advf, FALSE, &cache_entry );
|
2015-03-25 09:37:35 +01:00
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
{
|
|
|
|
DataCacheEntry_DiscardData( cache_entry );
|
|
|
|
if (cache_entry->stream) IStream_Release( cache_entry->stream );
|
|
|
|
cache_entry->stream = stm;
|
|
|
|
IStream_AddRef( stm );
|
|
|
|
cache_entry->stream_type = type;
|
|
|
|
cache_entry->dirty = FALSE;
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT parse_pres_streams( DataCache *This, IStorage *stg )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IEnumSTATSTG *stat_enum;
|
|
|
|
STATSTG stat;
|
|
|
|
IStream *stm;
|
|
|
|
PresentationDataHeader header;
|
|
|
|
ULONG actual_read;
|
|
|
|
CLIPFORMAT clipformat;
|
|
|
|
FORMATETC fmtetc;
|
|
|
|
|
|
|
|
hr = IStorage_EnumElements( stg, 0, NULL, 0, &stat_enum );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
while ((hr = IEnumSTATSTG_Next( stat_enum, 1, &stat, NULL )) == S_OK)
|
|
|
|
{
|
|
|
|
if (DataCache_IsPresentationStream( &stat ))
|
|
|
|
{
|
|
|
|
hr = IStorage_OpenStream( stg, stat.pwcsName, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE,
|
|
|
|
0, &stm );
|
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
{
|
|
|
|
hr = read_clipformat( stm, &clipformat );
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
hr = IStream_Read( stm, &header, sizeof(header), &actual_read );
|
|
|
|
|
|
|
|
if (hr == S_OK && actual_read == sizeof(header))
|
|
|
|
{
|
|
|
|
fmtetc.cfFormat = clipformat;
|
|
|
|
fmtetc.ptd = NULL; /* FIXME */
|
|
|
|
fmtetc.dwAspect = header.dvAspect;
|
|
|
|
fmtetc.lindex = header.lindex;
|
2017-06-06 12:46:48 +02:00
|
|
|
fmtetc.tymed = tymed_from_cf( clipformat );
|
2015-03-25 09:37:35 +01:00
|
|
|
|
2017-06-06 12:46:48 +02:00
|
|
|
add_cache_entry( This, &fmtetc, header.advf, stm, pres_stream );
|
2015-03-25 09:37:35 +01:00
|
|
|
}
|
|
|
|
IStream_Release( stm );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CoTaskMemFree( stat.pwcsName );
|
|
|
|
}
|
|
|
|
IEnumSTATSTG_Release( stat_enum );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 09:37:36 +01:00
|
|
|
static const FORMATETC static_dib_fmt = { CF_DIB, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
|
|
|
|
|
|
|
static HRESULT parse_contents_stream( DataCache *This, IStorage *stg, IStream *stm )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
STATSTG stat;
|
|
|
|
const FORMATETC *fmt;
|
|
|
|
|
|
|
|
hr = IStorage_Stat( stg, &stat, STATFLAG_NONAME );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
if (IsEqualCLSID( &stat.clsid, &CLSID_Picture_Dib ))
|
|
|
|
fmt = &static_dib_fmt;
|
|
|
|
else
|
2015-10-22 12:08:37 +02:00
|
|
|
{
|
|
|
|
FIXME("unsupported format %s\n", debugstr_guid( &stat.clsid ));
|
2015-03-25 09:37:36 +01:00
|
|
|
return E_FAIL;
|
2015-10-22 12:08:37 +02:00
|
|
|
}
|
2015-03-25 09:37:36 +01:00
|
|
|
|
2017-06-06 12:46:48 +02:00
|
|
|
return add_cache_entry( This, fmt, 0, stm, contents_stream );
|
2015-03-25 09:37:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const WCHAR CONTENTS[] = {'C','O','N','T','E','N','T','S',0};
|
2015-03-25 09:37:35 +01:00
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_Load (IPersistStorage)
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* The data cache implementation of IPersistStorage_Load doesn't
|
1999-05-02 11:27:08 +02:00
|
|
|
* actually load anything. Instead, it holds on to the storage pointer
|
2002-06-01 01:06:46 +02:00
|
|
|
* and it will load the presentation information when the
|
1999-05-02 11:27:08 +02:00
|
|
|
* IDataObject_GetData or IViewObject2_Draw methods are called.
|
|
|
|
*/
|
2015-03-25 09:37:35 +01:00
|
|
|
static HRESULT WINAPI DataCache_Load( IPersistStorage *iface, IStorage *pStg )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2006-12-01 16:01:38 +01:00
|
|
|
DataCache *This = impl_from_IPersistStorage(iface);
|
|
|
|
HRESULT hr;
|
2015-03-25 09:37:36 +01:00
|
|
|
IStream *stm;
|
2017-06-06 12:46:51 +02:00
|
|
|
CLSID clsid;
|
|
|
|
DataCacheEntry *entry, *cursor2;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
TRACE("(%p, %p)\n", iface, pStg);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2015-03-25 09:37:35 +01:00
|
|
|
IPersistStorage_HandsOffStorage( iface );
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2017-06-06 12:46:51 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( entry, cursor2, &This->cache_list, DataCacheEntry, entry )
|
|
|
|
DataCacheEntry_Destroy( This, entry );
|
|
|
|
|
|
|
|
ReadClassStg( pStg, &clsid );
|
|
|
|
hr = create_automatic_entry( This, &clsid );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
This->clsid = clsid;
|
|
|
|
|
2015-03-25 09:37:36 +01:00
|
|
|
hr = IStorage_OpenStream( pStg, CONTENTS, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE,
|
|
|
|
0, &stm );
|
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
{
|
|
|
|
hr = parse_contents_stream( This, pStg, stm );
|
|
|
|
IStream_Release( stm );
|
|
|
|
}
|
2015-10-23 12:32:22 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
2015-03-25 09:37:36 +01:00
|
|
|
hr = parse_pres_streams( This, pStg );
|
2006-12-01 16:01:38 +01:00
|
|
|
|
2015-03-25 09:37:35 +01:00
|
|
|
if (SUCCEEDED( hr ))
|
2006-12-01 16:01:38 +01:00
|
|
|
{
|
2015-03-25 09:37:35 +01:00
|
|
|
This->dirty = FALSE;
|
|
|
|
This->presentationStorage = pStg;
|
|
|
|
IStorage_AddRef( This->presentationStorage );
|
2006-12-01 16:01:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-25 09:37:35 +01:00
|
|
|
return hr;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_Save (IPersistStorage)
|
|
|
|
*
|
2006-03-21 18:24:49 +01:00
|
|
|
* Until we actually connect to a running object and retrieve new
|
1999-05-08 12:55:32 +02:00
|
|
|
* information to it, we never have to save anything. However, it is
|
2006-03-21 18:24:49 +01:00
|
|
|
* our responsibility to copy the information when saving to a new
|
1999-05-08 12:55:32 +02:00
|
|
|
* storage.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static HRESULT WINAPI DataCache_Save(
|
1999-05-02 11:27:08 +02:00
|
|
|
IPersistStorage* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
IStorage* pStg,
|
1999-05-02 11:27:08 +02:00
|
|
|
BOOL fSameAsLoad)
|
|
|
|
{
|
2006-12-01 16:03:19 +01:00
|
|
|
DataCache *This = impl_from_IPersistStorage(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
BOOL dirty = FALSE;
|
2006-12-01 16:04:04 +01:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
unsigned short stream_number = 0;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-12-01 16:03:19 +01:00
|
|
|
TRACE("(%p, %p, %d)\n", iface, pStg, fSameAsLoad);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-12-01 16:03:19 +01:00
|
|
|
dirty = This->dirty;
|
|
|
|
if (!dirty)
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
dirty = cache_entry->dirty;
|
|
|
|
if (dirty)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-12-01 16:04:04 +01:00
|
|
|
/* assign stream numbers to the cache entries */
|
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
if (cache_entry->stream_number != stream_number)
|
|
|
|
{
|
|
|
|
cache_entry->dirty = TRUE; /* needs to be written out again */
|
|
|
|
cache_entry->stream_number = stream_number;
|
|
|
|
}
|
|
|
|
stream_number++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write out the cache entries */
|
2006-12-01 16:03:19 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
2006-12-01 16:04:04 +01:00
|
|
|
if (!fSameAsLoad || cache_entry->dirty)
|
|
|
|
{
|
|
|
|
hr = DataCacheEntry_Save(cache_entry, pStg, fSameAsLoad);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
cache_entry->dirty = FALSE;
|
|
|
|
}
|
2006-12-01 16:03:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
This->dirty = FALSE;
|
2006-12-01 16:04:04 +01:00
|
|
|
return hr;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_SaveCompleted (IPersistStorage)
|
|
|
|
*
|
|
|
|
* This method is called to tell the cache to release the storage
|
2006-03-21 18:24:49 +01:00
|
|
|
* pointer it's currently holding.
|
1999-05-02 11:27:08 +02:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static HRESULT WINAPI DataCache_SaveCompleted(
|
|
|
|
IPersistStorage* iface,
|
1999-05-02 11:27:08 +02:00
|
|
|
IStorage* pStgNew)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p, %p)\n", iface, pStgNew);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2000-03-08 19:49:36 +01:00
|
|
|
if (pStgNew)
|
|
|
|
{
|
2010-11-01 14:11:37 +01:00
|
|
|
IPersistStorage_HandsOffStorage(iface);
|
2000-03-08 19:49:36 +01:00
|
|
|
|
2010-11-01 14:11:37 +01:00
|
|
|
DataCache_Load(iface, pStgNew);
|
2000-03-08 19:49:36 +01:00
|
|
|
}
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_HandsOffStorage (IPersistStorage)
|
|
|
|
*
|
|
|
|
* This method is called to tell the cache to release the storage
|
2006-03-21 18:24:49 +01:00
|
|
|
* pointer it's currently holding.
|
1999-05-02 11:27:08 +02:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_HandsOffStorage(
|
|
|
|
IPersistStorage* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IPersistStorage(iface);
|
2006-12-04 16:51:25 +01:00
|
|
|
DataCacheEntry *cache_entry;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n", iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
|
|
|
if (this->presentationStorage != NULL)
|
|
|
|
{
|
|
|
|
IStorage_Release(this->presentationStorage);
|
|
|
|
this->presentationStorage = NULL;
|
|
|
|
}
|
|
|
|
|
2006-12-04 16:51:25 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &this->cache_list, DataCacheEntry, entry)
|
|
|
|
DataCacheEntry_HandsOffStorage(cache_entry);
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* Method implementation for the IViewObject2
|
|
|
|
* part of the DataCache class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IViewObject2_QueryInterface (IUnknown)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_IViewObject2_QueryInterface(
|
|
|
|
IViewObject2* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IViewObject2(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_QueryInterface(this->outer_unk, riid, ppvObject);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IViewObject2_AddRef (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IViewObject2_AddRef(
|
1999-05-02 11:27:08 +02:00
|
|
|
IViewObject2* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IViewObject2(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_AddRef(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IViewObject2_Release (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IViewObject2_Release(
|
1999-05-02 11:27:08 +02:00
|
|
|
IViewObject2* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IViewObject2(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_Release(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_Draw (IViewObject2)
|
|
|
|
*
|
|
|
|
* This method will draw the cached representation of the object
|
|
|
|
* to the given device context.
|
|
|
|
*/
|
1999-05-02 11:27:08 +02:00
|
|
|
static HRESULT WINAPI DataCache_Draw(
|
|
|
|
IViewObject2* iface,
|
|
|
|
DWORD dwDrawAspect,
|
|
|
|
LONG lindex,
|
|
|
|
void* pvAspect,
|
2002-06-01 01:06:46 +02:00
|
|
|
DVTARGETDEVICE* ptd,
|
|
|
|
HDC hdcTargetDev,
|
1999-05-02 11:27:08 +02:00
|
|
|
HDC hdcDraw,
|
|
|
|
LPCRECTL lprcBounds,
|
|
|
|
LPCRECTL lprcWBounds,
|
2003-09-03 22:17:39 +02:00
|
|
|
BOOL (CALLBACK *pfnContinue)(ULONG_PTR dwContinue),
|
2004-10-19 00:39:21 +02:00
|
|
|
ULONG_PTR dwContinue)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2006-12-01 16:01:38 +01:00
|
|
|
DataCache *This = impl_from_IViewObject2(iface);
|
1999-05-08 12:55:32 +02:00
|
|
|
HRESULT hres;
|
2006-12-01 16:01:38 +01:00
|
|
|
DataCacheEntry *cache_entry;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %x, %d, %p, %p, %p, %p, %p, %p, %lx)\n",
|
1999-05-08 12:55:32 +02:00
|
|
|
iface,
|
|
|
|
dwDrawAspect,
|
|
|
|
lindex,
|
|
|
|
pvAspect,
|
2002-06-01 01:06:46 +02:00
|
|
|
hdcTargetDev,
|
1999-05-08 12:55:32 +02:00
|
|
|
hdcDraw,
|
|
|
|
lprcBounds,
|
|
|
|
lprcWBounds,
|
|
|
|
pfnContinue,
|
|
|
|
dwContinue);
|
|
|
|
|
|
|
|
if (lprcBounds==NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
/* FIXME: compare ptd too */
|
|
|
|
if ((cache_entry->fmtetc.dwAspect != dwDrawAspect) ||
|
|
|
|
(cache_entry->fmtetc.lindex != lindex))
|
|
|
|
continue;
|
|
|
|
|
2006-12-01 16:02:11 +01:00
|
|
|
/* if the data hasn't been loaded yet, do it now */
|
2015-03-25 09:37:34 +01:00
|
|
|
if ((cache_entry->stgmedium.tymed == TYMED_NULL) && cache_entry->stream)
|
2006-12-01 16:01:38 +01:00
|
|
|
{
|
2006-12-01 16:02:11 +01:00
|
|
|
hres = DataCacheEntry_LoadData(cache_entry);
|
|
|
|
if (FAILED(hres))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no data */
|
|
|
|
if (cache_entry->stgmedium.tymed == TYMED_NULL)
|
|
|
|
continue;
|
|
|
|
|
2010-09-28 11:48:23 +02:00
|
|
|
if (pfnContinue && !pfnContinue(dwContinue)) return E_ABORT;
|
|
|
|
|
2017-10-31 14:23:32 +01:00
|
|
|
switch (cache_entry->fmtetc.cfFormat)
|
2006-12-01 16:02:11 +01:00
|
|
|
{
|
|
|
|
case CF_METAFILEPICT:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have to be careful not to modify the state of the
|
|
|
|
* DC.
|
|
|
|
*/
|
|
|
|
INT prevMapMode;
|
|
|
|
SIZE oldWindowExt;
|
|
|
|
SIZE oldViewportExt;
|
|
|
|
POINT oldViewportOrg;
|
|
|
|
METAFILEPICT *mfpict;
|
|
|
|
|
|
|
|
if ((cache_entry->stgmedium.tymed != TYMED_MFPICT) ||
|
|
|
|
!((mfpict = GlobalLock(cache_entry->stgmedium.u.hMetaFilePict))))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
prevMapMode = SetMapMode(hdcDraw, mfpict->mm);
|
|
|
|
|
|
|
|
SetWindowExtEx(hdcDraw,
|
|
|
|
mfpict->xExt,
|
|
|
|
mfpict->yExt,
|
|
|
|
&oldWindowExt);
|
|
|
|
|
|
|
|
SetViewportExtEx(hdcDraw,
|
|
|
|
lprcBounds->right - lprcBounds->left,
|
|
|
|
lprcBounds->bottom - lprcBounds->top,
|
|
|
|
&oldViewportExt);
|
|
|
|
|
|
|
|
SetViewportOrgEx(hdcDraw,
|
|
|
|
lprcBounds->left,
|
|
|
|
lprcBounds->top,
|
|
|
|
&oldViewportOrg);
|
|
|
|
|
|
|
|
PlayMetaFile(hdcDraw, mfpict->hMF);
|
|
|
|
|
|
|
|
SetWindowExtEx(hdcDraw,
|
|
|
|
oldWindowExt.cx,
|
|
|
|
oldWindowExt.cy,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
SetViewportExtEx(hdcDraw,
|
|
|
|
oldViewportExt.cx,
|
|
|
|
oldViewportExt.cy,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
SetViewportOrgEx(hdcDraw,
|
|
|
|
oldViewportOrg.x,
|
|
|
|
oldViewportOrg.y,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
SetMapMode(hdcDraw, prevMapMode);
|
|
|
|
|
|
|
|
GlobalUnlock(cache_entry->stgmedium.u.hMetaFilePict);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2015-03-25 09:37:40 +01:00
|
|
|
case CF_DIB:
|
|
|
|
{
|
|
|
|
BITMAPINFO *info;
|
|
|
|
BYTE *bits;
|
|
|
|
|
|
|
|
if ((cache_entry->stgmedium.tymed != TYMED_HGLOBAL) ||
|
2017-05-18 12:07:06 +02:00
|
|
|
!((info = GlobalLock( cache_entry->stgmedium.u.hGlobal ))))
|
2015-03-25 09:37:40 +01:00
|
|
|
continue;
|
|
|
|
|
2017-05-18 12:07:06 +02:00
|
|
|
bits = (BYTE *) info + bitmap_info_size( info, DIB_RGB_COLORS );
|
2015-03-25 09:37:40 +01:00
|
|
|
StretchDIBits( hdcDraw, lprcBounds->left, lprcBounds->top,
|
|
|
|
lprcBounds->right - lprcBounds->left, lprcBounds->bottom - lprcBounds->top,
|
|
|
|
0, 0, info->bmiHeader.biWidth, info->bmiHeader.biHeight,
|
|
|
|
bits, info, DIB_RGB_COLORS, SRCCOPY );
|
|
|
|
|
|
|
|
GlobalUnlock( cache_entry->stgmedium.u.hGlobal );
|
|
|
|
return S_OK;
|
|
|
|
}
|
2006-12-01 16:01:38 +01:00
|
|
|
}
|
1999-05-08 12:55:32 +02:00
|
|
|
}
|
|
|
|
|
2006-12-02 19:17:05 +01:00
|
|
|
WARN("no data could be found to be drawn\n");
|
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
return OLE_E_BLANK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_GetColorSet(
|
2002-06-01 01:06:46 +02:00
|
|
|
IViewObject2* iface,
|
|
|
|
DWORD dwDrawAspect,
|
|
|
|
LONG lindex,
|
|
|
|
void* pvAspect,
|
|
|
|
DVTARGETDEVICE* ptd,
|
|
|
|
HDC hicTargetDevice,
|
1999-05-02 11:27:08 +02:00
|
|
|
LOGPALETTE** ppColorSet)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("stub\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_Freeze(
|
|
|
|
IViewObject2* iface,
|
|
|
|
DWORD dwDrawAspect,
|
|
|
|
LONG lindex,
|
2002-06-01 01:06:46 +02:00
|
|
|
void* pvAspect,
|
1999-05-02 11:27:08 +02:00
|
|
|
DWORD* pdwFreeze)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("stub\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_Unfreeze(
|
|
|
|
IViewObject2* iface,
|
|
|
|
DWORD dwFreeze)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("stub\n");
|
1999-05-02 11:27:08 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_SetAdvise (IViewObject2)
|
|
|
|
*
|
|
|
|
* This sets-up an advisory sink with the data cache. When the object's
|
|
|
|
* view changes, this sink is called.
|
|
|
|
*/
|
1999-05-02 11:27:08 +02:00
|
|
|
static HRESULT WINAPI DataCache_SetAdvise(
|
|
|
|
IViewObject2* iface,
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD aspects,
|
|
|
|
DWORD advf,
|
1999-05-02 11:27:08 +02:00
|
|
|
IAdviseSink* pAdvSink)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IViewObject2(iface);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %x, %x, %p)\n", iface, aspects, advf, pAdvSink);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A call to this function removes the previous sink
|
|
|
|
*/
|
|
|
|
if (this->sinkInterface != NULL)
|
|
|
|
{
|
|
|
|
IAdviseSink_Release(this->sinkInterface);
|
|
|
|
this->sinkInterface = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
this->sinkAspects = 0;
|
1999-05-08 12:55:32 +02:00
|
|
|
this->sinkAdviseFlag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, setup the new one.
|
|
|
|
*/
|
|
|
|
if (pAdvSink!=NULL)
|
|
|
|
{
|
|
|
|
this->sinkInterface = pAdvSink;
|
2002-06-01 01:06:46 +02:00
|
|
|
this->sinkAspects = aspects;
|
|
|
|
this->sinkAdviseFlag = advf;
|
1999-05-08 12:55:32 +02:00
|
|
|
|
|
|
|
IAdviseSink_AddRef(this->sinkInterface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the ADVF_PRIMEFIRST flag is set, we have to advise the
|
|
|
|
* sink immediately.
|
|
|
|
*/
|
|
|
|
if (advf & ADVF_PRIMEFIRST)
|
|
|
|
{
|
2006-12-01 16:02:40 +01:00
|
|
|
DataCache_FireOnViewChange(this, aspects, -1);
|
1999-05-08 12:55:32 +02:00
|
|
|
}
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_GetAdvise (IViewObject2)
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This method queries the current state of the advise sink
|
1999-05-08 12:55:32 +02:00
|
|
|
* installed on the data cache.
|
|
|
|
*/
|
1999-05-02 11:27:08 +02:00
|
|
|
static HRESULT WINAPI DataCache_GetAdvise(
|
2002-06-01 01:06:46 +02:00
|
|
|
IViewObject2* iface,
|
|
|
|
DWORD* pAspects,
|
|
|
|
DWORD* pAdvf,
|
1999-05-02 11:27:08 +02:00
|
|
|
IAdviseSink** ppAdvSink)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IViewObject2(iface);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p, %p, %p, %p)\n", iface, pAspects, pAdvf, ppAdvSink);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Just copy all the requested values.
|
|
|
|
*/
|
|
|
|
if (pAspects!=NULL)
|
|
|
|
*pAspects = this->sinkAspects;
|
|
|
|
|
|
|
|
if (pAdvf!=NULL)
|
|
|
|
*pAdvf = this->sinkAdviseFlag;
|
|
|
|
|
|
|
|
if (ppAdvSink!=NULL)
|
|
|
|
{
|
2005-09-28 20:12:58 +02:00
|
|
|
if (this->sinkInterface != NULL)
|
|
|
|
IAdviseSink_QueryInterface(this->sinkInterface,
|
2002-06-01 01:06:46 +02:00
|
|
|
&IID_IAdviseSink,
|
1999-05-08 12:55:32 +02:00
|
|
|
(void**)ppAdvSink);
|
2005-09-28 20:12:58 +02:00
|
|
|
else *ppAdvSink = NULL;
|
1999-05-08 12:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_GetExtent (IViewObject2)
|
|
|
|
*
|
|
|
|
* This method retrieves the "natural" size of this cached object.
|
|
|
|
*/
|
1999-05-02 11:27:08 +02:00
|
|
|
static HRESULT WINAPI DataCache_GetExtent(
|
2002-06-01 01:06:46 +02:00
|
|
|
IViewObject2* iface,
|
|
|
|
DWORD dwDrawAspect,
|
|
|
|
LONG lindex,
|
|
|
|
DVTARGETDEVICE* ptd,
|
1999-05-02 11:27:08 +02:00
|
|
|
LPSIZEL lpsizel)
|
|
|
|
{
|
2006-12-01 16:01:38 +01:00
|
|
|
DataCache *This = impl_from_IViewObject2(iface);
|
1999-05-08 12:55:32 +02:00
|
|
|
HRESULT hres = E_FAIL;
|
2006-12-01 16:01:38 +01:00
|
|
|
DataCacheEntry *cache_entry;
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %x, %d, %p, %p)\n",
|
1999-05-08 12:55:32 +02:00
|
|
|
iface, dwDrawAspect, lindex, ptd, lpsizel);
|
|
|
|
|
|
|
|
if (lpsizel==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
lpsizel->cx = 0;
|
|
|
|
lpsizel->cy = 0;
|
|
|
|
|
|
|
|
if (lindex!=-1)
|
2006-10-15 12:28:08 +02:00
|
|
|
FIXME("Unimplemented flag lindex = %d\n", lindex);
|
1999-05-08 12:55:32 +02:00
|
|
|
|
|
|
|
/*
|
2003-07-02 06:37:26 +02:00
|
|
|
* Right now, we support only the callback from
|
1999-05-08 12:55:32 +02:00
|
|
|
* the default handler.
|
|
|
|
*/
|
|
|
|
if (ptd!=NULL)
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("Unimplemented ptd = %p\n", ptd);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-12-01 16:01:38 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
/* FIXME: compare ptd too */
|
|
|
|
if ((cache_entry->fmtetc.dwAspect != dwDrawAspect) ||
|
|
|
|
(cache_entry->fmtetc.lindex != lindex))
|
|
|
|
continue;
|
|
|
|
|
2006-12-01 16:02:11 +01:00
|
|
|
/* if the data hasn't been loaded yet, do it now */
|
2015-03-25 09:37:34 +01:00
|
|
|
if ((cache_entry->stgmedium.tymed == TYMED_NULL) && cache_entry->stream)
|
2006-12-01 16:02:11 +01:00
|
|
|
{
|
|
|
|
hres = DataCacheEntry_LoadData(cache_entry);
|
|
|
|
if (FAILED(hres))
|
|
|
|
continue;
|
|
|
|
}
|
1999-05-08 12:55:32 +02:00
|
|
|
|
2006-12-01 16:02:11 +01:00
|
|
|
/* no data */
|
|
|
|
if (cache_entry->stgmedium.tymed == TYMED_NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
2017-10-31 14:23:32 +01:00
|
|
|
switch (cache_entry->fmtetc.cfFormat)
|
2006-12-01 16:01:38 +01:00
|
|
|
{
|
2006-12-01 16:02:11 +01:00
|
|
|
case CF_METAFILEPICT:
|
|
|
|
{
|
|
|
|
METAFILEPICT *mfpict;
|
|
|
|
|
|
|
|
if ((cache_entry->stgmedium.tymed != TYMED_MFPICT) ||
|
|
|
|
!((mfpict = GlobalLock(cache_entry->stgmedium.u.hMetaFilePict))))
|
|
|
|
continue;
|
2006-12-01 16:01:38 +01:00
|
|
|
|
2006-12-01 16:02:11 +01:00
|
|
|
lpsizel->cx = mfpict->xExt;
|
|
|
|
lpsizel->cy = mfpict->yExt;
|
|
|
|
|
|
|
|
GlobalUnlock(cache_entry->stgmedium.u.hMetaFilePict);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2015-03-25 09:37:39 +01:00
|
|
|
case CF_DIB:
|
|
|
|
{
|
|
|
|
BITMAPINFOHEADER *info;
|
|
|
|
LONG x_pels_m, y_pels_m;
|
|
|
|
|
|
|
|
|
|
|
|
if ((cache_entry->stgmedium.tymed != TYMED_HGLOBAL) ||
|
2017-05-18 12:07:06 +02:00
|
|
|
!((info = GlobalLock( cache_entry->stgmedium.u.hGlobal ))))
|
2015-03-25 09:37:39 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
x_pels_m = info->biXPelsPerMeter;
|
|
|
|
y_pels_m = info->biYPelsPerMeter;
|
|
|
|
|
|
|
|
/* Size in units of 0.01mm (ie. MM_HIMETRIC) */
|
|
|
|
if (x_pels_m != 0 && y_pels_m != 0)
|
|
|
|
{
|
|
|
|
lpsizel->cx = info->biWidth * 100000 / x_pels_m;
|
|
|
|
lpsizel->cy = info->biHeight * 100000 / y_pels_m;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HDC hdc = GetDC( 0 );
|
|
|
|
lpsizel->cx = info->biWidth * 2540 / GetDeviceCaps( hdc, LOGPIXELSX );
|
|
|
|
lpsizel->cy = info->biHeight * 2540 / GetDeviceCaps( hdc, LOGPIXELSY );
|
|
|
|
|
|
|
|
ReleaseDC( 0, hdc );
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock( cache_entry->stgmedium.u.hGlobal );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2006-12-01 16:01:38 +01:00
|
|
|
}
|
1999-05-08 12:55:32 +02:00
|
|
|
}
|
|
|
|
|
2006-12-02 19:17:05 +01:00
|
|
|
WARN("no data could be found to get the extents from\n");
|
|
|
|
|
1999-05-08 12:55:32 +02:00
|
|
|
/*
|
|
|
|
* This method returns OLE_E_BLANK when it fails.
|
|
|
|
*/
|
2006-12-01 16:01:38 +01:00
|
|
|
return OLE_E_BLANK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* Method implementation for the IOleCache2
|
|
|
|
* part of the DataCache class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IOleCache2_QueryInterface (IUnknown)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_IOleCache2_QueryInterface(
|
|
|
|
IOleCache2* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IOleCache2(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_QueryInterface(this->outer_unk, riid, ppvObject);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IOleCache2_AddRef (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IOleCache2_AddRef(
|
1999-05-02 11:27:08 +02:00
|
|
|
IOleCache2* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IOleCache2(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_AddRef(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IOleCache2_Release (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IOleCache2_Release(
|
1999-05-02 11:27:08 +02:00
|
|
|
IOleCache2* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IOleCache2(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_Release(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2010-11-01 15:08:45 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* setup_sink
|
|
|
|
*
|
|
|
|
* Set up the sink connection to the running object.
|
|
|
|
*/
|
|
|
|
static HRESULT setup_sink(DataCache *This, DataCacheEntry *cache_entry)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_FALSE;
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
/* Clear the ADVFCACHE_* bits. Native also sets the two highest bits for some reason. */
|
|
|
|
flags = cache_entry->advise_flags & ~(ADVFCACHE_NOHANDLER | ADVFCACHE_FORCEBUILTIN | ADVFCACHE_ONSAVE);
|
|
|
|
|
|
|
|
if(This->running_object)
|
|
|
|
if(!(flags & ADVF_NODATA))
|
|
|
|
hr = IDataObject_DAdvise(This->running_object, &cache_entry->fmtetc, flags,
|
2010-12-23 02:05:04 +01:00
|
|
|
&This->IAdviseSink_iface, &cache_entry->sink_id);
|
2010-11-01 15:08:45 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-05-02 11:27:08 +02:00
|
|
|
static HRESULT WINAPI DataCache_Cache(
|
|
|
|
IOleCache2* iface,
|
|
|
|
FORMATETC* pformatetc,
|
|
|
|
DWORD advf,
|
|
|
|
DWORD* pdwConnection)
|
|
|
|
{
|
2006-12-01 16:01:50 +01:00
|
|
|
DataCache *This = impl_from_IOleCache2(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
HRESULT hr;
|
2017-05-23 14:11:41 +02:00
|
|
|
FORMATETC fmt_cpy;
|
2006-12-01 16:01:50 +01:00
|
|
|
|
|
|
|
TRACE("(%p, 0x%x, %p)\n", pformatetc, advf, pdwConnection);
|
2007-11-13 19:58:34 +01:00
|
|
|
|
|
|
|
if (!pformatetc || !pdwConnection)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2006-12-06 12:05:31 +01:00
|
|
|
TRACE("pformatetc = %s\n", debugstr_formatetc(pformatetc));
|
2006-12-01 16:01:50 +01:00
|
|
|
|
2017-05-23 14:11:41 +02:00
|
|
|
fmt_cpy = *pformatetc; /* No need for a deep copy */
|
|
|
|
if (fmt_cpy.cfFormat == CF_BITMAP && fmt_cpy.tymed == TYMED_GDI)
|
|
|
|
{
|
|
|
|
fmt_cpy.cfFormat = CF_DIB;
|
|
|
|
fmt_cpy.tymed = TYMED_HGLOBAL;
|
|
|
|
}
|
|
|
|
|
2017-10-31 14:23:29 +01:00
|
|
|
/* View caching DVASPECT_ICON gets converted to CF_METAFILEPICT */
|
|
|
|
if (fmt_cpy.dwAspect == DVASPECT_ICON && fmt_cpy.cfFormat == 0)
|
|
|
|
{
|
|
|
|
fmt_cpy.cfFormat = CF_METAFILEPICT;
|
|
|
|
fmt_cpy.tymed = TYMED_MFPICT;
|
|
|
|
}
|
|
|
|
|
2006-12-01 16:01:50 +01:00
|
|
|
*pdwConnection = 0;
|
|
|
|
|
2017-05-23 14:11:41 +02:00
|
|
|
cache_entry = DataCache_GetEntryForFormatEtc(This, &fmt_cpy);
|
2006-12-01 16:01:50 +01:00
|
|
|
if (cache_entry)
|
|
|
|
{
|
2006-12-02 19:17:05 +01:00
|
|
|
TRACE("found an existing cache entry\n");
|
2006-12-01 16:01:50 +01:00
|
|
|
*pdwConnection = cache_entry->id;
|
|
|
|
return CACHE_S_SAMECACHE;
|
|
|
|
}
|
|
|
|
|
2017-06-06 12:46:51 +02:00
|
|
|
hr = DataCache_CreateEntry(This, &fmt_cpy, advf, FALSE, &cache_entry);
|
2006-12-01 16:01:50 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2010-11-01 15:08:45 +01:00
|
|
|
{
|
2006-12-01 16:01:50 +01:00
|
|
|
*pdwConnection = cache_entry->id;
|
2010-11-01 15:08:45 +01:00
|
|
|
setup_sink(This, cache_entry);
|
|
|
|
}
|
2006-12-01 16:01:50 +01:00
|
|
|
|
|
|
|
return hr;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_Uncache(
|
|
|
|
IOleCache2* iface,
|
|
|
|
DWORD dwConnection)
|
|
|
|
{
|
2006-12-01 16:01:50 +01:00
|
|
|
DataCache *This = impl_from_IOleCache2(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
|
|
|
|
TRACE("(%d)\n", dwConnection);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
if (cache_entry->id == dwConnection)
|
|
|
|
{
|
2010-11-01 15:08:45 +01:00
|
|
|
DataCacheEntry_Destroy(This, cache_entry);
|
2006-12-01 16:01:50 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-02 19:17:05 +01:00
|
|
|
WARN("no connection found for %d\n", dwConnection);
|
|
|
|
|
2006-12-01 16:01:50 +01:00
|
|
|
return OLE_E_NOCONNECTION;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2017-05-23 14:11:40 +02:00
|
|
|
static HRESULT WINAPI DataCache_EnumCache(IOleCache2 *iface,
|
|
|
|
IEnumSTATDATA **enum_stat)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2017-05-23 14:11:40 +02:00
|
|
|
DataCache *This = impl_from_IOleCache2( iface );
|
|
|
|
DataCacheEntry *cache_entry;
|
2017-05-23 14:11:41 +02:00
|
|
|
int i = 0, count = 0;
|
2017-05-23 14:11:40 +02:00
|
|
|
STATDATA *data;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p)\n", This, enum_stat );
|
|
|
|
|
2017-05-23 14:11:41 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( cache_entry, &This->cache_list, DataCacheEntry, entry )
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
if (cache_entry->fmtetc.cfFormat == CF_DIB)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2017-05-23 14:11:40 +02:00
|
|
|
data = CoTaskMemAlloc( count * sizeof(*data) );
|
|
|
|
if (!data) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( cache_entry, &This->cache_list, DataCacheEntry, entry )
|
|
|
|
{
|
2017-05-23 14:11:41 +02:00
|
|
|
if (i == count) goto fail;
|
2017-05-23 14:11:40 +02:00
|
|
|
hr = copy_formatetc( &data[i].formatetc, &cache_entry->fmtetc );
|
|
|
|
if (FAILED(hr)) goto fail;
|
|
|
|
data[i].advf = cache_entry->advise_flags;
|
|
|
|
data[i].pAdvSink = NULL;
|
|
|
|
data[i].dwConnection = cache_entry->id;
|
|
|
|
i++;
|
2017-05-23 14:11:41 +02:00
|
|
|
|
|
|
|
if (cache_entry->fmtetc.cfFormat == CF_DIB)
|
|
|
|
{
|
|
|
|
if (i == count) goto fail;
|
|
|
|
hr = copy_formatetc( &data[i].formatetc, &cache_entry->fmtetc );
|
|
|
|
if (FAILED(hr)) goto fail;
|
|
|
|
data[i].formatetc.cfFormat = CF_BITMAP;
|
|
|
|
data[i].formatetc.tymed = TYMED_GDI;
|
|
|
|
data[i].advf = cache_entry->advise_flags;
|
|
|
|
data[i].pAdvSink = NULL;
|
|
|
|
data[i].dwConnection = cache_entry->id;
|
|
|
|
i++;
|
|
|
|
}
|
2017-05-23 14:11:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hr = EnumSTATDATA_Construct( NULL, 0, i, data, FALSE, enum_stat );
|
|
|
|
if (SUCCEEDED(hr)) return hr;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
while (i--) CoTaskMemFree( data[i].formatetc.ptd );
|
|
|
|
CoTaskMemFree( data );
|
|
|
|
return hr;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2017-10-31 14:23:34 +01:00
|
|
|
static HRESULT WINAPI DataCache_InitCache( IOleCache2 *iface, IDataObject *data )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2017-10-31 14:23:34 +01:00
|
|
|
TRACE( "(%p %p)\n", iface, data );
|
|
|
|
return IOleCache2_UpdateCache( iface, data, UPDFCACHE_ALLBUTNODATACACHE, NULL );
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_IOleCache2_SetData(
|
|
|
|
IOleCache2* iface,
|
|
|
|
FORMATETC* pformatetc,
|
|
|
|
STGMEDIUM* pmedium,
|
|
|
|
BOOL fRelease)
|
|
|
|
{
|
2006-12-01 16:02:26 +01:00
|
|
|
DataCache *This = impl_from_IOleCache2(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %s)\n", pformatetc, pmedium, fRelease ? "TRUE" : "FALSE");
|
2006-12-06 12:05:31 +01:00
|
|
|
TRACE("formatetc = %s\n", debugstr_formatetc(pformatetc));
|
2006-12-01 16:02:26 +01:00
|
|
|
|
|
|
|
cache_entry = DataCache_GetEntryForFormatEtc(This, pformatetc);
|
|
|
|
if (cache_entry)
|
|
|
|
{
|
2006-12-02 19:16:53 +01:00
|
|
|
hr = DataCacheEntry_SetData(cache_entry, pformatetc, pmedium, fRelease);
|
2006-12-01 16:02:26 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
DataCache_FireOnViewChange(This, cache_entry->fmtetc.dwAspect,
|
|
|
|
cache_entry->fmtetc.lindex);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2006-12-02 19:16:53 +01:00
|
|
|
WARN("cache entry not found\n");
|
2006-12-01 16:02:26 +01:00
|
|
|
|
|
|
|
return OLE_E_BLANK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2017-10-31 14:23:33 +01:00
|
|
|
static BOOL entry_updateable( DataCacheEntry *entry, DWORD mode )
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2017-10-31 14:23:33 +01:00
|
|
|
BOOL is_blank = entry->stgmedium.tymed == TYMED_NULL;
|
|
|
|
|
|
|
|
if ((mode & UPDFCACHE_ONLYIFBLANK) && !is_blank) return FALSE;
|
|
|
|
|
|
|
|
if ((mode & UPDFCACHE_NODATACACHE) && (entry->advise_flags & ADVF_NODATA)) return TRUE;
|
|
|
|
if ((mode & UPDFCACHE_ONSAVECACHE) && (entry->advise_flags & ADVFCACHE_ONSAVE)) return TRUE;
|
|
|
|
if ((mode & UPDFCACHE_ONSTOPCACHE) && (entry->advise_flags & ADVF_DATAONSTOP)) return TRUE;
|
|
|
|
if ((mode & UPDFCACHE_NORMALCACHE) && (entry->advise_flags == 0)) return TRUE;
|
|
|
|
if ((mode & UPDFCACHE_IFBLANK) && (is_blank && !(entry->advise_flags & ADVF_NODATA))) return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_UpdateCache( IOleCache2 *iface, IDataObject *data,
|
|
|
|
DWORD mode, void *reserved )
|
|
|
|
{
|
|
|
|
DataCache *This = impl_from_IOleCache2(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
STGMEDIUM med;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
CLIPFORMAT view_list[] = { CF_METAFILEPICT, CF_ENHMETAFILE, CF_DIB, CF_BITMAP };
|
|
|
|
FORMATETC fmt;
|
|
|
|
int i, slots = 0;
|
|
|
|
BOOL done_one = FALSE;
|
|
|
|
|
|
|
|
TRACE( "(%p %p %08x %p)\n", iface, data, mode, reserved );
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( cache_entry, &This->cache_list, DataCacheEntry, entry )
|
|
|
|
{
|
|
|
|
slots++;
|
|
|
|
|
|
|
|
if (!entry_updateable( cache_entry, mode ))
|
|
|
|
{
|
|
|
|
done_one = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt = cache_entry->fmtetc;
|
|
|
|
|
|
|
|
if (fmt.cfFormat)
|
|
|
|
{
|
|
|
|
hr = IDataObject_GetData( data, &fmt, &med );
|
|
|
|
if (hr != S_OK && fmt.cfFormat == CF_DIB)
|
|
|
|
{
|
|
|
|
fmt.cfFormat = CF_BITMAP;
|
|
|
|
fmt.tymed = TYMED_GDI;
|
|
|
|
hr = IDataObject_GetData( data, &fmt, &med );
|
|
|
|
}
|
|
|
|
if (hr != S_OK && fmt.cfFormat == CF_ENHMETAFILE)
|
|
|
|
{
|
|
|
|
fmt.cfFormat = CF_METAFILEPICT;
|
|
|
|
fmt.tymed = TYMED_MFPICT;
|
|
|
|
hr = IDataObject_GetData( data, &fmt, &med );
|
|
|
|
}
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = DataCacheEntry_SetData( cache_entry, &fmt, &med, TRUE );
|
|
|
|
if (hr != S_OK) ReleaseStgMedium( &med );
|
|
|
|
else done_one = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < sizeof(view_list) / sizeof(view_list[0]); i++)
|
|
|
|
{
|
|
|
|
fmt.cfFormat = view_list[i];
|
|
|
|
fmt.tymed = tymed_from_cf( fmt.cfFormat );
|
|
|
|
hr = IDataObject_QueryGetData( data, &fmt );
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IDataObject_GetData( data, &fmt, &med );
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
if (fmt.cfFormat == CF_BITMAP)
|
|
|
|
{
|
|
|
|
cache_entry->fmtetc.cfFormat = CF_DIB;
|
|
|
|
cache_entry->fmtetc.tymed = TYMED_HGLOBAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cache_entry->fmtetc.cfFormat = fmt.cfFormat;
|
|
|
|
cache_entry->fmtetc.tymed = fmt.tymed;
|
|
|
|
}
|
|
|
|
hr = DataCacheEntry_SetData( cache_entry, &fmt, &med, TRUE );
|
|
|
|
if (hr != S_OK) ReleaseStgMedium( &med );
|
|
|
|
else done_one = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (!slots || done_one) ? S_OK : CACHE_E_NOCACHE_UPDATED;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DataCache_DiscardCache(
|
|
|
|
IOleCache2* iface,
|
|
|
|
DWORD dwDiscardOptions)
|
|
|
|
{
|
2006-12-04 16:51:05 +01:00
|
|
|
DataCache *This = impl_from_IOleCache2(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%d)\n", dwDiscardOptions);
|
|
|
|
|
|
|
|
if (dwDiscardOptions == DISCARDCACHE_SAVEIFDIRTY)
|
2010-12-23 02:05:04 +01:00
|
|
|
hr = DataCache_Save(&This->IPersistStorage_iface, This->presentationStorage, TRUE);
|
2006-12-04 16:51:05 +01:00
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
hr = DataCacheEntry_DiscardData(cache_entry);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* Method implementation for the IOleCacheControl
|
|
|
|
* part of the DataCache class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IOleCacheControl_QueryInterface (IUnknown)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_IOleCacheControl_QueryInterface(
|
|
|
|
IOleCacheControl* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IOleCacheControl(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_QueryInterface(this->outer_unk, riid, ppvObject);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IOleCacheControl_AddRef (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IOleCacheControl_AddRef(
|
1999-05-02 11:27:08 +02:00
|
|
|
IOleCacheControl* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IOleCacheControl(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_AddRef(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* DataCache_IOleCacheControl_Release (IUnknown)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI DataCache_IOleCacheControl_Release(
|
1999-05-02 11:27:08 +02:00
|
|
|
IOleCacheControl* iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
DataCache *this = impl_from_IOleCacheControl(iface);
|
1999-05-02 11:27:08 +02:00
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
return IUnknown_Release(this->outer_unk);
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2010-11-01 15:08:45 +01:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_OnRun (IOleCacheControl)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_OnRun(IOleCacheControl* iface, IDataObject *data_obj)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-11-01 15:08:45 +01:00
|
|
|
DataCache *This = impl_from_IOleCacheControl(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", iface, data_obj);
|
|
|
|
|
|
|
|
if(This->running_object) return S_OK;
|
|
|
|
|
|
|
|
/* No reference is taken on the data object */
|
|
|
|
This->running_object = data_obj;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
setup_sink(This, cache_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
|
|
|
|
2010-11-01 15:08:45 +01:00
|
|
|
/************************************************************************
|
|
|
|
* DataCache_OnStop (IOleCacheControl)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_OnStop(IOleCacheControl* iface)
|
1999-05-02 11:27:08 +02:00
|
|
|
{
|
2010-11-01 15:08:45 +01:00
|
|
|
DataCache *This = impl_from_IOleCacheControl(iface);
|
|
|
|
DataCacheEntry *cache_entry;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
if(!This->running_object) return S_OK;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(cache_entry, &This->cache_list, DataCacheEntry, entry)
|
|
|
|
{
|
|
|
|
if(cache_entry->sink_id)
|
|
|
|
{
|
|
|
|
IDataObject_DUnadvise(This->running_object, cache_entry->sink_id);
|
|
|
|
cache_entry->sink_id = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No ref taken in OnRun, so no Release call here */
|
|
|
|
This->running_object = NULL;
|
|
|
|
return S_OK;
|
1999-05-02 11:27:08 +02:00
|
|
|
}
|
2005-03-27 20:16:49 +02:00
|
|
|
|
2010-10-26 15:35:14 +02:00
|
|
|
/************************************************************************
|
|
|
|
* IAdviseSink methods.
|
|
|
|
* This behaves as an internal object to the data cache. QI'ing its ptr doesn't
|
|
|
|
* give access to the cache's other interfaces. We don't maintain a ref count,
|
|
|
|
* the object exists as long as the cache is around.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI DataCache_IAdviseSink_QueryInterface(IAdviseSink *iface, REFIID iid, void **obj)
|
|
|
|
{
|
|
|
|
*obj = NULL;
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IAdviseSink, iid))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*obj)
|
|
|
|
{
|
|
|
|
IAdviseSink_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DataCache_IAdviseSink_AddRef(IAdviseSink *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DataCache_IAdviseSink_Release(IAdviseSink *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI DataCache_OnDataChange(IAdviseSink *iface, FORMATETC *fmt, STGMEDIUM *med)
|
|
|
|
{
|
2010-11-01 15:08:45 +01:00
|
|
|
DataCache *This = impl_from_IAdviseSink(iface);
|
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_formatetc(fmt), med);
|
2012-08-13 11:40:33 +02:00
|
|
|
IOleCache2_SetData(&This->IOleCache2_iface, fmt, med, FALSE);
|
2010-10-26 15:35:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI DataCache_OnViewChange(IAdviseSink *iface, DWORD aspect, LONG index)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI DataCache_OnRename(IAdviseSink *iface, IMoniker *mk)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI DataCache_OnSave(IAdviseSink *iface)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI DataCache_OnClose(IAdviseSink *iface)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
}
|
|
|
|
|
2005-03-27 20:16:49 +02:00
|
|
|
/*
|
|
|
|
* Virtual function tables for the DataCache class.
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IUnknownVtbl DataCache_NDIUnknown_VTable =
|
2005-03-27 20:16:49 +02:00
|
|
|
{
|
|
|
|
DataCache_NDIUnknown_QueryInterface,
|
|
|
|
DataCache_NDIUnknown_AddRef,
|
|
|
|
DataCache_NDIUnknown_Release
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IDataObjectVtbl DataCache_IDataObject_VTable =
|
2005-03-27 20:16:49 +02:00
|
|
|
{
|
|
|
|
DataCache_IDataObject_QueryInterface,
|
|
|
|
DataCache_IDataObject_AddRef,
|
|
|
|
DataCache_IDataObject_Release,
|
|
|
|
DataCache_GetData,
|
|
|
|
DataCache_GetDataHere,
|
|
|
|
DataCache_QueryGetData,
|
|
|
|
DataCache_GetCanonicalFormatEtc,
|
|
|
|
DataCache_IDataObject_SetData,
|
|
|
|
DataCache_EnumFormatEtc,
|
|
|
|
DataCache_DAdvise,
|
|
|
|
DataCache_DUnadvise,
|
|
|
|
DataCache_EnumDAdvise
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPersistStorageVtbl DataCache_IPersistStorage_VTable =
|
2005-03-27 20:16:49 +02:00
|
|
|
{
|
|
|
|
DataCache_IPersistStorage_QueryInterface,
|
|
|
|
DataCache_IPersistStorage_AddRef,
|
|
|
|
DataCache_IPersistStorage_Release,
|
|
|
|
DataCache_GetClassID,
|
|
|
|
DataCache_IsDirty,
|
|
|
|
DataCache_InitNew,
|
|
|
|
DataCache_Load,
|
|
|
|
DataCache_Save,
|
|
|
|
DataCache_SaveCompleted,
|
|
|
|
DataCache_HandsOffStorage
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IViewObject2Vtbl DataCache_IViewObject2_VTable =
|
2005-03-27 20:16:49 +02:00
|
|
|
{
|
|
|
|
DataCache_IViewObject2_QueryInterface,
|
|
|
|
DataCache_IViewObject2_AddRef,
|
|
|
|
DataCache_IViewObject2_Release,
|
|
|
|
DataCache_Draw,
|
|
|
|
DataCache_GetColorSet,
|
|
|
|
DataCache_Freeze,
|
|
|
|
DataCache_Unfreeze,
|
|
|
|
DataCache_SetAdvise,
|
|
|
|
DataCache_GetAdvise,
|
|
|
|
DataCache_GetExtent
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IOleCache2Vtbl DataCache_IOleCache2_VTable =
|
2005-03-27 20:16:49 +02:00
|
|
|
{
|
|
|
|
DataCache_IOleCache2_QueryInterface,
|
|
|
|
DataCache_IOleCache2_AddRef,
|
|
|
|
DataCache_IOleCache2_Release,
|
|
|
|
DataCache_Cache,
|
|
|
|
DataCache_Uncache,
|
|
|
|
DataCache_EnumCache,
|
|
|
|
DataCache_InitCache,
|
|
|
|
DataCache_IOleCache2_SetData,
|
|
|
|
DataCache_UpdateCache,
|
|
|
|
DataCache_DiscardCache
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IOleCacheControlVtbl DataCache_IOleCacheControl_VTable =
|
2005-03-27 20:16:49 +02:00
|
|
|
{
|
|
|
|
DataCache_IOleCacheControl_QueryInterface,
|
|
|
|
DataCache_IOleCacheControl_AddRef,
|
|
|
|
DataCache_IOleCacheControl_Release,
|
|
|
|
DataCache_OnRun,
|
|
|
|
DataCache_OnStop
|
|
|
|
};
|
|
|
|
|
2010-10-26 15:35:14 +02:00
|
|
|
static const IAdviseSinkVtbl DataCache_IAdviseSink_VTable =
|
|
|
|
{
|
|
|
|
DataCache_IAdviseSink_QueryInterface,
|
|
|
|
DataCache_IAdviseSink_AddRef,
|
|
|
|
DataCache_IAdviseSink_Release,
|
|
|
|
DataCache_OnDataChange,
|
|
|
|
DataCache_OnViewChange,
|
|
|
|
DataCache_OnRename,
|
|
|
|
DataCache_OnSave,
|
|
|
|
DataCache_OnClose
|
|
|
|
};
|
|
|
|
|
2010-11-01 13:11:14 +01:00
|
|
|
/*********************************************************
|
|
|
|
* Method implementation for DataCache class.
|
|
|
|
*/
|
|
|
|
static DataCache* DataCache_Construct(
|
|
|
|
REFCLSID clsid,
|
|
|
|
LPUNKNOWN pUnkOuter)
|
|
|
|
{
|
|
|
|
DataCache* newObject = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for the object.
|
|
|
|
*/
|
|
|
|
newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(DataCache));
|
|
|
|
|
|
|
|
if (newObject==0)
|
|
|
|
return newObject;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the virtual function table.
|
|
|
|
*/
|
2010-12-23 02:05:04 +01:00
|
|
|
newObject->IDataObject_iface.lpVtbl = &DataCache_IDataObject_VTable;
|
2016-07-06 08:49:39 +02:00
|
|
|
newObject->IUnknown_inner.lpVtbl = &DataCache_NDIUnknown_VTable;
|
2010-12-23 02:05:04 +01:00
|
|
|
newObject->IPersistStorage_iface.lpVtbl = &DataCache_IPersistStorage_VTable;
|
|
|
|
newObject->IViewObject2_iface.lpVtbl = &DataCache_IViewObject2_VTable;
|
|
|
|
newObject->IOleCache2_iface.lpVtbl = &DataCache_IOleCache2_VTable;
|
|
|
|
newObject->IOleCacheControl_iface.lpVtbl = &DataCache_IOleCacheControl_VTable;
|
|
|
|
newObject->IAdviseSink_iface.lpVtbl = &DataCache_IAdviseSink_VTable;
|
2016-07-06 08:49:39 +02:00
|
|
|
newObject->outer_unk = pUnkOuter ? pUnkOuter : &newObject->IUnknown_inner;
|
2010-11-01 13:11:14 +01:00
|
|
|
newObject->ref = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the other members of the structure.
|
|
|
|
*/
|
|
|
|
newObject->sinkAspects = 0;
|
|
|
|
newObject->sinkAdviseFlag = 0;
|
|
|
|
newObject->sinkInterface = 0;
|
2017-06-06 12:46:51 +02:00
|
|
|
newObject->clsid = CLSID_NULL;
|
2010-11-01 13:11:14 +01:00
|
|
|
newObject->presentationStorage = NULL;
|
|
|
|
list_init(&newObject->cache_list);
|
2017-06-06 12:46:49 +02:00
|
|
|
newObject->last_cache_id = 2;
|
2010-11-01 13:11:14 +01:00
|
|
|
newObject->dirty = FALSE;
|
2010-11-01 15:08:45 +01:00
|
|
|
newObject->running_object = NULL;
|
2010-11-01 13:11:14 +01:00
|
|
|
|
2017-06-06 12:46:51 +02:00
|
|
|
create_automatic_entry( newObject, clsid );
|
|
|
|
newObject->clsid = *clsid;
|
|
|
|
|
2010-11-01 13:11:14 +01:00
|
|
|
return newObject;
|
|
|
|
}
|
2010-10-26 15:35:14 +02:00
|
|
|
|
2005-03-27 20:16:49 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateDataCache [OLE32.@]
|
2006-12-01 16:02:58 +01:00
|
|
|
*
|
|
|
|
* Creates a data cache to allow an object to render one or more of its views,
|
|
|
|
* whether running or not.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pUnkOuter [I] Outer unknown for the object.
|
|
|
|
* rclsid [I]
|
|
|
|
* riid [I] IID of interface to return.
|
|
|
|
* ppvObj [O] Address where the data cache object will be stored on return.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The following interfaces are supported by the returned data cache object:
|
2008-04-09 21:33:37 +02:00
|
|
|
* IOleCache, IOleCache2, IOleCacheControl, IPersistStorage, IDataObject,
|
2006-12-01 16:02:58 +01:00
|
|
|
* IViewObject and IViewObject2.
|
2005-03-27 20:16:49 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI CreateDataCache(
|
|
|
|
LPUNKNOWN pUnkOuter,
|
|
|
|
REFCLSID rclsid,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID* ppvObj)
|
|
|
|
{
|
|
|
|
DataCache* newCache = NULL;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%s, %p, %s, %p)\n", debugstr_guid(rclsid), pUnkOuter, debugstr_guid(riid), ppvObj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity check
|
|
|
|
*/
|
|
|
|
if (ppvObj==0)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppvObj = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this cache is constructed for aggregation, make sure
|
|
|
|
* the caller is requesting the IUnknown interface.
|
|
|
|
* This is necessary because it's the only time the non-delegating
|
|
|
|
* IUnknown pointer can be returned to the outside.
|
|
|
|
*/
|
2010-07-23 11:30:00 +02:00
|
|
|
if ( pUnkOuter && !IsEqualIID(&IID_IUnknown, riid) )
|
2016-03-21 09:55:57 +01:00
|
|
|
return E_INVALIDARG;
|
2005-03-27 20:16:49 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to construct a new instance of the class.
|
|
|
|
*/
|
|
|
|
newCache = DataCache_Construct(rclsid,
|
|
|
|
pUnkOuter);
|
|
|
|
|
|
|
|
if (newCache == 0)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2016-07-06 08:49:39 +02:00
|
|
|
hr = IUnknown_QueryInterface(&newCache->IUnknown_inner, riid, ppvObj);
|
|
|
|
IUnknown_Release(&newCache->IUnknown_inner);
|
2005-03-27 20:16:49 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|