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.

1076 lines
33 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2002
  4. *
  5. * TITLE: validate.cpp
  6. *
  7. * VERSION: 1.1
  8. *
  9. * DATE: 05 March, 2002
  10. *
  11. * DESCRIPTION:
  12. *
  13. *******************************************************************************/
  14. #include "pch.h"
  15. extern HINSTANCE g_hInst; // used for WIAS_LOGPROC macro
  16. #define MAX_PAGE_CAPACITY 25 // 25 pages
  17. /**************************************************************************\
  18. * ValidateDataTransferContext
  19. *
  20. * Checks the data transfer context to ensure it's valid.
  21. *
  22. * Arguments:
  23. *
  24. * pDataTransferContext - Pointer the data transfer context.
  25. *
  26. * Return Value:
  27. *
  28. * Status
  29. *
  30. * History:
  31. *
  32. * 03/05/2002 Original Version
  33. *
  34. \**************************************************************************/
  35. HRESULT CWIADevice::ValidateDataTransferContext(
  36. PMINIDRV_TRANSFER_CONTEXT pDataTransferContext)
  37. {
  38. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  39. WIALOG_NO_RESOURCE_ID,
  40. WIALOG_LEVEL3,
  41. "::ValidateDataTransferContext");
  42. //
  43. // If the caller does not specify a MINIDRV_TRANSFER_CONTEXT structure
  44. // pointer then fail with E_INVALIDARG.
  45. //
  46. if(!pDataTransferContext)
  47. {
  48. return E_INVALIDARG;
  49. }
  50. //
  51. // If the size of the MINIDRV_TRANSFER_CONTEXT is not equal to the one
  52. // that is expected, then fail with E_INVALIDARG.
  53. //
  54. if (pDataTransferContext->lSize != sizeof(MINIDRV_TRANSFER_CONTEXT)) {
  55. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ValidateDataTransferContext, invalid data transfer context"));
  56. return E_INVALIDARG;
  57. }
  58. HRESULT hr = S_OK;
  59. switch(pDataTransferContext->tymed)
  60. {
  61. case TYMED_FILE:
  62. {
  63. //
  64. // If the FORMAT guid is not WiaImgFmt_BMP or WiaImgFmt_TIFF
  65. // then fail with E_INVALIDARG
  66. //
  67. if ((pDataTransferContext->guidFormatID != WiaImgFmt_BMP) &&
  68. (pDataTransferContext->guidFormatID != WiaImgFmt_TIFF)) {
  69. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ValidateDataTransferContext, invalid format for TYMED_FILE"));
  70. hr = E_INVALIDARG;
  71. }
  72. }
  73. break;
  74. case TYMED_CALLBACK:
  75. {
  76. //
  77. // If the FORMAT guid is not WiaImgFmt_MEMORYBMP
  78. // then fail with E_INVALIDARG
  79. //
  80. if(pDataTransferContext->guidFormatID != WiaImgFmt_MEMORYBMP){
  81. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ValidateDataTransferContext, invalid format for TYMED_CALLBACK"));
  82. hr = E_INVALIDARG;
  83. }
  84. }
  85. break;
  86. case TYMED_MULTIPAGE_FILE:
  87. {
  88. //
  89. // If the FORMAT guid is not WiaImgFmt_TIFF
  90. // then fail with E_INVALIDARG
  91. //
  92. if(pDataTransferContext->guidFormatID != WiaImgFmt_TIFF){
  93. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ValidateDataTransferContext, invalid format for TYMED_MULTIPAGE_FILE"));
  94. hr = E_INVALIDARG;
  95. }
  96. }
  97. break;
  98. case TYMED_MULTIPAGE_CALLBACK:
  99. {
  100. //
  101. // If the FORMAT guid is not WiaImgFmt_TIFF
  102. // then fail with E_INVALIDARG
  103. //
  104. if(pDataTransferContext->guidFormatID != WiaImgFmt_TIFF){
  105. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ValidateDataTransferContext, invalid format for TYMED_MULTIPAGE_CALLBACK"));
  106. hr = E_INVALIDARG;
  107. }
  108. }
  109. break;
  110. default:
  111. hr = E_INVALIDARG;
  112. break;
  113. }
  114. return hr;
  115. }
  116. /**************************************************************************\
  117. * UpdateValidDepth
  118. *
  119. * Helper that updates the valid value for depth based on the data type.
  120. *
  121. * Arguments:
  122. *
  123. * pWiasContext - a pointer to the WiaItem context
  124. * lDataType - the value of the DataType property.
  125. * lDepth - the address of the variable where the Depth's new value
  126. * will be returned.
  127. *
  128. * Return Value:
  129. *
  130. * Status - S_OK if successful
  131. * E_INVALIDARG if lDataType is unknown
  132. * Errors are those returned by wiasReadPropLong,
  133. * and wiasWritePropLong.
  134. *
  135. * History:
  136. *
  137. * 03/05/2002 Original Version
  138. *
  139. \**************************************************************************/
  140. HRESULT CWIADevice::UpdateValidDepth(
  141. BYTE *pWiasContext,
  142. LONG lDataType,
  143. LONG *lDepth)
  144. {
  145. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  146. WIALOG_NO_RESOURCE_ID,
  147. WIALOG_LEVEL3,
  148. "CWIADevice::UpdateValidDepth");
  149. //
  150. // If the caller did not pass in the correct parameters, then fail the
  151. // call with E_INVALIDARG.
  152. //
  153. if((!pWiasContext)||(!lDepth)){
  154. return E_INVALIDARG;
  155. }
  156. //
  157. // Set the lDepth value according to the current lDataType setting
  158. //
  159. switch (lDataType) {
  160. case WIA_DATA_THRESHOLD:
  161. *lDepth = 1;
  162. break;
  163. case WIA_DATA_GRAYSCALE:
  164. *lDepth = 8;
  165. break;
  166. case WIA_DATA_COLOR:
  167. *lDepth = 24;
  168. break;
  169. default:
  170. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("UpdateValidDepth, unknown data type"));
  171. return E_INVALIDARG;
  172. }
  173. return S_OK;
  174. }
  175. /**************************************************************************\
  176. * CheckDataType
  177. *
  178. * This helper method is called to check whether WIA_IPA_DATATYPE
  179. * property is changed. When this property changes, other dependant
  180. * properties and their valid values must also be changed.
  181. *
  182. * Arguments:
  183. *
  184. * pWiasContext - a pointer to the item context whose properties have
  185. * changed.
  186. * pContext - a pointer to the property context (which indicates
  187. * which properties are being written).
  188. *
  189. * Return Value:
  190. *
  191. * Status
  192. *
  193. * History:
  194. *
  195. * 03/05/2002 Original Version
  196. *
  197. \**************************************************************************/
  198. HRESULT CWIADevice::CheckDataType(
  199. BYTE *pWiasContext,
  200. WIA_PROPERTY_CONTEXT *pContext)
  201. {
  202. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  203. WIALOG_NO_RESOURCE_ID,
  204. WIALOG_LEVEL3,
  205. "CWIADevice::CheckDataType");
  206. //
  207. // If the caller did not pass in the correct parameters, then fail the
  208. // call with E_INVALIDARG.
  209. //
  210. if((!pWiasContext)||(!pContext)){
  211. return E_INVALIDARG;
  212. }
  213. WIAS_CHANGED_VALUE_INFO cviDataType;
  214. memset(&cviDataType,0,sizeof(cviDataType));
  215. WIAS_CHANGED_VALUE_INFO cviDepth;
  216. memset(&cviDepth,0,sizeof(cviDepth));
  217. //
  218. // Call wiasGetChangedValue for DataType. It is checked first since it's
  219. // not dependant on any other property. All properties in this method
  220. // that follow are dependant properties of DataType.
  221. //
  222. // The call to wiasGetChangedValue specifies that validation should not be
  223. // skipped (since valid values for DataType never change). Also,
  224. // the address of a variable for the old value is NULL, since the old
  225. // value is not needed. The address of bDataTypeChanged is passed
  226. // so that dependant properties will know whether the DataType is being
  227. // changed or not. This is important since dependant properties may need
  228. // their valid values updated and may need to be folded to new valid
  229. // values.
  230. //
  231. HRESULT hr = wiasGetChangedValueLong(pWiasContext,pContext,FALSE,WIA_IPA_DATATYPE,&cviDataType);
  232. if (FAILED(hr)) {
  233. return hr;
  234. }
  235. //
  236. // Call wiasGetChangedValue for Depth. Depth is a dependant property of
  237. // DataType whose valid value changes according to what the current
  238. // value of DataType is.
  239. //
  240. // The call to wiasGetChangedValue specifies that validation should only
  241. // be skipped if the DataType has changed. This is because the valid
  242. // values for Depth will change according to the new value for
  243. // DataType. The address of a variable for the old value is NULL, since
  244. // the old value is not needed. The address of bDepthChanged is passed
  245. // so that dependant properties will know whether the Depth is being
  246. // changed or not. This is important since dependant properties may need
  247. // their valid values updated and may need to be folded to new valid
  248. // values.
  249. //
  250. hr = wiasGetChangedValueLong(pWiasContext,pContext,cviDataType.bChanged,WIA_IPA_DEPTH,&cviDepth);
  251. if (FAILED(hr)) {
  252. return hr;
  253. }
  254. if (cviDataType.bChanged) {
  255. //
  256. // DataType changed so update valid value for Depth
  257. //
  258. hr = UpdateValidDepth(pWiasContext, cviDataType.Current.lVal, &cviDepth.Current.lVal);
  259. if (S_OK == hr) {
  260. //
  261. // Check whether we must fold. Depth will only be folded if it
  262. // is not one of the properties that the app is changing.
  263. //
  264. if (!cviDepth.bChanged) {
  265. hr = wiasWritePropLong(pWiasContext, WIA_IPA_DEPTH, cviDepth.Current.lVal);
  266. }
  267. }
  268. }
  269. //
  270. // Update properties dependant on DataType and Depth.
  271. // Here, ChannelsPerPixel and BitsPerChannel are updated.
  272. //
  273. if (cviDataType.bChanged || cviDepth.bChanged) {
  274. if (S_OK == hr) {
  275. //
  276. // initialize PROPSPEC array
  277. //
  278. PROPSPEC ps[2] = {
  279. {PRSPEC_PROPID, WIA_IPA_CHANNELS_PER_PIXEL},
  280. {PRSPEC_PROPID, WIA_IPA_BITS_PER_CHANNEL }
  281. };
  282. //
  283. // initilize PROPVARIANT array
  284. //
  285. PROPVARIANT pv[2];
  286. for (LONG index = 0; index < 2; index++) {
  287. PropVariantInit(&pv[index]);
  288. pv[index].vt = VT_I4;
  289. }
  290. //
  291. // use the current WIA data type to determine the proper
  292. // WIA_IPA_CHANNELS_PER_PIXEL and WIA_IPA_BITS_PER_CHANNEL
  293. // settings
  294. //
  295. switch (cviDataType.Current.lVal) {
  296. case WIA_DATA_THRESHOLD:
  297. pv[0].lVal = 1;
  298. pv[1].lVal = 1;
  299. break;
  300. case WIA_DATA_GRAYSCALE:
  301. pv[0].lVal = 1;
  302. pv[1].lVal = 8;
  303. break;
  304. case WIA_DATA_COLOR:
  305. pv[0].lVal = 3;
  306. pv[1].lVal = 8;
  307. break;
  308. default:
  309. pv[0].lVal = 1;
  310. pv[1].lVal = 8;
  311. break;
  312. }
  313. hr = wiasWriteMultiple(pWiasContext, 2, ps, pv);
  314. }
  315. }
  316. return hr;
  317. }
  318. /**************************************************************************\
  319. * CheckIntent
  320. *
  321. * This helper method is called to make the relevant changes if the
  322. * Current Intent property changes.
  323. *
  324. * Arguments:
  325. *
  326. * pWiasContext - a pointer to the item context whose properties have
  327. * changed.
  328. * pContext - a pointer to the property context (which indicates
  329. * which properties are being written).
  330. *
  331. * Return Value:
  332. *
  333. * Status
  334. *
  335. * History:
  336. *
  337. * 03/05/2002 Original Version
  338. *
  339. \**************************************************************************/
  340. HRESULT CWIADevice::CheckIntent(
  341. BYTE *pWiasContext,
  342. WIA_PROPERTY_CONTEXT *pContext)
  343. {
  344. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  345. WIALOG_NO_RESOURCE_ID,
  346. WIALOG_LEVEL3,
  347. "CWIADevice::CheckIntent");
  348. //
  349. // If the caller did not pass in the correct parameters, then fail the
  350. // call with E_INVALIDARG.
  351. //
  352. if((!pWiasContext)||(!pContext)) {
  353. return E_INVALIDARG;
  354. }
  355. WIAS_CHANGED_VALUE_INFO cviIntent;
  356. memset(&cviIntent,0,sizeof(cviIntent));
  357. //
  358. // Call wiasGetChangedValue for CurrentIntent. CurrentIntent is checked first
  359. // since it's not dependant on any other property. All properties in
  360. // this method that follow are dependant properties of CurrentIntent.
  361. //
  362. // The call to wiasGetChangedValue specifies that validation should not be
  363. // skipped (since valid values for CurrentIntent never change). The
  364. // address of the old value is specified as NULL, since it is not used.
  365. // The address of bIntentChanged is passed so that dependant properties
  366. // will know whether the YResolution is being changed or not. This is
  367. // important since dependant properties will need their valid values
  368. // updated and may need to be folded to new valid values.
  369. //
  370. HRESULT hr = wiasGetChangedValueLong(pWiasContext,pContext,FALSE,WIA_IPS_CUR_INTENT,&cviIntent);
  371. if (S_OK ==hr) {
  372. //
  373. // If the WIA intent value was changed, then validate dependant values:
  374. // WIA_IPA_DATATYPE
  375. // WIA_IPA_DEPTH
  376. // WIA_IPS_XRES
  377. // WIA_IPS_YRES
  378. // WIA_IPS_XEXTENT
  379. // WIA_IPS_YEXTENT
  380. // WIA_IPA_PIXELS_PER_LINE
  381. // WIA_IPA_NUMBER_OF_LINES
  382. //
  383. if (cviIntent.bChanged) {
  384. LONG lImageTypeIntent = (cviIntent.Current.lVal & WIA_INTENT_IMAGE_TYPE_MASK);
  385. LONG lDataType = WIA_DATA_GRAYSCALE;
  386. LONG lDepth = 8;
  387. BOOL bUpdateDataTypeAndDepth = TRUE;
  388. switch (lImageTypeIntent) {
  389. case WIA_INTENT_NONE:
  390. bUpdateDataTypeAndDepth = FALSE;
  391. break;
  392. case WIA_INTENT_IMAGE_TYPE_GRAYSCALE:
  393. lDataType = WIA_DATA_GRAYSCALE;
  394. lDepth = 8;
  395. break;
  396. case WIA_INTENT_IMAGE_TYPE_TEXT:
  397. lDataType = WIA_DATA_THRESHOLD;
  398. lDepth = 1;
  399. break;
  400. case WIA_INTENT_IMAGE_TYPE_COLOR:
  401. lDataType = WIA_DATA_COLOR;
  402. lDepth = 24;
  403. break;
  404. default:
  405. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, unknown intent (TYPE) = %d",lImageTypeIntent));
  406. return E_INVALIDARG;
  407. }
  408. if (bUpdateDataTypeAndDepth) {
  409. //
  410. // update the WIA_IPA_DATATYPE property and the WIA_IPA_DEPTH property
  411. //
  412. hr = wiasWritePropLong(pWiasContext, WIA_IPA_DATATYPE, lDataType);
  413. if (S_OK == hr) {
  414. hr = wiasWritePropLong(pWiasContext, WIA_IPA_DEPTH, lDepth);
  415. }
  416. }
  417. //
  418. // if we failed to complete the above operations, then
  419. // return, to avoid proceeding any more.
  420. //
  421. if(FAILED(hr)){
  422. return hr;
  423. }
  424. LONG lImageSizeIntent = (cviIntent.Current.lVal & WIA_INTENT_SIZE_MASK);
  425. switch (lImageSizeIntent) {
  426. case WIA_INTENT_NONE:
  427. break;
  428. case WIA_INTENT_MINIMIZE_SIZE:
  429. case WIA_INTENT_MAXIMIZE_QUALITY:
  430. {
  431. //
  432. // Set the X and Y Resolutions.
  433. //
  434. hr = wiasWritePropLong(pWiasContext, WIA_IPS_XRES, lImageSizeIntent & WIA_INTENT_MINIMIZE_SIZE ? 150 : 300);
  435. if(S_OK == hr){
  436. hr = wiasWritePropLong(pWiasContext, WIA_IPS_YRES, lImageSizeIntent & WIA_INTENT_MINIMIZE_SIZE ? 150 : 300);
  437. }
  438. //
  439. // check if we failed to update the WIA_IPS_XRES and WIA_IPS_YRES property
  440. //
  441. if(FAILED(hr)){
  442. return hr;
  443. }
  444. //
  445. // The Resolutions and DataType were set, so update the property
  446. // context to indicate that they have changed.
  447. //
  448. hr = wiasSetPropChanged(WIA_IPS_XRES, pContext, TRUE);
  449. if(S_OK == hr){
  450. hr = wiasSetPropChanged(WIA_IPS_YRES, pContext, TRUE);
  451. if(S_OK == hr){
  452. hr = wiasSetPropChanged(WIA_IPA_DATATYPE, pContext, TRUE);
  453. }
  454. }
  455. //
  456. // check if we failed to flag WIA_IPS_XRES, WIA_IPS_YRES, and WIA_IPA_DATATYPE
  457. // properties as changed
  458. //
  459. if(FAILED(hr)){
  460. return hr;
  461. }
  462. //
  463. // update IPA_NUMBER_OF_LINES property
  464. //
  465. LONG lLength = 0;
  466. hr = wiasReadPropLong(pWiasContext, WIA_IPS_YEXTENT, &lLength, NULL, TRUE);
  467. if (SUCCEEDED(hr)) {
  468. hr = wiasWritePropLong(pWiasContext, WIA_IPA_NUMBER_OF_LINES, lLength);
  469. if (FAILED(hr)) {
  470. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not write WIA_IPA_NUMBER_OF_LINES"));
  471. return hr;
  472. }
  473. } else {
  474. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not read WIA_IPS_YEXTENT"));
  475. return hr;
  476. }
  477. //
  478. // update IPA_PIXEL_PER_LINE property
  479. //
  480. LONG lWidth = 0;
  481. hr = wiasReadPropLong(pWiasContext, WIA_IPS_XEXTENT, &lWidth, NULL, TRUE);
  482. if (SUCCEEDED(hr)) {
  483. hr = wiasWritePropLong(pWiasContext, WIA_IPA_PIXELS_PER_LINE, lWidth);
  484. if (FAILED(hr)) {
  485. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not write WIA_IPA_PIXELS_PER_LINE"));
  486. return hr;
  487. }
  488. } else {
  489. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not read WIA_IPS_XEXTENT"));
  490. return hr;
  491. }
  492. }
  493. break;
  494. default:
  495. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, unknown intent (SIZE) = %d",lImageSizeIntent));
  496. return E_INVALIDARG;
  497. }
  498. }
  499. } else {
  500. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, wiasGetChangedValue (intent) failed"));
  501. }
  502. return hr;
  503. }
  504. /**************************************************************************\
  505. * CheckPreferredFormat
  506. *
  507. * This helper method is called to make the relevant changes if the
  508. * Format property changes.
  509. *
  510. * Arguments:
  511. *
  512. * pWiasContext - a pointer to the item context whose properties have
  513. * changed.
  514. * pContext - a pointer to the property context (which indicates
  515. * which properties are being written).
  516. *
  517. * Return Value:
  518. *
  519. * Status
  520. *
  521. * History:
  522. *
  523. * 03/05/2002 Original Version
  524. *
  525. \**************************************************************************/
  526. HRESULT CWIADevice::CheckPreferredFormat(
  527. BYTE *pWiasContext,
  528. WIA_PROPERTY_CONTEXT *pContext)
  529. {
  530. //
  531. // If the caller did not pass in the correct parameters, then fail the
  532. // call with E_INVALIDARG.
  533. //
  534. if((!pWiasContext)||(!pContext)){
  535. return E_INVALIDARG;
  536. }
  537. //
  538. // update WIA_IPA_PREFERRED_FORMAT property to match current WIA_IPA_FORMAT setting.
  539. // This is a simple way of keeping the WIA_IPA_PREFERRED_FORMAT in sync with the
  540. // valid FORMAT.
  541. //
  542. // The proper action to take here is to choose the real preferred
  543. // format of your driver that fits in the valid value set of the current WIA_IPA_FORMAT
  544. // setting. The preferred format is a value that appliations may use to transfer by default.
  545. //
  546. // example: if your driver supports JPEG, and you prefer the application to transfer in JPEG
  547. // when ever possible, then make sure your preferred format is always JPEG. Remember
  548. // that the preferred format can only be set to JPEG if JPEG is one of the current
  549. // valid values for WIA_IPA_FORMAT. (If it is not, then the application might attempt
  550. // to set an invalid value, by reading the WIA_IPA_PREFERRED_FORMAT and writing it to
  551. // WIA_IPA_FORMAT)
  552. //
  553. GUID FormatGUID = GUID_NULL;
  554. HRESULT hr = wiasReadPropGuid(pWiasContext, WIA_IPA_FORMAT, &FormatGUID, NULL, TRUE);
  555. if (S_OK == hr) {
  556. //
  557. // update the WIA_IPA_FILENAME_EXTENSION property to the correct file extension
  558. //
  559. BSTR bstrFileExt = NULL;
  560. if((FormatGUID == WiaImgFmt_BMP)||(FormatGUID == WiaImgFmt_MEMORYBMP)) {
  561. bstrFileExt = SysAllocString(L"BMP");
  562. } else if (FormatGUID == WiaImgFmt_TIFF){
  563. bstrFileExt = SysAllocString(L"TIF");
  564. }
  565. //
  566. // if the allocation of the BSTR is successful, then attempt to set the
  567. // WIA_IPA_FILENAME_EXTENSION property.
  568. //
  569. if(bstrFileExt) {
  570. hr = wiasWritePropStr(pWiasContext,WIA_IPA_FILENAME_EXTENSION,bstrFileExt);
  571. //
  572. // free the allocated BSTR file extension
  573. //
  574. SysFreeString(bstrFileExt);
  575. bstrFileExt = NULL;
  576. }
  577. if (S_OK == hr){
  578. hr = wiasWritePropGuid(pWiasContext, WIA_IPA_PREFERRED_FORMAT, FormatGUID);
  579. if (FAILED(hr)){
  580. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckPreferredFormat, could not write WIA_IPA_PREFERRED_FORMAT"));
  581. return hr;
  582. }
  583. }
  584. } else {
  585. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not read WIA_IPA_FORMAT"));
  586. }
  587. return hr;
  588. }
  589. /**************************************************************************\
  590. * CheckADFStatus
  591. *
  592. *
  593. * Arguments:
  594. *
  595. * pWiasContext - a pointer to the item context whose properties have
  596. * changed.
  597. * pContext - a pointer to the property context (which indicates
  598. * which properties are being written).
  599. *
  600. * Return Value:
  601. *
  602. * Status
  603. *
  604. * History:
  605. *
  606. * 03/05/2002 Original Version
  607. *
  608. \**************************************************************************/
  609. HRESULT CWIADevice::CheckADFStatus(BYTE *pWiasContext,
  610. WIA_PROPERTY_CONTEXT *pContext)
  611. {
  612. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  613. WIALOG_NO_RESOURCE_ID,
  614. WIALOG_LEVEL3,
  615. "CWIADevice::CheckADFStatus");
  616. //
  617. // If the caller did not pass in the correct parameters, then fail the
  618. // call with E_INVALIDARG.
  619. //
  620. if((!pWiasContext)||(!pContext)){
  621. return E_INVALIDARG;
  622. }
  623. //
  624. // If there is NOT an ADF attached, just return S_OK, telling the caller that
  625. // everything is OK
  626. //
  627. if(!m_bADFAttached){
  628. return S_OK;
  629. }
  630. //
  631. // get the ROOT item, this is where the document feeder properties exist
  632. //
  633. BYTE *pRootItemCtx = NULL;
  634. HRESULT hr = wiasGetRootItem(pWiasContext, &pRootItemCtx);
  635. if (FAILED(hr)) {
  636. return E_FAIL;
  637. }
  638. //
  639. // read the current WIA_DPS_DOCUMENT_HANDLING_SELECT setting from the ROOT
  640. // item.
  641. //
  642. LONG lDocHandlingSelect = 0;
  643. hr = wiasReadPropLong(pRootItemCtx,
  644. WIA_DPS_DOCUMENT_HANDLING_SELECT,
  645. &lDocHandlingSelect,
  646. NULL,
  647. FALSE);
  648. //
  649. // if S_FALSE is returned, then the WIA_DPS_DOCUMENT_HANDLING_SELECT property does
  650. // not exist. This means that we should default to FLATBED settings
  651. //
  652. if(hr == S_FALSE){
  653. lDocHandlingSelect = FLATBED;
  654. }
  655. //
  656. // turn ON/OFF the ADF controller flag
  657. //
  658. if (SUCCEEDED(hr)) {
  659. switch (lDocHandlingSelect) {
  660. case FEEDER:
  661. m_bADFEnabled = TRUE;
  662. hr = S_OK;
  663. break;
  664. case FLATBED:
  665. m_bADFEnabled = FALSE;
  666. hr = S_OK;
  667. break;
  668. default:
  669. hr = E_INVALIDARG;
  670. break;
  671. }
  672. }
  673. if (S_OK == hr) {
  674. //
  675. // update document handling status
  676. //
  677. if (m_bADFEnabled) {
  678. HRESULT Temphr = m_pScanAPI->FakeScanner_ADFAvailable();
  679. if (S_OK == Temphr) {
  680. hr = wiasWritePropLong(pWiasContext, WIA_DPS_DOCUMENT_HANDLING_STATUS,FEED_READY);
  681. } else {
  682. hr = wiasWritePropLong(pWiasContext, WIA_DPS_DOCUMENT_HANDLING_STATUS,PAPER_JAM);
  683. }
  684. if (FAILED(Temphr))
  685. hr = Temphr;
  686. } else {
  687. hr = wiasWritePropLong(pWiasContext, WIA_DPS_DOCUMENT_HANDLING_STATUS,FLAT_READY);
  688. }
  689. }
  690. return hr;
  691. }
  692. /**************************************************************************\
  693. * CheckPreview
  694. *
  695. *
  696. * Arguments:
  697. *
  698. * pWiasContext - a pointer to the item context whose properties have
  699. * changed.
  700. * pContext - a pointer to the property context (which indicates
  701. * which properties are being written).
  702. *
  703. * Return Value:
  704. *
  705. * Status
  706. *
  707. * History:
  708. *
  709. * 03/05/2002 Original Version
  710. *
  711. \**************************************************************************/
  712. HRESULT CWIADevice::CheckPreview(BYTE *pWiasContext,
  713. WIA_PROPERTY_CONTEXT *pContext)
  714. {
  715. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  716. WIALOG_NO_RESOURCE_ID,
  717. WIALOG_LEVEL3,
  718. "CWIADevice::CheckPreview");
  719. //
  720. // If the caller did not pass in the correct parameters, then fail the
  721. // call with E_INVALIDARG.
  722. //
  723. if((!pWiasContext)||(!pContext)){
  724. return E_INVALIDARG;
  725. }
  726. //
  727. // get the ROOT item, this is where the preview property exists
  728. //
  729. BYTE *pRootItemCtx = NULL;
  730. HRESULT hr = wiasGetRootItem(pWiasContext, &pRootItemCtx);
  731. if (FAILED(hr)) {
  732. return E_FAIL;
  733. }
  734. //
  735. // read the current WIA_DPS_PREVIEW setting from the ROOT item.
  736. //
  737. LONG lPreview = 0;
  738. hr = wiasReadPropLong(pRootItemCtx,WIA_DPS_PREVIEW,&lPreview,NULL,FALSE);
  739. if(hr == S_FALSE){
  740. //
  741. // if S_FALSE is returned, then the WIA_DPS_PREVIEW property does
  742. // not exist. Return S_OK, because we are can not proceed any more.
  743. //
  744. return S_OK;
  745. }
  746. //
  747. // log the results to the debugger, to show the current status of the WIA_DPS_PREVIEW
  748. // property. This is where you would normally perform an operation to set the WIA minidriver
  749. // into PREVIEW mode. (ON/OFF)
  750. //
  751. if (S_OK == hr) {
  752. switch (lPreview) {
  753. case WIA_FINAL_SCAN:
  754. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("CheckPreview, Set to WIA_FINAL_SCAN"));
  755. break;
  756. case WIA_PREVIEW_SCAN:
  757. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("CheckPreview, Set to WIA_PREVIEW_SCAN"));
  758. break;
  759. default:
  760. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("CheckPreview, Set to invalid argument (%d)",lPreview));
  761. hr = E_INVALIDARG;
  762. break;
  763. }
  764. }
  765. return hr;
  766. }
  767. /**************************************************************************\
  768. * UpdateValidPages
  769. *
  770. * This helper method is called to make the relevant changes to the Pages
  771. * property if a file format can not support multi-page.
  772. *
  773. * Arguments:
  774. *
  775. * pWiasContext - a pointer to the item context whose properties have
  776. * changed.
  777. * pContext - a pointer to the property context (which indicates
  778. * which properties are being written).
  779. *
  780. * Return Value:
  781. *
  782. * Status
  783. *
  784. * History:
  785. *
  786. * 03/05/2002 Original Version
  787. *
  788. \**************************************************************************/
  789. HRESULT CWIADevice::UpdateValidPages(BYTE *pWiasContext,
  790. WIA_PROPERTY_CONTEXT *pContext)
  791. {
  792. //
  793. // If the caller did not pass in the correct parameters, then fail the
  794. // call with E_INVALIDARG.
  795. //
  796. if((!pWiasContext)||(!pContext)){
  797. return E_INVALIDARG;
  798. }
  799. //
  800. // get the ROOT item, this is where the pages property exists
  801. //
  802. BYTE *pRootItemCtx = NULL;
  803. HRESULT hr = wiasGetRootItem(pWiasContext, &pRootItemCtx);
  804. if (FAILED(hr)) {
  805. return hr;
  806. }
  807. //
  808. // read the current WIA_IPA_TYMED setting from the item
  809. //
  810. LONG lTymed = TYMED_FILE;
  811. hr = wiasReadPropLong(pWiasContext,WIA_IPA_TYMED,&lTymed,NULL,TRUE);
  812. if(S_OK == hr){
  813. switch(lTymed)
  814. {
  815. case TYMED_FILE:
  816. {
  817. GUID FormatGUID = GUID_NULL;
  818. hr = wiasReadPropGuid(pWiasContext,WIA_IPA_FORMAT,&FormatGUID,NULL,TRUE);
  819. if (S_OK == hr) {
  820. if (FormatGUID == WiaImgFmt_BMP) {
  821. //
  822. // set the valid values for WIA_IPA_PAGES property to 1
  823. // because there is no such thing as a multipage BMP file.
  824. //
  825. hr = wiasSetValidRangeLong(pRootItemCtx,WIA_DPS_PAGES,1,1,1,1);
  826. if (S_OK == hr) {
  827. hr = wiasWritePropLong(pRootItemCtx,WIA_DPS_PAGES,1);
  828. }
  829. }
  830. if (FormatGUID == WiaImgFmt_TIFF) {
  831. //
  832. // set the valid values for WIA_IPA_PAGES property to MAX_PAGE_CAPACITY
  833. // because there can be multiple pages transferred to TIF.
  834. //
  835. hr = wiasSetValidRangeLong(pRootItemCtx,WIA_DPS_PAGES,0,1,MAX_PAGE_CAPACITY,1);
  836. }
  837. }
  838. }
  839. break;
  840. case TYMED_CALLBACK:
  841. {
  842. //
  843. // set the valid values for WIA_IPA_PAGES property to MAX_PAGE_CAPACITY
  844. // because there can be multiple pages transferred to memory. Each page
  845. // will be separated by a IT_MSG_NEW_PAGE message in the application's
  846. // callback loop.
  847. //
  848. hr = wiasSetValidRangeLong(pRootItemCtx,WIA_DPS_PAGES,0,1,MAX_PAGE_CAPACITY,1);
  849. }
  850. break;
  851. default:
  852. break;
  853. }
  854. }
  855. return hr;
  856. }
  857. /**************************************************************************\
  858. * CheckXExtent
  859. *
  860. *
  861. * Arguments:
  862. *
  863. * pWiasContext - pointer to an Item.
  864. *
  865. * Return Value:
  866. *
  867. * Byte count.
  868. *
  869. * History:
  870. *
  871. * 03/05/2002 Original Version
  872. *
  873. \**************************************************************************/
  874. HRESULT CWIADevice::CheckXExtent(BYTE *pWiasContext,
  875. WIA_PROPERTY_CONTEXT *pContext,
  876. LONG lWidth)
  877. {
  878. HRESULT hr = S_OK;
  879. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  880. WIALOG_NO_RESOURCE_ID,
  881. WIALOG_LEVEL3,
  882. "CheckXExtent");
  883. //
  884. // If the caller did not pass in the correct parameters, then fail the
  885. // call with E_INVALIDARG.
  886. //
  887. if((!pWiasContext)||(!pContext)){
  888. return E_INVALIDARG;
  889. }
  890. LONG lMaxExtent;
  891. LONG lExt;
  892. WIAS_CHANGED_VALUE_INFO cviXRes, cviXExt;
  893. //
  894. // get x resolution changes
  895. //
  896. hr = wiasGetChangedValueLong(pWiasContext,pContext,FALSE,WIA_IPS_XRES,&cviXRes);
  897. if (FAILED(hr)) {
  898. return hr;
  899. }
  900. //
  901. // get x extent changes
  902. //
  903. hr = wiasGetChangedValueLong(pWiasContext,pContext,cviXRes.bChanged,WIA_IPS_XEXTENT,&cviXExt);
  904. if (FAILED(hr)) {
  905. return hr;
  906. }
  907. //
  908. // update extent
  909. //
  910. lMaxExtent = ((cviXRes.Current.lVal * lWidth) / 1000);
  911. //
  912. // Update read-only property : PIXELS_PER_LINE. The width in pixels
  913. // of the scanned image is the same size as the XExtent.
  914. //
  915. if (SUCCEEDED(hr)) {
  916. hr = wiasWritePropLong(pWiasContext, WIA_IPS_XEXTENT, lMaxExtent);
  917. if(S_OK == hr){
  918. hr = wiasWritePropLong(pWiasContext, WIA_IPA_PIXELS_PER_LINE, lMaxExtent);
  919. }
  920. }
  921. return hr;
  922. }