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.

1108 lines
22 KiB

  1. #include "gdiptest.h"
  2. //*******************************************************************
  3. //
  4. // AllBrushDialog
  5. //
  6. //
  7. //
  8. //*******************************************************************
  9. inline VOID NotImplementedBox()
  10. {
  11. MessageBox(NULL, _T("Not Implemented") , _T(""),MB_OK);
  12. };
  13. inline VOID WarningBox(TCHAR* string)
  14. {
  15. MessageBox(NULL, string, _T(""), MB_OK);
  16. };
  17. VOID WarningBeep()
  18. {
  19. Beep(5000 /* hertz */, 400 /* milliseconds */);
  20. }
  21. Brush* blackBrush = NULL;
  22. Brush* backBrush = NULL;
  23. Pen* blackPen = NULL;
  24. Color* blackColor = NULL;
  25. const TCHAR* tabStr = _T(" ");
  26. const TCHAR* formatList[numFormats] =
  27. {
  28. _T("CPP File"),
  29. _T("Java File"),
  30. _T("VML File")
  31. };
  32. const FormatType formatValue[numFormats] =
  33. {
  34. CPPFile,
  35. JavaFile,
  36. VMLFile
  37. };
  38. const TCHAR* shapeList[numShapes] =
  39. {
  40. _T("Line"),
  41. _T("Arc"),
  42. _T("Bezier"),
  43. _T("Rectangle"),
  44. _T("Ellipse"),
  45. _T("Pie"),
  46. _T("Polygon"),
  47. _T("Curve (Spline)"),
  48. _T("Closed Curve")
  49. };
  50. const INT shapeValue[numShapes] =
  51. {
  52. LineType,
  53. ArcType,
  54. BezierType,
  55. RectType,
  56. EllipseType,
  57. PieType,
  58. PolygonType,
  59. CurveType,
  60. ClosedCurveType
  61. };
  62. const INT inverseShapeValue[numShapes] = // index by ShapeType
  63. {
  64. 0,
  65. 1,
  66. 2,
  67. 3,
  68. 4,
  69. 5,
  70. 6,
  71. 7,
  72. 8
  73. };
  74. const TCHAR* brushList[numBrushes] =
  75. {
  76. _T("Solid"),
  77. _T("Texture (Bitmap)"),
  78. _T("Rectangle Gradient"),
  79. _T("Radial Gradient"),
  80. _T("Triangle Gradient"),
  81. _T("Polygon Gradient"),
  82. _T("Hatch")
  83. };
  84. const INT brushValue[numBrushes] =
  85. {
  86. SolidColorBrush,
  87. TextureFillBrush,
  88. RectGradBrush,
  89. RadialGradBrush,
  90. TriangleGradBrush,
  91. PathGradBrush,
  92. HatchFillBrush
  93. };
  94. const INT inverseBrushValue[numBrushes] = // index by BrushType
  95. {
  96. 0,
  97. 6,
  98. 1,
  99. 2,
  100. 3,
  101. 4,
  102. 5
  103. };
  104. const TCHAR* capList[numCaps] =
  105. {
  106. _T("Square"),
  107. _T("Round"),
  108. _T("Flat"),
  109. _T("Arrow"),
  110. _T("Diamond"),
  111. _T("Round")
  112. };
  113. const TCHAR* capStr[numCaps] =
  114. {
  115. _T("SquareCap"),
  116. _T("RoundCap"),
  117. _T("FlatCap"),
  118. _T("ArrowAnchor"),
  119. _T("DiamondAnchor"),
  120. _T("RoundAnchor")
  121. };
  122. const LineCap capValue[numCaps] =
  123. {
  124. SquareCap,
  125. RoundCap,
  126. FlatCap,
  127. ArrowAnchor,
  128. DiamondAnchor,
  129. RoundAnchor
  130. };
  131. const TCHAR* dashCapList[numDashCaps] =
  132. {
  133. _T("Flat"),
  134. _T("Round"),
  135. _T("Triangle")
  136. };
  137. const TCHAR* dashCapStr[numDashCaps] =
  138. {
  139. _T("FlatCap"),
  140. _T("RoundCap"),
  141. _T("TriangleCap")
  142. };
  143. const DashCap dashCapValue[numDashCaps] =
  144. {
  145. FlatCap,
  146. RoundCap,
  147. TriangleCap
  148. };
  149. const TCHAR* joinList[numJoin] =
  150. {
  151. _T("Miter"),
  152. _T("Round"),
  153. _T("Bevel")
  154. };
  155. const TCHAR* joinStr[numJoin] =
  156. {
  157. _T("MiterJoin"),
  158. _T("RoundJoin"),
  159. _T("BevelJoin")
  160. };
  161. const LineJoin joinValue[numJoin] =
  162. {
  163. MiterJoin,
  164. RoundJoin,
  165. BevelJoin
  166. };
  167. const TCHAR* dashList[numDash] =
  168. {
  169. _T("Solid"),
  170. _T("Dash"),
  171. _T("Dot"),
  172. _T("Dash Dot"),
  173. _T("Dash Dot Dot")
  174. };
  175. const TCHAR* dashStr[numDash] =
  176. {
  177. _T("Solid"),
  178. _T("Dash"),
  179. _T("Dot"),
  180. _T("DashDot"),
  181. _T("DashDotDot")
  182. };
  183. const DashStyle dashValue[numDash] =
  184. {
  185. Solid,
  186. Dash,
  187. Dot,
  188. DashDot,
  189. DashDotDot
  190. };
  191. const TCHAR* wrapList[numWrap] =
  192. {
  193. _T("Tile"),
  194. _T("Tile Flip X"),
  195. _T("Tile Flip Y"),
  196. _T("Tile Flip XY"),
  197. _T("Clamp"),
  198. _T("Extrapolate")
  199. };
  200. const TCHAR* wrapStr[numWrap] =
  201. {
  202. _T("Tile"),
  203. _T("TileFlipX"),
  204. _T("TileFlipY"),
  205. _T("TileFlipXY"),
  206. _T("Clamp"),
  207. _T("Extrapolate")
  208. };
  209. const WrapMode wrapValue[numWrap] =
  210. {
  211. Tile,
  212. TileFlipX,
  213. TileFlipY,
  214. TileFlipXY,
  215. Clamp,
  216. Extrapolate
  217. };
  218. const TCHAR* hatchList[numHatch] =
  219. {
  220. _T("Forward Diagonal"),
  221. _T("Backward Diagonal"),
  222. _T("Cross"),
  223. _T("Diagonal Cross"),
  224. _T("Horizontal"),
  225. _T("Vertical")
  226. };
  227. const TCHAR* hatchStr[numHatch] =
  228. {
  229. _T("ForwardDiagonal"),
  230. _T("BackwardDiagonal"),
  231. _T("Cross"),
  232. _T("DiagonalCross"),
  233. _T("Horizontal"),
  234. _T("Vertical")
  235. };
  236. const HatchStyle hatchValue[numHatch] =
  237. {
  238. ForwardDiagonal,
  239. BackwardDiagonal,
  240. Cross,
  241. DiagonalCross,
  242. Horizontal,
  243. Vertical
  244. };
  245. VOID SetDialogLong(HWND hwnd, UINT idc, UINT value, BOOL enable)
  246. {
  247. HWND hwndControl;
  248. TCHAR tmp[256];
  249. hwndControl = GetDlgItem(hwnd, idc);
  250. _stprintf(tmp, _T("%ld"), value);
  251. SendMessage(hwndControl, WM_SETTEXT, 0, (LPARAM)&tmp[0]);
  252. EnableWindow(hwndControl, enable);
  253. DeleteObject(hwndControl);
  254. }
  255. UINT GetDialogLong(HWND hwnd, UINT idc)
  256. {
  257. HWND hwndControl;
  258. TCHAR tmp[256];
  259. UINT value = 0;
  260. hwndControl = GetDlgItem(hwnd, idc);
  261. SendMessage(hwndControl, WM_GETTEXT, 255, (LPARAM)&tmp[0]);
  262. _stscanf(tmp,_T("%ld"), &value);
  263. DeleteObject(hwndControl);
  264. return value;
  265. }
  266. VOID SetDialogText(HWND hwnd, UINT idc, LPTSTR text, BOOL enable)
  267. {
  268. HWND hwndControl;
  269. hwndControl = GetDlgItem(hwnd, idc);
  270. SendMessage(hwndControl, WM_SETTEXT, 0, (LPARAM)text);
  271. EnableWindow(hwndControl, enable);
  272. DeleteObject(hwndControl);
  273. }
  274. VOID GetDialogText(HWND hwnd, UINT idc, LPTSTR text, INT maxSize)
  275. {
  276. HWND hwndControl;
  277. UINT value = 0;
  278. hwndControl = GetDlgItem(hwnd, idc);
  279. SendMessage(hwndControl, WM_GETTEXT, maxSize, (LPARAM)text);
  280. DeleteObject(hwndControl);
  281. }
  282. VOID SetDialogReal(HWND hwnd, UINT idc, REAL value)
  283. {
  284. HWND hwndControl;
  285. TCHAR tmp[256];
  286. hwndControl = GetDlgItem(hwnd, idc);
  287. _stprintf(tmp, _T("%8.3f"), value);
  288. SendMessage(hwndControl, WM_SETTEXT, 0, (LPARAM)&tmp[0]);
  289. DeleteObject(hwndControl);
  290. }
  291. REAL GetDialogReal(HWND hwnd, UINT idc)
  292. {
  293. HWND hwndControl;
  294. TCHAR tmp[256];
  295. REAL value = 0.0f;
  296. hwndControl = GetDlgItem(hwnd, idc);
  297. SendMessage(hwndControl, WM_GETTEXT, 255, (LPARAM)&tmp[0]);
  298. _stscanf(tmp, _T("%f"), &value);
  299. DeleteObject(hwndControl);
  300. return value;
  301. }
  302. VOID SetDialogRealList(HWND hwnd, UINT idc, REAL* blend, INT count)
  303. {
  304. HWND hwndControl;
  305. TCHAR buf[4*MAX_PATH];
  306. TCHAR tmp[MAX_PATH];
  307. hwndControl = GetDlgItem(hwnd, idc);
  308. buf[0] = _T('\0');
  309. for (INT i = 0; i < count; i++)
  310. {
  311. _stprintf(tmp, _T("%.2f"), blend[i]);
  312. _tcscat(buf, tmp);
  313. if (i != count-1)
  314. _tcscat(buf, _T(" "));
  315. }
  316. SendMessage(hwndControl, WM_SETTEXT, 0, (LPARAM)buf);
  317. DeleteObject(hwndControl);
  318. }
  319. VOID GetDialogRealList(HWND hwnd, UINT idc, REAL** blend, INT *count)
  320. {
  321. HWND hwndControl;
  322. TCHAR buf[4*MAX_PATH];
  323. TCHAR* curpos = &buf[0];
  324. REAL value;
  325. INT pos;
  326. const LPTSTR seps = _T(" \n\r,\t");
  327. hwndControl = GetDlgItem(hwnd, idc);
  328. SendMessage(hwndControl, WM_GETTEXT, 4*MAX_PATH, (LPARAM)buf);
  329. INT newCount = 0;
  330. curpos = _tcstok(&buf[0], seps);
  331. // find number of real values in list
  332. while (curpos)
  333. {
  334. if ((curpos[0] >= '0' && curpos[0] <= '9') ||
  335. curpos[0] == '.')
  336. {
  337. newCount++;
  338. }
  339. curpos = _tcstok(NULL, seps);
  340. }
  341. // !! caller must free the old blend factor memory
  342. //if (*count && *blend)
  343. // free(*blend);
  344. if (!newCount)
  345. {
  346. *count = newCount;
  347. *blend = NULL;
  348. return;
  349. }
  350. SendMessage(hwndControl, WM_GETTEXT, 4*MAX_PATH, (LPARAM)buf);
  351. *count = newCount;
  352. *blend = (REAL*) malloc(sizeof(REAL)*newCount);
  353. // extract actual values from the list.
  354. pos = 0;
  355. curpos = _tcstok(&buf[0], seps);
  356. while (curpos != NULL)
  357. {
  358. if ((curpos[0] >= '0' && curpos[0] <= '9') ||
  359. curpos[0] == '.')
  360. {
  361. ASSERT(pos < newCount);
  362. if (pos >= newCount)
  363. DebugBreak();
  364. _stscanf(curpos, _T("%f"), &value);
  365. (*blend)[pos] = value;
  366. pos++;
  367. }
  368. curpos = _tcstok(NULL, seps);
  369. }
  370. DeleteObject(hwndControl);
  371. }
  372. VOID SetDialogCombo(HWND hwnd, UINT idc, const TCHAR* strings[], INT count, INT cursel)
  373. {
  374. HWND hwndControl;
  375. // !!! use SendDlgItemMessage instead
  376. hwndControl = GetDlgItem(hwnd, idc);
  377. for (INT i=0; i<count; i++)
  378. SendMessage(hwndControl, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)strings[i]);
  379. SendMessage(hwndControl, CB_SETCURSEL, cursel, 0);
  380. DeleteObject(hwndControl);
  381. }
  382. INT GetDialogCombo(HWND hwnd, UINT idc)
  383. {
  384. HWND hwndControl;
  385. hwndControl = GetDlgItem(hwnd, idc);
  386. INT cursel = SendMessage(hwndControl, CB_GETCURSEL, 0, 0);
  387. DeleteObject(hwndControl);
  388. return cursel;
  389. }
  390. VOID SetDialogCheck(HWND hwnd, UINT idc, BOOL checked)
  391. {
  392. HWND hwndControl;
  393. hwndControl = GetDlgItem(hwnd, idc);
  394. SendMessage(hwndControl, BM_SETCHECK, (WPARAM)
  395. checked ? BST_CHECKED : BST_UNCHECKED, 0);
  396. DeleteObject(hwndControl);
  397. }
  398. BOOL GetDialogCheck(HWND hwnd, UINT idc)
  399. {
  400. HWND hwndControl;
  401. BOOL checked = FALSE;
  402. hwndControl = GetDlgItem(hwnd, idc);
  403. checked = SendMessage(hwndControl, BM_GETCHECK, 0, 0);
  404. DeleteObject(hwndControl);
  405. return checked;
  406. }
  407. VOID EnableDialogControl(HWND hwnd, INT idc, BOOL enable)
  408. {
  409. HWND hwndCtrl = GetDlgItem(hwnd, idc);
  410. EnableWindow(hwndCtrl, enable);
  411. DeleteObject(hwndCtrl);
  412. }
  413. VOID SetMenuCheck(HWND hwnd, INT menuPos, UINT idm, BOOL checked, BOOL byCmd)
  414. {
  415. HMENU hmenu = GetMenu(hwnd);
  416. HMENU otherHmenu = GetSubMenu(hmenu, menuPos);
  417. CheckMenuItem(otherHmenu, idm,
  418. (byCmd ? MF_BYCOMMAND : MF_BYPOSITION) |
  419. (checked ? MF_CHECKED : MF_UNCHECKED));
  420. DeleteObject(hmenu);
  421. DeleteObject(otherHmenu);
  422. }
  423. VOID UpdateColorPicture(HWND hwnd, INT idc, ARGB argb)
  424. {
  425. LOGBRUSH lb;
  426. lb.lbStyle = BS_SOLID;
  427. lb.lbColor = ((argb & Color::RedMask) >> Color::RedShift) |
  428. ((argb & Color::GreenMask)) |
  429. ((argb & Color::BlueMask) << Color::RedShift);
  430. lb.lbHatch = NULL;
  431. HWND hwndPic = GetDlgItem(hwnd, idc);
  432. HDC hdc = GetDC(hwndPic);
  433. HBRUSH hbr = CreateBrushIndirect(&lb);
  434. ASSERT(hbr);
  435. HBRUSH hbrOld = (HBRUSH) SelectObject(hdc, hbr);
  436. RECT rect;
  437. GetClientRect(hwndPic, &rect);
  438. FillRect(hdc, &rect, hbr);
  439. SelectObject(hdc, hbrOld);
  440. InvalidateRect(hwndPic, NULL, TRUE);
  441. DeleteObject(hbr);
  442. DeleteObject(hdc);
  443. DeleteObject(hwndPic);
  444. }
  445. VOID UpdateRGBColor(HWND hwnd, INT idcPic, ARGB& argb)
  446. {
  447. static COLORREF custColor[16]
  448. = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  449. CHOOSECOLOR chooseColor =
  450. {
  451. sizeof(CHOOSECOLOR),
  452. hwnd,
  453. 0,
  454. argb & ~Color::AlphaMask,
  455. (COLORREF*)&custColor[0],
  456. CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT,
  457. 0,
  458. 0,
  459. 0
  460. };
  461. if (ChooseColor(&chooseColor))
  462. {
  463. // COLORREF & ARGB reverse Red and Blue position
  464. argb = ((chooseColor.rgbResult & 0x0000FF) << 16) |
  465. ((chooseColor.rgbResult & 0x00FF00)) |
  466. ((chooseColor.rgbResult & 0xFF0000) >> 16);
  467. UpdateColorPicture(hwnd, idcPic, argb);
  468. }
  469. };
  470. /*
  471. VOID OutputRectangle(FILE* file, INT formatType, ERectangle* rect)
  472. {
  473. switch(formatType)
  474. {
  475. case CPPFile:
  476. _ftprintf(file,
  477. _T(tabStr tabStr tabStr
  478. "ERectangle rect(%e, %e,\n"
  479. tabStr tabStr tabStr
  480. " %e, %e);\n",
  481. rect.X, rect.Y, rect.Width, rect.Height);
  482. break;
  483. case JavaFile:
  484. _ftprintf(file,
  485. _T(tabStr tabStr tabStr
  486. "Rectangle rect = new Rectangle(%e, %e,\n"
  487. tabStr tabStr tabStr
  488. " %e, %e);\n",
  489. rect.X, rect.Y, rect.Width, rect.Height);
  490. break;
  491. case VMLFile:
  492. break;
  493. }
  494. }
  495. VOID OutputPointList(FILE* file, INT formatType, Point* pts, INT count)
  496. {
  497. INT cnt;
  498. switch(formatType)
  499. {
  500. case CPPFile:
  501. _ftprintf(file,
  502. _T(tabStr tabStr tabStr
  503. "Point pts[%d];\n"),
  504. count);
  505. for (cnt = 0; cnt < count; cnt++)
  506. _ftprintf(file,
  507. _T(tabStr tabStr tabStr
  508. "pts[%d].X = %e; "
  509. "pts[%d].Y = %e;\n"),
  510. cnt, pts[cnt].X,
  511. cnt, pts[cnt].Y);
  512. break;
  513. case JavaFile:
  514. _ftprintf(file,
  515. _T(tabStr tabStr tabStr
  516. "Point[] pts = new Point[%d]\n"),
  517. count);
  518. for (cnt = 0; cnt < count; cnt++)
  519. _ftprintf(file,
  520. _T(tabStr tabStr tabStr
  521. "pts[%d] = new Point(%e, %e)\n"),
  522. cnt, pts[cnt].X, pts[cnt].Y);
  523. break;
  524. case VMLFile:
  525. break;
  526. }
  527. };
  528. */
  529. //*******************************************************************
  530. //
  531. // TestTransform
  532. //
  533. //*******************************************************************
  534. BOOL TestTransform :: ChangeSettings(HWND hwndParent)
  535. {
  536. BOOL ok = DialogBoxParam(hInst,
  537. MAKEINTRESOURCE(IDD_MATRIX_DLG),
  538. hwndParent,
  539. AllDialogBox,
  540. (LPARAM)((TestDialogInterface*)this));
  541. if (ok)
  542. {
  543. REAL m[6];
  544. // !! This is bad inconsistency in matrix API
  545. matrix->GetElements(&m[0]);
  546. (*origMatrix)->SetElements(m[0], m[1], m[2], m[3], m[4], m[5]);
  547. }
  548. return ok;
  549. }
  550. VOID TestTransform :: Initialize()
  551. {
  552. DebugBreak();
  553. }
  554. VOID TestTransform :: Initialize(Matrix **newMatrix)
  555. {
  556. origMatrix = newMatrix;
  557. if (*newMatrix)
  558. matrix = (*newMatrix)->Clone();
  559. else
  560. matrix = new Matrix();
  561. }
  562. VOID TestTransform :: EnableDialogButtons(HWND hwnd, BOOL enable)
  563. {
  564. EnableDialogControl(hwnd, IDC_MATRIX_RESET, enable);
  565. EnableDialogControl(hwnd, IDC_MATRIX_TRANSLATE, enable);
  566. EnableDialogControl(hwnd, IDC_MATRIX_SCALE, enable);
  567. EnableDialogControl(hwnd, IDC_MATRIX_ROTATE, enable);
  568. EnableDialogControl(hwnd, IDC_MATRIX_SHEAR, enable);
  569. EnableDialogControl(hwnd, IDC_MATRIX_INVERT, enable);
  570. EnableDialogControl(hwnd, IDC_OK, enable);
  571. EnableDialogControl(hwnd, IDC_CANCEL, enable);
  572. }
  573. VOID TestTransform :: UpdateTransformPicture(HWND hwnd,
  574. INT idc,
  575. Matrix* matrix)
  576. {
  577. INT pos;
  578. Matrix tmpMatrix;
  579. // get client rectangle of picture area
  580. HWND hwndPic = GetDlgItem(hwnd, idc);
  581. RECT rect;
  582. GetClientRect(hwndPic, &rect);
  583. Graphics *g = new Graphics(hwndPic);
  584. ERectangle bound(REAL_MAX, REAL_MAX, -REAL_MAX, -REAL_MAX);
  585. ERectangle rectf(rect.left, rect.top,
  586. rect.right - rect.left,
  587. rect.bottom - rect.top);
  588. Point pts[4] =
  589. {
  590. Point(rectf.X-rectf.Width/2, rectf.Y-rectf.Height/2),
  591. Point(rectf.X+rectf.Width/2, rectf.Y-rectf.Height/2),
  592. Point(rectf.X+rectf.Width/2, rectf.Y+rectf.Height/2),
  593. Point(rectf.X-rectf.Width/2, rectf.Y+rectf.Height/2)
  594. };
  595. matrix->TransformPoints(&pts[0], 4);
  596. // compute bounding box of transformed rectangle
  597. for (pos=0; pos < 4; pos++)
  598. {
  599. if (pts[pos].X < bound.GetLeft())
  600. {
  601. bound.Width += fabsf(pts[pos].X-bound.GetLeft());
  602. bound.X = pts[pos].X;
  603. }
  604. if (pts[pos].X > bound.GetRight())
  605. bound.Width = fabsf(pts[pos].X-bound.GetLeft());
  606. // on screen, y positive goes downward
  607. // instead of the traditional upward
  608. if (pts[pos].Y < bound.GetTop())
  609. {
  610. bound.Height += fabsf(pts[pos].Y-bound.GetTop());
  611. bound.Y = pts[pos].Y;
  612. }
  613. if (pts[pos].Y > bound.GetBottom())
  614. bound.Height = fabsf(pts[pos].Y-bound.GetTop());
  615. }
  616. // translate relative to the origin
  617. tmpMatrix.Translate(-((bound.GetLeft()+bound.GetRight())/2),
  618. -((bound.GetTop()+bound.GetBottom())/2),
  619. AppendOrder);
  620. // scale to fit our rectangle
  621. REAL scale = min((rectf.Width-30.0f)/bound.Width,
  622. (rectf.Height-30.0f)/bound.Height);
  623. tmpMatrix.Scale(scale, scale, AppendOrder);
  624. // translate relative to center of our rectangle
  625. tmpMatrix.Translate(rectf.Width/2,
  626. rectf.Height/2,
  627. AppendOrder);
  628. // transform our points by tmpMatrix
  629. tmpMatrix.TransformPoints(&pts[0], 4);
  630. // opaque colors RED & BLACK
  631. Color redColor(0xFF000000 | Color::Red);
  632. SolidBrush redBrush(redColor);
  633. Color blackColor(0xFF000000 | Color::Black);
  634. SolidBrush myBlackBrush(blackColor);
  635. g->FillRectangle(&myBlackBrush, rectf);
  636. g->FillPolygon(&redBrush, &pts[0], 4);
  637. delete g;
  638. }
  639. VOID TestTransform :: InitDialog(HWND hwnd)
  640. {
  641. REAL m[6];
  642. matrix->GetElements(&m[0]);
  643. SetDialogReal(hwnd, IDC_MATRIX_M11, m[0]);
  644. SetDialogReal(hwnd, IDC_MATRIX_M12, m[1]);
  645. SetDialogReal(hwnd, IDC_MATRIX_M13, 0.0f);
  646. SetDialogReal(hwnd, IDC_MATRIX_M21, m[2]);
  647. SetDialogReal(hwnd, IDC_MATRIX_M22, m[3]);
  648. SetDialogReal(hwnd, IDC_MATRIX_M23, 0.0f);
  649. SetDialogReal(hwnd, IDC_MATRIX_M31, m[4]);
  650. SetDialogReal(hwnd, IDC_MATRIX_M32, m[5]);
  651. SetDialogReal(hwnd, IDC_MATRIX_M33, 1.0f);
  652. EnableDialogControl(hwnd, IDC_MATRIX_M13, FALSE);
  653. EnableDialogControl(hwnd, IDC_MATRIX_M23, FALSE);
  654. EnableDialogControl(hwnd, IDC_MATRIX_M33, FALSE);
  655. SetDialogCheck(hwnd, IDC_MATRIX_PREPEND,
  656. *matrixPrepend == PrependOrder ? TRUE : FALSE);
  657. UpdateTransformPicture(hwnd, IDC_MATRIX_PIC, matrix);
  658. }
  659. BOOL TestTransform :: SaveValues(HWND hwnd)
  660. {
  661. *matrixPrepend = (GetDialogCheck(hwnd, IDC_MATRIX_PREPEND) == TRUE ?
  662. PrependOrder : AppendOrder);
  663. matrix->SetElements(GetDialogReal(hwnd, IDC_MATRIX_M11),
  664. GetDialogReal(hwnd, IDC_MATRIX_M12),
  665. GetDialogReal(hwnd, IDC_MATRIX_M21),
  666. GetDialogReal(hwnd, IDC_MATRIX_M22),
  667. GetDialogReal(hwnd, IDC_MATRIX_M31),
  668. GetDialogReal(hwnd, IDC_MATRIX_M32));
  669. // !! check for singular matrix ??
  670. return FALSE;
  671. }
  672. BOOL TestTransform :: ProcessDialog(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  673. {
  674. if (msg == WM_COMMAND)
  675. {
  676. switch(LOWORD(wParam))
  677. {
  678. case IDC_OK:
  679. if (SaveValues(hwnd))
  680. WarningBeep();
  681. else
  682. ::EndDialog(hwnd, TRUE);
  683. break;
  684. case IDC_MATRIX_RESET:
  685. matrix->Reset();
  686. InitDialog(hwnd);
  687. break;
  688. case IDC_MATRIX_TRANSLATE:
  689. {
  690. EnableDialogButtons(hwnd, FALSE);
  691. TestMatrixOperation matrixOp;
  692. matrixOp.Initialize(_T("Translate Matrix Operation"),
  693. _T("Translate"),
  694. _T("Translate points by X and Y"),
  695. 2);
  696. if (matrixOp.ChangeSettings(hwnd))
  697. {
  698. matrix->Translate(matrixOp.GetX(),
  699. matrixOp.GetY(),
  700. *matrixPrepend);
  701. // redisplay dialog entries
  702. InitDialog(hwnd);
  703. }
  704. EnableDialogButtons(hwnd, TRUE);
  705. }
  706. break;
  707. case IDC_MATRIX_SCALE:
  708. {
  709. EnableDialogButtons(hwnd, FALSE);
  710. TestMatrixOperation matrixOp;
  711. matrixOp.Initialize(_T("Scale Matrix Operation"),
  712. _T("Scale"),
  713. _T("Scale points by X and Y"),
  714. 2);
  715. if (matrixOp.ChangeSettings(hwnd))
  716. {
  717. matrix->Scale(matrixOp.GetX(),
  718. matrixOp.GetY(),
  719. *matrixPrepend);
  720. // redisplay dialog entries
  721. InitDialog(hwnd);
  722. }
  723. EnableDialogButtons(hwnd, TRUE);
  724. }
  725. break;
  726. case IDC_MATRIX_ROTATE:
  727. {
  728. EnableDialogButtons(hwnd, FALSE);
  729. TestMatrixOperation matrixOp;
  730. matrixOp.Initialize(_T("Rotate Matrix Operation"),
  731. _T("Rotate"),
  732. _T("Rotate points by angle"),
  733. 1);
  734. if (matrixOp.ChangeSettings(hwnd))
  735. {
  736. matrix->Rotate(matrixOp.GetX(),
  737. *matrixPrepend);
  738. // redisplay dialog entries
  739. InitDialog(hwnd);
  740. }
  741. EnableDialogButtons(hwnd, TRUE);
  742. }
  743. break;
  744. case IDC_MATRIX_SHEAR:
  745. {
  746. EnableDialogButtons(hwnd, FALSE);
  747. TestMatrixOperation matrixOp;
  748. matrixOp.Initialize(_T("Shear Matrix Operation"),
  749. _T("Shear"),
  750. _T("Shear points by X and Y"),
  751. 2);
  752. if (matrixOp.ChangeSettings(hwnd))
  753. {
  754. matrix->Shear(matrixOp.GetX(),
  755. matrixOp.GetY());
  756. // !! should this be added?
  757. // *matrixPrepend);
  758. // redisplay dialog entries
  759. InitDialog(hwnd);
  760. }
  761. EnableDialogButtons(hwnd, TRUE);
  762. }
  763. break;
  764. case IDC_MATRIX_INVERT:
  765. matrix->Invert();
  766. InitDialog(hwnd);
  767. break;
  768. case IDC_REFRESH_PIC:
  769. UpdateTransformPicture(hwnd, IDC_MATRIX_PIC, matrix);
  770. break;
  771. case IDC_CANCEL:
  772. ::EndDialog(hwnd, FALSE);
  773. break;
  774. case IDC_MATRIX_PREPEND:
  775. *matrixPrepend = (GetDialogCheck(hwnd, IDC_MATRIX_PREPEND) == TRUE ?
  776. PrependOrder : AppendOrder);
  777. break;
  778. default:
  779. return FALSE;
  780. }
  781. return TRUE;
  782. }
  783. return FALSE;
  784. }
  785. BOOL TestMatrixOperation :: ChangeSettings(HWND hwndParent)
  786. {
  787. BOOL ok = DialogBoxParam(hInst,
  788. MAKEINTRESOURCE(IDD_MATRIX_DLG2),
  789. hwndParent,
  790. AllDialogBox,
  791. (LPARAM)((TestDialogInterface*)this));
  792. return ok;
  793. }
  794. VOID TestMatrixOperation :: Initialize()
  795. {
  796. DebugBreak();
  797. }
  798. VOID TestMatrixOperation :: Initialize(TCHAR* newDialogTitle,
  799. TCHAR* newSubTitle,
  800. TCHAR* newDescStr,
  801. INT newCount)
  802. {
  803. dialogTitle = newDialogTitle;
  804. subTitle = newSubTitle;
  805. descStr = newDescStr;
  806. count = newCount;
  807. }
  808. VOID TestMatrixOperation :: InitDialog(HWND hwnd)
  809. {
  810. SetWindowText(hwnd, dialogTitle);
  811. SetDialogText(hwnd, IDC_MATRIX_OPERATION, subTitle);
  812. SetDialogText(hwnd, IDC_MATRIX_TEXT, descStr);
  813. SetDialogReal(hwnd, IDC_MATRIX_X, x);
  814. SetDialogReal(hwnd, IDC_MATRIX_Y, y);
  815. EnableDialogControl(hwnd, IDC_MATRIX_Y, count >= 2);
  816. }
  817. BOOL TestMatrixOperation :: SaveValues(HWND hwnd)
  818. {
  819. x = GetDialogReal(hwnd, IDC_MATRIX_X);
  820. y = GetDialogReal(hwnd, IDC_MATRIX_Y);
  821. return FALSE;
  822. }
  823. BOOL TestMatrixOperation :: ProcessDialog(HWND hwnd,
  824. UINT msg,
  825. WPARAM wParam,
  826. LPARAM lParam)
  827. {
  828. if (msg == WM_COMMAND)
  829. {
  830. if (LOWORD(wParam) == IDC_OK)
  831. {
  832. if (SaveValues(hwnd))
  833. WarningBeep();
  834. else
  835. ::EndDialog(hwnd, TRUE);
  836. return TRUE;
  837. }
  838. else if (LOWORD(wParam) == IDC_CANCEL)
  839. {
  840. ::EndDialog(hwnd, FALSE);
  841. }
  842. }
  843. return FALSE;
  844. }
  845. //*******************************************************************
  846. //
  847. // Dialog Window Proc Handler
  848. //
  849. //*******************************************************************
  850. INT_PTR CALLBACK AllDialogBox(
  851. HWND hwnd,
  852. UINT msg,
  853. WPARAM wParam,
  854. LPARAM lParam
  855. )
  856. {
  857. switch (msg)
  858. {
  859. case WM_INITDIALOG:
  860. {
  861. // save pointer to brush interface for this object
  862. SetWindowLong(hwnd, DWL_USER, lParam);
  863. ASSERT(lParam != 0);
  864. TestDialogInterface* dlgInt = (TestDialogInterface*) lParam;
  865. dlgInt->InitDialog(hwnd);
  866. }
  867. break;
  868. case WM_PAINT:
  869. {
  870. TestDialogInterface* dlgInt = (TestDialogInterface*)
  871. GetWindowLong(hwnd, DWL_USER);
  872. ASSERT(dlgInt != NULL);
  873. if (dlgInt)
  874. dlgInt->ProcessDialog(hwnd, WM_COMMAND, IDC_REFRESH_PIC, 0);
  875. return FALSE;
  876. }
  877. break;
  878. case WM_CLOSE:
  879. {
  880. DestroyWindow(hwnd);
  881. break;
  882. }
  883. default:
  884. {
  885. TestDialogInterface* dlgInt = (TestDialogInterface*)
  886. GetWindowLong(hwnd, DWL_USER);
  887. ASSERT(dlgInt != NULL);
  888. if (dlgInt)
  889. return dlgInt->ProcessDialog(hwnd, msg, wParam, lParam);
  890. else
  891. return FALSE;
  892. }
  893. }
  894. return TRUE;
  895. }