[PATCH] ole32: Implement saving of view cache entries.

Huw Davies huw at codeweavers.com
Mon Jan 22 02:54:11 CST 2018


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/ole32/datacache.c  | 23 +++++++++++++++++++++--
 dlls/ole32/tests/ole2.c | 19 +++++++++++++------
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/dlls/ole32/datacache.c b/dlls/ole32/datacache.c
index 4ba08268d7..e2ff928ba8 100644
--- a/dlls/ole32/datacache.c
+++ b/dlls/ole32/datacache.c
@@ -506,7 +506,9 @@ static HRESULT write_clipformat(IStream *stream, CLIPFORMAT clipformat)
     HRESULT hr;
     char format_name[256];
 
-    if (clipformat < 0xc000)
+    if (clipformat == 0)
+        length = 0;
+    else if (clipformat < 0xc000)
         length = -1;
     else
     {
@@ -515,8 +517,9 @@ static HRESULT write_clipformat(IStream *stream, CLIPFORMAT clipformat)
         if (length) length++;
     }
     hr = IStream_Write(stream, &length, sizeof(length), NULL);
-    if (FAILED(hr))
+    if (FAILED(hr) || clipformat == 0)
         return hr;
+
     if (clipformat < 0xc000)
     {
         DWORD cf = clipformat;
@@ -993,6 +996,19 @@ static HRESULT save_emf(DataCacheEntry *entry, BOOL contents, IStream *stream)
     return hr;
 }
 
+static HRESULT save_view_cache(DataCacheEntry *entry, IStream *stream)
+{
+    HRESULT hr;
+    PresentationDataHeader header;
+
+    init_stream_header(entry, &header);
+    hr = write_clipformat(stream, entry->fmtetc.cfFormat);
+    if (SUCCEEDED(hr))
+        hr = IStream_Write(stream, &header, FIELD_OFFSET(PresentationDataHeader, unknown7), NULL);
+
+    return hr;
+}
+
 static const WCHAR CONTENTS[] = {'C','O','N','T','E','N','T','S',0};
 static HRESULT create_stream(DataCacheEntry *cache_entry, IStorage *storage,
                              BOOL contents, IStream **stream)
@@ -1037,6 +1053,9 @@ static HRESULT DataCacheEntry_Save(DataCacheEntry *cache_entry, IStorage *storag
     case CF_ENHMETAFILE:
         hr = save_emf(cache_entry, contents, stream);
         break;
+    case 0:
+        hr = save_view_cache(cache_entry, stream);
+        break;
     default:
         FIXME("got unsupported clipboard format %x\n", cache_entry->fmtetc.cfFormat);
     }
diff --git a/dlls/ole32/tests/ole2.c b/dlls/ole32/tests/ole2.c
index fe45c6a73e..7fcb1aa1e0 100644
--- a/dlls/ole32/tests/ole2.c
+++ b/dlls/ole32/tests/ole2.c
@@ -3986,13 +3986,18 @@ static void check_storage_contents(IStorage *stg, const struct storage_def *stg_
         hr = IStorage_OpenStream(stg, stat.pwcsName, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream);
         ok(hr == S_OK, "unexpected %#x\n", hr);
 
-        if (!memcmp(name, "\2OlePres", 7))
+        if (!memcmp(name, "\2OlePres", 8))
         {
+            ULONG header_size = sizeof(header);
+
             clipformat = read_clipformat(stream);
 
-            hr = IStream_Read(stream, &header, sizeof(header), &bytes);
+            if (clipformat == 0) /* view cache */
+                header_size = FIELD_OFFSET(PresentationDataHeader, unknown7);
+
+            hr = IStream_Read(stream, &header, header_size, &bytes);
             ok(hr == S_OK, "unexpected %#x\n", hr);
-            ok(bytes >= 24, "read %u bytes\n", bytes);
+            ok(bytes == header_size, "read %u bytes, expected %u\n", bytes, header_size);
 
             if (winetest_debug > 1)
                 trace("header: tdSize %#x, dvAspect %#x, lindex %#x, advf %#x, unknown7 %#x, dwObjectExtentX %#x, dwObjectExtentY %#x, dwSize %#x\n",
@@ -4228,12 +4233,14 @@ static void test_data_cache_save_data(void)
                 { CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
                 { CF_METAFILEPICT, 0, DVASPECT_CONTENT, -1, TYMED_MFPICT },
                 { CF_ENHMETAFILE, 0, DVASPECT_CONTENT, -1, TYMED_ENHMF },
+                { 0, 0, DVASPECT_DOCPRINT, -1, TYMED_HGLOBAL },
             },
-            3, 3, &CLSID_WineTest,
+            4, 3, &CLSID_WineTest,
             {
-                &CLSID_WineTestOld, 3, { { "\2OlePres000", CF_DIB, DVASPECT_CONTENT, 0, NULL, 0 },
+                &CLSID_WineTestOld, 4, { { "\2OlePres000", CF_DIB, DVASPECT_CONTENT, 0, NULL, 0 },
                                          { "\2OlePres001", CF_METAFILEPICT, DVASPECT_CONTENT, 0, NULL, 0 },
-                                         { "\2OlePres002", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 } }
+                                         { "\2OlePres002", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 },
+                                         { "\2OlePres003", 0, DVASPECT_DOCPRINT, 0, NULL, 0 } }
             }
         },
         /* without setting data */
-- 
2.12.0




More information about the wine-devel mailing list