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.

168 lines
4.8 KiB

  1. #ifndef __CAP_H_
  2. #define __CAP_H_
  3. typedef struct tagCapData
  4. {
  5. TW_UINT16 CapId; // TWAIN capability ID(CAP_xxx or ICAP_xxx)
  6. TW_UINT16 ItemType; // Item type, TWTY_xxx
  7. TW_UINT16 ConType; // Container type, TWON_xxx
  8. TW_UINT32 ItemSize; // size of each item
  9. TW_UINT16 Default; // Default and Current are both value if
  10. TW_UINT16 Current; // ConType is not TWON_ENUMERATION. They are
  11. // index into the enumeration item list
  12. // if ConType is TWON_ENUMERATION.
  13. // When ConType is TWON_ONEVALUE, this is
  14. // *the* value.
  15. TW_UINT16 MinValue; // if Contype is TWON_ENUMERATION,
  16. // MaxValue - MinValue + 1 is number of
  17. TW_UINT16 MaxValue; // items in the enumeration with
  18. // MinValue indexes to the first item and
  19. TW_UINT16 StepSize; // MaxValue indexes to the last item.
  20. // If ConType is not TWON_ENUMERATION, MinValue
  21. // and MaxValue creates a bound for all the
  22. // possible values. For TWON_ONEVALUE, step size
  23. // is 1. For TWON_RANGE, StepSize is the
  24. // step size.
  25. VOID *ItemList; // ignore if ConType is not TWON_ENUMERATION
  26. VOID *pStrData; // optional string data
  27. }CAPDATA, *PCAPDATA;
  28. //
  29. // This class serves as a basic repository for saving and retreiving
  30. // TWAIN data.
  31. class CCap
  32. {
  33. public:
  34. CCap()
  35. {
  36. m_CurMinValue =
  37. m_CurMaxValue =
  38. m_BaseMinValue =
  39. m_BaseMaxValue =
  40. m_CurrentValue =
  41. m_DefaultValue =
  42. m_CurEnumMask =
  43. m_CurNumItems =
  44. m_ResetNumItems =
  45. m_ResetCurIndex =
  46. m_ResetDefIndex = 0;
  47. m_pStrData = NULL;
  48. m_ItemList = NULL;
  49. m_ResetItemList = NULL;
  50. }
  51. ~CCap()
  52. {
  53. if (m_ItemList) {
  54. if (m_ResetItemList == m_ItemList) {
  55. m_ResetItemList = NULL;
  56. }
  57. ::LocalFree(m_ItemList);
  58. }
  59. if (m_ResetItemList) {
  60. ::LocalFree(m_ResetItemList);
  61. }
  62. if (m_pStrData) {
  63. ::LocalFree(m_pStrData);
  64. }
  65. }
  66. TW_UINT16 ICap(PCAPDATA pCapData);
  67. TW_UINT16 ValueSize(TW_UINT16 uTWAINType);
  68. TW_UINT16 GetCapId()
  69. {
  70. return m_CapId;
  71. }
  72. TW_UINT16 GetItemType()
  73. {
  74. return m_ItemType;
  75. }
  76. TW_UINT16 GetContainerType()
  77. {
  78. return m_ConType;
  79. }
  80. TW_UINT32 GetDefault();
  81. TW_UINT32 GetCurrent();
  82. TW_UINT16 Set(TW_UINT32 DefValue, TW_UINT32 CurValue,
  83. TW_UINT32 MinValue, TW_UINT32 MaxValue,
  84. TW_UINT32 StepSize = 0
  85. );
  86. TW_UINT16 Set(TW_UINT32 StrDataSize, BYTE *pStrData);
  87. TW_UINT16 Set(TW_UINT32 DefIndex, TW_UINT32 CurIndex,
  88. TW_UINT32 NumItems, BYTE *ItemList
  89. );
  90. TW_UINT16 Set(TW_UINT32 DefIndex, TW_UINT32 CurIndex,
  91. TW_UINT32 NumItems, BYTE *ItemList,BOOL bForce
  92. );
  93. TW_UINT16 CalcEnumBitMask(TW_ENUMERATION *pEnum);
  94. TW_UINT16 Reset();
  95. TW_UINT16 GetCurrent(TW_CAPABILITY *ptwCap)
  96. {
  97. return GetOneValue(FALSE, ptwCap);
  98. }
  99. TW_UINT16 GetDefault(TW_CAPABILITY *ptwCap)
  100. {
  101. return GetOneValue(TRUE, ptwCap);
  102. }
  103. TW_UINT16 Get(TW_CAPABILITY *ptwCap);
  104. TW_UINT16 SetCurrent(VOID *pNewValue);
  105. TW_UINT16 SetCurrent(TW_CAPABILITY *ptwCap);
  106. TW_UINT16 Set(TW_CAPABILITY *ptwCap);
  107. int CompareValue(TW_UINT32 This, TW_UINT32 That);
  108. TW_FIX32 FloatToFix32(FLOAT f);
  109. FLOAT Fix32ToFloat(TW_FIX32 fix32);
  110. TW_UINT16 SetCurrent(TW_UINT32 NewValue);
  111. protected:
  112. TW_UINT32 ExtractValue(BYTE *pData);
  113. TW_UINT16 m_CapId;
  114. TW_UINT16 m_ItemType;
  115. TW_UINT16 m_ConType;
  116. TW_UINT32 m_ItemSize;
  117. private:
  118. TW_UINT16 GetOneValue(BOOL bDefault, TW_CAPABILITY *ptwCap);
  119. TW_UINT32 GetClosestValue(TW_UINT32 Value);
  120. // copy contstructor.
  121. CCap(const CCap& CapData);
  122. // Assignment operator
  123. CCap& operator=(const CCap& CCap);
  124. TW_UINT32 m_CurrentValue;
  125. TW_UINT32 m_DefaultValue;
  126. TW_UINT32 m_StepSize;
  127. TW_UINT32 m_BaseMinValue;
  128. TW_UINT32 m_BaseMaxValue;
  129. TW_UINT32 m_CurMinValue;
  130. TW_UINT32 m_CurMaxValue;
  131. TW_UINT32 m_CurEnumMask;
  132. TW_UINT32 m_CurNumItems;
  133. TW_UINT32 m_ResetNumItems;
  134. TW_UINT32 m_ResetCurIndex;
  135. TW_UINT32 m_ResetDefIndex;
  136. BYTE *m_ItemList;
  137. BYTE *m_ResetItemList;
  138. BYTE *m_pStrData;
  139. //
  140. // debug helpers
  141. //
  142. void Debug_DumpEnumerationValues(TW_ENUMERATION *ptwEnumeration = NULL);
  143. };
  144. #endif // #ifndef __CAP_H_