- Move shldisp.h to the right place.
[reactos.git] / reactos / lib / oleaut32 / olepicture.c
1 /*
2 * OLE Picture object
3 *
4 * Implementation of OLE IPicture and related interfaces
5 *
6 * Copyright 2000 Huw D M Davies for CodeWeavers.
7 * Copyright 2001 Marcus Meissner
8 *
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.
13 *
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.
18 *
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
22 *
23 * BUGS
24 *
25 * Support PICTYPE_BITMAP and PICTYPE_ICON, altough only bitmaps very well..
26 * Lots of methods are just stubs.
27 *
28 *
29 * NOTES (or things that msdn doesn't tell you)
30 *
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).
35 *
36 */
37
38 #include "config.h"
39
40 #ifdef HAVE_UNISTD_H
41 # include <unistd.h>
42 #endif
43 #include <stdarg.h>
44 #include <stdio.h>
45 #include <string.h>
46
47 /* Must be before wine includes, the header has things conflicting with
48 * WINE headers.
49 */
50 #ifdef HAVE_GIF_LIB_H
51 # include <gif_lib.h>
52 #endif
53
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"
66
67 #include "wine/wingdi16.h"
68 #include "cursoricon.h"
69
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
81
82 WINE_DEFAULT_DEBUG_CHANNEL(ole);
83
84 /*************************************************************************
85 * Declaration of implementation class
86 */
87
88 typedef struct OLEPictureImpl {
89
90 /*
91 * IPicture handles IUnknown
92 */
93
94 IPictureVtbl *lpvtbl1;
95 IDispatchVtbl *lpvtbl2;
96 IPersistStreamVtbl *lpvtbl3;
97 IConnectionPointContainerVtbl *lpvtbl4;
98
99 /* Object referenece count */
100 DWORD ref;
101
102 /* We own the object and must destroy it ourselves */
103 BOOL fOwn;
104
105 /* Picture description */
106 PICTDESC desc;
107
108 /* These are the pixel size of a bitmap */
109 DWORD origWidth;
110 DWORD origHeight;
111
112 /* And these are the size of the picture converted into HIMETRIC units */
113 OLE_XSIZE_HIMETRIC himetricWidth;
114 OLE_YSIZE_HIMETRIC himetricHeight;
115
116 IConnectionPoint *pCP;
117
118 BOOL keepOrigFormat;
119 HDC hDCCur;
120
121 /* data */
122 void* data;
123 int datalen;
124 } OLEPictureImpl;
125
126 /*
127 * Macros to retrieve pointer to IUnknown (IPicture) from the other VTables.
128 */
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*));
135
136 /*
137 * Predeclare VTables. They get initialized at the end.
138 */
139 static IPictureVtbl OLEPictureImpl_VTable;
140 static IDispatchVtbl OLEPictureImpl_IDispatch_VTable;
141 static IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable;
142 static IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable;
143
144 /***********************************************************************
145 * Implementation of the OLEPictureImpl class.
146 */
147
148 static void OLEPictureImpl_SetBitmap(OLEPictureImpl*This) {
149 BITMAP bm;
150 HDC hdcRef;
151
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;
156 }
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);
167 }
168
169 /************************************************************************
170 * OLEPictureImpl_Construct
171 *
172 * This method will construct a new instance of the OLEPictureImpl
173 * class.
174 *
175 * The caller of this method must release the object when it's
176 * done with it.
177 */
178 static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
179 {
180 OLEPictureImpl* newObject = 0;
181
182 if (pictDesc)
183 TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
184
185 /*
186 * Allocate space for the object.
187 */
188 newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
189
190 if (newObject==0)
191 return newObject;
192
193 /*
194 * Initialize the virtual function table.
195 */
196 newObject->lpvtbl1 = &OLEPictureImpl_VTable;
197 newObject->lpvtbl2 = &OLEPictureImpl_IDispatch_VTable;
198 newObject->lpvtbl3 = &OLEPictureImpl_IPersistStream_VTable;
199 newObject->lpvtbl4 = &OLEPictureImpl_IConnectionPointContainer_VTable;
200
201 CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
202
203 /*
204 * Start with one reference count. The caller of this function
205 * must release the interface pointer when it is done.
206 */
207 newObject->ref = 1;
208 newObject->hDCCur = 0;
209
210 newObject->fOwn = fOwn;
211
212 /* dunno about original value */
213 newObject->keepOrigFormat = TRUE;
214
215 if (pictDesc) {
216 if(pictDesc->cbSizeofstruct != sizeof(PICTDESC)) {
217 FIXME("struct size = %d\n", pictDesc->cbSizeofstruct);
218 }
219 memcpy(&newObject->desc, pictDesc, sizeof(PICTDESC));
220
221
222 switch(pictDesc->picType) {
223 case PICTYPE_BITMAP:
224 OLEPictureImpl_SetBitmap(newObject);
225 break;
226
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;
232
233 case PICTYPE_NONE:
234 /* not sure what to do here */
235 newObject->himetricWidth = newObject->himetricHeight = 0;
236 break;
237
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;
244 }
245 } else {
246 newObject->desc.picType = PICTYPE_UNINITIALIZED;
247 }
248
249 TRACE("returning %p\n", newObject);
250 return newObject;
251 }
252
253 /************************************************************************
254 * OLEPictureImpl_Destroy
255 *
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)
260 {
261 TRACE("(%p)\n", Obj);
262
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;
280 }
281 }
282 if (Obj->data) HeapFree(GetProcessHeap(), 0, Obj->data);
283 HeapFree(GetProcessHeap(), 0, Obj);
284 }
285
286 static ULONG WINAPI OLEPictureImpl_AddRef(IPicture* iface);
287
288 /************************************************************************
289 * OLEPictureImpl_QueryInterface (IUnknown)
290 *
291 * See Windows documentation for more details on IUnknown methods.
292 */
293 static HRESULT WINAPI OLEPictureImpl_QueryInterface(
294 IPicture* iface,
295 REFIID riid,
296 void** ppvObject)
297 {
298 OLEPictureImpl *This = (OLEPictureImpl *)iface;
299 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
300
301 /*
302 * Perform a sanity check on the parameters.
303 */
304 if ( (This==0) || (ppvObject==0) )
305 return E_INVALIDARG;
306
307 /*
308 * Initialize the return parameter.
309 */
310 *ppvObject = 0;
311
312 /*
313 * Compare the riid with the interface IDs implemented by this object.
314 */
315 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
316 {
317 *ppvObject = (IPicture*)This;
318 }
319 else if (memcmp(&IID_IPicture, riid, sizeof(IID_IPicture)) == 0)
320 {
321 *ppvObject = (IPicture*)This;
322 }
323 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
324 {
325 *ppvObject = (IDispatch*)&(This->lpvtbl2);
326 }
327 else if (memcmp(&IID_IPictureDisp, riid, sizeof(IID_IPictureDisp)) == 0)
328 {
329 *ppvObject = (IDispatch*)&(This->lpvtbl2);
330 }
331 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
332 {
333 *ppvObject = (IPersistStream*)&(This->lpvtbl3);
334 }
335 else if (memcmp(&IID_IConnectionPointContainer, riid, sizeof(IID_IConnectionPointContainer)) == 0)
336 {
337 *ppvObject = (IConnectionPointContainer*)&(This->lpvtbl4);
338 }
339 /*
340 * Check that we obtained an interface.
341 */
342 if ((*ppvObject)==0)
343 {
344 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
345 return E_NOINTERFACE;
346 }
347
348 /*
349 * Query Interface always increases the reference count by one when it is
350 * successful
351 */
352 OLEPictureImpl_AddRef((IPicture*)This);
353
354 return S_OK;
355 }
356 /***********************************************************************
357 * OLEPicture_SendNotify (internal)
358 *
359 * Sends notification messages of changed properties to any interested
360 * connections.
361 */
362 static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
363 {
364 IEnumConnections *pEnum;
365 CONNECTDATA CD;
366
367 if (IConnectionPoint_EnumConnections(this->pCP, &pEnum))
368 return;
369 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
370 IPropertyNotifySink *sink;
371
372 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
373 IPropertyNotifySink_OnChanged(sink, dispID);
374 IPropertyNotifySink_Release(sink);
375 IUnknown_Release(CD.pUnk);
376 }
377 IEnumConnections_Release(pEnum);
378 return;
379 }
380
381 /************************************************************************
382 * OLEPictureImpl_AddRef (IUnknown)
383 *
384 * See Windows documentation for more details on IUnknown methods.
385 */
386 static ULONG WINAPI OLEPictureImpl_AddRef(
387 IPicture* iface)
388 {
389 OLEPictureImpl *This = (OLEPictureImpl *)iface;
390 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
391 This->ref++;
392
393 return This->ref;
394 }
395
396 /************************************************************************
397 * OLEPictureImpl_Release (IUnknown)
398 *
399 * See Windows documentation for more details on IUnknown methods.
400 */
401 static ULONG WINAPI OLEPictureImpl_Release(
402 IPicture* iface)
403 {
404 OLEPictureImpl *This = (OLEPictureImpl *)iface;
405 TRACE("(%p)->(ref=%ld)\n", This, This->ref);
406
407 /*
408 * Decrease the reference count on this object.
409 */
410 This->ref--;
411
412 /*
413 * If the reference count goes down to 0, perform suicide.
414 */
415 if (This->ref==0)
416 {
417 OLEPictureImpl_Destroy(This);
418
419 return 0;
420 }
421
422 return This->ref;
423 }
424
425
426 /************************************************************************
427 * OLEPictureImpl_get_Handle
428 */
429 static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
430 OLE_HANDLE *phandle)
431 {
432 OLEPictureImpl *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;
450 }
451 TRACE("returning handle %08x\n", *phandle);
452 return S_OK;
453 }
454
455 /************************************************************************
456 * OLEPictureImpl_get_hPal
457 */
458 static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
459 OLE_HANDLE *phandle)
460 {
461 OLEPictureImpl *This = (OLEPictureImpl *)iface;
462 FIXME("(%p)->(%p): stub\n", This, phandle);
463 return E_NOTIMPL;
464 }
465
466 /************************************************************************
467 * OLEPictureImpl_get_Type
468 */
469 static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
470 short *ptype)
471 {
472 OLEPictureImpl *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;
476 }
477
478 /************************************************************************
479 * OLEPictureImpl_get_Width
480 */
481 static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
482 OLE_XSIZE_HIMETRIC *pwidth)
483 {
484 OLEPictureImpl *This = (OLEPictureImpl *)iface;
485 TRACE("(%p)->(%p): width is %ld\n", This, pwidth, This->himetricWidth);
486 *pwidth = This->himetricWidth;
487 return S_OK;
488 }
489
490 /************************************************************************
491 * OLEPictureImpl_get_Height
492 */
493 static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
494 OLE_YSIZE_HIMETRIC *pheight)
495 {
496 OLEPictureImpl *This = (OLEPictureImpl *)iface;
497 TRACE("(%p)->(%p): height is %ld\n", This, pheight, This->himetricHeight);
498 *pheight = This->himetricHeight;
499 return S_OK;
500 }
501
502 /************************************************************************
503 * OLEPictureImpl_Render
504 */
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)
512 {
513 OLEPictureImpl *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);
519
520 /*
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);
524 */
525
526 switch(This->desc.picType) {
527 case PICTYPE_BITMAP:
528 {
529 HBITMAP hbmpOld;
530 HDC hdcBmp;
531
532 /* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
533 NB y-axis gets flipped */
534
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);
541
542 hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
543
544 StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
545
546 SelectObject(hdcBmp, hbmpOld);
547 DeleteDC(hdcBmp);
548 }
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;
554
555 case PICTYPE_METAFILE:
556 case PICTYPE_ENHMETAFILE:
557 default:
558 FIXME("type %d not implemented\n", This->desc.picType);
559 return E_NOTIMPL;
560 }
561 return S_OK;
562 }
563
564 /************************************************************************
565 * OLEPictureImpl_set_hPal
566 */
567 static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
568 OLE_HANDLE hpal)
569 {
570 OLEPictureImpl *This = (OLEPictureImpl *)iface;
571 FIXME("(%p)->(%08x): stub\n", This, hpal);
572 OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
573 return E_NOTIMPL;
574 }
575
576 /************************************************************************
577 * OLEPictureImpl_get_CurDC
578 */
579 static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
580 HDC *phdc)
581 {
582 OLEPictureImpl *This = (OLEPictureImpl *)iface;
583 TRACE("(%p), returning %p\n", This, This->hDCCur);
584 if (phdc) *phdc = This->hDCCur;
585 return S_OK;
586 }
587
588 /************************************************************************
589 * OLEPictureImpl_SelectPicture
590 */
591 static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
592 HDC hdcIn,
593 HDC *phdcOut,
594 OLE_HANDLE *phbmpOut)
595 {
596 OLEPictureImpl *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);
600
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;
610 }
611 }
612
613 /************************************************************************
614 * OLEPictureImpl_get_KeepOriginalFormat
615 */
616 static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
617 BOOL *pfKeep)
618 {
619 OLEPictureImpl *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;
625 }
626
627 /************************************************************************
628 * OLEPictureImpl_put_KeepOriginalFormat
629 */
630 static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
631 BOOL keep)
632 {
633 OLEPictureImpl *This = (OLEPictureImpl *)iface;
634 TRACE("(%p)->(%d)\n", This, keep);
635 This->keepOrigFormat = keep;
636 /* FIXME: what DISPID notification here? */
637 return S_OK;
638 }
639
640 /************************************************************************
641 * OLEPictureImpl_PictureChanged
642 */
643 static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
644 {
645 OLEPictureImpl *This = (OLEPictureImpl *)iface;
646 TRACE("(%p)->()\n", This);
647 OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
648 return S_OK;
649 }
650
651 /************************************************************************
652 * OLEPictureImpl_SaveAsFile
653 */
654 static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
655 IStream *pstream,
656 BOOL SaveMemCopy,
657 LONG *pcbSize)
658 {
659 OLEPictureImpl *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);
662 }
663
664 /************************************************************************
665 * OLEPictureImpl_get_Attributes
666 */
667 static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
668 DWORD *pdwAttr)
669 {
670 OLEPictureImpl *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;
678 }
679 return S_OK;
680 }
681
682
683 /************************************************************************
684 * IConnectionPointContainer
685 */
686
687 static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
688 IConnectionPointContainer* iface,
689 REFIID riid,
690 VOID** ppvoid
691 ) {
692 ICOM_THIS_From_IConnectionPointContainer(IPicture,iface);
693
694 return IPicture_QueryInterface(This,riid,ppvoid);
695 }
696
697 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
698 IConnectionPointContainer* iface)
699 {
700 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
701
702 return IPicture_AddRef(This);
703 }
704
705 static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
706 IConnectionPointContainer* iface)
707 {
708 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
709
710 return IPicture_Release(This);
711 }
712
713 static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
714 IConnectionPointContainer* iface,
715 IEnumConnectionPoints** ppEnum
716 ) {
717 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
718
719 FIXME("(%p,%p), stub!\n",This,ppEnum);
720 return E_NOTIMPL;
721 }
722
723 static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
724 IConnectionPointContainer* iface,
725 REFIID riid,
726 IConnectionPoint **ppCP
727 ) {
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;
737 }
738 /************************************************************************
739 * IPersistStream
740 */
741 /************************************************************************
742 * OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
743 *
744 * See Windows documentation for more details on IUnknown methods.
745 */
746 static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
747 IPersistStream* iface,
748 REFIID riid,
749 VOID** ppvoid)
750 {
751 ICOM_THIS_From_IPersistStream(IPicture, iface);
752
753 return IPicture_QueryInterface(This, riid, ppvoid);
754 }
755
756 /************************************************************************
757 * OLEPictureImpl_IPersistStream_AddRef (IUnknown)
758 *
759 * See Windows documentation for more details on IUnknown methods.
760 */
761 static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
762 IPersistStream* iface)
763 {
764 ICOM_THIS_From_IPersistStream(IPicture, iface);
765
766 return IPicture_AddRef(This);
767 }
768
769 /************************************************************************
770 * OLEPictureImpl_IPersistStream_Release (IUnknown)
771 *
772 * See Windows documentation for more details on IUnknown methods.
773 */
774 static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
775 IPersistStream* iface)
776 {
777 ICOM_THIS_From_IPersistStream(IPicture, iface);
778
779 return IPicture_Release(This);
780 }
781
782 /************************************************************************
783 * OLEPictureImpl_IPersistStream_GetClassID
784 */
785 static HRESULT WINAPI OLEPictureImpl_GetClassID(
786 IPersistStream* iface,CLSID* pClassID)
787 {
788 ICOM_THIS_From_IPersistStream(IPicture, iface);
789 FIXME("(%p),stub!\n",This);
790 return E_NOTIMPL;
791 }
792
793 /************************************************************************
794 * OLEPictureImpl_IPersistStream_IsDirty
795 */
796 static HRESULT WINAPI OLEPictureImpl_IsDirty(
797 IPersistStream* iface)
798 {
799 ICOM_THIS_From_IPersistStream(IPicture, iface);
800 FIXME("(%p),stub!\n",This);
801 return E_NOTIMPL;
802 }
803
804 #ifdef HAVE_LIBJPEG
805 /* for the jpeg decompressor source manager. */
806 static void _jpeg_init_source(j_decompress_ptr cinfo) { }
807
808 static boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
809 ERR("(), should not get here.\n");
810 return FALSE;
811 }
812
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;
817 }
818
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;
822 }
823 static void _jpeg_term_source(j_decompress_ptr cinfo) { }
824 #endif /* HAVE_LIBJPEG */
825
826 #ifdef HAVE_LIBGIF
827 struct gifdata {
828 unsigned char *data;
829 unsigned int curoff;
830 unsigned int len;
831 };
832
833 static int _gif_inputfunc(GifFileType *gif, GifByteType *data, int len) {
834 struct gifdata *gd = (struct gifdata*)gif->UserData;
835
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;
839 }
840 memcpy(data, gd->data+gd->curoff, len);
841 gd->curoff += len;
842 return len;
843 }
844 #endif
845
846 /************************************************************************
847 * OLEPictureImpl_IPersistStream_Load (IUnknown)
848 *
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;
853 *
854 * Currently implemented: BITMAP, ICON, JPEG.
855 */
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);
864
865 TRACE("(%p,%p)\n",This,pStm);
866
867 /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
868 * out whether we do.
869 */
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;
877 }
878 if (header[1] > statstg.cbSize.QuadPart || (header[1]==0)) {/* 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;
889 }
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;
902 }
903 if (xread != header[1])
904 FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
905 }
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;
919
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;
928 }
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;
935 }
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
940 );
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;
952 }
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;
968
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
977 );
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;
989 }
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;
1003
1004 /* This is basically so we can use in-memory data for jpeg decompression.
1005 * We need to have all the functions.
1006 */
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;
1014
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;
1025 }
1026
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);
1030
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;
1038 }
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);
1044 }
1045 bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
1046 samprow = oldsamprow;
1047 }
1048 bits = oldbits;
1049
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;
1061
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
1073 );
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;
1084 }
1085 case 0x4d42: { /* Bitmap */
1086 BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
1087 BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
1088 HDC hdcref;
1089
1090 /* Does not matter whether this is a coreheader or not, we only use
1091 * components which are in both
1092 */
1093 hdcref = GetDC(0);
1094 This->desc.u.bmp.hbitmap = CreateDIBitmap(
1095 hdcref,
1096 &(bi->bmiHeader),
1097 CBM_INIT,
1098 xbuf+bfh->bfOffBits,
1099 bi,
1100 (bi->bmiHeader.biBitCount<=8)?DIB_PAL_COLORS:DIB_RGB_COLORS
1101 );
1102 DeleteDC(hdcref);
1103 This->desc.picType = PICTYPE_BITMAP;
1104 OLEPictureImpl_SetBitmap(This);
1105 hr = S_OK;
1106 break;
1107 }
1108 case 0x0000: { /* ICON , first word is dwReserved */
1109 HICON hicon;
1110 CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
1111 int i;
1112
1113 /*
1114 FIXME("icon.idReserved=%d\n",cifd->idReserved);
1115 FIXME("icon.idType=%d\n",cifd->idType);
1116 FIXME("icon.idCount=%d\n",cifd->idCount);
1117
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);
1127 }
1128 */
1129 i=0;
1130 /* If we have more than one icon, try to find the best.
1131 * this currently means '32 pixel wide'.
1132 */
1133 if (cifd->idCount!=1) {
1134 for (i=0;i<cifd->idCount;i++) {
1135 if (cifd->idEntries[i].bWidth == 32)
1136 break;
1137 }
1138 if (i==cifd->idCount) i=0;
1139 }
1140
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,
1148 0
1149 );
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;
1159 }
1160 break;
1161 }
1162 default:
1163 {
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");
1171 }
1172 MESSAGE("\n");
1173 break;
1174 }
1175 }
1176
1177 /* FIXME: this notify is not really documented */
1178 if (hr==S_OK)
1179 OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1180 return hr;
1181 }
1182
1183 static HRESULT WINAPI OLEPictureImpl_Save(
1184 IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1185 {
1186 ICOM_THIS_From_IPersistStream(IPicture, iface);
1187 FIXME("(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
1188 return E_NOTIMPL;
1189 }
1190
1191 static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1192 IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1193 {
1194 ICOM_THIS_From_IPersistStream(IPicture, iface);
1195 FIXME("(%p,%p),stub!\n",This,pcbSize);
1196 return E_NOTIMPL;
1197 }
1198
1199 /************************************************************************
1200 * IDispatch
1201 */
1202 /************************************************************************
1203 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1204 *
1205 * See Windows documentation for more details on IUnknown methods.
1206 */
1207 static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1208 IDispatch* iface,
1209 REFIID riid,
1210 VOID** ppvoid)
1211 {
1212 ICOM_THIS_From_IDispatch(IPicture, iface);
1213
1214 return IPicture_QueryInterface(This, riid, ppvoid);
1215 }
1216
1217 /************************************************************************
1218 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1219 *
1220 * See Windows documentation for more details on IUnknown methods.
1221 */
1222 static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1223 IDispatch* iface)
1224 {
1225 ICOM_THIS_From_IDispatch(IPicture, iface);
1226
1227 return IPicture_AddRef(This);
1228 }
1229
1230 /************************************************************************
1231 * OLEPictureImpl_IDispatch_Release (IUnknown)
1232 *
1233 * See Windows documentation for more details on IUnknown methods.
1234 */
1235 static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1236 IDispatch* iface)
1237 {
1238 ICOM_THIS_From_IDispatch(IPicture, iface);
1239
1240 return IPicture_Release(This);
1241 }
1242
1243 /************************************************************************
1244 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1245 *
1246 * See Windows documentation for more details on IDispatch methods.
1247 */
1248 static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1249 IDispatch* iface,
1250 unsigned int* pctinfo)
1251 {
1252 FIXME("():Stub\n");
1253
1254 return E_NOTIMPL;
1255 }
1256
1257 /************************************************************************
1258 * OLEPictureImpl_GetTypeInfo (IDispatch)
1259 *
1260 * See Windows documentation for more details on IDispatch methods.
1261 */
1262 static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1263 IDispatch* iface,
1264 UINT iTInfo,
1265 LCID lcid,
1266 ITypeInfo** ppTInfo)
1267 {
1268 FIXME("():Stub\n");
1269
1270 return E_NOTIMPL;
1271 }
1272
1273 /************************************************************************
1274 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1275 *
1276 * See Windows documentation for more details on IDispatch methods.
1277 */
1278 static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1279 IDispatch* iface,
1280 REFIID riid,
1281 LPOLESTR* rgszNames,
1282 UINT cNames,
1283 LCID lcid,
1284 DISPID* rgDispId)
1285 {
1286 FIXME("():Stub\n");
1287
1288 return E_NOTIMPL;
1289 }
1290
1291 /************************************************************************
1292 * OLEPictureImpl_Invoke (IDispatch)
1293 *
1294 * See Windows documentation for more details on IDispatch methods.
1295 */
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)
1306 {
1307 FIXME("(dispid: %ld):Stub\n",dispIdMember);
1308
1309 VariantInit(pVarResult);
1310 V_VT(pVarResult) = VT_BOOL;
1311 V_UNION(pVarResult,boolVal) = FALSE;
1312 return S_OK;
1313 }
1314
1315
1316 static IPictureVtbl OLEPictureImpl_VTable =
1317 {
1318 OLEPictureImpl_QueryInterface,
1319 OLEPictureImpl_AddRef,
1320 OLEPictureImpl_Release,
1321 OLEPictureImpl_get_Handle,
1322 OLEPictureImpl_get_hPal,
1323 OLEPictureImpl_get_Type,
1324 OLEPictureImpl_get_Width,
1325 OLEPictureImpl_get_Height,
1326 OLEPictureImpl_Render,
1327 OLEPictureImpl_set_hPal,
1328 OLEPictureImpl_get_CurDC,
1329 OLEPictureImpl_SelectPicture,
1330 OLEPictureImpl_get_KeepOriginalFormat,
1331 OLEPictureImpl_put_KeepOriginalFormat,
1332 OLEPictureImpl_PictureChanged,
1333 OLEPictureImpl_SaveAsFile,
1334 OLEPictureImpl_get_Attributes
1335 };
1336
1337 static IDispatchVtbl OLEPictureImpl_IDispatch_VTable =
1338 {
1339 OLEPictureImpl_IDispatch_QueryInterface,
1340 OLEPictureImpl_IDispatch_AddRef,
1341 OLEPictureImpl_IDispatch_Release,
1342 OLEPictureImpl_GetTypeInfoCount,
1343 OLEPictureImpl_GetTypeInfo,
1344 OLEPictureImpl_GetIDsOfNames,
1345 OLEPictureImpl_Invoke
1346 };
1347
1348 static IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable =
1349 {
1350 OLEPictureImpl_IPersistStream_QueryInterface,
1351 OLEPictureImpl_IPersistStream_AddRef,
1352 OLEPictureImpl_IPersistStream_Release,
1353 OLEPictureImpl_GetClassID,
1354 OLEPictureImpl_IsDirty,
1355 OLEPictureImpl_Load,
1356 OLEPictureImpl_Save,
1357 OLEPictureImpl_GetSizeMax
1358 };
1359
1360 static IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable =
1361 {
1362 OLEPictureImpl_IConnectionPointContainer_QueryInterface,
1363 OLEPictureImpl_IConnectionPointContainer_AddRef,
1364 OLEPictureImpl_IConnectionPointContainer_Release,
1365 OLEPictureImpl_EnumConnectionPoints,
1366 OLEPictureImpl_FindConnectionPoint
1367 };
1368
1369 /***********************************************************************
1370 * OleCreatePictureIndirect (OLEAUT32.419)
1371 */
1372 HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
1373 BOOL fOwn, LPVOID *ppvObj )
1374 {
1375 OLEPictureImpl* newPict = NULL;
1376 HRESULT hr = S_OK;
1377
1378 TRACE("(%p,%p,%d,%p)\n", lpPictDesc, riid, fOwn, ppvObj);
1379
1380 /*
1381 * Sanity check
1382 */
1383 if (ppvObj==0)
1384 return E_POINTER;
1385
1386 *ppvObj = NULL;
1387
1388 /*
1389 * Try to construct a new instance of the class.
1390 */
1391 newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
1392
1393 if (newPict == NULL)
1394 return E_OUTOFMEMORY;
1395
1396 /*
1397 * Make sure it supports the interface required by the caller.
1398 */
1399 hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
1400
1401 /*
1402 * Release the reference obtained in the constructor. If
1403 * the QueryInterface was unsuccessful, it will free the class.
1404 */
1405 IPicture_Release((IPicture*)newPict);
1406
1407 return hr;
1408 }
1409
1410
1411 /***********************************************************************
1412 * OleLoadPicture (OLEAUT32.418)
1413 */
1414 HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1415 REFIID riid, LPVOID *ppvObj )
1416 {
1417 LPPERSISTSTREAM ps;
1418 IPicture *newpic;
1419 HRESULT hr;
1420
1421 TRACE("(%p,%ld,%d,%s,%p), partially implemented.\n",
1422 lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
1423
1424 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1425 if (hr)
1426 return hr;
1427 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1428 if (hr) {
1429 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1430 IPicture_Release(newpic);
1431 *ppvObj = NULL;
1432 return hr;
1433 }
1434 IPersistStream_Load(ps,lpstream);
1435 IPersistStream_Release(ps);
1436 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1437 if (hr)
1438 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1439 IPicture_Release(newpic);
1440 return hr;
1441 }
1442
1443 /***********************************************************************
1444 * OleLoadPictureEx (OLEAUT32.401)
1445 */
1446 HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1447 REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
1448 {
1449 LPPERSISTSTREAM ps;
1450 IPicture *newpic;
1451 HRESULT hr;
1452
1453 FIXME("(%p,%ld,%d,%s,x=%ld,y=%ld,f=%lx,%p), partially implemented.\n",
1454 lpstream, lSize, fRunmode, debugstr_guid(riid), xsiz, ysiz, flags, ppvObj);
1455
1456 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1457 if (hr)
1458 return hr;
1459 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1460 if (hr) {
1461 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1462 IPicture_Release(newpic);
1463 *ppvObj = NULL;
1464 return hr;
1465 }
1466 IPersistStream_Load(ps,lpstream);
1467 IPersistStream_Release(ps);
1468 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1469 if (hr)
1470 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1471 IPicture_Release(newpic);
1472 return hr;
1473 }
1474
1475 /*******************************************************************************
1476 * StdPic ClassFactory
1477 */
1478 typedef struct
1479 {
1480 /* IUnknown fields */
1481 IClassFactoryVtbl *lpVtbl;
1482 DWORD ref;
1483 } IClassFactoryImpl;
1484
1485 static HRESULT WINAPI
1486 SPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1487 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1488
1489 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1490 return E_NOINTERFACE;
1491 }
1492
1493 static ULONG WINAPI
1494 SPCF_AddRef(LPCLASSFACTORY iface) {
1495 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1496 return ++(This->ref);
1497 }
1498
1499 static ULONG WINAPI SPCF_Release(LPCLASSFACTORY iface) {
1500 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1501 /* static class, won't be freed */
1502 return --(This->ref);
1503 }
1504
1505 static HRESULT WINAPI SPCF_CreateInstance(
1506 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1507 ) {
1508 PICTDESC pd;
1509
1510 FIXME("(%p,%p,%s,%p), creating stdpic with PICTYPE_NONE.\n",iface,pOuter,debugstr_guid(riid),ppobj);
1511 pd.cbSizeofstruct = sizeof(pd);
1512 pd.picType = PICTYPE_NONE;
1513 return OleCreatePictureIndirect(&pd,riid,TRUE,ppobj);
1514
1515 }
1516
1517 static HRESULT WINAPI SPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1518 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1519 FIXME("(%p)->(%d),stub!\n",This,dolock);
1520 return S_OK;
1521 }
1522
1523 static IClassFactoryVtbl SPCF_Vtbl = {
1524 SPCF_QueryInterface,
1525 SPCF_AddRef,
1526 SPCF_Release,
1527 SPCF_CreateInstance,
1528 SPCF_LockServer
1529 };
1530 static IClassFactoryImpl STDPIC_CF = {&SPCF_Vtbl, 1 };
1531
1532 void _get_STDPIC_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDPIC_CF; }