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.

480 lines
12 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Abstract:
  6. *
  7. * Pen API related declarations
  8. *
  9. * Revision History:
  10. *
  11. * 12/09/1998 andrewgo
  12. * Flesh out pen interfaces.
  13. *
  14. * 12/08/1998 andrewgo
  15. * Created it.
  16. *
  17. \**************************************************************************/
  18. #ifndef _GDIPLUSPEN_H
  19. #define _GDIPLUSPEN_H
  20. //--------------------------------------------------------------------------
  21. // class for various pen types
  22. //--------------------------------------------------------------------------
  23. class Pen : public GdiplusBase
  24. {
  25. public:
  26. friend class GraphicsPath;
  27. friend class Graphics;
  28. // abstract Clone() can't be implemented here because it can't
  29. // new an object with pure virtual functions
  30. // Constructors
  31. Pen(IN const Color& color,
  32. IN REAL width = 1.0f)
  33. {
  34. Unit unit = UnitWorld;
  35. nativePen = NULL;
  36. lastResult = DllExports::GdipCreatePen1(color.GetValue(),
  37. width, unit, &nativePen);
  38. }
  39. Pen(IN const Brush* brush,
  40. IN REAL width = 1.0f)
  41. {
  42. Unit unit = UnitWorld;
  43. nativePen = NULL;
  44. lastResult = DllExports::GdipCreatePen2(brush->nativeBrush,
  45. width, unit, &nativePen);
  46. }
  47. ~Pen()
  48. {
  49. DllExports::GdipDeletePen(nativePen);
  50. }
  51. Pen* Clone() const
  52. {
  53. GpPen *clonePen = NULL;
  54. lastResult = DllExports::GdipClonePen(nativePen, &clonePen);
  55. return new Pen(clonePen, lastResult);
  56. }
  57. Status SetWidth(IN REAL width)
  58. {
  59. return SetStatus(DllExports::GdipSetPenWidth(nativePen, width));
  60. }
  61. REAL GetWidth() const
  62. {
  63. REAL width;
  64. SetStatus(DllExports::GdipGetPenWidth(nativePen, &width));
  65. return width;
  66. }
  67. // Set/get line caps: start, end, and dash
  68. // Line cap and join APIs by using LineCap and LineJoin enums.
  69. Status SetLineCap(IN LineCap startCap,
  70. IN LineCap endCap,
  71. IN LineCap dashCap)
  72. {
  73. return SetStatus(DllExports::GdipSetPenLineCap(nativePen,
  74. startCap, endCap, dashCap));
  75. }
  76. Status SetStartCap(IN LineCap startCap)
  77. {
  78. return SetStatus(DllExports::GdipSetPenStartCap(nativePen, startCap));
  79. }
  80. Status SetEndCap(IN LineCap endCap)
  81. {
  82. return SetStatus(DllExports::GdipSetPenEndCap(nativePen, endCap));
  83. }
  84. Status SetDashCap(IN LineCap dashCap)
  85. {
  86. return SetStatus(DllExports::GdipSetPenDashCap(nativePen, dashCap));
  87. }
  88. LineCap GetStartCap() const
  89. {
  90. LineCap startCap;
  91. SetStatus(DllExports::GdipGetPenStartCap(nativePen, &startCap));
  92. return startCap;
  93. }
  94. LineCap GetEndCap() const
  95. {
  96. LineCap endCap;
  97. SetStatus(DllExports::GdipGetPenEndCap(nativePen, &endCap));
  98. return endCap;
  99. }
  100. LineCap GetDashCap() const
  101. {
  102. LineCap dashCap;
  103. SetStatus(DllExports::GdipGetPenDashCap(nativePen, &dashCap));
  104. return dashCap;
  105. }
  106. // Set/get line join
  107. Status SetLineJoin(IN LineJoin lineJoin)
  108. {
  109. return SetStatus(DllExports::GdipSetPenLineJoin(nativePen, lineJoin));
  110. }
  111. LineJoin GetLineJoin() const
  112. {
  113. LineJoin lineJoin;
  114. SetStatus(DllExports::GdipGetPenLineJoin(nativePen, &lineJoin));
  115. return lineJoin;
  116. }
  117. Status SetCustomStartCap(IN const CustomLineCap* customCap)
  118. {
  119. GpCustomLineCap* nativeCap = NULL;
  120. if(customCap)
  121. nativeCap = customCap->nativeCap;
  122. return SetStatus(DllExports::GdipSetPenCustomStartCap(nativePen, nativeCap));
  123. }
  124. Status GetCustomStartCap(OUT CustomLineCap* customCap) const
  125. {
  126. if(!customCap)
  127. return SetStatus(InvalidParameter);
  128. return SetStatus(DllExports::GdipGetPenCustomStartCap(nativePen, &(customCap->nativeCap)));
  129. }
  130. Status SetCustomEndCap(IN const CustomLineCap* customCap)
  131. {
  132. GpCustomLineCap* nativeCap = NULL;
  133. if(customCap)
  134. nativeCap = customCap->nativeCap;
  135. return SetStatus(DllExports::GdipSetPenCustomEndCap(nativePen, nativeCap));
  136. }
  137. Status GetCustomEndCap(OUT CustomLineCap* customCap) const
  138. {
  139. if(!customCap)
  140. return SetStatus(InvalidParameter);
  141. return SetStatus(DllExports::GdipGetPenCustomEndCap(nativePen, &(customCap->nativeCap)));
  142. }
  143. Status SetMiterLimit(IN REAL miterLimit)
  144. {
  145. return SetStatus(DllExports::GdipSetPenMiterLimit(nativePen, miterLimit));
  146. }
  147. REAL GetMiterLimit() const
  148. {
  149. REAL miterLimit;
  150. SetStatus(DllExports::GdipGetPenMiterLimit(nativePen, &miterLimit));
  151. return miterLimit;
  152. }
  153. // Set/get pen mode
  154. Status SetAlignment(IN PenAlignment penAlignment)
  155. {
  156. return SetStatus(DllExports::GdipSetPenMode(nativePen, penAlignment));
  157. }
  158. PenAlignment GetAlignment() const
  159. {
  160. PenAlignment penAlignment;
  161. SetStatus(DllExports::GdipGetPenMode(nativePen, &penAlignment));
  162. return penAlignment;
  163. }
  164. // Set/get pen transform
  165. Status SetTransform(IN const Matrix* matrix)
  166. {
  167. return SetStatus(DllExports::GdipSetPenTransform(nativePen,
  168. matrix->nativeMatrix));
  169. }
  170. Status GetTransform(OUT Matrix* matrix) const
  171. {
  172. return SetStatus(DllExports::GdipGetPenTransform(nativePen, matrix->nativeMatrix));
  173. }
  174. Status ResetTransform()
  175. {
  176. return SetStatus(DllExports::GdipResetPenTransform(nativePen));
  177. }
  178. Status MultiplyTransform(IN Matrix* matrix,
  179. IN MatrixOrder order = MatrixOrderPrepend)
  180. {
  181. return SetStatus(DllExports::GdipMultiplyPenTransform(nativePen,
  182. matrix->nativeMatrix,
  183. order));
  184. }
  185. Status TranslateTransform(IN REAL dx,
  186. IN REAL dy,
  187. IN MatrixOrder order = MatrixOrderPrepend)
  188. {
  189. return SetStatus(DllExports::GdipTranslatePenTransform(nativePen,
  190. dx, dy, order));
  191. }
  192. Status ScaleTransform(IN REAL sx,
  193. IN REAL sy,
  194. IN MatrixOrder order = MatrixOrderPrepend)
  195. {
  196. return SetStatus(DllExports::GdipScalePenTransform(nativePen,
  197. sx, sy, order));
  198. }
  199. Status RotateTransform(IN REAL angle,
  200. IN MatrixOrder order = MatrixOrderPrepend)
  201. {
  202. return SetStatus(DllExports::GdipRotatePenTransform(nativePen,
  203. angle, order));
  204. }
  205. PenType GetPenType() const
  206. {
  207. PenType type;
  208. SetStatus(DllExports::GdipGetPenFillType(nativePen, &type));
  209. return type;
  210. }
  211. Status SetColor(IN const Color& color)
  212. {
  213. return SetStatus(DllExports::GdipSetPenColor(nativePen,
  214. color.GetValue()));
  215. }
  216. Status SetBrush(IN const Brush* brush)
  217. {
  218. return SetStatus(DllExports::GdipSetPenBrushFill(nativePen,
  219. brush->nativeBrush));
  220. }
  221. Status GetColor(OUT Color* color)
  222. {
  223. if (color == NULL)
  224. {
  225. return SetStatus(InvalidParameter);
  226. }
  227. PenType type = GetPenType();
  228. if (type != PenTypeSolidColor)
  229. {
  230. return WrongState;
  231. }
  232. ARGB argb;
  233. SetStatus(DllExports::GdipGetPenColor(nativePen,
  234. &argb));
  235. if (lastResult == Ok)
  236. {
  237. color->SetValue(argb);
  238. }
  239. return lastResult;
  240. }
  241. Brush* GetBrush() const
  242. {
  243. PenType type = GetPenType();
  244. Brush* brush = NULL;
  245. switch(type)
  246. {
  247. case PenTypeSolidColor:
  248. brush = new SolidBrush();
  249. break;
  250. case PenTypeHatchFill:
  251. brush = new HatchBrush();
  252. break;
  253. case PenTypeTextureFill:
  254. brush = new TextureBrush();
  255. break;
  256. case PenTypePathGradient:
  257. brush = new Brush();
  258. break;
  259. case PenTypeLinearGradient:
  260. brush = new LinearGradientBrush();
  261. break;
  262. default:
  263. break;
  264. }
  265. if(brush)
  266. {
  267. GpBrush* nativeBrush;
  268. SetStatus(DllExports::GdipGetPenBrushFill(nativePen, &nativeBrush));
  269. brush->SetNativeBrush(nativeBrush);
  270. }
  271. return brush;
  272. }
  273. DashStyle GetDashStyle() const
  274. {
  275. DashStyle dashStyle;
  276. SetStatus(DllExports::GdipGetPenDashStyle(nativePen, &dashStyle));
  277. return dashStyle;
  278. }
  279. Status SetDashStyle(IN DashStyle dashStyle)
  280. {
  281. return SetStatus(DllExports::GdipSetPenDashStyle(nativePen, dashStyle));
  282. }
  283. REAL GetDashOffset() const
  284. {
  285. REAL dashOffset;
  286. SetStatus(DllExports::GdipGetPenDashOffset(nativePen, &dashOffset));
  287. return dashOffset;
  288. }
  289. Status SetDashOffset(IN REAL dashOffset)
  290. {
  291. return SetStatus(DllExports::GdipSetPenDashOffset(nativePen, dashOffset));
  292. }
  293. Status SetDashPattern(IN const REAL* dashArray, IN INT count)
  294. {
  295. return SetStatus(DllExports::GdipSetPenDashArray(nativePen, dashArray,
  296. count));
  297. }
  298. INT GetDashPatternCount() const
  299. {
  300. INT count = 0;
  301. SetStatus(DllExports::GdipGetPenDashCount(nativePen, &count));
  302. return count;
  303. }
  304. Status GetDashPattern(OUT REAL* dashArray,
  305. IN INT count) const
  306. {
  307. if (dashArray == NULL || count <= 0)
  308. return SetStatus(InvalidParameter);
  309. return SetStatus(DllExports::GdipGetPenDashArray(nativePen,
  310. dashArray,
  311. count));
  312. }
  313. Status SetCompoundArray(IN const REAL* compoundArray,
  314. IN INT count)
  315. {
  316. return SetStatus(DllExports::GdipSetPenCompoundArray(nativePen, compoundArray,
  317. count));
  318. }
  319. INT GetCompoundArrayCount() const
  320. {
  321. INT count = 0;
  322. SetStatus(DllExports::GdipGetPenCompoundCount(nativePen, &count));
  323. return count;
  324. }
  325. Status GetCompoundArray(OUT REAL* compoundArray,
  326. IN INT count) const
  327. {
  328. if (compoundArray == NULL || count <= 0)
  329. return SetStatus(InvalidParameter);
  330. return SetStatus(DllExports::GdipGetPenCompoundArray(nativePen,
  331. compoundArray,
  332. count));
  333. }
  334. Status GetLastStatus() const
  335. {
  336. Status lastStatus = lastResult;
  337. lastResult = Ok;
  338. return lastStatus;
  339. }
  340. protected:
  341. Pen(const Pen& pen)
  342. {
  343. pen;
  344. SetStatus(NotImplemented);
  345. SetNativePen(NULL);
  346. }
  347. Pen& operator=(const Pen& pen)
  348. {
  349. pen;
  350. SetStatus(NotImplemented);
  351. return *this;
  352. }
  353. Pen(GpPen* nativePen, Status status)
  354. {
  355. lastResult = status;
  356. SetNativePen(nativePen);
  357. }
  358. VOID SetNativePen(GpPen* nativePen)
  359. {
  360. this->nativePen = nativePen;
  361. }
  362. Status SetStatus(Status status) const
  363. {
  364. if (status != Ok)
  365. return (lastResult = status);
  366. else
  367. return status;
  368. }
  369. protected:
  370. GpPen* nativePen;
  371. mutable Status lastResult;
  372. };
  373. #endif