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.

418 lines
8.2 KiB

  1. #include "gdiptest.h"
  2. //*******************************************************************
  3. //
  4. // OutputFile
  5. //
  6. //
  7. //
  8. //*******************************************************************
  9. OutputFile* OutputFile :: CreateOutputFile(LPTSTR filename)
  10. {
  11. // convert to upper case & verify file extension
  12. TCHAR tmpStr[MAX_PATH];
  13. _tcscpy(&tmpStr[0], filename);
  14. _tcsupr(&tmpStr[0]);
  15. LPTSTR ext = &tmpStr[0] + _tcslen(&tmpStr[0]) - 3;
  16. INT formatType = -1;
  17. FILE* outfile = _tfopen(filename, _T("w"));
  18. if (!outfile)
  19. {
  20. WarningBox(_T("Can't create the output file."));
  21. return NULL;
  22. }
  23. if (!_tcscmp(ext, _T("CPP")) ||
  24. !_tcscmp(ext, _T("C")) ||
  25. !_tcscmp(ext, _T("CXX")))
  26. return new CPPOutputFile(outfile);
  27. else if (!_tcscmp(ext, _T("JAVA")))
  28. return new JavaOutputFile(outfile);
  29. else if (!_tcscmp(ext, _T("VML")))
  30. return new VMLOutputFile(outfile);
  31. else
  32. {
  33. WarningBox(_T("Unrecognized file type (.cpp, .c, .cxx, .Java, .vml)"));
  34. return NULL;
  35. }
  36. }
  37. //*******************************************************************
  38. //
  39. // CPPOutputFile
  40. //
  41. //
  42. //
  43. //*******************************************************************
  44. VOID CPPOutputFile :: GraphicsProcedure()
  45. {
  46. _ftprintf(outfile, _T("VOID DoGraphicsTest(HWND hWnd)\n"));
  47. }
  48. VOID CPPOutputFile :: GraphicsDeclaration()
  49. {
  50. _ftprintf(outfile, _T("%*sGraphics g(hWnd);\n"),
  51. 4,
  52. _T(""));
  53. }
  54. VOID CPPOutputFile :: PointDeclaration(LPCTSTR pointName, Point* pts, INT count)
  55. {
  56. if (count < 0)
  57. _ftprintf(outfile,
  58. _T("%sPoint %s(%e, %e);\n"),
  59. tabStr,
  60. pointName,
  61. pts->X,
  62. pts->Y);
  63. else
  64. {
  65. _ftprintf(outfile,
  66. _T("%sPoint %s[%d];\n"),
  67. tabStr,
  68. pointName,
  69. count);
  70. for (INT pos=0; pos<count; pos++, pts++)
  71. _ftprintf(outfile,
  72. _T("%s%s[%d].X=%e; %s[%d].Y=%e;\n"),
  73. tabStr, pointName, pos, pts->X, pointName, pos, pts->Y);
  74. }
  75. }
  76. VOID CPPOutputFile :: ColorDeclaration(LPCTSTR colorName, ARGB* argb, INT count)
  77. {
  78. if (count < 0)
  79. _ftprintf(outfile,
  80. _T("%sColor %s(0x%08X);\n"),
  81. tabStr,
  82. colorName,
  83. *argb);
  84. else
  85. {
  86. _ftprintf(outfile,
  87. _T("%sColor %s[%d];\n"),
  88. tabStr,
  89. colorName,
  90. count);
  91. for (INT pos=0; pos<count; pos++, argb++)
  92. _ftprintf(outfile,
  93. _T("%s%s[%d] = Color(0x%08X);\n"),
  94. tabStr,
  95. colorName,
  96. pos,
  97. *argb);
  98. }
  99. }
  100. VOID CPPOutputFile :: RectangleDeclaration(LPCTSTR rectName, ERectangle& rect)
  101. {
  102. _ftprintf(outfile,
  103. _T("%sERectangle %s(%e, %e, \n"
  104. "%s%*s%e, %e);\n"),
  105. tabStr,
  106. rectName,
  107. rect.X,
  108. rect.Y,
  109. tabStr,
  110. 12 + _tcslen(rectName),
  111. _T(""),
  112. rect.Width,
  113. rect.Height);
  114. }
  115. VOID CPPOutputFile :: Declaration(LPCTSTR type,
  116. LPCTSTR object,
  117. LPCTSTR argList,
  118. ...)
  119. {
  120. TCHAR declArgs[MAX_PATH];
  121. va_list args;
  122. va_start (args, argList);
  123. _vstprintf(&declArgs[0], argList, args);
  124. va_end (args);
  125. _ftprintf(outfile,
  126. _T("%s%s %s(%s);\n"),
  127. tabStr,
  128. type,
  129. object,
  130. declArgs);
  131. }
  132. // set matrix, do nothing if identity matrix
  133. VOID CPPOutputFile :: SetPointDeclaration(LPCTSTR object,
  134. LPCTSTR command,
  135. LPCTSTR varName,
  136. Point* pts,
  137. INT count,
  138. BOOL ref)
  139. {
  140. if (count < 0)
  141. {
  142. _ftprintf(outfile,
  143. _T("%sPoint %s(%e, %e);\n"),
  144. tabStr,
  145. varName,
  146. pts->X,
  147. pts->Y);
  148. _ftprintf(outfile,
  149. _T("%s%s.%s(%s);\n"),
  150. tabStr,
  151. object,
  152. command,
  153. ref ? Ref(_T(varName)) : varName);
  154. }
  155. else
  156. {
  157. _ftprintf(outfile,
  158. _T("%sPoint %s[%d];\n"),
  159. tabStr,
  160. varName,
  161. count);
  162. for (INT pos=0; pos<count; pos++, pts++)
  163. _ftprintf(outfile,
  164. _T("%s%s[%d].X=%e; %s[%d].Y=%e;\n"),
  165. tabStr,
  166. varName,
  167. pos,
  168. pts->X,
  169. varName,
  170. pos,
  171. pts->Y);
  172. _ftprintf(outfile,
  173. _T("%s%s.%s(%s);\n"),
  174. tabStr,
  175. object,
  176. command,
  177. RefArray(varName));
  178. }
  179. }
  180. VOID CPPOutputFile :: SetColorDeclaration(LPCTSTR object,
  181. LPCTSTR command,
  182. LPCTSTR varName,
  183. ARGB* colors,
  184. INT count,
  185. BOOL ref)
  186. {
  187. if (count < 0)
  188. {
  189. _ftprintf(outfile,
  190. _T("%sColor %s(0x%08X);\n"),
  191. tabStr,
  192. varName,
  193. *colors);
  194. _ftprintf(outfile,
  195. _T("%s%s.%s(%s%s);\n"),
  196. tabStr,
  197. object,
  198. command,
  199. ref ? _T("&") : _T(""),
  200. varName);
  201. }
  202. else
  203. {
  204. _ftprintf(outfile,
  205. _T("%sColor %s[%d];\n"),
  206. tabStr,
  207. varName,
  208. count);
  209. for (INT pos=0; pos<count; pos++, colors++)
  210. _ftprintf(outfile,
  211. _T("%s%s[%d] = Color(0x%08X);\n"),
  212. tabStr,
  213. varName,
  214. pos,
  215. *colors);
  216. _ftprintf(outfile,
  217. _T("%s%s.%s(&%s[0]);\n"),
  218. tabStr,
  219. object,
  220. command,
  221. varName);
  222. }
  223. }
  224. VOID CPPOutputFile :: SetMatrixDeclaration(LPCTSTR object,
  225. LPCTSTR command,
  226. LPCTSTR varName,
  227. Matrix* matrix)
  228. {
  229. REAL m[6];
  230. if (matrix->IsIdentity())
  231. {
  232. _ftprintf(outfile,
  233. _T("%s// identity matrix transform\n"),
  234. tabStr);
  235. return;
  236. }
  237. matrix->GetElements(&m[0]);
  238. _ftprintf(outfile,
  239. _T("%sMatrix %s(%e, %e, %e, \n"
  240. "%s%*s%e, %e, %e);\n"),
  241. tabStr,
  242. varName,
  243. m[0],
  244. m[1],
  245. m[2],
  246. tabStr,
  247. 8 + _tcslen(varName),
  248. _T(""),
  249. m[3],
  250. m[4],
  251. m[5]);
  252. _ftprintf(outfile,
  253. _T("%s%s.%s(&%s);\n"),
  254. tabStr,
  255. object,
  256. command,
  257. varName);
  258. }
  259. VOID CPPOutputFile :: SetBlendDeclaration(LPCTSTR object,
  260. LPCTSTR command,
  261. LPCTSTR varName,
  262. REAL* blend,
  263. INT count)
  264. {
  265. _ftprintf(outfile,
  266. _T("%sREAL %s[%d];\n"),
  267. tabStr,
  268. varName,
  269. count);
  270. for (INT pos=0; pos<count; pos++, blend++)
  271. _ftprintf(outfile,
  272. _T("%s%s[%d] = %e;\n"),
  273. tabStr,
  274. varName,
  275. pos,
  276. *blend);
  277. _ftprintf(outfile,
  278. _T("%s%s.%s(&%s[0]);\n"),
  279. tabStr,
  280. object,
  281. command,
  282. varName);
  283. }
  284. VOID CPPOutputFile :: GraphicsCommand(LPCTSTR command,
  285. LPCTSTR argList,
  286. ...)
  287. {
  288. TCHAR declArgs[MAX_PATH];
  289. va_list args;
  290. va_start (args, argList);
  291. _vstprintf(&declArgs[0], argList, args);
  292. va_end (args);
  293. _ftprintf(outfile,
  294. _T("%sg.%s(%s);\n"),
  295. tabStr,
  296. command,
  297. declArgs);
  298. }
  299. VOID CPPOutputFile :: ObjectCommand(LPCTSTR object,
  300. LPCTSTR command,
  301. LPCTSTR argList,
  302. ...)
  303. {
  304. TCHAR declArgs[MAX_PATH];
  305. va_list args;
  306. va_start (args, argList);
  307. _vstprintf(&declArgs[0], argList, args);
  308. va_end (args);
  309. _ftprintf(outfile,
  310. _T("%s%s.%s(%s);\n"),
  311. tabStr,
  312. object,
  313. command,
  314. declArgs);
  315. }
  316. VOID CPPOutputFile :: BeginIndent()
  317. {
  318. TCHAR tmp[MAX_PATH];
  319. _ftprintf(outfile, _T("%s{\n"), tabStr);
  320. tabs++;
  321. _stprintf(&tmp[0], "%%%ds", tabs*4);
  322. _stprintf(&tabStr[0], &tmp[0], _T(""));
  323. }
  324. VOID CPPOutputFile :: EndIndent()
  325. {
  326. TCHAR tmp[MAX_PATH];
  327. tabs--;
  328. _stprintf(&tmp[0], "%%%ds", tabs*4);
  329. _stprintf(&tabStr[0], &tmp[0], _T(""));
  330. _ftprintf(outfile, _T("%s}\n"), tabStr);
  331. }
  332. VOID CPPOutputFile :: BlankLine()
  333. {
  334. _ftprintf(outfile, _T("\n"));
  335. }
  336. LPTSTR CPPOutputFile :: Ref(LPCTSTR refStr)
  337. {
  338. static TCHAR tmpStr[3][MAX_PATH];
  339. static INT pos = 0;
  340. _stprintf(&tmpStr[pos % 3][0], "&%s", refStr);
  341. pos++;
  342. return &tmpStr[(pos-1) % 3][0];
  343. }
  344. LPTSTR CPPOutputFile :: RefArray(LPCTSTR refStr)
  345. {
  346. static TCHAR tmpStr[3][MAX_PATH];
  347. static INT pos = 0;
  348. _stprintf(&tmpStr[pos % 3][0], "&%s[0]", refStr);
  349. pos++;
  350. return &tmpStr[(pos-1) % 3][0];
  351. }
  352. LPTSTR CPPOutputFile :: WStr(LPCTSTR refStr)
  353. {
  354. static TCHAR tmpStr[3][MAX_PATH];
  355. static INT pos = 0;
  356. TCHAR tmpSlash[MAX_PATH];
  357. INT cnt, cntpos = 0;
  358. // convert single slashes to double slashes
  359. for (cnt = 0; cnt < _tcslen(refStr)+1; cnt++)
  360. if (refStr[cnt] == '\\')
  361. {
  362. tmpSlash[cntpos++] = '\\';
  363. tmpSlash[cntpos++] = '\\';
  364. }
  365. else
  366. tmpSlash[cntpos++] = refStr[cnt];
  367. _stprintf(&tmpStr[pos % 3][0], "L\"%s\"", tmpSlash);
  368. pos++;
  369. return &tmpStr[(pos-1) % 3][0];
  370. }