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.

747 lines
15 KiB

  1. #ifndef GDIPSHAPE_HPP
  2. #define GDIPSHAPE_HPP
  3. class TestShapeInterface;
  4. class TestShape;
  5. class LineShape;
  6. class ArcShape;
  7. class BezierShape;
  8. class RectShape;
  9. class EllipseShape;
  10. class PieShape;
  11. class PolygonShape;
  12. class CurveShape;
  13. class ClosedCurveShape;
  14. class TestRectGradShape;
  15. class TestRadialGradShape;
  16. class TestTriangleGradShape;
  17. class TestPathGradShape;
  18. class TestShapeInterface : public TestConfigureInterface,
  19. public TestDialogInterface
  20. {
  21. public:
  22. // initialize shape parameters to that of compatible shape
  23. virtual VOID Initialize(TestShape *shape) = 0;
  24. // add point to shape
  25. virtual BOOL AddPoint(HWND hwnd, Point pt) = 0;
  26. // user indicates we're done shape
  27. virtual VOID DoneShape(HWND hwnd) = 0;
  28. // last point added directly by a user
  29. virtual BOOL EndPoint(HWND hwnd, Point pt) = 0;
  30. // remove last control point from shape
  31. virtual BOOL RemovePoint(HWND hwnd) = 0;
  32. // do we encapsulate an entire shape?
  33. virtual BOOL IsComplete() = 0;
  34. // are there no control points for this shape?
  35. virtual BOOL IsEmpty() = 0;
  36. // draw control points ONLY
  37. virtual VOID DrawPoints(Graphics* g) = 0;
  38. // draw entire shape (no control points)
  39. virtual VOID DrawShape(Graphics* g) = 0;
  40. // add shape to path if complete
  41. virtual VOID AddToPath(GraphicsPath* path) = 0;
  42. // write instructions to create function
  43. virtual VOID AddToFile(OutputFile* outfile) = 0;
  44. // get type of shape
  45. virtual INT GetType() = 0;
  46. // return DC containing shape picture
  47. virtual HDC CreatePictureDC(HWND hwnd, RECT *rect) = 0;
  48. };
  49. class TestShape: public TestShapeInterface
  50. {
  51. public:
  52. TestShape() : pen(NULL),
  53. brush(NULL),
  54. done(FALSE),
  55. shapeName(NULL),
  56. disabled(FALSE)
  57. {
  58. pts.Reset();
  59. // !! hack for distinct names
  60. static INT shapeCount = 0;
  61. shapeName = (LPTSTR)malloc(sizeof(TCHAR)*100);
  62. sprintf(shapeName, _T("Shape (%d)"), shapeCount++);
  63. hdcPic = NULL;
  64. }
  65. ~TestShape()
  66. {
  67. if (hdcPic)
  68. DeleteDC(hdcPic);
  69. delete pen;
  70. delete brush;
  71. if (shapeName)
  72. free(shapeName);
  73. }
  74. // useful helper functions
  75. static TestShape* CreateNewShape(INT type);
  76. // temporary overload for those who don't implement these.
  77. virtual VOID Initialize()
  78. {
  79. };
  80. virtual VOID Initialize(TestShape *shape)
  81. {
  82. this->Initialize();
  83. };
  84. virtual HDC CreatePictureDC(HWND hwnd, RECT *rect);
  85. virtual VOID SetBrush(TestBrush *newbrush)
  86. {
  87. delete brush;
  88. brush = newbrush;
  89. }
  90. virtual VOID SetPen(TestPen *newpen)
  91. {
  92. delete pen;
  93. pen = newpen;
  94. }
  95. virtual TestBrush* GetBrush()
  96. {
  97. return brush;
  98. }
  99. virtual TestPen* GetPen()
  100. {
  101. return pen;
  102. }
  103. virtual VOID SetDisabled(BOOL disabled)
  104. {
  105. this->disabled = disabled;
  106. }
  107. virtual BOOL GetDisabled()
  108. {
  109. return disabled;
  110. }
  111. virtual BOOL EndPoint(HWND hwnd, Point pt);
  112. virtual BOOL RemovePoint(HWND hwnd);
  113. virtual VOID DrawPoints(Graphics* g);
  114. virtual BOOL MoveControlPoint(Point origPt, Point newPt);
  115. virtual VOID AddToPath(GraphicsPath* path);
  116. virtual VOID AddToFile(OutputFile* outfile);
  117. virtual BOOL IsEmpty()
  118. {
  119. return (pts.GetCount() == 0);
  120. }
  121. virtual INT GetCount()
  122. {
  123. return pts.GetCount();
  124. }
  125. virtual INT GetType()
  126. {
  127. ASSERT(FALSE);
  128. return -1;
  129. }
  130. virtual LPTSTR GetShapeName()
  131. {
  132. // !! alter name based on Disabled/Not disabled?!?
  133. return shapeName;
  134. }
  135. /*
  136. virtual INT* ShapeCount()
  137. {
  138. static INT shapeCount = 0;
  139. return &shapeCount;
  140. }
  141. virtual INT* RevCount()
  142. {
  143. static INT revCount = 0;
  144. return &revCount;
  145. }
  146. virtual TestShape* Clone()
  147. {
  148. TestShape* newShape = new TestShape();
  149. *newShape = *this;
  150. // clone GDI+ brush and pen
  151. newShape->brush = brush->Clone();
  152. newShape->pen = pen->Clone();
  153. // make extra copy of dynamic point array and shape name
  154. newShape->pts.RenewDataBuffer();
  155. }
  156. */
  157. public:
  158. // for use by other objects in system for temporary storage
  159. DWORD dwFlags;
  160. protected:
  161. TestBrush *brush;
  162. TestPen *pen;
  163. PointArray pts;
  164. BOOL done;
  165. LPTSTR shapeName;
  166. BOOL disabled;
  167. HDC hdcPic;
  168. };
  169. class LineShape : public TestShape
  170. {
  171. public:
  172. friend class LineShape;
  173. // Shape usage methods
  174. virtual VOID Initialize(TestShape *shape);
  175. virtual BOOL AddPoint(HWND hwnd, Point pt);
  176. virtual VOID DoneShape(HWND hwnd);
  177. virtual BOOL RemovePoint(HWND hwnd);
  178. virtual BOOL IsComplete();
  179. virtual VOID DrawShape(Graphics* g);
  180. virtual VOID AddToPath(GraphicsPath* path);
  181. virtual VOID AddToFile(OutputFile* outfile);
  182. // Configuration Interface
  183. virtual BOOL ChangeSettings(HWND hwnd);
  184. virtual VOID Initialize();
  185. // Dialog Management Interface
  186. virtual VOID InitDialog(HWND hwnd);
  187. virtual BOOL SaveValues(HWND hwnd);
  188. virtual BOOL ProcessDialog(HWND hwnd,
  189. UINT msg,
  190. WPARAM wParam,
  191. LPARAM lParam);
  192. virtual INT GetType()
  193. {
  194. return LineType;
  195. }
  196. };
  197. class ArcShape : public TestShape
  198. {
  199. public:
  200. friend class ArcShape;
  201. // Shape usage methods
  202. virtual VOID Initialize(TestShape *shape);
  203. virtual BOOL AddPoint(HWND hwnd, Point pt);
  204. virtual VOID DoneShape(HWND hwnd);
  205. virtual BOOL RemovePoint(HWND hwnd);
  206. virtual BOOL IsComplete();
  207. virtual VOID DrawShape(Graphics* g);
  208. virtual VOID AddToPath(GraphicsPath* path);
  209. virtual VOID AddToFile(OutputFile* outfile);
  210. // Configuration Interface
  211. virtual BOOL ChangeSettings(HWND hwnd);
  212. virtual VOID Initialize();
  213. // Dialog Management Interface
  214. virtual VOID InitDialog(HWND hwnd);
  215. virtual BOOL SaveValues(HWND hwnd);
  216. virtual BOOL ProcessDialog(HWND hwnd,
  217. UINT msg,
  218. WPARAM wParam,
  219. LPARAM lParam);
  220. virtual INT GetType()
  221. {
  222. return ArcType;
  223. }
  224. private:
  225. REAL start;
  226. REAL sweep;
  227. BOOL popup;
  228. };
  229. class BezierShape : public TestShape
  230. {
  231. public:
  232. friend class BezierShape;
  233. // Shape usage methods
  234. virtual VOID Initialize(TestShape *shape);
  235. virtual BOOL AddPoint(HWND hwnd, Point pt);
  236. virtual VOID DoneShape(HWND hwnd);
  237. virtual BOOL RemovePoint(HWND hwnd);
  238. virtual BOOL IsComplete();
  239. virtual VOID DrawShape(Graphics* g);
  240. virtual VOID AddToPath(GraphicsPath* path);
  241. virtual VOID AddToFile(OutputFile* outfile);
  242. // Configuration Interface
  243. virtual BOOL ChangeSettings(HWND hwnd);
  244. virtual VOID Initialize();
  245. // Dialog Management Interface
  246. virtual VOID InitDialog(HWND hwnd);
  247. virtual BOOL SaveValues(HWND hwnd);
  248. virtual BOOL ProcessDialog(HWND hwnd,
  249. UINT msg,
  250. WPARAM wParam,
  251. LPARAM lParam);
  252. virtual INT GetType()
  253. {
  254. return BezierType;
  255. }
  256. };
  257. class RectShape : public TestShape
  258. {
  259. public:
  260. friend class RectShape;
  261. // Shape usage methods
  262. virtual VOID Initialize(TestShape *shape);
  263. virtual BOOL AddPoint(HWND hwnd, Point pt);
  264. virtual VOID DoneShape(HWND hwnd);
  265. virtual BOOL RemovePoint(HWND hwnd);
  266. virtual BOOL IsComplete();
  267. virtual VOID DrawShape(Graphics* g);
  268. virtual VOID AddToPath(GraphicsPath* path);
  269. virtual VOID AddToFile(OutputFile* outfile);
  270. // Configuration Interface
  271. virtual BOOL ChangeSettings(HWND hwnd);
  272. virtual VOID Initialize();
  273. // Dialog Management Interface
  274. virtual VOID InitDialog(HWND hwnd);
  275. virtual BOOL SaveValues(HWND hwnd);
  276. virtual BOOL ProcessDialog(HWND hwnd,
  277. UINT msg,
  278. WPARAM wParam,
  279. LPARAM lParam);
  280. virtual INT GetType()
  281. {
  282. return RectType;
  283. }
  284. };
  285. class EllipseShape : public TestShape
  286. {
  287. public:
  288. friend class EllipseShape;
  289. // Shape usage methods
  290. virtual VOID Initialize(TestShape *shape);
  291. virtual BOOL AddPoint(HWND hwnd, Point pt);
  292. virtual VOID DoneShape(HWND hwnd);
  293. virtual BOOL RemovePoint(HWND hwnd);
  294. virtual BOOL IsComplete();
  295. virtual VOID DrawShape(Graphics* g);
  296. virtual VOID AddToPath(GraphicsPath* path);
  297. virtual VOID AddToFile(OutputFile* outfile);
  298. // Configuration Interface
  299. virtual BOOL ChangeSettings(HWND hwnd);
  300. virtual VOID Initialize();
  301. // Dialog Management Interface
  302. virtual VOID InitDialog(HWND hwnd);
  303. virtual BOOL SaveValues(HWND hwnd);
  304. virtual BOOL ProcessDialog(HWND hwnd,
  305. UINT msg,
  306. WPARAM wParam,
  307. LPARAM lParam);
  308. virtual INT GetType()
  309. {
  310. return EllipseType;
  311. }
  312. };
  313. class PieShape : public TestShape
  314. {
  315. public:
  316. friend class PieShape;
  317. // Shape usage methods
  318. virtual VOID Initialize(TestShape *shape);
  319. virtual BOOL AddPoint(HWND hwnd, Point pt);
  320. virtual VOID DoneShape(HWND hwnd);
  321. virtual BOOL RemovePoint(HWND hwnd);
  322. virtual BOOL IsComplete();
  323. virtual VOID DrawShape(Graphics* g);
  324. virtual VOID AddToPath(GraphicsPath* path);
  325. virtual VOID AddToFile(OutputFile* outfile);
  326. // Configuration Interface
  327. virtual BOOL ChangeSettings(HWND hwnd);
  328. virtual VOID Initialize();
  329. // Dialog Management Interface
  330. virtual VOID InitDialog(HWND hwnd);
  331. virtual BOOL SaveValues(HWND hwnd);
  332. virtual BOOL ProcessDialog(HWND hwnd,
  333. UINT msg,
  334. WPARAM wParam,
  335. LPARAM lParam);
  336. virtual INT GetType()
  337. {
  338. return PieType;
  339. }
  340. private:
  341. REAL start;
  342. REAL sweep;
  343. BOOL popup;
  344. };
  345. class PolygonShape : public TestShape
  346. {
  347. public:
  348. friend class PolygonShape;
  349. // Shape usage methods
  350. virtual VOID Initialize(TestShape *shape);
  351. virtual BOOL AddPoint(HWND hwnd, Point pt);
  352. virtual VOID DoneShape(HWND hwnd);
  353. virtual BOOL RemovePoint(HWND hwnd);
  354. virtual BOOL IsComplete();
  355. virtual VOID DrawShape(Graphics* g);
  356. virtual VOID AddToPath(GraphicsPath* path);
  357. virtual VOID AddToFile(OutputFile* outfile);
  358. // Configuration Interface
  359. virtual BOOL ChangeSettings(HWND hwnd);
  360. virtual VOID Initialize();
  361. // Dialog Management Interface
  362. virtual VOID InitDialog(HWND hwnd);
  363. virtual BOOL SaveValues(HWND hwnd);
  364. virtual BOOL ProcessDialog(HWND hwnd,
  365. UINT msg,
  366. WPARAM wParam,
  367. LPARAM lParam);
  368. virtual INT GetType()
  369. {
  370. return PolygonType;
  371. }
  372. };
  373. class CurveShape : public TestShape
  374. {
  375. public:
  376. friend class CurveShape;
  377. // Shape usage methods
  378. virtual VOID Initialize(TestShape *shape);
  379. virtual BOOL AddPoint(HWND hwnd, Point pt);
  380. virtual VOID DoneShape(HWND hwnd);
  381. virtual BOOL RemovePoint(HWND hwnd);
  382. virtual BOOL IsComplete();
  383. virtual VOID DrawShape(Graphics* g);
  384. virtual VOID AddToPath(GraphicsPath* path);
  385. virtual VOID AddToFile(OutputFile* outfile);
  386. // Configuration Interface
  387. virtual BOOL ChangeSettings(HWND hwnd);
  388. virtual VOID Initialize();
  389. // Dialog Management Interface
  390. virtual VOID InitDialog(HWND hwnd);
  391. virtual BOOL SaveValues(HWND hwnd);
  392. virtual BOOL ProcessDialog(HWND hwnd,
  393. UINT msg,
  394. WPARAM wParam,
  395. LPARAM lParam);
  396. virtual INT GetType()
  397. {
  398. return CurveType;
  399. }
  400. private:
  401. REAL tension;
  402. INT offset;
  403. INT numSegments;
  404. BOOL popup;
  405. };
  406. class ClosedCurveShape : public TestShape
  407. {
  408. public:
  409. friend class ClosedCurveShape;
  410. // Shape usage methods
  411. virtual VOID Initialize(TestShape *shape);
  412. virtual BOOL AddPoint(HWND hwnd, Point pt);
  413. virtual VOID DoneShape(HWND hwnd);
  414. virtual BOOL RemovePoint(HWND hwnd);
  415. virtual BOOL IsComplete();
  416. virtual VOID DrawShape(Graphics* g);
  417. virtual VOID AddToPath(GraphicsPath* path);
  418. virtual VOID AddToFile(OutputFile* outfile);
  419. // Configuration Interface
  420. virtual BOOL ChangeSettings(HWND hwnd);
  421. virtual VOID Initialize();
  422. // Dialog Management Interface
  423. virtual VOID InitDialog(HWND hwnd);
  424. virtual BOOL SaveValues(HWND hwnd);
  425. virtual BOOL ProcessDialog(HWND hwnd,
  426. UINT msg,
  427. WPARAM wParam,
  428. LPARAM lParam);
  429. virtual INT GetType()
  430. {
  431. return ClosedCurveType;
  432. }
  433. private:
  434. REAL tension;
  435. BOOL popup;
  436. };
  437. //*******************************************************************
  438. //
  439. // TestGradShapeInterface
  440. //
  441. //
  442. //
  443. //*******************************************************************
  444. class TestGradShape : public TestShape
  445. {
  446. public:
  447. TestGradShape()
  448. {
  449. argb.Reset();
  450. }
  451. virtual VOID DrawPoints(Graphics* g);
  452. protected:
  453. INT FindControlPoint(Point pt);
  454. INT FindLocationToInsert(Point pt);
  455. ARGBArray argb;
  456. INT curIndex;
  457. ARGB tmpArgb;
  458. };
  459. //*******************************************************************
  460. //
  461. // TestTriangleGradShape
  462. //
  463. //
  464. //
  465. //*******************************************************************
  466. #define TriangleCount 3
  467. class TestTriangleGradShape : public TestGradShape
  468. {
  469. public:
  470. TestTriangleGradShape()
  471. {
  472. argb.Reset();
  473. blend[0] = blend[1] = blend[2] = NULL;
  474. gdiBrush = NULL;
  475. }
  476. ~TestTriangleGradShape()
  477. {
  478. for (INT i = 0; i < 3; i++)
  479. if (blend[i])
  480. free(blend[i]);
  481. delete gdiBrush;
  482. }
  483. // Shape usage methods
  484. virtual VOID Initialize(TestShape *shape);
  485. virtual BOOL AddPoint(HWND hwnd, Point pt);
  486. virtual VOID DoneShape(HWND hwnd);
  487. virtual BOOL EndPoint(HWND hwnd, Point pt);
  488. virtual BOOL RemovePoint(HWND hwnd);
  489. virtual BOOL IsComplete();
  490. virtual VOID DrawShape(Graphics* g);
  491. virtual BOOL MoveControlPoint(Point origPt, Point newPt);
  492. // Configuration Interface
  493. virtual BOOL ChangeSettings(HWND hwnd);
  494. virtual VOID Initialize();
  495. // Dialog Management Interface
  496. virtual VOID InitDialog(HWND hwnd);
  497. virtual BOOL SaveValues(HWND hwnd);
  498. virtual BOOL ProcessDialog(HWND hwnd,
  499. UINT msg,
  500. WPARAM wParam,
  501. LPARAM lParam);
  502. VOID Initialize(Point* pts,
  503. ARGB* argb,
  504. REAL** blend,
  505. INT* blendCount);
  506. Point* GetPoints()
  507. {
  508. return pts.GetDataBuffer();
  509. }
  510. ARGB* GetARGB()
  511. {
  512. return argb.GetDataBuffer();
  513. }
  514. REAL** GetBlend()
  515. {
  516. return &blend[0];
  517. }
  518. INT* GetBlendCount()
  519. {
  520. return &count[0];
  521. }
  522. private:
  523. TriangleGradientBrush* gdiBrush;
  524. REAL* blend[3];
  525. INT count[3];
  526. };
  527. //*******************************************************************
  528. //
  529. // TestPathGradShape
  530. //
  531. //
  532. //
  533. //*******************************************************************
  534. class TestPathGradShape : public TestGradShape
  535. {
  536. public:
  537. TestPathGradShape()
  538. {
  539. argb.Reset();
  540. surroundBlend = centerBlend = NULL;
  541. surroundCount = centerCount = 0;
  542. gdiBrush = NULL;
  543. }
  544. ~TestPathGradShape()
  545. {
  546. if (surroundBlend)
  547. free(surroundBlend);
  548. if (centerBlend)
  549. free(centerBlend);
  550. delete gdiBrush;
  551. }
  552. // Shape usage methods
  553. virtual VOID Initialize(TestShape *shape);
  554. virtual BOOL AddPoint(HWND hwnd, Point pt);
  555. virtual VOID DoneShape(HWND hwnd);
  556. virtual BOOL EndPoint(HWND hwnd, Point pt);
  557. virtual BOOL RemovePoint(HWND hwnd);
  558. virtual BOOL IsComplete();
  559. virtual VOID DrawShape(Graphics* g);
  560. virtual BOOL MoveControlPoint(Point origPt, Point newPt);
  561. // Configuration Interface
  562. virtual BOOL ChangeSettings(HWND hwnd);
  563. virtual VOID Initialize();
  564. // Dialog Management Interface
  565. virtual VOID InitDialog(HWND hwnd);
  566. virtual BOOL SaveValues(HWND hwnd);
  567. virtual BOOL ProcessDialog(HWND hwnd,
  568. UINT msg,
  569. WPARAM wParam,
  570. LPARAM lParam);
  571. VOID Initialize(PointArray* pts,
  572. ARGBArray* argb,
  573. REAL* surroundBlend,
  574. INT surroundColor,
  575. REAL* centerBlend,
  576. INT centerColor);
  577. Point* GetPoints()
  578. {
  579. return pts.GetDataBuffer();
  580. }
  581. ARGB* GetARGB()
  582. {
  583. return argb.GetDataBuffer();
  584. }
  585. REAL* GetCenterBlend()
  586. {
  587. return centerBlend;
  588. }
  589. INT GetCenterBlendCount()
  590. {
  591. return centerCount;
  592. }
  593. REAL* GetSurroundBlend()
  594. {
  595. return surroundBlend;
  596. }
  597. INT GetSurroundBlendCount()
  598. {
  599. return surroundCount;
  600. }
  601. private:
  602. PathGradientBrush* gdiBrush;
  603. REAL* surroundBlend;
  604. REAL* centerBlend;
  605. INT surroundCount, centerCount;
  606. };
  607. #endif // _GDIPSHAPE_HPP