Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

707 lines
20 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusHeaders.hpp
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Native C++ public header file
  12. *
  13. * Revision History:
  14. *
  15. * 03/03/1999 davidx
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #ifndef _GDIPLUSHEADERS_H
  20. #define _GDIPLUSHEADERS_H
  21. //--------------------------------------------------------------------------
  22. // Abstract base class for regions
  23. //--------------------------------------------------------------------------
  24. // Include the class declarations here and have inline class implementation
  25. // in separate file to avoid circular references.
  26. class Region : public GdiplusBase
  27. {
  28. public:
  29. friend class Graphics;
  30. Region();
  31. Region(IN const RectF& rect);
  32. Region(IN const Rect& rect);
  33. Region(IN const GraphicsPath* path);
  34. Region(IN const BYTE* regionData, IN INT size);
  35. Region(IN HRGN hRgn);
  36. static Region* FromHRGN(IN HRGN hRgn);
  37. ~Region();
  38. Region* Clone() const;
  39. Status MakeInfinite();
  40. Status MakeEmpty();
  41. // Get the size of the buffer needed for the GetData method
  42. UINT GetDataSize() const;
  43. // buffer - where to put the data
  44. // bufferSize - how big the buffer is (should be at least as big as GetDataSize())
  45. // sizeFilled - if not NULL, this is an OUT param that says how many bytes
  46. // of data were written to the buffer.
  47. Status GetData(OUT BYTE* buffer,
  48. IN UINT bufferSize,
  49. OUT UINT* sizeFilled = NULL) const;
  50. Status Intersect(IN const Rect& rect);
  51. Status Intersect(IN const RectF& rect);
  52. Status Intersect(IN const GraphicsPath* path);
  53. Status Intersect(IN const Region* region);
  54. Status Union(IN const Rect& rect);
  55. Status Union(IN const RectF& rect);
  56. Status Union(IN const GraphicsPath* path);
  57. Status Union(IN const Region* region);
  58. Status Xor(IN const Rect& rect);
  59. Status Xor(IN const RectF& rect);
  60. Status Xor(IN const GraphicsPath* path);
  61. Status Xor(IN const Region* region);
  62. Status Exclude(IN const Rect& rect);
  63. Status Exclude(IN const RectF& rect);
  64. Status Exclude(IN const GraphicsPath* path);
  65. Status Exclude(IN const Region* region);
  66. Status Complement(IN const Rect& rect);
  67. Status Complement(IN const RectF& rect);
  68. Status Complement(IN const GraphicsPath* path);
  69. Status Complement(IN const Region* region);
  70. Status Translate(IN REAL dx,
  71. IN REAL dy);
  72. Status Translate(IN INT dx,
  73. IN INT dy);
  74. Status Transform(IN const Matrix* matrix);
  75. Status GetBounds(OUT Rect* rect,
  76. IN const Graphics* g) const;
  77. Status GetBounds(OUT RectF* rect,
  78. IN const Graphics* g) const;
  79. HRGN GetHRGN (IN const Graphics * g) const;
  80. BOOL IsEmpty(IN const Graphics *g) const;
  81. BOOL IsInfinite(IN const Graphics *g) const;
  82. BOOL IsVisible(IN INT x,
  83. IN INT y,
  84. IN const Graphics* g = NULL) const
  85. {
  86. return IsVisible(Point(x, y), g);
  87. }
  88. BOOL IsVisible(IN const Point& point,
  89. IN const Graphics* g = NULL) const;
  90. BOOL IsVisible(IN REAL x,
  91. IN REAL y,
  92. IN const Graphics* g = NULL) const
  93. {
  94. return IsVisible(PointF(x, y), g);
  95. }
  96. BOOL IsVisible(IN const PointF& point,
  97. IN const Graphics* g = NULL) const;
  98. BOOL IsVisible(IN INT x,
  99. IN INT y,
  100. IN INT width,
  101. IN INT height,
  102. IN const Graphics* g) const
  103. {
  104. return IsVisible(Rect(x, y, width, height), g);
  105. }
  106. BOOL IsVisible(IN const Rect& rect,
  107. IN const Graphics* g = NULL) const;
  108. BOOL IsVisible(IN REAL x,
  109. IN REAL y,
  110. IN REAL width,
  111. IN REAL height,
  112. IN const Graphics* g = NULL) const
  113. {
  114. return IsVisible(RectF(x, y, width, height), g);
  115. }
  116. BOOL IsVisible(IN const RectF& rect,
  117. IN const Graphics* g = NULL) const;
  118. BOOL Equals(IN const Region* region,
  119. IN const Graphics* g) const;
  120. UINT GetRegionScansCount(IN const Matrix* matrix) const;
  121. Status GetRegionScans(IN const Matrix* matrix,
  122. OUT RectF* rects,
  123. OUT INT* count) const;
  124. Status GetRegionScans(IN const Matrix* matrix,
  125. OUT Rect* rects,
  126. OUT INT* count) const;
  127. Status GetLastStatus() const;
  128. protected:
  129. Region(const Region &region)
  130. {
  131. region; // reference parameter
  132. SetStatus(NotImplemented);
  133. }
  134. Region& operator=(const Region &region)
  135. {
  136. region; // reference parameter
  137. SetStatus(NotImplemented);
  138. return *this;
  139. }
  140. Status SetStatus(Status status) const
  141. {
  142. if (status != Ok)
  143. return (lastResult = status);
  144. else
  145. return status;
  146. }
  147. Region(GpRegion* nativeRegion);
  148. VOID SetNativeRegion(GpRegion* nativeRegion);
  149. protected:
  150. GpRegion* nativeRegion;
  151. mutable Status lastResult;
  152. };
  153. //--------------------------------------------------------------------------
  154. // Abstract base class for FontFamily
  155. //--------------------------------------------------------------------------
  156. class FontFamily : public GdiplusBase
  157. {
  158. public:
  159. friend class Font;
  160. friend class Graphics;
  161. friend class GraphicsPath;
  162. friend class FontCollection;
  163. FontFamily();
  164. FontFamily(
  165. IN const WCHAR *name,
  166. IN const FontCollection *fontCollection = NULL
  167. );
  168. ~FontFamily();
  169. static const FontFamily *GenericSansSerif();
  170. static const FontFamily *GenericSerif();
  171. static const FontFamily *GenericMonospace();
  172. Status GetFamilyName(
  173. OUT WCHAR name[LF_FACESIZE],
  174. IN LANGID language = 0
  175. ) const;
  176. // Copy operator
  177. FontFamily * Clone() const;
  178. BOOL IsAvailable() const
  179. {
  180. return (nativeFamily != NULL);
  181. };
  182. BOOL IsStyleAvailable(IN INT style) const;
  183. UINT16 GetEmHeight (IN INT style) const;
  184. UINT16 GetCellAscent (IN INT style) const;
  185. UINT16 GetCellDescent (IN INT style) const;
  186. UINT16 GetLineSpacing (IN INT style) const;
  187. ///////////////////////////////////////////////////////////
  188. Status GetLastStatus() const;
  189. protected:
  190. Status SetStatus(Status status) const;
  191. // private constructor for copy
  192. FontFamily(GpFontFamily * nativeFamily, Status status);
  193. ///////////////////////////////////////
  194. // Data members
  195. protected:
  196. GpFontFamily *nativeFamily;
  197. mutable Status lastResult;
  198. };
  199. static FontFamily *GenericSansSerifFontFamily = NULL;
  200. static FontFamily *GenericSerifFontFamily = NULL;
  201. static FontFamily *GenericMonospaceFontFamily = NULL;
  202. static BYTE GenericSansSerifFontFamilyBuffer[sizeof(FontFamily)] = {0};
  203. static BYTE GenericSerifFontFamilyBuffer [sizeof(FontFamily)] = {0};
  204. static BYTE GenericMonospaceFontFamilyBuffer[sizeof(FontFamily)] = {0};
  205. //--------------------------------------------------------------------------
  206. // Abstract base class for fonts
  207. //--------------------------------------------------------------------------
  208. class Font : public GdiplusBase
  209. {
  210. public:
  211. friend class Graphics;
  212. Font(IN HDC hdc);
  213. Font(IN HDC hdc,
  214. IN const LOGFONTA* logfont);
  215. Font(IN HDC hdc,
  216. IN const LOGFONTW* logfont);
  217. Font(
  218. IN const FontFamily * family,
  219. IN REAL emSize,
  220. IN INT style = FontStyleRegular,
  221. IN Unit unit = UnitPoint
  222. );
  223. Font(
  224. IN const WCHAR * familyName,
  225. IN REAL emSize,
  226. IN INT style = FontStyleRegular,
  227. IN Unit unit = UnitPoint,
  228. IN const FontCollection * fontCollection = NULL
  229. );
  230. Status GetLogFontA(IN const Graphics* g,
  231. OUT LOGFONTA * logfontA) const;
  232. Status GetLogFontW(IN const Graphics* g,
  233. OUT LOGFONTW * logfontW) const;
  234. Font* Clone() const;
  235. ~Font();
  236. BOOL IsAvailable() const;
  237. INT GetStyle() const;
  238. REAL GetSize() const;
  239. Unit GetUnit() const;
  240. Status GetLastStatus() const;
  241. REAL GetHeight(IN const Graphics *graphics = NULL) const;
  242. Status GetFamily(OUT FontFamily *family) const;
  243. protected:
  244. Font(GpFont* font, Status status);
  245. VOID SetNativeFont(GpFont *Font);
  246. Status SetStatus(Status status) const;
  247. protected:
  248. /*
  249. * handle to native line texture object
  250. */
  251. GpFont* nativeFont;
  252. mutable Status lastResult;
  253. };
  254. //--------------------------------------------------------------------------
  255. // Abstract base classes for font collections
  256. //--------------------------------------------------------------------------
  257. class FontCollection : public GdiplusBase
  258. {
  259. public:
  260. friend class FontFamily;
  261. FontCollection();
  262. virtual ~FontCollection();
  263. INT GetFamilyCount() const; // number of enumerable families in the collection
  264. Status GetFamilies( // enumerate the fonts in a collection
  265. IN INT numSought,
  266. OUT FontFamily * gpfamilies,
  267. OUT INT * numFound
  268. ) const;
  269. Status GetLastStatus() const;
  270. protected:
  271. Status SetStatus(Status status) const ;
  272. GpFontCollection *nativeFontCollection;
  273. mutable Status lastResult;
  274. };
  275. class InstalledFontCollection : public FontCollection
  276. {
  277. public:
  278. InstalledFontCollection();
  279. ~InstalledFontCollection();
  280. protected:
  281. // we will make these functions public in version 2
  282. Status InstallFontFile(IN const WCHAR* filename);
  283. Status UninstallFontFile(IN const WCHAR* filename);
  284. Status SetStatus(Status status) const ;
  285. };
  286. class PrivateFontCollection : public FontCollection
  287. {
  288. public:
  289. PrivateFontCollection();
  290. ~PrivateFontCollection();
  291. Status AddFontFile(IN const WCHAR* filename);
  292. Status AddMemoryFont(IN const VOID* memory,
  293. IN INT length);
  294. };
  295. //--------------------------------------------------------------------------
  296. // Abstract base class for bitmap image and metafile
  297. //--------------------------------------------------------------------------
  298. // !!! Note:
  299. // Include the class declarations here and have the inline class
  300. // implementation in a separate file. This is done to resolve a
  301. // circular dependency since one of the Bitmap methods needs to
  302. // access the private member nativeGraphics of the Graphics object.
  303. class Image : public GdiplusBase
  304. {
  305. public:
  306. friend class Brush;
  307. friend class TextureBrush;
  308. friend class Graphics;
  309. #ifndef DCR_USE_NEW_140782
  310. Image(
  311. IN const WCHAR* filename
  312. );
  313. Image(
  314. IN IStream* stream
  315. );
  316. static Image* FromFile(
  317. IN const WCHAR* filename
  318. );
  319. static Image* FromStream(
  320. IN IStream* stream
  321. );
  322. #else
  323. Image(
  324. IN const WCHAR* filename,
  325. IN BOOL useEmbeddedColorManagement = FALSE
  326. );
  327. Image(
  328. IN IStream* stream,
  329. IN BOOL useEmbeddedColorManagement = FALSE
  330. );
  331. static Image* FromFile(
  332. IN const WCHAR* filename,
  333. IN BOOL useEmbeddedColorManagement = FALSE
  334. );
  335. static Image* FromStream(
  336. IN IStream* stream,
  337. IN BOOL useEmbeddedColorManagement = FALSE
  338. );
  339. #endif
  340. virtual ~Image();
  341. virtual Image* Clone();
  342. Status Save(IN const WCHAR* filename,
  343. IN const CLSID* clsidEncoder,
  344. IN const EncoderParameters *encoderParams = NULL);
  345. Status Save(IN IStream* stream,
  346. IN const CLSID* clsidEncoder,
  347. IN const EncoderParameters *encoderParams = NULL);
  348. Status SaveAdd(IN const EncoderParameters* encoderParams);
  349. Status SaveAdd(IN Image* newImage,
  350. IN const EncoderParameters* encoderParams);
  351. ImageType GetType() const;
  352. Status GetPhysicalDimension(OUT SizeF* size);
  353. Status GetBounds(OUT RectF* srcRect,
  354. OUT Unit* srcUnit);
  355. UINT GetWidth();
  356. UINT GetHeight();
  357. REAL GetHorizontalResolution();
  358. REAL GetVerticalResolution();
  359. UINT GetFlags();
  360. Status GetRawFormat(OUT GUID *format);
  361. PixelFormat GetPixelFormat();
  362. INT GetPaletteSize();
  363. Status GetPalette(OUT ColorPalette* palette,
  364. IN INT size);
  365. Status SetPalette(IN const ColorPalette* palette);
  366. Image* GetThumbnailImage(IN UINT thumbWidth,
  367. IN UINT thumbHeight,
  368. IN GetThumbnailImageAbort callback = NULL,
  369. IN VOID* callbackData = NULL);
  370. UINT GetFrameDimensionsCount();
  371. Status GetFrameDimensionsList(OUT GUID* dimensionIDs,
  372. IN UINT count);
  373. UINT GetFrameCount(IN const GUID* dimensionID);
  374. Status SelectActiveFrame(IN const GUID* dimensionID,
  375. IN UINT frameIndex);
  376. UINT GetPropertyCount();
  377. Status GetPropertyIdList(IN UINT numOfProperty,
  378. OUT PROPID* list);
  379. UINT GetPropertyItemSize(IN PROPID propId);
  380. Status GetPropertyItem(IN PROPID propId,
  381. IN UINT propSize,
  382. OUT PropertyItem* buffer);
  383. Status GetPropertySize(OUT UINT* totalBufferSize,
  384. OUT UINT* numProperties);
  385. Status GetAllPropertyItems(IN UINT totalBufferSize,
  386. IN UINT numProperties,
  387. OUT PropertyItem* allItems);
  388. Status RemovePropertyItem(IN PROPID propId);
  389. Status SetPropertyItem(IN const PropertyItem* item);
  390. UINT GetEncoderParameterListSize(IN const CLSID* clsidEncoder);
  391. Status GetEncoderParameterList(IN const CLSID* clsidEncoder,
  392. IN UINT size,
  393. OUT EncoderParameters* buffer);
  394. // Support for Middle East localization (right-to-left mirroring)
  395. ImageLayout GetLayout() const;
  396. Status SetLayout(IN const ImageLayout layout);
  397. Status GetLastStatus() const;
  398. protected:
  399. Image() {}
  400. Image(GpImage *nativeImage, Status status);
  401. VOID SetNativeImage(GpImage* nativeImage);
  402. Status SetStatus(Status status) const
  403. {
  404. if (status != Ok)
  405. return (lastResult = status);
  406. else
  407. return status;
  408. }
  409. GpImage* nativeImage;
  410. mutable Status lastResult;
  411. mutable Status loadStatus;
  412. protected:
  413. // Disable copy constructor and assignment operator
  414. Image(IN const Image& C);
  415. Image& operator=(IN const Image& C);
  416. };
  417. class Bitmap : public Image
  418. {
  419. public:
  420. friend class Image;
  421. friend class CachedBitmap;
  422. Bitmap(
  423. IN const WCHAR *filename,
  424. IN BOOL useEmbeddedColorManagement = FALSE
  425. );
  426. Bitmap(
  427. IN IStream *stream,
  428. IN BOOL useEmbeddedColorManagement = FALSE
  429. );
  430. static Bitmap* FromFile(
  431. IN const WCHAR *filename,
  432. IN BOOL useEmbeddedColorManagement = FALSE
  433. );
  434. static Bitmap* FromStream(
  435. IN IStream *stream,
  436. IN BOOL useEmbeddedColorManagement = FALSE
  437. );
  438. Bitmap(IN INT width,
  439. IN INT height,
  440. IN INT stride, PixelFormat format,
  441. IN BYTE* scan0);
  442. Bitmap(IN INT width,
  443. IN INT height,
  444. IN PixelFormat format = PixelFormat32bppARGB);
  445. Bitmap(IN INT width,
  446. IN INT height,
  447. IN Graphics* target);
  448. Bitmap* Clone(IN const Rect& rect,
  449. IN PixelFormat format);
  450. Bitmap* Clone(IN INT x,
  451. IN INT y,
  452. IN INT width,
  453. IN INT height,
  454. IN PixelFormat format);
  455. Bitmap* Clone(IN const RectF& rect,
  456. IN PixelFormat format);
  457. Bitmap* Clone(IN REAL x,
  458. IN REAL y,
  459. IN REAL width,
  460. IN REAL height,
  461. IN PixelFormat format);
  462. Status LockBits(IN const Rect& rect,
  463. IN UINT flags,
  464. IN PixelFormat format,
  465. OUT BitmapData* lockedBitmapData);
  466. Status UnlockBits(IN BitmapData* lockedBitmapData);
  467. Status GetPixel(IN INT x,
  468. IN INT y,
  469. OUT Color *color);
  470. Status SetPixel(IN INT x,
  471. IN INT y,
  472. IN const Color &color);
  473. Status SetResolution(IN REAL xdpi,
  474. IN REAL ydpi);
  475. // GDI interop:
  476. Bitmap(IN IDirectDrawSurface7* surface);
  477. Bitmap(IN const BITMAPINFO* gdiBitmapInfo,
  478. IN VOID* gdiBitmapData);
  479. Bitmap(IN HBITMAP hbm,
  480. IN HPALETTE hpal);
  481. Bitmap(IN HICON hicon);
  482. Bitmap(IN HINSTANCE hInstance,
  483. IN const WCHAR * bitmapName);
  484. static Bitmap* FromDirectDrawSurface7(IN IDirectDrawSurface7* surface);
  485. static Bitmap* FromBITMAPINFO(IN const BITMAPINFO* gdiBitmapInfo,
  486. IN VOID* gdiBitmapData);
  487. static Bitmap* FromHBITMAP(IN HBITMAP hbm,
  488. IN HPALETTE hpal);
  489. static Bitmap* FromHICON(IN HICON hicon);
  490. static Bitmap* FromResource(IN HINSTANCE hInstance,
  491. IN const WCHAR * bitmapName);
  492. Status GetHBITMAP(IN const Color& colorBackground,
  493. OUT HBITMAP *hbmReturn);
  494. Status GetHICON(HICON *hicon);
  495. protected:
  496. Bitmap(GpBitmap *nativeBitmap);
  497. };
  498. class CustomLineCap : public GdiplusBase
  499. {
  500. public:
  501. friend class Pen;
  502. CustomLineCap(
  503. IN const GraphicsPath* fillPath,
  504. IN const GraphicsPath* strokePath,
  505. IN LineCap baseCap = LineCapFlat,
  506. IN REAL baseInset = 0
  507. );
  508. virtual ~CustomLineCap();
  509. CustomLineCap* Clone() const;
  510. Status SetStrokeCap(IN LineCap strokeCap)
  511. {
  512. // This changes both start and and caps.
  513. return SetStrokeCaps(strokeCap, strokeCap);
  514. }
  515. Status SetStrokeCaps(IN LineCap startCap,
  516. IN LineCap endCap);
  517. Status GetStrokeCaps(OUT LineCap* startCap,
  518. OUT LineCap* endCap) const;
  519. Status SetStrokeJoin(IN LineJoin lineJoin);
  520. LineJoin GetStrokeJoin() const;
  521. Status SetBaseCap(IN LineCap baseCap);
  522. LineCap GetBaseCap() const;
  523. Status SetBaseInset(IN REAL inset);
  524. REAL GetBaseInset() const;
  525. Status SetWidthScale(IN REAL widthScale);
  526. REAL GetWidthScale() const;
  527. protected:
  528. CustomLineCap();
  529. CustomLineCap(const CustomLineCap& customLineCap)
  530. {
  531. customLineCap;
  532. SetStatus(NotImplemented);
  533. }
  534. CustomLineCap& operator=(const CustomLineCap& customLineCap)
  535. {
  536. customLineCap;
  537. SetStatus(NotImplemented);
  538. return *this;
  539. }
  540. CustomLineCap(GpCustomLineCap* nativeCap, Status status)
  541. {
  542. lastResult = status;
  543. SetNativeCap(nativeCap);
  544. }
  545. VOID SetNativeCap(GpCustomLineCap* nativeCap)
  546. {
  547. this->nativeCap = nativeCap;
  548. }
  549. Status SetStatus(Status status) const
  550. {
  551. if (status != Ok)
  552. return (lastResult = status);
  553. else
  554. return status;
  555. }
  556. protected:
  557. GpCustomLineCap* nativeCap;
  558. mutable Status lastResult;
  559. };
  560. class CachedBitmap : public GdiplusBase
  561. {
  562. friend Graphics;
  563. public:
  564. CachedBitmap(IN Bitmap *bitmap,
  565. IN Graphics *graphics);
  566. virtual ~CachedBitmap();
  567. Status GetLastStatus() const;
  568. protected:
  569. GpCachedBitmap *nativeCachedBitmap;
  570. mutable Status lastResult;
  571. };
  572. #endif // !_GDIPLUSHEADERS.HPP