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.

475 lines
13 KiB

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