1 /**
2  * @file gdiplusimpl.h
3  * Copyright 2012, 2013 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 /* Created by Markus Koenig <markus@stber-koenig.de> */
25 #ifndef __GDIPLUS_IMPL_H
26 #define __GDIPLUS_IMPL_H
27 #pragma GCC system_header
28 #include <_mingw.h>
29 
30 /*
31  * GDI+ Bitmap, CachedBitmap, CustomLineCap, Font, FontCollection, FontFamily,
32  *      Image, InstalledFontCollection, PrivateFontCollection, Region
33  *      implementation.  Definitions of these classes are in gdiplusheaders.h.
34  */
35 
36 #ifndef __cplusplus
37 #error "A C++ compiler is required to include gdiplusimpl.h."
38 #endif
39 
40 /*
41  * FIXME: I called this file gdiplusimpl.h, but what should it really be called?
42  * Or did Microsoft create separate files for each class implemented here?
43  */
44 
45 
46 // Image
47 
FromFile(const WCHAR * filename,BOOL useEmbeddedColorManagement)48 __inline__ Image* Image::FromFile(const WCHAR *filename,
49 		BOOL useEmbeddedColorManagement)
50 {
51 	return new Image(filename, useEmbeddedColorManagement);
52 }
53 
FromStream(IStream * stream,BOOL useEmbeddedColorManagement)54 __inline__ Image* Image::FromStream(IStream *stream,
55 		BOOL useEmbeddedColorManagement)
56 {
57 	return new Image(stream, useEmbeddedColorManagement);
58 }
59 
Image(const WCHAR * filename,BOOL useEmbeddedColorManagement)60 __inline__ Image::Image(const WCHAR *filename, BOOL useEmbeddedColorManagement):
61 	nativeImage(NULL), lastStatus(Ok)
62 {
63 	if (useEmbeddedColorManagement) {
64 		lastStatus = DllExports::GdipLoadImageFromFileICM(
65 				filename, &nativeImage);
66 	} else {
67 		lastStatus = DllExports::GdipLoadImageFromFile(
68 				filename, &nativeImage);
69 	}
70 }
71 
Image(IStream * stream,BOOL useEmbeddedColorManagement)72 __inline__ Image::Image(IStream *stream, BOOL useEmbeddedColorManagement):
73 	nativeImage(NULL), lastStatus(Ok)
74 {
75 	if (useEmbeddedColorManagement) {
76 		lastStatus = DllExports::GdipLoadImageFromStreamICM(
77 				stream, &nativeImage);
78 	} else {
79 		lastStatus = DllExports::GdipLoadImageFromStream(
80 				stream, &nativeImage);
81 	}
82 }
83 
FindFirstItem(ImageItemData * item)84 __inline__ Status Image::FindFirstItem(ImageItemData *item)
85 {
86 	// FIXME: can't test GdipFindFirstImageItem b/c it isn't exported in 1.0
87 	return updateStatus(DllExports::GdipFindFirstImageItem(
88 			nativeImage, item));
89 }
90 
FindNextItem(ImageItemData * item)91 __inline__ Status Image::FindNextItem(ImageItemData *item)
92 {
93 	// FIXME: can't test GdipFindFirstImageItem b/c it isn't exported in 1.0
94 	return updateStatus(DllExports::GdipFindNextImageItem(
95 			nativeImage, item));
96 }
97 
GetAllPropertyItems(UINT totalBufferSize,UINT numProperties,PropertyItem * allItems)98 __inline__ Status Image::GetAllPropertyItems(UINT totalBufferSize,
99 		UINT numProperties, PropertyItem *allItems)
100 {
101 	return updateStatus(DllExports::GdipGetAllPropertyItems(
102 			nativeImage, totalBufferSize, numProperties, allItems));
103 }
104 
GetBounds(RectF * srcRect,Unit * srcUnit)105 __inline__ Status Image::GetBounds(RectF *srcRect, Unit *srcUnit)
106 {
107 	return updateStatus(DllExports::GdipGetImageBounds(
108 			nativeImage, srcRect, srcUnit));
109 }
110 
GetEncoderParameterList(const CLSID * clsidEncoder,UINT size,EncoderParameters * buffer)111 __inline__ Status Image::GetEncoderParameterList(const CLSID *clsidEncoder,
112 		UINT size, EncoderParameters *buffer)
113 {
114 	return updateStatus(DllExports::GdipGetEncoderParameterList(
115 			nativeImage, clsidEncoder, size, buffer));
116 }
117 
GetEncoderParameterListSize(const CLSID * clsidEncoder)118 __inline__ UINT Image::GetEncoderParameterListSize(const CLSID *clsidEncoder)
119 {
120 	UINT result = 0;
121 	updateStatus(DllExports::GdipGetEncoderParameterListSize(
122 			nativeImage, clsidEncoder, &result));
123 	return result;
124 }
125 
GetFlags()126 __inline__ UINT Image::GetFlags()
127 {
128 	UINT result = 0;
129 	updateStatus(DllExports::GdipGetImageFlags(nativeImage, &result));
130 	return result;
131 }
132 
GetFrameCount(const GUID * dimensionID)133 __inline__ UINT Image::GetFrameCount(const GUID *dimensionID)
134 {
135 	UINT result = 0;
136 	updateStatus(DllExports::GdipImageGetFrameCount(
137 			nativeImage, dimensionID, &result));
138 	return result;
139 }
140 
GetFrameDimensionsCount()141 __inline__ UINT Image::GetFrameDimensionsCount()
142 {
143 	UINT result = 0;
144 	updateStatus(DllExports::GdipImageGetFrameDimensionsCount(
145 			nativeImage, &result));
146 	return result;
147 }
148 
GetFrameDimensionsList(GUID * dimensionIDs,UINT count)149 __inline__ Status Image::GetFrameDimensionsList(GUID *dimensionIDs, UINT count)
150 {
151 	return updateStatus(DllExports::GdipImageGetFrameDimensionsList(
152 			nativeImage, dimensionIDs, count));
153 }
154 
GetHeight()155 __inline__ UINT Image::GetHeight()
156 {
157 	UINT result = 0;
158 	updateStatus(DllExports::GdipGetImageHeight(nativeImage, &result));
159 	return result;
160 }
161 
GetHorizontalResolution()162 __inline__ REAL Image::GetHorizontalResolution()
163 {
164 	REAL result = 0.0f;
165 	updateStatus(DllExports::GdipGetImageHorizontalResolution(
166 			nativeImage, &result));
167 	return result;
168 }
169 
GetItemData(ImageItemData * item)170 __inline__ Status Image::GetItemData(ImageItemData *item)
171 {
172 	// FIXME: can't test GdipGetImageItemData b/c it isn't exported in 1.0
173 	return updateStatus(DllExports::GdipGetImageItemData(
174 			nativeImage, item));
175 }
176 
GetPalette(ColorPalette * palette,INT size)177 __inline__ Status Image::GetPalette(ColorPalette *palette, INT size)
178 {
179 	return updateStatus(DllExports::GdipGetImagePalette(
180 			nativeImage, palette, size));
181 }
182 
GetPaletteSize()183 __inline__ INT Image::GetPaletteSize()
184 {
185 	INT result = 0;
186 	updateStatus(DllExports::GdipGetImagePaletteSize(nativeImage, &result));
187 	return result;
188 }
189 
GetPhysicalDimension(SizeF * size)190 __inline__ Status Image::GetPhysicalDimension(SizeF *size)
191 {
192 	if (!size) return lastStatus = InvalidParameter;
193 	return updateStatus(DllExports::GdipGetImageDimension(
194 			nativeImage, &size->Width, &size->Height));
195 }
196 
GetPixelFormat()197 __inline__ PixelFormat Image::GetPixelFormat()
198 {
199 	PixelFormat result = (PixelFormat) 0;
200 	updateStatus(DllExports::GdipGetImagePixelFormat(nativeImage, &result));
201 	return result;
202 }
203 
GetPropertyCount()204 __inline__ UINT Image::GetPropertyCount()
205 {
206 	UINT result = 0;
207 	updateStatus(DllExports::GdipGetPropertyCount(nativeImage, &result));
208 	return result;
209 }
210 
GetPropertyIdList(UINT numOfProperty,PROPID * list)211 __inline__ Status Image::GetPropertyIdList(UINT numOfProperty, PROPID *list)
212 {
213 	return updateStatus(DllExports::GdipGetPropertyIdList(
214 			nativeImage, numOfProperty, list));
215 }
216 
GetPropertyItem(PROPID propId,UINT propSize,PropertyItem * buffer)217 __inline__ Status Image::GetPropertyItem(PROPID propId, UINT propSize,
218 		PropertyItem *buffer)
219 {
220 	return updateStatus(DllExports::GdipGetPropertyItem(
221 			nativeImage, propId, propSize, buffer));
222 }
223 
GetPropertyItemSize(PROPID propId)224 __inline__ UINT Image::GetPropertyItemSize(PROPID propId)
225 {
226 	UINT result = 0;
227 	updateStatus(DllExports::GdipGetPropertyItemSize(
228 			nativeImage, propId, &result));
229 	return result;
230 }
231 
GetPropertySize(UINT * totalBufferSize,UINT * numProperties)232 __inline__ Status Image::GetPropertySize(
233 		UINT *totalBufferSize, UINT *numProperties)
234 {
235 	return updateStatus(DllExports::GdipGetPropertySize(
236 			nativeImage, totalBufferSize, numProperties));
237 }
238 
GetRawFormat(GUID * format)239 __inline__ Status Image::GetRawFormat(GUID *format)
240 {
241 	return updateStatus(DllExports::GdipGetImageRawFormat(
242 			nativeImage, format));
243 }
244 
GetThumbnailImage(UINT thumbWidth,UINT thumbHeight,GetThumbnailImageAbort callback,VOID * callbackData)245 __inline__ Image* Image::GetThumbnailImage(UINT thumbWidth, UINT thumbHeight,
246 		GetThumbnailImageAbort callback, VOID *callbackData)
247 {
248 	GpImage *thumbImage = NULL;
249 	Status status = updateStatus(DllExports::GdipGetImageThumbnail(
250 			nativeImage, thumbWidth, thumbHeight, &thumbImage,
251 			callback, callbackData));
252 
253 	if (status == Ok) {
254 		Image *result = new Image(thumbImage, Ok);
255 		if (!result) {
256 			DllExports::GdipDisposeImage(thumbImage);
257 			lastStatus = OutOfMemory;
258 		}
259 		return result;
260 	} else {
261 		return NULL;
262 	}
263 }
264 
GetType()265 __inline__ ImageType Image::GetType() const
266 {
267 	ImageType result = ImageTypeUnknown;
268 	updateStatus(DllExports::GdipGetImageType(nativeImage, &result));
269 	return result;
270 }
271 
GetVerticalResolution()272 __inline__ REAL Image::GetVerticalResolution()
273 {
274 	REAL result = 0.0f;
275 	updateStatus(DllExports::GdipGetImageVerticalResolution(
276 			nativeImage, &result));
277 	return result;
278 }
279 
GetWidth()280 __inline__ UINT Image::GetWidth()
281 {
282 	UINT result = 0;
283 	updateStatus(DllExports::GdipGetImageWidth(nativeImage, &result));
284 	return result;
285 }
286 
RemovePropertyItem(PROPID propId)287 __inline__ Status Image::RemovePropertyItem(PROPID propId)
288 {
289 	return updateStatus(DllExports::GdipRemovePropertyItem(
290 			nativeImage, propId));
291 }
292 
RotateFlip(RotateFlipType rotateFlipType)293 __inline__ Status Image::RotateFlip(RotateFlipType rotateFlipType)
294 {
295 	return updateStatus(DllExports::GdipImageRotateFlip(
296 			nativeImage, rotateFlipType));
297 }
298 
Save(const WCHAR * filename,const CLSID * clsidEncoder,const EncoderParameters * encoderParams)299 __inline__ Status Image::Save(const WCHAR *filename, const CLSID *clsidEncoder,
300 		const EncoderParameters *encoderParams)
301 {
302 	return updateStatus(DllExports::GdipSaveImageToFile(
303 			nativeImage, filename, clsidEncoder, encoderParams));
304 }
305 
Save(IStream * stream,const CLSID * clsidEncoder,const EncoderParameters * encoderParams)306 __inline__ Status Image::Save(IStream *stream, const CLSID *clsidEncoder,
307 		const EncoderParameters *encoderParams)
308 {
309 	return updateStatus(DllExports::GdipSaveImageToStream(
310 			nativeImage, stream, clsidEncoder, encoderParams));
311 }
312 
SaveAdd(const EncoderParameters * encoderParams)313 __inline__ Status Image::SaveAdd(const EncoderParameters *encoderParams)
314 {
315 	return updateStatus(DllExports::GdipSaveAdd(
316 			nativeImage, encoderParams));
317 }
318 
SaveAdd(Image * newImage,const EncoderParameters * encoderParams)319 __inline__ Status Image::SaveAdd(Image *newImage,
320 		const EncoderParameters *encoderParams)
321 {
322 	return updateStatus(DllExports::GdipSaveAddImage(
323 			nativeImage,
324 			newImage ? newImage->nativeImage : NULL,
325 			encoderParams));
326 }
327 
SelectActiveFrame(const GUID * dimensionID,UINT frameIndex)328 __inline__ Status Image::SelectActiveFrame(
329 		const GUID *dimensionID, UINT frameIndex)
330 {
331 	return updateStatus(DllExports::GdipImageSelectActiveFrame(
332 			nativeImage, dimensionID, frameIndex));
333 }
334 
SetAbort(GdiplusAbort * pIAbort)335 __inline__ Status Image::SetAbort(GdiplusAbort *pIAbort)
336 {
337 	// FIXME: can't test GdipImageSetAbort because it isn't exported in 1.0
338 	return updateStatus(DllExports::GdipImageSetAbort(
339 			nativeImage, pIAbort));
340 }
341 
SetPalette(const ColorPalette * palette)342 __inline__ Status Image::SetPalette(const ColorPalette *palette)
343 {
344 	return updateStatus(DllExports::GdipSetImagePalette(
345 			nativeImage, palette));
346 }
347 
SetPropertyItem(const PropertyItem * item)348 __inline__ Status Image::SetPropertyItem(const PropertyItem *item)
349 {
350 	return updateStatus(DllExports::GdipSetPropertyItem(nativeImage, item));
351 }
352 
353 
354 // Bitmap
355 
FromBITMAPINFO(const BITMAPINFO * gdiBitmapInfo,VOID * gdiBitmapData)356 __inline__ Bitmap* Bitmap::FromBITMAPINFO(const BITMAPINFO *gdiBitmapInfo,
357 		VOID *gdiBitmapData)
358 {
359 	return new Bitmap(gdiBitmapInfo, gdiBitmapData);
360 }
361 
FromDirectDrawSurface7(IDirectDrawSurface7 * surface)362 __inline__ Bitmap* Bitmap::FromDirectDrawSurface7(IDirectDrawSurface7 *surface)
363 {
364 	return new Bitmap(surface);
365 }
366 
FromFile(const WCHAR * filename,BOOL useEmbeddedColorManagement)367 __inline__ Bitmap* Bitmap::FromFile(const WCHAR *filename,
368 		BOOL useEmbeddedColorManagement)
369 {
370 	return new Bitmap(filename, useEmbeddedColorManagement);
371 }
372 
FromHBITMAP(HBITMAP hbm,HPALETTE hpal)373 __inline__ Bitmap* Bitmap::FromHBITMAP(HBITMAP hbm, HPALETTE hpal)
374 {
375 	return new Bitmap(hbm, hpal);
376 }
377 
FromHICON(HICON icon)378 __inline__ Bitmap* Bitmap::FromHICON(HICON icon)
379 {
380 	return new Bitmap(icon);
381 }
382 
FromResource(HINSTANCE hInstance,const WCHAR * bitmapName)383 __inline__ Bitmap* Bitmap::FromResource(
384 		HINSTANCE hInstance, const WCHAR *bitmapName)
385 {
386 	return new Bitmap(hInstance, bitmapName);
387 }
388 
FromStream(IStream * stream,BOOL useEmbeddedColorManagement)389 __inline__ Bitmap* Bitmap::FromStream(IStream *stream,
390 		BOOL useEmbeddedColorManagement)
391 {
392 	return new Bitmap(stream, useEmbeddedColorManagement);
393 }
394 
395 //TODO: [GDI+ 1.1] Bitmap::ApplyEffect
396 //__inline__ Status Bitmap::ApplyEffect(Bitmap **inputs, INT numInputs,
397 //		Effect *effect, RECT *ROI, RECT *outputRect, Bitmap **output)
398 //{
399 //	return NotImplemented;
400 //}
401 
InitializePalette(ColorPalette * palette,PaletteType paletteType,INT optimalColors,BOOL useTransparentColor,Bitmap * bitmap)402 __inline__ Status Bitmap::InitializePalette(ColorPalette *palette,
403 		PaletteType paletteType, INT optimalColors,
404 		BOOL useTransparentColor, Bitmap *bitmap)
405 {
406 	// FIXME: can't test GdipInitializePalette b/c it isn't exported in 1.0
407 	return DllExports::GdipInitializePalette(palette, paletteType,
408 			optimalColors, useTransparentColor,
409 			bitmap ? (GpBitmap*) bitmap->nativeImage : NULL);
410 }
411 
Bitmap(const BITMAPINFO * gdiBitmapInfo,VOID * gdiBitmapData)412 __inline__ Bitmap::Bitmap(const BITMAPINFO *gdiBitmapInfo, VOID *gdiBitmapData):
413 	Image(NULL, Ok)
414 {
415 	GpBitmap *nativeBitmap = NULL;
416 	lastStatus = DllExports::GdipCreateBitmapFromGdiDib(
417 			gdiBitmapInfo, gdiBitmapData, &nativeBitmap);
418 	nativeImage = nativeBitmap;
419 }
420 
Bitmap(IDirectDrawSurface7 * surface)421 __inline__ Bitmap::Bitmap(IDirectDrawSurface7 *surface): Image(NULL, Ok)
422 {
423 	GpBitmap *nativeBitmap = NULL;
424 	lastStatus = DllExports::GdipCreateBitmapFromDirectDrawSurface(
425 			surface, &nativeBitmap);
426 	nativeImage = nativeBitmap;
427 }
428 
Bitmap(const WCHAR * filename,BOOL useEmbeddedColorManagement)429 __inline__ Bitmap::Bitmap(const WCHAR *filename,
430 		BOOL useEmbeddedColorManagement): Image(NULL, Ok)
431 {
432 	GpBitmap *nativeBitmap = NULL;
433 	if (useEmbeddedColorManagement) {
434 		lastStatus = DllExports::GdipCreateBitmapFromFileICM(
435 				filename, &nativeBitmap);
436 	} else {
437 		lastStatus = DllExports::GdipCreateBitmapFromFile(
438 				filename, &nativeBitmap);
439 	}
440 	nativeImage = nativeBitmap;
441 }
442 
Bitmap(HBITMAP hbm,HPALETTE hpal)443 __inline__ Bitmap::Bitmap(HBITMAP hbm, HPALETTE hpal):
444 	Image(NULL, Ok)
445 {
446 	GpBitmap *nativeBitmap = NULL;
447 	lastStatus = DllExports::GdipCreateBitmapFromHBITMAP(
448 			hbm, hpal, &nativeBitmap);
449 	nativeImage = nativeBitmap;
450 }
451 
Bitmap(HICON hicon)452 __inline__ Bitmap::Bitmap(HICON hicon):
453 	Image(NULL, Ok)
454 {
455 	GpBitmap *nativeBitmap = NULL;
456 	lastStatus = DllExports::GdipCreateBitmapFromHICON(hicon, &nativeBitmap);
457 	nativeImage = nativeBitmap;
458 }
459 
Bitmap(HINSTANCE hInstance,const WCHAR * bitmapName)460 __inline__ Bitmap::Bitmap(HINSTANCE hInstance, const WCHAR *bitmapName):
461 	Image(NULL, Ok)
462 {
463 	GpBitmap *nativeBitmap = NULL;
464 	lastStatus = DllExports::GdipCreateBitmapFromResource(
465 			hInstance, bitmapName, &nativeBitmap);
466 	nativeImage = nativeBitmap;
467 }
468 
Bitmap(IStream * stream,BOOL useEmbeddedColorManagement)469 __inline__ Bitmap::Bitmap(IStream *stream, BOOL useEmbeddedColorManagement):
470 	Image(NULL, Ok)
471 {
472 	GpBitmap *nativeBitmap = NULL;
473 	if (useEmbeddedColorManagement) {
474 		lastStatus = DllExports::GdipCreateBitmapFromStreamICM(
475 				stream, &nativeBitmap);
476 	} else {
477 		lastStatus = DllExports::GdipCreateBitmapFromStream(
478 				stream, &nativeBitmap);
479 	}
480 	nativeImage = nativeBitmap;
481 }
482 
Bitmap(INT width,INT height,Graphics * target)483 __inline__ Bitmap::Bitmap(INT width, INT height, Graphics *target):
484 	Image(NULL, Ok)
485 {
486 	GpBitmap *nativeBitmap = NULL;
487 	lastStatus = DllExports::GdipCreateBitmapFromGraphics(
488 			width, height, target ? target->nativeGraphics : NULL,
489 			&nativeBitmap);
490 	nativeImage = nativeBitmap;
491 }
492 
Bitmap(INT width,INT height,PixelFormat format)493 __inline__ Bitmap::Bitmap(INT width, INT height, PixelFormat format):
494 	Image(NULL, Ok)
495 {
496 	GpBitmap *nativeBitmap = NULL;
497 	lastStatus = DllExports::GdipCreateBitmapFromScan0(
498 			width, height, 0, format, NULL, &nativeBitmap);
499 	nativeImage = nativeBitmap;
500 }
501 
Bitmap(INT width,INT height,INT stride,PixelFormat format,BYTE * scan0)502 __inline__ Bitmap::Bitmap(INT width, INT height, INT stride,
503 		PixelFormat format, BYTE *scan0): Image(NULL, Ok)
504 {
505 	GpBitmap *nativeBitmap = NULL;
506 	lastStatus = DllExports::GdipCreateBitmapFromScan0(
507 			width, height, stride, format, scan0, &nativeBitmap);
508 	nativeImage = nativeBitmap;
509 }
510 
Clone(const RectF & rect,PixelFormat format)511 __inline__ Bitmap* Bitmap::Clone(const RectF& rect, PixelFormat format) const
512 {
513 	return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
514 }
515 
Clone(const Rect & rect,PixelFormat format)516 __inline__ Bitmap* Bitmap::Clone(const Rect& rect, PixelFormat format) const
517 {
518 	return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
519 }
520 
Clone(REAL x,REAL y,REAL width,REAL height,PixelFormat format)521 __inline__ Bitmap* Bitmap::Clone(REAL x, REAL y, REAL width, REAL height,
522 		PixelFormat format) const
523 {
524 	GpBitmap *cloneBitmap = NULL;
525 	Status status = updateStatus(DllExports::GdipCloneBitmapArea(
526 			x, y, width, height, format,
527 			(GpBitmap*) nativeImage, &cloneBitmap));
528 	if (status == Ok) {
529 		Bitmap *result = new Bitmap(cloneBitmap, lastStatus);
530 		if (!result) {
531 			DllExports::GdipDisposeImage(cloneBitmap);
532 			lastStatus = OutOfMemory;
533 		}
534 		return result;
535 	} else {
536 		return NULL;
537 	}
538 }
539 
Clone(INT x,INT y,INT width,INT height,PixelFormat format)540 __inline__ Bitmap* Bitmap::Clone(INT x, INT y, INT width, INT height,
541 		PixelFormat format) const
542 {
543 	GpBitmap *cloneBitmap = NULL;
544 	Status status = updateStatus(DllExports::GdipCloneBitmapAreaI(
545 			x, y, width, height, format,
546 			(GpBitmap*) nativeImage, &cloneBitmap));
547 	if (status == Ok) {
548 		Bitmap *result = new Bitmap(cloneBitmap, lastStatus);
549 		if (!result) {
550 			DllExports::GdipDisposeImage(cloneBitmap);
551 			lastStatus = OutOfMemory;
552 		}
553 		return result;
554 	} else {
555 		return NULL;
556 	}
557 }
558 
559 //TODO: [GDI+ 1.1] Bitmap::ApplyEffect
560 //__inline__ Status Bitmap::ApplyEffect(Effect *effect, RECT *ROI)
561 //{
562 //	return NotImplemented;
563 //}
564 
ConvertFormat(PixelFormat format,DitherType ditherType,PaletteType paletteType,ColorPalette * palette,REAL alphaThresholdPercent)565 __inline__ Status Bitmap::ConvertFormat(PixelFormat format,
566 		DitherType ditherType, PaletteType paletteType,
567 		ColorPalette *palette, REAL alphaThresholdPercent)
568 {
569 	// FIXME: can't test GdipBitmapConvertFormat b/c it isn't exported in 1.0
570 	return updateStatus(DllExports::GdipBitmapConvertFormat(
571 			(GpBitmap*) nativeImage, format, ditherType,
572 			paletteType, palette, alphaThresholdPercent));
573 }
574 
GetHBITMAP(const Color & colorBackground,HBITMAP * hbmReturn)575 __inline__ Status Bitmap::GetHBITMAP(
576 		const Color& colorBackground, HBITMAP *hbmReturn) const
577 {
578 	return updateStatus(DllExports::GdipCreateHBITMAPFromBitmap(
579 			(GpBitmap*) nativeImage, hbmReturn,
580 			colorBackground.GetValue()));
581 }
582 
GetHICON(HICON * icon)583 __inline__ Status Bitmap::GetHICON(HICON *icon) const
584 {
585 	return updateStatus(DllExports::GdipCreateHICONFromBitmap(
586 			(GpBitmap*) nativeImage, icon));
587 }
588 
GetHistogram(HistogramFormat format,UINT numberOfEntries,UINT * channel0,UINT * channel1,UINT * channel2,UINT * channel3)589 __inline__ Status Bitmap::GetHistogram(HistogramFormat format,
590 		UINT numberOfEntries,
591 		UINT *channel0, UINT *channel1,
592 		UINT *channel2, UINT *channel3) const
593 {
594 	return updateStatus(DllExports::GdipBitmapGetHistogram(
595 			(GpBitmap*) nativeImage, format, numberOfEntries,
596 			channel0, channel1, channel2, channel3));
597 }
598 
GetHistogramSize(HistogramFormat format,UINT * numberOfEntries)599 __inline__ Status Bitmap::GetHistogramSize(HistogramFormat format,
600 		UINT *numberOfEntries) const
601 {
602 	return updateStatus(DllExports::GdipBitmapGetHistogramSize(
603 			format, numberOfEntries));
604 }
605 
GetPixel(INT x,INT y,Color * color)606 __inline__ Status Bitmap::GetPixel(INT x, INT y, Color *color) const
607 {
608 	return updateStatus(DllExports::GdipBitmapGetPixel(
609 			(GpBitmap*) nativeImage, x, y,
610 			color ? &color->Value : NULL));
611 }
612 
LockBits(const Rect * rect,UINT flags,PixelFormat format,BitmapData * lockedBitmapData)613 __inline__ Status Bitmap::LockBits(const Rect *rect, UINT flags,
614 		PixelFormat format, BitmapData *lockedBitmapData)
615 {
616 	return updateStatus(DllExports::GdipBitmapLockBits(
617 			(GpBitmap*) nativeImage, rect, flags, format,
618 			lockedBitmapData));
619 }
620 
SetPixel(INT x,INT y,const Color & color)621 __inline__ Status Bitmap::SetPixel(INT x, INT y, const Color& color)
622 {
623 	return updateStatus(DllExports::GdipBitmapSetPixel(
624 			(GpBitmap*) nativeImage, x, y, color.GetValue()));
625 }
626 
SetResolution(REAL xdpi,REAL ydpi)627 __inline__ Status Bitmap::SetResolution(REAL xdpi, REAL ydpi)
628 {
629 	return updateStatus(DllExports::GdipBitmapSetResolution(
630 			(GpBitmap*) nativeImage, xdpi, ydpi));
631 }
632 
UnlockBits(BitmapData * lockedBitmapData)633 __inline__ Status Bitmap::UnlockBits(BitmapData *lockedBitmapData)
634 {
635 	return updateStatus(DllExports::GdipBitmapUnlockBits(
636 			(GpBitmap*) nativeImage, lockedBitmapData));
637 }
638 
639 
640 // CachedBitmap
641 
CachedBitmap(Bitmap * bitmap,Graphics * graphics)642 __inline__ CachedBitmap::CachedBitmap(Bitmap *bitmap, Graphics *graphics):
643 	nativeCachedBitmap(NULL), lastStatus(Ok)
644 {
645 	lastStatus = DllExports::GdipCreateCachedBitmap(
646 			bitmap ? ((GpBitmap*) bitmap->nativeImage) : NULL,
647 			graphics ? graphics->nativeGraphics : NULL,
648 			&nativeCachedBitmap);
649 }
650 
~CachedBitmap()651 __inline__ CachedBitmap::~CachedBitmap()
652 {
653 	DllExports::GdipDeleteCachedBitmap(nativeCachedBitmap);
654 }
655 
656 
657 // CustomLineCap
658 
CustomLineCap(const GraphicsPath * fillPath,const GraphicsPath * strokePath,LineCap baseCap,REAL baseInset)659 __inline__ CustomLineCap::CustomLineCap(
660 		const GraphicsPath *fillPath,
661 		const GraphicsPath *strokePath,
662 		LineCap baseCap, REAL baseInset):
663 		nativeCustomLineCap(NULL), lastStatus(Ok)
664 {
665 	lastStatus = DllExports::GdipCreateCustomLineCap(
666 			fillPath ? fillPath->nativePath : NULL,
667 			strokePath ? strokePath->nativePath : NULL,
668 			baseCap, baseInset, &nativeCustomLineCap);
669 }
670 
GetBaseCap()671 __inline__ LineCap CustomLineCap::GetBaseCap() const
672 {
673 	LineCap result = LineCapFlat;
674 	updateStatus(DllExports::GdipGetCustomLineCapBaseCap(
675 			nativeCustomLineCap, &result));
676 	return result;
677 }
678 
GetBaseInset()679 __inline__ REAL CustomLineCap::GetBaseInset() const
680 {
681 	REAL result = 0.0f;
682 	updateStatus(DllExports::GdipGetCustomLineCapBaseInset(
683 			nativeCustomLineCap, &result));
684 	return result;
685 }
686 
GetStrokeCaps(LineCap * startCap,LineCap * endCap)687 __inline__ Status CustomLineCap::GetStrokeCaps(LineCap *startCap,
688 		LineCap *endCap) const
689 {
690 	return updateStatus(DllExports::GdipGetCustomLineCapStrokeCaps(
691 			nativeCustomLineCap, startCap, endCap));
692 }
693 
GetStrokeJoin()694 __inline__ LineJoin CustomLineCap::GetStrokeJoin() const
695 {
696 	LineJoin result = LineJoinMiter;
697 	updateStatus(DllExports::GdipGetCustomLineCapStrokeJoin(
698 			nativeCustomLineCap, &result));
699 	return result;
700 }
701 
GetWidthScale()702 __inline__ REAL CustomLineCap::GetWidthScale() const
703 {
704 	REAL result = 0.0f;
705 	updateStatus(DllExports::GdipGetCustomLineCapWidthScale(
706 			nativeCustomLineCap, &result));
707 	return result;
708 }
709 
SetBaseCap(LineCap baseCap)710 __inline__ Status CustomLineCap::SetBaseCap(LineCap baseCap)
711 {
712 	return updateStatus(DllExports::GdipSetCustomLineCapBaseCap(
713 			nativeCustomLineCap, baseCap));
714 }
715 
SetBaseInset(REAL inset)716 __inline__ Status CustomLineCap::SetBaseInset(REAL inset)
717 {
718 	return updateStatus(DllExports::GdipSetCustomLineCapBaseInset(
719 			nativeCustomLineCap, inset));
720 }
721 
SetStrokeCap(LineCap strokeCap)722 __inline__ Status CustomLineCap::SetStrokeCap(LineCap strokeCap)
723 {
724 	return updateStatus(DllExports::GdipSetCustomLineCapStrokeCaps(
725 			nativeCustomLineCap, strokeCap, strokeCap));
726 }
727 
SetStrokeCaps(LineCap startCap,LineCap endCap)728 __inline__ Status CustomLineCap::SetStrokeCaps(LineCap startCap, LineCap endCap)
729 {
730 	return updateStatus(DllExports::GdipSetCustomLineCapStrokeCaps(
731 			nativeCustomLineCap, startCap, endCap));
732 }
733 
SetStrokeJoin(LineJoin lineJoin)734 __inline__ Status CustomLineCap::SetStrokeJoin(LineJoin lineJoin)
735 {
736 	return updateStatus(DllExports::GdipSetCustomLineCapStrokeJoin(
737 			nativeCustomLineCap, lineJoin));
738 }
739 
SetWidthScale(REAL widthScale)740 __inline__ Status CustomLineCap::SetWidthScale(REAL widthScale)
741 {
742 	return updateStatus(DllExports::GdipSetCustomLineCapWidthScale(
743 			nativeCustomLineCap, widthScale));
744 }
745 
746 
747 // Font
748 
Font(const FontFamily * family,REAL emSize,INT style,Unit unit)749 __inline__ Font::Font(const FontFamily *family,
750 		REAL emSize, INT style, Unit unit):
751 		nativeFont(NULL), lastStatus(Ok)
752 {
753 	lastStatus = DllExports::GdipCreateFont(
754 			family ? family->nativeFontFamily : NULL,
755 			emSize, style, unit, &nativeFont);
756 }
757 
Font(HDC hdc,HFONT hfont)758 __inline__ Font::Font(HDC hdc, HFONT hfont):
759 	nativeFont(NULL), lastStatus(Ok)
760 {
761 	LOGFONTW logfont;
762 	if (GetObject(hfont, sizeof logfont, &logfont)) {
763 		lastStatus = DllExports::GdipCreateFontFromLogfontW(
764 				hdc, &logfont, &nativeFont);
765 	} else {
766 		lastStatus = DllExports::GdipCreateFontFromDC(
767 				hdc, &nativeFont);
768 	}
769 }
770 
Font(HDC hdc,const LOGFONTA * logfont)771 __inline__ Font::Font(HDC hdc, const LOGFONTA *logfont):
772 	nativeFont(NULL), lastStatus(Ok)
773 {
774 	lastStatus = DllExports::GdipCreateFontFromLogfontA(
775 			hdc, logfont, &nativeFont);
776 }
777 
Font(HDC hdc,const LOGFONTW * logfont)778 __inline__ Font::Font(HDC hdc, const LOGFONTW *logfont):
779 	nativeFont(NULL), lastStatus(Ok)
780 {
781 	lastStatus = DllExports::GdipCreateFontFromLogfontW(
782 			hdc, logfont, &nativeFont);
783 }
784 
Font(HDC hdc)785 __inline__ Font::Font(HDC hdc):
786 	nativeFont(NULL), lastStatus(Ok)
787 {
788 	lastStatus = DllExports::GdipCreateFontFromDC(hdc, &nativeFont);
789 }
790 
Font(const WCHAR * familyName,REAL emSize,INT style,Unit unit,const FontCollection * fontCollection)791 __inline__ Font::Font(const WCHAR *familyName, REAL emSize, INT style,
792 		Unit unit, const FontCollection *fontCollection):
793 		nativeFont(NULL), lastStatus(Ok)
794 {
795 	GpFontFamily *nativeFamily = NULL;
796 	lastStatus = DllExports::GdipCreateFontFamilyFromName(
797 			familyName,
798 			fontCollection ? fontCollection->nativeFontCollection : NULL,
799 			&nativeFamily);
800 
801 	if (nativeFamily) {
802 		lastStatus = DllExports::GdipCreateFont(
803 				nativeFamily, emSize, style, unit, &nativeFont);
804 		DllExports::GdipDeleteFontFamily(nativeFamily);
805 	}
806 }
807 
~Font()808 __inline__ Font::~Font()
809 {
810 	DllExports::GdipDeleteFont(nativeFont);
811 }
812 
Clone()813 __inline__ Font* Font::Clone() const
814 {
815 	GpFont *cloneFont = NULL;
816 	Status status = updateStatus(DllExports::GdipCloneFont(
817 			nativeFont, &cloneFont));
818 	if (status == Ok) {
819 		Font *result = new Font(cloneFont, lastStatus);
820 		if (!result) {
821 			DllExports::GdipDeleteFont(cloneFont);
822 			lastStatus = OutOfMemory;
823 		}
824 		return result;
825 	} else {
826 		return NULL;
827 	}
828 }
829 
GetFamily(FontFamily * family)830 __inline__ Status Font::GetFamily(FontFamily *family) const
831 {
832 	if (!family) return lastStatus = InvalidParameter;
833 	// FIXME: do we need to call GdipDeleteFontFamily first?
834 	return family->lastStatus = updateStatus(DllExports::GdipGetFamily(
835 			nativeFont, &family->nativeFontFamily));
836 }
837 
GetHeight(const Graphics * graphics)838 __inline__ REAL Font::GetHeight(const Graphics *graphics) const
839 {
840 	REAL result = 0.0f;
841 	updateStatus(DllExports::GdipGetFontHeight(
842 			nativeFont, graphics ? graphics->nativeGraphics : NULL,
843 			&result));
844 	return result;
845 }
846 
GetHeight(REAL dpi)847 __inline__ REAL Font::GetHeight(REAL dpi) const
848 {
849 	REAL result = 0.0f;
850 	updateStatus(DllExports::GdipGetFontHeightGivenDPI(
851 			nativeFont, dpi, &result));
852 	return result;
853 }
854 
GetLogFontA(const Graphics * graphics,LOGFONTA * logfontA)855 __inline__ Status Font::GetLogFontA(const Graphics *graphics, LOGFONTA *logfontA)
856 const
857 {
858 	return updateStatus(DllExports::GdipGetLogFontA(
859 			nativeFont, graphics ? graphics->nativeGraphics : NULL,
860 			logfontA));
861 }
862 
GetLogFontW(const Graphics * graphics,LOGFONTW * logfontW)863 __inline__ Status Font::GetLogFontW(const Graphics *graphics, LOGFONTW *logfontW)
864 const
865 {
866 	return updateStatus(DllExports::GdipGetLogFontW(
867 			nativeFont, graphics ? graphics->nativeGraphics : NULL,
868 			logfontW));
869 }
870 
GetSize()871 __inline__ REAL Font::GetSize() const
872 {
873 	REAL result = 0.0;
874 	updateStatus(DllExports::GdipGetFontSize(nativeFont, &result));
875 	return result;
876 }
877 
GetStyle()878 __inline__ INT Font::GetStyle() const
879 {
880 	INT result = FontStyleRegular;
881 	updateStatus(DllExports::GdipGetFontStyle(nativeFont, &result));
882 	return result;
883 }
884 
GetUnit()885 __inline__ Unit Font::GetUnit() const
886 {
887 	Unit result = UnitPoint;
888 	updateStatus(DllExports::GdipGetFontUnit(nativeFont, &result));
889 	return result;
890 }
891 
892 
893 // FontCollection
894 
FontCollection()895 __inline__ FontCollection::FontCollection():
896 	nativeFontCollection(NULL), lastStatus(Ok)
897 {
898 }
899 
GetFamilies(INT numSought,FontFamily * families,INT * numFound)900 __inline__ Status FontCollection::GetFamilies(INT numSought,
901 		FontFamily *families, INT *numFound) const
902 {
903 	if (numSought <= 0 || !families || !numFound)
904 		return lastStatus = InvalidParameter;
905 
906 	for (int i = 0; i < numSought; ++i) {
907 		families[i].nativeFontFamily = NULL;
908 		families[i].lastStatus = FontFamilyNotFound;
909 	}
910 	*numFound = 0;
911 
912 	GpFontFamily **nativeFamilyArray = (GpFontFamily**)
913 		DllExports::GdipAlloc(numSought * sizeof (GpFontFamily*));
914 	if (!nativeFamilyArray)
915 		return lastStatus = OutOfMemory;
916 
917 	Status status = updateStatus(DllExports::GdipGetFontCollectionFamilyList(
918 			nativeFontCollection, numSought, nativeFamilyArray,
919 			numFound));
920 
921 	// FIXME: must the native GpFontFamily objects be cloned? Seems so.
922 	// (if this is not done, the "Creating a Private Font Collection"
923 	// example crashes on "delete[] pFontFamily")
924 
925 	if (status == Ok) {
926 		for (int i = 0; i < *numFound; ++i) {
927 			families[i].lastStatus =
928 				updateStatus(DllExports::GdipCloneFontFamily(
929 					nativeFamilyArray[i],
930 					&families[i].nativeFontFamily));
931 		}
932 	}
933 
934 	DllExports::GdipFree(nativeFamilyArray);
935 	return status;
936 }
937 
GetFamilyCount()938 __inline__ INT FontCollection::GetFamilyCount() const
939 {
940 	INT result = 0;
941 	updateStatus(DllExports::GdipGetFontCollectionFamilyCount(
942 			nativeFontCollection, &result));
943 	return result;
944 }
945 
946 
947 // FontFamily
948 
949 // FIXME: do FontFamily::GenericMonospace() et al. need to be thread safe?
950 // FIXME: maybe put parts of this in gdiplus.c
951 
952 extern "C" void *_GdipFontFamilyCachedGenericMonospace;
953 extern "C" void *_GdipFontFamilyCachedGenericSansSerif;
954 extern "C" void *_GdipFontFamilyCachedGenericSerif;
955 
GenericMonospace()956 __inline__ const FontFamily* FontFamily::GenericMonospace()
957 {
958 	if (!_GdipFontFamilyCachedGenericMonospace) {
959 		GpFontFamily *nativeFontFamily = 0;
960 		Status status = DllExports::GdipGetGenericFontFamilyMonospace(
961 				&nativeFontFamily);
962 		if (status == Ok && nativeFontFamily) {
963 			_GdipFontFamilyCachedGenericMonospace = (void*)
964 				new FontFamily(nativeFontFamily, Ok);
965 		}
966 	}
967 	return (FontFamily*) _GdipFontFamilyCachedGenericMonospace;
968 }
969 
GenericSansSerif()970 __inline__ const FontFamily* FontFamily::GenericSansSerif()
971 {
972 	if (!_GdipFontFamilyCachedGenericSansSerif) {
973 		GpFontFamily *nativeFontFamily = 0;
974 		Status status = DllExports::GdipGetGenericFontFamilySansSerif(
975 				&nativeFontFamily);
976 		if (status == Ok && nativeFontFamily) {
977 			_GdipFontFamilyCachedGenericSansSerif = (void*)
978 				new FontFamily(nativeFontFamily, Ok);
979 		}
980 	}
981 	return (FontFamily*) _GdipFontFamilyCachedGenericSansSerif;
982 }
983 
GenericSerif()984 __inline__ const FontFamily* FontFamily::GenericSerif()
985 {
986 	if (!_GdipFontFamilyCachedGenericSerif) {
987 		GpFontFamily *nativeFontFamily = 0;
988 		Status status = DllExports::GdipGetGenericFontFamilySerif(
989 				&nativeFontFamily);
990 		if (status == Ok && nativeFontFamily) {
991 			_GdipFontFamilyCachedGenericSerif = (void*)
992 				new FontFamily(nativeFontFamily, Ok);
993 		}
994 	}
995 	return (FontFamily*) _GdipFontFamilyCachedGenericSerif;
996 }
997 
FontFamily()998 __inline__ FontFamily::FontFamily():
999 	nativeFontFamily(NULL), lastStatus(Ok)
1000 {
1001 }
1002 
FontFamily(const WCHAR * name,const FontCollection * fontCollection)1003 __inline__ FontFamily::FontFamily(const WCHAR *name,
1004 		const FontCollection *fontCollection):
1005 		nativeFontFamily(NULL), lastStatus(Ok)
1006 {
1007 	lastStatus = DllExports::GdipCreateFontFamilyFromName(name,
1008 			fontCollection ? fontCollection->nativeFontCollection : NULL,
1009 			&nativeFontFamily);
1010 }
1011 
~FontFamily()1012 __inline__ FontFamily::~FontFamily()
1013 {
1014 	DllExports::GdipDeleteFontFamily(nativeFontFamily);
1015 }
1016 
Clone()1017 __inline__ FontFamily* FontFamily::Clone() const
1018 {
1019 	GpFontFamily *cloneFontFamily = NULL;
1020 	Status status = updateStatus(DllExports::GdipCloneFontFamily(
1021 			nativeFontFamily, &cloneFontFamily));
1022 	if (status == Ok) {
1023 		FontFamily *result = new FontFamily(cloneFontFamily, lastStatus);
1024 		if (!result) {
1025 			DllExports::GdipDeleteFontFamily(cloneFontFamily);
1026 			lastStatus = OutOfMemory;
1027 		}
1028 		return result;
1029 	} else {
1030 		return NULL;
1031 	}
1032 }
1033 
GetCellAscent(INT style)1034 __inline__ UINT16 FontFamily::GetCellAscent(INT style) const
1035 {
1036 	UINT16 result = 0;
1037 	updateStatus(DllExports::GdipGetCellAscent(
1038 			nativeFontFamily, style, &result));
1039 	return result;
1040 }
1041 
GetCellDescent(INT style)1042 __inline__ UINT16 FontFamily::GetCellDescent(INT style) const
1043 {
1044 	UINT16 result = 0;
1045 	updateStatus(DllExports::GdipGetCellDescent(
1046 			nativeFontFamily, style, &result));
1047 	return result;
1048 }
1049 
GetEmHeight(INT style)1050 __inline__ UINT16 FontFamily::GetEmHeight(INT style) const
1051 {
1052 	UINT16 result = 0;
1053 	updateStatus(DllExports::GdipGetEmHeight(
1054 			nativeFontFamily, style, &result));
1055 	return result;
1056 }
1057 
GetFamilyName(WCHAR name[LF_FACESIZE],LANGID language)1058 __inline__ Status FontFamily::GetFamilyName(WCHAR name[LF_FACESIZE],
1059 		LANGID language) const
1060 {
1061 	return updateStatus(DllExports::GdipGetFamilyName(
1062 			nativeFontFamily, name, language));
1063 }
1064 
GetLineSpacing(INT style)1065 __inline__ UINT16 FontFamily::GetLineSpacing(INT style) const
1066 {
1067 	UINT16 result = 0;
1068 	updateStatus(DllExports::GdipGetLineSpacing(
1069 			nativeFontFamily, style, &result));
1070 	return result;
1071 }
1072 
IsStyleAvailable(INT style)1073 __inline__ BOOL FontFamily::IsStyleAvailable(INT style) const
1074 {
1075 	BOOL result = FALSE;
1076 	updateStatus(DllExports::GdipIsStyleAvailable(
1077 			nativeFontFamily, style, &result));
1078 	return result;
1079 }
1080 
1081 
1082 // InstalledFontCollection
1083 
InstalledFontCollection()1084 __inline__ InstalledFontCollection::InstalledFontCollection()
1085 {
1086 	lastStatus = DllExports::GdipNewInstalledFontCollection(
1087 			&nativeFontCollection);
1088 }
1089 
1090 
1091 // PrivateFontCollection
1092 
PrivateFontCollection()1093 __inline__ PrivateFontCollection::PrivateFontCollection()
1094 {
1095 	lastStatus = DllExports::GdipNewPrivateFontCollection(
1096 			&nativeFontCollection);
1097 }
1098 
AddFontFile(const WCHAR * filename)1099 __inline__ Status PrivateFontCollection::AddFontFile(const WCHAR *filename)
1100 {
1101 	return updateStatus(DllExports::GdipPrivateAddFontFile(
1102 			nativeFontCollection, filename));
1103 }
1104 
AddMemoryFont(const VOID * memory,INT length)1105 __inline__ Status PrivateFontCollection::AddMemoryFont(
1106 		const VOID *memory, INT length)
1107 {
1108 	return updateStatus(DllExports::GdipPrivateAddMemoryFont(
1109 			nativeFontCollection, memory, length));
1110 }
1111 
1112 
1113 // Region
1114 
FromHRGN(HRGN hrgn)1115 __inline__ Region* Region::FromHRGN(HRGN hrgn)
1116 {
1117 	return new Region(hrgn);
1118 }
1119 
Region()1120 __inline__ Region::Region(): nativeRegion(NULL), lastStatus(Ok)
1121 {
1122 	lastStatus = DllExports::GdipCreateRegion(&nativeRegion);
1123 }
1124 
Region(const RectF & rect)1125 __inline__ Region::Region(const RectF& rect): nativeRegion(NULL), lastStatus(Ok)
1126 {
1127 	lastStatus = DllExports::GdipCreateRegionRect(&rect, &nativeRegion);
1128 }
1129 
Region(const Rect & rect)1130 __inline__ Region::Region(const Rect& rect): nativeRegion(NULL), lastStatus(Ok)
1131 {
1132 	lastStatus = DllExports::GdipCreateRegionRectI(&rect, &nativeRegion);
1133 }
1134 
Region(const GraphicsPath * path)1135 __inline__ Region::Region(const GraphicsPath *path):
1136 	nativeRegion(NULL), lastStatus(Ok)
1137 {
1138 	lastStatus = DllExports::GdipCreateRegionPath(
1139 			path ? path->nativePath : NULL, &nativeRegion);
1140 }
1141 
Region(const BYTE * regionData,INT size)1142 __inline__ Region::Region(const BYTE *regionData, INT size):
1143 	nativeRegion(NULL), lastStatus(Ok)
1144 {
1145 	lastStatus = DllExports::GdipCreateRegionRgnData(
1146 			regionData, size, &nativeRegion);
1147 }
1148 
Region(HRGN hrgn)1149 __inline__ Region::Region(HRGN hrgn): nativeRegion(NULL), lastStatus(Ok)
1150 {
1151 	lastStatus = DllExports::GdipCreateRegionHrgn(hrgn, &nativeRegion);
1152 }
1153 
~Region()1154 __inline__ Region::~Region()
1155 {
1156 	DllExports::GdipDeleteRegion(nativeRegion);
1157 }
1158 
Clone()1159 __inline__ Region* Region::Clone() const
1160 {
1161 	GpRegion *cloneRegion = NULL;
1162 	Status status = updateStatus(DllExports::GdipCloneRegion(
1163 			nativeRegion, &cloneRegion));
1164 	if (status == Ok) {
1165 		Region *result = new Region(cloneRegion, lastStatus);
1166 		if (!result) {
1167 			DllExports::GdipDeleteRegion(cloneRegion);
1168 			lastStatus = OutOfMemory;
1169 		}
1170 		return result;
1171 	} else {
1172 		return NULL;
1173 	}
1174 }
1175 
Complement(const RectF & rect)1176 __inline__ Status Region::Complement(const RectF& rect)
1177 {
1178 	return updateStatus(DllExports::GdipCombineRegionRect(
1179 			nativeRegion, &rect, CombineModeComplement));
1180 }
1181 
Complement(const Rect & rect)1182 __inline__ Status Region::Complement(const Rect& rect)
1183 {
1184 	return updateStatus(DllExports::GdipCombineRegionRectI(
1185 			nativeRegion, &rect, CombineModeComplement));
1186 }
1187 
Complement(const Region * region)1188 __inline__ Status Region::Complement(const Region *region)
1189 {
1190 	return updateStatus(DllExports::GdipCombineRegionRegion(
1191 			nativeRegion, region ? region->nativeRegion : NULL,
1192 			CombineModeComplement));
1193 }
1194 
Complement(const GraphicsPath * path)1195 __inline__ Status Region::Complement(const GraphicsPath *path)
1196 {
1197 	return updateStatus(DllExports::GdipCombineRegionPath(
1198 			nativeRegion, path ? path->nativePath : NULL,
1199 			CombineModeComplement));
1200 }
1201 
Equals(const Region * region,const Graphics * graphics)1202 __inline__ BOOL Region::Equals(const Region *region, const Graphics *graphics)
1203 const
1204 {
1205 	BOOL result = FALSE;
1206 	updateStatus(DllExports::GdipIsEqualRegion(
1207 			nativeRegion, region ? region->nativeRegion : NULL,
1208 			graphics ? graphics->nativeGraphics : NULL, &result));
1209 	return result;
1210 }
1211 
Exclude(const RectF & rect)1212 __inline__ Status Region::Exclude(const RectF& rect)
1213 {
1214 	return updateStatus(DllExports::GdipCombineRegionRect(
1215 			nativeRegion, &rect, CombineModeExclude));
1216 }
1217 
Exclude(const Rect & rect)1218 __inline__ Status Region::Exclude(const Rect& rect)
1219 {
1220 	return updateStatus(DllExports::GdipCombineRegionRectI(
1221 			nativeRegion, &rect, CombineModeExclude));
1222 }
1223 
Exclude(const Region * region)1224 __inline__ Status Region::Exclude(const Region *region)
1225 {
1226 	return updateStatus(DllExports::GdipCombineRegionRegion(
1227 			nativeRegion, region ? region->nativeRegion : NULL,
1228 			CombineModeExclude));
1229 }
1230 
Exclude(const GraphicsPath * path)1231 __inline__ Status Region::Exclude(const GraphicsPath *path)
1232 {
1233 	return updateStatus(DllExports::GdipCombineRegionPath(
1234 			nativeRegion, path ? path->nativePath : NULL,
1235 			CombineModeExclude));
1236 }
1237 
GetBounds(RectF * rect,const Graphics * graphics)1238 __inline__ Status Region::GetBounds(RectF *rect, const Graphics *graphics) const
1239 {
1240 	return updateStatus(DllExports::GdipGetRegionBounds(nativeRegion,
1241 			graphics ? graphics->nativeGraphics : NULL, rect));
1242 }
1243 
GetBounds(Rect * rect,const Graphics * graphics)1244 __inline__ Status Region::GetBounds(Rect *rect, const Graphics *graphics) const
1245 {
1246 	return updateStatus(DllExports::GdipGetRegionBoundsI(nativeRegion,
1247 			graphics ? graphics->nativeGraphics : NULL, rect));
1248 }
1249 
GetData(BYTE * buffer,UINT bufferSize,UINT * sizeFilled)1250 __inline__ Status Region::GetData(BYTE *buffer, UINT bufferSize,
1251 		UINT *sizeFilled) const
1252 {
1253 	return updateStatus(DllExports::GdipGetRegionData(
1254 			nativeRegion, buffer, bufferSize, sizeFilled));
1255 }
1256 
GetDataSize()1257 __inline__ UINT Region::GetDataSize() const
1258 {
1259 	UINT result = 0;
1260 	updateStatus(DllExports::GdipGetRegionDataSize(nativeRegion, &result));
1261 	return result;
1262 }
1263 
GetHRGN(const Graphics * graphics)1264 __inline__ HRGN Region::GetHRGN(const Graphics *graphics) const
1265 {
1266 	HRGN result = NULL;
1267 	updateStatus(DllExports::GdipGetRegionHRgn(nativeRegion,
1268 			graphics ? graphics->nativeGraphics : NULL, &result));
1269 	return result;
1270 }
1271 
GetRegionScans(const Matrix * matrix,RectF * rects,INT * count)1272 __inline__ Status Region::GetRegionScans(const Matrix *matrix,
1273 		RectF *rects, INT *count) const
1274 {
1275 	return updateStatus(DllExports::GdipGetRegionScans(
1276 			nativeRegion, rects, count,
1277 			matrix ? matrix->nativeMatrix : NULL));
1278 }
1279 
GetRegionScans(const Matrix * matrix,Rect * rects,INT * count)1280 __inline__ Status Region::GetRegionScans(const Matrix *matrix,
1281 		Rect *rects, INT *count) const
1282 {
1283 	return updateStatus(DllExports::GdipGetRegionScansI(
1284 			nativeRegion, rects, count,
1285 			matrix ? matrix->nativeMatrix : NULL));
1286 }
1287 
GetRegionScansCount(const Matrix * matrix)1288 __inline__ UINT Region::GetRegionScansCount(const Matrix *matrix) const
1289 {
1290 	UINT result = 0;
1291 	updateStatus(DllExports::GdipGetRegionScansCount(
1292 			nativeRegion, &result,
1293 			matrix ? matrix->nativeMatrix : NULL));
1294 	return result;
1295 }
1296 
Intersect(const RectF & rect)1297 __inline__ Status Region::Intersect(const RectF& rect)
1298 {
1299 	return updateStatus(DllExports::GdipCombineRegionRect(
1300 			nativeRegion, &rect, CombineModeIntersect));
1301 }
1302 
Intersect(const Rect & rect)1303 __inline__ Status Region::Intersect(const Rect& rect)
1304 {
1305 	return updateStatus(DllExports::GdipCombineRegionRectI(
1306 			nativeRegion, &rect, CombineModeIntersect));
1307 }
1308 
Intersect(const Region * region)1309 __inline__ Status Region::Intersect(const Region *region)
1310 {
1311 	return updateStatus(DllExports::GdipCombineRegionRegion(
1312 			nativeRegion, region ? region->nativeRegion : NULL,
1313 			CombineModeIntersect));
1314 }
1315 
Intersect(const GraphicsPath * path)1316 __inline__ Status Region::Intersect(const GraphicsPath *path)
1317 {
1318 	return updateStatus(DllExports::GdipCombineRegionPath(
1319 			nativeRegion, path ? path->nativePath : NULL,
1320 			CombineModeIntersect));
1321 }
1322 
IsEmpty(const Graphics * graphics)1323 __inline__ BOOL Region::IsEmpty(const Graphics *graphics) const
1324 {
1325 	BOOL result = FALSE;
1326 	updateStatus(DllExports::GdipIsEmptyRegion(nativeRegion,
1327 			graphics ? graphics->nativeGraphics : NULL, &result));
1328 	return result;
1329 }
1330 
IsInfinite(const Graphics * graphics)1331 __inline__ BOOL Region::IsInfinite(const Graphics *graphics) const
1332 {
1333 	BOOL result = FALSE;
1334 	updateStatus(DllExports::GdipIsInfiniteRegion(nativeRegion,
1335 			graphics ? graphics->nativeGraphics : NULL, &result));
1336 	return result;
1337 }
1338 
IsVisible(REAL x,REAL y,const Graphics * graphics)1339 __inline__ BOOL Region::IsVisible(REAL x, REAL y,
1340 		const Graphics *graphics) const
1341 {
1342 	BOOL result = FALSE;
1343 	updateStatus(DllExports::GdipIsVisibleRegionPoint(
1344 			nativeRegion, x, y,
1345 			graphics ? graphics->nativeGraphics : NULL, &result));
1346 	return result;
1347 }
1348 
IsVisible(INT x,INT y,const Graphics * graphics)1349 __inline__ BOOL Region::IsVisible(INT x, INT y,
1350 		const Graphics *graphics) const
1351 {
1352 	BOOL result = FALSE;
1353 	updateStatus(DllExports::GdipIsVisibleRegionPointI(
1354 			nativeRegion, x, y,
1355 			graphics ? graphics->nativeGraphics : NULL, &result));
1356 	return result;
1357 }
1358 
IsVisible(const PointF & point,const Graphics * graphics)1359 __inline__ BOOL Region::IsVisible(const PointF& point,
1360 		const Graphics *graphics) const
1361 {
1362 	BOOL result = FALSE;
1363 	updateStatus(DllExports::GdipIsVisibleRegionPoint(
1364 			nativeRegion, point.X, point.Y,
1365 			graphics ? graphics->nativeGraphics : NULL, &result));
1366 	return result;
1367 }
1368 
IsVisible(const Point & point,const Graphics * graphics)1369 __inline__ BOOL Region::IsVisible(const Point& point,
1370 		const Graphics *graphics) const
1371 {
1372 	BOOL result = FALSE;
1373 	updateStatus(DllExports::GdipIsVisibleRegionPointI(
1374 			nativeRegion, point.X, point.Y,
1375 			graphics ? graphics->nativeGraphics : NULL, &result));
1376 	return result;
1377 }
1378 
IsVisible(REAL x,REAL y,REAL width,REAL height,const Graphics * graphics)1379 __inline__ BOOL Region::IsVisible(REAL x, REAL y, REAL width, REAL height,
1380 		const Graphics *graphics) const
1381 {
1382 	BOOL result = FALSE;
1383 	updateStatus(DllExports::GdipIsVisibleRegionRect(
1384 			nativeRegion, x, y, width, height,
1385 			graphics ? graphics->nativeGraphics : NULL, &result));
1386 	return result;
1387 }
1388 
IsVisible(INT x,INT y,INT width,INT height,const Graphics * graphics)1389 __inline__ BOOL Region::IsVisible(INT x, INT y, INT width, INT height,
1390 		const Graphics *graphics) const
1391 {
1392 	BOOL result = FALSE;
1393 	updateStatus(DllExports::GdipIsVisibleRegionRectI(
1394 			nativeRegion, x, y, width, height,
1395 			graphics ? graphics->nativeGraphics : NULL, &result));
1396 	return result;
1397 }
1398 
IsVisible(const RectF & rect,const Graphics * graphics)1399 __inline__ BOOL Region::IsVisible(const RectF& rect,
1400 		const Graphics *graphics) const
1401 {
1402 	BOOL result = FALSE;
1403 	updateStatus(DllExports::GdipIsVisibleRegionRect(
1404 			nativeRegion, rect.X, rect.Y, rect.Width, rect.Height,
1405 			graphics ? graphics->nativeGraphics : NULL, &result));
1406 	return result;
1407 }
1408 
IsVisible(const Rect & rect,const Graphics * graphics)1409 __inline__ BOOL Region::IsVisible(const Rect& rect,
1410 		const Graphics *graphics) const
1411 {
1412 	BOOL result = FALSE;
1413 	updateStatus(DllExports::GdipIsVisibleRegionRectI(
1414 			nativeRegion, rect.X, rect.Y, rect.Width, rect.Height,
1415 			graphics ? graphics->nativeGraphics : NULL, &result));
1416 	return result;
1417 }
1418 
MakeEmpty()1419 __inline__ Status Region::MakeEmpty()
1420 {
1421 	return updateStatus(DllExports::GdipSetEmpty(nativeRegion));
1422 }
1423 
MakeInfinite()1424 __inline__ Status Region::MakeInfinite()
1425 {
1426 	return updateStatus(DllExports::GdipSetInfinite(nativeRegion));
1427 }
1428 
Transform(const Matrix * matrix)1429 __inline__ Status Region::Transform(const Matrix *matrix)
1430 {
1431 	return updateStatus(DllExports::GdipTransformRegion(
1432 			nativeRegion, matrix ? matrix->nativeMatrix : NULL));
1433 }
1434 
Translate(REAL dx,REAL dy)1435 __inline__ Status Region::Translate(REAL dx, REAL dy)
1436 {
1437 	return updateStatus(DllExports::GdipTranslateRegion(
1438 			nativeRegion, dx, dy));
1439 }
1440 
Translate(INT dx,INT dy)1441 __inline__ Status Region::Translate(INT dx, INT dy)
1442 {
1443 	return updateStatus(DllExports::GdipTranslateRegionI(
1444 			nativeRegion, dx, dy));
1445 }
1446 
Union(const RectF & rect)1447 __inline__ Status Region::Union(const RectF& rect)
1448 {
1449 	return updateStatus(DllExports::GdipCombineRegionRect(
1450 			nativeRegion, &rect, CombineModeUnion));
1451 }
1452 
Union(const Rect & rect)1453 __inline__ Status Region::Union(const Rect& rect)
1454 {
1455 	return updateStatus(DllExports::GdipCombineRegionRectI(
1456 			nativeRegion, &rect, CombineModeUnion));
1457 }
1458 
Union(const Region * region)1459 __inline__ Status Region::Union(const Region *region)
1460 {
1461 	return updateStatus(DllExports::GdipCombineRegionRegion(
1462 			nativeRegion, region ? region->nativeRegion : NULL,
1463 			CombineModeUnion));
1464 }
1465 
Union(const GraphicsPath * path)1466 __inline__ Status Region::Union(const GraphicsPath *path)
1467 {
1468 	return updateStatus(DllExports::GdipCombineRegionPath(
1469 			nativeRegion, path ? path->nativePath : NULL,
1470 			CombineModeUnion));
1471 }
1472 
Xor(const RectF & rect)1473 __inline__ Status Region::Xor(const RectF& rect)
1474 {
1475 	return updateStatus(DllExports::GdipCombineRegionRect(
1476 			nativeRegion, &rect, CombineModeXor));
1477 }
1478 
Xor(const Rect & rect)1479 __inline__ Status Region::Xor(const Rect& rect)
1480 {
1481 	return updateStatus(DllExports::GdipCombineRegionRectI(
1482 			nativeRegion, &rect, CombineModeXor));
1483 }
1484 
Xor(const Region * region)1485 __inline__ Status Region::Xor(const Region *region)
1486 {
1487 	return updateStatus(DllExports::GdipCombineRegionRegion(
1488 			nativeRegion, region ? region->nativeRegion : NULL,
1489 			CombineModeXor));
1490 }
1491 
Xor(const GraphicsPath * path)1492 __inline__ Status Region::Xor(const GraphicsPath *path)
1493 {
1494 	return updateStatus(DllExports::GdipCombineRegionPath(
1495 			nativeRegion, path ? path->nativePath : NULL,
1496 			CombineModeXor));
1497 }
1498 
1499 
1500 // GraphicsPath
1501 
IsOutlineVisible(REAL x,REAL y,const Pen * pen,const Graphics * g)1502 __inline__ BOOL GraphicsPath::IsOutlineVisible(REAL x, REAL y, const Pen *pen,
1503 		const Graphics *g) const
1504 {
1505 	BOOL result = FALSE;
1506 	updateStatus(DllExports::GdipIsOutlineVisiblePathPoint(
1507 			nativePath, x, y, pen ? pen->nativePen : NULL,
1508 			g ? g->nativeGraphics : NULL, &result));
1509 	return result;
1510 }
1511 
IsOutlineVisible(INT x,INT y,const Pen * pen,const Graphics * g)1512 __inline__ BOOL GraphicsPath::IsOutlineVisible(INT x, INT y, const Pen *pen,
1513 		const Graphics *g) const
1514 {
1515 	BOOL result = FALSE;
1516 	updateStatus(DllExports::GdipIsOutlineVisiblePathPointI(
1517 			nativePath, x, y, pen ? pen->nativePen : NULL,
1518 			g ? g->nativeGraphics : NULL, &result));
1519 	return result;
1520 }
1521 
IsOutlineVisible(const PointF & point,const Pen * pen,const Graphics * g)1522 __inline__ BOOL GraphicsPath::IsOutlineVisible(const PointF& point, const Pen *pen,
1523 		const Graphics *g) const
1524 {
1525 	BOOL result = FALSE;
1526 	updateStatus(DllExports::GdipIsOutlineVisiblePathPoint(
1527 			nativePath, point.X, point.Y,
1528 			pen ? pen->nativePen : NULL,
1529 			g ? g->nativeGraphics : NULL, &result));
1530 	return result;
1531 }
1532 
IsOutlineVisible(const Point & point,const Pen * pen,const Graphics * g)1533 __inline__ BOOL GraphicsPath::IsOutlineVisible(const Point& point, const Pen *pen,
1534 		const Graphics *g) const
1535 {
1536 	BOOL result = FALSE;
1537 	updateStatus(DllExports::GdipIsOutlineVisiblePathPointI(
1538 			nativePath, point.X, point.Y,
1539 			pen ? pen->nativePen : NULL,
1540 			g ? g->nativeGraphics : NULL, &result));
1541 	return result;
1542 }
1543 
IsVisible(REAL x,REAL y,const Graphics * g)1544 __inline__ BOOL GraphicsPath::IsVisible(REAL x, REAL y, const Graphics *g) const
1545 {
1546 	BOOL result = FALSE;
1547 	updateStatus(DllExports::GdipIsVisiblePathPoint(
1548 			nativePath, x, y,
1549 			g ? g->nativeGraphics : NULL, &result));
1550 	return result;
1551 }
IsVisible(INT x,INT y,const Graphics * g)1552 __inline__ BOOL GraphicsPath::IsVisible(INT x, INT y, const Graphics *g) const
1553 {
1554 	BOOL result = FALSE;
1555 	updateStatus(DllExports::GdipIsVisiblePathPointI(
1556 			nativePath, x, y,
1557 			g ? g->nativeGraphics : NULL, &result));
1558 	return result;
1559 }
1560 
IsVisible(const PointF & point,const Graphics * g)1561 __inline__ BOOL GraphicsPath::IsVisible(const PointF& point,
1562 		const Graphics *g) const
1563 {
1564 	BOOL result = FALSE;
1565 	updateStatus(DllExports::GdipIsVisiblePathPoint(
1566 			nativePath, point.X, point.Y,
1567 			g ? g->nativeGraphics : NULL, &result));
1568 	return result;
1569 }
1570 
IsVisible(const Point & point,const Graphics * g)1571 __inline__ BOOL GraphicsPath::IsVisible(const Point& point, const Graphics *g) const
1572 {
1573 	BOOL result = FALSE;
1574 	updateStatus(DllExports::GdipIsVisiblePathPointI(
1575 			nativePath, point.X, point.Y,
1576 			g ? g->nativeGraphics : NULL, &result));
1577 	return result;
1578 }
1579 
1580 
1581 // PathData
1582 
AllocateArrays(INT capacity)1583 __inline__ Status PathData::AllocateArrays(INT capacity)
1584 {
1585 	if (capacity < 0) {
1586 		return InvalidParameter;
1587 	} else if (Count < capacity) {
1588 		FreeArrays();
1589 
1590 		PointF *pointArray = (PointF*)
1591 			DllExports::GdipAlloc(capacity * sizeof(PointF));
1592 		if (!pointArray)
1593 			return OutOfMemory;
1594 
1595 		BYTE *typeArray = (BYTE*)
1596 			DllExports::GdipAlloc(capacity * sizeof(BYTE));
1597 		if (!typeArray) {
1598 			DllExports::GdipFree(pointArray);
1599 			return OutOfMemory;
1600 		}
1601 
1602 		Count = capacity;
1603 		Points = pointArray;
1604 		Types = typeArray;
1605 	}
1606 	return Ok;
1607 }
1608 
FreeArrays()1609 __inline__ VOID PathData::FreeArrays()
1610 {
1611 	if (Points) DllExports::GdipFree(Points);
1612 	if (Types) DllExports::GdipFree(Types);
1613 	Count = 0;
1614 	Points = NULL;
1615 	Types = NULL;
1616 }
1617 
1618 #endif /* __GDIPLUS_IMPL_H */
1619