forked from wine-mirror/wine
/
olepicture.c
2439 lines (2115 loc) · 72.2 KB
/
olepicture.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* OLE Picture object
*
* Implementation of OLE IPicture and related interfaces
*
* Copyright 2000 Huw D M Davies for CodeWeavers.
* Copyright 2001 Marcus Meissner
* Copyright 2008 Kirill K. Smirnov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* BUGS
*
* Support PICTYPE_BITMAP and PICTYPE_ICON, although only bitmaps very well..
* Lots of methods are just stubs.
*
*
* NOTES (or things that msdn doesn't tell you)
*
* The width and height properties are returned in HIMETRIC units (0.01mm)
* IPicture::Render also uses these to select a region of the src picture.
* A bitmap's size is converted into these units by using the screen resolution
* thus an 8x8 bitmap on a 96dpi screen has a size of 212x212 (8/96 * 2540).
*
*/
#include "config.h"
#include "wine/port.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#define COBJMACROS
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "winerror.h"
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "ole2.h"
#include "olectl.h"
#include "oleauto.h"
#include "connpt.h"
#include "urlmon.h"
#include "initguid.h"
#include "wincodec.h"
#include "wine/debug.h"
#include "wine/unicode.h"
#include "wine/library.h"
WINE_DEFAULT_DEBUG_CHANNEL(olepicture);
#define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
#define BITMAP_FORMAT_JPEG 0xd8ff
#define BITMAP_FORMAT_GIF 0x4947
#define BITMAP_FORMAT_PNG 0x5089
#define BITMAP_FORMAT_APM 0xcdd7
#include "pshpack1.h"
/* Header for Aldus Placable Metafiles - a standard metafile follows */
typedef struct _APM_HEADER
{
DWORD key;
WORD handle;
SHORT left;
SHORT top;
SHORT right;
SHORT bottom;
WORD inch;
DWORD reserved;
WORD checksum;
} APM_HEADER;
typedef struct {
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
BYTE bReserved;
WORD xHotspot;
WORD yHotspot;
DWORD dwDIBSize;
DWORD dwDIBOffset;
} CURSORICONFILEDIRENTRY;
typedef struct
{
WORD idReserved;
WORD idType;
WORD idCount;
CURSORICONFILEDIRENTRY idEntries[1];
} CURSORICONFILEDIR;
#include "poppack.h"
/*************************************************************************
* Declaration of implementation class
*/
typedef struct OLEPictureImpl {
/*
* IPicture handles IUnknown
*/
IPicture IPicture_iface;
IDispatch IDispatch_iface;
IPersistStream IPersistStream_iface;
IConnectionPointContainer IConnectionPointContainer_iface;
/* Object reference count */
LONG ref;
/* We own the object and must destroy it ourselves */
BOOL fOwn;
/* Picture description */
PICTDESC desc;
/* These are the pixel size of a bitmap */
DWORD origWidth;
DWORD origHeight;
/* And these are the size of the picture converted into HIMETRIC units */
OLE_XSIZE_HIMETRIC himetricWidth;
OLE_YSIZE_HIMETRIC himetricHeight;
IConnectionPoint *pCP;
BOOL keepOrigFormat;
HDC hDCCur;
HBITMAP stock_bitmap;
/* Bitmap transparency mask */
HBITMAP hbmMask;
HBITMAP hbmXor;
COLORREF rgbTrans;
/* data */
void* data;
int datalen;
BOOL bIsDirty; /* Set to TRUE if picture has changed */
unsigned int loadtime_magic; /* If a length header was found, saves value */
unsigned int loadtime_format; /* for PICTYPE_BITMAP only, keeps track of image format (GIF/BMP/JPEG) */
} OLEPictureImpl;
static inline OLEPictureImpl *impl_from_IPicture(IPicture *iface)
{
return CONTAINING_RECORD(iface, OLEPictureImpl, IPicture_iface);
}
static inline OLEPictureImpl *impl_from_IDispatch( IDispatch *iface )
{
return CONTAINING_RECORD(iface, OLEPictureImpl, IDispatch_iface);
}
static inline OLEPictureImpl *impl_from_IPersistStream( IPersistStream *iface )
{
return CONTAINING_RECORD(iface, OLEPictureImpl, IPersistStream_iface);
}
static inline OLEPictureImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
{
return CONTAINING_RECORD(iface, OLEPictureImpl, IConnectionPointContainer_iface);
}
/*
* Predeclare VTables. They get initialized at the end.
*/
static const IPictureVtbl OLEPictureImpl_VTable;
static const IDispatchVtbl OLEPictureImpl_IDispatch_VTable;
static const IPersistStreamVtbl OLEPictureImpl_IPersistStream_VTable;
static const IConnectionPointContainerVtbl OLEPictureImpl_IConnectionPointContainer_VTable;
/* pixels to HIMETRIC units conversion */
static inline OLE_XSIZE_HIMETRIC xpixels_to_himetric(INT pixels, HDC hdc)
{
return MulDiv(pixels, 2540, GetDeviceCaps(hdc, LOGPIXELSX));
}
static inline OLE_YSIZE_HIMETRIC ypixels_to_himetric(INT pixels, HDC hdc)
{
return MulDiv(pixels, 2540, GetDeviceCaps(hdc, LOGPIXELSY));
}
/***********************************************************************
* Implementation of the OLEPictureImpl class.
*/
static void OLEPictureImpl_SetBitmap(OLEPictureImpl *This)
{
BITMAP bm;
HDC hdcRef;
TRACE("bitmap handle %p\n", This->desc.u.bmp.hbitmap);
if(GetObjectW(This->desc.u.bmp.hbitmap, sizeof(bm), &bm) != sizeof(bm)) {
ERR("GetObject fails\n");
return;
}
This->origWidth = bm.bmWidth;
This->origHeight = bm.bmHeight;
TRACE("width %d, height %d, bpp %d\n", bm.bmWidth, bm.bmHeight, bm.bmBitsPixel);
/* The width and height are stored in HIMETRIC units (0.01 mm),
so we take our pixel width divide by pixels per inch and
multiply by 25.4 * 100 */
/* Should we use GetBitmapDimension if available? */
hdcRef = CreateCompatibleDC(0);
This->himetricWidth = xpixels_to_himetric(bm.bmWidth, hdcRef);
This->himetricHeight = ypixels_to_himetric(bm.bmHeight, hdcRef);
This->stock_bitmap = GetCurrentObject( hdcRef, OBJ_BITMAP );
This->loadtime_format = BITMAP_FORMAT_BMP;
DeleteDC(hdcRef);
}
static void OLEPictureImpl_SetIcon(OLEPictureImpl * This)
{
ICONINFO infoIcon;
TRACE("icon handle %p\n", This->desc.u.icon.hicon);
if (GetIconInfo(This->desc.u.icon.hicon, &infoIcon)) {
HDC hdcRef;
BITMAP bm;
TRACE("bitmap handle for icon is %p\n", infoIcon.hbmColor);
if(GetObjectW(infoIcon.hbmColor ? infoIcon.hbmColor : infoIcon.hbmMask, sizeof(bm), &bm) != sizeof(bm)) {
ERR("GetObject fails on icon bitmap\n");
return;
}
This->origWidth = bm.bmWidth;
This->origHeight = infoIcon.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
/* see comment on HIMETRIC on OLEPictureImpl_SetBitmap() */
hdcRef = GetDC(0);
This->himetricWidth = xpixels_to_himetric(This->origWidth, hdcRef);
This->himetricHeight = ypixels_to_himetric(This->origHeight, hdcRef);
ReleaseDC(0, hdcRef);
DeleteObject(infoIcon.hbmMask);
if (infoIcon.hbmColor) DeleteObject(infoIcon.hbmColor);
} else {
ERR("GetIconInfo() fails on icon %p\n", This->desc.u.icon.hicon);
}
}
/************************************************************************
* OLEPictureImpl_Construct
*
* This method will construct a new instance of the OLEPictureImpl
* class.
*
* The caller of this method must release the object when it's
* done with it.
*/
static OLEPictureImpl* OLEPictureImpl_Construct(LPPICTDESC pictDesc, BOOL fOwn)
{
OLEPictureImpl* newObject = 0;
if (pictDesc)
TRACE("(%p) type = %d\n", pictDesc, pictDesc->picType);
/*
* Allocate space for the object.
*/
newObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OLEPictureImpl));
if (newObject==0)
return newObject;
/*
* Initialize the virtual function table.
*/
newObject->IPicture_iface.lpVtbl = &OLEPictureImpl_VTable;
newObject->IDispatch_iface.lpVtbl = &OLEPictureImpl_IDispatch_VTable;
newObject->IPersistStream_iface.lpVtbl = &OLEPictureImpl_IPersistStream_VTable;
newObject->IConnectionPointContainer_iface.lpVtbl = &OLEPictureImpl_IConnectionPointContainer_VTable;
newObject->pCP = NULL;
CreateConnectionPoint((IUnknown*)newObject,&IID_IPropertyNotifySink,&newObject->pCP);
if (!newObject->pCP)
{
HeapFree(GetProcessHeap(), 0, newObject);
return NULL;
}
/*
* Start with one reference count. The caller of this function
* must release the interface pointer when it is done.
*/
newObject->ref = 1;
newObject->hDCCur = 0;
newObject->fOwn = fOwn;
/* dunno about original value */
newObject->keepOrigFormat = TRUE;
newObject->hbmMask = NULL;
newObject->hbmXor = NULL;
newObject->loadtime_magic = 0xdeadbeef;
newObject->loadtime_format = 0;
newObject->bIsDirty = FALSE;
if (pictDesc) {
newObject->desc = *pictDesc;
switch(pictDesc->picType) {
case PICTYPE_BITMAP:
OLEPictureImpl_SetBitmap(newObject);
break;
case PICTYPE_METAFILE:
TRACE("metafile handle %p\n", pictDesc->u.wmf.hmeta);
newObject->himetricWidth = pictDesc->u.wmf.xExt;
newObject->himetricHeight = pictDesc->u.wmf.yExt;
break;
case PICTYPE_NONE:
/* not sure what to do here */
newObject->himetricWidth = newObject->himetricHeight = 0;
break;
case PICTYPE_ICON:
OLEPictureImpl_SetIcon(newObject);
break;
case PICTYPE_ENHMETAFILE:
default:
FIXME("Unsupported type %d\n", pictDesc->picType);
newObject->himetricWidth = newObject->himetricHeight = 0;
break;
}
} else {
newObject->desc.picType = PICTYPE_UNINITIALIZED;
}
TRACE("returning %p\n", newObject);
return newObject;
}
/************************************************************************
* OLEPictureImpl_Destroy
*
* This method is called by the Release method when the reference
* count goes down to 0. It will free all resources used by
* this object. */
static void OLEPictureImpl_Destroy(OLEPictureImpl* Obj)
{
TRACE("(%p)\n", Obj);
if (Obj->pCP)
IConnectionPoint_Release(Obj->pCP);
if(Obj->fOwn) { /* We need to destroy the picture */
switch(Obj->desc.picType) {
case PICTYPE_BITMAP:
DeleteObject(Obj->desc.u.bmp.hbitmap);
if (Obj->hbmMask != NULL) DeleteObject(Obj->hbmMask);
if (Obj->hbmXor != NULL) DeleteObject(Obj->hbmXor);
break;
case PICTYPE_METAFILE:
DeleteMetaFile(Obj->desc.u.wmf.hmeta);
break;
case PICTYPE_ICON:
DestroyIcon(Obj->desc.u.icon.hicon);
break;
case PICTYPE_ENHMETAFILE:
DeleteEnhMetaFile(Obj->desc.u.emf.hemf);
break;
case PICTYPE_NONE:
case PICTYPE_UNINITIALIZED:
/* Nothing to do */
break;
default:
FIXME("Unsupported type %d - unable to delete\n", Obj->desc.picType);
break;
}
}
HeapFree(GetProcessHeap(), 0, Obj->data);
HeapFree(GetProcessHeap(), 0, Obj);
}
/************************************************************************
* OLEPictureImpl_AddRef (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static ULONG WINAPI OLEPictureImpl_AddRef(
IPicture* iface)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
ULONG refCount = InterlockedIncrement(&This->ref);
TRACE("(%p)->(ref before=%d)\n", This, refCount - 1);
return refCount;
}
/************************************************************************
* OLEPictureImpl_Release (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static ULONG WINAPI OLEPictureImpl_Release(
IPicture* iface)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
ULONG refCount = InterlockedDecrement(&This->ref);
TRACE("(%p)->(ref before=%d)\n", This, refCount + 1);
/*
* If the reference count goes down to 0, perform suicide.
*/
if (!refCount) OLEPictureImpl_Destroy(This);
return refCount;
}
/************************************************************************
* OLEPictureImpl_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static HRESULT WINAPI OLEPictureImpl_QueryInterface(
IPicture* iface,
REFIID riid,
void** ppvObject)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
if (!ppvObject)
return E_INVALIDARG;
*ppvObject = 0;
if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPicture, riid))
*ppvObject = This;
else if (IsEqualIID(&IID_IDispatch, riid))
*ppvObject = &This->IDispatch_iface;
else if (IsEqualIID(&IID_IPictureDisp, riid))
*ppvObject = &This->IDispatch_iface;
else if (IsEqualIID(&IID_IPersist, riid) || IsEqualIID(&IID_IPersistStream, riid))
*ppvObject = &This->IPersistStream_iface;
else if (IsEqualIID(&IID_IConnectionPointContainer, riid))
*ppvObject = &This->IConnectionPointContainer_iface;
if (!*ppvObject)
{
FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
return E_NOINTERFACE;
}
IPicture_AddRef(iface);
return S_OK;
}
/***********************************************************************
* OLEPicture_SendNotify (internal)
*
* Sends notification messages of changed properties to any interested
* connections.
*/
static void OLEPicture_SendNotify(OLEPictureImpl* this, DISPID dispID)
{
IEnumConnections *pEnum;
CONNECTDATA CD;
if (IConnectionPoint_EnumConnections(this->pCP, &pEnum) != S_OK)
return;
while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
IPropertyNotifySink *sink;
IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
IPropertyNotifySink_OnChanged(sink, dispID);
IPropertyNotifySink_Release(sink);
IUnknown_Release(CD.pUnk);
}
IEnumConnections_Release(pEnum);
}
/************************************************************************
* OLEPictureImpl_get_Handle
*/
static HRESULT WINAPI OLEPictureImpl_get_Handle(IPicture *iface,
OLE_HANDLE *phandle)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p)\n", This, phandle);
if(!phandle)
return E_POINTER;
switch(This->desc.picType) {
case PICTYPE_NONE:
case PICTYPE_UNINITIALIZED:
*phandle = 0;
break;
case PICTYPE_BITMAP:
*phandle = HandleToUlong(This->desc.u.bmp.hbitmap);
break;
case PICTYPE_METAFILE:
*phandle = HandleToUlong(This->desc.u.wmf.hmeta);
break;
case PICTYPE_ICON:
*phandle = HandleToUlong(This->desc.u.icon.hicon);
break;
case PICTYPE_ENHMETAFILE:
*phandle = HandleToUlong(This->desc.u.emf.hemf);
break;
default:
FIXME("Unimplemented type %d\n", This->desc.picType);
return E_NOTIMPL;
}
TRACE("returning handle %08x\n", *phandle);
return S_OK;
}
/************************************************************************
* OLEPictureImpl_get_hPal
*/
static HRESULT WINAPI OLEPictureImpl_get_hPal(IPicture *iface,
OLE_HANDLE *phandle)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
HRESULT hres;
TRACE("(%p)->(%p)\n", This, phandle);
if (!phandle)
return E_POINTER;
switch (This->desc.picType) {
case (UINT)PICTYPE_UNINITIALIZED:
case PICTYPE_NONE:
*phandle = 0;
hres = S_FALSE;
break;
case PICTYPE_BITMAP:
*phandle = HandleToUlong(This->desc.u.bmp.hpal);
hres = S_OK;
break;
case PICTYPE_METAFILE:
hres = E_FAIL;
break;
case PICTYPE_ICON:
case PICTYPE_ENHMETAFILE:
default:
FIXME("unimplemented for type %d. Returning 0 palette.\n",
This->desc.picType);
*phandle = 0;
hres = S_OK;
}
TRACE("returning 0x%08x, palette handle %08x\n", hres, *phandle);
return hres;
}
/************************************************************************
* OLEPictureImpl_get_Type
*/
static HRESULT WINAPI OLEPictureImpl_get_Type(IPicture *iface,
short *ptype)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p): type is %d\n", This, ptype, This->desc.picType);
if(!ptype)
return E_POINTER;
*ptype = This->desc.picType;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_get_Width
*/
static HRESULT WINAPI OLEPictureImpl_get_Width(IPicture *iface,
OLE_XSIZE_HIMETRIC *pwidth)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p): width is %d\n", This, pwidth, This->himetricWidth);
*pwidth = This->himetricWidth;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_get_Height
*/
static HRESULT WINAPI OLEPictureImpl_get_Height(IPicture *iface,
OLE_YSIZE_HIMETRIC *pheight)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p): height is %d\n", This, pheight, This->himetricHeight);
*pheight = This->himetricHeight;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_Render
*/
static HRESULT WINAPI OLEPictureImpl_Render(IPicture *iface, HDC hdc,
LONG x, LONG y, LONG cx, LONG cy,
OLE_XPOS_HIMETRIC xSrc,
OLE_YPOS_HIMETRIC ySrc,
OLE_XSIZE_HIMETRIC cxSrc,
OLE_YSIZE_HIMETRIC cySrc,
LPCRECT prcWBounds)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p, (%d,%d), (%d,%d) <- (%d,%d), (%d,%d), %p)\n",
This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
if(prcWBounds)
TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
prcWBounds->right, prcWBounds->bottom);
if(cx == 0 || cy == 0 || cxSrc == 0 || cySrc == 0){
return CTL_E_INVALIDPROPERTYVALUE;
}
/*
* While the documentation suggests this to be here (or after rendering?)
* it does cause an endless recursion in my sample app. -MM 20010804
OLEPicture_SendNotify(This,DISPID_PICT_RENDER);
*/
switch(This->desc.picType) {
case PICTYPE_UNINITIALIZED:
case PICTYPE_NONE:
/* nothing to do */
return S_OK;
case PICTYPE_BITMAP:
{
HBITMAP hbmpOld;
HDC hdcBmp;
/* Set a mapping mode that maps bitmap pixels into HIMETRIC units.
NB y-axis gets flipped */
hdcBmp = CreateCompatibleDC(0);
SetMapMode(hdcBmp, MM_ANISOTROPIC);
SetWindowOrgEx(hdcBmp, 0, 0, NULL);
SetWindowExtEx(hdcBmp, This->himetricWidth, This->himetricHeight, NULL);
SetViewportOrgEx(hdcBmp, 0, This->origHeight, NULL);
SetViewportExtEx(hdcBmp, This->origWidth, -This->origHeight, NULL);
if (This->hbmMask) {
HDC hdcMask = CreateCompatibleDC(0);
HBITMAP hOldbm = SelectObject(hdcMask, This->hbmMask);
hbmpOld = SelectObject(hdcBmp, This->hbmXor);
SetMapMode(hdcMask, MM_ANISOTROPIC);
SetWindowOrgEx(hdcMask, 0, 0, NULL);
SetWindowExtEx(hdcMask, This->himetricWidth, This->himetricHeight, NULL);
SetViewportOrgEx(hdcMask, 0, This->origHeight, NULL);
SetViewportExtEx(hdcMask, This->origWidth, -This->origHeight, NULL);
SetBkColor(hdc, RGB(255, 255, 255));
SetTextColor(hdc, RGB(0, 0, 0));
StretchBlt(hdc, x, y, cx, cy, hdcMask, xSrc, ySrc, cxSrc, cySrc, SRCAND);
StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCPAINT);
SelectObject(hdcMask, hOldbm);
DeleteDC(hdcMask);
} else {
hbmpOld = SelectObject(hdcBmp, This->desc.u.bmp.hbitmap);
StretchBlt(hdc, x, y, cx, cy, hdcBmp, xSrc, ySrc, cxSrc, cySrc, SRCCOPY);
}
SelectObject(hdcBmp, hbmpOld);
DeleteDC(hdcBmp);
}
break;
case PICTYPE_ICON:
FIXME("Not quite correct implementation of rendering icons...\n");
DrawIconEx(hdc, x, y, This->desc.u.icon.hicon, cx, cy, 0, NULL, DI_NORMAL);
break;
case PICTYPE_METAFILE:
{
POINT prevOrg, prevWndOrg;
SIZE prevExt, prevWndExt;
int oldmode;
/* Render the WMF to the appropriate location by setting the
appropriate ratio between "device units" and "logical units" */
oldmode = SetMapMode(hdc, MM_ANISOTROPIC);
/* For the "source rectangle" the y-axis must be inverted */
SetWindowOrgEx(hdc, xSrc, This->himetricHeight-ySrc, &prevWndOrg);
SetWindowExtEx(hdc, cxSrc, -cySrc, &prevWndExt);
/* For the "destination rectangle" no inversion is necessary */
SetViewportOrgEx(hdc, x, y, &prevOrg);
SetViewportExtEx(hdc, cx, cy, &prevExt);
if (!PlayMetaFile(hdc, This->desc.u.wmf.hmeta))
ERR("PlayMetaFile failed!\n");
/* We're done, restore the DC to the previous settings for converting
logical units to device units */
SetWindowExtEx(hdc, prevWndExt.cx, prevWndExt.cy, NULL);
SetWindowOrgEx(hdc, prevWndOrg.x, prevWndOrg.y, NULL);
SetViewportExtEx(hdc, prevExt.cx, prevExt.cy, NULL);
SetViewportOrgEx(hdc, prevOrg.x, prevOrg.y, NULL);
SetMapMode(hdc, oldmode);
break;
}
case PICTYPE_ENHMETAFILE:
{
RECT rc = { x, y, x + cx, y + cy };
PlayEnhMetaFile(hdc, This->desc.u.emf.hemf, &rc);
break;
}
default:
FIXME("type %d not implemented\n", This->desc.picType);
return E_NOTIMPL;
}
return S_OK;
}
/************************************************************************
* OLEPictureImpl_set_hPal
*/
static HRESULT WINAPI OLEPictureImpl_set_hPal(IPicture *iface,
OLE_HANDLE hpal)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
FIXME("(%p)->(%08x): stub\n", This, hpal);
OLEPicture_SendNotify(This,DISPID_PICT_HPAL);
return E_NOTIMPL;
}
/************************************************************************
* OLEPictureImpl_get_CurDC
*/
static HRESULT WINAPI OLEPictureImpl_get_CurDC(IPicture *iface,
HDC *phdc)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p), returning %p\n", This, This->hDCCur);
if (phdc) *phdc = This->hDCCur;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_SelectPicture
*/
static HRESULT WINAPI OLEPictureImpl_SelectPicture(IPicture *iface,
HDC hdcIn,
HDC *phdcOut,
OLE_HANDLE *phbmpOut)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p, %p, %p)\n", This, hdcIn, phdcOut, phbmpOut);
if (This->desc.picType == PICTYPE_BITMAP) {
if (phdcOut)
*phdcOut = This->hDCCur;
if (This->hDCCur) SelectObject(This->hDCCur,This->stock_bitmap);
if (hdcIn) SelectObject(hdcIn,This->desc.u.bmp.hbitmap);
This->hDCCur = hdcIn;
if (phbmpOut)
*phbmpOut = HandleToUlong(This->desc.u.bmp.hbitmap);
return S_OK;
} else {
FIXME("Don't know how to select picture type %d\n",This->desc.picType);
return E_FAIL;
}
}
/************************************************************************
* OLEPictureImpl_get_KeepOriginalFormat
*/
static HRESULT WINAPI OLEPictureImpl_get_KeepOriginalFormat(IPicture *iface,
BOOL *pfKeep)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p)\n", This, pfKeep);
if (!pfKeep)
return E_POINTER;
*pfKeep = This->keepOrigFormat;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_put_KeepOriginalFormat
*/
static HRESULT WINAPI OLEPictureImpl_put_KeepOriginalFormat(IPicture *iface,
BOOL keep)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%d)\n", This, keep);
This->keepOrigFormat = keep;
/* FIXME: what DISPID notification here? */
return S_OK;
}
/************************************************************************
* OLEPictureImpl_PictureChanged
*/
static HRESULT WINAPI OLEPictureImpl_PictureChanged(IPicture *iface)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->()\n", This);
OLEPicture_SendNotify(This,DISPID_PICT_HANDLE);
This->bIsDirty = TRUE;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_SaveAsFile
*/
static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
IStream *pstream,
BOOL SaveMemCopy,
LONG *pcbSize)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
FIXME("(%p)->(%p, %d, %p), hacked stub.\n", This, pstream, SaveMemCopy, pcbSize);
return IStream_Write(pstream,This->data,This->datalen,(ULONG*)pcbSize);
}
/************************************************************************
* OLEPictureImpl_get_Attributes
*/
static HRESULT WINAPI OLEPictureImpl_get_Attributes(IPicture *iface,
DWORD *pdwAttr)
{
OLEPictureImpl *This = impl_from_IPicture(iface);
TRACE("(%p)->(%p).\n", This, pdwAttr);
if(!pdwAttr)
return E_POINTER;
*pdwAttr = 0;
switch (This->desc.picType) {
case PICTYPE_UNINITIALIZED:
case PICTYPE_NONE: break;
case PICTYPE_BITMAP: if (This->hbmMask) *pdwAttr = PICTURE_TRANSPARENT; break; /* not 'truly' scalable, see MSDN. */
case PICTYPE_ICON: *pdwAttr = PICTURE_TRANSPARENT;break;
case PICTYPE_ENHMETAFILE: /* fall through */
case PICTYPE_METAFILE: *pdwAttr = PICTURE_TRANSPARENT|PICTURE_SCALABLE;break;
default:FIXME("Unknown pictype %d\n",This->desc.picType);break;
}
return S_OK;
}
/************************************************************************
* IConnectionPointContainer
*/
static HRESULT WINAPI OLEPictureImpl_IConnectionPointContainer_QueryInterface(
IConnectionPointContainer* iface,
REFIID riid,
VOID** ppvoid)
{
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
return IPicture_QueryInterface(&This->IPicture_iface,riid,ppvoid);
}
static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_AddRef(
IConnectionPointContainer* iface)
{
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
return IPicture_AddRef(&This->IPicture_iface);
}
static ULONG WINAPI OLEPictureImpl_IConnectionPointContainer_Release(
IConnectionPointContainer* iface)
{
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
return IPicture_Release(&This->IPicture_iface);
}
static HRESULT WINAPI OLEPictureImpl_EnumConnectionPoints(
IConnectionPointContainer* iface,
IEnumConnectionPoints** ppEnum)
{
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
FIXME("(%p,%p), stub!\n",This,ppEnum);
return E_NOTIMPL;
}
static HRESULT WINAPI OLEPictureImpl_FindConnectionPoint(
IConnectionPointContainer* iface,
REFIID riid,
IConnectionPoint **ppCP)
{
OLEPictureImpl *This = impl_from_IConnectionPointContainer(iface);
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppCP);
if (!ppCP)
return E_POINTER;
*ppCP = NULL;
if (IsEqualGUID(riid,&IID_IPropertyNotifySink))
return IConnectionPoint_QueryInterface(This->pCP,&IID_IConnectionPoint,(LPVOID)ppCP);
FIXME("no connection point for %s\n",debugstr_guid(riid));
return CONNECT_E_NOCONNECTION;
}
/************************************************************************
* IPersistStream
*/
/************************************************************************
* OLEPictureImpl_IPersistStream_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static HRESULT WINAPI OLEPictureImpl_IPersistStream_QueryInterface(
IPersistStream* iface,
REFIID riid,
VOID** ppvoid)
{
OLEPictureImpl *This = impl_from_IPersistStream(iface);
return IPicture_QueryInterface(&This->IPicture_iface, riid, ppvoid);
}
/************************************************************************
* OLEPictureImpl_IPersistStream_AddRef (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static ULONG WINAPI OLEPictureImpl_IPersistStream_AddRef(
IPersistStream* iface)
{
OLEPictureImpl *This = impl_from_IPersistStream(iface);
return IPicture_AddRef(&This->IPicture_iface);
}
/************************************************************************
* OLEPictureImpl_IPersistStream_Release (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static ULONG WINAPI OLEPictureImpl_IPersistStream_Release(
IPersistStream* iface)
{
OLEPictureImpl *This = impl_from_IPersistStream(iface);
return IPicture_Release(&This->IPicture_iface);
}
/************************************************************************
* OLEPictureImpl_IPersistStream_GetClassID
*/
static HRESULT WINAPI OLEPictureImpl_GetClassID(
IPersistStream* iface,CLSID* pClassID)
{
TRACE("(%p)\n", pClassID);
*pClassID = CLSID_StdPicture;
return S_OK;
}
/************************************************************************
* OLEPictureImpl_IPersistStream_IsDirty
*/
static HRESULT WINAPI OLEPictureImpl_IsDirty(
IPersistStream* iface)
{
OLEPictureImpl *This = impl_from_IPersistStream(iface);
FIXME("(%p),stub!\n",This);
return E_NOTIMPL;
}
static HRESULT OLEPictureImpl_LoadDIB(OLEPictureImpl *This, BYTE *xbuf, ULONG xread)
{