Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenole2impl.c
Go to the documentation of this file.
00001 /* 00002 * Ole 2 Create functions implementation 00003 * 00004 * Copyright (C) 1999-2000 Abey George 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include <stdarg.h> 00022 #include <string.h> 00023 00024 #define COBJMACROS 00025 #define NONAMELESSUNION 00026 #define NONAMELESSSTRUCT 00027 00028 #include "windef.h" 00029 #include "winbase.h" 00030 #include "wingdi.h" 00031 #include "winuser.h" 00032 #include "wine/debug.h" 00033 #include "ole2.h" 00034 #include "olestd.h" 00035 #include "compobj_private.h" 00036 00037 WINE_DEFAULT_DEBUG_CHANNEL(ole); 00038 00039 #define MAX_CLIPFORMAT_NAME 80 00040 00041 /****************************************************************************** 00042 * OleQueryCreateFromData [OLE32.@] 00043 * 00044 * Checks whether an object can become an embedded object. 00045 * the clipboard or OLE drag and drop. 00046 * Returns : S_OK - Format that supports Embedded object creation are present. 00047 * OLE_E_STATIC - Format that supports static object creation are present. 00048 * S_FALSE - No acceptable format is available. 00049 */ 00050 00051 HRESULT WINAPI OleQueryCreateFromData(IDataObject *data) 00052 { 00053 IEnumFORMATETC *enum_fmt; 00054 FORMATETC fmt; 00055 BOOL found_static = FALSE; 00056 HRESULT hr; 00057 00058 hr = IDataObject_EnumFormatEtc(data, DATADIR_GET, &enum_fmt); 00059 00060 if(FAILED(hr)) return hr; 00061 00062 do 00063 { 00064 hr = IEnumFORMATETC_Next(enum_fmt, 1, &fmt, NULL); 00065 if(hr == S_OK) 00066 { 00067 if(fmt.cfFormat == embedded_object_clipboard_format || 00068 fmt.cfFormat == embed_source_clipboard_format || 00069 fmt.cfFormat == filename_clipboard_format) 00070 { 00071 IEnumFORMATETC_Release(enum_fmt); 00072 return S_OK; 00073 } 00074 00075 if(fmt.cfFormat == CF_METAFILEPICT || 00076 fmt.cfFormat == CF_BITMAP || 00077 fmt.cfFormat == CF_DIB) 00078 found_static = TRUE; 00079 } 00080 } while (hr == S_OK); 00081 00082 IEnumFORMATETC_Release(enum_fmt); 00083 00084 return found_static ? OLE_S_STATIC : S_FALSE; 00085 } 00086 00087 static inline void init_fmtetc(FORMATETC *fmt, CLIPFORMAT cf, TYMED tymed) 00088 { 00089 fmt->cfFormat = cf; 00090 fmt->ptd = NULL; 00091 fmt->dwAspect = DVASPECT_CONTENT; 00092 fmt->lindex = -1; 00093 fmt->tymed = tymed; 00094 } 00095 00096 /*************************************************************************** 00097 * get_storage 00098 * 00099 * Retrieve an object's storage from a variety of sources. 00100 * 00101 * FIXME: CF_FILENAME. 00102 */ 00103 static HRESULT get_storage(IDataObject *data, IStorage *stg, UINT *src_cf) 00104 { 00105 HRESULT hr; 00106 FORMATETC fmt; 00107 STGMEDIUM med; 00108 IPersistStorage *persist; 00109 CLSID clsid; 00110 00111 *src_cf = 0; 00112 00113 /* CF_EMBEDEDOBJECT */ 00114 init_fmtetc(&fmt, embedded_object_clipboard_format, TYMED_ISTORAGE); 00115 med.tymed = TYMED_ISTORAGE; 00116 med.u.pstg = stg; 00117 hr = IDataObject_GetDataHere(data, &fmt, &med); 00118 if(SUCCEEDED(hr)) 00119 { 00120 *src_cf = embedded_object_clipboard_format; 00121 return hr; 00122 } 00123 00124 /* CF_EMBEDSOURCE */ 00125 init_fmtetc(&fmt, embed_source_clipboard_format, TYMED_ISTORAGE); 00126 med.tymed = TYMED_ISTORAGE; 00127 med.u.pstg = stg; 00128 hr = IDataObject_GetDataHere(data, &fmt, &med); 00129 if(SUCCEEDED(hr)) 00130 { 00131 *src_cf = embed_source_clipboard_format; 00132 return hr; 00133 } 00134 00135 /* IPersistStorage */ 00136 hr = IDataObject_QueryInterface(data, &IID_IPersistStorage, (void**)&persist); 00137 if(FAILED(hr)) return hr; 00138 00139 hr = IPersistStorage_GetClassID(persist, &clsid); 00140 if(FAILED(hr)) goto end; 00141 00142 hr = IStorage_SetClass(stg, &clsid); 00143 if(FAILED(hr)) goto end; 00144 00145 hr = IPersistStorage_Save(persist, stg, FALSE); 00146 if(FAILED(hr)) goto end; 00147 00148 hr = IPersistStorage_SaveCompleted(persist, NULL); 00149 00150 end: 00151 IPersistStorage_Release(persist); 00152 00153 return hr; 00154 } 00155 00156 /****************************************************************************** 00157 * OleCreateFromDataEx [OLE32.@] 00158 * 00159 * Creates an embedded object from data transfer object retrieved from 00160 * the clipboard or OLE drag and drop. 00161 */ 00162 HRESULT WINAPI OleCreateFromDataEx(IDataObject *data, REFIID iid, DWORD flags, 00163 DWORD renderopt, ULONG num_cache_fmts, DWORD *adv_flags, FORMATETC *cache_fmts, 00164 IAdviseSink *sink, DWORD *conns, 00165 IOleClientSite *client_site, IStorage *stg, void **obj) 00166 { 00167 HRESULT hr; 00168 UINT src_cf; 00169 00170 FIXME("(%p, %s, %08x, %08x, %d, %p, %p, %p, %p, %p, %p, %p): stub\n", 00171 data, debugstr_guid(iid), flags, renderopt, num_cache_fmts, adv_flags, cache_fmts, 00172 sink, conns, client_site, stg, obj); 00173 00174 hr = get_storage(data, stg, &src_cf); 00175 if(FAILED(hr)) return hr; 00176 00177 hr = OleLoad(stg, iid, client_site, obj); 00178 if(FAILED(hr)) return hr; 00179 00180 /* FIXME: Init cache */ 00181 00182 return hr; 00183 } 00184 00185 /****************************************************************************** 00186 * OleCreateFromData [OLE32.@] 00187 */ 00188 HRESULT WINAPI OleCreateFromData(LPDATAOBJECT data, REFIID iid, 00189 DWORD renderopt, LPFORMATETC fmt, 00190 LPOLECLIENTSITE client_site, LPSTORAGE stg, 00191 LPVOID* obj) 00192 { 00193 DWORD advf = ADVF_PRIMEFIRST; 00194 00195 return OleCreateFromDataEx(data, iid, 0, renderopt, fmt ? 1 : 0, fmt ? &advf : NULL, 00196 fmt, NULL, NULL, client_site, stg, obj); 00197 } 00198 00199 00200 /****************************************************************************** 00201 * OleDuplicateData [OLE32.@] 00202 * 00203 * Duplicates clipboard data. 00204 * 00205 * PARAMS 00206 * hSrc [I] Handle of the source clipboard data. 00207 * cfFormat [I] The clipboard format of hSrc. 00208 * uiFlags [I] Flags to pass to GlobalAlloc. 00209 * 00210 * RETURNS 00211 * Success: handle to the duplicated data. 00212 * Failure: NULL. 00213 */ 00214 HANDLE WINAPI OleDuplicateData(HANDLE hSrc, CLIPFORMAT cfFormat, 00215 UINT uiFlags) 00216 { 00217 HANDLE hDst = NULL; 00218 00219 TRACE("(%p,%x,%x)\n", hSrc, cfFormat, uiFlags); 00220 00221 if (!uiFlags) uiFlags = GMEM_MOVEABLE; 00222 00223 switch (cfFormat) 00224 { 00225 case CF_ENHMETAFILE: 00226 hDst = CopyEnhMetaFileW(hSrc, NULL); 00227 break; 00228 case CF_METAFILEPICT: 00229 hDst = CopyMetaFileW(hSrc, NULL); 00230 break; 00231 case CF_PALETTE: 00232 { 00233 LOGPALETTE * logpalette; 00234 UINT nEntries = GetPaletteEntries(hSrc, 0, 0, NULL); 00235 if (!nEntries) return NULL; 00236 logpalette = HeapAlloc(GetProcessHeap(), 0, 00237 FIELD_OFFSET(LOGPALETTE, palPalEntry[nEntries])); 00238 if (!logpalette) return NULL; 00239 if (!GetPaletteEntries(hSrc, 0, nEntries, logpalette->palPalEntry)) 00240 { 00241 HeapFree(GetProcessHeap(), 0, logpalette); 00242 return NULL; 00243 } 00244 logpalette->palVersion = 0x300; 00245 logpalette->palNumEntries = (WORD)nEntries; 00246 00247 hDst = CreatePalette(logpalette); 00248 00249 HeapFree(GetProcessHeap(), 0, logpalette); 00250 break; 00251 } 00252 case CF_BITMAP: 00253 { 00254 LONG size; 00255 BITMAP bm; 00256 if (!GetObjectW(hSrc, sizeof(bm), &bm)) 00257 return NULL; 00258 size = GetBitmapBits(hSrc, 0, NULL); 00259 if (!size) return NULL; 00260 bm.bmBits = HeapAlloc(GetProcessHeap(), 0, size); 00261 if (!bm.bmBits) return NULL; 00262 if (GetBitmapBits(hSrc, size, bm.bmBits)) 00263 hDst = CreateBitmapIndirect(&bm); 00264 HeapFree(GetProcessHeap(), 0, bm.bmBits); 00265 break; 00266 } 00267 default: 00268 { 00269 SIZE_T size = GlobalSize(hSrc); 00270 LPVOID pvSrc = NULL; 00271 LPVOID pvDst = NULL; 00272 00273 /* allocate space for object */ 00274 if (!size) return NULL; 00275 hDst = GlobalAlloc(uiFlags, size); 00276 if (!hDst) return NULL; 00277 00278 /* lock pointers */ 00279 pvSrc = GlobalLock(hSrc); 00280 if (!pvSrc) 00281 { 00282 GlobalFree(hDst); 00283 return NULL; 00284 } 00285 pvDst = GlobalLock(hDst); 00286 if (!pvDst) 00287 { 00288 GlobalUnlock(hSrc); 00289 GlobalFree(hDst); 00290 return NULL; 00291 } 00292 /* copy data */ 00293 memcpy(pvDst, pvSrc, size); 00294 00295 /* cleanup */ 00296 GlobalUnlock(hDst); 00297 GlobalUnlock(hSrc); 00298 } 00299 } 00300 00301 TRACE("returning %p\n", hDst); 00302 return hDst; 00303 } Generated on Sun May 27 2012 04:25:39 for ReactOS by
1.7.6.1
|