2 * Ole 2 Create functions implementation
4 * Copyright (C) 1999-2000 Abey George
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
38 #define MAX_CLIPFORMAT_NAME 80
40 /******************************************************************************
41 * OleQueryCreateFromData [OLE32.@]
43 * Author : Abey George
44 * Checks whether an object can become an embedded object.
45 * the clipboard or OLE drag and drop.
46 * Returns : S_OK - Format that supports Embedded object creation are present.
47 * OLE_E_STATIC - Format that supports static object creation are present.
48 * S_FALSE - No acceptable format is available.
51 HRESULT WINAPI
OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject
)
55 CHAR szFmtName
[MAX_CLIPFORMAT_NAME
];
56 BOOL bFoundStatic
= FALSE
;
58 HRESULT hr
= IDataObject_EnumFormatEtc(pSrcDataObject
, DATADIR_GET
, &pfmt
);
61 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
65 GetClipboardFormatNameA(fmt
.cfFormat
, szFmtName
, MAX_CLIPFORMAT_NAME
-1);
67 /* first, Check for Embedded Object, Embed Source or Filename */
69 if (!strcmp(szFmtName
, CF_EMBEDDEDOBJECT
) || !strcmp(szFmtName
, CF_EMBEDSOURCE
) || !strcmp(szFmtName
, CF_FILENAME
))
72 /* Check for Metafile, Bitmap or DIB */
74 if (fmt
.cfFormat
== CF_METAFILEPICT
|| fmt
.cfFormat
== CF_BITMAP
|| fmt
.cfFormat
== CF_DIB
)
77 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
80 /* Found a static format, but no embed format */
88 /******************************************************************************
89 * OleCreateFromData [OLE32.@]
91 * Author : Abey George
92 * Creates an embedded object from data transfer object retrieved from
93 * the clipboard or OLE drag and drop.
94 * Returns : S_OK - Embedded object was created successfully.
95 * OLE_E_STATIC - OLE can create only a static object
96 * DV_E_FORMATETC - No acceptable format is available (only error return code)
97 * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
100 HRESULT WINAPI
OleCreateFromData(LPDATAOBJECT pSrcDataObject
, REFIID riid
,
101 DWORD renderopt
, LPFORMATETC pFormatEtc
,
102 LPOLECLIENTSITE pClientSite
, LPSTORAGE pStg
,
105 IEnumFORMATETC
*pfmt
;
107 CHAR szFmtName
[MAX_CLIPFORMAT_NAME
];
112 hr
= IDataObject_EnumFormatEtc(pSrcDataObject
, DATADIR_GET
, &pfmt
);
116 memset(&std
, 0, sizeof(STGMEDIUM
));
118 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
121 GetClipboardFormatNameA(fmt
.cfFormat
, szFmtName
, MAX_CLIPFORMAT_NAME
-1);
123 /* first, Check for Embedded Object, Embed Source or Filename */
124 /* TODO: Currently checks only for Embed Source. */
126 if (!strcmp(szFmtName
, CF_EMBEDSOURCE
))
128 std
.tymed
= TYMED_HGLOBAL
;
130 if ((hr1
= IDataObject_GetData(pSrcDataObject
, &fmt
, &std
)) == S_OK
)
132 ILockBytes
*ptrILockBytes
= 0;
133 IStorage
*pStorage
= 0;
134 IOleObject
*pOleObject
= 0;
135 IPersistStorage
*pPersistStorage
= 0;
138 /* Create ILock bytes */
140 hr1
= CreateILockBytesOnHGlobal(std
.u
.hGlobal
, FALSE
, &ptrILockBytes
);
142 /* Open storage on the ILock bytes */
145 hr1
= StgOpenStorageOnILockBytes(ptrILockBytes
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &pStorage
);
147 /* Get Class ID from the opened storage */
150 hr1
= ReadClassStg(pStorage
, &clsID
);
152 /* Create default handler for Persist storage */
155 hr1
= OleCreateDefaultHandler(&clsID
, NULL
, &IID_IPersistStorage
, (LPVOID
*)&pPersistStorage
);
157 /* Load the storage to Persist storage */
160 hr1
= IPersistStorage_Load(pPersistStorage
, pStorage
);
162 /* Query for IOleObject */
165 hr1
= IPersistStorage_QueryInterface(pPersistStorage
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
167 /* Set client site with the IOleObject */
170 hr1
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
172 IPersistStorage_Release(pPersistStorage
);
173 /* Query for the requested interface */
176 hr1
= IPersistStorage_QueryInterface(pPersistStorage
, riid
, ppvObj
);
178 IPersistStorage_Release(pPersistStorage
);
180 IStorage_Release(pStorage
);
188 return DV_E_FORMATETC
;
191 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
195 return DV_E_FORMATETC
;
199 /******************************************************************************
200 * OleDuplicateData [OLE32.@]
202 * Duplicates clipboard data.
205 * hSrc [I] Handle of the source clipboard data.
206 * cfFormat [I] The clipboard format of hSrc.
207 * uiFlags [I] Flags to pass to GlobalAlloc.
210 * Success: handle to the duplicated data.
213 HANDLE WINAPI
OleDuplicateData(HANDLE hSrc
, CLIPFORMAT cfFormat
,
218 TRACE("(%p,%x,%x)\n", hSrc
, cfFormat
, uiFlags
);
220 if (!uiFlags
) uiFlags
= GMEM_MOVEABLE
;
225 hDst
= CopyEnhMetaFileW(hSrc
, NULL
);
227 case CF_METAFILEPICT
:
228 hDst
= CopyMetaFileW(hSrc
, NULL
);
232 LOGPALETTE
* logpalette
;
233 UINT nEntries
= GetPaletteEntries(hSrc
, 0, 0, NULL
);
234 if (!nEntries
) return NULL
;
235 logpalette
= HeapAlloc(GetProcessHeap(), 0,
236 FIELD_OFFSET(LOGPALETTE
, palPalEntry
[nEntries
]));
237 if (!logpalette
) return NULL
;
238 if (!GetPaletteEntries(hSrc
, 0, nEntries
, logpalette
->palPalEntry
))
240 HeapFree(GetProcessHeap(), 0, logpalette
);
243 logpalette
->palVersion
= 0x300;
244 logpalette
->palNumEntries
= (WORD
)nEntries
;
246 hDst
= CreatePalette(logpalette
);
248 HeapFree(GetProcessHeap(), 0, logpalette
);
255 if (!GetObjectW(hSrc
, sizeof(bm
), &bm
))
257 size
= GetBitmapBits(hSrc
, 0, NULL
);
258 if (!size
) return NULL
;
259 bm
.bmBits
= HeapAlloc(GetProcessHeap(), 0, size
);
260 if (!bm
.bmBits
) return NULL
;
261 if (GetBitmapBits(hSrc
, size
, bm
.bmBits
))
262 hDst
= CreateBitmapIndirect(&bm
);
263 HeapFree(GetProcessHeap(), 0, bm
.bmBits
);
268 SIZE_T size
= GlobalSize(hSrc
);
272 /* allocate space for object */
273 if (!size
) return NULL
;
274 hDst
= GlobalAlloc(uiFlags
, size
);
275 if (!hDst
) return NULL
;
278 pvSrc
= GlobalLock(hSrc
);
284 pvDst
= GlobalLock(hDst
);
292 memcpy(pvDst
, pvSrc
, size
);
300 TRACE("returning %p\n", hDst
);