source: trunk/src/oleaut32/olepicture.c@ 10367

Last change on this file since 10367 was 10266, checked in by sandervl, 22 years ago

PF: GIF and JPEG static libs for IPicture interface implementation

File size: 43.5 KB
Line 
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
82WINE_DEFAULT_DEBUG_CHANNEL(ole);
83
84/*************************************************************************
85 * Declaration of implementation class
86 */
87
88typedef struct OLEPictureImpl {
89
90 /*
91 * IPicture handles IUnknown
92 */
93
94 ICOM_VTABLE(IPicture) *lpvtbl1;
95 ICOM_VTABLE(IDispatch) *lpvtbl2;
96 ICOM_VTABLE(IPersistStream) *lpvtbl3;
97 ICOM_VTABLE(IConnectionPointContainer) *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 */
139static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable;
140static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable;
141static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable;
142static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable;
143
144/***********************************************************************
145 * Implementation of the OLEPictureImpl class.
146 */
147
148static 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 */
178static 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. */
259static 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
286static ULONG WINAPI OLEPictureImpl_AddRef(IPicture* iface);
287
288/************************************************************************
289 * OLEPictureImpl_QueryInterface (IUnknown)
290 *
291 * See Windows documentation for more details on IUnknown methods.
292 */
293static HRESULT WINAPI OLEPictureImpl_QueryInterface(
294 IPicture* iface,
295 REFIID riid,
296 void** ppvObject)
297{
298 ICOM_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 */
362static 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 */
386static ULONG WINAPI OLEPictureImpl_AddRef(
387 IPicture* iface)
388{
389 ICOM_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 */
401static ULONG WINAPI OLEPictureImpl_Release(
402 IPicture* iface)
403{
404 ICOM_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 */
429static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
430 OLE_HANDLE *phandle)
431{
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;
450 }
451 TRACE("returning handle %08x\n", *phandle);
452 return S_OK;
453}
454
455/************************************************************************
456 * OLEPictureImpl_get_hPal
457 */
458static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
459 OLE_HANDLE *phandle)
460{
461 ICOM_THIS(OLEPictureImpl, iface);
462 FIXME("(%p)->(%p): stub\n", This, phandle);
463 return E_NOTIMPL;
464}
465
466/************************************************************************
467 * OLEPictureImpl_get_Type
468 */
469static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
470 short *ptype)
471{
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;
476}
477
478/************************************************************************
479 * OLEPictureImpl_get_Width
480 */
481static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
482 OLE_XSIZE_HIMETRIC *pwidth)
483{
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;
488}
489
490/************************************************************************
491 * OLEPictureImpl_get_Height
492 */
493static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
494 OLE_YSIZE_HIMETRIC *pheight)
495{
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;
500}
501
502/************************************************************************
503 * OLEPictureImpl_Render
504 */
505static 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 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);
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 */
567static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
568 OLE_HANDLE hpal)
569{
570 ICOM_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 */
579static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
580 HDC *phdc)
581{
582 ICOM_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 */
591static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
592 HDC hdcIn,
593 HDC *phdcOut,
594 OLE_HANDLE *phbmpOut)
595{
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);
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 */
616static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
617 BOOL *pfKeep)
618{
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;
625}
626
627/************************************************************************
628 * OLEPictureImpl_put_KeepOriginalFormat
629 */
630static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
631 BOOL keep)
632{
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;
638}
639
640/************************************************************************
641 * OLEPictureImpl_PictureChanged
642 */
643static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
644{
645 ICOM_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 */
654static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
655 IStream *pstream,
656 BOOL SaveMemCopy,
657 LONG *pcbSize)
658{
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);
662}
663
664/************************************************************************
665 * OLEPictureImpl_get_Attributes
666 */
667static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
668 DWORD *pdwAttr)
669{
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;
678 }
679 return S_OK;
680}
681
682
683/************************************************************************
684 * IConnectionPointContainer
685 */
686
687static 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
697static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
698 IConnectionPointContainer* iface)
699{
700 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
701
702 return IPicture_AddRef(This);
703}
704
705static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
706 IConnectionPointContainer* iface)
707{
708 ICOM_THIS_From_IConnectionPointContainer(IPicture, iface);
709
710 return IPicture_Release(This);
711}
712
713static 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
723static 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 */
746static 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 */
761static 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 */
774static 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 */
785static 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 */
796static 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. */
806static void _jpeg_init_source(j_decompress_ptr cinfo) { }
807
808static boolean _jpeg_fill_input_buffer(j_decompress_ptr cinfo) {
809 ERR("(), should not get here.\n");
810 return FALSE;
811}
812
813static 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
819static 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}
823static void _jpeg_term_source(j_decompress_ptr cinfo) { }
824#endif /* HAVE_LIBJPEG */
825
826#ifdef HAVE_LIBGIF
827struct gifdata {
828 unsigned char *data;
829 unsigned int curoff;
830 unsigned int len;
831};
832
833static 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 */
856static 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) {/* Incorrect header, assume none. */
879 xread = 8;
880#ifdef __WIN32OS2__
881 // PF Can't understand problem here.. Using QuadPart causes all sorts of corruptions.
882 // Anyway we use only LowPart currently.
883 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,statstg.cbSize.s.LowPart);
884#else
885 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,statstg.cbSize.QuadPart);
886#endif
887 memcpy(xbuf,&header,8);
888#ifdef __WIN32OS2__
889 This->datalen = statstg.cbSize.s.LowPart;
890#else
891 This->datalen = statstg.cbSize.QuadPart;
892#endif
893 while (xread < This->datalen) {
894 ULONG nread;
895 hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
896 xread+=nread;
897 if (hr || !nread)
898 break;
899 }
900 if (xread != This->datalen)
901 FIXME("Could only read %ld of %d bytes in no-header case?\n",xread,This->datalen);
902 } else {
903 xread = 0;
904 xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
905 This->datalen = header[1];
906 while (xread < header[1]) {
907 ULONG nread;
908 hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
909 xread+=nread;
910 if (hr || !nread)
911 break;
912 }
913 if (xread != header[1])
914 FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
915 }
916 magic = xbuf[0] + (xbuf[1]<<8);
917 switch (magic) {
918 case 0x4947: { /* GIF */
919#ifdef HAVE_LIBGIF
920 struct gifdata gd;
921 GifFileType *gif;
922 BITMAPINFO *bmi;
923 HDC hdcref;
924 LPBYTE bytes;
925 int i,j,ret;
926 GifImageDesc *gid;
927 SavedImage *si;
928 ColorMapObject *cm;
929
930 gd.data = xbuf;
931 gd.curoff = 0;
932 gd.len = xread;
933 gif = DGifOpen((void*)&gd, _gif_inputfunc);
934 ret = DGifSlurp(gif);
935 if (ret == GIF_ERROR) {
936 FIXME("Failed reading GIF using libgif.\n");
937 return E_FAIL;
938 }
939 TRACE("screen height %d, width %d\n", gif->SWidth, gif->SHeight);
940 TRACE("color res %d, backgcolor %d\n", gif->SColorResolution, gif->SBackGroundColor);
941 TRACE("imgcnt %d\n", gif->ImageCount);
942 if (gif->ImageCount<1) {
943 FIXME("GIF stream does not have images inside?\n");
944 return E_FAIL;
945 }
946 TRACE("curimage: %d x %d, on %dx%d, interlace %d\n",
947 gif->Image.Width, gif->Image.Height,
948 gif->Image.Left, gif->Image.Top,
949 gif->Image.Interlace
950 );
951 /* */
952 bmi = HeapAlloc(GetProcessHeap(),0,sizeof(BITMAPINFOHEADER)+(1<<gif->SColorResolution)*sizeof(RGBQUAD));
953 bytes= HeapAlloc(GetProcessHeap(),0,gif->SWidth*gif->SHeight);
954 si = gif->SavedImages+0;
955 gid = &(si->ImageDesc);
956 cm = gid->ColorMap;
957 if (!cm) cm = gif->SColorMap;
958 for (i=0;i<(1<<gif->SColorResolution);i++) {
959 bmi->bmiColors[i].rgbRed = cm->Colors[i].Red;
960 bmi->bmiColors[i].rgbGreen = cm->Colors[i].Green;
961 bmi->bmiColors[i].rgbBlue = cm->Colors[i].Blue;
962 }
963 /* Map to in picture coordinates */
964 for (i=0;i<gid->Height;i++)
965 for (j=0;j<gid->Width;j++)
966 bytes[(gid->Top+i)*gif->SWidth+gid->Left+j]=si->RasterBits[i*gid->Width+j];
967 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
968 bmi->bmiHeader.biWidth = gif->SWidth;
969 bmi->bmiHeader.biHeight = gif->SHeight;
970 bmi->bmiHeader.biPlanes = 1;
971 bmi->bmiHeader.biBitCount = 8;
972 bmi->bmiHeader.biCompression = BI_RGB;
973 bmi->bmiHeader.biSizeImage = gif->SWidth*gif->SHeight;
974 bmi->bmiHeader.biXPelsPerMeter = 0;
975 bmi->bmiHeader.biYPelsPerMeter = 0;
976 bmi->bmiHeader.biClrUsed = 1 << gif->SColorResolution;
977 bmi->bmiHeader.biClrImportant = 0;
978
979 hdcref = GetDC(0);
980 This->desc.u.bmp.hbitmap=CreateDIBitmap(
981 hdcref,
982 &bmi->bmiHeader,
983 CBM_INIT,
984 bytes,
985 bmi,
986 DIB_PAL_COLORS
987 );
988 DeleteDC(hdcref);
989 This->desc.picType = PICTYPE_BITMAP;
990 OLEPictureImpl_SetBitmap(This);
991 DGifCloseFile(gif);
992 HeapFree(GetProcessHeap(),0,bytes);
993 return S_OK;
994#else
995 FIXME("Trying to load GIF, but no support for libgif/libungif compiled in.\n");
996 return E_FAIL;
997#endif
998 break;
999 }
1000 case 0xd8ff: { /* JPEG */
1001#ifdef HAVE_LIBJPEG
1002 struct jpeg_decompress_struct jd;
1003 struct jpeg_error_mgr jerr;
1004 int ret;
1005 JDIMENSION x;
1006 JSAMPROW samprow,oldsamprow;
1007 BITMAPINFOHEADER bmi;
1008 LPBYTE bits;
1009 HDC hdcref;
1010 struct jpeg_source_mgr xjsm;
1011 LPBYTE oldbits;
1012 int i;
1013
1014 /* This is basically so we can use in-memory data for jpeg decompression.
1015 * We need to have all the functions.
1016 */
1017 xjsm.next_input_byte = xbuf;
1018 xjsm.bytes_in_buffer = xread;
1019 xjsm.init_source = _jpeg_init_source;
1020 xjsm.fill_input_buffer = _jpeg_fill_input_buffer;
1021 xjsm.skip_input_data = _jpeg_skip_input_data;
1022 xjsm.resync_to_restart = _jpeg_resync_to_restart;
1023 xjsm.term_source = _jpeg_term_source;
1024
1025 jd.err = jpeg_std_error(&jerr);
1026 jpeg_create_decompress(&jd);
1027 jd.src = &xjsm;
1028 ret=jpeg_read_header(&jd,TRUE);
1029 jd.out_color_space = JCS_RGB;
1030 jpeg_start_decompress(&jd);
1031 if (ret != JPEG_HEADER_OK) {
1032 ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
1033 HeapFree(GetProcessHeap(),0,xbuf);
1034 return E_FAIL;
1035 }
1036
1037 bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
1038 (jd.output_height+1) * ((jd.output_width*jd.output_components + 3) & ~3) );
1039 samprow=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
1040
1041 oldbits = bits;
1042 oldsamprow = samprow;
1043 while ( jd.output_scanline<jd.output_height ) {
1044 x = jpeg_read_scanlines(&jd,&samprow,1);
1045 if (x != 1) {
1046 FIXME("failed to read current scanline?\n");
1047 break;
1048 }
1049 /* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
1050 for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) {
1051 *(bits++) = *(samprow+2);
1052 *(bits++) = *(samprow+1);
1053 *(bits++) = *(samprow);
1054 }
1055#ifdef __WIN32OS2__
1056 bits = (LPBYTE)((unsigned long)(bits + 3) & ~3);
1057#else
1058 bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
1059#endif
1060 samprow = oldsamprow;
1061 }
1062 bits = oldbits;
1063
1064 bmi.biSize = sizeof(bmi);
1065 bmi.biWidth = jd.output_width;
1066 bmi.biHeight = -jd.output_height;
1067 bmi.biPlanes = 1;
1068 bmi.biBitCount = jd.output_components<<3;
1069 bmi.biCompression = BI_RGB;
1070 bmi.biSizeImage = jd.output_height*jd.output_width*jd.output_components;
1071 bmi.biXPelsPerMeter = 0;
1072 bmi.biYPelsPerMeter = 0;
1073 bmi.biClrUsed = 0;
1074 bmi.biClrImportant = 0;
1075
1076 HeapFree(GetProcessHeap(),0,samprow);
1077 jpeg_finish_decompress(&jd);
1078 jpeg_destroy_decompress(&jd);
1079 hdcref = GetDC(0);
1080 This->desc.u.bmp.hbitmap=CreateDIBitmap(
1081 hdcref,
1082 &bmi,
1083 CBM_INIT,
1084 bits,
1085 (BITMAPINFO*)&bmi,
1086 DIB_RGB_COLORS
1087 );
1088 DeleteDC(hdcref);
1089 This->desc.picType = PICTYPE_BITMAP;
1090 OLEPictureImpl_SetBitmap(This);
1091 hr = S_OK;
1092 HeapFree(GetProcessHeap(),0,bits);
1093#else
1094 ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");
1095 hr = E_FAIL;
1096#endif
1097 break;
1098 }
1099 case 0x4d42: { /* Bitmap */
1100 BITMAPFILEHEADER *bfh = (BITMAPFILEHEADER*)xbuf;
1101 BITMAPINFO *bi = (BITMAPINFO*)(bfh+1);
1102 HDC hdcref;
1103
1104 /* Does not matter whether this is a coreheader or not, we only use
1105 * components which are in both
1106 */
1107 hdcref = GetDC(0);
1108 This->desc.u.bmp.hbitmap = CreateDIBitmap(
1109 hdcref,
1110 &(bi->bmiHeader),
1111 CBM_INIT,
1112 xbuf+bfh->bfOffBits,
1113 bi,
1114 (bi->bmiHeader.biBitCount<=8)?DIB_PAL_COLORS:DIB_RGB_COLORS
1115 );
1116 DeleteDC(hdcref);
1117 This->desc.picType = PICTYPE_BITMAP;
1118 OLEPictureImpl_SetBitmap(This);
1119 hr = S_OK;
1120 break;
1121 }
1122 case 0x0000: { /* ICON , first word is dwReserved */
1123 HICON hicon;
1124 CURSORICONFILEDIR *cifd = (CURSORICONFILEDIR*)xbuf;
1125 int i;
1126
1127 /*
1128 FIXME("icon.idReserved=%d\n",cifd->idReserved);
1129 FIXME("icon.idType=%d\n",cifd->idType);
1130 FIXME("icon.idCount=%d\n",cifd->idCount);
1131
1132 for (i=0;i<cifd->idCount;i++) {
1133 FIXME("[%d] width %d\n",i,cifd->idEntries[i].bWidth);
1134 FIXME("[%d] height %d\n",i,cifd->idEntries[i].bHeight);
1135 FIXME("[%d] bColorCount %d\n",i,cifd->idEntries[i].bColorCount);
1136 FIXME("[%d] bReserved %d\n",i,cifd->idEntries[i].bReserved);
1137 FIXME("[%d] xHotspot %d\n",i,cifd->idEntries[i].xHotspot);
1138 FIXME("[%d] yHotspot %d\n",i,cifd->idEntries[i].yHotspot);
1139 FIXME("[%d] dwDIBSize %d\n",i,cifd->idEntries[i].dwDIBSize);
1140 FIXME("[%d] dwDIBOffset %d\n",i,cifd->idEntries[i].dwDIBOffset);
1141 }
1142 */
1143 i=0;
1144 /* If we have more than one icon, try to find the best.
1145 * this currently means '32 pixel wide'.
1146 */
1147 if (cifd->idCount!=1) {
1148 for (i=0;i<cifd->idCount;i++) {
1149 if (cifd->idEntries[i].bWidth == 32)
1150 break;
1151 }
1152 if (i==cifd->idCount) i=0;
1153 }
1154
1155 hicon = CreateIconFromResourceEx(
1156 xbuf+cifd->idEntries[i].dwDIBOffset,
1157 cifd->idEntries[i].dwDIBSize,
1158 TRUE, /* is icon */
1159 0x00030000,
1160 cifd->idEntries[i].bWidth,
1161 cifd->idEntries[i].bHeight,
1162 0
1163 );
1164 if (!hicon) {
1165 FIXME("CreateIcon failed.\n");
1166 hr = E_FAIL;
1167 } else {
1168 This->desc.picType = PICTYPE_ICON;
1169 This->desc.u.icon.hicon = hicon;
1170 This->himetricWidth = cifd->idEntries[i].bWidth;
1171 This->himetricHeight = cifd->idEntries[i].bHeight;
1172 hr = S_OK;
1173 }
1174 break;
1175 }
1176 default:
1177 {
1178 int i;
1179 FIXME("Unknown magic %04x, %ld read bytes:\n",magic,xread);
1180 hr=E_FAIL;
1181 for (i=0;i<xread+8;i++) {
1182 if (i<8) MESSAGE("%02x ",((unsigned char*)&header)[i]);
1183 else MESSAGE("%02x ",xbuf[i-8]);
1184 if (i % 10 == 9) MESSAGE("\n");
1185 }
1186 MESSAGE("\n");
1187 break;
1188 }
1189 }
1190
1191 /* FIXME: this notify is not really documented */
1192 if (hr==S_OK)
1193 OLEPicture_SendNotify(This,DISPID_PICT_TYPE);
1194 return hr;
1195}
1196
1197static HRESULT WINAPI OLEPictureImpl_Save(
1198 IPersistStream* iface,IStream*pStm,BOOL fClearDirty)
1199{
1200 ICOM_THIS_From_IPersistStream(IPicture, iface);
1201 FIXME("(%p,%p,%d),stub!\n",This,pStm,fClearDirty);
1202 return E_NOTIMPL;
1203}
1204
1205static HRESULT WINAPI OLEPictureImpl_GetSizeMax(
1206 IPersistStream* iface,ULARGE_INTEGER*pcbSize)
1207{
1208 ICOM_THIS_From_IPersistStream(IPicture, iface);
1209 FIXME("(%p,%p),stub!\n",This,pcbSize);
1210 return E_NOTIMPL;
1211}
1212
1213/************************************************************************
1214 * IDispatch
1215 */
1216/************************************************************************
1217 * OLEPictureImpl_IDispatch_QueryInterface (IUnknown)
1218 *
1219 * See Windows documentation for more details on IUnknown methods.
1220 */
1221static HRESULT WINAPI OLEPictureImpl_IDispatch_QueryInterface(
1222 IDispatch* iface,
1223 REFIID riid,
1224 VOID** ppvoid)
1225{
1226 ICOM_THIS_From_IDispatch(IPicture, iface);
1227
1228 return IPicture_QueryInterface(This, riid, ppvoid);
1229}
1230
1231/************************************************************************
1232 * OLEPictureImpl_IDispatch_AddRef (IUnknown)
1233 *
1234 * See Windows documentation for more details on IUnknown methods.
1235 */
1236static ULONG WINAPI OLEPictureImpl_IDispatch_AddRef(
1237 IDispatch* iface)
1238{
1239 ICOM_THIS_From_IDispatch(IPicture, iface);
1240
1241 return IPicture_AddRef(This);
1242}
1243
1244/************************************************************************
1245 * OLEPictureImpl_IDispatch_Release (IUnknown)
1246 *
1247 * See Windows documentation for more details on IUnknown methods.
1248 */
1249static ULONG WINAPI OLEPictureImpl_IDispatch_Release(
1250 IDispatch* iface)
1251{
1252 ICOM_THIS_From_IDispatch(IPicture, iface);
1253
1254 return IPicture_Release(This);
1255}
1256
1257/************************************************************************
1258 * OLEPictureImpl_GetTypeInfoCount (IDispatch)
1259 *
1260 * See Windows documentation for more details on IDispatch methods.
1261 */
1262static HRESULT WINAPI OLEPictureImpl_GetTypeInfoCount(
1263 IDispatch* iface,
1264 unsigned int* pctinfo)
1265{
1266 FIXME("():Stub\n");
1267
1268 return E_NOTIMPL;
1269}
1270
1271/************************************************************************
1272 * OLEPictureImpl_GetTypeInfo (IDispatch)
1273 *
1274 * See Windows documentation for more details on IDispatch methods.
1275 */
1276static HRESULT WINAPI OLEPictureImpl_GetTypeInfo(
1277 IDispatch* iface,
1278 UINT iTInfo,
1279 LCID lcid,
1280 ITypeInfo** ppTInfo)
1281{
1282 FIXME("():Stub\n");
1283
1284 return E_NOTIMPL;
1285}
1286
1287/************************************************************************
1288 * OLEPictureImpl_GetIDsOfNames (IDispatch)
1289 *
1290 * See Windows documentation for more details on IDispatch methods.
1291 */
1292static HRESULT WINAPI OLEPictureImpl_GetIDsOfNames(
1293 IDispatch* iface,
1294 REFIID riid,
1295 LPOLESTR* rgszNames,
1296 UINT cNames,
1297 LCID lcid,
1298 DISPID* rgDispId)
1299{
1300 FIXME("():Stub\n");
1301
1302 return E_NOTIMPL;
1303}
1304
1305/************************************************************************
1306 * OLEPictureImpl_Invoke (IDispatch)
1307 *
1308 * See Windows documentation for more details on IDispatch methods.
1309 */
1310static HRESULT WINAPI OLEPictureImpl_Invoke(
1311 IDispatch* iface,
1312 DISPID dispIdMember,
1313 REFIID riid,
1314 LCID lcid,
1315 WORD wFlags,
1316 DISPPARAMS* pDispParams,
1317 VARIANT* pVarResult,
1318 EXCEPINFO* pExepInfo,
1319 UINT* puArgErr)
1320{
1321 FIXME("(dispid: %ld):Stub\n",dispIdMember);
1322
1323 VariantInit(pVarResult);
1324 V_VT(pVarResult) = VT_BOOL;
1325 V_UNION(pVarResult,boolVal) = FALSE;
1326 return S_OK;
1327}
1328
1329
1330static ICOM_VTABLE(IPicture) OLEPictureImpl_VTable =
1331{
1332 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1333 OLEPictureImpl_QueryInterface,
1334 OLEPictureImpl_AddRef,
1335 OLEPictureImpl_Release,
1336 OLEPictureImpl_get_Handle,
1337 OLEPictureImpl_get_hPal,
1338 OLEPictureImpl_get_Type,
1339 OLEPictureImpl_get_Width,
1340 OLEPictureImpl_get_Height,
1341 OLEPictureImpl_Render,
1342 OLEPictureImpl_set_hPal,
1343 OLEPictureImpl_get_CurDC,
1344 OLEPictureImpl_SelectPicture,
1345 OLEPictureImpl_get_KeepOriginalFormat,
1346 OLEPictureImpl_put_KeepOriginalFormat,
1347 OLEPictureImpl_PictureChanged,
1348 OLEPictureImpl_SaveAsFile,
1349 OLEPictureImpl_get_Attributes
1350};
1351
1352static ICOM_VTABLE(IDispatch) OLEPictureImpl_IDispatch_VTable =
1353{
1354 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1355 OLEPictureImpl_IDispatch_QueryInterface,
1356 OLEPictureImpl_IDispatch_AddRef,
1357 OLEPictureImpl_IDispatch_Release,
1358 OLEPictureImpl_GetTypeInfoCount,
1359 OLEPictureImpl_GetTypeInfo,
1360 OLEPictureImpl_GetIDsOfNames,
1361 OLEPictureImpl_Invoke
1362};
1363
1364static ICOM_VTABLE(IPersistStream) OLEPictureImpl_IPersistStream_VTable =
1365{
1366 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1367 OLEPictureImpl_IPersistStream_QueryInterface,
1368 OLEPictureImpl_IPersistStream_AddRef,
1369 OLEPictureImpl_IPersistStream_Release,
1370 OLEPictureImpl_GetClassID,
1371 OLEPictureImpl_IsDirty,
1372 OLEPictureImpl_Load,
1373 OLEPictureImpl_Save,
1374 OLEPictureImpl_GetSizeMax
1375};
1376
1377static ICOM_VTABLE(IConnectionPointContainer) OLEPictureImpl_IConnectionPointContainer_VTable =
1378{
1379 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1380 OLEPictureImpl_IConnectionPointContainer_QueryInterface,
1381 OLEPictureImpl_IConnectionPointContainer_AddRef,
1382 OLEPictureImpl_IConnectionPointContainer_Release,
1383 OLEPictureImpl_EnumConnectionPoints,
1384 OLEPictureImpl_FindConnectionPoint
1385};
1386
1387/***********************************************************************
1388 * OleCreatePictureIndirect (OLEAUT32.419)
1389 */
1390HRESULT WINAPI OleCreatePictureIndirect(LPPICTDESC lpPictDesc, REFIID riid,
1391 BOOL fOwn, LPVOID *ppvObj )
1392{
1393 OLEPictureImpl* newPict = NULL;
1394 HRESULT hr = S_OK;
1395
1396 TRACE("(%p,%p,%d,%p)\n", lpPictDesc, riid, fOwn, ppvObj);
1397
1398 /*
1399 * Sanity check
1400 */
1401 if (ppvObj==0)
1402 return E_POINTER;
1403
1404 *ppvObj = NULL;
1405
1406 /*
1407 * Try to construct a new instance of the class.
1408 */
1409 newPict = OLEPictureImpl_Construct(lpPictDesc, fOwn);
1410
1411 if (newPict == NULL)
1412 return E_OUTOFMEMORY;
1413
1414 /*
1415 * Make sure it supports the interface required by the caller.
1416 */
1417 hr = IPicture_QueryInterface((IPicture*)newPict, riid, ppvObj);
1418
1419 /*
1420 * Release the reference obtained in the constructor. If
1421 * the QueryInterface was unsuccessful, it will free the class.
1422 */
1423 IPicture_Release((IPicture*)newPict);
1424
1425 return hr;
1426}
1427
1428
1429/***********************************************************************
1430 * OleLoadPicture (OLEAUT32.418)
1431 */
1432HRESULT WINAPI OleLoadPicture( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1433 REFIID riid, LPVOID *ppvObj )
1434{
1435 LPPERSISTSTREAM ps;
1436 IPicture *newpic;
1437 HRESULT hr;
1438
1439 TRACE("(%p,%ld,%d,%s,%p), partially implemented.\n",
1440 lpstream, lSize, fRunmode, debugstr_guid(riid), ppvObj);
1441
1442 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1443 if (hr)
1444 return hr;
1445 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1446 if (hr) {
1447 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1448 IPicture_Release(newpic);
1449 *ppvObj = NULL;
1450 return hr;
1451 }
1452 IPersistStream_Load(ps,lpstream);
1453 IPersistStream_Release(ps);
1454 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1455 if (hr)
1456 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1457 IPicture_Release(newpic);
1458 return hr;
1459}
1460
1461/***********************************************************************
1462 * OleLoadPictureEx (OLEAUT32.401)
1463 */
1464HRESULT WINAPI OleLoadPictureEx( LPSTREAM lpstream, LONG lSize, BOOL fRunmode,
1465 REFIID riid, DWORD xsiz, DWORD ysiz, DWORD flags, LPVOID *ppvObj )
1466{
1467 LPPERSISTSTREAM ps;
1468 IPicture *newpic;
1469 HRESULT hr;
1470
1471 FIXME("(%p,%ld,%d,%s,x=%ld,y=%ld,f=%lx,%p), partially implemented.\n",
1472 lpstream, lSize, fRunmode, debugstr_guid(riid), xsiz, ysiz, flags, ppvObj);
1473
1474 hr = OleCreatePictureIndirect(NULL,riid,!fRunmode,(LPVOID*)&newpic);
1475 if (hr)
1476 return hr;
1477 hr = IPicture_QueryInterface(newpic,&IID_IPersistStream, (LPVOID*)&ps);
1478 if (hr) {
1479 FIXME("Could not get IPersistStream iface from Ole Picture?\n");
1480 IPicture_Release(newpic);
1481 *ppvObj = NULL;
1482 return hr;
1483 }
1484 IPersistStream_Load(ps,lpstream);
1485 IPersistStream_Release(ps);
1486 hr = IPicture_QueryInterface(newpic,riid,ppvObj);
1487 if (hr)
1488 FIXME("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
1489 IPicture_Release(newpic);
1490 return hr;
1491}
1492
1493/*******************************************************************************
1494 * StdPic ClassFactory
1495 */
1496typedef struct
1497{
1498 /* IUnknown fields */
1499 ICOM_VFIELD(IClassFactory);
1500 DWORD ref;
1501} IClassFactoryImpl;
1502
1503static HRESULT WINAPI
1504SPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1505 ICOM_THIS(IClassFactoryImpl,iface);
1506
1507 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1508 return E_NOINTERFACE;
1509}
1510
1511static ULONG WINAPI
1512SPCF_AddRef(LPCLASSFACTORY iface) {
1513 ICOM_THIS(IClassFactoryImpl,iface);
1514 return ++(This->ref);
1515}
1516
1517static ULONG WINAPI SPCF_Release(LPCLASSFACTORY iface) {
1518 ICOM_THIS(IClassFactoryImpl,iface);
1519 /* static class, won't be freed */
1520 return --(This->ref);
1521}
1522
1523static HRESULT WINAPI SPCF_CreateInstance(
1524 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1525) {
1526 PICTDESC pd;
1527
1528 FIXME("(%p,%p,%s,%p), creating stdpic with PICTYPE_NONE.\n",iface,pOuter,debugstr_guid(riid),ppobj);
1529 pd.cbSizeofstruct = sizeof(pd);
1530 pd.picType = PICTYPE_NONE;
1531 return OleCreatePictureIndirect(&pd,riid,TRUE,ppobj);
1532
1533}
1534
1535static HRESULT WINAPI SPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1536 ICOM_THIS(IClassFactoryImpl,iface);
1537 FIXME("(%p)->(%d),stub!\n",This,dolock);
1538 return S_OK;
1539}
1540
1541static ICOM_VTABLE(IClassFactory) SPCF_Vtbl = {
1542 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1543 SPCF_QueryInterface,
1544 SPCF_AddRef,
1545 SPCF_Release,
1546 SPCF_CreateInstance,
1547 SPCF_LockServer
1548};
1549static IClassFactoryImpl STDPIC_CF = {&SPCF_Vtbl, 1 };
1550
1551void _get_STDPIC_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDPIC_CF; }
Note: See TracBrowser for help on using the repository browser.