Sql tokens are case insensitive in msi.dll.
[wine/wine64.git] / dlls / oleaut32 / olepicture.c
blob5f174faa946e9e156b2a9d7957b0a142f1ce2bd2
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 /* data */
122 void* data;
123 int datalen;
124 } OLEPictureImpl;
127 * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
129 #define ICOM_THIS_From_IDispatch(impl, name) \
130 impl *This = (impl*)(((char*)name)-sizeof(void*));
131 #define ICOM_THIS_From_IPersistStream(impl, name) \
132 impl *This = (impl*)(((char*)name)-2*sizeof(void*));
133 #define ICOM_THIS_From_IConnectionPointContainer(impl, name) \
134 impl *This = (impl*)(((char*)name)-3*sizeof(void*));
137 * Predeclare VTables. They get initialized at the end.
139 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable;
140 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable;
141 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable;
142 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable;
144 /***********************************************************************
145 * Implementation of the OLEPictureImpl class.
148 static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
149 BITMAP bm;
150 HDC hdcRef;
152 TRACE("bitmap handle %p\n", This->desc.u.bmp.hbitmap);
153 if(GetObjectA(This->desc.u.bmp.hbitmap, sizeof(bm), &bm) != sizeof(bm)) {
154 ERR("GetObject fails\n");
155 return;
157 This->origWidth = bm.bmWidth;
158 This->origHeight = bm.bmHeight;
159 /* The width and height are stored in HIMETRIC units (0.01 mm),
160 so we take our pixel width divide by pixels per inch and
161 multiply by 25.4 * 100 */
162 /* Should we use GetBitmapDimension if available? */
163 hdcRef = CreateCompatibleDC(0);
164 This->himetricWidth =(bm.bmWidth *2540)/GetDeviceCaps(hdcRef, LOGPIXELSX);
165 This->himetricHeight=(bm.bmHeight*2540)/GetDeviceCaps(hdcRef, LOGPIXELSY);
166 DeleteDC(hdcRef);
169 /************************************************************************
170 * OLEPictureImpl_Construct
172 * This method will construct a new instance of the OLEPictureImpl
173 * class.
175 * The caller of this method must release the object when it's
176 * done with it.
178 static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
180 OLEPictureImpl* newObject = 0;
182 if (pictDesc)
183 TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
186 * Allocate space for the object.
188 newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
190 if (newObject==0)
191 return newObject;
194 * Initialize the virtual function table.
196 newObject->lpvtbl1 = &OLEPictureImpl_VTable;
197 newObject->lpvtbl2 = &OLEPictureImpl_IDispatch_VTable;
198 newObject->lpvtbl3 = &OLEPictureImpl_IPersistStream_VTable;
199 newObject->lpvtbl4 = &OLEPictureImpl_IConnectionPointContainer_VTable;
201 CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
204 * Start with one reference count. The caller of this function
205 * must release the interface pointer when it is done.
207 newObject->ref = 1;
208 newObject->hDCCur = 0;
210 newObject->fOwn = fOwn;
212 /* dunno about original value */
213 newObject->keepOrigFormat = TRUE;
215 if (pictDesc) {
216 if(pictDesc->cbSizeofstruct != sizeof(PICTDESC)) {
217 FIXME("struct size = %d\n", pictDesc->cbSizeofstruct);
219 memcpy(&newObject->desc, pictDesc, sizeof(PICTDESC));
222 switch(pictDesc->picType) {
223 case PICTYPE_BITMAP:
224 OLEPictureImpl_SetBitmap(newObject);
225 break;
227 case PICTYPE_METAFILE:
228 TRACE("metafile handle %p\n", pictDesc->u.wmf.hmeta);
229 newObject->himetricWidth = pictDesc->u.wmf.xExt;
230 newObject->himetricHeight = pictDesc->u.wmf.yExt;
231 break;
233 case PICTYPE_NONE:
234 /* not sure what to do here */
235 newObject->himetricWidth = newObject->himetricHeight = 0;
236 break;
238 case PICTYPE_ICON:
239 case PICTYPE_ENHMETAFILE:
240 default:
241 FIXME("Unsupported type %d\n", pictDesc->picType);
242 newObject->himetricWidth = newObject->himetricHeight = 0;
243 break;
245 } else {
246 newObject->desc.picType = PICTYPE_UNINITIALIZED;
249 TRACE("returning %p\n", newObject);
250 return newObject;
253 /************************************************************************
254 * OLEPictureImpl_Destroy
256 * This method is called by the Release method when the reference
257 * count goes down to 0. It will free all resources used by
258 * this object. */
259 static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
261 TRACE("(%p)\n", Obj);
263 if(Obj->fOwn) { /* We need to destroy the picture */
264 switch(Obj->desc.picType) {
265 case PICTYPE_BITMAP:
266 DeleteObject(Obj->desc.u.bmp.hbitmap);
267 break;
268 case PICTYPE_METAFILE:
269 DeleteMetaFile(Obj->desc.u.wmf.hmeta);
270 break;
271 case PICTYPE_ICON:
272 DestroyIcon(Obj->desc.u.icon.hicon);
273 break;
274 case PICTYPE_ENHMETAFILE:
275 DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
276 break;
277 default:
278 FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
279 break;
282 if (Obj->data) HeapFree(GetProcessHeap(), 0, Obj->data);
283 HeapFree(GetProcessHeap(), 0, Obj);
286 static ULONG WINAPI OLEPictureImpl_AddRef(IPicture* iface);
288 /************************************************************************
289 * OLEPictureImpl_QueryInterface (IUnknown)
291 * See Windows documentation for more details on IUnknown methods.
293 static HRESULT WINAPI OLEPictureImpl_QueryInterface(
294 IPicture* iface,
295 REFIID riid,
296 void** ppvObject)
298 ICOM_THIS(OLEPictureImpl, iface);
299 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
302 * Perform a sanity check on the parameters.
304 if ( (This==0) || (ppvObject==0) )
305 return E_INVALIDARG;
308 * Initialize the return parameter.
310 *ppvObject = 0;
313 * Compare the riid with the interface IDs implemented by this object.
315 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
317 *ppvObject = (IPicture*)This;
319 else if (memcmp(&IID_IPicture, riid, sizeof(IID_IPicture)) == 0)
321 *ppvObject = (IPicture*)This;
323 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
325 *ppvObject = (IDispatch*)&(This->lpvtbl2);
327 else if (memcmp(&IID_IPictureDisp, riid, sizeof(IID_IPictureDisp)) == 0)
329 *ppvObject = (IDispatch*)&(This->lpvtbl2);
331 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
333 *ppvObject = (IPersistStream*)&(This->lpvtbl3);
335 else if (memcmp(&IID_IConnectionPointContainer, riid, sizeof(IID_IConnectionPointContainer)) == 0)
337 *ppvObject = (IConnectionPointContainer*)&(This->lpvtbl4);
340 * Check that we obtained an interface.
342 if ((*ppvObject)==0)
344 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
345 return E_NOINTERFACE;
349 * Query Interface always increases the reference count by one when it is
350 * successful
352 OLEPictureImpl_AddRef((IPicture*)This);
354 return S_OK;
356 /***********************************************************************
357 * OLEPicture_SendNotify (internal)
359 * Sends notification messages of changed properties to any interested
360 * connections.
362 static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
364 IEnumConnections *pEnum;
365 CONNECTDATA CD;
367 if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
368 return;
369 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
370 IPropertyNotifySink *sink;
372 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
373 IPropertyNotifySink_OnChanged(sink, dispID);
374 IPropertyNotifySink_Release(sink);
375 IUnknown_Release(CD.pUnk);
377 IEnumConnections_Release(pEnum);
378 return;
381 /************************************************************************
382 * OLEPictureImpl_AddRef (IUnknown)
384 * See Windows documentation for more details on IUnknown methods.
386 static ULONG WINAPI OLEPictureImpl_AddRef(
387 IPicture* iface)
389 ICOM_THIS(OLEPictureImpl, iface);
390 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
391 This->ref++;
393 return This->ref;
396 /************************************************************************
397 * OLEPictureImpl_Release (IUnknown)
399 * See Windows documentation for more details on IUnknown methods.
401 static ULONG WINAPI OLEPictureImpl_Release(
402 IPicture* iface)
404 ICOM_THIS(OLEPictureImpl, iface);
405 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
408 * Decrease the reference count on this object.
410 This->ref--;
413 * If the reference count goes down to 0, perform suicide.
415 if (This->ref==0)
417 OLEPictureImpl_Destroy(This);
419 return 0;
422 return This->ref;
426 /************************************************************************
427 * OLEPictureImpl_get_Handle
429 static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
430 OLE_HANDLE *phandle)
432 ICOM_THIS(OLEPictureImpl, iface);
433 TRACE("(%p)->(%p)\n", This, phandle);
434 switch(This->desc.picType) {
435 case PICTYPE_BITMAP:
436 *phandle = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
437 break;
438 case PICTYPE_METAFILE:
439 *phandle = (OLE_HANDLE)This->desc.u.wmf.hmeta;
440 break;
441 case PICTYPE_ICON:
442 *phandle = (OLE_HANDLE)This->desc.u.icon.hicon;
443 break;
444 case PICTYPE_ENHMETAFILE:
445 *phandle = (OLE_HANDLE)This->desc.u.emf.hemf;
446 break;
447 default:
448 FIXME("Unimplemented type %d\n", This->desc.picType);
449 return E_NOTIMPL;
451 TRACE("returning handle %08x\n", *phandle);
452 return S_OK;
455 /************************************************************************
456 * OLEPictureImpl_get_hPal
458 static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
459 OLE_HANDLE *phandle)
461 ICOM_THIS(OLEPictureImpl, iface);
462 FIXME("(%p)->(%p): stub\n", This, phandle);
463 return E_NOTIMPL;
466 /************************************************************************
467 * OLEPictureImpl_get_Type
469 static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
470 short *ptype)
472 ICOM_THIS(OLEPictureImpl, iface);
473 TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
474 *ptype = This->desc.picType;
475 return S_OK;
478 /************************************************************************
479 * OLEPictureImpl_get_Width
481 static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
482 OLE_XSIZE_HIMETRIC *pwidth)
484 ICOM_THIS(OLEPictureImpl, iface);
485 TRACE("(%p)->(%p): width is %ld\n", This, pwidth, This->himetricWidth);
486 *pwidth = This->himetricWidth;
487 return S_OK;
490 /************************************************************************
491 * OLEPictureImpl_get_Height
493 static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
494 OLE_YSIZE_HIMETRIC *pheight)
496 ICOM_THIS(OLEPictureImpl, iface);
497 TRACE("(%p)->(%p): height is %ld\n", This, pheight, This->himetricHeight);
498 *pheight = This->himetricHeight;
499 return S_OK;
502 /************************************************************************
503 * OLEPictureImpl_Render
505 static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
506 long x, long y, long cx, long cy,
507 OLE_XPOS_HIMETRIC xSrc,
508 OLE_YPOS_HIMETRIC ySrc,
509 OLE_XSIZE_HIMETRIC cxSrc,
510 OLE_YSIZE_HIMETRIC cySrc,
511 LPCRECT prcWBounds)
513 ICOM_THIS(OLEPictureImpl, iface);
514 TRACE("(%p)->(%p, (%ld,%ld), (%ld,%ld) <- (%ld,%ld), (%ld,%ld), %p)\n",
515 This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
516 if(prcWBounds)
517 TRACE("prcWBounds (%ld,%ld) - (%ld,%ld)\n", prcWBounds->left, prcWBounds->top,
518 prcWBounds->right, prcWBounds->bottom);
521 * While the documentation suggests this to be here (or after rendering?)
522 * it does cause an endless recursion in my sample app. -MM 20010804
523 OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
526 switch(This->desc.picType) {
527 case PICTYPE_BITMAP:
529 HBITMAP hbmpOld;
530 HDC hdcBmp;
532 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
533 NB y-axis gets flipped */
535 hdcBmp = CreateCompatibleDC(0);
536 SetMapMode(hdcBmp, MM_ANISOTROPIC);
537 SetWindowOrgEx(hdcBmp, 0, 0, NULL);
538 SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
539 SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
540 SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
542 hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
544 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
546 SelectObject(hdcBmp, hbmpOld);
547 DeleteDC(hdcBmp);
549 break;
550 case PICTYPE_ICON:
551 FIXME("Not quite correct implementation of rendering icons...\n");
552 DrawIcon(hdc,x,y,This->desc.u.icon.hicon);
553 break;
555 case PICTYPE_METAFILE:
556 case PICTYPE_ENHMETAFILE:
557 default:
558 FIXME("type %d not implemented\n", This->desc.picType);
559 return E_NOTIMPL;
561 return S_OK;
564 /************************************************************************
565 * OLEPictureImpl_set_hPal
567 static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
568 OLE_HANDLE hpal)
570 ICOM_THIS(OLEPictureImpl, iface);
571 FIXME("(%p)->(%08x): stub\n", This, hpal);
572 OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
573 return E_NOTIMPL;
576 /************************************************************************
577 * OLEPictureImpl_get_CurDC
579 static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
580 HDC *phdc)
582 ICOM_THIS(OLEPictureImpl, iface);
583 TRACE("(%p), returning %p\n", This, This->hDCCur);
584 if (phdc) *phdc = This->hDCCur;
585 return S_OK;
588 /************************************************************************
589 * OLEPictureImpl_SelectPicture
591 static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
592 HDC hdcIn,
593 HDC *phdcOut,
594 OLE_HANDLE *phbmpOut)
596 ICOM_THIS(OLEPictureImpl, iface);
597 TRACE("(%p)->(%p, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
598 if (This->desc.picType == PICTYPE_BITMAP) {
599 SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
601 if (phdcOut)
602 *phdcOut = This->hDCCur;
603 This->hDCCur = hdcIn;
604 if (phbmpOut)
605 *phbmpOut = (OLE_HANDLE)This->desc.u.bmp.hbitmap;
606 return S_OK;
607 } else {
608 FIXME("Don't know how to select picture type %d\n",This->desc.picType);
609 return E_FAIL;
613 /************************************************************************
614 * OLEPictureImpl_get_KeepOriginalFormat
616 static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
617 BOOL *pfKeep)
619 ICOM_THIS(OLEPictureImpl, iface);
620 TRACE("(%p)->(%p)\n", This, pfKeep);
621 if (!pfKeep)
622 return E_POINTER;
623 *pfKeep = This->keepOrigFormat;
624 return S_OK;
627 /************************************************************************
628 * OLEPictureImpl_put_KeepOriginalFormat
630 static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
631 BOOL keep)
633 ICOM_THIS(OLEPictureImpl, iface);
634 TRACE("(%p)->(%d)\n", This, keep);
635 This->keepOrigFormat = keep;
636 /* FIXME: what DISPID notification here? */
637 return S_OK;
640 /************************************************************************
641 * OLEPictureImpl_PictureChanged
643 static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
645 ICOM_THIS(OLEPictureImpl, iface);
646 TRACE("(%p)->()\n", This);
647 OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
648 return S_OK;
651 /************************************************************************
652 * OLEPictureImpl_SaveAsFile
654 static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
655 IStream *pstream,
656 BOOL SaveMemCopy,
657 LONG *pcbSize)
659 ICOM_THIS(OLEPictureImpl, iface);
660 FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This, pstream, SaveMemCopy, pcbSize);
661 return IStream_Write(pstream,This->data,This->datalen,(ULONG*)pcbSize);
664 /************************************************************************
665 * OLEPictureImpl_get_Attributes
667 static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
668 DWORD *pdwAttr)
670 ICOM_THIS(OLEPictureImpl, iface);
671 TRACE("(%p)->(%p).\n", This, pdwAttr);
672 *pdwAttr = 0;
673 switch (This->desc.picType) {
674 case PICTYPE_BITMAP: break; /* not 'truely' scalable, see MSDN. */
675 case PICTYPE_ICON: *pdwAttr = PICTURE_TRANSPARENT;break;
676 case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
677 default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
679 return S_OK;
683 /************************************************************************
684 * IConnectionPointContainer
687 static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
688 IConnectionPointContainer* iface,
689 REFIID riid,
690 VOID** ppvoid
692 ICOM_THIS_From_IConnectionPointContainer(IPicture,iface);
694 return IPicture_QueryInterface(This,riid,ppvoid);
697 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
698 IConnectionPointContainer* iface)
700 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
702 return IPicture_AddRef(This);
705 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
706 IConnectionPointContainer* iface)
708 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
710 return IPicture_Release(This);
713 static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
714 IConnectionPointContainer* iface,
715 IEnumConnectionPoints** ppEnum
717 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
719 FIXME("(%p,%p), stub!\n",This,ppEnum);
720 return E_NOTIMPL;
723 static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
724 IConnectionPointContainer* iface,
725 REFIID riid,
726 IConnectionPoint **ppCP
728 ICOM_THIS_From_IConnectionPointContainer(OLEPictureImpl, iface);
729 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
730 if (!ppCP)
731 return E_POINTER;
732 *ppCP = NULL;
733 if (IsEqualGUID(riid,&IID_IPropertyNotifySink))
734 return IConnectionPoint_QueryInterface(This->pCP,&IID_IConnectionPoint,(LPVOID)ppCP);
735 FIXME("tried to find connection point on %s?\n",debugstr_guid(riid));
736 return 0x80040200;
738 /************************************************************************
739 * IPersistStream
741 /************************************************************************
742 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
744 * See Windows documentation for more details on IUnknown methods.
746 static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
747 IPersistStream* iface,
748 REFIID riid,
749 VOID** ppvoid)
751 ICOM_THIS_From_IPersistStream(IPicture, iface);
753 return IPicture_QueryInterface(This, riid, ppvoid);
756 /************************************************************************
757 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
759 * See Windows documentation for more details on IUnknown methods.
761 static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
762 IPersistStream* iface)
764 ICOM_THIS_From_IPersistStream(IPicture, iface);
766 return IPicture_AddRef(This);
769 /************************************************************************
770 * OLEPictureImpl_IPersistStream_Release (IUnknown)
772 * See Windows documentation for more details on IUnknown methods.
774 static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
775 IPersistStream* iface)
777 ICOM_THIS_From_IPersistStream(IPicture, iface);
779 return IPicture_Release(This);
782 /************************************************************************
783 * OLEPictureImpl_IPersistStream_GetClassID
785 static HRESULT WINAPI OLEPictureImpl_GetClassID(
786 IPersistStream* iface,CLSID* pClassID)
788 ICOM_THIS_From_IPersistStream(IPicture, iface);
789 FIXME("(%p),stub!\n",This);
790 return E_NOTIMPL;
793 /************************************************************************
794 * OLEPictureImpl_IPersistStream_IsDirty
796 static HRESULT WINAPI OLEPictureImpl_IsDirty(
797 IPersistStream* iface)
799 ICOM_THIS_From_IPersistStream(IPicture, iface);
800 FIXME("(%p),stub!\n",This);
801 return E_NOTIMPL;
804 #ifdef HAVE_LIBJPEG
805 /* for the jpeg decompressor source manager. */
806 static void _jpeg_init_source(j_decompress_ptr cinfo) { }
808 static boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
809 ERR("(), should not get here.\n");
810 return FALSE;
813 static void _jpeg_skip_input_data(j_decompress_ptr cinfo,long num_bytes) {
814 TRACE("Skipping %ld bytes...\n", num_bytes);
815 cinfo->src->next_input_byte += num_bytes;
816 cinfo->src->bytes_in_buffer -= num_bytes;
819 static boolean _jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired) {
820 ERR("(desired=%d), should not get here.\n",desired);
821 return FALSE;
823 static void _jpeg_term_source(j_decompress_ptr cinfo) { }
824 #endif /* HAVE_LIBJPEG */
826 #ifdef HAVE_LIBGIF
827 struct gifdata {
828 unsigned char *data;
829 unsigned int curoff;
830 unsigned int len;
833 static int _gif_inputfunc(GifFileType *gif, GifByteType *data, int len) {
834 struct gifdata *gd = (struct gifdata*)gif->UserData;
836 if (len+gd->curoff > gd->len) {
837 FIXME("Trying to read %d bytes, but only %d available.\n",len, gd->len-gd->curoff);
838 len = gd->len - gd->curoff;
840 memcpy(data, gd->data+gd->curoff, len);
841 gd->curoff += len;
842 return len;
844 #endif
846 /************************************************************************
847 * OLEPictureImpl_IPersistStream_Load (IUnknown)
849 * Loads the binary data from the IStream. Starts at current position.
850 * There appears to be an 2 DWORD header:
851 * DWORD magic;
852 * DWORD len;
854 * Currently implemented: BITMAP, ICON, JPEG.
856 static HRESULT WINAPI OLEPictureImpl_Load(IPersistStream* iface,IStream*pStm) {
857 HRESULT hr = E_FAIL;
858 ULONG xread;
859 BYTE *xbuf;
860 DWORD header[2];
861 WORD magic;
862 STATSTG statstg;
863 ICOM_THIS_From_IPersistStream(OLEPictureImpl, iface);
865 TRACE("(%p,%p)\n",This,pStm);
867 /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
868 * out whether we do.
870 hr=IStream_Stat(pStm,&statstg,STATFLAG_NONAME);
871 if (hr)
872 FIXME("Stat failed with hres %lx\n",hr);
873 hr=IStream_Read(pStm,header,8,&xread);
874 if (hr || xread!=8) {
875 FIXME("Failure while reading picture header (hr is %lx, nread is %ld).\n",hr,xread);
876 return hr;
878 if (header[1] > statstg.cbSize.QuadPart) {/* Incorrect header, assume none. */
879 xread = 8;
880 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,statstg.cbSize.QuadPart);
881 memcpy(xbuf,&header,8);
882 This->datalen = statstg.cbSize.QuadPart;
883 while (xread < This->datalen) {
884 ULONG nread;
885 hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
886 xread+=nread;
887 if (hr || !nread)
888 break;
890 if (xread != This->datalen)
891 FIXME("Could only read %ld of %d bytes in no-header case?\n",xread,This->datalen);
892 } else {
893 xread = 0;
894 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
895 This->datalen = header[1];
896 while (xread < header[1]) {
897 ULONG nread;
898 hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
899 xread+=nread;
900 if (hr || !nread)
901 break;
903 if (xread != header[1])
904 FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
906 magic = xbuf[0] + (xbuf[1]<<8);
907 switch (magic) {
908 case 0x4947: { /* GIF */
909 #ifdef HAVE_LIBGIF
910 struct gifdata gd;
911 GifFileType *gif;
912 BITMAPINFO *bmi;
913 HDC hdcref;
914 LPBYTE bytes;
915 int i,j,ret;
916 GifImageDesc *gid;
917 SavedImage *si;
918 ColorMapObject *cm;
920 gd.data = xbuf;
921 gd.curoff = 0;
922 gd.len = xread;
923 gif = DGifOpen((void*)&gd, _gif_inputfunc);
924 ret = DGifSlurp(gif);
925 if (ret == GIF_ERROR) {
926 FIXME("Failed reading GIF using libgif.\n");
927 return E_FAIL;
929 TRACE("screen height %d, width %d\n", gif->SWidth, gif->SHeight);
930 TRACE("color res %d, backgcolor %d\n", gif->SColorResolution, gif->SBackGroundColor);
931 TRACE("imgcnt %d\n", gif->ImageCount);
932 if (gif->ImageCount<1) {
933 FIXME("GIF stream does not have images inside?\n");
934 return E_FAIL;
936 TRACE("curimage: %d x %d, on %dx%d, interlace %d\n",
937 gif->Image.Width, gif->Image.Height,
938 gif->Image.Left, gif->Image.Top,
939 gif->Image.Interlace
941 /* */
942 bmi = HeapAlloc(GetProcessHeap(),0,sizeof(BITMAPINFOHEADER)+(1<<gif->SColorResolution)*sizeof(RGBQUAD));
943 bytes= HeapAlloc(GetProcessHeap(),0,gif->SWidth*gif->SHeight);
944 si = gif->SavedImages+0;
945 gid = &(si->ImageDesc);
946 cm = gid->ColorMap;
947 if (!cm) cm = gif->SColorMap;
948 for (i=0;i<(1<<gif->SColorResolution);i++) {
949 bmi->bmiColors[i].rgbRed = cm->Colors[i].Red;
950 bmi->bmiColors[i].rgbGreen = cm->Colors[i].Green;
951 bmi->bmiColors[i].rgbBlue = cm->Colors[i].Blue;
953 /* Map to in picture coordinates */
954 for (i=0;i<gid->Height;i++)
955 for (j=0;j<gid->Width;j++)
956 bytes[(gid->Top+i)*gif->SWidth+gid->Left+j]=si->RasterBits[i*gid->Width+j];
957 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
958 bmi->bmiHeader.biWidth = gif->SWidth;
959 bmi->bmiHeader.biHeight = gif->SHeight;
960 bmi->bmiHeader.biPlanes = 1;
961 bmi->bmiHeader.biBitCount = 8;
962 bmi->bmiHeader.biCompression = BI_RGB;
963 bmi->bmiHeader.biSizeImage = gif->SWidth*gif->SHeight;
964 bmi->bmiHeader.biXPelsPerMeter = 0;
965 bmi->bmiHeader.biYPelsPerMeter = 0;
966 bmi->bmiHeader.biClrUsed = 1 << gif->SColorResolution;
967 bmi->bmiHeader.biClrImportant = 0;
969 hdcref = GetDC(0);
970 This->desc.u.bmp.hbitmap=CreateDIBitmap(
971 hdcref,
972 &bmi->bmiHeader,
973 CBM_INIT,
974 bytes,
975 bmi,
976 DIB_PAL_COLORS
978 DeleteDC(hdcref);
979 This->desc.picType = PICTYPE_BITMAP;
980 OLEPictureImpl_SetBitmap(This);
981 DGifCloseFile(gif);
982 HeapFree(GetProcessHeap(),0,bytes);
983 return S_OK;
984 #else
985 FIXME("Trying to load GIF, but no support for libgif/libungif compiled in.\n");
986 return E_FAIL;
987 #endif
988 break;
990 case 0xd8ff: { /* JPEG */
991 #ifdef HAVE_LIBJPEG
992 struct jpeg_decompress_struct jd;
993 struct jpeg_error_mgr jerr;
994 int ret;
995 JDIMENSION x;
996 JSAMPROW samprow,oldsamprow;
997 BITMAPINFOHEADER bmi;
998 LPBYTE bits;
999 HDC hdcref;
1000 struct jpeg_source_mgr xjsm;
1001 LPBYTE oldbits;
1002 int i;
1004 /* This is basically so we can use in-memory data for jpeg decompression.
1005 * We need to have all the functions.
1007 xjsm.next_input_byte = xbuf;
1008 xjsm.bytes_in_buffer = xread;
1009 xjsm.init_source = _jpeg_init_source;
1010 xjsm.fill_input_buffer = _jpeg_fill_input_buffer;
1011 xjsm.skip_input_data = _jpeg_skip_input_data;
1012 xjsm.resync_to_restart = _jpeg_resync_to_restart;
1013 xjsm.term_source = _jpeg_term_source;
1015 jd.err = jpeg_std_error(&jerr);
1016 jpeg_create_decompress(&jd);
1017 jd.src = &xjsm;
1018 ret=jpeg_read_header(&jd,TRUE);
1019 jd.out_color_space = JCS_RGB;
1020 jpeg_start_decompress(&jd);
1021 if (ret != JPEG_HEADER_OK) {
1022 ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
1023 HeapFree(GetProcessHeap(),0,xbuf);
1024 return E_FAIL;
1027 bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
1028 (jd.output_height+1) * ((jd.output_width*jd.output_components + 3) & ~3) );
1029 samprow=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
1031 oldbits = bits;
1032 oldsamprow = samprow;
1033 while ( jd.output_scanline<jd.output_height ) {
1034 x = jpeg_read_scanlines(&jd,&samprow,1);
1035 if (x != 1) {
1036 FIXME("failed to read current scanline?\n");
1037 break;
1039 /* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
1040 for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) {
1041 *(bits++) = *(samprow+2);
1042 *(bits++) = *(samprow+1);
1043 *(bits++) = *(samprow);
1045 bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
1046 samprow = oldsamprow;
1048 bits = oldbits;
1050 bmi.biSize = sizeof(bmi);
1051 bmi.biWidth = jd.output_width;
1052 bmi.biHeight = -jd.output_height;
1053 bmi.biPlanes = 1;
1054 bmi.biBitCount = jd.output_components<<3;
1055 bmi.biCompression = BI_RGB;
1056 bmi.biSizeImage = jd.output_height*jd.output_width*jd.output_components;
1057 bmi.biXPelsPerMeter = 0;
1058 bmi.biYPelsPerMeter = 0;
1059 bmi.biClrUsed = 0;
1060 bmi.biClrImportant = 0;
1062 HeapFree(GetProcessHeap(),0,samprow);
1063 jpeg_finish_decompress(&jd);
1064 jpeg_destroy_decompress(&jd);
1065 hdcref = GetDC(0);
1066 This->desc.u.bmp.hbitmap=CreateDIBitmap(
1067 hdcref,
1068 &bmi,
1069 CBM_INIT,
1070 bits,
1071 (BITMAPINFO*)&bmi,
1072 DIB_RGB_COLORS
1074 DeleteDC(hdcref);
1075 This->desc.picType = PICTYPE_BITMAP;
1076 OLEPictureImpl_SetBitmap(This);
1077 hr = S_OK;
1078 HeapFree(GetProcessHeap(),0,bits);
1079 #else
1080 ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
1081 hr = E_FAIL;
1082 #endif
1083 break;
1085 case 0x4d42: { /* Bitmap */
1086 BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
1087 BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
1088 HDC hdcref;
1090 /* Does not matter whether this is a coreheader or not, we only use
1091 * components which are in both
1093 hdcref = GetDC(0);
1094 This->desc.u.bmp.hbitmap = CreateDIBitmap(
1095 hdcref,
1096 &(bi->bmiHeader),
1097 CBM_INIT,
1098 xbuf+bfh->bfOffBits,
1100 (bi->bmiHeader.biBitCount<=8)?DIB_PAL_COLORS:DIB_RGB_COLORS
1102 DeleteDC(hdcref);
1103 This->desc.picType = PICTYPE_BITMAP;
1104 OLEPictureImpl_SetBitmap(This);
1105 hr = S_OK;
1106 break;
1108 case 0x0000: { /* ICON , first word is dwReserved */
1109 HICON hicon;
1110 CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
1111 int i;
1114 FIXME("icon.idReserved=%d\n",cifd->idReserved);
1115 FIXME("icon.idType=%d\n",cifd->idType);
1116 FIXME("icon.idCount=%d\n",cifd->idCount);
1118 for (i=0;i<cifd->idCount;i++) {
1119 FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
1120 FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
1121 FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
1122 FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
1123 FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
1124 FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
1125 FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
1126 FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
1129 i=0;
1130 /* If we have more than one icon, try to find the best.
1131 * this currently means '32 pixel wide'.
1133 if (cifd->idCount!=1) {
1134 for (i=0;i<cifd->idCount;i++) {
1135 if (cifd->idEntries[i].bWidth == 32)
1136 break;
1138 if (i==cifd->idCount) i=0;
1141 hicon = CreateIconFromResourceEx(
1142 xbuf+cifd->idEntries[i].dwDIBOffset,
1143 cifd->idEntries[i].dwDIBSize,
1144 TRUE, /* is icon */
1145 0x00030000,
1146 cifd->idEntries[i].bWidth,
1147 cifd->idEntries[i].bHeight,
1150 if (!hicon) {
1151 FIXME("CreateIcon failed.\n");
1152 hr = E_FAIL;
1153 } else {
1154 This->desc.picType = PICTYPE_ICON;
1155 This->desc.u.icon.hicon = hicon;
1156 This->himetricWidth = cifd->idEntries[i].bWidth;
1157 This->himetricHeight = cifd->idEntries[i].bHeight;
1158 hr = S_OK;
1160 break;
1162 default:
1164 int i;
1165 FIXME("Unknown magic %04x, %ld read bytes:\n",magic,xread);
1166 hr=E_FAIL;
1167 for (i=0;i<xread+8;i++) {
1168 if (i<8) MESSAGE("%02x ",((unsigned char*)&header)[i]);
1169 else MESSAGE("%02x ",xbuf[i-8]);
1170 if (i % 10 == 9) MESSAGE("\n");
1172 MESSAGE("\n");
1173 break;
1177 /* FIXME: this notify is not really documented */
1178 if (hr==S_OK)
1179 OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1180 return hr;
1183 static HRESULT WINAPI OLEPictureImpl_Save(
1184 IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1186 ICOM_THIS_From_IPersistStream(IPicture, iface);
1187 FIXME("(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
1188 return E_NOTIMPL;
1191 static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1192 IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1194 ICOM_THIS_From_IPersistStream(IPicture, iface);
1195 FIXME("(%p,%p),stub!\n",This,pcbSize);
1196 return E_NOTIMPL;
1199 /************************************************************************
1200 * IDispatch
1202 /************************************************************************
1203 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1205 * See Windows documentation for more details on IUnknown methods.
1207 static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1208 IDispatch* iface,
1209 REFIID riid,
1210 VOID** ppvoid)
1212 ICOM_THIS_From_IDispatch(IPicture, iface);
1214 return IPicture_QueryInterface(This, riid, ppvoid);
1217 /************************************************************************
1218 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1220 * See Windows documentation for more details on IUnknown methods.
1222 static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1223 IDispatch* iface)
1225 ICOM_THIS_From_IDispatch(IPicture, iface);
1227 return IPicture_AddRef(This);
1230 /************************************************************************
1231 * OLEPictureImpl_IDispatch_Release (IUnknown)
1233 * See Windows documentation for more details on IUnknown methods.
1235 static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1236 IDispatch* iface)
1238 ICOM_THIS_From_IDispatch(IPicture, iface);
1240 return IPicture_Release(This);
1243 /************************************************************************
1244 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1246 * See Windows documentation for more details on IDispatch methods.
1248 static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1249 IDispatch* iface,
1250 unsigned int* pctinfo)
1252 FIXME("():Stub\n");
1254 return E_NOTIMPL;
1257 /************************************************************************
1258 * OLEPictureImpl_GetTypeInfo (IDispatch)
1260 * See Windows documentation for more details on IDispatch methods.
1262 static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1263 IDispatch* iface,
1264 UINT iTInfo,
1265 LCID lcid,
1266 ITypeInfo** ppTInfo)
1268 FIXME("():Stub\n");
1270 return E_NOTIMPL;
1273 /************************************************************************
1274 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1276 * See Windows documentation for more details on IDispatch methods.
1278 static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1279 IDispatch* iface,
1280 REFIID riid,
1281 LPOLESTR* rgszNames,
1282 UINT cNames,
1283 LCID lcid,
1284 DISPID* rgDispId)
1286 FIXME("():Stub\n");
1288 return E_NOTIMPL;
1291 /************************************************************************
1292 * OLEPictureImpl_Invoke (IDispatch)
1294 * See Windows documentation for more details on IDispatch methods.
1296 static HRESULT WINAPI OLEPictureImpl_Invoke(
1297 IDispatch* iface,
1298 DISPID dispIdMember,
1299 REFIID riid,
1300 LCID lcid,
1301 WORD wFlags,
1302 DISPPARAMS* pDispParams,
1303 VARIANT* pVarResult,
1304 EXCEPINFO* pExepInfo,
1305 UINT* puArgErr)
1307 FIXME("(dispid: %ld):Stub\n",dispIdMember);
1309 VariantInit(pVarResult);
1310 V_VT(pVarResult) = VT_BOOL;
1311 V_UNION(pVarResult,boolVal) = FALSE;
1312 return S_OK;
1316 static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable =
1318 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1319 OLEPictureImpl_QueryInterface,
1320 OLEPictureImpl_AddRef,
1321 OLEPictureImpl_Release,
1322 OLEPictureImpl_get_Handle,
1323 OLEPictureImpl_get_hPal,
1324 OLEPictureImpl_get_Type,
1325 OLEPictureImpl_get_Width,
1326 OLEPictureImpl_get_Height,
1327 OLEPictureImpl_Render,
1328 OLEPictureImpl_set_hPal,
1329 OLEPictureImpl_get_CurDC,
1330 OLEPictureImpl_SelectPicture,
1331 OLEPictureImpl_get_KeepOriginalFormat,
1332 OLEPictureImpl_put_KeepOriginalFormat,
1333 OLEPictureImpl_PictureChanged,
1334 OLEPictureImpl_SaveAsFile,
1335 OLEPictureImpl_get_Attributes
1338 static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable =
1340 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1341 OLEPictureImpl_IDispatch_QueryInterface,
1342 OLEPictureImpl_IDispatch_AddRef,
1343 OLEPictureImpl_IDispatch_Release,
1344 OLEPictureImpl_GetTypeInfoCount,
1345 OLEPictureImpl_GetTypeInfo,
1346 OLEPictureImpl_GetIDsOfNames,
1347 OLEPictureImpl_Invoke
1350 static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable =
1352 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1353 OLEPictureImpl_IPersistStream_QueryInterface,
1354 OLEPictureImpl_IPersistStream_AddRef,
1355 OLEPictureImpl_IPersistStream_Release,
1356 OLEPictureImpl_GetClassID,
1357 OLEPictureImpl_IsDirty,
1358 OLEPictureImpl_Load,
1359 OLEPictureImpl_Save,
1360 OLEPictureImpl_GetSizeMax
1363 static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable =
1365 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1366 OLEPictureImpl_IConnectionPointContainer_QueryInterface,
1367 OLEPictureImpl_IConnectionPointContainer_AddRef,
1368 OLEPictureImpl_IConnectionPointContainer_Release,
1369 OLEPictureImpl_EnumConnectionPoints,
1370 OLEPictureImpl_FindConnectionPoint
1373 /***********************************************************************
1374 * OleCreatePictureIndirect (OLEAUT32.419)
1376 HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
1377 BOOL fOwn, LPVOID *ppvObj )
1379 OLEPictureImpl* newPict = NULL;
1380 HRESULT hr = S_OK;
1382 TRACE("(%p,%p,%d,%p)\n", lpPictDesc, riid, fOwn, ppvObj);
1385 * Sanity check
1387 if (ppvObj==0)
1388 return E_POINTER;
1390 *ppvObj = NULL;
1393 * Try to construct a new instance of the class.
1395 newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
1397 if (newPict == NULL)
1398 return E_OUTOFMEMORY;
1401 * Make sure it supports the interface required by the caller.
1403 hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
1406 * Release the reference obtained in the constructor. If
1407 * the QueryInterface was unsuccessful, it will free the class.
1409 IPicture_Release((IPicture*)newPict);
1411 return hr;
1415 /***********************************************************************
1416 * OleLoadPicture (OLEAUT32.418)
1418 HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1419 REFIID riid, LPVOID *ppvObj )
1421 LPPERSISTSTREAM ps;
1422 IPicture *newpic;
1423 HRESULT hr;
1425 TRACE("(%p,%ld,%d,%s,%p), partially implemented.\n",
1426 lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
1428 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1429 if (hr)
1430 return hr;
1431 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1432 if (hr) {
1433 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1434 IPicture_Release(newpic);
1435 *ppvObj = NULL;
1436 return hr;
1438 IPersistStream_Load(ps,lpstream);
1439 IPersistStream_Release(ps);
1440 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1441 if (hr)
1442 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1443 IPicture_Release(newpic);
1444 return hr;
1447 /***********************************************************************
1448 * OleLoadPictureEx (OLEAUT32.401)
1450 HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1451 REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
1453 LPPERSISTSTREAM ps;
1454 IPicture *newpic;
1455 HRESULT hr;
1457 FIXME("(%p,%ld,%d,%s,x=%ld,y=%ld,f=%lx,%p), partially implemented.\n",
1458 lpstream, lSize, fRunmode, debugstr_guid(riid), xsiz, ysiz, flags, ppvObj);
1460 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1461 if (hr)
1462 return hr;
1463 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1464 if (hr) {
1465 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1466 IPicture_Release(newpic);
1467 *ppvObj = NULL;
1468 return hr;
1470 IPersistStream_Load(ps,lpstream);
1471 IPersistStream_Release(ps);
1472 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1473 if (hr)
1474 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1475 IPicture_Release(newpic);
1476 return hr;
1479 /*******************************************************************************
1480 * StdPic ClassFactory
1482 typedef struct
1484 /* IUnknown fields */
1485 ICOM_VFIELD(IClassFactory);
1486 DWORD ref;
1487 } IClassFactoryImpl;
1489 static HRESULT WINAPI
1490 SPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1491 ICOM_THIS(IClassFactoryImpl,iface);
1493 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1494 return E_NOINTERFACE;
1497 static ULONG WINAPI
1498 SPCF_AddRef(LPCLASSFACTORY iface) {
1499 ICOM_THIS(IClassFactoryImpl,iface);
1500 return ++(This->ref);
1503 static ULONG WINAPI SPCF_Release(LPCLASSFACTORY iface) {
1504 ICOM_THIS(IClassFactoryImpl,iface);
1505 /* static class, won't be freed */
1506 return --(This->ref);
1509 static HRESULT WINAPI SPCF_CreateInstance(
1510 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1512 PICTDESC pd;
1514 FIXME("(%p,%p,%s,%p), creating stdpic with PICTYPE_NONE.\n",iface,pOuter,debugstr_guid(riid),ppobj);
1515 pd.cbSizeofstruct = sizeof(pd);
1516 pd.picType = PICTYPE_NONE;
1517 return OleCreatePictureIndirect(&pd,riid,TRUE,ppobj);
1521 static HRESULT WINAPI SPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1522 ICOM_THIS(IClassFactoryImpl,iface);
1523 FIXME("(%p)->(%d),stub!\n",This,dolock);
1524 return S_OK;
1527 static ICOM_VTABLE(IClassFactory) SPCF_Vtbl = {
1528 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1529 SPCF_QueryInterface,
1530 SPCF_AddRef,
1531 SPCF_Release,
1532 SPCF_CreateInstance,
1533 SPCF_LockServer
1535 static IClassFactoryImpl STDPIC_CF = {&SPCF_Vtbl, 1 };
1537 void _get_STDPIC_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDPIC_CF; }