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.

473 lines
14 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright 2001 - 2003 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // FILE: Helper.cpp
  9. //
  10. //
  11. // PURPOSE: Implementation of wrapper class for Driver UI Helper interface.
  12. //
  13. //
  14. // Functions:
  15. //
  16. //
  17. //
  18. //
  19. // PLATFORMS: Windows 2000, Windows XP, Windows Server 2003
  20. //
  21. //
  22. #include "precomp.h"
  23. #include <PRCOMOEM.H>
  24. #include "Helper.h"
  25. // StrSafe.h needs to be included last
  26. // to disallow bad string functions.
  27. #include <STRSAFE.H>
  28. ////////////////////////////////////////////////////////
  29. // Internal Macros
  30. ////////////////////////////////////////////////////////
  31. // Macros for simplifying calling the Driver UI Helper interfaces correctly.
  32. #define CALL_HELPER(MethodName, args) \
  33. if (IsEqualGUID(&m_iidUIHelper, &IID_IPrintOemDriverUI)) \
  34. { \
  35. return static_cast<IPrintOemDriverUI *>(m_pUIHelper)->MethodName args; \
  36. } \
  37. else if (IsEqualGUID(&m_iidUIHelper, &IID_IPrintCoreUI2)) \
  38. { \
  39. return static_cast<IPrintCoreUI2 *>(m_pUIHelper)->MethodName args; \
  40. } \
  41. return E_NOINTERFACE;
  42. #define CALL_HELPER2(MethodName, args) \
  43. if (IsEqualGUID(&m_iidUIHelper, &IID_IPrintCoreUI2)) \
  44. { \
  45. return static_cast<IPrintCoreUI2 *>(m_pUIHelper)->MethodName args; \
  46. } \
  47. return E_NOINTERFACE;
  48. /////////////////////////////////////////////////////////////
  49. //
  50. // CUIHelper Class Methods
  51. //
  52. //
  53. // Private Methods
  54. //
  55. // Clears or initializes data members.
  56. void CUIHelper::Clear()
  57. {
  58. // Clear stored interface
  59. m_pUIHelper = NULL;
  60. m_iidUIHelper = GUID_NULL;
  61. }
  62. //
  63. // Public Methods
  64. //
  65. // Default contructor.
  66. CUIHelper::CUIHelper()
  67. {
  68. // Initialize the data members.
  69. Clear();
  70. }
  71. // Constructor with assignment.
  72. CUIHelper::CUIHelper(const IID &HelperIID, PVOID pHelper)
  73. {
  74. // Assign the interface.
  75. Assign(HelperIID, pHelper);
  76. }
  77. // Destructor
  78. CUIHelper::~CUIHelper()
  79. {
  80. // Release the interface reference.
  81. Release();
  82. }
  83. // Stores helper interface in helper entry structure.
  84. void CUIHelper::Assign(const IID &HelperIID, PVOID pHelper)
  85. {
  86. // If we already have a helper interface, release it.
  87. if(IsValid())
  88. {
  89. Release();
  90. }
  91. // Store helper interface and IID for it.
  92. m_pUIHelper = static_cast<IUnknown*>(pHelper);
  93. m_iidUIHelper = HelperIID;
  94. }
  95. // Releases the helper interface and
  96. // our removes the references to it.
  97. ULONG CUIHelper::Release()
  98. {
  99. ULONG ulRef = 0;
  100. if(IsValid())
  101. {
  102. // Release the interface.
  103. // Since IPrintCoreUI2 inherits from IPrintOemDriverUI,
  104. // it is safe to cast both types of helper interfaces
  105. // to IPrintOemDriverUI for purposes of calling a
  106. // method implemented in IPrintOemDriverUI.
  107. // NOTE: can't cast to IUnknown since it just has pure virtual
  108. // calls for AddRef and Release.
  109. ulRef = static_cast<IPrintOemDriverUI *>(m_pUIHelper)->Release();
  110. // Clear the data members.
  111. Clear();
  112. }
  113. return ulRef;
  114. }
  115. //
  116. // IPrintOemDriverUI methods
  117. //
  118. //
  119. // Helper function to get driver settings. This function is only supported
  120. // for UI plugins that do not fully replace core driver's standard UI.
  121. //
  122. HRESULT __stdcall CUIHelper::DrvGetDriverSetting(
  123. PVOID pci,
  124. PCSTR Feature,
  125. PVOID pOutput,
  126. DWORD cbSize,
  127. PDWORD pcbNeeded,
  128. PDWORD pdwOptionsReturned
  129. )
  130. {
  131. CALL_HELPER(DrvGetDriverSetting,
  132. (pci,
  133. Feature,
  134. pOutput,
  135. cbSize,
  136. pcbNeeded,
  137. pdwOptionsReturned
  138. )
  139. );
  140. }
  141. //
  142. // Helper function to allow OEM plugins upgrade private registry
  143. // settings. This function is supported for any UI plugins and should be
  144. // called only by OEM's UpgradePrinter.
  145. //
  146. HRESULT __stdcall CUIHelper::DrvUpgradeRegistrySetting(
  147. HANDLE hPrinter,
  148. PCSTR pFeature,
  149. PCSTR pOption
  150. )
  151. {
  152. CALL_HELPER(DrvUpgradeRegistrySetting,
  153. (hPrinter,
  154. pFeature,
  155. pOption
  156. )
  157. );
  158. }
  159. //
  160. // Helper function to allow OEM plugins to update the driver UI settings.
  161. // This function is only supported for UI plugins that do not fully replace
  162. // core driver's standard UI. It should be called only when the UI is present.
  163. //
  164. HRESULT __stdcall CUIHelper::DrvUpdateUISetting(
  165. PVOID pci,
  166. PVOID pOptItem,
  167. DWORD dwPreviousSelection,
  168. DWORD dwMode
  169. )
  170. {
  171. CALL_HELPER(DrvUpdateUISetting,
  172. (pci,
  173. pOptItem,
  174. dwPreviousSelection,
  175. dwMode
  176. )
  177. );
  178. }
  179. //
  180. // IPrintCoreUI2 new methods
  181. //
  182. //
  183. // Following four helper functions are only supported for UI plugins that fully
  184. // replace core driver's standard UI. They should only be called by the UI plugin's
  185. // DocumentPropertySheets, DevicePropertySheets and their property sheet callback
  186. // functions.
  187. //
  188. // Helper function to retrieve driver's current setting as a list of
  189. // feature/option keyword pairs.
  190. //
  191. HRESULT __stdcall CUIHelper::GetOptions(
  192. IN POEMUIOBJ poemuiobj,
  193. IN DWORD dwFlags,
  194. IN PCSTR pmszFeaturesRequested,
  195. IN DWORD cbIn,
  196. OUT PSTR pmszFeatureOptionBuf,
  197. IN DWORD cbSize,
  198. OUT PDWORD pcbNeeded)
  199. {
  200. CALL_HELPER2(GetOptions,
  201. (poemuiobj,
  202. dwFlags,
  203. pmszFeaturesRequested,
  204. cbIn,
  205. pmszFeatureOptionBuf,
  206. cbSize,
  207. pcbNeeded
  208. )
  209. );
  210. }
  211. //
  212. // Helper function to change driver's setting using a list of feature/option
  213. // keyword pairs.
  214. //
  215. HRESULT __stdcall CUIHelper::SetOptions(
  216. IN POEMUIOBJ poemuiobj,
  217. IN DWORD dwFlags,
  218. IN PCSTR pmszFeatureOptionBuf,
  219. IN DWORD cbIn,
  220. OUT PDWORD pdwResult)
  221. {
  222. CALL_HELPER2(SetOptions,
  223. (poemuiobj,
  224. dwFlags,
  225. pmszFeatureOptionBuf,
  226. cbIn,
  227. pdwResult
  228. )
  229. );
  230. }
  231. //
  232. // Helper function to retrieve the option(s) of a given feature that are
  233. // constrained in driver's current setting.
  234. //
  235. HRESULT __stdcall CUIHelper::EnumConstrainedOptions(
  236. IN POEMUIOBJ poemuiobj,
  237. IN DWORD dwFlags,
  238. IN PCSTR pszFeatureKeyword,
  239. OUT PSTR pmszConstrainedOptionList,
  240. IN DWORD cbSize,
  241. OUT PDWORD pcbNeeded)
  242. {
  243. CALL_HELPER2(EnumConstrainedOptions,
  244. (poemuiobj,
  245. dwFlags,
  246. pszFeatureKeyword,
  247. pmszConstrainedOptionList,
  248. cbSize,
  249. pcbNeeded
  250. )
  251. );
  252. }
  253. //
  254. // Helper function to retrieve a list of feature/option keyword pairs from
  255. // driver's current setting that conflict with the given feature/option pair.
  256. //
  257. HRESULT __stdcall CUIHelper::WhyConstrained(
  258. IN POEMUIOBJ poemuiobj,
  259. IN DWORD dwFlags,
  260. IN PCSTR pszFeatureKeyword,
  261. IN PCSTR pszOptionKeyword,
  262. OUT PSTR pmszReasonList,
  263. IN DWORD cbSize,
  264. OUT PDWORD pcbNeeded)
  265. {
  266. CALL_HELPER2(WhyConstrained,
  267. (poemuiobj,
  268. dwFlags,
  269. pszFeatureKeyword,
  270. pszOptionKeyword,
  271. pmszReasonList,
  272. cbSize,
  273. pcbNeeded
  274. )
  275. );
  276. }
  277. //
  278. // Following five helper functions are supported for any UI plugins.
  279. //
  280. // Helper function to retrieve global attribute.
  281. //
  282. HRESULT __stdcall CUIHelper::GetGlobalAttribute(
  283. IN POEMUIOBJ poemuiobj,
  284. IN DWORD dwFlags,
  285. IN PCSTR pszAttribute,
  286. OUT PDWORD pdwDataType,
  287. OUT PBYTE pbData,
  288. IN DWORD cbSize,
  289. OUT PDWORD pcbNeeded)
  290. {
  291. CALL_HELPER2(GetGlobalAttribute,
  292. (poemuiobj,
  293. dwFlags,
  294. pszAttribute,
  295. pdwDataType,
  296. pbData,
  297. cbSize,
  298. pcbNeeded
  299. )
  300. );
  301. }
  302. //
  303. // Helper function to retrieve attribute of a given feature.
  304. //
  305. HRESULT __stdcall CUIHelper::GetFeatureAttribute(
  306. IN POEMUIOBJ poemuiobj,
  307. IN DWORD dwFlags,
  308. IN PCSTR pszFeatureKeyword,
  309. IN PCSTR pszAttribute,
  310. OUT PDWORD pdwDataType,
  311. OUT PBYTE pbData,
  312. IN DWORD cbSize,
  313. OUT PDWORD pcbNeeded)
  314. {
  315. CALL_HELPER2(GetFeatureAttribute,
  316. (poemuiobj,
  317. dwFlags,
  318. pszFeatureKeyword,
  319. pszAttribute,
  320. pdwDataType,
  321. pbData,
  322. cbSize,
  323. pcbNeeded
  324. )
  325. );
  326. }
  327. //
  328. // Helper function to retrieve attribute of a given feature/option selection.
  329. //
  330. HRESULT __stdcall CUIHelper::GetOptionAttribute(
  331. IN POEMUIOBJ poemuiobj,
  332. IN DWORD dwFlags,
  333. IN PCSTR pszFeatureKeyword,
  334. IN PCSTR pszOptionKeyword,
  335. IN PCSTR pszAttribute,
  336. OUT PDWORD pdwDataType,
  337. OUT PBYTE pbData,
  338. IN DWORD cbSize,
  339. OUT PDWORD pcbNeeded)
  340. {
  341. CALL_HELPER2(GetOptionAttribute,
  342. (poemuiobj,
  343. dwFlags,
  344. pszFeatureKeyword,
  345. pszOptionKeyword,
  346. pszAttribute,
  347. pdwDataType,
  348. pbData,
  349. cbSize,
  350. pcbNeeded
  351. )
  352. );
  353. }
  354. //
  355. // Helper function to retrieve the list of feature keyword.
  356. //
  357. HRESULT __stdcall CUIHelper::EnumFeatures(
  358. IN POEMUIOBJ poemuiobj,
  359. IN DWORD dwFlags,
  360. OUT PSTR pmszFeatureList,
  361. IN DWORD cbSize,
  362. OUT PDWORD pcbNeeded)
  363. {
  364. CALL_HELPER2(EnumFeatures,
  365. (poemuiobj,
  366. dwFlags,
  367. pmszFeatureList,
  368. cbSize,
  369. pcbNeeded
  370. )
  371. );
  372. }
  373. //
  374. // Helper function to retrieve the list of options keyword of a given feature.
  375. //
  376. HRESULT __stdcall CUIHelper::EnumOptions(
  377. IN POEMUIOBJ poemuiobj,
  378. IN DWORD dwFlags,
  379. IN PCSTR pszFeatureKeyword,
  380. OUT PSTR pmszOptionList,
  381. IN DWORD cbSize,
  382. OUT PDWORD pcbNeeded)
  383. {
  384. CALL_HELPER2(EnumOptions,
  385. (poemuiobj,
  386. dwFlags,
  387. pszFeatureKeyword,
  388. pmszOptionList,
  389. cbSize,
  390. pcbNeeded
  391. )
  392. );
  393. }
  394. //
  395. // Helper function to query system simulation support
  396. //
  397. HRESULT __stdcall CUIHelper::QuerySimulationSupport(
  398. IN HANDLE hPrinter,
  399. IN DWORD dwLevel,
  400. OUT PBYTE pCaps,
  401. IN DWORD cbSize,
  402. OUT PDWORD pcbNeeded)
  403. {
  404. CALL_HELPER2(QuerySimulationSupport,
  405. (hPrinter,
  406. dwLevel,
  407. pCaps,
  408. cbSize,
  409. pcbNeeded
  410. )
  411. );
  412. }