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.

260 lines
11 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION
  4. *
  5. * TITLE: PAPRSIZE.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 1/8/2001
  12. *
  13. * DESCRIPTION: Scanner paper sizes
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "wiauiext.h"
  19. #include "paprsize.h"
  20. extern HINSTANCE g_hInstance;
  21. static const struct
  22. {
  23. int nStringId;
  24. LONG nWidth;
  25. LONG nHeight;
  26. } g_SupportedPaperSizes[] =
  27. {
  28. { IDS_WIA_PAPER_SIZE_E_SIZE_SHEET, 34000, 44000 },
  29. { IDS_WIA_PAPER_SIZE_D_SIZE_SHEET, 22000, 34000 },
  30. { IDS_WIA_PAPER_SIZE_A2, 16535, 23386 },
  31. { IDS_WIA_PAPER_SIZE_C_SIZE_SHEET, 17000, 22000 },
  32. { IDS_WIA_PAPER_SIZE_SUPER_B, 12008, 19173 },
  33. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_10_ROTATED, 18031, 12756 },
  34. { IDS_WIA_PAPER_SIZE_ENVELOPE_C3, 12756, 18031 },
  35. { IDS_WIA_PAPER_SIZE_A3_EXTRA, 12677, 17520 },
  36. { IDS_WIA_PAPER_SIZE_TABLOID_EXTRA, 12000, 18000 },
  37. { IDS_WIA_PAPER_SIZE_A3_ROTATED, 16535, 11693 },
  38. { IDS_WIA_PAPER_SIZE_A3, 11693, 16535 },
  39. { IDS_WIA_PAPER_SIZE_LEDGER, 17000, 11000 },
  40. { IDS_WIA_PAPER_SIZE_TABLOID, 11000, 17000 },
  41. { IDS_WIA_PAPER_SIZE_15X11, 15000, 11000 },
  42. { IDS_WIA_PAPER_SIZE_US_STD_FANFOLD, 14875, 11000 },
  43. { IDS_WIA_PAPER_SIZE_B4_JIS_ROTATED, 14331, 10118 },
  44. { IDS_WIA_PAPER_SIZE_B4_JIS, 10118, 14331 },
  45. { IDS_WIA_PAPER_SIZE_LEGAL_EXTRA, 9500, 15000 },
  46. { IDS_WIA_PAPER_SIZE_10X14, 10000, 14000 },
  47. { IDS_WIA_PAPER_SIZE_B4_ISO, 9843, 13898 },
  48. { IDS_WIA_PAPER_SIZE_12X11, 12005, 11005 },
  49. { IDS_WIA_PAPER_SIZE_SUPER_A, 8937, 14016 },
  50. { IDS_WIA_PAPER_SIZE_JAPAN_ENVELOPE_KAKU_2_ROTATED, 13071, 9449 },
  51. { IDS_WIA_PAPER_SIZE_JAPANESE_ENVELOPE_KAKU_2, 9449, 13071 },
  52. { IDS_WIA_PAPER_SIZE_LEGAL, 8500, 14000 },
  53. { IDS_WIA_PAPER_SIZE_A4_EXTRA, 9270, 12690 },
  54. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_9_ROTATED, 12756, 9016 },
  55. { IDS_WIA_PAPER_SIZE_ENVELOPE_C4, 9016, 12756 },
  56. { IDS_WIA_PAPER_SIZE_LETTER_EXTRA, 9500, 12000 },
  57. { IDS_WIA_PAPER_SIZE_FOLIO, 8500, 13000 },
  58. { IDS_WIA_PAPER_SIZE_10X11, 10000, 11000 },
  59. { IDS_WIA_PAPER_SIZE_LETTER_PLUS, 8500, 12690 },
  60. { IDS_WIA_PAPER_SIZE_A4_PLUS, 8268, 12992 },
  61. { IDS_WIA_PAPER_SIZE_GERMAN_STD_FANFOLD, 8500, 12000 },
  62. { IDS_WIA_PAPER_SIZE_9X11, 9000, 11000 },
  63. { IDS_WIA_PAPER_SIZE_A4_ROTATED, 11693, 8268 },
  64. { IDS_WIA_PAPER_SIZE_A4, 8268, 11693 },
  65. { IDS_WIA_PAPER_SIZE_LETTER_ROTATED, 11000, 8500 },
  66. { IDS_WIA_PAPER_SIZE_LETTER, 8500, 11000 },
  67. { IDS_WIA_PAPER_SIZE_JAPAN_ENVELOPE_KAKU_3_ROTATED, 10906, 8504 },
  68. { IDS_WIA_PAPER_SIZE_JAPANESE_ENVELOPE_KAKU_3, 8504, 10906 },
  69. { IDS_WIA_PAPER_SIZE_QUARTO, 8465, 10827 },
  70. { IDS_WIA_PAPER_SIZE_B5_ISO_EXTRA, 7913, 10866 },
  71. { IDS_WIA_PAPER_SIZE_EXECUTIVE, 7250, 10500 },
  72. { IDS_WIA_PAPER_SIZE_PRC_16K_ROTATED, 10236, 7402 },
  73. { IDS_WIA_PAPER_SIZE_PRC_16K, 7402, 10236 },
  74. { IDS_WIA_PAPER_SIZE_ENVELOPE_INVITE, 8661, 8661 },
  75. { IDS_WIA_PAPER_SIZE_B5_JIS_ROTATED, 10118, 7165 },
  76. { IDS_WIA_PAPER_SIZE_B5_JIS, 7165, 10118 },
  77. { IDS_WIA_PAPER_SIZE_ENVELOPE_B5, 6929, 9843 },
  78. { IDS_WIA_PAPER_SIZE_A5_EXTRA, 6850, 9252 },
  79. { IDS_WIA_PAPER_SIZE_ENVELOPE_C5, 6378, 9016 },
  80. { IDS_WIA_PAPER_SIZE_ENVELOPE_14, 5000, 11500 },
  81. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_8_ROTATED, 12165, 4724 },
  82. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_8, 4724, 12165 },
  83. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_7_ROTATED, 9055, 6299 },
  84. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_7, 6299, 9055 },
  85. { IDS_WIA_PAPER_SIZE_ENVELOPE_12, 4750, 11000 },
  86. { IDS_WIA_PAPER_SIZE_A5_ROTATED, 8268, 5827 },
  87. { IDS_WIA_PAPER_SIZE_A5, 5827, 8268 },
  88. { IDS_WIA_PAPER_SIZE_STATEMENT, 5500, 8500 },
  89. { IDS_WIA_PAPER_SIZE_ENVELOPE_11, 4500, 10375 },
  90. { IDS_WIA_PAPER_SIZE_JAPANESE_DOUBLE_POSTCARD, 7874, 5827 },
  91. { IDS_WIA_PAPER_SIZE_DOUBLE_JAPAN_POSTCARD_ROTATED, 5827, 7874 },
  92. { IDS_WIA_PAPER_SIZE_PRC_32KBIG_ROTATED, 7992, 5512 },
  93. { IDS_WIA_PAPER_SIZE_PRC_32KBIG, 5512, 7992 },
  94. { IDS_WIA_PAPER_SIZE_JAPAN_ENVELOPE_CHOU_3_ROTATED, 9252, 4724 },
  95. { IDS_WIA_PAPER_SIZE_JAPANESE_ENVELOPE_CHOU_3, 4724, 9252 },
  96. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_6_ROTATED, 9055, 4724 },
  97. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_6, 4724, 9055 },
  98. { IDS_WIA_PAPER_SIZE_ENVELOPE_C65, 4488, 9016 },
  99. { IDS_WIA_PAPER_SIZE_ENVELOPE, 4331, 9055 },
  100. { IDS_WIA_PAPER_SIZE_ENVELOPE_10, 4125, 9500 },
  101. { IDS_WIA_PAPER_SIZE_JAPAN_ENVELOPE_YOU_4_ROTATED, 9252, 4134 },
  102. { IDS_WIA_PAPER_SIZE_JAPAN_ENVELOPE_YOU_4, 4134, 9252 },
  103. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_5_ROTATED, 8661, 4331 },
  104. { IDS_WIA_PAPER_SIZE_ENVELOPE_DL, 4331, 8661 },
  105. { IDS_WIA_PAPER_SIZE_PRC_32K_ROTATED, 7244, 5118 },
  106. { IDS_WIA_PAPER_SIZE_PRC_32K, 5118, 7244 },
  107. { IDS_WIA_PAPER_SIZE_B6, 5040, 7170 },
  108. { IDS_WIA_PAPER_SIZE_B6_JIS_ROTATED, 7165, 5039 },
  109. { IDS_WIA_PAPER_SIZE_B6_JIS, 5039, 7165 },
  110. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_4_ROTATED, 8189, 4331 },
  111. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_4, 4331, 8189 },
  112. { IDS_WIA_PAPER_SIZE_ENVELOPE_9, 3875, 8875 },
  113. { IDS_WIA_PAPER_SIZE_ENVELOPE_B6, 6929, 4921 },
  114. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_3, 4921, 6929 },
  115. { IDS_WIA_PAPER_SIZE_ENVELOPE_MONARCH, 3875, 7500 },
  116. { IDS_WIA_PAPER_SIZE_ENVELOPE_C6, 4488, 6378 },
  117. { IDS_WIA_PAPER_SIZE_JAPAN_ENVELOPE_CHOU_4_ROTATED, 8071, 3543 },
  118. { IDS_WIA_PAPER_SIZE_JAPANESE_ENVELOPE_CHOU_4, 3543, 8071 },
  119. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_2_ROTATED, 6929, 4016 },
  120. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_2, 4016, 6929 },
  121. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_1_ROTATED, 6496, 4016 },
  122. { IDS_WIA_PAPER_SIZE_PRC_ENVELOPE_1, 4016, 6496 },
  123. { IDS_WIA_PAPER_SIZE_A6_105_X_148, 4133, 5830 },
  124. { IDS_WIA_PAPER_SIZE_A6_ROTATED, 5827, 4134 },
  125. { IDS_WIA_PAPER_SIZE_A6, 4134, 5827 },
  126. { IDS_WIA_PAPER_SIZE_6_34_ENVELOPE, 3625, 6500 },
  127. { IDS_WIA_PAPER_SIZE_JAPANESE_POSTCARD_ROTATED, 5827, 3937 },
  128. { IDS_WIA_PAPER_SIZE_JAPANESE_POSTCARD, 3937, 5827 }
  129. };
  130. static const UINT g_SupportedPaperSizeCount = ARRAYSIZE(g_SupportedPaperSizes);
  131. STDMETHODIMP CWiaDefaultUI::GetPaperSizes( CWiaPaperSize **ppPaperSizes, UINT *pnCount )
  132. {
  133. //
  134. // Verify arguments
  135. //
  136. if (!ppPaperSizes || !pnCount)
  137. {
  138. return E_INVALIDARG;
  139. }
  140. //
  141. // Initialize to NULL
  142. //
  143. *ppPaperSizes = NULL;
  144. *pnCount = 0;
  145. //
  146. // Allocate the array of paper sizes
  147. //
  148. CWiaPaperSize *pPaperSizes = reinterpret_cast<CWiaPaperSize*>(CoTaskMemAlloc( sizeof(CWiaPaperSize) * g_SupportedPaperSizeCount ));
  149. if (pPaperSizes)
  150. {
  151. //
  152. // Initialize each name, so we can delete them if we encounter an error.
  153. //
  154. for (UINT i=0;i<g_SupportedPaperSizeCount;i++)
  155. {
  156. pPaperSizes[i].pszName = NULL;
  157. }
  158. //
  159. // Assume success
  160. //
  161. bool bSucceeded = true;
  162. //
  163. // Loop through the paper size array
  164. //
  165. for (UINT i=0;i<g_SupportedPaperSizeCount && bSucceeded;i++)
  166. {
  167. //
  168. // Load the name of this paper size
  169. //
  170. CSimpleStringWide strPaperName = CSimpleStringConvert::WideString(CSimpleString(g_SupportedPaperSizes[i].nStringId,g_hInstance));
  171. if (strPaperName.Length())
  172. {
  173. //
  174. // Allocate the string to hold the paper size name
  175. //
  176. pPaperSizes[i].pszName = reinterpret_cast<LPWSTR>(CoTaskMemAlloc((strPaperName.Length()+1) * sizeof(WCHAR)));
  177. if (pPaperSizes[i].pszName)
  178. {
  179. //
  180. // Copy over all the paper size values
  181. //
  182. lstrcpyW( pPaperSizes[i].pszName, strPaperName );
  183. pPaperSizes[i].nWidth = g_SupportedPaperSizes[i].nWidth;
  184. pPaperSizes[i].nHeight = g_SupportedPaperSizes[i].nHeight;
  185. }
  186. else
  187. {
  188. bSucceeded = false;
  189. }
  190. }
  191. else
  192. {
  193. bSucceeded = false;
  194. }
  195. }
  196. //
  197. // If we hit some kind of error, free all memory
  198. //
  199. if (!bSucceeded)
  200. {
  201. UINT nCount = g_SupportedPaperSizeCount;
  202. FreePaperSizes( &pPaperSizes, &nCount );
  203. }
  204. }
  205. //
  206. // Save the paper size and the array size
  207. //
  208. *ppPaperSizes = pPaperSizes;
  209. *pnCount = g_SupportedPaperSizeCount;
  210. //
  211. // Return success if we successfully allocated the paper size array
  212. //
  213. return (*ppPaperSizes && *pnCount) ? S_OK : E_FAIL;
  214. }
  215. STDMETHODIMP CWiaDefaultUI::FreePaperSizes( CWiaPaperSize **ppPaperSizes, UINT *pnCount )
  216. {
  217. //
  218. // Verify arguments
  219. //
  220. if (!ppPaperSizes || !pnCount)
  221. {
  222. return E_INVALIDARG;
  223. }
  224. //
  225. // Loop and free the strings
  226. //
  227. for (UINT i=0;i<*pnCount;i++)
  228. {
  229. if ((*ppPaperSizes)[i].pszName)
  230. {
  231. CoTaskMemFree((*ppPaperSizes)[i].pszName);
  232. }
  233. }
  234. //
  235. // Free the array
  236. //
  237. CoTaskMemFree(*ppPaperSizes);
  238. //
  239. // 0 everything
  240. //
  241. *ppPaperSizes = NULL;
  242. *pnCount = 0;
  243. return S_OK;
  244. }