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.

408 lines
8.6 KiB

  1. #include "gdiptest.h"
  2. //*******************************************************************
  3. //
  4. // TestPen
  5. //
  6. //
  7. //
  8. //*******************************************************************
  9. BOOL TestPen :: ChangeSettings(HWND hwndParent)
  10. {
  11. BOOL ok = DialogBoxParam(hInst,
  12. MAKEINTRESOURCE(IDD_PEN_DLG),
  13. hwndParent,
  14. AllDialogBox,
  15. (LPARAM)(static_cast<TestDialogInterface*>(this)));
  16. // customize brush && then cancel
  17. if (tempBrush)
  18. {
  19. delete tempBrush;
  20. tempBrush = NULL;
  21. }
  22. if (ok)
  23. {
  24. delete pen;
  25. if (useBrush)
  26. {
  27. ASSERT(brush);
  28. pen = new Pen(brush->GetBrush(), width);
  29. }
  30. else
  31. {
  32. Color color(argb);
  33. pen = new Pen(color, width);
  34. }
  35. pen->SetLineCap(capValue[startCap],
  36. capValue[endCap],
  37. dashCapValue[dashCap]);
  38. pen->SetLineJoin(joinValue[lineJoin]);
  39. pen->SetMiterLimit(miterLimit);
  40. pen->SetDashStyle(dashValue[dashStyle]);
  41. return TRUE;
  42. }
  43. return FALSE;
  44. };
  45. VOID TestPen :: Initialize()
  46. {
  47. delete brush;
  48. brush = NULL;
  49. delete tempBrush;
  50. tempBrush = NULL;
  51. brushSelect = tempBrushSelect = 0;
  52. useBrush = FALSE;
  53. argb = 0x80808080; // grayish, alpha = 0x80
  54. width = 5.0f;
  55. startCap = SquareCap;
  56. endCap = SquareCap;
  57. dashCap = FlatCap;
  58. lineJoin = RoundJoin;
  59. miterLimit = 0;
  60. dashStyle = Solid;
  61. Color color(argb);
  62. pen = new Pen(color, width);
  63. pen->SetLineCap(capValue[startCap],
  64. capValue[endCap],
  65. dashCapValue[dashCap]);
  66. pen->SetLineJoin(joinValue[lineJoin]);
  67. pen->SetMiterLimit(miterLimit);
  68. pen->SetDashStyle(dashValue[dashStyle]);
  69. }
  70. VOID TestPen :: AddToFile(OutputFile* outfile, INT id)
  71. {
  72. TCHAR penStr[MAX_PATH];
  73. TCHAR brushStr[MAX_PATH];
  74. TCHAR colorStr[MAX_PATH];
  75. if (id)
  76. {
  77. _stprintf(&penStr[0], _T("pen%dp"), id);
  78. _stprintf(&colorStr[0], _T("color%dp"), id);
  79. }
  80. else
  81. {
  82. _tcscpy(&penStr[0], _T("pen"));
  83. _tcscpy(&colorStr[0], _T("color"));
  84. }
  85. if (useBrush)
  86. {
  87. _stprintf(&brushStr[0], "brush%d", 2);
  88. brush->AddToFile(outfile, 2);
  89. outfile->Declaration(_T("Pen"),
  90. &penStr[0],
  91. _T("%s, %e"),
  92. outfile->Ref(&brushStr[0]),
  93. width);
  94. }
  95. else
  96. {
  97. outfile->ColorDeclaration(&colorStr[0],
  98. &argb);
  99. outfile->Declaration(_T("Pen"),
  100. &penStr[0],
  101. _T("%s, %e"),
  102. &colorStr[0],
  103. width);
  104. }
  105. outfile->ObjectCommand(&penStr[0],
  106. _T("SetLineCap"),
  107. _T("%s, %s, %s"),
  108. capStr[startCap],
  109. capStr[endCap],
  110. dashCapStr[dashCap]);
  111. outfile->ObjectCommand(&penStr[0],
  112. _T("SetLineJoin"),
  113. joinStr[lineJoin]);
  114. if (joinValue[lineJoin] == MiterJoin)
  115. outfile->ObjectCommand(&penStr[0],
  116. _T("SetMiterLimit"),
  117. _T("%e"),
  118. miterLimit);
  119. outfile->ObjectCommand(&penStr[0],
  120. _T("SetDashStyle"),
  121. dashStr[dashStyle]);
  122. }
  123. VOID TestPen :: EnableBrushFields(HWND hwnd, BOOL enable)
  124. {
  125. HWND hwdAlpha = GetDlgItem(hwnd, IDC_PEN_ALPHA);
  126. HWND hwdColorB = GetDlgItem(hwnd, IDC_PEN_COLORBUTTON);
  127. HWND hwdColorP = GetDlgItem(hwnd, IDC_PEN_COLORPIC);
  128. HWND hwdBrushB = GetDlgItem(hwnd, IDC_PEN_BRUSHBUTTON);
  129. HWND hwdList = GetDlgItem(hwnd, IDC_PEN_BRUSHLIST);
  130. SetDialogCheck(hwnd, IDC_PEN_BRUSH, enable);
  131. SetDialogCheck(hwnd, IDC_PEN_COLOR, !enable);
  132. EnableWindow(hwdBrushB, enable);
  133. EnableWindow(hwdList, enable);
  134. EnableWindow(hwdAlpha, !enable);
  135. EnableWindow(hwdColorP, !enable);
  136. EnableWindow(hwdColorB, !enable);
  137. DeleteObject(hwdAlpha);
  138. DeleteObject(hwdColorP);
  139. DeleteObject(hwdColorB);
  140. DeleteObject(hwdBrushB);
  141. DeleteObject(hwdList);
  142. }
  143. VOID TestPen :: InitDialog(HWND hwnd)
  144. {
  145. INT i,j;
  146. // Color/Brush button
  147. SetDialogCheck(hwnd, IDC_PEN_BRUSH, useBrush);
  148. SetDialogCheck(hwnd, IDC_PEN_COLOR, !useBrush);
  149. HWND hwndBrushList = GetDlgItem(hwnd, IDC_PEN_BRUSHLIST);
  150. EnableWindow(hwndBrushList, useBrush);
  151. // Store pointer to underlying Brush object in Brush Button
  152. if (tempBrush)
  153. {
  154. // we had a warning, keep the temp Brush until we really save.
  155. }
  156. else if (brush)
  157. {
  158. // first pop-up occurrence
  159. tempBrush = brush->Clone();
  160. tempBrushSelect = brushSelect;
  161. SetDialogCombo(hwnd, IDC_PEN_BRUSHLIST, brushList, numBrushes, brushSelect);
  162. }
  163. else
  164. {
  165. tempBrush = NULL;
  166. tempBrushSelect = 0;
  167. SetDialogCombo(hwnd, IDC_PEN_BRUSHLIST, brushList, numBrushes, 0);
  168. }
  169. DeleteObject(hwndBrushList);
  170. // Color values
  171. SetDialogLong(hwnd, IDC_PEN_ALPHA, argb >> Color::AlphaShift);
  172. EnableBrushFields(hwnd, useBrush);
  173. // Start/End/Dash Cap
  174. SetDialogCombo(hwnd, IDC_PEN_STARTCAP, capList, numCaps, startCap);
  175. SetDialogCombo(hwnd, IDC_PEN_ENDCAP, capList, numCaps, endCap);
  176. SetDialogCombo(hwnd, IDC_PEN_DASHCAP, dashCapList, numDashCaps, dashCap);
  177. // Line Join
  178. SetDialogCombo(hwnd, IDC_PEN_JOIN, joinList, numJoin, lineJoin);
  179. // Dash Style
  180. SetDialogCombo(hwnd, IDC_PEN_DASHSTYLE, dashList, numDash, dashStyle);
  181. // Width
  182. SetDialogReal(hwnd, IDC_PEN_WIDTH, width);
  183. }
  184. BOOL TestPen :: SaveValues(HWND hwnd)
  185. {
  186. BOOL warning = FALSE;
  187. // Solid color values
  188. argb = (argb & ~Color::AlphaMask) |
  189. (GetDialogLong(hwnd, IDC_PEN_ALPHA)
  190. << Color::AlphaShift);
  191. startCap = GetDialogCombo(hwnd, IDC_PEN_STARTCAP);
  192. endCap = GetDialogCombo(hwnd, IDC_PEN_ENDCAP);
  193. dashCap = GetDialogCombo(hwnd, IDC_PEN_DASHCAP);
  194. // Width
  195. width = GetDialogReal(hwnd, IDC_PEN_WIDTH);
  196. if (width < 0.01f)
  197. {
  198. width = 0.01f;
  199. warning = TRUE;
  200. }
  201. else if (width > 100)
  202. {
  203. width = 100.0f;
  204. warning = TRUE;
  205. }
  206. dashStyle = GetDialogCombo(hwnd, IDC_PEN_DASHSTYLE);
  207. lineJoin = GetDialogCombo(hwnd, IDC_PEN_JOIN);
  208. // !! miter limit not currently supported
  209. miterLimit = 0;
  210. BOOL tempUse = GetDialogCheck(hwnd, IDC_PEN_BRUSH);
  211. if (tempUse)
  212. {
  213. tempBrushSelect = GetDialogCombo(hwnd, IDC_PEN_BRUSHLIST);
  214. if (!tempBrush ||
  215. (tempBrush->GetType() != brushValue[tempBrushSelect]))
  216. {
  217. WarningBox("Must customize Brush or select Color.");
  218. warning = TRUE;
  219. }
  220. else
  221. {
  222. // we are saving, copy tempBrush to real Brush
  223. // no reason to clone
  224. if (!warning)
  225. {
  226. delete brush;
  227. brush = tempBrush;
  228. brushSelect = tempBrushSelect;
  229. tempBrush = NULL;
  230. tempBrushSelect = 0;
  231. }
  232. }
  233. }
  234. else
  235. {
  236. // no warnings and not using temp brush, delete it.
  237. if (!warning)
  238. {
  239. delete tempBrush;
  240. tempBrush = NULL;
  241. }
  242. }
  243. if (warning)
  244. InitDialog(hwnd);
  245. return warning;
  246. }
  247. BOOL TestPen :: ProcessDialog(HWND hwnd,
  248. UINT msg,
  249. WPARAM wParam,
  250. LPARAM lParam)
  251. {
  252. if (msg == WM_COMMAND)
  253. {
  254. switch(LOWORD(wParam))
  255. {
  256. case IDC_OK:
  257. if (SaveValues(hwnd))
  258. WarningBeep();
  259. else
  260. ::EndDialog(hwnd, TRUE);
  261. break;
  262. case IDC_CANCEL:
  263. ::EndDialog(hwnd, FALSE);
  264. break;
  265. // pop-up brush customization window
  266. case IDC_PEN_BRUSHBUTTON:
  267. {
  268. ASSERT(useBrush);
  269. // get selected brush type
  270. tempBrushSelect = GetDialogCombo(hwnd, IDC_PEN_BRUSHLIST);
  271. if (tempBrush)
  272. {
  273. // change in brush type, create new temp brush
  274. if (tempBrush->GetType() != brushValue[tempBrushSelect])
  275. {
  276. // we've changed type,
  277. delete tempBrush;
  278. tempBrush = NULL;
  279. tempBrush = TestBrush::CreateNewBrush(brushValue[tempBrushSelect]);
  280. tempBrush->Initialize();
  281. if (!tempBrush->ChangeSettings(hwnd))
  282. {
  283. delete tempBrush;
  284. tempBrush = NULL;
  285. }
  286. }
  287. else
  288. {
  289. // change settings on temp brush
  290. tempBrush->ChangeSettings(hwnd);
  291. }
  292. }
  293. else
  294. {
  295. // no brush type previously selected.
  296. tempBrush = TestBrush::CreateNewBrush(brushValue[tempBrushSelect]);
  297. tempBrush->Initialize();
  298. if (!tempBrush->ChangeSettings(hwnd))
  299. {
  300. delete tempBrush;
  301. tempBrush = NULL;
  302. }
  303. }
  304. }
  305. break;
  306. case IDC_REFRESH_PIC:
  307. UpdateColorPicture(hwnd, IDC_PEN_COLORPIC, argb);
  308. break;
  309. case IDC_PEN_COLORBUTTON:
  310. UpdateRGBColor(hwnd, IDC_PEN_COLORPIC, argb);
  311. break;
  312. // enable/disable appropriate fields
  313. case IDC_PEN_BRUSH:
  314. EnableBrushFields(hwnd, TRUE);
  315. useBrush = TRUE;
  316. break;
  317. case IDC_PEN_COLOR:
  318. EnableBrushFields(hwnd,FALSE);
  319. useBrush = FALSE;
  320. break;
  321. default:
  322. return FALSE;
  323. }
  324. return TRUE;
  325. }
  326. /*
  327. if (HIWORD(wParam) == CBN_DROPDOWN)
  328. {
  329. // list box about to be displayed
  330. DebugBreak();
  331. }
  332. if (HIWORD(wParam) == CBN_CLOSEUP)
  333. {
  334. // about to close list-box
  335. DebugBreak();
  336. }
  337. */
  338. return FALSE;
  339. }