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
64 #include "wine/debug.h"
65 #include "wine/unicode.h"
66 #include "wine/library.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(olepicture
);
70 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
71 #define BITMAP_FORMAT_JPEG 0xd8ff
72 #define BITMAP_FORMAT_GIF 0x4947
73 #define BITMAP_FORMAT_PNG 0x5089
74 #define BITMAP_FORMAT_APM 0xcdd7
78 /* Header for Aldus Placable Metafiles - a standard metafile follows */
79 typedef struct _APM_HEADER
101 } CURSORICONFILEDIRENTRY
;
108 CURSORICONFILEDIRENTRY idEntries
[1];
113 /*************************************************************************
114 * Declaration of implementation class
117 typedef struct OLEPictureImpl
{
120 * IPicture handles IUnknown
123 IPicture IPicture_iface
;
124 IDispatch IDispatch_iface
;
125 IPersistStream IPersistStream_iface
;
126 IConnectionPointContainer IConnectionPointContainer_iface
;
128 /* Object reference count */
131 /* We own the object and must destroy it ourselves */
134 /* Picture description */
137 /* These are the pixel size of a bitmap */
141 /* And these are the size of the picture converted into HIMETRIC units */
142 OLE_XSIZE_HIMETRIC himetricWidth
;
143 OLE_YSIZE_HIMETRIC himetricHeight
;
145 IConnectionPoint
*pCP
;
149 HBITMAP stock_bitmap
;
151 /* Bitmap transparency mask */
159 BOOL bIsDirty
; /* Set to TRUE if picture has changed */
160 unsigned int loadtime_magic
; /* If a length header was found, saves value */
161 unsigned int loadtime_format
; /* for PICTYPE_BITMAP only, keeps track of image format (GIF/BMP/JPEG) */
164 static inline OLEPictureImpl
*impl_from_IPicture(IPicture
*iface
)
166 return CONTAINING_RECORD(iface
, OLEPictureImpl
, IPicture_iface
);
169 static inline OLEPictureImpl
*impl_from_IDispatch( IDispatch
*iface
)
171 return CONTAINING_RECORD(iface
, OLEPictureImpl
, IDispatch_iface
);
174 static inline OLEPictureImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
176 return CONTAINING_RECORD(iface
, OLEPictureImpl
, IPersistStream_iface
);
179 static inline OLEPictureImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
181 return CONTAINING_RECORD(iface
, OLEPictureImpl
, IConnectionPointContainer_iface
);
185 * Predeclare VTables. They get initialized at the end.
187 static const IPictureVtbl OLEPictureImpl_VTable
;
188 static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable
;
189 static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable
;
190 static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable
;
192 /* pixels to HIMETRIC units conversion */
193 static inline OLE_XSIZE_HIMETRIC
xpixels_to_himetric(INT pixels
, HDC hdc
)
195 return MulDiv(pixels
, 2540, GetDeviceCaps(hdc
, LOGPIXELSX
));
198 static inline OLE_YSIZE_HIMETRIC
ypixels_to_himetric(INT pixels
, HDC hdc
)
200 return MulDiv(pixels
, 2540, GetDeviceCaps(hdc
, LOGPIXELSY
));
203 /***********************************************************************
204 * Implementation of the OLEPictureImpl class.
207 static void OLEPictureImpl_SetBitmap(OLEPictureImpl
*This
)
212 TRACE("bitmap handle %p\n", This
->desc
.u
.bmp
.hbitmap
);
213 if(GetObjectW(This
->desc
.u
.bmp
.hbitmap
, sizeof(bm
), &bm
) != sizeof(bm
)) {
214 ERR("GetObject fails\n");
217 This
->origWidth
= bm
.bmWidth
;
218 This
->origHeight
= bm
.bmHeight
;
220 TRACE("width %d, height %d, bpp %d\n", bm
.bmWidth
, bm
.bmHeight
, bm
.bmBitsPixel
);
222 /* The width and height are stored in HIMETRIC units (0.01 mm),
223 so we take our pixel width divide by pixels per inch and
224 multiply by 25.4 * 100 */
225 /* Should we use GetBitmapDimension if available? */
226 hdcRef
= CreateCompatibleDC(0);
228 This
->himetricWidth
= xpixels_to_himetric(bm
.bmWidth
, hdcRef
);
229 This
->himetricHeight
= ypixels_to_himetric(bm
.bmHeight
, hdcRef
);
230 This
->stock_bitmap
= GetCurrentObject( hdcRef
, OBJ_BITMAP
);
232 This
->loadtime_format
= BITMAP_FORMAT_BMP
;
237 static void OLEPictureImpl_SetIcon(OLEPictureImpl
* This
)
241 TRACE("icon handle %p\n", This
->desc
.u
.icon
.hicon
);
242 if (GetIconInfo(This
->desc
.u
.icon
.hicon
, &infoIcon
)) {
246 TRACE("bitmap handle for icon is %p\n", infoIcon
.hbmColor
);
247 if(GetObjectW(infoIcon
.hbmColor
? infoIcon
.hbmColor
: infoIcon
.hbmMask
, sizeof(bm
), &bm
) != sizeof(bm
)) {
248 ERR("GetObject fails on icon bitmap\n");
252 This
->origWidth
= bm
.bmWidth
;
253 This
->origHeight
= infoIcon
.hbmColor
? bm
.bmHeight
: bm
.bmHeight
/ 2;
254 /* see comment on HIMETRIC on OLEPictureImpl_SetBitmap() */
257 This
->himetricWidth
= xpixels_to_himetric(This
->origWidth
, hdcRef
);
258 This
->himetricHeight
= ypixels_to_himetric(This
->origHeight
, hdcRef
);
260 ReleaseDC(0, hdcRef
);
262 DeleteObject(infoIcon
.hbmMask
);
263 if (infoIcon
.hbmColor
) DeleteObject(infoIcon
.hbmColor
);
265 ERR("GetIconInfo() fails on icon %p\n", This
->desc
.u
.icon
.hicon
);
269 /************************************************************************
270 * OLEPictureImpl_Construct
272 * This method will construct a new instance of the OLEPictureImpl
275 * The caller of this method must release the object when it's
278 static OLEPictureImpl
* OLEPictureImpl_Construct(LPPICTDESC pictDesc
, BOOL fOwn
)
280 OLEPictureImpl
* newObject
= 0;
283 TRACE("(%p) type = %d\n", pictDesc
, pictDesc
->picType
);
286 * Allocate space for the object.
288 newObject
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(OLEPictureImpl
));
294 * Initialize the virtual function table.
296 newObject
->IPicture_iface
.lpVtbl
= &OLEPictureImpl_VTable
;
297 newObject
->IDispatch_iface
.lpVtbl
= &OLEPictureImpl_IDispatch_VTable
;
298 newObject
->IPersistStream_iface
.lpVtbl
= &OLEPictureImpl_IPersistStream_VTable
;
299 newObject
->IConnectionPointContainer_iface
.lpVtbl
= &OLEPictureImpl_IConnectionPointContainer_VTable
;
301 newObject
->pCP
= NULL
;
302 CreateConnectionPoint((IUnknown
*)newObject
,&IID_IPropertyNotifySink
,&newObject
->pCP
);
305 HeapFree(GetProcessHeap(), 0, newObject
);
310 * Start with one reference count. The caller of this function
311 * must release the interface pointer when it is done.
314 newObject
->hDCCur
= 0;
316 newObject
->fOwn
= fOwn
;
318 /* dunno about original value */
319 newObject
->keepOrigFormat
= TRUE
;
321 newObject
->hbmMask
= NULL
;
322 newObject
->hbmXor
= NULL
;
323 newObject
->loadtime_magic
= 0xdeadbeef;
324 newObject
->loadtime_format
= 0;
325 newObject
->bIsDirty
= FALSE
;
328 newObject
->desc
= *pictDesc
;
330 switch(pictDesc
->picType
) {
332 OLEPictureImpl_SetBitmap(newObject
);
335 case PICTYPE_METAFILE
:
336 TRACE("metafile handle %p\n", pictDesc
->u
.wmf
.hmeta
);
337 newObject
->himetricWidth
= pictDesc
->u
.wmf
.xExt
;
338 newObject
->himetricHeight
= pictDesc
->u
.wmf
.yExt
;
342 /* not sure what to do here */
343 newObject
->himetricWidth
= newObject
->himetricHeight
= 0;
347 OLEPictureImpl_SetIcon(newObject
);
349 case PICTYPE_ENHMETAFILE
:
351 FIXME("Unsupported type %d\n", pictDesc
->picType
);
352 newObject
->himetricWidth
= newObject
->himetricHeight
= 0;
356 newObject
->desc
.picType
= PICTYPE_UNINITIALIZED
;
359 TRACE("returning %p\n", newObject
);
363 /************************************************************************
364 * OLEPictureImpl_Destroy
366 * This method is called by the Release method when the reference
367 * count goes down to 0. It will free all resources used by
369 static void OLEPictureImpl_Destroy(OLEPictureImpl
* Obj
)
371 TRACE("(%p)\n", Obj
);
374 IConnectionPoint_Release(Obj
->pCP
);
376 if(Obj
->fOwn
) { /* We need to destroy the picture */
377 switch(Obj
->desc
.picType
) {
379 DeleteObject(Obj
->desc
.u
.bmp
.hbitmap
);
380 if (Obj
->hbmMask
!= NULL
) DeleteObject(Obj
->hbmMask
);
381 if (Obj
->hbmXor
!= NULL
) DeleteObject(Obj
->hbmXor
);
383 case PICTYPE_METAFILE
:
384 DeleteMetaFile(Obj
->desc
.u
.wmf
.hmeta
);
387 DestroyIcon(Obj
->desc
.u
.icon
.hicon
);
389 case PICTYPE_ENHMETAFILE
:
390 DeleteEnhMetaFile(Obj
->desc
.u
.emf
.hemf
);
393 case PICTYPE_UNINITIALIZED
:
397 FIXME("Unsupported type %d - unable to delete\n", Obj
->desc
.picType
);
401 HeapFree(GetProcessHeap(), 0, Obj
->data
);
402 HeapFree(GetProcessHeap(), 0, Obj
);
406 /************************************************************************
407 * OLEPictureImpl_AddRef (IUnknown)
409 * See Windows documentation for more details on IUnknown methods.
411 static ULONG WINAPI
OLEPictureImpl_AddRef(
414 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
415 ULONG refCount
= InterlockedIncrement(&This
->ref
);
417 TRACE("(%p)->(ref before=%d)\n", This
, refCount
- 1);
422 /************************************************************************
423 * OLEPictureImpl_Release (IUnknown)
425 * See Windows documentation for more details on IUnknown methods.
427 static ULONG WINAPI
OLEPictureImpl_Release(
430 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
431 ULONG refCount
= InterlockedDecrement(&This
->ref
);
433 TRACE("(%p)->(ref before=%d)\n", This
, refCount
+ 1);
436 * If the reference count goes down to 0, perform suicide.
438 if (!refCount
) OLEPictureImpl_Destroy(This
);
443 /************************************************************************
444 * OLEPictureImpl_QueryInterface (IUnknown)
446 * See Windows documentation for more details on IUnknown methods.
448 static HRESULT WINAPI
OLEPictureImpl_QueryInterface(
453 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
455 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
462 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IPicture
, riid
))
464 else if (IsEqualIID(&IID_IDispatch
, riid
))
465 *ppvObject
= &This
->IDispatch_iface
;
466 else if (IsEqualIID(&IID_IPictureDisp
, riid
))
467 *ppvObject
= &This
->IDispatch_iface
;
468 else if (IsEqualIID(&IID_IPersist
, riid
) || IsEqualIID(&IID_IPersistStream
, riid
))
469 *ppvObject
= &This
->IPersistStream_iface
;
470 else if (IsEqualIID(&IID_IConnectionPointContainer
, riid
))
471 *ppvObject
= &This
->IConnectionPointContainer_iface
;
475 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid
));
476 return E_NOINTERFACE
;
479 IPicture_AddRef(iface
);
484 /***********************************************************************
485 * OLEPicture_SendNotify (internal)
487 * Sends notification messages of changed properties to any interested
490 static void OLEPicture_SendNotify(OLEPictureImpl
* this, DISPID dispID
)
492 IEnumConnections
*pEnum
;
495 if (IConnectionPoint_EnumConnections(this->pCP
, &pEnum
) != S_OK
)
497 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
498 IPropertyNotifySink
*sink
;
500 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (LPVOID
)&sink
);
501 IPropertyNotifySink_OnChanged(sink
, dispID
);
502 IPropertyNotifySink_Release(sink
);
503 IUnknown_Release(CD
.pUnk
);
505 IEnumConnections_Release(pEnum
);
508 /************************************************************************
509 * OLEPictureImpl_get_Handle
511 static HRESULT WINAPI
OLEPictureImpl_get_Handle(IPicture
*iface
,
514 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
515 TRACE("(%p)->(%p)\n", This
, phandle
);
520 switch(This
->desc
.picType
) {
522 case PICTYPE_UNINITIALIZED
:
526 *phandle
= HandleToUlong(This
->desc
.u
.bmp
.hbitmap
);
528 case PICTYPE_METAFILE
:
529 *phandle
= HandleToUlong(This
->desc
.u
.wmf
.hmeta
);
532 *phandle
= HandleToUlong(This
->desc
.u
.icon
.hicon
);
534 case PICTYPE_ENHMETAFILE
:
535 *phandle
= HandleToUlong(This
->desc
.u
.emf
.hemf
);
538 FIXME("Unimplemented type %d\n", This
->desc
.picType
);
541 TRACE("returning handle %08x\n", *phandle
);
545 /************************************************************************
546 * OLEPictureImpl_get_hPal
548 static HRESULT WINAPI
OLEPictureImpl_get_hPal(IPicture
*iface
,
551 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
553 TRACE("(%p)->(%p)\n", This
, phandle
);
558 switch (This
->desc
.picType
) {
559 case (UINT
)PICTYPE_UNINITIALIZED
:
565 *phandle
= HandleToUlong(This
->desc
.u
.bmp
.hpal
);
568 case PICTYPE_METAFILE
:
572 case PICTYPE_ENHMETAFILE
:
574 FIXME("unimplemented for type %d. Returning 0 palette.\n",
580 TRACE("returning 0x%08x, palette handle %08x\n", hres
, *phandle
);
584 /************************************************************************
585 * OLEPictureImpl_get_Type
587 static HRESULT WINAPI
OLEPictureImpl_get_Type(IPicture
*iface
,
590 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
591 TRACE("(%p)->(%p): type is %d\n", This
, ptype
, This
->desc
.picType
);
596 *ptype
= This
->desc
.picType
;
600 /************************************************************************
601 * OLEPictureImpl_get_Width
603 static HRESULT WINAPI
OLEPictureImpl_get_Width(IPicture
*iface
,
604 OLE_XSIZE_HIMETRIC
*pwidth
)
606 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
607 TRACE("(%p)->(%p): width is %d\n", This
, pwidth
, This
->himetricWidth
);
608 *pwidth
= This
->himetricWidth
;
612 /************************************************************************
613 * OLEPictureImpl_get_Height
615 static HRESULT WINAPI
OLEPictureImpl_get_Height(IPicture
*iface
,
616 OLE_YSIZE_HIMETRIC
*pheight
)
618 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
619 TRACE("(%p)->(%p): height is %d\n", This
, pheight
, This
->himetricHeight
);
620 *pheight
= This
->himetricHeight
;
624 /************************************************************************
625 * OLEPictureImpl_Render
627 static HRESULT WINAPI
OLEPictureImpl_Render(IPicture
*iface
, HDC hdc
,
628 LONG x
, LONG y
, LONG cx
, LONG cy
,
629 OLE_XPOS_HIMETRIC xSrc
,
630 OLE_YPOS_HIMETRIC ySrc
,
631 OLE_XSIZE_HIMETRIC cxSrc
,
632 OLE_YSIZE_HIMETRIC cySrc
,
635 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
636 TRACE("(%p)->(%p, (%d,%d), (%d,%d) <- (%d,%d), (%d,%d), %p)\n",
637 This
, hdc
, x
, y
, cx
, cy
, xSrc
, ySrc
, cxSrc
, cySrc
, prcWBounds
);
639 TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds
->left
, prcWBounds
->top
,
640 prcWBounds
->right
, prcWBounds
->bottom
);
642 if(cx
== 0 || cy
== 0 || cxSrc
== 0 || cySrc
== 0){
643 return CTL_E_INVALIDPROPERTYVALUE
;
647 * While the documentation suggests this to be here (or after rendering?)
648 * it does cause an endless recursion in my sample app. -MM 20010804
649 OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
652 switch(This
->desc
.picType
) {
653 case PICTYPE_UNINITIALIZED
:
662 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
663 NB y-axis gets flipped */
665 hdcBmp
= CreateCompatibleDC(0);
666 SetMapMode(hdcBmp
, MM_ANISOTROPIC
);
667 SetWindowOrgEx(hdcBmp
, 0, 0, NULL
);
668 SetWindowExtEx(hdcBmp
, This
->himetricWidth
, This
->himetricHeight
, NULL
);
669 SetViewportOrgEx(hdcBmp
, 0, This
->origHeight
, NULL
);
670 SetViewportExtEx(hdcBmp
, This
->origWidth
, -This
->origHeight
, NULL
);
673 HDC hdcMask
= CreateCompatibleDC(0);
674 HBITMAP hOldbm
= SelectObject(hdcMask
, This
->hbmMask
);
676 hbmpOld
= SelectObject(hdcBmp
, This
->hbmXor
);
678 SetMapMode(hdcMask
, MM_ANISOTROPIC
);
679 SetWindowOrgEx(hdcMask
, 0, 0, NULL
);
680 SetWindowExtEx(hdcMask
, This
->himetricWidth
, This
->himetricHeight
, NULL
);
681 SetViewportOrgEx(hdcMask
, 0, This
->origHeight
, NULL
);
682 SetViewportExtEx(hdcMask
, This
->origWidth
, -This
->origHeight
, NULL
);
684 SetBkColor(hdc
, RGB(255, 255, 255));
685 SetTextColor(hdc
, RGB(0, 0, 0));
686 StretchBlt(hdc
, x
, y
, cx
, cy
, hdcMask
, xSrc
, ySrc
, cxSrc
, cySrc
, SRCAND
);
687 StretchBlt(hdc
, x
, y
, cx
, cy
, hdcBmp
, xSrc
, ySrc
, cxSrc
, cySrc
, SRCPAINT
);
689 SelectObject(hdcMask
, hOldbm
);
692 hbmpOld
= SelectObject(hdcBmp
, This
->desc
.u
.bmp
.hbitmap
);
693 StretchBlt(hdc
, x
, y
, cx
, cy
, hdcBmp
, xSrc
, ySrc
, cxSrc
, cySrc
, SRCCOPY
);
696 SelectObject(hdcBmp
, hbmpOld
);
701 FIXME("Not quite correct implementation of rendering icons...\n");
702 DrawIconEx(hdc
, x
, y
, This
->desc
.u
.icon
.hicon
, cx
, cy
, 0, NULL
, DI_NORMAL
);
705 case PICTYPE_METAFILE
:
707 POINT prevOrg
, prevWndOrg
;
708 SIZE prevExt
, prevWndExt
;
711 /* Render the WMF to the appropriate location by setting the
712 appropriate ratio between "device units" and "logical units" */
713 oldmode
= SetMapMode(hdc
, MM_ANISOTROPIC
);
714 /* For the "source rectangle" the y-axis must be inverted */
715 SetWindowOrgEx(hdc
, xSrc
, This
->himetricHeight
-ySrc
, &prevWndOrg
);
716 SetWindowExtEx(hdc
, cxSrc
, -cySrc
, &prevWndExt
);
717 /* For the "destination rectangle" no inversion is necessary */
718 SetViewportOrgEx(hdc
, x
, y
, &prevOrg
);
719 SetViewportExtEx(hdc
, cx
, cy
, &prevExt
);
721 if (!PlayMetaFile(hdc
, This
->desc
.u
.wmf
.hmeta
))
722 ERR("PlayMetaFile failed!\n");
724 /* We're done, restore the DC to the previous settings for converting
725 logical units to device units */
726 SetWindowExtEx(hdc
, prevWndExt
.cx
, prevWndExt
.cy
, NULL
);
727 SetWindowOrgEx(hdc
, prevWndOrg
.x
, prevWndOrg
.y
, NULL
);
728 SetViewportExtEx(hdc
, prevExt
.cx
, prevExt
.cy
, NULL
);
729 SetViewportOrgEx(hdc
, prevOrg
.x
, prevOrg
.y
, NULL
);
730 SetMapMode(hdc
, oldmode
);
734 case PICTYPE_ENHMETAFILE
:
736 RECT rc
= { x
, y
, x
+ cx
, y
+ cy
};
737 PlayEnhMetaFile(hdc
, This
->desc
.u
.emf
.hemf
, &rc
);
742 FIXME("type %d not implemented\n", This
->desc
.picType
);
748 /************************************************************************
749 * OLEPictureImpl_set_hPal
751 static HRESULT WINAPI
OLEPictureImpl_set_hPal(IPicture
*iface
,
754 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
755 FIXME("(%p)->(%08x): stub\n", This
, hpal
);
756 OLEPicture_SendNotify(This
,DISPID_PICT_HPAL
);
760 /************************************************************************
761 * OLEPictureImpl_get_CurDC
763 static HRESULT WINAPI
OLEPictureImpl_get_CurDC(IPicture
*iface
,
766 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
767 TRACE("(%p), returning %p\n", This
, This
->hDCCur
);
768 if (phdc
) *phdc
= This
->hDCCur
;
772 /************************************************************************
773 * OLEPictureImpl_SelectPicture
775 static HRESULT WINAPI
OLEPictureImpl_SelectPicture(IPicture
*iface
,
778 OLE_HANDLE
*phbmpOut
)
780 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
781 TRACE("(%p)->(%p, %p, %p)\n", This
, hdcIn
, phdcOut
, phbmpOut
);
782 if (This
->desc
.picType
== PICTYPE_BITMAP
) {
784 *phdcOut
= This
->hDCCur
;
785 if (This
->hDCCur
) SelectObject(This
->hDCCur
,This
->stock_bitmap
);
786 if (hdcIn
) SelectObject(hdcIn
,This
->desc
.u
.bmp
.hbitmap
);
787 This
->hDCCur
= hdcIn
;
789 *phbmpOut
= HandleToUlong(This
->desc
.u
.bmp
.hbitmap
);
792 FIXME("Don't know how to select picture type %d\n",This
->desc
.picType
);
797 /************************************************************************
798 * OLEPictureImpl_get_KeepOriginalFormat
800 static HRESULT WINAPI
OLEPictureImpl_get_KeepOriginalFormat(IPicture
*iface
,
803 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
804 TRACE("(%p)->(%p)\n", This
, pfKeep
);
807 *pfKeep
= This
->keepOrigFormat
;
811 /************************************************************************
812 * OLEPictureImpl_put_KeepOriginalFormat
814 static HRESULT WINAPI
OLEPictureImpl_put_KeepOriginalFormat(IPicture
*iface
,
817 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
818 TRACE("(%p)->(%d)\n", This
, keep
);
819 This
->keepOrigFormat
= keep
;
820 /* FIXME: what DISPID notification here? */
824 /************************************************************************
825 * OLEPictureImpl_PictureChanged
827 static HRESULT WINAPI
OLEPictureImpl_PictureChanged(IPicture
*iface
)
829 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
830 TRACE("(%p)->()\n", This
);
831 OLEPicture_SendNotify(This
,DISPID_PICT_HANDLE
);
832 This
->bIsDirty
= TRUE
;
836 /************************************************************************
837 * OLEPictureImpl_SaveAsFile
839 static HRESULT WINAPI
OLEPictureImpl_SaveAsFile(IPicture
*iface
,
844 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
845 FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This
, pstream
, SaveMemCopy
, pcbSize
);
846 return IStream_Write(pstream
,This
->data
,This
->datalen
,(ULONG
*)pcbSize
);
849 /************************************************************************
850 * OLEPictureImpl_get_Attributes
852 static HRESULT WINAPI
OLEPictureImpl_get_Attributes(IPicture
*iface
,
855 OLEPictureImpl
*This
= impl_from_IPicture(iface
);
856 TRACE("(%p)->(%p).\n", This
, pdwAttr
);
862 switch (This
->desc
.picType
) {
863 case PICTYPE_UNINITIALIZED
:
864 case PICTYPE_NONE
: break;
865 case PICTYPE_BITMAP
: if (This
->hbmMask
) *pdwAttr
= PICTURE_TRANSPARENT
; break; /* not 'truly' scalable, see MSDN. */
866 case PICTYPE_ICON
: *pdwAttr
= PICTURE_TRANSPARENT
;break;
867 case PICTYPE_ENHMETAFILE
: /* fall through */
868 case PICTYPE_METAFILE
: *pdwAttr
= PICTURE_TRANSPARENT
|PICTURE_SCALABLE
;break;
869 default:FIXME("Unknown pictype %d\n",This
->desc
.picType
);break;
875 /************************************************************************
876 * IConnectionPointContainer
878 static HRESULT WINAPI
OLEPictureImpl_IConnectionPointContainer_QueryInterface(
879 IConnectionPointContainer
* iface
,
883 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
885 return IPicture_QueryInterface(&This
->IPicture_iface
,riid
,ppvoid
);
888 static ULONG WINAPI
OLEPictureImpl_IConnectionPointContainer_AddRef(
889 IConnectionPointContainer
* iface
)
891 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
893 return IPicture_AddRef(&This
->IPicture_iface
);
896 static ULONG WINAPI
OLEPictureImpl_IConnectionPointContainer_Release(
897 IConnectionPointContainer
* iface
)
899 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
901 return IPicture_Release(&This
->IPicture_iface
);
904 static HRESULT WINAPI
OLEPictureImpl_EnumConnectionPoints(
905 IConnectionPointContainer
* iface
,
906 IEnumConnectionPoints
** ppEnum
)
908 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
910 FIXME("(%p,%p), stub!\n",This
,ppEnum
);
914 static HRESULT WINAPI
OLEPictureImpl_FindConnectionPoint(
915 IConnectionPointContainer
* iface
,
917 IConnectionPoint
**ppCP
)
919 OLEPictureImpl
*This
= impl_from_IConnectionPointContainer(iface
);
920 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppCP
);
924 if (IsEqualGUID(riid
,&IID_IPropertyNotifySink
))
925 return IConnectionPoint_QueryInterface(This
->pCP
, &IID_IConnectionPoint
, (void**)ppCP
);
926 FIXME("no connection point for %s\n",debugstr_guid(riid
));
927 return CONNECT_E_NOCONNECTION
;
931 /************************************************************************
935 /************************************************************************
936 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
938 * See Windows documentation for more details on IUnknown methods.
940 static HRESULT WINAPI
OLEPictureImpl_IPersistStream_QueryInterface(
941 IPersistStream
* iface
,
945 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
947 return IPicture_QueryInterface(&This
->IPicture_iface
, riid
, ppvoid
);
950 /************************************************************************
951 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
953 * See Windows documentation for more details on IUnknown methods.
955 static ULONG WINAPI
OLEPictureImpl_IPersistStream_AddRef(
956 IPersistStream
* iface
)
958 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
960 return IPicture_AddRef(&This
->IPicture_iface
);
963 /************************************************************************
964 * OLEPictureImpl_IPersistStream_Release (IUnknown)
966 * See Windows documentation for more details on IUnknown methods.
968 static ULONG WINAPI
OLEPictureImpl_IPersistStream_Release(
969 IPersistStream
* iface
)
971 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
973 return IPicture_Release(&This
->IPicture_iface
);
976 /************************************************************************
977 * OLEPictureImpl_IPersistStream_GetClassID
979 static HRESULT WINAPI
OLEPictureImpl_GetClassID(
980 IPersistStream
* iface
,CLSID
* pClassID
)
982 TRACE("(%p)\n", pClassID
);
983 *pClassID
= CLSID_StdPicture
;
987 /************************************************************************
988 * OLEPictureImpl_IPersistStream_IsDirty
990 static HRESULT WINAPI
OLEPictureImpl_IsDirty(
991 IPersistStream
* iface
)
993 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
994 FIXME("(%p),stub!\n",This
);
998 static HRESULT
OLEPictureImpl_LoadDIB(OLEPictureImpl
*This
, BYTE
*xbuf
, ULONG xread
)
1000 BITMAPFILEHEADER
*bfh
= (BITMAPFILEHEADER
*)xbuf
;
1001 BITMAPINFO
*bi
= (BITMAPINFO
*)(bfh
+1);
1004 /* Does not matter whether this is a coreheader or not, we only use
1005 * components which are in both
1008 This
->desc
.u
.bmp
.hbitmap
= CreateDIBitmap(
1012 xbuf
+bfh
->bfOffBits
,
1016 ReleaseDC(0, hdcref
);
1017 if (This
->desc
.u
.bmp
.hbitmap
== 0)
1019 This
->desc
.picType
= PICTYPE_BITMAP
;
1020 OLEPictureImpl_SetBitmap(This
);
1024 static HRESULT
OLEPictureImpl_LoadWICSource(OLEPictureImpl
*This
, IWICBitmapSource
*src
)
1027 BITMAPINFOHEADER bih
;
1030 UINT stride
, buffersize
;
1033 IWICBitmapSource
*real_source
;
1035 COLORREF white
= RGB(255, 255, 255), black
= RGB(0, 0, 0);
1036 BOOL has_alpha
=FALSE
;
1038 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, src
, &real_source
);
1039 if (FAILED(hr
)) return hr
;
1041 hr
= IWICBitmapSource_GetSize(real_source
, &width
, &height
);
1042 if (FAILED(hr
)) goto end
;
1044 bih
.biSize
= sizeof(bih
);
1045 bih
.biWidth
= width
;
1046 bih
.biHeight
= -height
;
1048 bih
.biBitCount
= 32;
1049 bih
.biCompression
= BI_RGB
;
1050 bih
.biSizeImage
= 0;
1051 bih
.biXPelsPerMeter
= 4085; /* olepicture ignores the stored resolution */
1052 bih
.biYPelsPerMeter
= 4085;
1054 bih
.biClrImportant
= 0;
1057 buffersize
= stride
* height
;
1059 bits
= HeapAlloc(GetProcessHeap(), 0, buffersize
);
1070 hr
= IWICBitmapSource_CopyPixels(real_source
, &rc
, stride
, buffersize
, bits
);
1075 This
->desc
.u
.bmp
.hbitmap
= CreateDIBitmap(
1083 if (This
->desc
.u
.bmp
.hbitmap
== 0)
1086 ReleaseDC(0, hdcref
);
1090 This
->desc
.picType
= PICTYPE_BITMAP
;
1091 OLEPictureImpl_SetBitmap(This
);
1093 /* set transparent pixels to black, all others to white */
1094 for(y
= 0; y
< height
; y
++){
1095 for(x
= 0; x
< width
; x
++){
1096 DWORD
*pixel
= (DWORD
*)(bits
+ stride
*y
+ 4*x
);
1097 if((*pixel
& 0x80000000) == 0)
1109 HDC hdcBmp
, hdcXor
, hdcMask
;
1110 HBITMAP hbmoldBmp
, hbmoldXor
, hbmoldMask
;
1112 This
->hbmXor
= CreateDIBitmap(
1121 This
->hbmMask
= CreateBitmap(width
,-height
,1,1,NULL
);
1122 hdcBmp
= CreateCompatibleDC(NULL
);
1123 hdcXor
= CreateCompatibleDC(NULL
);
1124 hdcMask
= CreateCompatibleDC(NULL
);
1126 hbmoldBmp
= SelectObject(hdcBmp
,This
->desc
.u
.bmp
.hbitmap
);
1127 hbmoldXor
= SelectObject(hdcXor
,This
->hbmXor
);
1128 hbmoldMask
= SelectObject(hdcMask
,This
->hbmMask
);
1130 SetBkColor(hdcXor
,black
);
1131 BitBlt(hdcMask
,0,0,width
,height
,hdcXor
,0,0,SRCCOPY
);
1132 BitBlt(hdcXor
,0,0,width
,height
,hdcBmp
,0,0,SRCAND
);
1134 SelectObject(hdcBmp
,hbmoldBmp
);
1135 SelectObject(hdcXor
,hbmoldXor
);
1136 SelectObject(hdcMask
,hbmoldMask
);
1143 ReleaseDC(0, hdcref
);
1146 HeapFree(GetProcessHeap(), 0, bits
);
1147 IWICBitmapSource_Release(real_source
);
1151 static HRESULT
OLEPictureImpl_LoadWICDecoder(OLEPictureImpl
*This
, REFCLSID decoder_clsid
, BYTE
*xbuf
, ULONG xread
)
1154 IWICImagingFactory
*factory
;
1155 IWICBitmapDecoder
*decoder
;
1156 IWICBitmapFrameDecode
*framedecode
;
1160 initresult
= CoInitialize(NULL
);
1162 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
1163 &IID_IWICImagingFactory
, (void**)&factory
);
1164 if (SUCCEEDED(hr
)) /* created factory */
1166 hr
= IWICImagingFactory_CreateStream(factory
, &stream
);
1167 IWICImagingFactory_Release(factory
);
1170 if (SUCCEEDED(hr
)) /* created stream */
1172 hr
= IWICStream_InitializeFromMemory(stream
, xbuf
, xread
);
1174 if (SUCCEEDED(hr
)) /* initialized stream */
1176 hr
= CoCreateInstance(decoder_clsid
, NULL
, CLSCTX_INPROC_SERVER
,
1177 &IID_IWICBitmapDecoder
, (void**)&decoder
);
1178 if (SUCCEEDED(hr
)) /* created decoder */
1180 hr
= IWICBitmapDecoder_Initialize(decoder
, (IStream
*)stream
, WICDecodeMetadataCacheOnLoad
);
1182 if (SUCCEEDED(hr
)) /* initialized decoder */
1183 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &framedecode
);
1185 IWICBitmapDecoder_Release(decoder
);
1189 IWICStream_Release(stream
);
1192 if (SUCCEEDED(hr
)) /* got framedecode */
1194 hr
= OLEPictureImpl_LoadWICSource(This
, (IWICBitmapSource
*)framedecode
);
1195 IWICBitmapFrameDecode_Release(framedecode
);
1198 if (SUCCEEDED(initresult
)) CoUninitialize();
1202 /*****************************************************
1203 * start of Icon-specific code
1206 static HRESULT
OLEPictureImpl_LoadIcon(OLEPictureImpl
*This
, BYTE
*xbuf
, ULONG xread
)
1209 CURSORICONFILEDIR
*cifd
= (CURSORICONFILEDIR
*)xbuf
;
1214 FIXME("icon.idReserved=%d\n",cifd->idReserved);
1215 FIXME("icon.idType=%d\n",cifd->idType);
1216 FIXME("icon.idCount=%d\n",cifd->idCount);
1218 for (i=0;i<cifd->idCount;i++) {
1219 FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
1220 FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
1221 FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
1222 FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
1223 FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
1224 FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
1225 FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
1226 FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
1230 /* If we have more than one icon, try to find the best.
1231 * this currently means '32 pixel wide'.
1233 if (cifd
->idCount
!=1) {
1234 for (i
=0;i
<cifd
->idCount
;i
++) {
1235 if (cifd
->idEntries
[i
].bWidth
== 32)
1238 if (i
==cifd
->idCount
) i
=0;
1240 if (cifd
->idType
== 2)
1242 LPBYTE buf
= HeapAlloc(GetProcessHeap(), 0, cifd
->idEntries
[i
].dwDIBSize
+ 4);
1243 memcpy(buf
, &cifd
->idEntries
[i
].xHotspot
, 4);
1244 memcpy(buf
+ 4, xbuf
+cifd
->idEntries
[i
].dwDIBOffset
, cifd
->idEntries
[i
].dwDIBSize
);
1245 hicon
= CreateIconFromResourceEx(
1247 cifd
->idEntries
[i
].dwDIBSize
+ 4,
1248 FALSE
, /* is cursor */
1250 cifd
->idEntries
[i
].bWidth
,
1251 cifd
->idEntries
[i
].bHeight
,
1254 HeapFree(GetProcessHeap(), 0, buf
);
1258 hicon
= CreateIconFromResourceEx(
1259 xbuf
+cifd
->idEntries
[i
].dwDIBOffset
,
1260 cifd
->idEntries
[i
].dwDIBSize
,
1263 cifd
->idEntries
[i
].bWidth
,
1264 cifd
->idEntries
[i
].bHeight
,
1269 ERR("CreateIcon failed.\n");
1272 This
->desc
.picType
= PICTYPE_ICON
;
1273 This
->desc
.u
.icon
.hicon
= hicon
;
1274 This
->origWidth
= cifd
->idEntries
[i
].bWidth
;
1275 This
->origHeight
= cifd
->idEntries
[i
].bHeight
;
1276 hdcRef
= CreateCompatibleDC(0);
1277 This
->himetricWidth
= xpixels_to_himetric(cifd
->idEntries
[i
].bWidth
, hdcRef
);
1278 This
->himetricHeight
= ypixels_to_himetric(cifd
->idEntries
[i
].bHeight
, hdcRef
);
1284 static HRESULT
OLEPictureImpl_LoadEnhMetafile(OLEPictureImpl
*This
,
1285 const BYTE
*data
, ULONG size
)
1290 hemf
= SetEnhMetaFileBits(size
, data
);
1291 if (!hemf
) return E_FAIL
;
1293 GetEnhMetaFileHeader(hemf
, sizeof(hdr
), &hdr
);
1295 This
->desc
.picType
= PICTYPE_ENHMETAFILE
;
1296 This
->desc
.u
.emf
.hemf
= hemf
;
1298 This
->origWidth
= 0;
1299 This
->origHeight
= 0;
1300 This
->himetricWidth
= hdr
.rclFrame
.right
- hdr
.rclFrame
.left
;
1301 This
->himetricHeight
= hdr
.rclFrame
.bottom
- hdr
.rclFrame
.top
;
1306 static HRESULT
OLEPictureImpl_LoadAPM(OLEPictureImpl
*This
,
1307 const BYTE
*data
, ULONG size
)
1309 const APM_HEADER
*header
= (const APM_HEADER
*)data
;
1312 if (size
< sizeof(APM_HEADER
))
1314 if (header
->key
!= 0x9ac6cdd7)
1317 /* SetMetaFileBitsEx performs data check on its own */
1318 hmf
= SetMetaFileBitsEx(size
- sizeof(*header
), data
+ sizeof(*header
));
1319 if (!hmf
) return E_FAIL
;
1321 This
->desc
.picType
= PICTYPE_METAFILE
;
1322 This
->desc
.u
.wmf
.hmeta
= hmf
;
1323 This
->desc
.u
.wmf
.xExt
= 0;
1324 This
->desc
.u
.wmf
.yExt
= 0;
1326 This
->origWidth
= 0;
1327 This
->origHeight
= 0;
1328 This
->himetricWidth
= MulDiv((INT
)header
->right
- header
->left
, 2540, header
->inch
);
1329 This
->himetricHeight
= MulDiv((INT
)header
->bottom
- header
->top
, 2540, header
->inch
);
1333 /************************************************************************
1334 * OLEPictureImpl_IPersistStream_Load (IUnknown)
1336 * Loads the binary data from the IStream. Starts at current position.
1337 * There appears to be an 2 DWORD header:
1341 * Currently implemented: BITMAP, ICON, CURSOR, JPEG, GIF, WMF, EMF
1343 static HRESULT WINAPI
OLEPictureImpl_Load(IPersistStream
* iface
, IStream
*pStm
) {
1346 BOOL statfailed
= FALSE
;
1347 ULONG xread
, toread
;
1353 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
1355 TRACE("(%p,%p)\n",This
,pStm
);
1357 /****************************************************************************************
1358 * Part 1: Load the data
1360 /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
1361 * out whether we do.
1363 * UPDATE: the IStream can be mapped to a plain file instead of a stream in a
1364 * compound file. This may explain most, if not all, of the cases of "no
1365 * header", and the header validation should take this into account.
1366 * At least in Visual Basic 6, resource streams, valid headers are
1367 * header[0] == "lt\0\0",
1368 * header[1] == length_of_stream.
1370 * Also handle streams where we do not have a working "Stat" method by
1371 * reading all data until the end of the stream.
1373 hr
= IStream_Stat(pStm
,&statstg
,STATFLAG_NONAME
);
1375 TRACE("stat failed with hres %x, proceeding to read all data.\n",hr
);
1377 /* we will read at least 8 byte ... just right below */
1378 statstg
.cbSize
.QuadPart
= 8;
1383 headerisdata
= FALSE
;
1385 hr
= IStream_Read(pStm
, header
, 8, &xread
);
1386 if (hr
!= S_OK
|| xread
!=8) {
1387 ERR("Failure while reading picture header (hr is %x, nread is %d).\n",hr
,xread
);
1388 return (hr
?hr
:E_FAIL
);
1390 headerread
+= xread
;
1393 if (!memcmp(&(header
[0]),"lt\0\0", 4) && (statfailed
|| (header
[1] + headerread
<= statstg
.cbSize
.QuadPart
))) {
1394 if (toread
!= 0 && toread
!= header
[1])
1395 FIXME("varying lengths of image data (prev=%u curr=%u), only last one will be used\n",
1400 statstg
.cbSize
.QuadPart
= header
[1] + 8;
1403 if (toread
== 0) break;
1405 if (!memcmp(&(header
[0]), "GIF8", 4) || /* GIF header */
1406 !memcmp(&(header
[0]), "BM", 2) || /* BMP header */
1407 !memcmp(&(header
[0]), "\xff\xd8", 2) || /* JPEG header */
1408 (header
[0] == EMR_HEADER
) || /* EMF header */
1409 (header
[0] == 0x10000) || /* icon: idReserved 0, idType 1 */
1410 (header
[0] == 0x20000) || /* cursor: idReserved 0, idType 2 */
1411 (header
[1] > statstg
.cbSize
.QuadPart
)|| /* invalid size */
1413 ) {/* Found start of bitmap data */
1414 headerisdata
= TRUE
;
1416 toread
= statstg
.cbSize
.QuadPart
-8;
1420 FIXME("Unknown stream header magic: %08x\n", header
[0]);
1424 } while (!headerisdata
);
1426 if (statfailed
) { /* we don't know the size ... read all we get */
1427 unsigned int sizeinc
= 4096;
1428 unsigned int origsize
= sizeinc
;
1431 TRACE("Reading all data from stream.\n");
1432 xbuf
= HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, origsize
);
1434 memcpy (xbuf
, header
, 8);
1436 while (xread
< origsize
) {
1437 hr
= IStream_Read(pStm
,xbuf
+xread
,origsize
-xread
,&nread
);
1439 if (hr
!= S_OK
|| !nread
)
1442 if (!nread
|| hr
!= S_OK
) /* done, or error */
1444 if (xread
== origsize
) {
1445 origsize
+= sizeinc
;
1446 sizeinc
= 2*sizeinc
; /* exponential increase */
1447 xbuf
= HeapReAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, xbuf
, origsize
);
1451 TRACE("hr in no-stat loader case is %08x\n", hr
);
1452 TRACE("loaded %d bytes.\n", xread
);
1453 This
->datalen
= xread
;
1456 This
->datalen
= toread
+(headerisdata
?8:0);
1457 xbuf
= This
->data
= HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->datalen
);
1459 return E_OUTOFMEMORY
;
1462 memcpy (xbuf
, header
, 8);
1464 while (xread
< This
->datalen
) {
1466 hr
= IStream_Read(pStm
,xbuf
+xread
,This
->datalen
-xread
,&nread
);
1468 if (hr
!= S_OK
|| !nread
)
1471 if (xread
!= This
->datalen
)
1472 ERR("Could only read %d of %d bytes out of stream?\n",xread
,This
->datalen
);
1474 if (This
->datalen
== 0) { /* Marks the "NONE" picture */
1475 This
->desc
.picType
= PICTYPE_NONE
;
1480 /****************************************************************************************
1481 * Part 2: Process the loaded data
1484 magic
= xbuf
[0] + (xbuf
[1]<<8);
1485 This
->loadtime_format
= magic
;
1488 case BITMAP_FORMAT_GIF
: /* GIF */
1489 hr
= OLEPictureImpl_LoadWICDecoder(This
, &CLSID_WICGifDecoder
, xbuf
, xread
);
1491 case BITMAP_FORMAT_JPEG
: /* JPEG */
1492 hr
= OLEPictureImpl_LoadWICDecoder(This
, &CLSID_WICJpegDecoder
, xbuf
, xread
);
1494 case BITMAP_FORMAT_BMP
: /* Bitmap */
1495 hr
= OLEPictureImpl_LoadDIB(This
, xbuf
, xread
);
1497 case BITMAP_FORMAT_PNG
: /* PNG */
1498 hr
= OLEPictureImpl_LoadWICDecoder(This
, &CLSID_WICPngDecoder
, xbuf
, xread
);
1500 case BITMAP_FORMAT_APM
: /* APM */
1501 hr
= OLEPictureImpl_LoadAPM(This
, xbuf
, xread
);
1503 case 0x0000: { /* ICON or CURSOR, first word is dwReserved */
1504 hr
= OLEPictureImpl_LoadIcon(This
, xbuf
, xread
);
1511 /* let's see if it's a EMF */
1512 hr
= OLEPictureImpl_LoadEnhMetafile(This
, xbuf
, xread
);
1513 if (hr
== S_OK
) break;
1515 FIXME("Unknown magic %04x, %d read bytes:\n",magic
,xread
);
1517 for (i
=0;i
<xread
+8;i
++) {
1518 if (i
<8) MESSAGE("%02x ",((unsigned char*)header
)[i
]);
1519 else MESSAGE("%02x ",xbuf
[i
-8]);
1520 if (i
% 10 == 9) MESSAGE("\n");
1526 This
->bIsDirty
= FALSE
;
1528 /* FIXME: this notify is not really documented */
1530 OLEPicture_SendNotify(This
,DISPID_PICT_TYPE
);
1534 static BOOL
serializeBMP(HBITMAP hBitmap
, void ** ppBuffer
, unsigned int * pLength
)
1536 BOOL success
= FALSE
;
1538 BITMAPINFO
* pInfoBitmap
;
1539 int iNumPaletteEntries
;
1540 unsigned char * pPixelData
;
1541 BITMAPFILEHEADER
* pFileHeader
;
1542 BITMAPINFO
* pInfoHeader
;
1544 pInfoBitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1545 sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1547 /* Find out bitmap size and padded length */
1549 pInfoBitmap
->bmiHeader
.biSize
= sizeof(pInfoBitmap
->bmiHeader
);
1550 GetDIBits(hDC
, hBitmap
, 0, 0, NULL
, pInfoBitmap
, DIB_RGB_COLORS
);
1552 /* Fetch bitmap palette & pixel data */
1554 pPixelData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, pInfoBitmap
->bmiHeader
.biSizeImage
);
1555 GetDIBits(hDC
, hBitmap
, 0, pInfoBitmap
->bmiHeader
.biHeight
, pPixelData
, pInfoBitmap
, DIB_RGB_COLORS
);
1557 /* Calculate the total length required for the BMP data */
1558 if (pInfoBitmap
->bmiHeader
.biClrUsed
!= 0) {
1559 iNumPaletteEntries
= pInfoBitmap
->bmiHeader
.biClrUsed
;
1560 if (iNumPaletteEntries
> 256) iNumPaletteEntries
= 256;
1562 if (pInfoBitmap
->bmiHeader
.biBitCount
<= 8)
1563 iNumPaletteEntries
= 1 << pInfoBitmap
->bmiHeader
.biBitCount
;
1565 iNumPaletteEntries
= 0;
1568 sizeof(BITMAPFILEHEADER
) +
1569 sizeof(BITMAPINFOHEADER
) +
1570 iNumPaletteEntries
* sizeof(RGBQUAD
) +
1571 pInfoBitmap
->bmiHeader
.biSizeImage
;
1572 *ppBuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *pLength
);
1574 /* Fill the BITMAPFILEHEADER */
1575 pFileHeader
= *ppBuffer
;
1576 pFileHeader
->bfType
= BITMAP_FORMAT_BMP
;
1577 pFileHeader
->bfSize
= *pLength
;
1578 pFileHeader
->bfOffBits
=
1579 sizeof(BITMAPFILEHEADER
) +
1580 sizeof(BITMAPINFOHEADER
) +
1581 iNumPaletteEntries
* sizeof(RGBQUAD
);
1583 /* Fill the BITMAPINFOHEADER and the palette data */
1584 pInfoHeader
= (BITMAPINFO
*)((unsigned char *)(*ppBuffer
) + sizeof(BITMAPFILEHEADER
));
1585 memcpy(pInfoHeader
, pInfoBitmap
, sizeof(BITMAPINFOHEADER
) + iNumPaletteEntries
* sizeof(RGBQUAD
));
1587 (unsigned char *)(*ppBuffer
) +
1588 sizeof(BITMAPFILEHEADER
) +
1589 sizeof(BITMAPINFOHEADER
) +
1590 iNumPaletteEntries
* sizeof(RGBQUAD
),
1591 pPixelData
, pInfoBitmap
->bmiHeader
.biSizeImage
);
1594 HeapFree(GetProcessHeap(), 0, pPixelData
);
1595 HeapFree(GetProcessHeap(), 0, pInfoBitmap
);
1599 static BOOL
serializeIcon(HICON hIcon
, void ** ppBuffer
, unsigned int * pLength
)
1602 BOOL success
= FALSE
;
1604 *ppBuffer
= NULL
; *pLength
= 0;
1605 if (GetIconInfo(hIcon
, &infoIcon
)) {
1607 BITMAPINFO
* pInfoBitmap
;
1608 unsigned char * pIconData
= NULL
;
1609 unsigned int iDataSize
= 0;
1611 pInfoBitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1613 /* Find out icon size */
1615 pInfoBitmap
->bmiHeader
.biSize
= sizeof(pInfoBitmap
->bmiHeader
);
1616 GetDIBits(hDC
, infoIcon
.hbmColor
, 0, 0, NULL
, pInfoBitmap
, DIB_RGB_COLORS
);
1618 /* Auxiliary pointers */
1619 CURSORICONFILEDIR
* pIconDir
;
1620 CURSORICONFILEDIRENTRY
* pIconEntry
;
1621 BITMAPINFOHEADER
* pIconBitmapHeader
;
1622 unsigned int iOffsetPalette
;
1623 unsigned int iOffsetColorData
;
1624 unsigned int iOffsetMaskData
;
1626 unsigned int iLengthScanLineMask
;
1627 unsigned int iNumEntriesPalette
;
1629 iLengthScanLineMask
= ((pInfoBitmap
->bmiHeader
.biWidth
+ 31) >> 5) << 2;
1631 FIXME("DEBUG: bitmap size is %d x %d\n",
1632 pInfoBitmap->bmiHeader.biWidth,
1633 pInfoBitmap->bmiHeader.biHeight);
1634 FIXME("DEBUG: bitmap bpp is %d\n",
1635 pInfoBitmap->bmiHeader.biBitCount);
1636 FIXME("DEBUG: bitmap nplanes is %d\n",
1637 pInfoBitmap->bmiHeader.biPlanes);
1638 FIXME("DEBUG: bitmap biSizeImage is %u\n",
1639 pInfoBitmap->bmiHeader.biSizeImage);
1641 /* Let's start with one CURSORICONFILEDIR and one CURSORICONFILEDIRENTRY */
1642 iDataSize
+= 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
) + sizeof(BITMAPINFOHEADER
);
1643 pIconData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, iDataSize
);
1645 /* Fill out the CURSORICONFILEDIR */
1646 pIconDir
= (CURSORICONFILEDIR
*)pIconData
;
1647 pIconDir
->idType
= 1;
1648 pIconDir
->idCount
= 1;
1649 pIconDir
->idReserved
= 0;
1651 /* Fill out the CURSORICONFILEDIRENTRY */
1652 pIconEntry
= (CURSORICONFILEDIRENTRY
*)(pIconData
+ 3 * sizeof(WORD
));
1653 pIconEntry
->bWidth
= (unsigned char)pInfoBitmap
->bmiHeader
.biWidth
;
1654 pIconEntry
->bHeight
= (unsigned char)pInfoBitmap
->bmiHeader
.biHeight
;
1655 pIconEntry
->bColorCount
=
1656 (pInfoBitmap
->bmiHeader
.biBitCount
< 8)
1657 ? 1 << pInfoBitmap
->bmiHeader
.biBitCount
1659 pIconEntry
->xHotspot
= pInfoBitmap
->bmiHeader
.biPlanes
;
1660 pIconEntry
->yHotspot
= pInfoBitmap
->bmiHeader
.biBitCount
;
1661 pIconEntry
->dwDIBSize
= 0;
1662 pIconEntry
->dwDIBOffset
= 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
);
1664 /* Fill out the BITMAPINFOHEADER */
1665 pIconBitmapHeader
= (BITMAPINFOHEADER
*)(pIconData
+ 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
));
1666 *pIconBitmapHeader
= pInfoBitmap
->bmiHeader
;
1668 /* Find out whether a palette exists for the bitmap */
1669 if ( (pInfoBitmap
->bmiHeader
.biBitCount
== 16 && pInfoBitmap
->bmiHeader
.biCompression
== BI_RGB
)
1670 || (pInfoBitmap
->bmiHeader
.biBitCount
== 24)
1671 || (pInfoBitmap
->bmiHeader
.biBitCount
== 32 && pInfoBitmap
->bmiHeader
.biCompression
== BI_RGB
)) {
1672 iNumEntriesPalette
= pInfoBitmap
->bmiHeader
.biClrUsed
;
1673 if (iNumEntriesPalette
> 256) iNumEntriesPalette
= 256;
1674 } else if ((pInfoBitmap
->bmiHeader
.biBitCount
== 16 || pInfoBitmap
->bmiHeader
.biBitCount
== 32)
1675 && pInfoBitmap
->bmiHeader
.biCompression
== BI_BITFIELDS
) {
1676 iNumEntriesPalette
= 3;
1677 } else if (pInfoBitmap
->bmiHeader
.biBitCount
<= 8) {
1678 iNumEntriesPalette
= 1 << pInfoBitmap
->bmiHeader
.biBitCount
;
1680 iNumEntriesPalette
= 0;
1683 /* Add bitmap size and header size to icon data size. */
1684 iOffsetPalette
= iDataSize
;
1685 iDataSize
+= iNumEntriesPalette
* sizeof(DWORD
);
1686 iOffsetColorData
= iDataSize
;
1687 iDataSize
+= pIconBitmapHeader
->biSizeImage
;
1688 iOffsetMaskData
= iDataSize
;
1689 iDataSize
+= pIconBitmapHeader
->biHeight
* iLengthScanLineMask
;
1690 pIconBitmapHeader
->biSizeImage
+= pIconBitmapHeader
->biHeight
* iLengthScanLineMask
;
1691 pIconBitmapHeader
->biHeight
*= 2;
1692 pIconData
= HeapReAlloc(GetProcessHeap(), 0, pIconData
, iDataSize
);
1693 pIconEntry
= (CURSORICONFILEDIRENTRY
*)(pIconData
+ 3 * sizeof(WORD
));
1694 pIconBitmapHeader
= (BITMAPINFOHEADER
*)(pIconData
+ 3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
));
1695 pIconEntry
->dwDIBSize
= iDataSize
- (3 * sizeof(WORD
) + sizeof(CURSORICONFILEDIRENTRY
));
1697 /* Get the actual bitmap data from the icon bitmap */
1698 GetDIBits(hDC
, infoIcon
.hbmColor
, 0, pInfoBitmap
->bmiHeader
.biHeight
,
1699 pIconData
+ iOffsetColorData
, pInfoBitmap
, DIB_RGB_COLORS
);
1700 if (iNumEntriesPalette
> 0) {
1701 memcpy(pIconData
+ iOffsetPalette
, pInfoBitmap
->bmiColors
,
1702 iNumEntriesPalette
* sizeof(RGBQUAD
));
1705 /* Reset all values so that GetDIBits call succeeds */
1706 memset(pIconData
+ iOffsetMaskData
, 0, iDataSize
- iOffsetMaskData
);
1707 memset(pInfoBitmap
, 0, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1708 pInfoBitmap
->bmiHeader
.biSize
= sizeof(pInfoBitmap
->bmiHeader
);
1710 if (!(GetDIBits(hDC, infoIcon.hbmMask, 0, 0, NULL, pInfoBitmap, DIB_RGB_COLORS)
1711 && GetDIBits(hDC, infoIcon.hbmMask, 0, pIconEntry->bHeight,
1712 pIconData + iOffsetMaskData, pInfoBitmap, DIB_RGB_COLORS))) {
1714 printf("ERROR: unable to get bitmap mask (error %u)\n",
1719 GetDIBits(hDC
, infoIcon
.hbmMask
, 0, 0, NULL
, pInfoBitmap
, DIB_RGB_COLORS
);
1720 GetDIBits(hDC
, infoIcon
.hbmMask
, 0, pIconEntry
->bHeight
, pIconData
+ iOffsetMaskData
, pInfoBitmap
, DIB_RGB_COLORS
);
1722 /* Write out everything produced so far to the stream */
1723 *ppBuffer
= pIconData
; *pLength
= iDataSize
;
1727 printf("ERROR: unable to get bitmap information via GetDIBits() (error %u)\n",
1732 Remarks (from MSDN entry on GetIconInfo):
1734 GetIconInfo creates bitmaps for the hbmMask and hbmColor
1735 members of ICONINFO. The calling application must manage
1736 these bitmaps and delete them when they are no longer
1739 if (hDC
) ReleaseDC(0, hDC
);
1740 DeleteObject(infoIcon
.hbmMask
);
1741 if (infoIcon
.hbmColor
) DeleteObject(infoIcon
.hbmColor
);
1742 HeapFree(GetProcessHeap(), 0, pInfoBitmap
);
1744 printf("ERROR: Unable to get icon information (error %u)\n",
1750 static HRESULT WINAPI
OLEPictureImpl_Save(
1751 IPersistStream
* iface
,IStream
*pStm
,BOOL fClearDirty
)
1753 HRESULT hResult
= E_NOTIMPL
;
1755 unsigned int iDataSize
;
1758 BOOL serializeResult
= FALSE
;
1759 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
1761 TRACE("%p %p %d\n", This
, pStm
, fClearDirty
);
1763 switch (This
->desc
.picType
) {
1765 header
[0] = 0x0000746c;
1767 hResult
= IStream_Write(pStm
, header
, 2 * sizeof(DWORD
), &dummy
);
1771 if (This
->bIsDirty
|| !This
->data
) {
1772 if (!serializeIcon(This
->desc
.u
.icon
.hicon
, &pIconData
, &iDataSize
)) {
1773 ERR("(%p,%p,%d), serializeIcon() failed\n", This
, pStm
, fClearDirty
);
1777 HeapFree(GetProcessHeap(), 0, This
->data
);
1778 This
->data
= pIconData
;
1779 This
->datalen
= iDataSize
;
1782 header
[0] = (This
->loadtime_magic
!= 0xdeadbeef) ? This
->loadtime_magic
: 0x0000746c;
1783 header
[1] = This
->datalen
;
1784 IStream_Write(pStm
, header
, 2 * sizeof(DWORD
), &dummy
);
1785 IStream_Write(pStm
, This
->data
, This
->datalen
, &dummy
);
1788 case PICTYPE_BITMAP
:
1789 if (This
->bIsDirty
|| !This
->data
) {
1790 switch (This
->keepOrigFormat
? This
->loadtime_format
: BITMAP_FORMAT_BMP
) {
1791 case BITMAP_FORMAT_BMP
:
1792 serializeResult
= serializeBMP(This
->desc
.u
.bmp
.hbitmap
, &pIconData
, &iDataSize
);
1794 case BITMAP_FORMAT_JPEG
:
1795 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format JPEG) not implemented!\n",This
,pStm
,fClearDirty
);
1797 case BITMAP_FORMAT_GIF
:
1798 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format GIF) not implemented!\n",This
,pStm
,fClearDirty
);
1800 case BITMAP_FORMAT_PNG
:
1801 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format PNG) not implemented!\n",This
,pStm
,fClearDirty
);
1804 FIXME("(%p,%p,%d), PICTYPE_BITMAP (format UNKNOWN, using BMP?) not implemented!\n",This
,pStm
,fClearDirty
);
1808 if (!serializeResult
)
1814 HeapFree(GetProcessHeap(), 0, This
->data
);
1815 This
->data
= pIconData
;
1816 This
->datalen
= iDataSize
;
1819 header
[0] = (This
->loadtime_magic
!= 0xdeadbeef) ? This
->loadtime_magic
: 0x0000746c;
1820 header
[1] = This
->datalen
;
1821 IStream_Write(pStm
, header
, 2 * sizeof(DWORD
), &dummy
);
1822 IStream_Write(pStm
, This
->data
, This
->datalen
, &dummy
);
1825 case PICTYPE_METAFILE
:
1826 FIXME("(%p,%p,%d), PICTYPE_METAFILE not implemented!\n",This
,pStm
,fClearDirty
);
1828 case PICTYPE_ENHMETAFILE
:
1829 FIXME("(%p,%p,%d),PICTYPE_ENHMETAFILE not implemented!\n",This
,pStm
,fClearDirty
);
1832 FIXME("(%p,%p,%d), [unknown type] not implemented!\n",This
,pStm
,fClearDirty
);
1835 if (hResult
== S_OK
&& fClearDirty
) This
->bIsDirty
= FALSE
;
1839 static HRESULT WINAPI
OLEPictureImpl_GetSizeMax(
1840 IPersistStream
* iface
,ULARGE_INTEGER
*pcbSize
)
1842 OLEPictureImpl
*This
= impl_from_IPersistStream(iface
);
1843 FIXME("(%p,%p),stub!\n",This
,pcbSize
);
1848 /************************************************************************
1852 /************************************************************************
1853 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1855 * See Windows documentation for more details on IUnknown methods.
1857 static HRESULT WINAPI
OLEPictureImpl_IDispatch_QueryInterface(
1862 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
1864 return IPicture_QueryInterface(&This
->IPicture_iface
, riid
, ppvoid
);
1867 /************************************************************************
1868 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1870 * See Windows documentation for more details on IUnknown methods.
1872 static ULONG WINAPI
OLEPictureImpl_IDispatch_AddRef(
1875 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
1877 return IPicture_AddRef(&This
->IPicture_iface
);
1880 /************************************************************************
1881 * OLEPictureImpl_IDispatch_Release (IUnknown)
1883 * See Windows documentation for more details on IUnknown methods.
1885 static ULONG WINAPI
OLEPictureImpl_IDispatch_Release(
1888 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
1890 return IPicture_Release(&This
->IPicture_iface
);
1893 /************************************************************************
1894 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1896 * See Windows documentation for more details on IDispatch methods.
1898 static HRESULT WINAPI
OLEPictureImpl_GetTypeInfoCount(
1900 unsigned int* pctinfo
)
1902 TRACE("(%p)\n", pctinfo
);
1909 /************************************************************************
1910 * OLEPictureImpl_GetTypeInfo (IDispatch)
1912 * See Windows documentation for more details on IDispatch methods.
1914 static HRESULT WINAPI
OLEPictureImpl_GetTypeInfo(
1918 ITypeInfo
** ppTInfo
)
1920 static const WCHAR stdole2tlb
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1924 TRACE("(iTInfo=%d, lcid=%04x, %p)\n", iTInfo
, (int)lcid
, ppTInfo
);
1929 hres
= LoadTypeLib(stdole2tlb
, &tl
);
1932 ERR("Could not load stdole2.tlb\n");
1936 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IPictureDisp
, ppTInfo
);
1938 ERR("Did not get IPictureDisp typeinfo from typelib, hres %x\n", hres
);
1943 /************************************************************************
1944 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1946 * See Windows documentation for more details on IDispatch methods.
1948 static HRESULT WINAPI
OLEPictureImpl_GetIDsOfNames(
1951 LPOLESTR
* rgszNames
,
1959 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", iface
, debugstr_guid(riid
),
1960 rgszNames
, cNames
, (int)lcid
, rgDispId
);
1964 return E_INVALIDARG
;
1968 /* retrieve type information */
1969 hres
= OLEPictureImpl_GetTypeInfo(iface
, 0, lcid
, &pTInfo
);
1973 ERR("GetTypeInfo failed.\n");
1977 /* convert names to DISPIDs */
1978 hres
= DispGetIDsOfNames (pTInfo
, rgszNames
, cNames
, rgDispId
);
1979 ITypeInfo_Release(pTInfo
);
1985 /************************************************************************
1986 * OLEPictureImpl_Invoke (IDispatch)
1988 * See Windows documentation for more details on IDispatch methods.
1990 static HRESULT WINAPI
OLEPictureImpl_Invoke(
1992 DISPID dispIdMember
,
1996 DISPPARAMS
* pDispParams
,
1997 VARIANT
* pVarResult
,
1998 EXCEPINFO
* pExepInfo
,
2001 OLEPictureImpl
*This
= impl_from_IDispatch(iface
);
2004 /* validate parameters */
2006 if (!IsEqualIID(riid
, &IID_NULL
))
2008 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
2009 return DISP_E_UNKNOWNNAME
;
2014 ERR("null pDispParams not allowed\n");
2015 return DISP_E_PARAMNOTOPTIONAL
;
2018 if (wFlags
& DISPATCH_PROPERTYGET
)
2020 if (pDispParams
->cArgs
!= 0)
2022 ERR("param count for DISPATCH_PROPERTYGET was %d instead of 0\n", pDispParams
->cArgs
);
2023 return DISP_E_BADPARAMCOUNT
;
2027 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
2028 return DISP_E_PARAMNOTOPTIONAL
;
2031 else if (wFlags
& DISPATCH_PROPERTYPUT
)
2033 if (pDispParams
->cArgs
!= 1)
2035 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
2036 return DISP_E_BADPARAMCOUNT
;
2040 switch (dispIdMember
)
2042 case DISPID_PICT_HANDLE
:
2043 if (wFlags
& DISPATCH_PROPERTYGET
)
2045 TRACE("DISPID_PICT_HANDLE\n");
2046 V_VT(pVarResult
) = VT_I4
;
2047 return IPicture_get_Handle(&This
->IPicture_iface
, &V_UINT(pVarResult
));
2050 case DISPID_PICT_HPAL
:
2051 if (wFlags
& DISPATCH_PROPERTYGET
)
2053 TRACE("DISPID_PICT_HPAL\n");
2054 V_VT(pVarResult
) = VT_I4
;
2055 return IPicture_get_hPal(&This
->IPicture_iface
, &V_UINT(pVarResult
));
2057 else if (wFlags
& DISPATCH_PROPERTYPUT
)
2061 TRACE("DISPID_PICT_HPAL\n");
2063 VariantInit(&vararg
);
2064 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I4
);
2068 hr
= IPicture_set_hPal(&This
->IPicture_iface
, V_I4(&vararg
));
2070 VariantClear(&vararg
);
2074 case DISPID_PICT_TYPE
:
2075 if (wFlags
& DISPATCH_PROPERTYGET
)
2077 TRACE("DISPID_PICT_TYPE\n");
2078 V_VT(pVarResult
) = VT_I2
;
2079 return OLEPictureImpl_get_Type(&This
->IPicture_iface
, &V_I2(pVarResult
));
2082 case DISPID_PICT_WIDTH
:
2083 if (wFlags
& DISPATCH_PROPERTYGET
)
2085 TRACE("DISPID_PICT_WIDTH\n");
2086 V_VT(pVarResult
) = VT_I4
;
2087 return IPicture_get_Width(&This
->IPicture_iface
, &V_I4(pVarResult
));
2090 case DISPID_PICT_HEIGHT
:
2091 if (wFlags
& DISPATCH_PROPERTYGET
)
2093 TRACE("DISPID_PICT_HEIGHT\n");
2094 V_VT(pVarResult
) = VT_I4
;
2095 return IPicture_get_Height(&This
->IPicture_iface
, &V_I4(pVarResult
));
2098 case DISPID_PICT_RENDER
:
2099 if (wFlags
& DISPATCH_METHOD
)
2101 VARIANTARG
*args
= pDispParams
->rgvarg
;
2104 TRACE("DISPID_PICT_RENDER\n");
2106 if (pDispParams
->cArgs
!= 10)
2107 return DISP_E_BADPARAMCOUNT
;
2109 /* All parameters are supposed to be VT_I4 (on 64 bits too). */
2110 for (i
= 0; i
< pDispParams
->cArgs
; i
++)
2111 if (V_VT(&args
[i
]) != VT_I4
)
2113 ERR("DISPID_PICT_RENDER: wrong argument type %d:%d\n", i
, V_VT(&args
[i
]));
2114 return DISP_E_TYPEMISMATCH
;
2117 /* FIXME: rectangle pointer argument handling seems broken on 64 bits,
2118 currently Render() doesn't use it at all so for now NULL is passed. */
2119 return IPicture_Render(&This
->IPicture_iface
,
2120 LongToHandle(V_I4(&args
[9])),
2134 ERR("invalid dispid 0x%x or wFlags 0x%x\n", dispIdMember
, wFlags
);
2135 return DISP_E_MEMBERNOTFOUND
;
2139 static const IPictureVtbl OLEPictureImpl_VTable
=
2141 OLEPictureImpl_QueryInterface
,
2142 OLEPictureImpl_AddRef
,
2143 OLEPictureImpl_Release
,
2144 OLEPictureImpl_get_Handle
,
2145 OLEPictureImpl_get_hPal
,
2146 OLEPictureImpl_get_Type
,
2147 OLEPictureImpl_get_Width
,
2148 OLEPictureImpl_get_Height
,
2149 OLEPictureImpl_Render
,
2150 OLEPictureImpl_set_hPal
,
2151 OLEPictureImpl_get_CurDC
,
2152 OLEPictureImpl_SelectPicture
,
2153 OLEPictureImpl_get_KeepOriginalFormat
,
2154 OLEPictureImpl_put_KeepOriginalFormat
,
2155 OLEPictureImpl_PictureChanged
,
2156 OLEPictureImpl_SaveAsFile
,
2157 OLEPictureImpl_get_Attributes
2160 static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable
=
2162 OLEPictureImpl_IDispatch_QueryInterface
,
2163 OLEPictureImpl_IDispatch_AddRef
,
2164 OLEPictureImpl_IDispatch_Release
,
2165 OLEPictureImpl_GetTypeInfoCount
,
2166 OLEPictureImpl_GetTypeInfo
,
2167 OLEPictureImpl_GetIDsOfNames
,
2168 OLEPictureImpl_Invoke
2171 static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable
=
2173 OLEPictureImpl_IPersistStream_QueryInterface
,
2174 OLEPictureImpl_IPersistStream_AddRef
,
2175 OLEPictureImpl_IPersistStream_Release
,
2176 OLEPictureImpl_GetClassID
,
2177 OLEPictureImpl_IsDirty
,
2178 OLEPictureImpl_Load
,
2179 OLEPictureImpl_Save
,
2180 OLEPictureImpl_GetSizeMax
2183 static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable
=
2185 OLEPictureImpl_IConnectionPointContainer_QueryInterface
,
2186 OLEPictureImpl_IConnectionPointContainer_AddRef
,
2187 OLEPictureImpl_IConnectionPointContainer_Release
,
2188 OLEPictureImpl_EnumConnectionPoints
,
2189 OLEPictureImpl_FindConnectionPoint
2192 /***********************************************************************
2193 * OleCreatePictureIndirect (OLEAUT32.419)
2195 HRESULT WINAPI
OleCreatePictureIndirect(LPPICTDESC lpPictDesc
, REFIID riid
,
2196 BOOL Own
, void **ppvObj
)
2198 OLEPictureImpl
* newPict
;
2201 TRACE("(%p,%s,%d,%p)\n", lpPictDesc
, debugstr_guid(riid
), Own
, ppvObj
);
2205 newPict
= OLEPictureImpl_Construct(lpPictDesc
, Own
);
2207 if (newPict
== NULL
)
2208 return E_OUTOFMEMORY
;
2211 * Make sure it supports the interface required by the caller.
2213 hr
= IPicture_QueryInterface(&newPict
->IPicture_iface
, riid
, ppvObj
);
2216 * Release the reference obtained in the constructor. If
2217 * the QueryInterface was unsuccessful, it will free the class.
2219 IPicture_Release(&newPict
->IPicture_iface
);
2225 /***********************************************************************
2226 * OleLoadPicture (OLEAUT32.418)
2228 HRESULT WINAPI
OleLoadPicture( LPSTREAM lpstream
, LONG lSize
, BOOL fRunmode
,
2229 REFIID riid
, LPVOID
*ppvObj
)
2235 TRACE("(%p,%d,%d,%s,%p), partially implemented.\n",
2236 lpstream
, lSize
, fRunmode
, debugstr_guid(riid
), ppvObj
);
2238 hr
= OleCreatePictureIndirect(NULL
,riid
,!fRunmode
,(LPVOID
*)&newpic
);
2241 hr
= IPicture_QueryInterface(newpic
,&IID_IPersistStream
, (LPVOID
*)&ps
);
2243 ERR("Could not get IPersistStream iface from Ole Picture?\n");
2244 IPicture_Release(newpic
);
2248 hr
= IPersistStream_Load(ps
,lpstream
);
2249 IPersistStream_Release(ps
);
2252 ERR("IPersistStream_Load failed\n");
2253 IPicture_Release(newpic
);
2257 hr
= IPicture_QueryInterface(newpic
,riid
,ppvObj
);
2259 ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid
));
2260 IPicture_Release(newpic
);
2264 /***********************************************************************
2265 * OleLoadPictureEx (OLEAUT32.401)
2267 HRESULT WINAPI
OleLoadPictureEx( LPSTREAM lpstream
, LONG lSize
, BOOL fRunmode
,
2268 REFIID riid
, DWORD xsiz
, DWORD ysiz
, DWORD flags
, LPVOID
*ppvObj
)
2274 FIXME("(%p,%d,%d,%s,x=%d,y=%d,f=%x,%p), partially implemented.\n",
2275 lpstream
, lSize
, fRunmode
, debugstr_guid(riid
), xsiz
, ysiz
, flags
, ppvObj
);
2277 hr
= OleCreatePictureIndirect(NULL
,riid
,!fRunmode
,(LPVOID
*)&newpic
);
2280 hr
= IPicture_QueryInterface(newpic
,&IID_IPersistStream
, (LPVOID
*)&ps
);
2282 ERR("Could not get IPersistStream iface from Ole Picture?\n");
2283 IPicture_Release(newpic
);
2287 hr
= IPersistStream_Load(ps
,lpstream
);
2288 IPersistStream_Release(ps
);
2291 ERR("IPersistStream_Load failed\n");
2292 IPicture_Release(newpic
);
2296 hr
= IPicture_QueryInterface(newpic
,riid
,ppvObj
);
2298 ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid
));
2299 IPicture_Release(newpic
);
2303 /***********************************************************************
2304 * OleSavePictureFile (OLEAUT32.423)
2306 HRESULT WINAPI
OleSavePictureFile(IDispatch
*picture
, BSTR filename
)
2308 FIXME("(%p %s): stub\n", picture
, debugstr_w(filename
));
2309 return CTL_E_FILENOTFOUND
;
2312 /***********************************************************************
2313 * OleLoadPicturePath (OLEAUT32.424)
2315 HRESULT WINAPI
OleLoadPicturePath( LPOLESTR szURLorPath
, LPUNKNOWN punkCaller
,
2316 DWORD dwReserved
, OLE_COLOR clrReserved
, REFIID riid
,
2319 static const WCHAR file
[] = { 'f','i','l','e',':',0 };
2323 HGLOBAL hGlobal
= NULL
;
2327 IPersistStream
*pStream
;
2330 WCHAR
*file_candidate
;
2331 WCHAR path_buf
[MAX_PATH
];
2333 TRACE("(%s,%p,%d,%08x,%s,%p): stub\n",
2334 debugstr_w(szURLorPath
), punkCaller
, dwReserved
, clrReserved
,
2335 debugstr_guid(riid
), ppvRet
);
2337 if (!szURLorPath
|| !ppvRet
)
2338 return E_INVALIDARG
;
2342 /* Convert file URLs to DOS paths. */
2343 if (strncmpW(szURLorPath
, file
, 5) == 0) {
2345 hRes
= CoInternetParseUrl(szURLorPath
, PARSE_PATH_FROM_URL
, 0, path_buf
,
2346 sizeof(path_buf
)/sizeof(WCHAR
), &size
, 0);
2350 file_candidate
= path_buf
;
2353 file_candidate
= szURLorPath
;
2355 /* Handle candidate DOS paths separately. */
2356 if (file_candidate
[1] == ':') {
2357 hFile
= CreateFileW(file_candidate
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
2359 if (hFile
== INVALID_HANDLE_VALUE
)
2360 return INET_E_RESOURCE_NOT_FOUND
;
2362 dwFileSize
= GetFileSize(hFile
, NULL
);
2363 if (dwFileSize
!= INVALID_FILE_SIZE
)
2365 hGlobal
= GlobalAlloc(GMEM_FIXED
,dwFileSize
);
2368 bRead
= ReadFile(hFile
, hGlobal
, dwFileSize
, &dwBytesRead
, NULL
) && dwBytesRead
== dwFileSize
;
2371 GlobalFree(hGlobal
);
2379 return INET_E_RESOURCE_NOT_FOUND
;
2381 hRes
= CreateStreamOnHGlobal(hGlobal
, TRUE
, &stream
);
2384 GlobalFree(hGlobal
);
2391 hRes
= CreateBindCtx(0, &pbc
);
2392 if (SUCCEEDED(hRes
))
2394 hRes
= CreateURLMoniker(NULL
, szURLorPath
, &pmnk
);
2395 if (SUCCEEDED(hRes
))
2397 hRes
= IMoniker_BindToStorage(pmnk
, pbc
, NULL
, &IID_IStream
, (LPVOID
*)&stream
);
2398 IMoniker_Release(pmnk
);
2400 IBindCtx_Release(pbc
);
2406 init_res
= CoInitialize(NULL
);
2408 hRes
= CoCreateInstance(&CLSID_StdPicture
, punkCaller
, CLSCTX_INPROC_SERVER
,
2409 &IID_IPicture
, (LPVOID
*)&ipicture
);
2410 if (SUCCEEDED(hRes
)) {
2411 hRes
= IPicture_QueryInterface(ipicture
, &IID_IPersistStream
, (LPVOID
*)&pStream
);
2413 if (SUCCEEDED(hRes
)) {
2414 hRes
= IPersistStream_Load(pStream
, stream
);
2416 if (SUCCEEDED(hRes
)) {
2417 hRes
= IPicture_QueryInterface(ipicture
, riid
, ppvRet
);
2420 ERR("Failed to get interface %s from IPicture.\n", debugstr_guid(riid
));
2422 IPersistStream_Release(pStream
);
2424 IPicture_Release(ipicture
);
2427 IStream_Release(stream
);
2429 if (SUCCEEDED(init_res
))
2435 /*******************************************************************************
2436 * StdPic ClassFactory
2440 /* IUnknown fields */
2441 IClassFactory IClassFactory_iface
;
2443 } IClassFactoryImpl
;
2445 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
2447 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
2450 static HRESULT WINAPI
2451 SPCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2452 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2454 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2455 return E_NOINTERFACE
;
2459 SPCF_AddRef(LPCLASSFACTORY iface
) {
2460 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2461 return InterlockedIncrement(&This
->ref
);
2464 static ULONG WINAPI
SPCF_Release(LPCLASSFACTORY iface
) {
2465 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2466 /* static class, won't be freed */
2467 return InterlockedDecrement(&This
->ref
);
2470 static HRESULT WINAPI
SPCF_CreateInstance(
2471 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2473 /* Creates an uninitialized picture */
2474 return OleCreatePictureIndirect(NULL
,riid
,TRUE
,ppobj
);
2478 static HRESULT WINAPI
SPCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2479 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2480 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2484 static const IClassFactoryVtbl SPCF_Vtbl
= {
2485 SPCF_QueryInterface
,
2488 SPCF_CreateInstance
,
2491 static IClassFactoryImpl STDPIC_CF
= {{&SPCF_Vtbl
}, 1 };
2493 void _get_STDPIC_CF(LPVOID
*ppv
) { *ppv
= &STDPIC_CF
; }