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