Avoid lvalue casts (based on a patch by Marcus Meissner).
[wine/testsucceed.git] / dlls / oleaut32 / olepicture.c
blobe874a75153c33a43153e1ecb490e593025c7dc13
1 /*
2 * OLE Picture object
4 * Implementation of OLE IPicture and related interfaces
6 * Copyright 2000 Huw D M Davies for CodeWeavers.
7 * Copyright 2001 Marcus Meissner
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * BUGS
25 * Support PICTYPE_BITMAP and PICTYPE_ICON, altough only bitmaps very well..
26 * Lots of methods are just stubs.
29 * NOTES (or things that msdn doesn't tell you)
31 * The width and height properties are returned in HIMETRIC units (0.01mm)
32 * IPicture::Render also uses these to select a region of the src picture.
33 * A bitmap's size is converted into these units by using the screen resolution
34 * thus an 8x8 bitmap on a 96dpi screen has a size of 212x212 (8/96 * 2540).
38 #include "config.h"
40 #ifdef HAVE_UNISTD_H
41 # include <unistd.h>
42 #endif
43 #include <stdarg.h>
44 #include <stdio.h>
45 #include <string.h>
47 /* Must be before wine includes, the header has things conflicting with
48 * WINE headers.
50 #ifdef HAVE_GIF_LIB_H
51 # include <gif_lib.h>
52 #endif
54 #define NONAMELESSUNION
55 #define NONAMELESSSTRUCT
56 #include "winerror.h"
57 #include "windef.h"
58 #include "winbase.h"
59 #include "wingdi.h"
60 #include "winuser.h"
61 #include "ole2.h"
62 #include "olectl.h"
63 #include "oleauto.h"
64 #include "connpt.h"
65 #include "wine/debug.h"
67 #include "wine/wingdi16.h"
68 #include "cursoricon.h"
70 #ifdef HAVE_LIBJPEG
71 /* This is a hack, so jpeglib.h does not redefine INT32 and the like*/
72 #define XMD_H
73 #define UINT8 JPEG_UINT8
74 #define UINT16 JPEG_UINT16
75 #undef FAR
76 #ifdef HAVE_JPEGLIB_H
77 # include <jpeglib.h>
78 #endif
79 #undef UINT16
80 #endif
82 WINE_DEFAULT_DEBUG_CHANNEL(ole);
84 /*************************************************************************
85 * Declaration of implementation class
88 typedef struct OLEPictureImpl {
91 * IPicture handles IUnknown
94 ICOM_VTABLE(IPicture) *lpvtbl1;
95 ICOM_VTABLE(IDispatch) *lpvtbl2;
96 ICOM_VTABLE(IPersistStream) *lpvtbl3;
97 ICOM_VTABLE(IConnectionPointContainer) *lpvtbl4;
99 /* Object referenece count */
100 DWORD ref;
102 /* We own the object and must destroy it ourselves */
103 BOOL fOwn;
105 /* Picture description */
106 PICTDESC desc;
108 /* These are the pixel size of a bitmap */
109 DWORD origWidth;
110 DWORD origHeight;
112 /* And these are the size of the picture converted into HIMETRIC units */
113 OLE_XSIZE_HIMETRIC himetricWidth;
114 OLE_YSIZE_HIMETRIC himetricHeight;
116 IConnectionPoint *pCP;
118 BOOL keepOrigFormat;
119 HDC hDCCur;
121 /* Bitmap transparency mask */
122 HBITMAP hbmMask;
123 COLORREF rgbTrans;
125 /* data */
126 void* data;
127 int datalen;
128 } OLEPictureImpl;
131 * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
133 #define ICOM_THIS_From_IDispatch(impl, name) \
134 impl *This = (impl*)(((char*)name)-sizeof(void*));
135 #define ICOM_THIS_From_IPersistStream(impl, name) \
136 impl *This = (impl*)(((char*)name)-2*sizeof(void*));
137 #define ICOM_THIS_From_IConnectionPointContainer(impl, name) \
138 impl *This = (impl*)(((char*)name)-3*sizeof(void*));
141 * Predeclare VTables. They get initialized at the end.
143 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable;
144 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable;
145 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable;
146 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable;
148 /***********************************************************************
149 * Implementation of the OLEPictureImpl class.
152 static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
153 BITMAP bm;
154 HDC hdcRef;
156 TRACE("bitmap handle %p\n", This->desc.u.bmp.hbitmap);
157 if(GetObjectA(This->desc.u.bmp.hbitmap, sizeof(bm), &bm) != sizeof(bm)) {
158 ERR("GetObject fails\n");
159 return;
161 This->origWidth = bm.bmWidth;
162 This->origHeight = bm.bmHeight;
163 /* The width and height are stored in HIMETRIC units (0.01 mm),
164 so we take our pixel width divide by pixels per inch and
165 multiply by 25.4 * 100 */
166 /* Should we use GetBitmapDimension if available? */
167 hdcRef = CreateCompatibleDC(0);
168 This->himetricWidth =(bm.bmWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
169 This->himetricHeight=(bm.bmHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
170 DeleteDC(hdcRef);
173 /************************************************************************
174 * OLEPictureImpl_Construct
176 * This method will construct a new instance of the OLEPictureImpl
177 * class.
179 * The caller of this method must release the object when it's
180 * done with it.
182 static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
184 OLEPictureImpl* newObject = 0;
186 if (pictDesc)
187 TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
190 * Allocate space for the object.
192 newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
194 if (newObject==0)
195 return newObject;
198 * Initialize the virtual function table.
200 newObject->lpvtbl1 = &OLEPictureImpl_VTable;
201 newObject->lpvtbl2 = &OLEPictureImpl_IDispatch_VTable;
202 newObject->lpvtbl3 = &OLEPictureImpl_IPersistStream_VTable;
203 newObject->lpvtbl4 = &OLEPictureImpl_IConnectionPointContainer_VTable;
205 CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
208 * Start with one reference count. The caller of this function
209 * must release the interface pointer when it is done.
211 newObject->ref = 1;
212 newObject->hDCCur = 0;
214 newObject->fOwn = fOwn;
216 /* dunno about original value */
217 newObject->keepOrigFormat = TRUE;
219 newObject->hbmMask = NULL;
221 if (pictDesc) {
222 if(pictDesc->cbSizeofstruct != sizeof(PICTDESC)) {
223 FIXME("struct size = %d\n", pictDesc->cbSizeofstruct);
225 memcpy(&newObject->desc, pictDesc, sizeof(PICTDESC));
228 switch(pictDesc->picType) {
229 case PICTYPE_BITMAP:
230 OLEPictureImpl_SetBitmap(newObject);
231 break;
233 case PICTYPE_METAFILE:
234 TRACE("metafile handle %p\n", pictDesc->u.wmf.hmeta);
235 newObject->himetricWidth = pictDesc->u.wmf.xExt;
236 newObject->himetricHeight = pictDesc->u.wmf.yExt;
237 break;
239 case PICTYPE_NONE:
240 /* not sure what to do here */
241 newObject->himetricWidth = newObject->himetricHeight = 0;
242 break;
244 case PICTYPE_ICON:
245 case PICTYPE_ENHMETAFILE:
246 default:
247 FIXME("Unsupported type %d\n", pictDesc->picType);
248 newObject->himetricWidth = newObject->himetricHeight = 0;
249 break;
251 } else {
252 newObject->desc.picType = PICTYPE_UNINITIALIZED;
255 TRACE("returning %p\n", newObject);
256 return newObject;
259 /************************************************************************
260 * OLEPictureImpl_Destroy
262 * This method is called by the Release method when the reference
263 * count goes down to 0. It will free all resources used by
264 * this object. */
265 static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
267 TRACE("(%p)\n", Obj);
269 if(Obj->fOwn) { /* We need to destroy the picture */
270 switch(Obj->desc.picType) {
271 case PICTYPE_BITMAP:
272 DeleteObject(Obj->desc.u.bmp.hbitmap);
273 break;
274 case PICTYPE_METAFILE:
275 DeleteMetaFile(Obj->desc.u.wmf.hmeta);
276 break;
277 case PICTYPE_ICON:
278 DestroyIcon(Obj->desc.u.icon.hicon);
279 break;
280 case PICTYPE_ENHMETAFILE:
281 DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
282 break;
283 default:
284 FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
285 break;
288 if (Obj->data) HeapFree(GetProcessHeap(), 0, Obj->data);
289 HeapFree(GetProcessHeap(), 0, Obj);
292 static ULONG WINAPI OLEPictureImpl_AddRef(IPicture* iface);
294 /************************************************************************
295 * OLEPictureImpl_QueryInterface (IUnknown)
297 * See Windows documentation for more details on IUnknown methods.
299 static HRESULT WINAPI OLEPictureImpl_QueryInterface(
300 IPicture* iface,
301 REFIID riid,
302 void** ppvObject)
304 ICOM_THIS(OLEPictureImpl, iface);
305 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
308 * Perform a sanity check on the parameters.
310 if ( (This==0) || (ppvObject==0) )
311 return E_INVALIDARG;
314 * Initialize the return parameter.
316 *ppvObject = 0;
319 * Compare the riid with the interface IDs implemented by this object.
321 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
323 *ppvObject = (IPicture*)This;
325 else if (memcmp(&IID_IPicture, riid, sizeof(IID_IPicture)) == 0)
327 *ppvObject = (IPicture*)This;
329 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
331 *ppvObject = (IDispatch*)&(This->lpvtbl2);
333 else if (memcmp(&IID_IPictureDisp, riid, sizeof(IID_IPictureDisp)) == 0)
335 *ppvObject = (IDispatch*)&(This->lpvtbl2);
337 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
339 *ppvObject = (IPersistStream*)&(This->lpvtbl3);
341 else if (memcmp(&IID_IConnectionPointContainer, riid, sizeof(IID_IConnectionPointContainer)) == 0)
343 *ppvObject = (IConnectionPointContainer*)&(This->lpvtbl4);
346 * Check that we obtained an interface.
348 if ((*ppvObject)==0)
350 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
351 return E_NOINTERFACE;
355 * Query Interface always increases the reference count by one when it is
356 * successful
358 OLEPictureImpl_AddRef((IPicture*)This);
360 return S_OK;
362 /***********************************************************************
363 * OLEPicture_SendNotify (internal)
365 * Sends notification messages of changed properties to any interested
366 * connections.
368 static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
370 IEnumConnections *pEnum;
371 CONNECTDATA CD;
373 if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
374 return;
375 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
376 IPropertyNotifySink *sink;
378 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
379 IPropertyNotifySink_OnChanged(sink, dispID);
380 IPropertyNotifySink_Release(sink);
381 IUnknown_Release(CD.pUnk);
383 IEnumConnections_Release(pEnum);
384 return;
387 /************************************************************************
388 * OLEPictureImpl_AddRef (IUnknown)
390 * See Windows documentation for more details on IUnknown methods.
392 static ULONG WINAPI OLEPictureImpl_AddRef(
393 IPicture* iface)
395 ICOM_THIS(OLEPictureImpl, iface);
396 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
397 This->ref++;
399 return This->ref;
402 /************************************************************************
403 * OLEPictureImpl_Release (IUnknown)
405 * See Windows documentation for more details on IUnknown methods.
407 static ULONG WINAPI OLEPictureImpl_Release(
408 IPicture* iface)
410 ICOM_THIS(OLEPictureImpl, iface);
411 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
414 * Decrease the reference count on this object.
416 This->ref--;
419 * If the reference count goes down to 0, perform suicide.
421 if (This->ref==0)
423 OLEPictureImpl_Destroy(This);
425 return 0;
428 return This->ref;
432 /************************************************************************
433 * OLEPictureImpl_get_Handle
435 static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
436 OLE_HANDLE *phandle)
438 ICOM_THIS(OLEPictureImpl, iface);
439 TRACE("(%p)->(%p)\n", This, phandle);
440 switch(This->desc.picType) {
441 case PICTYPE_BITMAP:
442 *phandle = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
443 break;
444 case PICTYPE_METAFILE:
445 *phandle = (OLE_HANDLE)This->desc.u.wmf.hmeta;
446 break;
447 case PICTYPE_ICON:
448 *phandle = (OLE_HANDLE)This->desc.u.icon.hicon;
449 break;
450 case PICTYPE_ENHMETAFILE:
451 *phandle = (OLE_HANDLE)This->desc.u.emf.hemf;
452 break;
453 default:
454 FIXME("Unimplemented type %d\n", This->desc.picType);
455 return E_NOTIMPL;
457 TRACE("returning handle %08x\n", *phandle);
458 return S_OK;
461 /************************************************************************
462 * OLEPictureImpl_get_hPal
464 static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
465 OLE_HANDLE *phandle)
467 ICOM_THIS(OLEPictureImpl, iface);
468 FIXME("(%p)->(%p): stub\n", This, phandle);
469 return E_NOTIMPL;
472 /************************************************************************
473 * OLEPictureImpl_get_Type
475 static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
476 short *ptype)
478 ICOM_THIS(OLEPictureImpl, iface);
479 TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
480 *ptype = This->desc.picType;
481 return S_OK;
484 /************************************************************************
485 * OLEPictureImpl_get_Width
487 static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
488 OLE_XSIZE_HIMETRIC *pwidth)
490 ICOM_THIS(OLEPictureImpl, iface);
491 TRACE("(%p)->(%p): width is %ld\n", This, pwidth, This->himetricWidth);
492 *pwidth = This->himetricWidth;
493 return S_OK;
496 /************************************************************************
497 * OLEPictureImpl_get_Height
499 static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
500 OLE_YSIZE_HIMETRIC *pheight)
502 ICOM_THIS(OLEPictureImpl, iface);
503 TRACE("(%p)->(%p): height is %ld\n", This, pheight, This->himetricHeight);
504 *pheight = This->himetricHeight;
505 return S_OK;
508 /************************************************************************
509 * OLEPictureImpl_Render
511 static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
512 long x, long y, long cx, long cy,
513 OLE_XPOS_HIMETRIC xSrc,
514 OLE_YPOS_HIMETRIC ySrc,
515 OLE_XSIZE_HIMETRIC cxSrc,
516 OLE_YSIZE_HIMETRIC cySrc,
517 LPCRECT prcWBounds)
519 ICOM_THIS(OLEPictureImpl, iface);
520 TRACE("(%p)->(%p, (%ld,%ld), (%ld,%ld) <- (%ld,%ld), (%ld,%ld), %p)\n",
521 This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
522 if(prcWBounds)
523 TRACE("prcWBounds (%ld,%ld) - (%ld,%ld)\n", prcWBounds->left, prcWBounds->top,
524 prcWBounds->right, prcWBounds->bottom);
527 * While the documentation suggests this to be here (or after rendering?)
528 * it does cause an endless recursion in my sample app. -MM 20010804
529 OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
532 switch(This->desc.picType) {
533 case PICTYPE_BITMAP:
535 HBITMAP hbmpOld;
536 HDC hdcBmp;
538 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
539 NB y-axis gets flipped */
541 hdcBmp = CreateCompatibleDC(0);
542 SetMapMode(hdcBmp, MM_ANISOTROPIC);
543 SetWindowOrgEx(hdcBmp, 0, 0, NULL);
544 SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
545 SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
546 SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
548 hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
550 if (This->hbmMask) {
551 HDC hdcMask = CreateCompatibleDC(0);
552 HBITMAP hOldbm = SelectObject(hdcMask, This->hbmMask);
554 SetMapMode(hdcMask, MM_ANISOTROPIC);
555 SetWindowOrgEx(hdcMask, 0, 0, NULL);
556 SetWindowExtEx(hdcMask, This->himetricWidth, This->himetricHeight, NULL);
557 SetViewportOrgEx(hdcMask, 0, This->origHeight, NULL);
558 SetViewportExtEx(hdcMask, This->origWidth, -This->origHeight, NULL);
560 SetBkColor(hdc, RGB(255, 255, 255));
561 SetTextColor(hdc, RGB(0, 0, 0));
562 StretchBlt(hdc, x, y, cx, cy, hdcMask, xSrc, ySrc, cxSrc, cySrc, SRCAND);
563 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCPAINT);
565 SelectObject(hdcMask, hOldbm);
566 DeleteDC(hdcMask);
567 } else
568 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
570 SelectObject(hdcBmp, hbmpOld);
571 DeleteDC(hdcBmp);
573 break;
574 case PICTYPE_ICON:
575 FIXME("Not quite correct implementation of rendering icons...\n");
576 DrawIcon(hdc,x,y,This->desc.u.icon.hicon);
577 break;
579 case PICTYPE_METAFILE:
580 case PICTYPE_ENHMETAFILE:
581 default:
582 FIXME("type %d not implemented\n", This->desc.picType);
583 return E_NOTIMPL;
585 return S_OK;
588 /************************************************************************
589 * OLEPictureImpl_set_hPal
591 static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
592 OLE_HANDLE hpal)
594 ICOM_THIS(OLEPictureImpl, iface);
595 FIXME("(%p)->(%08x): stub\n", This, hpal);
596 OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
597 return E_NOTIMPL;
600 /************************************************************************
601 * OLEPictureImpl_get_CurDC
603 static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
604 HDC *phdc)
606 ICOM_THIS(OLEPictureImpl, iface);
607 TRACE("(%p), returning %p\n", This, This->hDCCur);
608 if (phdc) *phdc = This->hDCCur;
609 return S_OK;
612 /************************************************************************
613 * OLEPictureImpl_SelectPicture
615 static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
616 HDC hdcIn,
617 HDC *phdcOut,
618 OLE_HANDLE *phbmpOut)
620 ICOM_THIS(OLEPictureImpl, iface);
621 TRACE("(%p)->(%p, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
622 if (This->desc.picType == PICTYPE_BITMAP) {
623 SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
625 if (phdcOut)
626 *phdcOut = This->hDCCur;
627 This->hDCCur = hdcIn;
628 if (phbmpOut)
629 *phbmpOut = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
630 return S_OK;
631 } else {
632 FIXME("Don't know how to select picture type %d\n",This->desc.picType);
633 return E_FAIL;
637 /************************************************************************
638 * OLEPictureImpl_get_KeepOriginalFormat
640 static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
641 BOOL *pfKeep)
643 ICOM_THIS(OLEPictureImpl, iface);
644 TRACE("(%p)->(%p)\n", This, pfKeep);
645 if (!pfKeep)
646 return E_POINTER;
647 *pfKeep = This->keepOrigFormat;
648 return S_OK;
651 /************************************************************************
652 * OLEPictureImpl_put_KeepOriginalFormat
654 static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
655 BOOL keep)
657 ICOM_THIS(OLEPictureImpl, iface);
658 TRACE("(%p)->(%d)\n", This, keep);
659 This->keepOrigFormat = keep;
660 /* FIXME: what DISPID notification here? */
661 return S_OK;
664 /************************************************************************
665 * OLEPictureImpl_PictureChanged
667 static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
669 ICOM_THIS(OLEPictureImpl, iface);
670 TRACE("(%p)->()\n", This);
671 OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
672 return S_OK;
675 /************************************************************************
676 * OLEPictureImpl_SaveAsFile
678 static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
679 IStream *pstream,
680 BOOL SaveMemCopy,
681 LONG *pcbSize)
683 ICOM_THIS(OLEPictureImpl, iface);
684 FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This, pstream, SaveMemCopy, pcbSize);
685 return IStream_Write(pstream,This->data,This->datalen,(ULONG*)pcbSize);
688 /************************************************************************
689 * OLEPictureImpl_get_Attributes
691 static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
692 DWORD *pdwAttr)
694 ICOM_THIS(OLEPictureImpl, iface);
695 TRACE("(%p)->(%p).\n", This, pdwAttr);
696 *pdwAttr = 0;
697 switch (This->desc.picType) {
698 case PICTYPE_BITMAP: break; /* not 'truely' scalable, see MSDN. */
699 case PICTYPE_ICON: *pdwAttr = PICTURE_TRANSPARENT;break;
700 case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
701 default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
703 return S_OK;
707 /************************************************************************
708 * IConnectionPointContainer
711 static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
712 IConnectionPointContainer* iface,
713 REFIID riid,
714 VOID** ppvoid
716 ICOM_THIS_From_IConnectionPointContainer(IPicture,iface);
718 return IPicture_QueryInterface(This,riid,ppvoid);
721 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
722 IConnectionPointContainer* iface)
724 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
726 return IPicture_AddRef(This);
729 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
730 IConnectionPointContainer* iface)
732 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
734 return IPicture_Release(This);
737 static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
738 IConnectionPointContainer* iface,
739 IEnumConnectionPoints** ppEnum
741 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
743 FIXME("(%p,%p), stub!\n",This,ppEnum);
744 return E_NOTIMPL;
747 static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
748 IConnectionPointContainer* iface,
749 REFIID riid,
750 IConnectionPoint **ppCP
752 ICOM_THIS_From_IConnectionPointContainer(OLEPictureImpl, iface);
753 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
754 if (!ppCP)
755 return E_POINTER;
756 *ppCP = NULL;
757 if (IsEqualGUID(riid,&IID_IPropertyNotifySink))
758 return IConnectionPoint_QueryInterface(This->pCP,&IID_IConnectionPoint,(LPVOID)ppCP);
759 FIXME("tried to find connection point on %s?\n",debugstr_guid(riid));
760 return 0x80040200;
762 /************************************************************************
763 * IPersistStream
765 /************************************************************************
766 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
768 * See Windows documentation for more details on IUnknown methods.
770 static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
771 IPersistStream* iface,
772 REFIID riid,
773 VOID** ppvoid)
775 ICOM_THIS_From_IPersistStream(IPicture, iface);
777 return IPicture_QueryInterface(This, riid, ppvoid);
780 /************************************************************************
781 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
783 * See Windows documentation for more details on IUnknown methods.
785 static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
786 IPersistStream* iface)
788 ICOM_THIS_From_IPersistStream(IPicture, iface);
790 return IPicture_AddRef(This);
793 /************************************************************************
794 * OLEPictureImpl_IPersistStream_Release (IUnknown)
796 * See Windows documentation for more details on IUnknown methods.
798 static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
799 IPersistStream* iface)
801 ICOM_THIS_From_IPersistStream(IPicture, iface);
803 return IPicture_Release(This);
806 /************************************************************************
807 * OLEPictureImpl_IPersistStream_GetClassID
809 static HRESULT WINAPI OLEPictureImpl_GetClassID(
810 IPersistStream* iface,CLSID* pClassID)
812 ICOM_THIS_From_IPersistStream(IPicture, iface);
813 FIXME("(%p),stub!\n",This);
814 return E_NOTIMPL;
817 /************************************************************************
818 * OLEPictureImpl_IPersistStream_IsDirty
820 static HRESULT WINAPI OLEPictureImpl_IsDirty(
821 IPersistStream* iface)
823 ICOM_THIS_From_IPersistStream(IPicture, iface);
824 FIXME("(%p),stub!\n",This);
825 return E_NOTIMPL;
828 #ifdef HAVE_LIBJPEG
829 /* for the jpeg decompressor source manager. */
830 static void _jpeg_init_source(j_decompress_ptr cinfo) { }
832 static boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
833 ERR("(), should not get here.\n");
834 return FALSE;
837 static void _jpeg_skip_input_data(j_decompress_ptr cinfo,long num_bytes) {
838 TRACE("Skipping %ld bytes...\n", num_bytes);
839 cinfo->src->next_input_byte += num_bytes;
840 cinfo->src->bytes_in_buffer -= num_bytes;
843 static boolean _jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired) {
844 ERR("(desired=%d), should not get here.\n",desired);
845 return FALSE;
847 static void _jpeg_term_source(j_decompress_ptr cinfo) { }
848 #endif /* HAVE_LIBJPEG */
850 #ifdef HAVE_LIBGIF
851 struct gifdata {
852 unsigned char *data;
853 unsigned int curoff;
854 unsigned int len;
857 static int _gif_inputfunc(GifFileType *gif, GifByteType *data, int len) {
858 struct gifdata *gd = (struct gifdata*)gif->UserData;
860 if (len+gd->curoff > gd->len) {
861 FIXME("Trying to read %d bytes, but only %d available.\n",len, gd->len-gd->curoff);
862 len = gd->len - gd->curoff;
864 memcpy(data, gd->data+gd->curoff, len);
865 gd->curoff += len;
866 return len;
868 #endif
870 /************************************************************************
871 * OLEPictureImpl_IPersistStream_Load (IUnknown)
873 * Loads the binary data from the IStream. Starts at current position.
874 * There appears to be an 2 DWORD header:
875 * DWORD magic;
876 * DWORD len;
878 * Currently implemented: BITMAP, ICON, JPEG.
880 static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
881 HRESULT hr = E_FAIL;
882 ULONG xread;
883 BYTE *xbuf;
884 DWORD header[2];
885 WORD magic;
886 STATSTG statstg;
887 ICOM_THIS_From_IPersistStream(OLEPictureImpl, iface);
889 TRACE("(%p,%p)\n",This,pStm);
891 /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
892 * out whether we do.
894 hr=IStream_Stat(pStm,&statstg,STATFLAG_NONAME);
895 if (hr)
896 FIXME("Stat failed with hres %lx\n",hr);
897 hr=IStream_Read(pStm,header,8,&xread);
898 if (hr || xread!=8) {
899 FIXME("Failure while reading picture header (hr is %lx, nread is %ld).\n",hr,xread);
900 return hr;
902 if (header[1] > statstg.cbSize.QuadPart || (header[1]==0)) {/* Incorrect header, assume none. */
903 xread = 8;
904 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,statstg.cbSize.QuadPart);
905 memcpy(xbuf,&header,8);
906 This->datalen = statstg.cbSize.QuadPart;
907 while (xread < This->datalen) {
908 ULONG nread;
909 hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
910 xread+=nread;
911 if (hr || !nread)
912 break;
914 if (xread != This->datalen)
915 FIXME("Could only read %ld of %d bytes in no-header case?\n",xread,This->datalen);
916 } else {
917 xread = 0;
918 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
919 This->datalen = header[1];
920 while (xread < header[1]) {
921 ULONG nread;
922 hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
923 xread+=nread;
924 if (hr || !nread)
925 break;
927 if (xread != header[1])
928 FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
930 magic = xbuf[0] + (xbuf[1]<<8);
931 switch (magic) {
932 case 0x4947: { /* GIF */
933 #ifdef HAVE_LIBGIF
934 struct gifdata gd;
935 GifFileType *gif;
936 BITMAPINFO *bmi;
937 HDC hdcref;
938 LPBYTE bytes;
939 int i,j,ret;
940 GifImageDesc *gid;
941 SavedImage *si;
942 ColorMapObject *cm;
943 int transparent = -1;
944 ExtensionBlock *eb;
945 int padding;
947 gd.data = xbuf;
948 gd.curoff = 0;
949 gd.len = xread;
950 gif = DGifOpen((void*)&gd, _gif_inputfunc);
951 ret = DGifSlurp(gif);
952 if (ret == GIF_ERROR) {
953 FIXME("Failed reading GIF using libgif.\n");
954 return E_FAIL;
956 TRACE("screen height %d, width %d\n", gif->SWidth, gif->SHeight);
957 TRACE("color res %d, backgcolor %d\n", gif->SColorResolution, gif->SBackGroundColor);
958 TRACE("imgcnt %d\n", gif->ImageCount);
959 if (gif->ImageCount<1) {
960 FIXME("GIF stream does not have images inside?\n");
961 return E_FAIL;
963 TRACE("curimage: %d x %d, on %dx%d, interlace %d\n",
964 gif->Image.Width, gif->Image.Height,
965 gif->Image.Left, gif->Image.Top,
966 gif->Image.Interlace
968 /* */
969 padding = (gif->SWidth+3) & ~3;
970 bmi = HeapAlloc(GetProcessHeap(),0,sizeof(BITMAPINFOHEADER)+(1<<gif->SColorResolution)*sizeof(RGBQUAD));
971 bytes= HeapAlloc(GetProcessHeap(),0,padding*gif->SHeight);
972 si = gif->SavedImages+0;
973 gid = &(si->ImageDesc);
974 cm = gid->ColorMap;
975 if (!cm) cm = gif->SColorMap;
977 /* look for the transparent color extension */
978 for (i = 0; i < si->ExtensionBlockCount; ++i) {
979 eb = si->ExtensionBlocks + i;
980 if (eb->Function == 0xF9 && eb->ByteCount == 4) {
981 if ((eb->Bytes[0] & 1) == 1) {
982 transparent = eb->Bytes[3];
987 for (i=0;i<(1<<gif->SColorResolution);i++) {
988 bmi->bmiColors[i].rgbRed = cm->Colors[i].Red;
989 bmi->bmiColors[i].rgbGreen = cm->Colors[i].Green;
990 bmi->bmiColors[i].rgbBlue = cm->Colors[i].Blue;
991 if (i == transparent) {
992 This->rgbTrans = RGB(bmi->bmiColors[i].rgbRed,
993 bmi->bmiColors[i].rgbGreen,
994 bmi->bmiColors[i].rgbBlue);
998 /* Map to in picture coordinates */
999 for (i=0;i<gid->Height;i++)
1000 for (j=0;j<gid->Width;j++)
1001 bytes[(gid->Top+i)*(padding)+gid->Left+j]=si->RasterBits[i*gid->Width+j];
1003 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1004 bmi->bmiHeader.biWidth = gif->SWidth;
1005 bmi->bmiHeader.biHeight = -gif->SHeight;
1006 bmi->bmiHeader.biPlanes = 1;
1007 bmi->bmiHeader.biBitCount = 8;
1008 bmi->bmiHeader.biCompression = BI_RGB;
1009 bmi->bmiHeader.biSizeImage = padding*gif->SHeight;
1010 bmi->bmiHeader.biXPelsPerMeter = 0;
1011 bmi->bmiHeader.biYPelsPerMeter = 0;
1012 bmi->bmiHeader.biClrUsed = 1 << gif->SColorResolution;
1013 bmi->bmiHeader.biClrImportant = 0;
1015 hdcref = GetDC(0);
1016 This->desc.u.bmp.hbitmap=CreateDIBitmap(
1017 hdcref,
1018 &bmi->bmiHeader,
1019 CBM_INIT,
1020 bytes,
1021 bmi,
1022 DIB_RGB_COLORS
1025 if (transparent > -1) {
1026 /* Create the Mask */
1027 HDC hdc = CreateCompatibleDC(0);
1028 HDC hdcMask = CreateCompatibleDC(0);
1029 HBITMAP hOldbitmap;
1030 HBITMAP hOldbitmapmask;
1032 This->hbmMask = CreateBitmap(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, 1, 1, NULL);
1034 hOldbitmap = SelectObject(hdc,This->desc.u.bmp.hbitmap);
1035 hOldbitmapmask = SelectObject(hdcMask, This->hbmMask);
1036 SetBkColor(hdc, This->rgbTrans);
1037 BitBlt(hdcMask, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, hdc, 0, 0, SRCCOPY);
1039 /* We no longer need the original bitmap, so we apply the first
1040 transformation with the mask to speed up the rendering */
1041 SetBkColor(hdc, RGB(0,0,0));
1042 SetTextColor(hdc, RGB(255,255,255));
1043 BitBlt(hdc, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
1044 hdcMask, 0, 0, SRCAND);
1046 SelectObject(hdc, hOldbitmap);
1047 SelectObject(hdcMask, hOldbitmapmask);
1048 DeleteDC(hdcMask);
1049 DeleteDC(hdc);
1052 DeleteDC(hdcref);
1053 This->desc.picType = PICTYPE_BITMAP;
1054 OLEPictureImpl_SetBitmap(This);
1055 DGifCloseFile(gif);
1056 HeapFree(GetProcessHeap(),0,bytes);
1057 return S_OK;
1058 #else
1059 FIXME("Trying to load GIF, but no support for libgif/libungif compiled in.\n");
1060 return E_FAIL;
1061 #endif
1062 break;
1064 case 0xd8ff: { /* JPEG */
1065 #ifdef HAVE_LIBJPEG
1066 struct jpeg_decompress_struct jd;
1067 struct jpeg_error_mgr jerr;
1068 int ret;
1069 JDIMENSION x;
1070 JSAMPROW samprow,oldsamprow;
1071 BITMAPINFOHEADER bmi;
1072 LPBYTE bits;
1073 HDC hdcref;
1074 struct jpeg_source_mgr xjsm;
1075 LPBYTE oldbits;
1076 int i;
1078 /* This is basically so we can use in-memory data for jpeg decompression.
1079 * We need to have all the functions.
1081 xjsm.next_input_byte = xbuf;
1082 xjsm.bytes_in_buffer = xread;
1083 xjsm.init_source = _jpeg_init_source;
1084 xjsm.fill_input_buffer = _jpeg_fill_input_buffer;
1085 xjsm.skip_input_data = _jpeg_skip_input_data;
1086 xjsm.resync_to_restart = _jpeg_resync_to_restart;
1087 xjsm.term_source = _jpeg_term_source;
1089 jd.err = jpeg_std_error(&jerr);
1090 jpeg_create_decompress(&jd);
1091 jd.src = &xjsm;
1092 ret=jpeg_read_header(&jd,TRUE);
1093 jd.out_color_space = JCS_RGB;
1094 jpeg_start_decompress(&jd);
1095 if (ret != JPEG_HEADER_OK) {
1096 ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
1097 HeapFree(GetProcessHeap(),0,xbuf);
1098 return E_FAIL;
1101 bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
1102 (jd.output_height+1) * ((jd.output_width*jd.output_components + 3) & ~3) );
1103 samprow=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
1105 oldbits = bits;
1106 oldsamprow = samprow;
1107 while ( jd.output_scanline<jd.output_height ) {
1108 x = jpeg_read_scanlines(&jd,&samprow,1);
1109 if (x != 1) {
1110 FIXME("failed to read current scanline?\n");
1111 break;
1113 /* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
1114 for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) {
1115 *(bits++) = *(samprow+2);
1116 *(bits++) = *(samprow+1);
1117 *(bits++) = *(samprow);
1119 bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
1120 samprow = oldsamprow;
1122 bits = oldbits;
1124 bmi.biSize = sizeof(bmi);
1125 bmi.biWidth = jd.output_width;
1126 bmi.biHeight = -jd.output_height;
1127 bmi.biPlanes = 1;
1128 bmi.biBitCount = jd.output_components<<3;
1129 bmi.biCompression = BI_RGB;
1130 bmi.biSizeImage = jd.output_height*jd.output_width*jd.output_components;
1131 bmi.biXPelsPerMeter = 0;
1132 bmi.biYPelsPerMeter = 0;
1133 bmi.biClrUsed = 0;
1134 bmi.biClrImportant = 0;
1136 HeapFree(GetProcessHeap(),0,samprow);
1137 jpeg_finish_decompress(&jd);
1138 jpeg_destroy_decompress(&jd);
1139 hdcref = GetDC(0);
1140 This->desc.u.bmp.hbitmap=CreateDIBitmap(
1141 hdcref,
1142 &bmi,
1143 CBM_INIT,
1144 bits,
1145 (BITMAPINFO*)&bmi,
1146 DIB_RGB_COLORS
1148 DeleteDC(hdcref);
1149 This->desc.picType = PICTYPE_BITMAP;
1150 OLEPictureImpl_SetBitmap(This);
1151 hr = S_OK;
1152 HeapFree(GetProcessHeap(),0,bits);
1153 #else
1154 ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
1155 hr = E_FAIL;
1156 #endif
1157 break;
1159 case 0x4d42: { /* Bitmap */
1160 BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
1161 BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
1162 HDC hdcref;
1164 /* Does not matter whether this is a coreheader or not, we only use
1165 * components which are in both
1167 hdcref = GetDC(0);
1168 This->desc.u.bmp.hbitmap = CreateDIBitmap(
1169 hdcref,
1170 &(bi->bmiHeader),
1171 CBM_INIT,
1172 xbuf+bfh->bfOffBits,
1174 (bi->bmiHeader.biBitCount<=8)?DIB_PAL_COLORS:DIB_RGB_COLORS
1176 DeleteDC(hdcref);
1177 This->desc.picType = PICTYPE_BITMAP;
1178 OLEPictureImpl_SetBitmap(This);
1179 hr = S_OK;
1180 break;
1182 case 0x0000: { /* ICON , first word is dwReserved */
1183 HICON hicon;
1184 CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
1185 int i;
1188 FIXME("icon.idReserved=%d\n",cifd->idReserved);
1189 FIXME("icon.idType=%d\n",cifd->idType);
1190 FIXME("icon.idCount=%d\n",cifd->idCount);
1192 for (i=0;i<cifd->idCount;i++) {
1193 FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
1194 FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
1195 FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
1196 FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
1197 FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
1198 FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
1199 FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
1200 FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
1203 i=0;
1204 /* If we have more than one icon, try to find the best.
1205 * this currently means '32 pixel wide'.
1207 if (cifd->idCount!=1) {
1208 for (i=0;i<cifd->idCount;i++) {
1209 if (cifd->idEntries[i].bWidth == 32)
1210 break;
1212 if (i==cifd->idCount) i=0;
1215 hicon = CreateIconFromResourceEx(
1216 xbuf+cifd->idEntries[i].dwDIBOffset,
1217 cifd->idEntries[i].dwDIBSize,
1218 TRUE, /* is icon */
1219 0x00030000,
1220 cifd->idEntries[i].bWidth,
1221 cifd->idEntries[i].bHeight,
1224 if (!hicon) {
1225 FIXME("CreateIcon failed.\n");
1226 hr = E_FAIL;
1227 } else {
1228 This->desc.picType = PICTYPE_ICON;
1229 This->desc.u.icon.hicon = hicon;
1230 This->himetricWidth = cifd->idEntries[i].bWidth;
1231 This->himetricHeight = cifd->idEntries[i].bHeight;
1232 hr = S_OK;
1234 break;
1236 default:
1238 int i;
1239 FIXME("Unknown magic %04x, %ld read bytes:\n",magic,xread);
1240 hr=E_FAIL;
1241 for (i=0;i<xread+8;i++) {
1242 if (i<8) MESSAGE("%02x ",((unsigned char*)&header)[i]);
1243 else MESSAGE("%02x ",xbuf[i-8]);
1244 if (i % 10 == 9) MESSAGE("\n");
1246 MESSAGE("\n");
1247 break;
1251 /* FIXME: this notify is not really documented */
1252 if (hr==S_OK)
1253 OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1254 return hr;
1257 static HRESULT WINAPI OLEPictureImpl_Save(
1258 IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1260 ICOM_THIS_From_IPersistStream(IPicture, iface);
1261 FIXME("(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
1262 return E_NOTIMPL;
1265 static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1266 IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1268 ICOM_THIS_From_IPersistStream(IPicture, iface);
1269 FIXME("(%p,%p),stub!\n",This,pcbSize);
1270 return E_NOTIMPL;
1273 /************************************************************************
1274 * IDispatch
1276 /************************************************************************
1277 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1279 * See Windows documentation for more details on IUnknown methods.
1281 static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1282 IDispatch* iface,
1283 REFIID riid,
1284 VOID** ppvoid)
1286 ICOM_THIS_From_IDispatch(IPicture, iface);
1288 return IPicture_QueryInterface(This, riid, ppvoid);
1291 /************************************************************************
1292 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1294 * See Windows documentation for more details on IUnknown methods.
1296 static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1297 IDispatch* iface)
1299 ICOM_THIS_From_IDispatch(IPicture, iface);
1301 return IPicture_AddRef(This);
1304 /************************************************************************
1305 * OLEPictureImpl_IDispatch_Release (IUnknown)
1307 * See Windows documentation for more details on IUnknown methods.
1309 static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1310 IDispatch* iface)
1312 ICOM_THIS_From_IDispatch(IPicture, iface);
1314 return IPicture_Release(This);
1317 /************************************************************************
1318 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1320 * See Windows documentation for more details on IDispatch methods.
1322 static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1323 IDispatch* iface,
1324 unsigned int* pctinfo)
1326 FIXME("():Stub\n");
1328 return E_NOTIMPL;
1331 /************************************************************************
1332 * OLEPictureImpl_GetTypeInfo (IDispatch)
1334 * See Windows documentation for more details on IDispatch methods.
1336 static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1337 IDispatch* iface,
1338 UINT iTInfo,
1339 LCID lcid,
1340 ITypeInfo** ppTInfo)
1342 FIXME("():Stub\n");
1344 return E_NOTIMPL;
1347 /************************************************************************
1348 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1350 * See Windows documentation for more details on IDispatch methods.
1352 static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1353 IDispatch* iface,
1354 REFIID riid,
1355 LPOLESTR* rgszNames,
1356 UINT cNames,
1357 LCID lcid,
1358 DISPID* rgDispId)
1360 FIXME("():Stub\n");
1362 return E_NOTIMPL;
1365 /************************************************************************
1366 * OLEPictureImpl_Invoke (IDispatch)
1368 * See Windows documentation for more details on IDispatch methods.
1370 static HRESULT WINAPI OLEPictureImpl_Invoke(
1371 IDispatch* iface,
1372 DISPID dispIdMember,
1373 REFIID riid,
1374 LCID lcid,
1375 WORD wFlags,
1376 DISPPARAMS* pDispParams,
1377 VARIANT* pVarResult,
1378 EXCEPINFO* pExepInfo,
1379 UINT* puArgErr)
1381 FIXME("(dispid: %ld):Stub\n",dispIdMember);
1383 VariantInit(pVarResult);
1384 V_VT(pVarResult) = VT_BOOL;
1385 V_UNION(pVarResult,boolVal) = FALSE;
1386 return S_OK;
1390 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable =
1392 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1393 OLEPictureImpl_QueryInterface,
1394 OLEPictureImpl_AddRef,
1395 OLEPictureImpl_Release,
1396 OLEPictureImpl_get_Handle,
1397 OLEPictureImpl_get_hPal,
1398 OLEPictureImpl_get_Type,
1399 OLEPictureImpl_get_Width,
1400 OLEPictureImpl_get_Height,
1401 OLEPictureImpl_Render,
1402 OLEPictureImpl_set_hPal,
1403 OLEPictureImpl_get_CurDC,
1404 OLEPictureImpl_SelectPicture,
1405 OLEPictureImpl_get_KeepOriginalFormat,
1406 OLEPictureImpl_put_KeepOriginalFormat,
1407 OLEPictureImpl_PictureChanged,
1408 OLEPictureImpl_SaveAsFile,
1409 OLEPictureImpl_get_Attributes
1412 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable =
1414 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1415 OLEPictureImpl_IDispatch_QueryInterface,
1416 OLEPictureImpl_IDispatch_AddRef,
1417 OLEPictureImpl_IDispatch_Release,
1418 OLEPictureImpl_GetTypeInfoCount,
1419 OLEPictureImpl_GetTypeInfo,
1420 OLEPictureImpl_GetIDsOfNames,
1421 OLEPictureImpl_Invoke
1424 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable =
1426 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1427 OLEPictureImpl_IPersistStream_QueryInterface,
1428 OLEPictureImpl_IPersistStream_AddRef,
1429 OLEPictureImpl_IPersistStream_Release,
1430 OLEPictureImpl_GetClassID,
1431 OLEPictureImpl_IsDirty,
1432 OLEPictureImpl_Load,
1433 OLEPictureImpl_Save,
1434 OLEPictureImpl_GetSizeMax
1437 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable =
1439 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1440 OLEPictureImpl_IConnectionPointContainer_QueryInterface,
1441 OLEPictureImpl_IConnectionPointContainer_AddRef,
1442 OLEPictureImpl_IConnectionPointContainer_Release,
1443 OLEPictureImpl_EnumConnectionPoints,
1444 OLEPictureImpl_FindConnectionPoint
1447 /***********************************************************************
1448 * OleCreatePictureIndirect (OLEAUT32.419)
1450 HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
1451 BOOL fOwn, LPVOID *ppvObj )
1453 OLEPictureImpl* newPict = NULL;
1454 HRESULT hr = S_OK;
1456 TRACE("(%p,%p,%d,%p)\n", lpPictDesc, riid, fOwn, ppvObj);
1459 * Sanity check
1461 if (ppvObj==0)
1462 return E_POINTER;
1464 *ppvObj = NULL;
1467 * Try to construct a new instance of the class.
1469 newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
1471 if (newPict == NULL)
1472 return E_OUTOFMEMORY;
1475 * Make sure it supports the interface required by the caller.
1477 hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
1480 * Release the reference obtained in the constructor. If
1481 * the QueryInterface was unsuccessful, it will free the class.
1483 IPicture_Release((IPicture*)newPict);
1485 return hr;
1489 /***********************************************************************
1490 * OleLoadPicture (OLEAUT32.418)
1492 HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1493 REFIID riid, LPVOID *ppvObj )
1495 LPPERSISTSTREAM ps;
1496 IPicture *newpic;
1497 HRESULT hr;
1499 TRACE("(%p,%ld,%d,%s,%p), partially implemented.\n",
1500 lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
1502 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1503 if (hr)
1504 return hr;
1505 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1506 if (hr) {
1507 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1508 IPicture_Release(newpic);
1509 *ppvObj = NULL;
1510 return hr;
1512 IPersistStream_Load(ps,lpstream);
1513 IPersistStream_Release(ps);
1514 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1515 if (hr)
1516 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1517 IPicture_Release(newpic);
1518 return hr;
1521 /***********************************************************************
1522 * OleLoadPictureEx (OLEAUT32.401)
1524 HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1525 REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
1527 LPPERSISTSTREAM ps;
1528 IPicture *newpic;
1529 HRESULT hr;
1531 FIXME("(%p,%ld,%d,%s,x=%ld,y=%ld,f=%lx,%p), partially implemented.\n",
1532 lpstream, lSize, fRunmode, debugstr_guid(riid), xsiz, ysiz, flags, ppvObj);
1534 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1535 if (hr)
1536 return hr;
1537 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1538 if (hr) {
1539 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1540 IPicture_Release(newpic);
1541 *ppvObj = NULL;
1542 return hr;
1544 IPersistStream_Load(ps,lpstream);
1545 IPersistStream_Release(ps);
1546 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1547 if (hr)
1548 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1549 IPicture_Release(newpic);
1550 return hr;
1553 /*******************************************************************************
1554 * StdPic ClassFactory
1556 typedef struct
1558 /* IUnknown fields */
1559 ICOM_VFIELD(IClassFactory);
1560 DWORD ref;
1561 } IClassFactoryImpl;
1563 static HRESULT WINAPI
1564 SPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1565 ICOM_THIS(IClassFactoryImpl,iface);
1567 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1568 return E_NOINTERFACE;
1571 static ULONG WINAPI
1572 SPCF_AddRef(LPCLASSFACTORY iface) {
1573 ICOM_THIS(IClassFactoryImpl,iface);
1574 return ++(This->ref);
1577 static ULONG WINAPI SPCF_Release(LPCLASSFACTORY iface) {
1578 ICOM_THIS(IClassFactoryImpl,iface);
1579 /* static class, won't be freed */
1580 return --(This->ref);
1583 static HRESULT WINAPI SPCF_CreateInstance(
1584 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1586 PICTDESC pd;
1588 FIXME("(%p,%p,%s,%p), creating stdpic with PICTYPE_NONE.\n",iface,pOuter,debugstr_guid(riid),ppobj);
1589 pd.cbSizeofstruct = sizeof(pd);
1590 pd.picType = PICTYPE_NONE;
1591 return OleCreatePictureIndirect(&pd,riid,TRUE,ppobj);
1595 static HRESULT WINAPI SPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1596 ICOM_THIS(IClassFactoryImpl,iface);
1597 FIXME("(%p)->(%d),stub!\n",This,dolock);
1598 return S_OK;
1601 static ICOM_VTABLE(IClassFactory) SPCF_Vtbl = {
1602 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1603 SPCF_QueryInterface,
1604 SPCF_AddRef,
1605 SPCF_Release,
1606 SPCF_CreateInstance,
1607 SPCF_LockServer
1609 static IClassFactoryImpl STDPIC_CF = {&SPCF_Vtbl, 1 };
1611 void _get_STDPIC_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDPIC_CF; }