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.

560 lines
12 KiB

  1. //// window.cpp
  2. //
  3. // Maintains the text display panel
  4. #include "precomp.hpp"
  5. #include "global.h"
  6. #include "winspool.h"
  7. #include <Tchar.h>
  8. #include "commdlg.h"
  9. INT GetTotalPageCount()
  10. {
  11. return FamilyTest().GetPageCount()
  12. + FormatTest().GetPageCount()
  13. + BrushTest().GetPageCount();
  14. }
  15. void DrawTestPage(Graphics *graphics, INT page, REAL width, REAL height)
  16. {
  17. if (page < FamilyTest().GetPageCount())
  18. {
  19. FamilyTest().DrawPage(
  20. graphics,
  21. page,
  22. width,
  23. height
  24. );
  25. }
  26. else
  27. {
  28. page -= FamilyTest().GetPageCount();
  29. if (page < BrushTest().GetPageCount())
  30. {
  31. BrushTest().DrawPage(
  32. graphics,
  33. page,
  34. width,
  35. height
  36. );
  37. }
  38. else
  39. {
  40. page -= BrushTest().GetPageCount();
  41. if (page < FormatTest().GetPageCount())
  42. {
  43. FormatTest().DrawPage(
  44. graphics,
  45. page,
  46. width,
  47. height
  48. );
  49. }
  50. else
  51. {
  52. page -= FormatTest().GetPageCount();
  53. }
  54. }
  55. }
  56. }
  57. //// Print tests
  58. //
  59. //
  60. HDC StartPrintDoc(DWORD flags)
  61. {
  62. PRINTDLG printDialog;
  63. memset(&printDialog, 0, sizeof(printDialog));
  64. printDialog.lStructSize = sizeof(printDialog);
  65. printDialog.Flags = flags | PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION ;
  66. if (PrintDlg(&printDialog))
  67. {
  68. HDC dc = printDialog.hDC;
  69. DEVMODE * dv;
  70. dv = (DEVMODE *) GlobalLock(printDialog.hDevMode);
  71. if (G.PSLevel2)
  72. OpenPrinter((LPSTR) &dv->dmDeviceName[0], &G.ghPrinter, NULL);
  73. if (dc != NULL)
  74. {
  75. DOCINFO documentInfo;
  76. documentInfo.cbSize = sizeof(documentInfo);
  77. documentInfo.lpszDocName = _T("autoText gdiPlus test");
  78. documentInfo.lpszOutput = NULL;
  79. documentInfo.lpszDatatype = NULL;
  80. documentInfo.fwType = 0;
  81. if (StartDoc(dc, &documentInfo))
  82. {
  83. return dc;
  84. }
  85. else
  86. {
  87. DeleteDC(dc);
  88. }
  89. }
  90. }
  91. return FALSE;
  92. }
  93. void PrintAllTests()
  94. {
  95. HDC dc = StartPrintDoc(0);
  96. if (dc)
  97. {
  98. INT page = 0;
  99. INT pageCount = GetTotalPageCount();
  100. while (page < pageCount)
  101. {
  102. if (StartPage(dc) > 0)
  103. {
  104. HANDLE h = 0;
  105. if (G.PSLevel2)
  106. h = G.ghPrinter;
  107. Graphics graphics(dc, h);
  108. graphics.SetPageUnit(UnitPixel);
  109. DrawTestPage(
  110. &graphics,
  111. page,
  112. REAL(GetDeviceCaps(dc, HORZRES)),
  113. REAL(GetDeviceCaps(dc, VERTRES))
  114. );
  115. EndPage(dc);
  116. }
  117. page++;
  118. }
  119. EndDoc(dc);
  120. DeleteDC(dc);
  121. if (G.PSLevel2)
  122. {
  123. ClosePrinter(G.ghPrinter);
  124. G.ghPrinter = 0;
  125. }
  126. }
  127. }
  128. void PrintTest(INT pageNumber)
  129. {
  130. HDC dc = StartPrintDoc(0);
  131. if (dc)
  132. {
  133. if (StartPage(dc) > 0)
  134. {
  135. HANDLE h = 0;
  136. if (G.PSLevel2)
  137. h = G.ghPrinter;
  138. Graphics graphics(dc, h);
  139. graphics.SetPageUnit(UnitPixel);
  140. DrawTestPage(
  141. &graphics,
  142. pageNumber,
  143. REAL(GetDeviceCaps(dc, HORZRES)),
  144. REAL(GetDeviceCaps(dc, VERTRES))
  145. );
  146. EndPage(dc);
  147. }
  148. EndDoc(dc);
  149. DeleteDC(dc);
  150. if (G.PSLevel2)
  151. {
  152. ClosePrinter(G.ghPrinter);
  153. G.ghPrinter = 0;
  154. }
  155. }
  156. }
  157. void PrintFirstPages(DWORD flags)
  158. {
  159. HDC dc = StartPrintDoc(flags);
  160. if (dc)
  161. {
  162. HANDLE h = 0;
  163. if (G.PSLevel2)
  164. h = G.ghPrinter;
  165. Graphics graphics(dc, h);
  166. graphics.SetPageUnit(UnitPixel);
  167. if (StartPage(dc) > 0)
  168. {
  169. DrawTestPage(
  170. &graphics,
  171. 0,
  172. REAL(GetDeviceCaps(dc, HORZRES)),
  173. REAL(GetDeviceCaps(dc, VERTRES))
  174. );
  175. EndPage(dc);
  176. }
  177. if (StartPage(dc) > 0)
  178. {
  179. DrawTestPage(
  180. &graphics,
  181. FamilyTest().GetPageCount(),
  182. REAL(GetDeviceCaps(dc, HORZRES)),
  183. REAL(GetDeviceCaps(dc, VERTRES))
  184. );
  185. EndPage(dc);
  186. }
  187. if (StartPage(dc) > 0)
  188. {
  189. DrawTestPage(
  190. &graphics,
  191. FamilyTest().GetPageCount()
  192. + FormatTest().GetPageCount(),
  193. REAL(GetDeviceCaps(dc, HORZRES)),
  194. REAL(GetDeviceCaps(dc, VERTRES))
  195. );
  196. EndPage(dc);
  197. }
  198. EndDoc(dc);
  199. DeleteDC(dc);
  200. if (G.PSLevel2)
  201. {
  202. ClosePrinter(G.ghPrinter);
  203. G.ghPrinter = 0;
  204. }
  205. }
  206. }
  207. //// Paint - redraw part or all of client area
  208. //
  209. //
  210. void PaintWindow(HWND hWnd) {
  211. PAINTSTRUCT ps;
  212. HDC hdc;
  213. hdc = BeginPaint(hWnd, &ps);
  214. Graphics graphics(hdc);
  215. RectF clip(
  216. REAL(ps.rcPaint.left),
  217. REAL(ps.rcPaint.top),
  218. REAL(ps.rcPaint.right-ps.rcPaint.left),
  219. REAL(ps.rcPaint.bottom-ps.rcPaint.top)
  220. );
  221. if (ps.fErase)
  222. {
  223. graphics.FillRectangle(
  224. &SolidBrush(Color(0xff, 0xff, 0xff)),
  225. clip
  226. );
  227. }
  228. RECT rcWnd;
  229. GetClientRect(hWnd, &rcWnd);
  230. if (G.RunAllTests)
  231. {
  232. for (INT i=0; i<GetTotalPageCount(); i++)
  233. {
  234. G.TestPage = i;
  235. DrawTestPage(
  236. &graphics,
  237. G.TestPage,
  238. REAL(rcWnd.right - rcWnd.left),
  239. REAL(rcWnd.bottom - rcWnd.top)
  240. );
  241. graphics.FillRectangle(
  242. &SolidBrush(Color(0xff, 0xff, 0xff)),
  243. RectF(
  244. REAL(rcWnd.left),
  245. REAL(rcWnd.top),
  246. REAL(rcWnd.right-ps.rcPaint.left),
  247. REAL(rcWnd.bottom-ps.rcPaint.top)
  248. )
  249. );
  250. }
  251. G.RunAllTests = FALSE;
  252. }
  253. else
  254. {
  255. DrawTestPage(
  256. &graphics,
  257. G.TestPage,
  258. REAL(rcWnd.right - rcWnd.left),
  259. REAL(rcWnd.bottom - rcWnd.top)
  260. );
  261. }
  262. EndPaint(hWnd, &ps);
  263. if (G.AutoPrintRegress)
  264. {
  265. PrintFirstPages(PD_RETURNDEFAULT);
  266. }
  267. if ( G.AutoDisplayRegress
  268. || G.AutoPrintRegress)
  269. {
  270. SendMessage(hWnd, WM_CLOSE, 0, 0);
  271. }
  272. }
  273. //// TextWndProc - Main window message handler and dispatcher
  274. //
  275. //
  276. LRESULT CALLBACK TextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  277. HDC hdc;
  278. switch (message) {
  279. case WM_ERASEBKGND:
  280. return 0; // Leave Paint to erase the background
  281. case WM_PAINT:
  282. PaintWindow(hWnd);
  283. break;
  284. case WM_DESTROY:
  285. PostQuitMessage(0);
  286. return 0;
  287. case WM_COMMAND:
  288. //INT command = LOWORD(wParam);
  289. //INT notify = HIWORD(wParam);
  290. //HWND item = HWND(lParam);
  291. switch (LOWORD(wParam))
  292. {
  293. case ID_NEXT_TEST:
  294. G.TestPage++;
  295. if (G.TestPage >= GetTotalPageCount())
  296. {
  297. G.TestPage = 0;
  298. }
  299. InvalidateRect(hWnd, NULL, TRUE);
  300. break;
  301. case ID_PREV_TEST:
  302. G.TestPage--;
  303. if (G.TestPage < 0)
  304. {
  305. G.TestPage = GetTotalPageCount()-1;
  306. }
  307. InvalidateRect(hWnd, NULL, TRUE);
  308. break;
  309. case ID_PS_LEVEL1:
  310. G.PSLevel2 = FALSE;
  311. break;
  312. case ID_PS_LEVEL2:
  313. G.PSLevel2 = TRUE;
  314. break;
  315. case ID_FIRST_FAMILY:
  316. G.TestPage = 0;
  317. InvalidateRect(hWnd, NULL, TRUE);
  318. break;
  319. case ID_FIRST_BRUSH:
  320. G.TestPage = FamilyTest().GetPageCount();
  321. InvalidateRect(hWnd, NULL, TRUE);
  322. break;
  323. case ID_FIRST_FORMAT:
  324. G.TestPage = FamilyTest().GetPageCount() + BrushTest().GetPageCount();
  325. InvalidateRect(hWnd, NULL, TRUE);
  326. break;
  327. case ID_FILE_REGRESS:
  328. G.TestPage = 0;
  329. G.RunAllTests = TRUE;
  330. InvalidateRect(hWnd, NULL, TRUE);
  331. break;
  332. case ID_FILE_PRINT_CURRENT_TEST:
  333. PrintTest(G.TestPage);
  334. break;
  335. case ID_FILE_PRINT_FIRST_PAGE:
  336. PrintFirstPages(0);
  337. break;
  338. case ID_FILE_PRINTALLTESTS:
  339. PrintAllTests();
  340. break;
  341. case IDM_EXIT:
  342. SendMessage(hWnd, WM_CLOSE, 0, 0);
  343. break;
  344. }
  345. // Validate current test page number
  346. if (G.TestPage < 0)
  347. {
  348. G.TestPage = 0;
  349. }
  350. else
  351. {
  352. if (G.TestPage >= GetTotalPageCount())
  353. {
  354. G.TestPage = GetTotalPageCount()-1;
  355. }
  356. }
  357. return 0;
  358. default:
  359. if (G.Unicode) {
  360. return DefWindowProcW(hWnd, message, wParam, lParam);
  361. } else {
  362. return DefWindowProcA(hWnd, message, wParam, lParam);
  363. }
  364. }
  365. return 0;
  366. }
  367. //// CreateTextWindow - create window class and window
  368. //
  369. // Attempts to use a Unicode window, if this fails uses an ANSI
  370. // window.
  371. //
  372. // For example the Unicode window will succeed on Windows NT and
  373. // Windows CE, but fail on Windows 9x.
  374. HWND CreateTextWindow() {
  375. WNDCLASSA wcA;
  376. WNDCLASSW wcW;
  377. HWND hWnd;
  378. // Try registering as a Unicode window
  379. wcW.style = CS_HREDRAW | CS_VREDRAW;
  380. wcW.lpfnWndProc = TextWndProc;
  381. wcW.cbClsExtra = 0;
  382. wcW.cbWndExtra = 0;
  383. wcW.hInstance = G.Instance;
  384. wcW.hIcon = LoadIconW(G.Instance, APPNAMEW);
  385. wcW.hCursor = LoadCursorW(NULL, (WCHAR*)IDC_ARROW);
  386. wcW.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  387. wcW.lpszMenuName = L"MAINMENU";
  388. wcW.lpszClassName = APPNAMEW;
  389. if (RegisterClassW(&wcW)) {
  390. // Use a Unicode window
  391. G.Unicode = TRUE;
  392. hWnd = CreateWindowW(
  393. APPNAMEW, APPTITLEW,
  394. WS_OVERLAPPEDWINDOW,
  395. CW_USEDEFAULT, 0,
  396. CW_USEDEFAULT, 0,
  397. NULL, NULL,
  398. G.Instance,
  399. NULL);
  400. return hWnd;
  401. } else {
  402. // Must use an ANSI window.
  403. wcA.style = CS_HREDRAW | CS_VREDRAW;
  404. wcA.lpfnWndProc = TextWndProc;
  405. wcA.cbClsExtra = 0;
  406. wcA.cbWndExtra = 0;
  407. wcA.hInstance = G.Instance;
  408. wcA.hIcon = LoadIconA(G.Instance, APPNAMEA);
  409. wcA.hCursor = LoadCursor(NULL, IDC_ARROW);
  410. wcA.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  411. wcA.lpszMenuName = "MAINMENU";
  412. wcA.lpszClassName = APPNAMEA;
  413. if (!RegisterClassA(&wcA)) {
  414. return NULL;
  415. }
  416. G.Unicode = FALSE;
  417. hWnd = CreateWindowA(
  418. APPNAMEA, APPTITLEA,
  419. WS_OVERLAPPEDWINDOW,
  420. CW_USEDEFAULT, 0,
  421. CW_USEDEFAULT, 0,
  422. NULL, NULL,
  423. G.Instance,
  424. NULL);
  425. };
  426. return hWnd;
  427. }