4 * Implementation of OLE IPicture and related interfaces
6 * Copyright 2000 Huw D M Davies for CodeWeavers.
7 * Copyright 2001 Marcus Meissner
8 * Copyright 2008 Kirill K. Smirnov
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * Support PICTYPE_BITMAP and PICTYPE_ICON, although only bitmaps very well..
27 * Lots of methods are just stubs.
30 * NOTES (or things that msdn doesn't tell you)
32 * The width and height properties are returned in HIMETRIC units (0.01mm)
33 * IPicture::Render also uses these to select a region of the src picture.
34 * A bitmap's size is converted into these units by using the screen resolution
35 * thus an 8x8 bitmap on a 96dpi screen has a size of 212x212 (8/96 * 2540).
40 #include "wine/port.h"
50 #define NONAMELESSUNION
51 #define NONAMELESSSTRUCT
64 #include "wine/debug.h"
65 #include "wine/unicode.h"
66 #include "wine/library.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(ole);
72 /* Header for Aldus Placable Metafiles - a standard metafile follows */
73 typedef struct _APM_HEADER
95 } CURSORICONFILEDIRENTRY;
102 CURSORICONFILEDIRENTRY idEntries[1];
107 /*************************************************************************
108 * Declaration of implementation class
111 typedef struct OLEPictureImpl {
114 * IPicture handles IUnknown
117 const IPictureVtbl *lpVtbl;
118 const IDispatchVtbl *lpvtblIDispatch;
119 const IPersistStreamVtbl *lpvtblIPersistStream;
120 const IConnectionPointContainerVtbl *lpvtblIConnectionPointContainer;
122 /* Object reference count */
125 /* We own the object and must destroy it ourselves */
128 /* Picture description */
131 /* These are the pixel size of a bitmap */
135 /* And these are the size of the picture converted into HIMETRIC units */
136 OLE_XSIZE_HIMETRIC himetricWidth;
137 OLE_YSIZE_HIMETRIC himetricHeight;
139 IConnectionPoint *pCP;
144 /* Bitmap transparency mask */
152 BOOL bIsDirty; /* Set to TRUE if picture has changed */
153 unsigned int loadtime_magic; /* If a length header was found, saves value */
154 unsigned int loadtime_format; /* for PICTYPE_BITMAP only, keeps track of image format (GIF/BMP/JPEG) */
158 * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
161 static inline OLEPictureImpl *impl_from_IDispatch( IDispatch *iface )
163 return (OLEPictureImpl *)((char*)iface - FIELD_OFFSET(OLEPictureImpl, lpvtblIDispatch));
166 static inline OLEPictureImpl *impl_from_IPersistStream( IPersistStream *iface )
168 return (OLEPictureImpl *)((char*)iface - FIELD_OFFSET(OLEPictureImpl, lpvtblIPersistStream));
171 static inline OLEPictureImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
173 return (OLEPictureImpl *)((char*)iface - FIELD_OFFSET(OLEPictureImpl, lpvtblIConnectionPointContainer));
177 * Predeclare VTables. They get initialized at the end.
179 static const IPictureVtbl OLEPictureImpl_VTable;
180 static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable;
181 static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable;
182 static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable;
184 /***********************************************************************
185 * Implementation of the OLEPictureImpl class.
188 static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
192 TRACE("bitmap handle %p\n", This->desc.u.bmp.hbitmap);
193 if(GetObjectA(This->desc.u.bmp.hbitmap, sizeof(bm), &bm) != sizeof(bm)) {
194 ERR("GetObject fails\n");
197 This->origWidth = bm.bmWidth;
198 This->origHeight = bm.bmHeight;
199 /* The width and height are stored in HIMETRIC units (0.01 mm),
200 so we take our pixel width divide by pixels per inch and
201 multiply by 25.4 * 100 */
202 /* Should we use GetBitmapDimension if available? */
203 hdcRef = CreateCompatibleDC(0);
204 This->himetricWidth =(bm.bmWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
205 This->himetricHeight=(bm.bmHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
209 static void OLEPictureImpl_SetIcon(OLEPictureImpl * This)
213 TRACE("icon handle %p\n", This->desc.u.icon.hicon);
214 if (GetIconInfo(This->desc.u.icon.hicon, &infoIcon)) {
218 TRACE("bitmap handle for icon is %p\n", infoIcon.hbmColor);
219 if(GetObjectA(infoIcon.hbmColor ? infoIcon.hbmColor : infoIcon.hbmMask, sizeof(bm), &bm) != sizeof(bm)) {
220 ERR("GetObject fails on icon bitmap\n");
224 This->origWidth = bm.bmWidth;
225 This->origHeight = infoIcon.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
226 /* see comment on HIMETRIC on OLEPictureImpl_SetBitmap() */
228 This->himetricWidth = (This->origWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
229 This->himetricHeight= (This->origHeight *2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
230 ReleaseDC(0, hdcRef);
232 DeleteObject(infoIcon.hbmMask);
233 if (infoIcon.hbmColor) DeleteObject(infoIcon.hbmColor);
235 ERR("GetIconInfo() fails on icon %p\n", This->desc.u.icon.hicon);
239 /************************************************************************
240 * OLEPictureImpl_Construct
242 * This method will construct a new instance of the OLEPictureImpl
245 * The caller of this method must release the object when it's
248 static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
250 OLEPictureImpl* newObject = 0;
253 TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
256 * Allocate space for the object.
258 newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
264 * Initialize the virtual function table.
266 newObject->lpVtbl = &OLEPictureImpl_VTable;
267 newObject->lpvtblIDispatch = &OLEPictureImpl_IDispatch_VTable;
268 newObject->lpvtblIPersistStream = &OLEPictureImpl_IPersistStream_VTable;
269 newObject->lpvtblIConnectionPointContainer = &OLEPictureImpl_IConnectionPointContainer_VTable;
271 newObject->pCP = NULL;
272 CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
275 HeapFree(GetProcessHeap(), 0, newObject);
280 * Start with one reference count. The caller of this function
281 * must release the interface pointer when it is done.
284 newObject->hDCCur = 0;
286 newObject->fOwn = fOwn;
288 /* dunno about original value */
289 newObject->keepOrigFormat = TRUE;
291 newObject->hbmMask = NULL;
292 newObject->hbmXor = NULL;
293 newObject->loadtime_magic = 0xdeadbeef;
294 newObject->loadtime_format = 0;
295 newObject->bIsDirty = FALSE;
298 newObject->desc = *pictDesc;
300 switch(pictDesc->picType) {
302 OLEPictureImpl_SetBitmap(newObject);
305 case PICTYPE_METAFILE:
306 TRACE("metafile handle %p\n", pictDesc->u.wmf.hmeta);
307 newObject->himetricWidth = pictDesc->u.wmf.xExt;
308 newObject->himetricHeight = pictDesc->u.wmf.yExt;
312 /* not sure what to do here */
313 newObject->himetricWidth = newObject->himetricHeight = 0;
317 OLEPictureImpl_SetIcon(newObject);
319 case PICTYPE_ENHMETAFILE:
321 FIXME("Unsupported type %d\n", pictDesc->picType);
322 newObject->himetricWidth = newObject->himetricHeight = 0;
326 newObject->desc.picType = PICTYPE_UNINITIALIZED;
329 TRACE("returning %p\n", newObject);
333 /************************************************************************
334 * OLEPictureImpl_Destroy
336 * This method is called by the Release method when the reference
337 * count goes down to 0. It will free all resources used by
339 static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
341 TRACE("(%p)\n", Obj);
344 IConnectionPoint_Release(Obj->pCP);
346 if(Obj->fOwn) { /* We need to destroy the picture */
347 switch(Obj->desc.picType) {
349 DeleteObject(Obj->desc.u.bmp.hbitmap);
350 if (Obj->hbmMask != NULL) DeleteObject(Obj->hbmMask);
351 if (Obj->hbmXor != NULL) DeleteObject(Obj->hbmXor);
353 case PICTYPE_METAFILE:
354 DeleteMetaFile(Obj->desc.u.wmf.hmeta);
357 DestroyIcon(Obj->desc.u.icon.hicon);
359 case PICTYPE_ENHMETAFILE:
360 DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
363 case PICTYPE_UNINITIALIZED:
367 FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
371 HeapFree(GetProcessHeap(), 0, Obj->data);
372 HeapFree(GetProcessHeap(), 0, Obj);
376 /************************************************************************
377 * OLEPictureImpl_AddRef (IUnknown)
379 * See Windows documentation for more details on IUnknown methods.
381 static ULONG WINAPI OLEPictureImpl_AddRef(
384 OLEPictureImpl *This = (OLEPictureImpl *)iface;
385 ULONG refCount = InterlockedIncrement(&This->ref);
387 TRACE("(%p)->(ref before=%d)\n", This, refCount - 1);
392 /************************************************************************
393 * OLEPictureImpl_Release (IUnknown)
395 * See Windows documentation for more details on IUnknown methods.
397 static ULONG WINAPI OLEPictureImpl_Release(
400 OLEPictureImpl *This = (OLEPictureImpl *)iface;
401 ULONG refCount = InterlockedDecrement(&This->ref);
403 TRACE("(%p)->(ref before=%d)\n", This, refCount + 1);
406 * If the reference count goes down to 0, perform suicide.
408 if (!refCount) OLEPictureImpl_Destroy(This);
413 /************************************************************************
414 * OLEPictureImpl_QueryInterface (IUnknown)
416 * See Windows documentation for more details on IUnknown methods.
418 static HRESULT WINAPI OLEPictureImpl_QueryInterface(
423 OLEPictureImpl *This = (OLEPictureImpl *)iface;
424 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
427 * Perform a sanity check on the parameters.
429 if ( (This==0) || (ppvObject==0) )
433 * Initialize the return parameter.
438 * Compare the riid with the interface IDs implemented by this object.
440 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPicture, riid))
442 else if (IsEqualIID(&IID_IDispatch, riid))
443 *ppvObject = &This->lpvtblIDispatch;
444 else if (IsEqualIID(&IID_IPictureDisp, riid))
445 *ppvObject = &This->lpvtblIDispatch;
446 else if (IsEqualIID(&IID_IPersist, riid) || IsEqualIID(&IID_IPersistStream, riid))
447 *ppvObject = &This->lpvtblIPersistStream;
448 else if (IsEqualIID(&IID_IConnectionPointContainer, riid))
449 *ppvObject = &This->lpvtblIConnectionPointContainer;
452 * Check that we obtained an interface.
456 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
457 return E_NOINTERFACE;
461 * Query Interface always increases the reference count by one when it is
464 OLEPictureImpl_AddRef((IPicture*)This);
469 /***********************************************************************
470 * OLEPicture_SendNotify (internal)
472 * Sends notification messages of changed properties to any interested
475 static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
477 IEnumConnections *pEnum;
480 if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
482 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
483 IPropertyNotifySink *sink;
485 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
486 IPropertyNotifySink_OnChanged(sink, dispID);
487 IPropertyNotifySink_Release(sink);
488 IUnknown_Release(CD.pUnk);
490 IEnumConnections_Release(pEnum);
493 /************************************************************************
494 * OLEPictureImpl_get_Handle
496 static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
499 OLEPictureImpl *This = (OLEPictureImpl *)iface;
500 TRACE("(%p)->(%p)\n", This, phandle);
505 switch(This->desc.picType) {
507 case PICTYPE_UNINITIALIZED:
511 *phandle = HandleToUlong(This->desc.u.bmp.hbitmap);
513 case PICTYPE_METAFILE:
514 *phandle = HandleToUlong(This->desc.u.wmf.hmeta);
517 *phandle = HandleToUlong(This->desc.u.icon.hicon);
519 case PICTYPE_ENHMETAFILE:
520 *phandle = HandleToUlong(This->desc.u.emf.hemf);
523 FIXME("Unimplemented type %d\n", This->desc.picType);
526 TRACE("returning handle %08x\n", *phandle);
530 /************************************************************************
531 * OLEPictureImpl_get_hPal
533 static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
536 OLEPictureImpl *This = (OLEPictureImpl *)iface;
538 TRACE("(%p)->(%p)\n", This, phandle);
543 switch (This->desc.picType) {
544 case (UINT)PICTYPE_UNINITIALIZED:
550 *phandle = HandleToUlong(This->desc.u.bmp.hpal);
553 case PICTYPE_METAFILE:
557 case PICTYPE_ENHMETAFILE:
559 FIXME("unimplemented for type %d. Returning 0 palette.\n",
565 TRACE("returning 0x%08x, palette handle %08x\n", hres, *phandle);
569 /************************************************************************
570 * OLEPictureImpl_get_Type
572 static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
575 OLEPictureImpl *This = (OLEPictureImpl *)iface;
576 TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
581 *ptype = This->desc.picType;
585 /************************************************************************
586 * OLEPictureImpl_get_Width
588 static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
589 OLE_XSIZE_HIMETRIC *pwidth)
591 OLEPictureImpl *This = (OLEPictureImpl *)iface;
592 TRACE("(%p)->(%p): width is %d\n", This, pwidth, This->himetricWidth);
593 *pwidth = This->himetricWidth;
597 /************************************************************************
598 * OLEPictureImpl_get_Height
600 static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
601 OLE_YSIZE_HIMETRIC *pheight)
603 OLEPictureImpl *This = (OLEPictureImpl *)iface;
604 TRACE("(%p)->(%p): height is %d\n", This, pheight, This->himetricHeight);
605 *pheight = This->himetricHeight;
609 /************************************************************************
610 * OLEPictureImpl_Render
612 static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
613 LONG x, LONG y, LONG cx, LONG cy,
614 OLE_XPOS_HIMETRIC xSrc,
615 OLE_YPOS_HIMETRIC ySrc,
616 OLE_XSIZE_HIMETRIC cxSrc,
617 OLE_YSIZE_HIMETRIC cySrc,
620 OLEPictureImpl *This = (OLEPictureImpl *)iface;
621 TRACE("(%p)->(%p, (%d,%d), (%d,%d) <- (%d,%d), (%d,%d), %p)\n",
622 This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
624 TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
625 prcWBounds->right, prcWBounds->bottom);
627 if(cx == 0 || cy == 0 || cxSrc == 0 || cySrc == 0){
628 return CTL_E_INVALIDPROPERTYVALUE;
632 * While the documentation suggests this to be here (or after rendering?)
633 * it does cause an endless recursion in my sample app. -MM 20010804
634 OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
637 switch(This->desc.picType) {
638 case PICTYPE_UNINITIALIZED:
647 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
648 NB y-axis gets flipped */
650 hdcBmp = CreateCompatibleDC(0);
651 SetMapMode(hdcBmp, MM_ANISOTROPIC);
652 SetWindowOrgEx(hdcBmp, 0, 0, NULL);
653 SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
654 SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
655 SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
658 HDC hdcMask = CreateCompatibleDC(0);
659 HBITMAP hOldbm = SelectObject(hdcMask, This->hbmMask);
661 hbmpOld = SelectObject(hdcBmp, This->hbmXor);
663 SetMapMode(hdcMask, MM_ANISOTROPIC);
664 SetWindowOrgEx(hdcMask, 0, 0, NULL);
665 SetWindowExtEx(hdcMask, This->himetricWidth, This->himetricHeight, NULL);
666 SetViewportOrgEx(hdcMask, 0, This->origHeight, NULL);
667 SetViewportExtEx(hdcMask, This->origWidth, -This->origHeight, NULL);
669 SetBkColor(hdc, RGB(255, 255, 255));
670 SetTextColor(hdc, RGB(0, 0, 0));
671 StretchBlt(hdc, x, y, cx, cy, hdcMask, xSrc, ySrc, cxSrc, cySrc, SRCAND);
672 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCPAINT);
674 SelectObject(hdcMask, hOldbm);
677 hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
678 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
681 SelectObject(hdcBmp, hbmpOld);
686 FIXME("Not quite correct implementation of rendering icons...\n");
687 DrawIconEx(hdc, x, y, This->desc.u.icon.hicon, cx, cy, 0, NULL, DI_NORMAL);
690 case PICTYPE_METAFILE:
692 POINT prevOrg, prevWndOrg;
693 SIZE prevExt, prevWndExt;
696 /* Render the WMF to the appropriate location by setting the
697 appropriate ratio between "device units" and "logical units" */
698 oldmode = SetMapMode(hdc, MM_ANISOTROPIC);
699 /* For the "source rectangle" the y-axis must be inverted */
700 SetWindowOrgEx(hdc, xSrc, This->himetricHeight-ySrc, &prevWndOrg);
701 SetWindowExtEx(hdc, cxSrc, -cySrc, &prevWndExt);
702 /* For the "destination rectangle" no inversion is necessary */
703 SetViewportOrgEx(hdc, x, y, &prevOrg);
704 SetViewportExtEx(hdc, cx, cy, &prevExt);
706 if (!PlayMetaFile(hdc, This->desc.u.wmf.hmeta))
707 ERR("PlayMetaFile failed!\n");
709 /* We're done, restore the DC to the previous settings for converting
710 logical units to device units */
711 SetWindowExtEx(hdc, prevWndExt.cx, prevWndExt.cy, NULL);
712 SetWindowOrgEx(hdc, prevWndOrg.x, prevWndOrg.y, NULL);
713 SetViewportExtEx(hdc, prevExt.cx, prevExt.cy, NULL);
714 SetViewportOrgEx(hdc, prevOrg.x, prevOrg.y, NULL);
715 SetMapMode(hdc, oldmode);
719 case PICTYPE_ENHMETAFILE:
721 RECT rc = { x, y, x + cx, y + cy };
722 PlayEnhMetaFile(hdc, This->desc.u.emf.hemf, &rc);
727 FIXME("type %d not implemented\n", This->desc.picType);
733 /************************************************************************
734 * OLEPictureImpl_set_hPal
736 static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
739 OLEPictureImpl *This = (OLEPictureImpl *)iface;
740 FIXME("(%p)->(%08x): stub\n", This, hpal);
741 OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
745 /************************************************************************
746 * OLEPictureImpl_get_CurDC
748 static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
751 OLEPictureImpl *This = (OLEPictureImpl *)iface;
752 TRACE("(%p), returning %p\n", This, This->hDCCur);
753 if (phdc) *phdc = This->hDCCur;
757 /************************************************************************
758 * OLEPictureImpl_SelectPicture
760 static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
763 OLE_HANDLE *phbmpOut)
765 OLEPictureImpl *This = (OLEPictureImpl *)iface;
766 TRACE("(%p)->(%p, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
767 if (This->desc.picType == PICTYPE_BITMAP) {
768 SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
771 *phdcOut = This->hDCCur;
772 This->hDCCur = hdcIn;
774 *phbmpOut = HandleToUlong(This->desc.u.bmp.hbitmap);
777 FIXME("Don't know how to select picture type %d\n",This->desc.picType);
782 /************************************************************************
783 * OLEPictureImpl_get_KeepOriginalFormat
785 static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
788 OLEPictureImpl *This = (OLEPictureImpl *)iface;
789 TRACE("(%p)->(%p)\n", This, pfKeep);
792 *pfKeep = This->keepOrigFormat;
796 /************************************************************************
797 * OLEPictureImpl_put_KeepOriginalFormat
799 static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
802 OLEPictureImpl *This = (OLEPictureImpl *)iface;
803 TRACE("(%p)->(%d)\n", This, keep);
804 This->keepOrigFormat = keep;
805 /* FIXME: what DISPID notification here? */
809 /************************************************************************
810 * OLEPictureImpl_PictureChanged
812 static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
814 OLEPictureImpl *This = (OLEPictureImpl *)iface;
815 TRACE("(%p)->()\n", This);
816 OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
817 This->bIsDirty = TRUE;
821 /************************************************************************
822 * OLEPictureImpl_SaveAsFile
824 static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
829 OLEPictureImpl *This = (OLEPictureImpl *)iface;
830 FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This, pstream, SaveMemCopy, pcbSize);
831 return IStream_Write(pstream,This->data,This->datalen,(ULONG*)pcbSize);
834 /************************************************************************
835 * OLEPictureImpl_get_Attributes
837 static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
840 OLEPictureImpl *This = (OLEPictureImpl *)iface;
841 TRACE("(%p)->(%p).\n", This, pdwAttr);
847 switch (This->desc.picType) {
848 case PICTYPE_UNINITIALIZED:
849 case PICTYPE_NONE: break;
850 case PICTYPE_BITMAP: if (This->hbmMask) *pdwAttr = PICTURE_TRANSPARENT; break; /* not 'truly' scalable, see MSDN. */
851 case PICTYPE_ICON: *pdwAttr = PICTURE_TRANSPARENT;break;
852 case PICTYPE_ENHMETAFILE: /* fall through */
853 case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
854 default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
860 /************************************************************************
861 * IConnectionPointContainer
863 static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
864 IConnectionPointContainer* iface,
868 OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
870 return IPicture_QueryInterface((IPicture *)This,riid,ppvoid);
873 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
874 IConnectionPointContainer* iface)
876 OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
878 return IPicture_AddRef((IPicture *)This);
881 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
882 IConnectionPointContainer* iface)
884 OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
886 return IPicture_Release((IPicture *)This);
889 static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
890 IConnectionPointContainer* iface,
891 IEnumConnectionPoints** ppEnum)
893 OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
895 FIXME("(%p,%p), stub!\n",This,ppEnum);
899 static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
900 IConnectionPointContainer* iface,
902 IConnectionPoint **ppCP)
904 OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
905 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
909 if (IsEqualGUID(riid,&IID_IPropertyNotifySink))
910 return IConnectionPoint_QueryInterface(This->pCP,&IID_IConnectionPoint,(LPVOID)ppCP);
911 FIXME("no connection point for %s\n",debugstr_guid(riid));
912 return CONNECT_E_NOCONNECTION;
916 /************************************************************************
920 /************************************************************************
921 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
923 * See Windows documentation for more details on IUnknown methods.
925 static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
926 IPersistStream* iface,
930 OLEPictureImpl *This = impl_from_IPersistStream(iface);
932 return IPicture_QueryInterface((IPicture *)This, riid, ppvoid);
935 /************************************************************************
936 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
938 * See Windows documentation for more details on IUnknown methods.
940 static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
941 IPersistStream* iface)
943 OLEPictureImpl *This = impl_from_IPersistStream(iface);
945 return IPicture_AddRef((IPicture *)This);
948 /************************************************************************
949 * OLEPictureImpl_IPersistStream_Release (IUnknown)
951 * See Windows documentation for more details on IUnknown methods.
953 static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
954 IPersistStream* iface)
956 OLEPictureImpl *This = impl_from_IPersistStream(iface);
958 return IPicture_Release((IPicture *)This);
961 /************************************************************************
962 * OLEPictureImpl_IPersistStream_GetClassID
964 static HRESULT WINAPI OLEPictureImpl_GetClassID(
965 IPersistStream* iface,CLSID* pClassID)
967 TRACE("(%p)\n", pClassID);
968 *pClassID = CLSID_StdPicture;
972 /************************************************************************
973 * OLEPictureImpl_IPersistStream_IsDirty
975 static HRESULT WINAPI OLEPictureImpl_IsDirty(
976 IPersistStream* iface)
978 OLEPictureImpl *This = impl_from_IPersistStream(iface);
979 FIXME("(%p),stub!\n",This);
983 static HRESULT OLEPictureImpl_LoadDIB(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
985 BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
986 BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
989 /* Does not matter whether this is a coreheader or not, we only use
990 * components which are in both
993 This->desc.u.bmp.hbitmap = CreateDIBitmap(
1001 ReleaseDC(0, hdcref);
1002 if (This->desc.u.bmp.hbitmap == 0)
1004 This->desc.picType = PICTYPE_BITMAP;
1005 OLEPictureImpl_SetBitmap(This);
1009 static HRESULT OLEPictureImpl_LoadWICSource(OLEPictureImpl *This, IWICBitmapSource *src)
1012 BITMAPINFOHEADER bih;
1015 UINT stride, buffersize;
1018 IWICBitmapSource *real_source;
1020 COLORREF white = RGB(255, 255, 255), black = RGB(0, 0, 0);
1021 BOOL has_alpha=FALSE;
1023 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, src, &real_source);
1024 if (FAILED(hr)) return hr;
1026 hr = IWICBitmapSource_GetSize(real_source, &width, &height);
1027 if (FAILED(hr)) goto end;
1029 bih.biSize = sizeof(bih);
1030 bih.biWidth = width;
1031 bih.biHeight = -height;
1033 bih.biBitCount = 32;
1034 bih.biCompression = BI_RGB;
1035 bih.biSizeImage = 0;
1036 bih.biXPelsPerMeter = 4085; /* olepicture ignores the stored resolution */
1037 bih.biYPelsPerMeter = 4085;
1039 bih.biClrImportant = 0;
1042 buffersize = stride * height;
1044 bits = HeapAlloc(GetProcessHeap(), 0, buffersize);
1055 hr = IWICBitmapSource_CopyPixels(real_source, &rc, stride, buffersize, bits);
1060 This->desc.u.bmp.hbitmap = CreateDIBitmap(
1068 if (This->desc.u.bmp.hbitmap == 0)
1071 ReleaseDC(0, hdcref);
1075 This->desc.picType = PICTYPE_BITMAP;
1076 OLEPictureImpl_SetBitmap(This);
1078 /* set transparent pixels to black, all others to white */
1079 for(y = 0; y < height; y++){
1080 for(x = 0; x < width; x++){
1081 DWORD *pixel = (DWORD*)(bits + stride*y + 4*x);
1082 if((*pixel & 0x80000000) == 0)
1094 HDC hdcBmp, hdcXor, hdcMask;
1095 HBITMAP hbmoldBmp, hbmoldXor, hbmoldMask;
1097 This->hbmXor = CreateDIBitmap(
1106 This->hbmMask = CreateBitmap(width,-height,1,1,NULL);
1107 hdcBmp = CreateCompatibleDC(NULL);
1108 hdcXor = CreateCompatibleDC(NULL);
1109 hdcMask = CreateCompatibleDC(NULL);
1111 hbmoldBmp = SelectObject(hdcBmp,This->desc.u.bmp.hbitmap);
1112 hbmoldXor = SelectObject(hdcXor,This->hbmXor);
1113 hbmoldMask = SelectObject(hdcMask,This->hbmMask);
1115 SetBkColor(hdcXor,black);
1116 BitBlt(hdcMask,0,0,width,height,hdcXor,0,0,SRCCOPY);
1117 BitBlt(hdcXor,0,0,width,height,hdcBmp,0,0,SRCAND);
1119 SelectObject(hdcBmp,hbmoldBmp);
1120 SelectObject(hdcXor,hbmoldXor);
1121 SelectObject(hdcMask,hbmoldMask);
1128 ReleaseDC(0, hdcref);
1131 HeapFree(GetProcessHeap(), 0, bits);
1132 IWICBitmapSource_Release(real_source);
1136 static HRESULT OLEPictureImpl_LoadWICDecoder(OLEPictureImpl *This, REFCLSID decoder_clsid, BYTE *xbuf, ULONG xread)
1139 IWICImagingFactory *factory;
1140 IWICBitmapDecoder *decoder;
1141 IWICBitmapFrameDecode *framedecode;
1145 initresult = CoInitialize(NULL);
1147 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1148 &IID_IWICImagingFactory, (void**)&factory);
1149 if (SUCCEEDED(hr)) /* created factory */
1151 hr = IWICImagingFactory_CreateStream(factory, &stream);
1152 IWICImagingFactory_Release(factory);
1155 if (SUCCEEDED(hr)) /* created stream */
1157 hr = IWICStream_InitializeFromMemory(stream, xbuf, xread);
1159 if (SUCCEEDED(hr)) /* initialized stream */
1161 hr = CoCreateInstance(decoder_clsid, NULL, CLSCTX_INPROC_SERVER,
1162 &IID_IWICBitmapDecoder, (void**)&decoder);
1163 if (SUCCEEDED(hr)) /* created decoder */
1165 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnLoad);
1167 if (SUCCEEDED(hr)) /* initialized decoder */
1168 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
1170 IWICBitmapDecoder_Release(decoder);
1174 IWICStream_Release(stream);
1177 if (SUCCEEDED(hr)) /* got framedecode */
1179 hr = OLEPictureImpl_LoadWICSource(This, (IWICBitmapSource*)framedecode);
1180 IWICBitmapFrameDecode_Release(framedecode);
1183 if (SUCCEEDED(initresult)) CoUninitialize();
1187 /*****************************************************
1188 * start of Icon-specific code
1191 static HRESULT OLEPictureImpl_LoadIcon(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
1194 CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
1199 FIXME("icon.idReserved=%d\n",cifd->idReserved);
1200 FIXME("icon.idType=%d\n",cifd->idType);
1201 FIXME("icon.idCount=%d\n",cifd->idCount);
1203 for (i=0;i<cifd->idCount;i++) {
1204 FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
1205 FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
1206 FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
1207 FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
1208 FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
1209 FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
1210 FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
1211 FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
1215 /* If we have more than one icon, try to find the best.
1216 * this currently means '32 pixel wide'.
1218 if (cifd->idCount!=1) {
1219 for (i=0;i<cifd->idCount;i++) {
1220 if (cifd->idEntries[i].bWidth == 32)
1223 if (i==cifd->idCount) i=0;
1226 hicon = CreateIconFromResourceEx(
1227 xbuf+cifd->idEntries[i].dwDIBOffset,
1228 cifd->idEntries[i].dwDIBSize,
1231 cifd->idEntries[i].bWidth,
1232 cifd->idEntries[i].bHeight,
1236 ERR("CreateIcon failed.\n");
1239 This->desc.picType = PICTYPE_ICON;
1240 This->desc.u.icon.hicon = hicon;
1241 This->origWidth = cifd->idEntries[i].bWidth;
1242 This->origHeight = cifd->idEntries[i].bHeight;
1243 hdcRef = CreateCompatibleDC(0);
1244 This->himetricWidth =(cifd->idEntries[i].bWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
1245 This->himetricHeight=(cifd->idEntries[i].bHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
1251 static HRESULT OLEPictureImpl_LoadEnhMetafile(OLEPictureImpl *This,
1252 const BYTE *data, ULONG size)
1257 hemf = SetEnhMetaFileBits(size, data);
1258 if (!hemf) return E_FAIL;
1260 GetEnhMetaFileHeader(hemf, sizeof(hdr), &hdr);
1262 This->desc.picType = PICTYPE_ENHMETAFILE;
1263 This->desc.u.emf.hemf = hemf;
1265 This->origWidth = 0;
1266 This->origHeight = 0;
1267 This->himetricWidth = hdr.rclFrame.right - hdr.rclFrame.left;
1268 This->himetricHeight = hdr.rclFrame.bottom - hdr.rclFrame.top;
1273 static HRESULT OLEPictureImpl_LoadAPM(OLEPictureImpl *This,
1274 const BYTE *data, ULONG size)
1276 const APM_HEADER *header = (const APM_HEADER *)data;
1279 if (size < sizeof(APM_HEADER))
1281 if (header->key != 0x9ac6cdd7)
1284 /* SetMetaFileBitsEx performs data check on its own */
1285 hmf = SetMetaFileBitsEx(size - sizeof(*header), data + sizeof(*header));
1286 if (!hmf) return E_FAIL;
1288 This->desc.picType = PICTYPE_METAFILE;
1289 This->desc.u.wmf.hmeta = hmf;
1290 This->desc.u.wmf.xExt = 0;
1291 This->desc.u.wmf.yExt = 0;
1293 This->origWidth = 0;
1294 This->origHeight = 0;
1295 This->himetricWidth = MulDiv((INT)header->right - header->left, 2540, header->inch);
1296 This->himetricHeight = MulDiv((INT)header->bottom - header->top, 2540, header->inch);
1300 /************************************************************************
1301 * BITMAP FORMAT FLAGS -
1302 * Flags that differentiate between different types of bitmaps.
1305 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1306 #define BITMAP_FORMAT_JPEG 0xd8ff
1307 #define BITMAP_FORMAT_GIF 0x4947
1308 #define BITMAP_FORMAT_PNG 0x5089
1309 #define BITMAP_FORMAT_APM 0xcdd7
1311 /************************************************************************
1312 * OLEPictureImpl_IPersistStream_Load (IUnknown)
1314 * Loads the binary data from the IStream. Starts at current position.
1315 * There appears to be an 2 DWORD header:
1319 * Currently implemented: BITMAP, ICON, JPEG, GIF, WMF, EMF
1321 static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
1322 HRESULT hr = E_FAIL;
1323 BOOL headerisdata = FALSE;
1324 BOOL statfailed = FALSE;
1325 ULONG xread, toread;
1331 OLEPictureImpl *This = impl_from_IPersistStream(iface);
1333 TRACE("(%p,%p)\n",This,pStm);
1335 /****************************************************************************************
1336 * Part 1: Load the data
1338 /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
1339 * out whether we do.
1341 * UPDATE: the IStream can be mapped to a plain file instead of a stream in a
1342 * compound file. This may explain most, if not all, of the cases of "no
1343 * header", and the header validation should take this into account.
1344 * At least in Visual Basic 6, resource streams, valid headers are
1345 * header[0] == "lt\0\0",
1346 * header[1] == length_of_stream.
1348 * Also handle streams where we do not have a working "Stat" method by
1349 * reading all data until the end of the stream.
1351 hr=IStream_Stat(pStm,&statstg,STATFLAG_NONAME);
1353 TRACE("stat failed with hres %x, proceeding to read all data.\n",hr);
1355 /* we will read at least 8 byte ... just right below */
1356 statstg.cbSize.QuadPart = 8;
1361 headerisdata = FALSE;
1363 hr=IStream_Read(pStm,header,8,&xread);
1364 if (hr || xread!=8) {
1365 ERR("Failure while reading picture header (hr is %x, nread is %d).\n",hr,xread);
1366 return (hr?hr:E_FAIL);
1368 headerread += xread;
1371 if (!memcmp(&(header[0]),"lt\0\0", 4) && (statfailed || (header[1] + headerread <= statstg.cbSize.QuadPart))) {
1372 if (toread != 0 && toread != header[1])
1373 FIXME("varying lengths of image data (prev=%u curr=%u), only last one will be used\n",
1376 if (toread == 0) break;
1378 if (!memcmp(&(header[0]), "GIF8", 4) || /* GIF header */
1379 !memcmp(&(header[0]), "BM", 2) || /* BMP header */
1380 !memcmp(&(header[0]), "\xff\xd8", 2) || /* JPEG header */
1381 (header[0] == EMR_HEADER) || /* EMF header */
1382 (header[1] > statstg.cbSize.QuadPart)|| /* invalid size */
1384 ) {/* Found start of bitmap data */
1385 headerisdata = TRUE;
1387 toread = statstg.cbSize.QuadPart-8;
1391 FIXME("Unknown stream header magic: %08x\n", header[0]);
1395 } while (!headerisdata);
1397 if (statfailed) { /* we don't know the size ... read all we get */
1399 int origsize = sizeinc;
1402 TRACE("Reading all data from stream.\n");
1403 xbuf = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, origsize);
1405 memcpy (xbuf, header, 8);
1407 while (xread < origsize) {
1408 hr = IStream_Read(pStm,xbuf+xread,origsize-xread,&nread);
1413 if (!nread || hr) /* done, or error */
1415 if (xread == origsize) {
1416 origsize += sizeinc;
1417 sizeinc = 2*sizeinc; /* exponential increase */
1418 xbuf = HeapReAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, xbuf, origsize);
1422 TRACE("hr in no-stat loader case is %08x\n", hr);
1423 TRACE("loaded %d bytes.\n", xread);
1424 This->datalen = xread;
1427 This->datalen = toread+(headerisdata?8:0);
1428 xbuf = This->data = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, This->datalen);
1430 return E_OUTOFMEMORY;
1433 memcpy (xbuf, header, 8);
1435 while (xread < This->datalen) {
1437 hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
1442 if (xread != This->datalen)
1443 ERR("Could only read %d of %d bytes out of stream?\n",xread,This->datalen);
1445 if (This->datalen == 0) { /* Marks the "NONE" picture */
1446 This->desc.picType = PICTYPE_NONE;
1451 /****************************************************************************************
1452 * Part 2: Process the loaded data
1455 magic = xbuf[0] + (xbuf[1]<<8);
1456 This->loadtime_format = magic;
1459 case BITMAP_FORMAT_GIF: /* GIF */
1460 hr = OLEPictureImpl_LoadWICDecoder(This, &CLSID_WICGifDecoder, xbuf, xread);
1462 case BITMAP_FORMAT_JPEG: /* JPEG */
1463 hr = OLEPictureImpl_LoadWICDecoder(This, &CLSID_WICJpegDecoder, xbuf, xread);
1465 case BITMAP_FORMAT_BMP: /* Bitmap */
1466 hr = OLEPictureImpl_LoadDIB(This, xbuf, xread);
1468 case BITMAP_FORMAT_PNG: /* PNG */
1469 hr = OLEPictureImpl_LoadWICDecoder(This, &CLSID_WICPngDecoder, xbuf, xread);
1471 case BITMAP_FORMAT_APM: /* APM */
1472 hr = OLEPictureImpl_LoadAPM(This, xbuf, xread);
1474 case 0x0000: { /* ICON , first word is dwReserved */
1475 hr = OLEPictureImpl_LoadIcon(This, xbuf, xread);
1482 /* let's see if it's a EMF */
1483 hr = OLEPictureImpl_LoadEnhMetafile(This, xbuf, xread);
1484 if (hr == S_OK) break;
1486 FIXME("Unknown magic %04x, %d read bytes:\n",magic,xread);
1488 for (i=0;i<xread+8;i++) {
1489 if (i<8) MESSAGE("%02x ",((unsigned char*)header)[i]);
1490 else MESSAGE("%02x ",xbuf[i-8]);
1491 if (i % 10 == 9) MESSAGE("\n");
1497 This->bIsDirty = FALSE;
1499 /* FIXME: this notify is not really documented */
1501 OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1505 static int serializeBMP(HBITMAP hBitmap, void ** ppBuffer, unsigned int * pLength)
1509 BITMAPINFO * pInfoBitmap;
1510 int iNumPaletteEntries;
1511 unsigned char * pPixelData;
1512 BITMAPFILEHEADER * pFileHeader;
1513 BITMAPINFO * pInfoHeader;
1515 pInfoBitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1516 sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1518 /* Find out bitmap size and padded length */
1520 pInfoBitmap->bmiHeader.biSize = sizeof(pInfoBitmap->bmiHeader);
1521 GetDIBits(hDC, hBitmap, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS);
1523 /* Fetch bitmap palette & pixel data */
1525 pPixelData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pInfoBitmap->bmiHeader.biSizeImage);
1526 GetDIBits(hDC, hBitmap, 0, pInfoBitmap->bmiHeader.biHeight, pPixelData, pInfoBitmap, DIB_RGB_COLORS);
1528 /* Calculate the total length required for the BMP data */
1529 if (pInfoBitmap->bmiHeader.biClrUsed != 0) {
1530 iNumPaletteEntries = pInfoBitmap->bmiHeader.biClrUsed;
1531 if (iNumPaletteEntries > 256) iNumPaletteEntries = 256;
1533 if (pInfoBitmap->bmiHeader.biBitCount <= 8)
1534 iNumPaletteEntries = 1 << pInfoBitmap->bmiHeader.biBitCount;
1536 iNumPaletteEntries = 0;
1539 sizeof(BITMAPFILEHEADER) +
1540 sizeof(BITMAPINFOHEADER) +
1541 iNumPaletteEntries * sizeof(RGBQUAD) +
1542 pInfoBitmap->bmiHeader.biSizeImage;
1543 *ppBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *pLength);
1545 /* Fill the BITMAPFILEHEADER */
1546 pFileHeader = *ppBuffer;
1547 pFileHeader->bfType = BITMAP_FORMAT_BMP;
1548 pFileHeader->bfSize = *pLength;
1549 pFileHeader->bfOffBits =
1550 sizeof(BITMAPFILEHEADER) +
1551 sizeof(BITMAPINFOHEADER) +
1552 iNumPaletteEntries * sizeof(RGBQUAD);
1554 /* Fill the BITMAPINFOHEADER and the palette data */
1555 pInfoHeader = (BITMAPINFO *)((unsigned char *)(*ppBuffer) + sizeof(BITMAPFILEHEADER));
1556 memcpy(pInfoHeader, pInfoBitmap, sizeof(BITMAPINFOHEADER) + iNumPaletteEntries * sizeof(RGBQUAD));
1558 (unsigned char *)(*ppBuffer) +
1559 sizeof(BITMAPFILEHEADER) +
1560 sizeof(BITMAPINFOHEADER) +
1561 iNumPaletteEntries * sizeof(RGBQUAD),
1562 pPixelData, pInfoBitmap->bmiHeader.biSizeImage);
1565 HeapFree(GetProcessHeap(), 0, pPixelData);
1566 HeapFree(GetProcessHeap(), 0, pInfoBitmap);
1570 static int serializeIcon(HICON hIcon, void ** ppBuffer, unsigned int * pLength)
1575 *ppBuffer = NULL; *pLength = 0;
1576 if (GetIconInfo(hIcon, &infoIcon)) {
1578 BITMAPINFO * pInfoBitmap;
1579 unsigned char * pIconData = NULL;
1580 unsigned int iDataSize = 0;
1582 pInfoBitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1584 /* Find out icon size */
1586 pInfoBitmap->bmiHeader.biSize = sizeof(pInfoBitmap->bmiHeader);
1587 GetDIBits(hDC, infoIcon.hbmColor, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS);
1589 /* Auxiliary pointers */
1590 CURSORICONFILEDIR * pIconDir;
1591 CURSORICONFILEDIRENTRY * pIconEntry;
1592 BITMAPINFOHEADER * pIconBitmapHeader;
1593 unsigned int iOffsetPalette;
1594 unsigned int iOffsetColorData;
1595 unsigned int iOffsetMaskData;
1597 unsigned int iLengthScanLineMask;
1598 unsigned int iNumEntriesPalette;
1600 iLengthScanLineMask = ((pInfoBitmap->bmiHeader.biWidth + 31) >> 5) << 2;
1602 FIXME("DEBUG: bitmap size is %d x %d\n",
1603 pInfoBitmap->bmiHeader.biWidth,
1604 pInfoBitmap->bmiHeader.biHeight);
1605 FIXME("DEBUG: bitmap bpp is %d\n",
1606 pInfoBitmap->bmiHeader.biBitCount);
1607 FIXME("DEBUG: bitmap nplanes is %d\n",
1608 pInfoBitmap->bmiHeader.biPlanes);
1609 FIXME("DEBUG: bitmap biSizeImage is %u\n",
1610 pInfoBitmap->bmiHeader.biSizeImage);
1612 /* Let's start with one CURSORICONFILEDIR and one CURSORICONFILEDIRENTRY */
1613 iDataSize += 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY) + sizeof(BITMAPINFOHEADER);
1614 pIconData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, iDataSize);
1616 /* Fill out the CURSORICONFILEDIR */
1617 pIconDir = (CURSORICONFILEDIR *)pIconData;
1618 pIconDir->idType = 1;
1619 pIconDir->idCount = 1;
1621 /* Fill out the CURSORICONFILEDIRENTRY */
1622 pIconEntry = (CURSORICONFILEDIRENTRY *)(pIconData + 3 * sizeof(WORD));
1623 pIconEntry->bWidth = (unsigned char)pInfoBitmap->bmiHeader.biWidth;
1624 pIconEntry->bHeight = (unsigned char)pInfoBitmap->bmiHeader.biHeight;
1625 pIconEntry->bColorCount =
1626 (pInfoBitmap->bmiHeader.biBitCount < 8)
1627 ? 1 << pInfoBitmap->bmiHeader.biBitCount
1629 pIconEntry->xHotspot = pInfoBitmap->bmiHeader.biPlanes;
1630 pIconEntry->yHotspot = pInfoBitmap->bmiHeader.biBitCount;
1631 pIconEntry->dwDIBSize = 0;
1632 pIconEntry->dwDIBOffset = 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY);
1634 /* Fill out the BITMAPINFOHEADER */
1635 pIconBitmapHeader = (BITMAPINFOHEADER *)(pIconData + 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY));
1636 *pIconBitmapHeader = pInfoBitmap->bmiHeader;
1638 /* Find out whether a palette exists for the bitmap */
1639 if ( (pInfoBitmap->bmiHeader.biBitCount == 16 && pInfoBitmap->bmiHeader.biCompression == BI_RGB)
1640 || (pInfoBitmap->bmiHeader.biBitCount == 24)
1641 || (pInfoBitmap->bmiHeader.biBitCount == 32 && pInfoBitmap->bmiHeader.biCompression == BI_RGB)) {
1642 iNumEntriesPalette = pInfoBitmap->bmiHeader.biClrUsed;
1643 if (iNumEntriesPalette > 256) iNumEntriesPalette = 256;
1644 } else if ((pInfoBitmap->bmiHeader.biBitCount == 16 || pInfoBitmap->bmiHeader.biBitCount == 32)
1645 && pInfoBitmap->bmiHeader.biCompression == BI_BITFIELDS) {
1646 iNumEntriesPalette = 3;
1647 } else if (pInfoBitmap->bmiHeader.biBitCount <= 8) {
1648 iNumEntriesPalette = 1 << pInfoBitmap->bmiHeader.biBitCount;
1650 iNumEntriesPalette = 0;
1653 /* Add bitmap size and header size to icon data size. */
1654 iOffsetPalette = iDataSize;
1655 iDataSize += iNumEntriesPalette * sizeof(DWORD);
1656 iOffsetColorData = iDataSize;
1657 iDataSize += pIconBitmapHeader->biSizeImage;
1658 iOffsetMaskData = iDataSize;
1659 iDataSize += pIconBitmapHeader->biHeight * iLengthScanLineMask;
1660 pIconBitmapHeader->biSizeImage += pIconBitmapHeader->biHeight * iLengthScanLineMask;
1661 pIconBitmapHeader->biHeight *= 2;
1662 pIconData = HeapReAlloc(GetProcessHeap(), 0, pIconData, iDataSize);
1663 pIconEntry = (CURSORICONFILEDIRENTRY *)(pIconData + 3 * sizeof(WORD));
1664 pIconBitmapHeader = (BITMAPINFOHEADER *)(pIconData + 3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY));
1665 pIconEntry->dwDIBSize = iDataSize - (3 * sizeof(WORD) + sizeof(CURSORICONFILEDIRENTRY));
1667 /* Get the actual bitmap data from the icon bitmap */
1668 GetDIBits(hDC, infoIcon.hbmColor, 0, pInfoBitmap->bmiHeader.biHeight,
1669 pIconData + iOffsetColorData, pInfoBitmap, DIB_RGB_COLORS);
1670 if (iNumEntriesPalette > 0) {
1671 memcpy(pIconData + iOffsetPalette, pInfoBitmap->bmiColors,
1672 iNumEntriesPalette * sizeof(RGBQUAD));
1675 /* Reset all values so that GetDIBits call succeeds */
1676 memset(pIconData + iOffsetMaskData, 0, iDataSize - iOffsetMaskData);
1677 memset(pInfoBitmap, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1678 pInfoBitmap->bmiHeader.biSize = sizeof(pInfoBitmap->bmiHeader);
1680 if (!(GetDIBits(hDC, infoIcon.hbmMask, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS)
1681 && GetDIBits(hDC, infoIcon.hbmMask, 0, pIconEntry->bHeight,
1682 pIconData + iOffsetMaskData, pInfoBitmap, DIB_RGB_COLORS))) {
1684 printf("ERROR: unable to get bitmap mask (error %u)\n",
1689 GetDIBits(hDC, infoIcon.hbmMask, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS);
1690 GetDIBits(hDC, infoIcon.hbmMask, 0, pIconEntry->bHeight, pIconData + iOffsetMaskData, pInfoBitmap, DIB_RGB_COLORS);
1692 /* Write out everything produced so far to the stream */
1693 *ppBuffer = pIconData; *pLength = iDataSize;
1697 printf("ERROR: unable to get bitmap information via GetDIBits() (error %u)\n",
1702 Remarks (from MSDN entry on GetIconInfo):
1704 GetIconInfo creates bitmaps for the hbmMask and hbmColor
1705 members of ICONINFO. The calling application must manage
1706 these bitmaps and delete them when they are no longer
1709 if (hDC) ReleaseDC(0, hDC);
1710 DeleteObject(infoIcon.hbmMask);
1711 if (infoIcon.hbmColor) DeleteObject(infoIcon.hbmColor);
1712 HeapFree(GetProcessHeap(), 0, pInfoBitmap);
1714 printf("ERROR: Unable to get icon information (error %u)\n",
1720 static HRESULT WINAPI OLEPictureImpl_Save(
1721 IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1723 HRESULT hResult = E_NOTIMPL;
1725 unsigned int iDataSize;
1727 int iSerializeResult = 0;
1728 OLEPictureImpl *This = impl_from_IPersistStream(iface);
1730 TRACE("%p %p %d\n", This, pStm, fClearDirty);
1732 switch (This->desc.picType) {
1734 if (This->bIsDirty || !This->data) {
1735 if (!serializeIcon(This->desc.u.icon.hicon, &pIconData, &iDataSize)) {
1736 ERR("(%p,%p,%d), serializeIcon() failed\n", This, pStm, fClearDirty);
1740 HeapFree(GetProcessHeap(), 0, This->data);
1741 This->data = pIconData;
1742 This->datalen = iDataSize;
1744 if (This->loadtime_magic != 0xdeadbeef) {
1747 header[0] = This->loadtime_magic;
1748 header[1] = This->datalen;
1749 IStream_Write(pStm, header, 2 * sizeof(DWORD), &dummy);
1751 IStream_Write(pStm, This->data, This->datalen, &dummy);
1755 case PICTYPE_BITMAP:
1756 if (This->bIsDirty) {
1757 switch (This->keepOrigFormat ? This->loadtime_format : BITMAP_FORMAT_BMP) {
1758 case BITMAP_FORMAT_BMP:
1759 iSerializeResult = serializeBMP(This->desc.u.bmp.hbitmap, &pIconData, &iDataSize);
1761 case BITMAP_FORMAT_JPEG:
1762 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format JPEG) not implemented!\n",This,pStm,fClearDirty);
1764 case BITMAP_FORMAT_GIF:
1765 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format GIF) not implemented!\n",This,pStm,fClearDirty);
1767 case BITMAP_FORMAT_PNG:
1768 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format PNG) not implemented!\n",This,pStm,fClearDirty);
1771 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format UNKNOWN, using BMP?) not implemented!\n",This,pStm,fClearDirty);
1774 if (iSerializeResult) {
1776 if (This->loadtime_magic != 0xdeadbeef) {
1781 header[0] = (This->loadtime_magic != 0xdeadbeef) ? This->loadtime_magic : 0x0000746c;
1782 header[1] = iDataSize;
1783 IStream_Write(pStm, header, 2 * sizeof(DWORD), &dummy);
1785 IStream_Write(pStm, pIconData, iDataSize, &dummy);
1787 HeapFree(GetProcessHeap(), 0, This->data);
1788 This->data = pIconData;
1789 This->datalen = iDataSize;
1794 if (This->loadtime_magic != 0xdeadbeef) {
1799 header[0] = (This->loadtime_magic != 0xdeadbeef) ? This->loadtime_magic : 0x0000746c;
1800 header[1] = This->datalen;
1801 IStream_Write(pStm, header, 2 * sizeof(DWORD), &dummy);
1803 IStream_Write(pStm, This->data, This->datalen, &dummy);
1807 case PICTYPE_METAFILE:
1808 FIXME("(%p,%p,%d), PICTYPE_METAFILE not implemented!\n",This,pStm,fClearDirty);
1810 case PICTYPE_ENHMETAFILE:
1811 FIXME("(%p,%p,%d),PICTYPE_ENHMETAFILE not implemented!\n",This,pStm,fClearDirty);
1814 FIXME("(%p,%p,%d), [unknown type] not implemented!\n",This,pStm,fClearDirty);
1817 if (hResult == S_OK && fClearDirty) This->bIsDirty = FALSE;
1821 static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1822 IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1824 OLEPictureImpl *This = impl_from_IPersistStream(iface);
1825 FIXME("(%p,%p),stub!\n",This,pcbSize);
1830 /************************************************************************
1834 /************************************************************************
1835 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1837 * See Windows documentation for more details on IUnknown methods.
1839 static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1844 OLEPictureImpl *This = impl_from_IDispatch(iface);
1846 return IPicture_QueryInterface((IPicture *)This, riid, ppvoid);
1849 /************************************************************************
1850 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1852 * See Windows documentation for more details on IUnknown methods.
1854 static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1857 OLEPictureImpl *This = impl_from_IDispatch(iface);
1859 return IPicture_AddRef((IPicture *)This);
1862 /************************************************************************
1863 * OLEPictureImpl_IDispatch_Release (IUnknown)
1865 * See Windows documentation for more details on IUnknown methods.
1867 static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1870 OLEPictureImpl *This = impl_from_IDispatch(iface);
1872 return IPicture_Release((IPicture *)This);
1875 /************************************************************************
1876 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1878 * See Windows documentation for more details on IDispatch methods.
1880 static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1882 unsigned int* pctinfo)
1884 TRACE("(%p)\n", pctinfo);
1891 /************************************************************************
1892 * OLEPictureImpl_GetTypeInfo (IDispatch)
1894 * See Windows documentation for more details on IDispatch methods.
1896 static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1900 ITypeInfo** ppTInfo)
1902 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1906 TRACE("(iTInfo=%d, lcid=%04x, %p)\n", iTInfo, (int)lcid, ppTInfo);
1911 hres = LoadTypeLib(stdole2tlb, &tl);
1914 ERR("Could not load stdole2.tlb\n");
1918 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IPictureDisp, ppTInfo);
1920 ERR("Did not get IPictureDisp typeinfo from typelib, hres %x\n", hres);
1925 /************************************************************************
1926 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1928 * See Windows documentation for more details on IDispatch methods.
1930 static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1933 LPOLESTR* rgszNames,
1941 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", iface, debugstr_guid(riid),
1942 rgszNames, cNames, (int)lcid, rgDispId);
1946 return E_INVALIDARG;
1950 /* retrieve type information */
1951 hres = OLEPictureImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1955 ERR("GetTypeInfo failed.\n");
1959 /* convert names to DISPIDs */
1960 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1961 ITypeInfo_Release(pTInfo);
1967 /************************************************************************
1968 * OLEPictureImpl_Invoke (IDispatch)
1970 * See Windows documentation for more details on IDispatch methods.
1972 static HRESULT WINAPI OLEPictureImpl_Invoke(
1974 DISPID dispIdMember,
1978 DISPPARAMS* pDispParams,
1979 VARIANT* pVarResult,
1980 EXCEPINFO* pExepInfo,
1983 OLEPictureImpl *This = impl_from_IDispatch(iface);
1985 /* validate parameters */
1987 if (!IsEqualIID(riid, &IID_NULL))
1989 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1990 return DISP_E_UNKNOWNNAME;
1995 ERR("null pDispParams not allowed\n");
1996 return DISP_E_PARAMNOTOPTIONAL;
1999 if (wFlags & DISPATCH_PROPERTYGET)
2001 if (pDispParams->cArgs != 0)
2003 ERR("param count for DISPATCH_PROPERTYGET was %d instead of 0\n", pDispParams->cArgs);
2004 return DISP_E_BADPARAMCOUNT;
2008 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
2009 return DISP_E_PARAMNOTOPTIONAL;
2012 else if (wFlags & DISPATCH_PROPERTYPUT)
2014 if (pDispParams->cArgs != 1)
2016 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
2017 return DISP_E_BADPARAMCOUNT;
2021 switch (dispIdMember)
2023 case DISPID_PICT_HANDLE:
2024 if (wFlags & DISPATCH_PROPERTYGET)
2026 TRACE("DISPID_PICT_HANDLE\n");
2027 V_VT(pVarResult) = VT_I4;
2028 return IPicture_get_Handle((IPicture *)&This->lpVtbl, &V_UINT(pVarResult));
2031 case DISPID_PICT_HPAL:
2032 if (wFlags & DISPATCH_PROPERTYGET)
2034 TRACE("DISPID_PICT_HPAL\n");
2035 V_VT(pVarResult) = VT_I4;
2036 return IPicture_get_hPal((IPicture *)&This->lpVtbl, &V_UINT(pVarResult));
2038 else if (wFlags & DISPATCH_PROPERTYPUT)
2042 TRACE("DISPID_PICT_HPAL\n");
2044 VariantInit(&vararg);
2045 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I4);
2049 hr = IPicture_set_hPal((IPicture *)&This->lpVtbl, V_I4(&vararg));
2051 VariantClear(&vararg);
2055 case DISPID_PICT_TYPE:
2056 if (wFlags & DISPATCH_PROPERTYGET)
2058 TRACE("DISPID_PICT_TYPE\n");
2059 V_VT(pVarResult) = VT_I2;
2060 return OLEPictureImpl_get_Type((IPicture *)&This->lpVtbl, &V_I2(pVarResult));
2063 case DISPID_PICT_WIDTH:
2064 if (wFlags & DISPATCH_PROPERTYGET)
2066 TRACE("DISPID_PICT_WIDTH\n");
2067 V_VT(pVarResult) = VT_I4;
2068 return IPicture_get_Width((IPicture *)&This->lpVtbl, &V_I4(pVarResult));
2071 case DISPID_PICT_HEIGHT:
2072 if (wFlags & DISPATCH_PROPERTYGET)
2074 TRACE("DISPID_PICT_HEIGHT\n");
2075 V_VT(pVarResult) = VT_I4;
2076 return IPicture_get_Height((IPicture *)&This->lpVtbl, &V_I4(pVarResult));
2081 ERR("invalid dispid 0x%x or wFlags 0x%x\n", dispIdMember, wFlags);
2082 return DISP_E_MEMBERNOTFOUND;
2086 static const IPictureVtbl OLEPictureImpl_VTable =
2088 OLEPictureImpl_QueryInterface,
2089 OLEPictureImpl_AddRef,
2090 OLEPictureImpl_Release,
2091 OLEPictureImpl_get_Handle,
2092 OLEPictureImpl_get_hPal,
2093 OLEPictureImpl_get_Type,
2094 OLEPictureImpl_get_Width,
2095 OLEPictureImpl_get_Height,
2096 OLEPictureImpl_Render,
2097 OLEPictureImpl_set_hPal,
2098 OLEPictureImpl_get_CurDC,
2099 OLEPictureImpl_SelectPicture,
2100 OLEPictureImpl_get_KeepOriginalFormat,
2101 OLEPictureImpl_put_KeepOriginalFormat,
2102 OLEPictureImpl_PictureChanged,
2103 OLEPictureImpl_SaveAsFile,
2104 OLEPictureImpl_get_Attributes
2107 static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable =
2109 OLEPictureImpl_IDispatch_QueryInterface,
2110 OLEPictureImpl_IDispatch_AddRef,
2111 OLEPictureImpl_IDispatch_Release,
2112 OLEPictureImpl_GetTypeInfoCount,
2113 OLEPictureImpl_GetTypeInfo,
2114 OLEPictureImpl_GetIDsOfNames,
2115 OLEPictureImpl_Invoke
2118 static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable =
2120 OLEPictureImpl_IPersistStream_QueryInterface,
2121 OLEPictureImpl_IPersistStream_AddRef,
2122 OLEPictureImpl_IPersistStream_Release,
2123 OLEPictureImpl_GetClassID,
2124 OLEPictureImpl_IsDirty,
2125 OLEPictureImpl_Load,
2126 OLEPictureImpl_Save,
2127 OLEPictureImpl_GetSizeMax
2130 static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable =
2132 OLEPictureImpl_IConnectionPointContainer_QueryInterface,
2133 OLEPictureImpl_IConnectionPointContainer_AddRef,
2134 OLEPictureImpl_IConnectionPointContainer_Release,
2135 OLEPictureImpl_EnumConnectionPoints,
2136 OLEPictureImpl_FindConnectionPoint
2139 /***********************************************************************
2140 * OleCreatePictureIndirect (OLEAUT32.419)
2142 HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
2143 BOOL fOwn, LPVOID *ppvObj )
2145 OLEPictureImpl* newPict = NULL;
2148 TRACE("(%p,%s,%d,%p)\n", lpPictDesc, debugstr_guid(riid), fOwn, ppvObj);
2159 * Try to construct a new instance of the class.
2161 newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
2163 if (newPict == NULL)
2164 return E_OUTOFMEMORY;
2167 * Make sure it supports the interface required by the caller.
2169 hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
2172 * Release the reference obtained in the constructor. If
2173 * the QueryInterface was unsuccessful, it will free the class.
2175 IPicture_Release((IPicture*)newPict);
2181 /***********************************************************************
2182 * OleLoadPicture (OLEAUT32.418)
2184 HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
2185 REFIID riid, LPVOID *ppvObj )
2191 TRACE("(%p,%d,%d,%s,%p), partially implemented.\n",
2192 lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
2194 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
2197 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
2199 ERR("Could not get IPersistStream iface from Ole Picture?\n");
2200 IPicture_Release(newpic);
2204 hr = IPersistStream_Load(ps,lpstream);
2205 IPersistStream_Release(ps);
2208 ERR("IPersistStream_Load failed\n");
2209 IPicture_Release(newpic);
2213 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
2215 ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
2216 IPicture_Release(newpic);
2220 /***********************************************************************
2221 * OleLoadPictureEx (OLEAUT32.401)
2223 HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
2224 REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
2230 FIXME("(%p,%d,%d,%s,x=%d,y=%d,f=%x,%p), partially implemented.\n",
2231 lpstream, lSize, fRunmode, debugstr_guid(riid), xsiz, ysiz, flags, ppvObj);
2233 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
2236 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
2238 ERR("Could not get IPersistStream iface from Ole Picture?\n");
2239 IPicture_Release(newpic);
2243 hr = IPersistStream_Load(ps,lpstream);
2244 IPersistStream_Release(ps);
2247 ERR("IPersistStream_Load failed\n");
2248 IPicture_Release(newpic);
2252 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
2254 ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
2255 IPicture_Release(newpic);
2259 /***********************************************************************
2260 * OleLoadPicturePath (OLEAUT32.424)
2262 HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
2263 DWORD dwReserved, OLE_COLOR clrReserved, REFIID riid,
2266 static const WCHAR file[] = { 'f','i','l','e',':',0 };
2270 HGLOBAL hGlobal = NULL;
2271 DWORD dwBytesRead = 0;
2274 IPersistStream *pStream;
2277 WCHAR *file_candidate;
2278 WCHAR path_buf[MAX_PATH];
2280 TRACE("(%s,%p,%d,%08x,%s,%p): stub\n",
2281 debugstr_w(szURLorPath), punkCaller, dwReserved, clrReserved,
2282 debugstr_guid(riid), ppvRet);
2284 if (!szURLorPath || !ppvRet)
2285 return E_INVALIDARG;
2289 /* Convert file URLs to DOS paths. */
2290 if (strncmpW(szURLorPath, file, 5) == 0) {
2292 hRes = CoInternetParseUrl(szURLorPath, PARSE_PATH_FROM_URL, 0, path_buf,
2293 sizeof(path_buf)/sizeof(WCHAR), &size, 0);
2297 file_candidate = path_buf;
2300 file_candidate = szURLorPath;
2302 /* Handle candidate DOS paths separately. */
2303 if (file_candidate[1] == ':') {
2304 hFile = CreateFileW(file_candidate, GENERIC_READ, 0, NULL, OPEN_EXISTING,
2306 if (hFile == INVALID_HANDLE_VALUE)
2307 return E_UNEXPECTED;
2309 dwFileSize = GetFileSize(hFile, NULL);
2310 if (dwFileSize != INVALID_FILE_SIZE )
2312 hGlobal = GlobalAlloc(GMEM_FIXED,dwFileSize);
2315 bRead = ReadFile(hFile, hGlobal, dwFileSize, &dwBytesRead, NULL);
2318 GlobalFree(hGlobal);
2326 return E_UNEXPECTED;
2328 hRes = CreateStreamOnHGlobal(hGlobal, TRUE, &stream);
2331 GlobalFree(hGlobal);
2338 hRes = CreateBindCtx(0, &pbc);
2339 if (SUCCEEDED(hRes))
2341 hRes = CreateURLMoniker(NULL, szURLorPath, &pmnk);
2342 if (SUCCEEDED(hRes))
2344 hRes = IMoniker_BindToStorage(pmnk, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
2345 IMoniker_Release(pmnk);
2347 IBindCtx_Release(pbc);
2353 init_res = CoInitialize(NULL);
2355 hRes = CoCreateInstance(&CLSID_StdPicture, punkCaller, CLSCTX_INPROC_SERVER,
2356 &IID_IPicture, (LPVOID*)&ipicture);
2357 if (SUCCEEDED(hRes)) {
2358 hRes = IPicture_QueryInterface(ipicture, &IID_IPersistStream, (LPVOID*)&pStream);
2360 if (SUCCEEDED(hRes)) {
2361 hRes = IPersistStream_Load(pStream, stream);
2363 if (SUCCEEDED(hRes)) {
2364 hRes = IPicture_QueryInterface(ipicture, riid, ppvRet);
2367 ERR("Failed to get interface %s from IPicture.\n", debugstr_guid(riid));
2369 IPersistStream_Release(pStream);
2371 IPicture_Release(ipicture);
2374 IStream_Release(stream);
2376 if (SUCCEEDED(init_res))
2382 /*******************************************************************************
2383 * StdPic ClassFactory
2387 /* IUnknown fields */
2388 const IClassFactoryVtbl *lpVtbl;
2390 } IClassFactoryImpl;
2392 static HRESULT WINAPI
2393 SPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2394 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2396 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2397 return E_NOINTERFACE;
2401 SPCF_AddRef(LPCLASSFACTORY iface) {
2402 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2403 return InterlockedIncrement(&This->ref);
2406 static ULONG WINAPI SPCF_Release(LPCLASSFACTORY iface) {
2407 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2408 /* static class, won't be freed */
2409 return InterlockedDecrement(&This->ref);
2412 static HRESULT WINAPI SPCF_CreateInstance(
2413 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2415 /* Creates an uninitialized picture */
2416 return OleCreatePictureIndirect(NULL,riid,TRUE,ppobj);
2420 static HRESULT WINAPI SPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2421 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2422 FIXME("(%p)->(%d),stub!\n",This,dolock);
2426 static const IClassFactoryVtbl SPCF_Vtbl = {
2427 SPCF_QueryInterface,
2430 SPCF_CreateInstance,
2433 static IClassFactoryImpl STDPIC_CF = {&SPCF_Vtbl, 1 };
2435 void _get_STDPIC_CF(LPVOID *ppv) { *ppv = &STDPIC_CF; }