xref: /reactos/sdk/include/psdk/gdiplusheaders.h (revision 1e83f8b5)
1 /*
2  * GdiPlusHeaders.h
3  *
4  * Windows GDI+
5  *
6  * This file is part of the w32api package.
7  *
8  * THIS SOFTWARE IS NOT COPYRIGHTED
9  *
10  * This source code is offered for use in the public domain. You may
11  * use, modify or distribute it freely.
12  *
13  * This code is distributed in the hope that it will be useful but
14  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
15  * DISCLAIMED. This includes but is not limited to warranties of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  */
18 
19 #ifndef _GDIPLUSHEADERS_H
20 #define _GDIPLUSHEADERS_H
21 
22 class Image : public GdiplusBase
23 {
24   public:
25     friend class Graphics;
26     friend class TextureBrush;
27 
nativeImage(NULL)28     Image(IStream *stream, BOOL useEmbeddedColorManagement = FALSE) : nativeImage(NULL)
29     {
30         if (useEmbeddedColorManagement)
31             lastStatus = DllExports::GdipLoadImageFromStreamICM(stream, &nativeImage);
32         else
33             lastStatus = DllExports::GdipLoadImageFromStream(stream, &nativeImage);
34     }
35 
nativeImage(NULL)36     Image(const WCHAR *filename, BOOL useEmbeddedColorManagement = FALSE) : nativeImage(NULL)
37     {
38         if (useEmbeddedColorManagement)
39             lastStatus = DllExports::GdipLoadImageFromFileICM(filename, &nativeImage);
40         else
41             lastStatus = DllExports::GdipLoadImageFromFile(filename, &nativeImage);
42     }
43 
44     Image *
Clone()45     Clone()
46     {
47         GpImage *cloneimage = NULL;
48         SetStatus(DllExports::GdipCloneImage(nativeImage, &cloneimage));
49         return new Image(cloneimage, lastStatus);
50     }
51 
~Image()52     virtual ~Image()
53     {
54         DllExports::GdipDisposeImage(nativeImage);
55     }
56 
57     static Image *
58     FromFile(const WCHAR *filename, BOOL useEmbeddedColorManagement = FALSE)
59     {
60         return new Image(filename, useEmbeddedColorManagement);
61     }
62 
63     static Image *
64     FromStream(IStream *stream, BOOL useEmbeddedColorManagement = FALSE)
65     {
66         return new Image(stream, useEmbeddedColorManagement);
67     }
68 
69     Status
GetAllPropertyItems(UINT totalBufferSize,UINT numProperties,PropertyItem * allItems)70     GetAllPropertyItems(UINT totalBufferSize, UINT numProperties, PropertyItem *allItems)
71     {
72         if (allItems == NULL)
73             return SetStatus(InvalidParameter);
74         return SetStatus(DllExports::GdipGetAllPropertyItems(nativeImage, totalBufferSize, numProperties, allItems));
75     }
76 
77     Status
GetBounds(RectF * srcRect,Unit * srcUnit)78     GetBounds(RectF *srcRect, Unit *srcUnit)
79     {
80         return SetStatus(DllExports::GdipGetImageBounds(nativeImage, srcRect, srcUnit));
81     }
82 
83     Status
GetEncoderParameterList(const CLSID * clsidEncoder,UINT size,EncoderParameters * buffer)84     GetEncoderParameterList(const CLSID *clsidEncoder, UINT size, EncoderParameters *buffer)
85     {
86 #if 1
87         return SetStatus(NotImplemented);
88 #else
89         return SetStatus(DllExports::GdipGetEncoderParameterList(nativeImage, clsidEncoder, size, buffer));
90 #endif
91     }
92 
93     UINT
GetEncoderParameterListSize(const CLSID * clsidEncoder)94     GetEncoderParameterListSize(const CLSID *clsidEncoder)
95     {
96         UINT size = 0;
97         SetStatus(DllExports::GdipGetEncoderParameterListSize(nativeImage, clsidEncoder, &size));
98         return size;
99     }
100 
101     UINT
GetFlags()102     GetFlags()
103     {
104         UINT flags = 0;
105         SetStatus(DllExports::GdipGetImageFlags(nativeImage, &flags));
106         return flags;
107     }
108 
109     UINT
GetFrameCount(const GUID * dimensionID)110     GetFrameCount(const GUID *dimensionID)
111     {
112         UINT count = 0;
113         SetStatus(DllExports::GdipImageGetFrameCount(nativeImage, dimensionID, &count));
114         return count;
115     }
116 
117     UINT
GetFrameDimensionsCount()118     GetFrameDimensionsCount()
119     {
120         UINT count = 0;
121         SetStatus(DllExports::GdipImageGetFrameDimensionsCount(nativeImage, &count));
122         return count;
123     }
124 
125     Status
GetFrameDimensionsList(GUID * dimensionIDs,UINT count)126     GetFrameDimensionsList(GUID *dimensionIDs, UINT count)
127     {
128         return SetStatus(DllExports::GdipImageGetFrameDimensionsList(nativeImage, dimensionIDs, count));
129     }
130 
131     UINT
GetHeight()132     GetHeight()
133     {
134         UINT height = 0;
135         SetStatus(DllExports::GdipGetImageHeight(nativeImage, &height));
136         return height;
137     }
138 
139     REAL
GetHorizontalResolution()140     GetHorizontalResolution()
141     {
142         REAL resolution = 0.0f;
143         SetStatus(DllExports::GdipGetImageHorizontalResolution(nativeImage, &resolution));
144         return resolution;
145     }
146 
147     Status
GetLastStatus()148     GetLastStatus()
149     {
150         return lastStatus;
151     }
152 
153     Status
GetPalette(ColorPalette * palette,INT size)154     GetPalette(ColorPalette *palette, INT size)
155     {
156         return SetStatus(DllExports::GdipGetImagePalette(nativeImage, palette, size));
157     }
158 
159     INT
GetPaletteSize()160     GetPaletteSize()
161     {
162         INT size = 0;
163         SetStatus(DllExports::GdipGetImagePaletteSize(nativeImage, &size));
164         return size;
165     }
166 
167     Status
GetPhysicalDimension(SizeF * size)168     GetPhysicalDimension(SizeF *size)
169     {
170         if (size == NULL)
171             return SetStatus(InvalidParameter);
172 
173         return SetStatus(DllExports::GdipGetImageDimension(nativeImage, &size->Width, &size->Height));
174     }
175 
176     PixelFormat
GetPixelFormat()177     GetPixelFormat()
178     {
179         PixelFormat format;
180         SetStatus(DllExports::GdipGetImagePixelFormat(nativeImage, &format));
181         return format;
182     }
183 
184     UINT
GetPropertyCount()185     GetPropertyCount()
186     {
187         UINT numOfProperty = 0;
188         SetStatus(DllExports::GdipGetPropertyCount(nativeImage, &numOfProperty));
189         return numOfProperty;
190     }
191 
192     Status
GetPropertyIdList(UINT numOfProperty,PROPID * list)193     GetPropertyIdList(UINT numOfProperty, PROPID *list)
194     {
195         return SetStatus(DllExports::GdipGetPropertyIdList(nativeImage, numOfProperty, list));
196     }
197 
198     Status
GetPropertyItem(PROPID propId,UINT propSize,PropertyItem * buffer)199     GetPropertyItem(PROPID propId, UINT propSize, PropertyItem *buffer)
200     {
201         return SetStatus(DllExports::GdipGetPropertyItem(nativeImage, propId, propSize, buffer));
202     }
203 
204     UINT
GetPropertyItemSize(PROPID propId)205     GetPropertyItemSize(PROPID propId)
206     {
207         UINT size = 0;
208         SetStatus(DllExports::GdipGetPropertyItemSize(nativeImage, propId, &size));
209         return size;
210     }
211 
212     Status
GetPropertySize(UINT * totalBufferSize,UINT * numProperties)213     GetPropertySize(UINT *totalBufferSize, UINT *numProperties)
214     {
215         return SetStatus(DllExports::GdipGetPropertySize(nativeImage, totalBufferSize, numProperties));
216     }
217 
218     Status
GetRawFormat(GUID * format)219     GetRawFormat(GUID *format)
220     {
221         return SetStatus(DllExports::GdipGetImageRawFormat(nativeImage, format));
222     }
223 
224     Image *
GetThumbnailImage(UINT thumbWidth,UINT thumbHeight,GetThumbnailImageAbort callback,VOID * callbackData)225     GetThumbnailImage(UINT thumbWidth, UINT thumbHeight, GetThumbnailImageAbort callback, VOID *callbackData)
226     {
227         GpImage *thumbImage = NULL;
228         SetStatus(DllExports::GdipGetImageThumbnail(
229             nativeImage, thumbWidth, thumbHeight, &thumbImage, callback, callbackData));
230         Image *newImage = new Image(thumbImage, lastStatus);
231         if (newImage == NULL)
232         {
233             DllExports::GdipDisposeImage(thumbImage);
234         }
235         return newImage;
236     }
237 
238     ImageType
GetType()239     GetType()
240     {
241         ImageType type;
242         SetStatus(DllExports::GdipGetImageType(nativeImage, &type));
243         return type;
244     }
245 
246     REAL
GetVerticalResolution()247     GetVerticalResolution()
248     {
249         REAL resolution = 0.0f;
250         SetStatus(DllExports::GdipGetImageVerticalResolution(nativeImage, &resolution));
251         return resolution;
252     }
253 
254     UINT
GetWidth()255     GetWidth()
256     {
257         UINT width = 0;
258         SetStatus(DllExports::GdipGetImageWidth(nativeImage, &width));
259         return width;
260     }
261 
262     Status
RemovePropertyItem(PROPID propId)263     RemovePropertyItem(PROPID propId)
264     {
265         return SetStatus(DllExports::GdipRemovePropertyItem(nativeImage, propId));
266     }
267 
268     Status
RotateFlip(RotateFlipType rotateFlipType)269     RotateFlip(RotateFlipType rotateFlipType)
270     {
271         return SetStatus(DllExports::GdipImageRotateFlip(nativeImage, rotateFlipType));
272     }
273 
274     Status
Save(IStream * stream,const CLSID * clsidEncoder,const EncoderParameters * encoderParams)275     Save(IStream *stream, const CLSID *clsidEncoder, const EncoderParameters *encoderParams)
276     {
277         return SetStatus(DllExports::GdipSaveImageToStream(nativeImage, stream, clsidEncoder, encoderParams));
278     }
279 
280     Status
Save(const WCHAR * filename,const CLSID * clsidEncoder,const EncoderParameters * encoderParams)281     Save(const WCHAR *filename, const CLSID *clsidEncoder, const EncoderParameters *encoderParams)
282     {
283         return SetStatus(DllExports::GdipSaveImageToFile(nativeImage, filename, clsidEncoder, encoderParams));
284     }
285 
286     Status
SaveAdd(const EncoderParameters * encoderParams)287     SaveAdd(const EncoderParameters *encoderParams)
288     {
289         return SetStatus(DllExports::GdipSaveAdd(nativeImage, encoderParams));
290     }
291 
292     Status
SaveAdd(Image * newImage,const EncoderParameters * encoderParams)293     SaveAdd(Image *newImage, const EncoderParameters *encoderParams)
294     {
295 #if 1
296         // FIXME: Not available yet
297         return SetStatus(NotImplemented);
298 #else
299         if (!newImage)
300             return SetStatus(InvalidParameter);
301 
302         return SetStatus(DllExports::GdipSaveAddImage(nativeImage, getNat(newImage), encoderParams));
303 #endif
304     }
305 
306     Status
SelectActiveFrame(const GUID * dimensionID,UINT frameIndex)307     SelectActiveFrame(const GUID *dimensionID, UINT frameIndex)
308     {
309         return SetStatus(DllExports::GdipImageSelectActiveFrame(nativeImage, dimensionID, frameIndex));
310     }
311 
312     Status
SetPalette(const ColorPalette * palette)313     SetPalette(const ColorPalette *palette)
314     {
315         return SetStatus(DllExports::GdipSetImagePalette(nativeImage, palette));
316     }
317 
318     Status
SetPropertyItem(const PropertyItem * item)319     SetPropertyItem(const PropertyItem *item)
320     {
321         return SetStatus(DllExports::GdipSetPropertyItem(nativeImage, item));
322     }
323 
324 #if 0
325     ImageLayout
326     GetLayout() const
327     {
328         return SetStatus(NotImplemented);
329     }
330 
331     Status
332     SetLayout(const ImageLayout layout)
333     {
334         return SetStatus(NotImplemented);
335     }
336 #endif
337 
338   protected:
339     GpImage *nativeImage;
340     mutable Status lastStatus;
341 
Image()342     Image()
343     {
344     }
345 
Image(GpImage * image,Status status)346     Image(GpImage *image, Status status) : nativeImage(image), lastStatus(status)
347     {
348     }
349 
350     Status
SetStatus(Status status)351     SetStatus(Status status) const
352     {
353         if (status != Ok)
354             lastStatus = status;
355         return status;
356     }
357 
358     void
SetNativeImage(GpImage * image)359     SetNativeImage(GpImage *image)
360     {
361         nativeImage = image;
362     }
363 
364   private:
365     // Image is not copyable
366     Image(const Image &);
367     Image &
368     operator=(const Image &);
369 
370     // get native
371     friend inline GpImage *&
getNat(const Image * image)372     getNat(const Image *image)
373     {
374         return const_cast<Image *>(image)->nativeImage;
375     }
376 };
377 
378 class Bitmap : public Image
379 {
380     friend class CachedBitmap;
381 
382   public:
383     // Bitmap(IDirectDrawSurface7 *surface)  // <-- FIXME: compiler does not like this
384     // {
385     //   lastStatus = DllExports::GdipCreateBitmapFromDirectDrawSurface(surface, &bitmap);
386     // }
387 
Bitmap(INT width,INT height,Graphics * target)388     Bitmap(INT width, INT height, Graphics *target)
389     {
390         GpBitmap *bitmap = NULL;
391         lastStatus = DllExports::GdipCreateBitmapFromGraphics(width, height, target ? getNat(target) : NULL, &bitmap);
392         SetNativeImage(bitmap);
393     }
394 
Bitmap(const BITMAPINFO * gdiBitmapInfo,VOID * gdiBitmapData)395     Bitmap(const BITMAPINFO *gdiBitmapInfo, VOID *gdiBitmapData)
396     {
397         GpBitmap *bitmap = NULL;
398         lastStatus = DllExports::GdipCreateBitmapFromGdiDib(gdiBitmapInfo, gdiBitmapData, &bitmap);
399         SetNativeImage(bitmap);
400     }
401 
Bitmap(INT width,INT height,PixelFormat format)402     Bitmap(INT width, INT height, PixelFormat format)
403     {
404         GpBitmap *bitmap = NULL;
405         lastStatus = DllExports::GdipCreateBitmapFromScan0(width, height, 0, format, NULL, &bitmap);
406         SetNativeImage(bitmap);
407     }
408 
Bitmap(HBITMAP hbm,HPALETTE hpal)409     Bitmap(HBITMAP hbm, HPALETTE hpal)
410     {
411         GpBitmap *bitmap = NULL;
412         lastStatus = DllExports::GdipCreateBitmapFromHBITMAP(hbm, hpal, &bitmap);
413         SetNativeImage(bitmap);
414     }
415 
Bitmap(INT width,INT height,INT stride,PixelFormat format,BYTE * scan0)416     Bitmap(INT width, INT height, INT stride, PixelFormat format, BYTE *scan0)
417     {
418         GpBitmap *bitmap = NULL;
419         lastStatus = DllExports::GdipCreateBitmapFromScan0(width, height, stride, format, scan0, &bitmap);
420         SetNativeImage(bitmap);
421     }
422 
Bitmap(const WCHAR * filename,BOOL useIcm)423     Bitmap(const WCHAR *filename, BOOL useIcm)
424     {
425         GpBitmap *bitmap = NULL;
426 
427         if (useIcm)
428             lastStatus = DllExports::GdipCreateBitmapFromFileICM(filename, &bitmap);
429         else
430             lastStatus = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);
431 
432         SetNativeImage(bitmap);
433     }
434 
Bitmap(HINSTANCE hInstance,const WCHAR * bitmapName)435     Bitmap(HINSTANCE hInstance, const WCHAR *bitmapName)
436     {
437         GpBitmap *bitmap = NULL;
438         lastStatus = DllExports::GdipCreateBitmapFromResource(hInstance, bitmapName, &bitmap);
439         SetNativeImage(bitmap);
440     }
441 
Bitmap(HICON hicon)442     Bitmap(HICON hicon)
443     {
444         GpBitmap *bitmap = NULL;
445         lastStatus = DllExports::GdipCreateBitmapFromHICON(hicon, &bitmap);
446         SetNativeImage(bitmap);
447     }
448 
Bitmap(IStream * stream,BOOL useIcm)449     Bitmap(IStream *stream, BOOL useIcm)
450     {
451         GpBitmap *bitmap = NULL;
452         if (useIcm)
453             lastStatus = DllExports::GdipCreateBitmapFromStreamICM(stream, &bitmap);
454         else
455             lastStatus = DllExports::GdipCreateBitmapFromStream(stream, &bitmap);
456         SetNativeImage(bitmap);
457     }
458 
459     Bitmap *
Clone(const Rect & rect,PixelFormat format)460     Clone(const Rect &rect, PixelFormat format)
461     {
462         return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
463     }
464 
465     Bitmap *
Clone(const RectF & rect,PixelFormat format)466     Clone(const RectF &rect, PixelFormat format)
467     {
468         return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
469     }
470 
471     Bitmap *
Clone(REAL x,REAL y,REAL width,REAL height,PixelFormat format)472     Clone(REAL x, REAL y, REAL width, REAL height, PixelFormat format)
473     {
474         GpBitmap *bitmap = NULL;
475         lastStatus = DllExports::GdipCloneBitmapArea(x, y, width, height, format, GetNativeBitmap(), &bitmap);
476 
477         if (lastStatus != Ok)
478             return NULL;
479 
480         Bitmap *newBitmap = new Bitmap(bitmap);
481         if (newBitmap == NULL)
482         {
483             DllExports::GdipDisposeImage(bitmap);
484         }
485 
486         return newBitmap;
487     }
488 
489     Bitmap *
Clone(INT x,INT y,INT width,INT height,PixelFormat format)490     Clone(INT x, INT y, INT width, INT height, PixelFormat format)
491     {
492         GpBitmap *bitmap = NULL;
493         lastStatus = DllExports::GdipCloneBitmapAreaI(x, y, width, height, format, GetNativeBitmap(), &bitmap);
494 
495         if (lastStatus != Ok)
496             return NULL;
497 
498         Bitmap *newBitmap = new Bitmap(bitmap);
499         if (newBitmap == NULL)
500         {
501             DllExports::GdipDisposeImage(bitmap);
502         }
503 
504         return newBitmap;
505     }
506 
507     static Bitmap *
FromBITMAPINFO(const BITMAPINFO * gdiBitmapInfo,VOID * gdiBitmapData)508     FromBITMAPINFO(const BITMAPINFO *gdiBitmapInfo, VOID *gdiBitmapData)
509     {
510         return new Bitmap(gdiBitmapInfo, gdiBitmapData);
511     }
512 
513     // static Bitmap *FromDirectDrawSurface7(IDirectDrawSurface7 *surface)  // <-- FIXME: compiler does not like this
514     // {
515     //   return new Bitmap(surface);
516     // }
517 
518     static Bitmap *
FromFile(const WCHAR * filename,BOOL useEmbeddedColorManagement)519     FromFile(const WCHAR *filename, BOOL useEmbeddedColorManagement)
520     {
521         return new Bitmap(filename, useEmbeddedColorManagement);
522     }
523 
524     static Bitmap *
FromHBITMAP(HBITMAP hbm,HPALETTE hpal)525     FromHBITMAP(HBITMAP hbm, HPALETTE hpal)
526     {
527         return new Bitmap(hbm, hpal);
528     }
529 
530     static Bitmap *
FromHICON(HICON hicon)531     FromHICON(HICON hicon)
532     {
533         return new Bitmap(hicon);
534     }
535 
536     static Bitmap *
FromResource(HINSTANCE hInstance,const WCHAR * bitmapName)537     FromResource(HINSTANCE hInstance, const WCHAR *bitmapName)
538     {
539         return new Bitmap(hInstance, bitmapName);
540     }
541 
542     static Bitmap *
FromStream(IStream * stream,BOOL useEmbeddedColorManagement)543     FromStream(IStream *stream, BOOL useEmbeddedColorManagement)
544     {
545         return new Bitmap(stream, useEmbeddedColorManagement);
546     }
547 
548     Status
GetHBITMAP(const Color & colorBackground,HBITMAP * hbmReturn)549     GetHBITMAP(const Color &colorBackground, HBITMAP *hbmReturn)
550     {
551         return SetStatus(
552             DllExports::GdipCreateHBITMAPFromBitmap(GetNativeBitmap(), hbmReturn, colorBackground.GetValue()));
553     }
554 
555     Status
GetHICON(HICON * hicon)556     GetHICON(HICON *hicon)
557     {
558         return SetStatus(DllExports::GdipCreateHICONFromBitmap(GetNativeBitmap(), hicon));
559     }
560 
561     Status
GetPixel(INT x,INT y,Color * color)562     GetPixel(INT x, INT y, Color *color)
563     {
564         ARGB argb;
565         Status s = SetStatus(DllExports::GdipBitmapGetPixel(GetNativeBitmap(), x, y, &argb));
566         if (color)
567             color->SetValue(argb);
568         return s;
569     }
570 
571     Status
LockBits(const Rect * rect,UINT flags,PixelFormat format,BitmapData * lockedBitmapData)572     LockBits(const Rect *rect, UINT flags, PixelFormat format, BitmapData *lockedBitmapData)
573     {
574         return SetStatus(DllExports::GdipBitmapLockBits(GetNativeBitmap(), rect, flags, format, lockedBitmapData));
575     }
576 
577     Status
SetPixel(INT x,INT y,const Color & color)578     SetPixel(INT x, INT y, const Color &color)
579     {
580         return SetStatus(DllExports::GdipBitmapSetPixel(GetNativeBitmap(), x, y, color.GetValue()));
581     }
582 
583     Status
SetResolution(REAL xdpi,REAL ydpi)584     SetResolution(REAL xdpi, REAL ydpi)
585     {
586         return SetStatus(DllExports::GdipBitmapSetResolution(GetNativeBitmap(), xdpi, ydpi));
587     }
588 
589     Status
UnlockBits(BitmapData * lockedBitmapData)590     UnlockBits(BitmapData *lockedBitmapData)
591     {
592         return SetStatus(DllExports::GdipBitmapUnlockBits(GetNativeBitmap(), lockedBitmapData));
593     }
594 
595   protected:
Bitmap()596     Bitmap()
597     {
598     }
599 
Bitmap(GpBitmap * nativeBitmap)600     Bitmap(GpBitmap *nativeBitmap)
601     {
602         lastStatus = Ok;
603         SetNativeImage(nativeBitmap);
604     }
605 
606     GpBitmap *
GetNativeBitmap()607     GetNativeBitmap() const
608     {
609         return static_cast<GpBitmap *>(nativeImage);
610     }
611 };
612 
613 class CachedBitmap : public GdiplusBase
614 {
615   public:
CachedBitmap(Bitmap * bitmap,Graphics * graphics)616     CachedBitmap(Bitmap *bitmap, Graphics *graphics)
617     {
618         nativeCachedBitmap = NULL;
619         lastStatus = DllExports::GdipCreateCachedBitmap(
620             bitmap->GetNativeBitmap(), graphics ? getNat(graphics) : NULL, &nativeCachedBitmap);
621     }
622 
~CachedBitmap()623     ~CachedBitmap()
624     {
625         DllExports::GdipDeleteCachedBitmap(nativeCachedBitmap);
626     }
627 
628     Status
GetLastStatus()629     GetLastStatus()
630     {
631         return lastStatus;
632     }
633 
634   protected:
635     mutable Status lastStatus;
636     GpCachedBitmap *nativeCachedBitmap;
637 
638   private:
639     // CachedBitmap is not copyable
640     CachedBitmap(const CachedBitmap &);
641     CachedBitmap &
642     operator=(const CachedBitmap &);
643 
644     // get native
645     friend inline GpCachedBitmap *&
getNat(const CachedBitmap * cb)646     getNat(const CachedBitmap *cb)
647     {
648         return const_cast<CachedBitmap *>(cb)->nativeCachedBitmap;
649     }
650 };
651 
652 class FontCollection : public GdiplusBase
653 {
654     friend class FontFamily;
655 
656   public:
FontCollection()657     FontCollection() : nativeFontCollection(NULL), lastStatus(Ok)
658     {
659     }
660 
~FontCollection()661     virtual ~FontCollection()
662     {
663     }
664 
665     Status
GetFamilies(INT numSought,FontFamily * gpfamilies,INT * numFound)666     GetFamilies(INT numSought, FontFamily *gpfamilies, INT *numFound) const
667     {
668         return SetStatus(NotImplemented);
669     }
670 
671     INT
GetFamilyCount()672     GetFamilyCount() const
673     {
674         INT numFound = 0;
675         lastStatus = DllExports::GdipGetFontCollectionFamilyCount(nativeFontCollection, &numFound);
676         return numFound;
677     }
678 
679     Status
GetLastStatus()680     GetLastStatus() const
681     {
682         return lastStatus;
683     }
684 
685   protected:
686     GpFontCollection *nativeFontCollection;
687     mutable Status lastStatus;
688 
689     Status
SetStatus(Status status)690     SetStatus(Status status) const
691     {
692         if (status != Ok)
693             lastStatus = status;
694         return status;
695     }
696 
697   private:
698     // FontCollection is not copyable
699     FontCollection(const FontCollection &);
700     FontCollection &
701     operator=(const FontCollection &);
702 
703     // get native
704     friend inline GpFontCollection *&
getNat(const FontCollection * fc)705     getNat(const FontCollection *fc)
706     {
707         return const_cast<FontCollection *>(fc)->nativeFontCollection;
708     }
709 };
710 
711 class FontFamily : public GdiplusBase
712 {
713     friend class Font;
714 
715   public:
FontFamily()716     FontFamily()
717     {
718     }
719 
FontFamily(const WCHAR * name,const FontCollection * fontCollection)720     FontFamily(const WCHAR *name, const FontCollection *fontCollection)
721     {
722         GpFontCollection *theCollection = fontCollection ? getNat(fontCollection) : NULL;
723         status = DllExports::GdipCreateFontFamilyFromName(name, theCollection, &fontFamily);
724     }
725 
726     FontFamily *
Clone()727     Clone()
728     {
729         return NULL;
730     }
731 
732     static const FontFamily *
GenericMonospace()733     GenericMonospace()
734     {
735         FontFamily *genericMonospace = new FontFamily();
736         genericMonospace->status =
737             DllExports::GdipGetGenericFontFamilyMonospace(genericMonospace ? &genericMonospace->fontFamily : NULL);
738         return genericMonospace;
739     }
740 
741     static const FontFamily *
GenericSansSerif()742     GenericSansSerif()
743     {
744         FontFamily *genericSansSerif = new FontFamily();
745         genericSansSerif->status =
746             DllExports::GdipGetGenericFontFamilySansSerif(genericSansSerif ? &genericSansSerif->fontFamily : NULL);
747         return genericSansSerif;
748     }
749 
750     static const FontFamily *
GenericSerif()751     GenericSerif()
752     {
753         FontFamily *genericSerif = new FontFamily();
754         genericSerif->status =
755             DllExports::GdipGetGenericFontFamilyMonospace(genericSerif ? &genericSerif->fontFamily : NULL);
756         return genericSerif;
757     }
758 
759     UINT16
GetCellAscent(INT style)760     GetCellAscent(INT style) const
761     {
762         UINT16 CellAscent;
763         SetStatus(DllExports::GdipGetCellAscent(fontFamily, style, &CellAscent));
764         return CellAscent;
765     }
766 
767     UINT16
GetCellDescent(INT style)768     GetCellDescent(INT style) const
769     {
770         UINT16 CellDescent;
771         SetStatus(DllExports::GdipGetCellDescent(fontFamily, style, &CellDescent));
772         return CellDescent;
773     }
774 
775     UINT16
GetEmHeight(INT style)776     GetEmHeight(INT style)
777     {
778         UINT16 EmHeight;
779         SetStatus(DllExports::GdipGetEmHeight(fontFamily, style, &EmHeight));
780         return EmHeight;
781     }
782 
783     Status
GetFamilyName(WCHAR name[LF_FACESIZE],WCHAR language)784     GetFamilyName(WCHAR name[LF_FACESIZE], WCHAR language) const
785     {
786         return SetStatus(DllExports::GdipGetFamilyName(fontFamily, name, language));
787     }
788 
789     Status
GetLastStatus()790     GetLastStatus() const
791     {
792         return status;
793     }
794 
795     UINT16
GetLineSpacing(INT style)796     GetLineSpacing(INT style) const
797     {
798         UINT16 LineSpacing;
799         SetStatus(DllExports::GdipGetLineSpacing(fontFamily, style, &LineSpacing));
800         return LineSpacing;
801     }
802 
803     BOOL
IsAvailable()804     IsAvailable() const
805     {
806         return FALSE;
807     }
808 
809     BOOL
IsStyleAvailable(INT style)810     IsStyleAvailable(INT style) const
811     {
812         BOOL StyleAvailable;
813         SetStatus(DllExports::GdipIsStyleAvailable(fontFamily, style, &StyleAvailable));
814         return StyleAvailable;
815     }
816 
817   private:
818     mutable Status status;
819     GpFontFamily *fontFamily;
820 
821     Status
SetStatus(Status status)822     SetStatus(Status status) const
823     {
824         if (status == Ok)
825             return status;
826         this->status = status;
827         return status;
828     }
829 
830     // get native
831     friend inline GpFontFamily *&
getNat(const FontFamily * ff)832     getNat(const FontFamily *ff)
833     {
834         return const_cast<FontFamily *>(ff)->fontFamily;
835     }
836 };
837 
838 class InstalledFontFamily : public FontFamily
839 {
840   public:
InstalledFontFamily()841     InstalledFontFamily()
842     {
843     }
844 };
845 
846 class PrivateFontCollection : public FontCollection
847 {
848   public:
PrivateFontCollection()849     PrivateFontCollection()
850     {
851         nativeFontCollection = NULL;
852         lastStatus = DllExports::GdipNewPrivateFontCollection(&nativeFontCollection);
853     }
854 
~PrivateFontCollection()855     virtual ~PrivateFontCollection()
856     {
857         DllExports::GdipDeletePrivateFontCollection(&nativeFontCollection);
858     }
859 
860     Status
AddFontFile(const WCHAR * filename)861     AddFontFile(const WCHAR *filename)
862     {
863         return SetStatus(DllExports::GdipPrivateAddFontFile(nativeFontCollection, filename));
864     }
865 
866     Status
AddMemoryFont(const VOID * memory,INT length)867     AddMemoryFont(const VOID *memory, INT length)
868     {
869         return SetStatus(DllExports::GdipPrivateAddMemoryFont(nativeFontCollection, memory, length));
870     }
871 };
872 
873 class Font : public GdiplusBase
874 {
875   public:
876     friend class FontFamily;
877     friend class FontCollection;
878     friend class Graphics;
879 
Font(const FontFamily * family,REAL emSize,INT style,Unit unit)880     Font(const FontFamily *family, REAL emSize, INT style, Unit unit)
881     {
882         status = DllExports::GdipCreateFont(family->fontFamily, emSize, style, unit, &font);
883     }
884 
Font(HDC hdc,const HFONT hfont)885     Font(HDC hdc, const HFONT hfont)
886     {
887     }
888 
Font(HDC hdc,const LOGFONTA * logfont)889     Font(HDC hdc, const LOGFONTA *logfont)
890     {
891         status = DllExports::GdipCreateFontFromLogfontA(hdc, logfont, &font);
892     }
893 
Font(HDC hdc,const LOGFONTW * logfont)894     Font(HDC hdc, const LOGFONTW *logfont)
895     {
896         status = DllExports::GdipCreateFontFromLogfontW(hdc, logfont, &font);
897     }
898 
Font(const WCHAR * familyName,REAL emSize,INT style,Unit unit,const FontCollection * fontCollection)899     Font(const WCHAR *familyName, REAL emSize, INT style, Unit unit, const FontCollection *fontCollection)
900     {
901     }
902 
Font(HDC hdc)903     Font(HDC hdc)
904     {
905         status = DllExports::GdipCreateFontFromDC(hdc, &font);
906     }
907 
908     Font *
Clone()909     Clone() const
910     {
911         Font *cloneFont = new Font();
912         cloneFont->status = DllExports::GdipCloneFont(font, cloneFont ? &cloneFont->font : NULL);
913         return cloneFont;
914     }
915 
916     Status
GetFamily(FontFamily * family)917     GetFamily(FontFamily *family) const
918     {
919         return SetStatus(DllExports::GdipGetFamily(font, family ? &family->fontFamily : NULL));
920     }
921 
922     REAL
GetHeight(const Graphics * graphics)923     GetHeight(const Graphics *graphics) const
924     {
925         REAL height;
926         SetStatus(DllExports::GdipGetFontHeight(font, graphics ? getNat(graphics) : NULL, &height));
927         return height;
928     }
929 
930     REAL
GetHeight(REAL dpi)931     GetHeight(REAL dpi) const
932     {
933         REAL height;
934         SetStatus(DllExports::GdipGetFontHeightGivenDPI(font, dpi, &height));
935         return height;
936     }
937 
938     Status
GetLastStatus()939     GetLastStatus() const
940     {
941         return status;
942     }
943 
944     Status
GetLogFontA(const Graphics * g,LOGFONTA * logfontA)945     GetLogFontA(const Graphics *g, LOGFONTA *logfontA) const
946     {
947         return SetStatus(DllExports::GdipGetLogFontA(font, g ? getNat(g) : NULL, logfontA));
948     }
949 
950     Status
GetLogFontW(const Graphics * g,LOGFONTW * logfontW)951     GetLogFontW(const Graphics *g, LOGFONTW *logfontW) const
952     {
953         return SetStatus(DllExports::GdipGetLogFontW(font, g ? getNat(g) : NULL, logfontW));
954     }
955 
956     REAL
GetSize()957     GetSize() const
958     {
959         REAL size;
960         SetStatus(DllExports::GdipGetFontSize(font, &size));
961         return size;
962     }
963 
964     INT
GetStyle()965     GetStyle() const
966     {
967         INT style;
968         SetStatus(DllExports::GdipGetFontStyle(font, &style));
969         return style;
970     }
971 
972     Unit
GetUnit()973     GetUnit() const
974     {
975         Unit unit;
976         SetStatus(DllExports::GdipGetFontUnit(font, &unit));
977         return unit;
978     }
979 
980     BOOL
IsAvailable()981     IsAvailable() const
982     {
983         return FALSE;
984     }
985 
986   protected:
Font()987     Font()
988     {
989     }
990 
991   private:
992     mutable Status status;
993     GpFont *font;
994 
995     Status
SetStatus(Status status)996     SetStatus(Status status) const
997     {
998         if (status == Ok)
999             return status;
1000         this->status = status;
1001         return status;
1002     }
1003 
1004     // get native
1005     friend inline GpFont *&
getNat(const Font * font)1006     getNat(const Font *font)
1007     {
1008         return const_cast<Font *>(font)->font;
1009     }
1010 };
1011 
1012 class Region : public GdiplusBase
1013 {
1014   public:
1015     friend class Graphics;
1016     friend class GraphicsPath;
1017     friend class Matrix;
1018 
Region(const Rect & rect)1019     Region(const Rect &rect)
1020     {
1021         lastStatus = DllExports::GdipCreateRegionRectI(&rect, &nativeRegion);
1022     }
1023 
Region()1024     Region()
1025     {
1026         lastStatus = DllExports::GdipCreateRegion(&nativeRegion);
1027     }
1028 
Region(const BYTE * regionData,INT size)1029     Region(const BYTE *regionData, INT size)
1030     {
1031         lastStatus = DllExports::GdipCreateRegionRgnData(regionData, size, &nativeRegion);
1032     }
1033 
Region(const GraphicsPath * path)1034     Region(const GraphicsPath *path)
1035     {
1036         lastStatus = DllExports::GdipCreateRegionPath(getNat(path), &nativeRegion);
1037     }
1038 
Region(HRGN hRgn)1039     Region(HRGN hRgn)
1040     {
1041         lastStatus = DllExports::GdipCreateRegionHrgn(hRgn, &nativeRegion);
1042     }
1043 
Region(const RectF & rect)1044     Region(const RectF &rect)
1045     {
1046         lastStatus = DllExports::GdipCreateRegionRect(&rect, &nativeRegion);
1047     }
1048 
1049     Region *
Clone()1050     Clone()
1051     {
1052         Region *cloneRegion = new Region();
1053         cloneRegion->lastStatus =
1054             DllExports::GdipCloneRegion(nativeRegion, cloneRegion ? &cloneRegion->nativeRegion : NULL);
1055         return cloneRegion;
1056     }
1057 
1058     Status
Complement(const GraphicsPath * path)1059     Complement(const GraphicsPath *path)
1060     {
1061         GpPath *thePath = path ? getNat(path) : NULL;
1062         return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, thePath, CombineModeComplement));
1063     }
1064 
1065     Status
Complement(const Region * region)1066     Complement(const Region *region)
1067     {
1068         GpRegion *theRegion = region ? getNat(region) : NULL;
1069         return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion, theRegion, CombineModeComplement));
1070     }
1071 
1072     Status
Complement(const Rect & rect)1073     Complement(const Rect &rect)
1074     {
1075         return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeComplement));
1076     }
1077 
1078     Status
Complement(const RectF & rect)1079     Complement(const RectF &rect)
1080     {
1081         return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeComplement));
1082     }
1083 
1084     BOOL
Equals(const Region * region,const Graphics * g)1085     Equals(const Region *region, const Graphics *g) const
1086     {
1087         BOOL result;
1088         SetStatus(
1089             DllExports::GdipIsEqualRegion(nativeRegion, region ? getNat(region) : NULL, g ? getNat(g) : NULL, &result));
1090         return result;
1091     }
1092 
1093     Status
Exclude(const GraphicsPath * path)1094     Exclude(const GraphicsPath *path)
1095     {
1096         return SetStatus(
1097             DllExports::GdipCombineRegionPath(nativeRegion, path ? getNat(path) : NULL, CombineModeExclude));
1098     }
1099 
1100     Status
Exclude(const RectF & rect)1101     Exclude(const RectF &rect)
1102     {
1103         return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeExclude));
1104     }
1105 
1106     Status
Exclude(const Rect & rect)1107     Exclude(const Rect &rect)
1108     {
1109         return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeExclude));
1110     }
1111 
1112     Status
Exclude(const Region * region)1113     Exclude(const Region *region)
1114     {
1115         return SetStatus(
1116             DllExports::GdipCombineRegionRegion(nativeRegion, region ? getNat(region) : NULL, CombineModeExclude));
1117     }
1118 
1119     static Region *
FromHRGN(HRGN hRgn)1120     FromHRGN(HRGN hRgn)
1121     {
1122         return new Region(hRgn);
1123     }
1124 
1125     Status
GetBounds(Rect * rect,const Graphics * g)1126     GetBounds(Rect *rect, const Graphics *g) const
1127     {
1128         return SetStatus(DllExports::GdipGetRegionBoundsI(nativeRegion, g ? getNat(g) : NULL, rect));
1129     }
1130 
1131     Status
GetBounds(RectF * rect,const Graphics * g)1132     GetBounds(RectF *rect, const Graphics *g) const
1133     {
1134         return SetStatus(DllExports::GdipGetRegionBounds(nativeRegion, g ? getNat(g) : NULL, rect));
1135     }
1136 
1137     Status
GetData(BYTE * buffer,UINT bufferSize,UINT * sizeFilled)1138     GetData(BYTE *buffer, UINT bufferSize, UINT *sizeFilled) const
1139     {
1140         return SetStatus(DllExports::GdipGetRegionData(nativeRegion, buffer, bufferSize, sizeFilled));
1141     }
1142 
1143     UINT
GetDataSize()1144     GetDataSize() const
1145     {
1146         UINT bufferSize;
1147         SetStatus(DllExports::GdipGetRegionDataSize(nativeRegion, &bufferSize));
1148         return bufferSize;
1149     }
1150 
1151     HRGN
GetHRGN(const Graphics * g)1152     GetHRGN(const Graphics *g) const
1153     {
1154         HRGN hRgn;
1155         SetStatus(DllExports::GdipGetRegionHRgn(nativeRegion, g ? getNat(g) : NULL, &hRgn));
1156         return hRgn;
1157     }
1158 
1159     Status
GetLastStatus()1160     GetLastStatus()
1161     {
1162         return lastStatus;
1163     }
1164 
1165     Status
GetRegionScans(const Matrix * matrix,Rect * rects,INT * count)1166     GetRegionScans(const Matrix *matrix, Rect *rects, INT *count) const
1167     {
1168         return SetStatus(DllExports::GdipGetRegionScansI(nativeRegion, rects, count, matrix ? getNat(matrix) : NULL));
1169     }
1170 
1171     Status
GetRegionScans(const Matrix * matrix,RectF * rects,INT * count)1172     GetRegionScans(const Matrix *matrix, RectF *rects, INT *count) const
1173     {
1174         return SetStatus(DllExports::GdipGetRegionScans(nativeRegion, rects, count, matrix ? getNat(matrix) : NULL));
1175     }
1176 
1177     UINT
GetRegionScansCount(const Matrix * matrix)1178     GetRegionScansCount(const Matrix *matrix) const
1179     {
1180         UINT count;
1181         SetStatus(DllExports::GdipGetRegionScansCount(nativeRegion, &count, matrix ? getNat(matrix) : NULL));
1182         return count;
1183     }
1184 
1185     Status
Intersect(const Rect & rect)1186     Intersect(const Rect &rect)
1187     {
1188         return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeIntersect));
1189     }
1190 
1191     Status
Intersect(const GraphicsPath * path)1192     Intersect(const GraphicsPath *path)
1193     {
1194         GpPath *thePath = path ? getNat(path) : NULL;
1195         return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, thePath, CombineModeIntersect));
1196     }
1197 
1198     Status
Intersect(const RectF & rect)1199     Intersect(const RectF &rect)
1200     {
1201         return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeIntersect));
1202     }
1203 
1204     Status
Intersect(const Region * region)1205     Intersect(const Region *region)
1206     {
1207         return SetStatus(
1208             DllExports::GdipCombineRegionRegion(nativeRegion, region ? getNat(region) : NULL, CombineModeIntersect));
1209     }
1210 
1211     BOOL
IsEmpty(const Graphics * g)1212     IsEmpty(const Graphics *g) const
1213     {
1214         BOOL result;
1215         SetStatus(DllExports::GdipIsEmptyRegion(nativeRegion, g ? getNat(g) : NULL, &result));
1216         return result;
1217     }
1218 
1219     BOOL
IsInfinite(const Graphics * g)1220     IsInfinite(const Graphics *g) const
1221     {
1222         BOOL result;
1223         SetStatus(DllExports::GdipIsInfiniteRegion(nativeRegion, g ? getNat(g) : NULL, &result));
1224         return result;
1225     }
1226 
1227     BOOL
IsVisible(const PointF & point,const Graphics * g)1228     IsVisible(const PointF &point, const Graphics *g) const
1229     {
1230         BOOL result;
1231         SetStatus(DllExports::GdipIsVisibleRegionPoint(nativeRegion, point.X, point.Y, g ? getNat(g) : NULL, &result));
1232         return result;
1233     }
1234 
1235     BOOL
IsVisible(const RectF & rect,const Graphics * g)1236     IsVisible(const RectF &rect, const Graphics *g) const
1237     {
1238         BOOL result;
1239         SetStatus(DllExports::GdipIsVisibleRegionRect(
1240             nativeRegion, rect.X, rect.Y, rect.Width, rect.Height, g ? getNat(g) : NULL, &result));
1241         return result;
1242     }
1243 
1244     BOOL
IsVisible(const Rect & rect,const Graphics * g)1245     IsVisible(const Rect &rect, const Graphics *g) const
1246     {
1247         BOOL result;
1248         SetStatus(DllExports::GdipIsVisibleRegionRectI(
1249             nativeRegion, rect.X, rect.Y, rect.Width, rect.Height, g ? getNat(g) : NULL, &result));
1250         return result;
1251     }
1252 
1253     BOOL
IsVisible(INT x,INT y,const Graphics * g)1254     IsVisible(INT x, INT y, const Graphics *g) const
1255     {
1256         BOOL result;
1257         SetStatus(DllExports::GdipIsVisibleRegionPointI(nativeRegion, x, y, g ? getNat(g) : NULL, &result));
1258         return result;
1259     }
1260 
1261     BOOL
IsVisible(REAL x,REAL y,const Graphics * g)1262     IsVisible(REAL x, REAL y, const Graphics *g) const
1263     {
1264         BOOL result;
1265         SetStatus(DllExports::GdipIsVisibleRegionPoint(nativeRegion, x, y, g ? getNat(g) : NULL, &result));
1266         return result;
1267     }
1268 
1269     BOOL
IsVisible(INT x,INT y,INT width,INT height,const Graphics * g)1270     IsVisible(INT x, INT y, INT width, INT height, const Graphics *g) const
1271     {
1272         BOOL result;
1273         SetStatus(
1274             DllExports::GdipIsVisibleRegionRectI(nativeRegion, x, y, width, height, g ? getNat(g) : NULL, &result));
1275         return result;
1276     }
1277 
1278     BOOL
IsVisible(const Point & point,const Graphics * g)1279     IsVisible(const Point &point, const Graphics *g) const
1280     {
1281         BOOL result;
1282         SetStatus(DllExports::GdipIsVisibleRegionPointI(nativeRegion, point.X, point.Y, g ? getNat(g) : NULL, &result));
1283         return result;
1284     }
1285 
1286     BOOL
IsVisible(REAL x,REAL y,REAL width,REAL height,const Graphics * g)1287     IsVisible(REAL x, REAL y, REAL width, REAL height, const Graphics *g) const
1288     {
1289         BOOL result;
1290         SetStatus(
1291             DllExports::GdipIsVisibleRegionRect(nativeRegion, x, y, width, height, g ? getNat(g) : NULL, &result));
1292         return result;
1293     }
1294 
1295     Status
MakeEmpty()1296     MakeEmpty()
1297     {
1298         return SetStatus(DllExports::GdipSetEmpty(nativeRegion));
1299     }
1300 
1301     Status
MakeInfinite()1302     MakeInfinite()
1303     {
1304         return SetStatus(DllExports::GdipSetInfinite(nativeRegion));
1305     }
1306 
1307     Status
Transform(const Matrix * matrix)1308     Transform(const Matrix *matrix)
1309     {
1310         return SetStatus(DllExports::GdipTransformRegion(nativeRegion, matrix ? getNat(matrix) : NULL));
1311     }
1312 
1313     Status
Translate(REAL dx,REAL dy)1314     Translate(REAL dx, REAL dy)
1315     {
1316         return SetStatus(DllExports::GdipTranslateRegion(nativeRegion, dx, dy));
1317     }
1318 
1319     Status
Translate(INT dx,INT dy)1320     Translate(INT dx, INT dy)
1321     {
1322         return SetStatus(DllExports::GdipTranslateRegionI(nativeRegion, dx, dy));
1323     }
1324 
1325     Status
Union(const Rect & rect)1326     Union(const Rect &rect)
1327     {
1328         return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeUnion));
1329     }
1330 
1331     Status
Union(const Region * region)1332     Union(const Region *region)
1333     {
1334         return SetStatus(
1335             DllExports::GdipCombineRegionRegion(nativeRegion, region ? getNat(region) : NULL, CombineModeUnion));
1336     }
1337 
1338     Status
Union(const RectF & rect)1339     Union(const RectF &rect)
1340     {
1341         return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeUnion));
1342     }
1343 
1344     Status
Union(const GraphicsPath * path)1345     Union(const GraphicsPath *path)
1346     {
1347         return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path ? getNat(path) : NULL, CombineModeUnion));
1348     }
1349 
1350     Status
Xor(const GraphicsPath * path)1351     Xor(const GraphicsPath *path)
1352     {
1353         return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path ? getNat(path) : NULL, CombineModeXor));
1354     }
1355 
1356     Status
Xor(const RectF & rect)1357     Xor(const RectF &rect)
1358     {
1359         return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeXor));
1360     }
1361 
1362     Status
Xor(const Rect & rect)1363     Xor(const Rect &rect)
1364     {
1365         return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeXor));
1366     }
1367 
1368     Status
Xor(const Region * region)1369     Xor(const Region *region)
1370     {
1371         return SetStatus(
1372             DllExports::GdipCombineRegionRegion(nativeRegion, region ? getNat(region) : NULL, CombineModeXor));
1373     }
1374 
1375   private:
1376     GpRegion *nativeRegion;
1377     mutable Status lastStatus;
1378 
1379     Status
SetStatus(Status status)1380     SetStatus(Status status) const
1381     {
1382         if (status != Ok)
1383             lastStatus = status;
1384         return status;
1385     }
1386 
1387     // get native
1388     friend inline GpRegion *&
getNat(const Region * region)1389     getNat(const Region *region)
1390     {
1391         return const_cast<Region *>(region)->nativeRegion;
1392     }
1393 };
1394 
1395 class CustomLineCap : public GdiplusBase
1396 {
1397   public:
1398     CustomLineCap(const GraphicsPath *fillPath, const GraphicsPath *strokePath, LineCap baseCap, REAL baseInset = 0);
1399 
1400     ~CustomLineCap();
1401 
1402     CustomLineCap *
1403     Clone();
1404 
1405     LineCap
1406     GetBaseCap();
1407 
1408     REAL
1409     GetBaseInset();
1410 
1411     Status
1412     GetLastStatus();
1413 
1414     Status
1415     GetStrokeCaps(LineCap *startCap, LineCap *endCap);
1416 
1417     LineJoin
1418     GetStrokeJoin();
1419 
1420     REAL
1421     GetWidthScale();
1422 
1423     Status
1424     SetBaseCap(LineCap baseCap);
1425 
1426     Status
1427     SetBaseInset(REAL inset);
1428 
1429     Status
1430     SetStrokeCap(LineCap strokeCap);
1431 
1432     Status
1433     SetStrokeCaps(LineCap startCap, LineCap endCap);
1434 
1435     Status
1436     SetStrokeJoin(LineJoin lineJoin);
1437 
1438     Status
1439     SetWidthScale(IN REAL widthScale);
1440 
1441   protected:
1442     GpCustomLineCap *nativeCap;
1443     mutable Status lastStatus;
1444 
CustomLineCap()1445     CustomLineCap() : nativeCap(NULL), lastStatus(Ok)
1446     {
1447     }
1448 
CustomLineCap(GpCustomLineCap * cap,Status status)1449     CustomLineCap(GpCustomLineCap *cap, Status status) : nativeCap(cap), lastStatus(status)
1450     {
1451     }
1452 
1453     void
SetNativeCap(GpCustomLineCap * cap)1454     SetNativeCap(GpCustomLineCap *cap)
1455     {
1456         nativeCap = cap;
1457     }
1458 
1459     Status
SetStatus(Status status)1460     SetStatus(Status status) const
1461     {
1462         if (status == Ok)
1463             lastStatus = status;
1464         return status;
1465     }
1466 
1467   private:
1468     // CustomLineCap is not copyable
1469     CustomLineCap(const CustomLineCap &);
1470     CustomLineCap &
1471     operator=(const CustomLineCap &);
1472 
1473     // get native
1474     friend inline GpCustomLineCap *&
getNat(const CustomLineCap * cap)1475     getNat(const CustomLineCap *cap)
1476     {
1477         return const_cast<CustomLineCap *>(cap)->nativeCap;
1478     }
1479 };
1480 
1481 inline Image *
GetImage()1482 TextureBrush::GetImage() const
1483 {
1484     GpImage *image = NULL;
1485     GpTexture *texture = GetNativeTexture();
1486     SetStatus(DllExports::GdipGetTextureImage(texture, &image));
1487     if (lastStatus != Ok)
1488         return NULL;
1489 
1490     Image *newImage = new Image(image, lastStatus);
1491     if (!newImage)
1492         DllExports::GdipDisposeImage(image);
1493     return newImage;
1494 }
1495 
1496 #endif /* _GDIPLUSHEADERS_H */
1497