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.

1040 lines
37 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 1997 - 2003 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // FILE: OEMUI.cpp
  9. //
  10. //
  11. // PURPOSE: Main file for OEM UI test module.
  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 "resource.h"
  24. #include "debug.h"
  25. #include "stringutils.h"
  26. #include "oemui.h"
  27. // StrSafe.h needs to be included last
  28. // to disallow bad string functions.
  29. #include <STRSAFE.H>
  30. ////////////////////////////////////////////////////////
  31. // INTERNAL MACROS and DEFINES
  32. ////////////////////////////////////////////////////////
  33. typedef struct _tagCBUserData
  34. {
  35. HANDLE hComPropSheet;
  36. HANDLE hPropPage;
  37. POEMUIPSPARAM pOEMUIParam;
  38. PFNCOMPROPSHEET pfnComPropSheet;
  39. CUIHelper *pHelper;
  40. POEMUIOBJ poemuiobj;
  41. BOOL bPermission;
  42. BOOL bHidingStandardUI;
  43. } CBUSERDATA, *PCBUSERDATA;
  44. ////////////////////////////////////////////////////////
  45. // INTERNAL PROTOTYPES
  46. ////////////////////////////////////////////////////////
  47. static HRESULT hrDocumentPropertyPage(DWORD dwMode, POEMCUIPPARAM pOEMUIParam);
  48. static HRESULT hrPrinterPropertyPage(DWORD dwMode, POEMCUIPPARAM pOEMUIParam);
  49. LONG APIENTRY OEMPrinterUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam);
  50. LONG APIENTRY OEMDocUIItemCallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam);
  51. LONG APIENTRY OEMDocUICallBack(PCPSUICBPARAM pCallbackParam);
  52. LONG APIENTRY OEMDevUICallBack(PCPSUICBPARAM pCallbackParam);
  53. INT_PTR CALLBACK DevicePropPageProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
  54. static void InitOptItems(POPTITEM pOptItems, DWORD dwOptItems);
  55. ////////////////////////////////////////////////////////////////////////////////
  56. //
  57. // Initializes OptItems to display OEM device or document property UI.
  58. //
  59. HRESULT hrOEMPropertyPage(DWORD dwMode, POEMCUIPPARAM pOEMUIParam)
  60. {
  61. HRESULT hResult = S_OK;
  62. VERBOSE(DLLTEXT("hrOEMPropertyPage(%d) entry.\r\n"), dwMode);
  63. // Validate parameters.
  64. if( (OEMCUIP_DOCPROP != dwMode)
  65. &&
  66. (OEMCUIP_PRNPROP != dwMode)
  67. )
  68. {
  69. ERR(ERRORTEXT("hrOEMPropertyPage() ERROR_INVALID_PARAMETER.\r\n"));
  70. VERBOSE(DLLTEXT("\tdwMode = %d, pOEMUIParam = %#lx.\r\n"), dwMode, pOEMUIParam);
  71. // Return invalid parameter error.
  72. SetLastError(ERROR_INVALID_PARAMETER);
  73. return E_FAIL;
  74. }
  75. switch(dwMode)
  76. {
  77. case OEMCUIP_DOCPROP:
  78. hResult = hrDocumentPropertyPage(dwMode, pOEMUIParam);
  79. break;
  80. case OEMCUIP_PRNPROP:
  81. hResult = hrPrinterPropertyPage(dwMode, pOEMUIParam);
  82. break;
  83. default:
  84. // Should never reach this!
  85. ERR(ERRORTEXT("hrOEMPropertyPage() Invalid dwMode, %d"), dwMode);
  86. SetLastError(ERROR_INVALID_PARAMETER);
  87. hResult = E_FAIL;
  88. break;
  89. }
  90. return hResult;
  91. }
  92. ////////////////////////////////////////////////////////////////////////////////
  93. //
  94. // Initializes OptItems to display OEM document property UI.
  95. //
  96. static HRESULT hrDocumentPropertyPage(DWORD dwMode, POEMCUIPPARAM pOEMUIParam)
  97. {
  98. HRESULT hrResult = S_OK;
  99. if(NULL == pOEMUIParam->pOEMOptItems)
  100. {
  101. // Fill in the number of OptItems to create for OEM document property UI.
  102. pOEMUIParam->cOEMOptItems = 1;
  103. VERBOSE(DLLTEXT("hrDocumentPropertyPage() requesting %d number of items.\r\n"), pOEMUIParam->cOEMOptItems);
  104. }
  105. else
  106. {
  107. POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
  108. VERBOSE(DLLTEXT("hrDocumentPropertyPage() fill out %d items.\r\n"), pOEMUIParam->cOEMOptItems);
  109. // Init UI Callback reference.
  110. pOEMUIParam->OEMCUIPCallback = OEMDocUIItemCallBack;
  111. // Init OEMOptItmes.
  112. InitOptItems(pOEMUIParam->pOEMOptItems, pOEMUIParam->cOEMOptItems);
  113. // Fill out tree view items.
  114. // New section.
  115. pOEMUIParam->pOEMOptItems[0].Level = 1;
  116. pOEMUIParam->pOEMOptItems[0].Flags = OPTIF_COLLAPSE;
  117. pOEMUIParam->pOEMOptItems[0].Sel = pOEMDev->dwAdvancedData;
  118. hrResult = GetStringResource(pOEMUIParam->hOEMHeap,
  119. (HMODULE) pOEMUIParam->hModule,
  120. IDS_ADV_SECTION,
  121. &pOEMUIParam->pOEMOptItems[0].pName);
  122. if(!SUCCEEDED(hrResult))
  123. {
  124. ERR(ERRORTEXT("hrDocumentPropertyPage() failed to get section name. (hrResult = 0x%x)\r\n"),
  125. hrResult);
  126. goto Exit;
  127. }
  128. pOEMUIParam->pOEMOptItems[0].pOptType = CreateOptType(pOEMUIParam->hOEMHeap, 2);
  129. pOEMUIParam->pOEMOptItems[0].pOptType->Type = TVOT_UDARROW;
  130. pOEMUIParam->pOEMOptItems[0].pOptType->pOptParam[1].IconID = 0;
  131. pOEMUIParam->pOEMOptItems[0].pOptType->pOptParam[1].lParam = 100;
  132. }
  133. Exit:
  134. return hrResult;
  135. }
  136. ////////////////////////////////////////////////////////////////////////////////
  137. //
  138. // Initializes OptItems to display OEM printer property UI.
  139. //
  140. static HRESULT hrPrinterPropertyPage(DWORD dwMode, POEMCUIPPARAM pOEMUIParam)
  141. {
  142. HRESULT hrResult = S_OK;
  143. if(NULL == pOEMUIParam->pOEMOptItems)
  144. {
  145. // Fill in the number of OptItems to create for OEM printer property UI.
  146. pOEMUIParam->cOEMOptItems = 1;
  147. VERBOSE(DLLTEXT("hrPrinterPropertyPage() requesting %d number of items.\r\n"), pOEMUIParam->cOEMOptItems);
  148. }
  149. else
  150. {
  151. DWORD dwError;
  152. DWORD dwDeviceValue;
  153. DWORD dwType;
  154. DWORD dwNeeded;
  155. VERBOSE(DLLTEXT("hrPrinterPropertyPage() fill out %d items.\r\n"), pOEMUIParam->cOEMOptItems);
  156. // Get device settings value from printer.
  157. dwError = GetPrinterData(pOEMUIParam->hPrinter, OEMUI_VALUE, &dwType, (PBYTE) &dwDeviceValue,
  158. sizeof(dwDeviceValue), &dwNeeded);
  159. if( (ERROR_SUCCESS != dwError)
  160. ||
  161. (dwDeviceValue > 100)
  162. )
  163. {
  164. // Failed to get the device value or value is invalid, just use the default.
  165. dwDeviceValue = 0;
  166. }
  167. // Init UI Callback reference.
  168. pOEMUIParam->OEMCUIPCallback = OEMPrinterUICallBack;
  169. // Init OEMOptItmes.
  170. InitOptItems(pOEMUIParam->pOEMOptItems, pOEMUIParam->cOEMOptItems);
  171. // Fill out tree view items.
  172. // New section.
  173. pOEMUIParam->pOEMOptItems[0].Level = 1;
  174. pOEMUIParam->pOEMOptItems[0].Flags = OPTIF_COLLAPSE;
  175. hrResult = GetStringResource(pOEMUIParam->hOEMHeap,
  176. (HMODULE) pOEMUIParam->hModule,
  177. IDS_DEV_SECTION,
  178. &pOEMUIParam->pOEMOptItems[0].pName);
  179. if(!SUCCEEDED(hrResult))
  180. {
  181. ERR(ERRORTEXT("hrPrinterPropertyPage() failed to get section name. (hrResult = 0x%x)\r\n"),
  182. hrResult);
  183. goto Exit;
  184. }
  185. pOEMUIParam->pOEMOptItems[0].Sel = dwDeviceValue;
  186. pOEMUIParam->pOEMOptItems[0].pOptType = CreateOptType(pOEMUIParam->hOEMHeap, 2);
  187. pOEMUIParam->pOEMOptItems[0].pOptType->Type = TVOT_UDARROW;
  188. pOEMUIParam->pOEMOptItems[0].pOptType->pOptParam[1].IconID = 0;
  189. pOEMUIParam->pOEMOptItems[0].pOptType->pOptParam[1].lParam = 100;
  190. }
  191. Exit:
  192. return hrResult;
  193. }
  194. ////////////////////////////////////////////////////////////////////////////////
  195. //
  196. // Adds property page to Document property sheet.
  197. //
  198. HRESULT hrOEMDocumentPropertySheets(PPROPSHEETUI_INFO pPSUIInfo,
  199. LPARAM lParam,
  200. CUIHelper &Helper,
  201. CFeatures *pFeatures,
  202. BOOL bHidingStandardUI)
  203. {
  204. LONG_PTR lResult;
  205. HRESULT hrResult = S_OK;
  206. VERBOSE(DLLTEXT("OEMDocumentPropertySheets() entry.\r\n"));
  207. // Validate parameters.
  208. if( (NULL == pPSUIInfo)
  209. ||
  210. (PROPSHEETUI_INFO_VERSION != pPSUIInfo->Version)
  211. )
  212. {
  213. ERR(ERRORTEXT("OEMDocumentPropertySheets() ERROR_INVALID_PARAMETER.\r\n"));
  214. // Return invalid parameter error.
  215. SetLastError(ERROR_INVALID_PARAMETER);
  216. return E_FAIL;
  217. }
  218. // Do action.
  219. switch(pPSUIInfo->Reason)
  220. {
  221. case PROPSHEETUI_REASON_INIT:
  222. {
  223. WORD wFeatures = 0;
  224. WORD wIndex = 0;
  225. DWORD dwSheets = 0;
  226. PCBUSERDATA pUserData = NULL;
  227. POEMUIPSPARAM pOEMUIParam = (POEMUIPSPARAM) pPSUIInfo->lParamInit;
  228. BOOL bPermission = ((pOEMUIParam->dwFlags & DPS_NOPERMISSION) == 0);
  229. HANDLE hHeap = pOEMUIParam->hOEMHeap;
  230. POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
  231. COMPROPSHEETUI Sheet;
  232. // Make sure that we have the Core Driver Features.
  233. // Only get features if we are hiding the standard
  234. // document property sheets.
  235. if(bHidingStandardUI)
  236. {
  237. pFeatures->Acquire(hHeap, Helper, pOEMUIParam->poemuiobj);
  238. wFeatures = pFeatures->GetCount(OEMCUIP_DOCPROP);
  239. }
  240. // Init property page.
  241. memset(&Sheet, 0, sizeof(COMPROPSHEETUI));
  242. Sheet.cbSize = sizeof(COMPROPSHEETUI);
  243. Sheet.Flags = bPermission ? CPSUIF_UPDATE_PERMISSION : 0;
  244. Sheet.hInstCaller = ghInstance;
  245. Sheet.pHelpFile = NULL;
  246. Sheet.pfnCallBack = OEMDocUICallBack;
  247. Sheet.pDlgPage = CPSUI_PDLGPAGE_TREEVIEWONLY;
  248. Sheet.cOptItem = wFeatures + 1;
  249. Sheet.IconID = IDI_CPSUI_PRINTER;
  250. Sheet.CallerVersion = 0x100;
  251. Sheet.OptItemVersion = 0x100;
  252. // Get Caller's name.
  253. hrResult = GetStringResource(hHeap, ghInstance, IDS_NAME, &Sheet.pCallerName);
  254. if(!SUCCEEDED(hrResult))
  255. {
  256. ERR(ERRORTEXT("hrOEMDocumentPropertySheets() failed to get caller name. (hrResult = 0x%x)\r\n"),
  257. hrResult);
  258. goto Exit;
  259. }
  260. // Get section name.
  261. hrResult = GetStringResource(hHeap, ghInstance, IDS_SECTION, &Sheet.pOptItemName);
  262. if(!SUCCEEDED(hrResult))
  263. {
  264. ERR(ERRORTEXT("hrOEMDocumentPropertySheets() failed to get section name. (hrResult = 0x%x)\r\n"),
  265. hrResult);
  266. goto Exit;
  267. }
  268. // Init user data.
  269. pUserData = (PCBUSERDATA) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(CBUSERDATA));
  270. if(NULL == pUserData)
  271. {
  272. ERR(ERRORTEXT("hrOEMDocumentPropertySheets() failed to allocate user data.\r\n"));
  273. hrResult = E_OUTOFMEMORY;
  274. goto Exit;
  275. }
  276. pUserData->hComPropSheet = pPSUIInfo->hComPropSheet;
  277. pUserData->pfnComPropSheet = pPSUIInfo->pfnComPropSheet;
  278. pUserData->pOEMUIParam = pOEMUIParam;
  279. pUserData->pHelper = &Helper;
  280. pUserData->poemuiobj = pOEMUIParam->poemuiobj;
  281. pUserData->bPermission = bPermission;
  282. pUserData->bHidingStandardUI = bHidingStandardUI;
  283. Sheet.UserData = (ULONG_PTR) pUserData;
  284. // Create OptItems for page.
  285. Sheet.pOptItem = CreateOptItems(hHeap, Sheet.cOptItem);
  286. if(NULL == Sheet.pOptItem)
  287. {
  288. ERR(ERRORTEXT("hrOEMDocumentPropertySheets() failed to allocate OPTITEMs.\r\n"));
  289. hrResult = E_OUTOFMEMORY;
  290. goto Exit;
  291. }
  292. // Add Core Driver features.
  293. for(wIndex = 0; wIndex < wFeatures; ++wIndex)
  294. {
  295. // Initialize level and basic state for feature.
  296. Sheet.pOptItem[wIndex].Level = 1;
  297. Sheet.pOptItem[wIndex].Flags = OPTIF_COLLAPSE;
  298. // Get the OPTITEM for this feature.
  299. hrResult = pFeatures->InitOptItem(hHeap,
  300. Sheet.pOptItem + wIndex,
  301. wIndex,
  302. OEMCUIP_DOCPROP);
  303. if(!SUCCEEDED(hrResult))
  304. {
  305. ERR(ERRORTEXT("hrOEMDocumentPropertySheets() failed to get OPTITEM for feature %hs.\r\n"),
  306. pFeatures->GetKeyword(wIndex, OEMCUIP_DOCPROP));
  307. goto Exit;
  308. }
  309. }
  310. // Initialize Plug-in OptItems
  311. Sheet.pOptItem[wIndex].Level = 1;
  312. Sheet.pOptItem[wIndex].Flags = OPTIF_COLLAPSE;
  313. Sheet.pOptItem[wIndex].Sel = pOEMDev->dwDriverData;
  314. // get optitem name.
  315. hrResult = GetStringResource(hHeap, ghInstance, IDS_SECTION, &Sheet.pOptItem[wIndex].pName);
  316. if(!SUCCEEDED(hrResult))
  317. {
  318. ERR(ERRORTEXT("hrOEMDocumentPropertySheets() failed to get OptItem %d name. (hrResult = 0x%x)\r\n"),
  319. wIndex,
  320. hrResult);
  321. goto Exit;
  322. }
  323. Sheet.pOptItem[wIndex].pOptType = CreateOptType(hHeap, 2);
  324. Sheet.pOptItem[wIndex].pOptType->Type = TVOT_UDARROW;
  325. Sheet.pOptItem[wIndex].pOptType->pOptParam[1].IconID = 0;
  326. Sheet.pOptItem[wIndex].pOptType->pOptParam[1].lParam = 100;
  327. // Add property sheets.
  328. lResult = pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PCOMPROPSHEETUI,
  329. (LPARAM)&Sheet, (LPARAM)&dwSheets);
  330. }
  331. break;
  332. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  333. {
  334. PPROPSHEETUI_INFO_HEADER pHeader = (PPROPSHEETUI_INFO_HEADER) lParam;
  335. pHeader->pTitle = (LPTSTR)PROP_TITLE;
  336. lResult = TRUE;
  337. }
  338. break;
  339. case PROPSHEETUI_REASON_GET_ICON:
  340. // No icon
  341. lResult = 0;
  342. break;
  343. case PROPSHEETUI_REASON_SET_RESULT:
  344. {
  345. PSETRESULT_INFO pInfo = (PSETRESULT_INFO) lParam;
  346. lResult = pInfo->Result;
  347. }
  348. break;
  349. case PROPSHEETUI_REASON_DESTROY:
  350. lResult = TRUE;
  351. break;
  352. }
  353. Exit:
  354. pPSUIInfo->Result = lResult;
  355. return hrResult;
  356. }
  357. ////////////////////////////////////////////////////////////////////////////////
  358. //
  359. // Adds property page to printer property sheet.
  360. //
  361. HRESULT hrOEMDevicePropertySheets(PPROPSHEETUI_INFO pPSUIInfo,
  362. LPARAM lParam,
  363. CUIHelper &Helper,
  364. CFeatures *pFeatures,
  365. BOOL bHidingStandardUI)
  366. {
  367. LONG_PTR lResult;
  368. HRESULT hrResult = S_OK;
  369. VERBOSE(DLLTEXT("hrOEMDevicePropertySheets(%#x, %#x) entry\r\n"), pPSUIInfo, lParam);
  370. // Validate parameters.
  371. if( (NULL == pPSUIInfo)
  372. ||
  373. (PROPSHEETUI_INFO_VERSION != pPSUIInfo->Version)
  374. )
  375. {
  376. ERR(ERRORTEXT("hrOEMDevicePropertySheets() ERROR_INVALID_PARAMETER.\r\n"));
  377. // Return invalid parameter error.
  378. SetLastError(ERROR_INVALID_PARAMETER);
  379. return E_FAIL;
  380. }
  381. Dump(pPSUIInfo);
  382. // Do action.
  383. switch(pPSUIInfo->Reason)
  384. {
  385. case PROPSHEETUI_REASON_INIT:
  386. {
  387. PROPSHEETPAGE Page;
  388. // If hiding standard UI, then
  389. // need to add Device Settings page, too.
  390. if(bHidingStandardUI)
  391. {
  392. POEMUIPSPARAM pOEMUIParam = (POEMUIPSPARAM) pPSUIInfo->lParamInit;
  393. BOOL bPermission = ((pOEMUIParam->dwFlags & DPS_NOPERMISSION) == 0);
  394. HANDLE hHeap = pOEMUIParam->hOEMHeap;
  395. POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
  396. WORD wFeatures = 0;
  397. WORD wIndex = 0;
  398. DWORD dwSheets = 0;
  399. DLGPAGE DlgPage;
  400. PCBUSERDATA pUserData = NULL;
  401. COMPROPSHEETUI Sheet;
  402. // Make sure that we have the Core Driver Features.
  403. pFeatures->Acquire(hHeap, Helper, pOEMUIParam->poemuiobj);
  404. wFeatures = pFeatures->GetCount(OEMCUIP_PRNPROP);
  405. // Init DlgPage struct for Device Settings replacement page.
  406. memset(&DlgPage, 0, sizeof(DLGPAGE));
  407. DlgPage.cbSize = sizeof(DLGPAGE);
  408. DlgPage.DlgTemplateID = DP_STD_TREEVIEWPAGE;
  409. // Get Device Settings display name.
  410. hrResult = GetStringResource(hHeap, ghInstance, IDS_DEVICE_SETTINGS_NAME, &DlgPage.pTabName);
  411. if(!SUCCEEDED(hrResult))
  412. {
  413. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to get Device Settings display name. (hrResult = 0x%x)\r\n"),
  414. hrResult);
  415. goto Exit;
  416. }
  417. // Init Device Settings replacement page.
  418. memset(&Sheet, 0, sizeof(COMPROPSHEETUI));
  419. Sheet.cbSize = sizeof(COMPROPSHEETUI);
  420. Sheet.Flags = bPermission ? CPSUIF_UPDATE_PERMISSION : 0;
  421. Sheet.hInstCaller = ghInstance;
  422. Sheet.pHelpFile = NULL;
  423. Sheet.pfnCallBack = OEMDevUICallBack;
  424. Sheet.pDlgPage = &DlgPage; //CPSUI_PDLGPAGE_TREEVIEWONLY;
  425. Sheet.cOptItem = wFeatures;
  426. Sheet.cDlgPage = 1;
  427. Sheet.IconID = IDI_CPSUI_PRINTER;
  428. Sheet.CallerVersion = 0x100;
  429. Sheet.OptItemVersion = 0x100;
  430. // Get Caller's name.
  431. hrResult = GetStringResource(hHeap, ghInstance, IDS_NAME, &Sheet.pCallerName);
  432. if(!SUCCEEDED(hrResult))
  433. {
  434. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to get caller name. (hrResult = 0x%x)\r\n"),
  435. hrResult);
  436. goto Exit;
  437. }
  438. // Get section name.
  439. hrResult = GetStringResource(hHeap, ghInstance, IDS_SECTION, &Sheet.pOptItemName);
  440. if(!SUCCEEDED(hrResult))
  441. {
  442. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to get section name. (hrResult = 0x%x)\r\n"),
  443. hrResult);
  444. goto Exit;
  445. }
  446. // Allocate and init User data used in our callback for this page.
  447. pUserData = (PCBUSERDATA) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(CBUSERDATA));
  448. if(NULL == pUserData)
  449. {
  450. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to allocate user data.\r\n"));
  451. hrResult = E_OUTOFMEMORY;
  452. goto Exit;
  453. }
  454. pUserData->hComPropSheet = pPSUIInfo->hComPropSheet;
  455. pUserData->pfnComPropSheet = pPSUIInfo->pfnComPropSheet;
  456. pUserData->pOEMUIParam = pOEMUIParam;
  457. pUserData->pHelper = &Helper;
  458. pUserData->poemuiobj = pOEMUIParam->poemuiobj;
  459. pUserData->bPermission = bPermission;
  460. pUserData->bHidingStandardUI = bHidingStandardUI;
  461. Sheet.UserData = (ULONG_PTR) pUserData;
  462. // Create OptItems for page.
  463. Sheet.pOptItem = CreateOptItems(hHeap, Sheet.cOptItem);
  464. if(NULL == Sheet.pOptItem)
  465. {
  466. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to allocate OPTITEMs.\r\n"));
  467. hrResult = E_OUTOFMEMORY;
  468. goto Exit;
  469. }
  470. // Add Core Driver features.
  471. for(wIndex = 0; wIndex < wFeatures; ++wIndex)
  472. {
  473. // Initialize level and basic state for feature.
  474. Sheet.pOptItem[wIndex].Level = 1;
  475. Sheet.pOptItem[wIndex].Flags = OPTIF_COLLAPSE;
  476. // Get the OPTITEM for this feature.
  477. hrResult = pFeatures->InitOptItem(hHeap,
  478. Sheet.pOptItem + wIndex,
  479. wIndex,
  480. OEMCUIP_PRNPROP);
  481. if(!SUCCEEDED(hrResult))
  482. {
  483. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to get OPTITEM for feature %hs.\r\n"),
  484. pFeatures->GetKeyword(wIndex, OEMCUIP_PRNPROP));
  485. goto Exit;
  486. }
  487. }
  488. // Add property sheets.
  489. lResult = pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PCOMPROPSHEETUI,
  490. (LPARAM)&Sheet, (LPARAM)&dwSheets);
  491. if(!SUCCEEDED(lResult))
  492. {
  493. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to add Device Settings replacement page. (lResult = 0x%x)\r\n"),
  494. lResult);
  495. goto Exit;
  496. }
  497. }
  498. // Init our property page.
  499. memset(&Page, 0, sizeof(PROPSHEETPAGE));
  500. Page.dwSize = sizeof(PROPSHEETPAGE);
  501. Page.dwFlags = PSP_DEFAULT;
  502. Page.hInstance = ghInstance;
  503. Page.pszTemplate = MAKEINTRESOURCE(IDD_DEVICE_PROPPAGE);
  504. Page.pfnDlgProc = DevicePropPageProc;
  505. // Add property sheets.
  506. lResult = pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PROPSHEETPAGE, (LPARAM)&Page, 0);
  507. if(!SUCCEEDED(lResult))
  508. {
  509. ERR(ERRORTEXT("hrOEMDevicePropertySheets() failed to add our Device Property page. (lResult = 0x%x)\r\n"),
  510. lResult);
  511. goto Exit;
  512. }
  513. VERBOSE(DLLTEXT("hrOEMDevicePropertySheets() pfnComPropSheet returned %d.\r\n"), lResult);
  514. }
  515. break;
  516. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  517. {
  518. PPROPSHEETUI_INFO_HEADER pHeader = (PPROPSHEETUI_INFO_HEADER) lParam;
  519. pHeader->pTitle = (LPTSTR)PROP_TITLE;
  520. lResult = TRUE;
  521. }
  522. break;
  523. case PROPSHEETUI_REASON_GET_ICON:
  524. // No icon
  525. lResult = 0;
  526. break;
  527. case PROPSHEETUI_REASON_SET_RESULT:
  528. {
  529. PSETRESULT_INFO pInfo = (PSETRESULT_INFO) lParam;
  530. lResult = pInfo->Result;
  531. }
  532. break;
  533. case PROPSHEETUI_REASON_DESTROY:
  534. lResult = TRUE;
  535. break;
  536. }
  537. Exit:
  538. pPSUIInfo->Result = lResult;
  539. return hrResult;
  540. }
  541. ////////////////////////////////////////////////////////////////////////////////
  542. //
  543. // OptItems call back for OEM printer property UI.
  544. //
  545. LONG APIENTRY OEMPrinterUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam)
  546. {
  547. LONG lReturn = CPSUICB_ACTION_NONE;
  548. POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
  549. VERBOSE(DLLTEXT("OEMPrinterUICallBack() entry, Reason is %d.\r\n"), pCallbackParam->Reason);
  550. switch(pCallbackParam->Reason)
  551. {
  552. case CPSUICB_REASON_APPLYNOW:
  553. {
  554. DWORD dwDriverValue = pOEMUIParam->pOEMOptItems[0].Sel;
  555. // Store OptItems state in printer data.
  556. SetPrinterData(pOEMUIParam->hPrinter, OEMUI_VALUE, REG_DWORD, (PBYTE) &dwDriverValue, sizeof(DWORD));
  557. }
  558. break;
  559. default:
  560. break;
  561. }
  562. return lReturn;
  563. }
  564. ////////////////////////////////////////////////////////////////////////////////
  565. //
  566. // Call back for OEM device property UI.
  567. //
  568. INT_PTR CALLBACK DevicePropPageProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  569. {
  570. switch (uiMsg)
  571. {
  572. case WM_COMMAND:
  573. switch(HIWORD(wParam))
  574. {
  575. case BN_CLICKED:
  576. switch(LOWORD(wParam))
  577. {
  578. case IDC_CALIBRATE:
  579. // Just display a message that the printer is calibrated,
  580. // since we don't acutally calibrate anything.
  581. {
  582. TCHAR szName[MAX_PATH];
  583. TCHAR szCalibrated[MAX_PATH];
  584. LoadString(ghInstance, IDS_NAME, szName, sizeof(szName)/sizeof(szName[0]));
  585. LoadString(ghInstance, IDS_CALIBRATED, szCalibrated, sizeof(szCalibrated)/sizeof(szCalibrated[0]));
  586. MessageBox(hDlg, szCalibrated, szName, MB_OK);
  587. }
  588. break;
  589. }
  590. break;
  591. default:
  592. return FALSE;
  593. }
  594. return TRUE;
  595. case WM_NOTIFY:
  596. {
  597. switch (((LPNMHDR)lParam)->code) // type of notification message
  598. {
  599. case PSN_SETACTIVE:
  600. break;
  601. case PSN_KILLACTIVE:
  602. break;
  603. case PSN_APPLY:
  604. break;
  605. case PSN_RESET:
  606. break;
  607. }
  608. }
  609. break;
  610. }
  611. return FALSE;
  612. }
  613. ////////////////////////////////////////////////////////////////////////////////
  614. //
  615. // OptItems call back for OEM document property UI.
  616. //
  617. LONG APIENTRY OEMDocUIItemCallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam)
  618. {
  619. LONG lReturn = CPSUICB_ACTION_NONE;
  620. POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
  621. VERBOSE(DLLTEXT("OEMDocUIItemCallBack() entry, Reason is %d.\r\n"), pCallbackParam->Reason);
  622. switch(pCallbackParam->Reason)
  623. {
  624. case CPSUICB_REASON_APPLYNOW:
  625. // Store OptItems state in DEVMODE.
  626. pOEMDev->dwAdvancedData = pOEMUIParam->pOEMOptItems[0].Sel;
  627. break;
  628. case CPSUICB_REASON_KILLACTIVE:
  629. pOEMDev->dwAdvancedData = pOEMUIParam->pOEMOptItems[0].Sel;
  630. break;
  631. case CPSUICB_REASON_SETACTIVE:
  632. if(pOEMUIParam->pOEMOptItems[0].Sel != pOEMDev->dwAdvancedData)
  633. {
  634. pOEMUIParam->pOEMOptItems[0].Sel = pOEMDev->dwAdvancedData;
  635. pOEMUIParam->pOEMOptItems[0].Flags |= OPTIF_CHANGED;
  636. lReturn = CPSUICB_ACTION_OPTIF_CHANGED;
  637. }
  638. break;
  639. default:
  640. break;
  641. }
  642. return lReturn;
  643. }
  644. LONG APIENTRY OEMDocUICallBack(PCPSUICBPARAM pCallbackParam)
  645. {
  646. WORD wItems = pCallbackParam->cOptItem;
  647. LONG lReturn = CPSUICB_ACTION_NONE;
  648. POPTITEM pOptItem = pCallbackParam->pOptItem;
  649. PCBUSERDATA pUserData = (PCBUSERDATA) pCallbackParam->UserData;
  650. HANDLE hHeap = pUserData->pOEMUIParam->hOEMHeap;
  651. POEMDEV pOEMDev = (POEMDEV) pUserData->pOEMUIParam->pOEMDM;
  652. VERBOSE(DLLTEXT("OEMDocUICallBack() entry, Reason is %d.\r\n"), pCallbackParam->Reason);
  653. //
  654. // If user has no permission to change anything, then
  655. // simply return without taking any action.
  656. //
  657. if (!pUserData->bPermission && (pCallbackParam->Reason != CPSUICB_REASON_ABOUT))
  658. return CPSUICB_ACTION_NONE;
  659. switch(pCallbackParam->Reason)
  660. {
  661. case CPSUICB_REASON_APPLYNOW:
  662. if(wItems > 0)
  663. {
  664. // Save feature options if hidig standard UI.
  665. if(pUserData->bHidingStandardUI)
  666. {
  667. HRESULT hrResult;
  668. // Save feature OPTITEMs.
  669. hrResult = SaveFeatureOptItems(hHeap,
  670. pUserData->pHelper,
  671. pUserData->poemuiobj,
  672. pCallbackParam->hDlg,
  673. pOptItem,
  674. wItems);
  675. if(!SUCCEEDED(hrResult))
  676. {
  677. // Return that we didn't save changes.
  678. // NOTE: it is up to SaveFeatureOptItems() to display
  679. // any UI for failure.
  680. return CPSUICB_ACTION_NO_APPLY_EXIT;
  681. }
  682. }
  683. // Save OPTITEM that we explicitly added.
  684. pOEMDev->dwDriverData = pOptItem[wItems - 1].Sel;
  685. pUserData->pfnComPropSheet(pUserData->hComPropSheet, CPSFUNC_SET_RESULT,
  686. (LPARAM)pUserData->hPropPage,
  687. (LPARAM)CPSUI_OK);
  688. }
  689. break;
  690. case CPSUICB_REASON_KILLACTIVE:
  691. if(wItems > 0)
  692. {
  693. // Update OPTITEM that we explicitly added.
  694. pOEMDev->dwDriverData = pOptItem[wItems - 1].Sel;
  695. }
  696. break;
  697. case CPSUICB_REASON_SETACTIVE:
  698. if(wItems > 0)
  699. {
  700. if(pOptItem[wItems - 1].Sel != pOEMDev->dwDriverData)
  701. {
  702. // Update OPTITEM that we explicitly added.
  703. pOptItem[wItems - 1].Sel = pOEMDev->dwDriverData;
  704. pOptItem[wItems - 1].Flags |= OPTIF_CHANGED;
  705. }
  706. }
  707. lReturn = CPSUICB_ACTION_OPTIF_CHANGED;
  708. break;
  709. default:
  710. break;
  711. }
  712. return lReturn;
  713. }
  714. LONG APIENTRY OEMDevUICallBack(PCPSUICBPARAM pCallbackParam)
  715. {
  716. WORD wItems = pCallbackParam->cOptItem;
  717. LONG lReturn = CPSUICB_ACTION_NONE;
  718. POPTITEM pOptItem = pCallbackParam->pOptItem;
  719. PCBUSERDATA pUserData = (PCBUSERDATA) pCallbackParam->UserData;
  720. HANDLE hHeap = pUserData->pOEMUIParam->hOEMHeap;
  721. VERBOSE(DLLTEXT("OEMDevUICallBack() entry, Reason is %d.\r\n"), pCallbackParam->Reason);
  722. //
  723. // If user has no permission to change anything, then
  724. // simply return without taking any action.
  725. //
  726. if (!pUserData->bPermission && (pCallbackParam->Reason != CPSUICB_REASON_ABOUT))
  727. return CPSUICB_ACTION_NONE;
  728. switch(pCallbackParam->Reason)
  729. {
  730. case CPSUICB_REASON_APPLYNOW:
  731. if(wItems > 0)
  732. {
  733. // Save feature options if hidig standard UI.
  734. if(pUserData->bHidingStandardUI)
  735. {
  736. HRESULT hrResult;
  737. // Save feature OPTITEMs.
  738. hrResult = SaveFeatureOptItems(hHeap,
  739. pUserData->pHelper,
  740. pUserData->poemuiobj,
  741. pCallbackParam->hDlg,
  742. pOptItem,
  743. wItems);
  744. if(!SUCCEEDED(hrResult))
  745. {
  746. // Return that we didn't save changes.
  747. // NOTE: it is up to SaveFeatureOptItems() to display
  748. // any UI for failure.
  749. return CPSUICB_ACTION_NO_APPLY_EXIT;
  750. }
  751. }
  752. pUserData->pfnComPropSheet(pUserData->hComPropSheet, CPSFUNC_SET_RESULT,
  753. (LPARAM)pUserData->hPropPage,
  754. (LPARAM)CPSUI_OK);
  755. }
  756. break;
  757. case CPSUICB_REASON_KILLACTIVE:
  758. break;
  759. case CPSUICB_REASON_SETACTIVE:
  760. break;
  761. default:
  762. break;
  763. }
  764. return lReturn;
  765. }
  766. ////////////////////////////////////////////////////////////////////////////////
  767. //
  768. // Creates and Initializes OptItems.
  769. //
  770. POPTITEM CreateOptItems(HANDLE hHeap, DWORD dwOptItems)
  771. {
  772. POPTITEM pOptItems = NULL;
  773. // Allocate memory for OptItems;
  774. pOptItems = (POPTITEM) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(OPTITEM) * dwOptItems);
  775. if(NULL != pOptItems)
  776. {
  777. InitOptItems(pOptItems, dwOptItems);
  778. }
  779. else
  780. {
  781. ERR(ERRORTEXT("CreateOptItems() failed to allocate memory for OPTITEMs!\r\n"));
  782. }
  783. return pOptItems;
  784. }
  785. ////////////////////////////////////////////////////////////////////////////////
  786. //
  787. // Initializes OptItems.
  788. //
  789. static void InitOptItems(POPTITEM pOptItems, DWORD dwOptItems)
  790. {
  791. VERBOSE(DLLTEXT("InitOptItems() entry.\r\n"));
  792. // Zero out memory.
  793. memset(pOptItems, 0, sizeof(OPTITEM) * dwOptItems);
  794. // Set each OptItem's size, and Public DM ID.
  795. for(DWORD dwCount = 0; dwCount < dwOptItems; dwCount++)
  796. {
  797. pOptItems[dwCount].cbSize = sizeof(OPTITEM);
  798. pOptItems[dwCount].DMPubID = DMPUB_NONE;
  799. }
  800. }
  801. ////////////////////////////////////////////////////////////////////////////////
  802. //
  803. // Allocates and initializes OptType for OptItem.
  804. //
  805. POPTTYPE CreateOptType(HANDLE hHeap, WORD wOptParams)
  806. {
  807. POPTTYPE pOptType = NULL;
  808. VERBOSE(DLLTEXT("CreateOptType() entry.\r\n"));
  809. // Allocate memory from the heap for the OPTTYPE; the driver will take care of clean up.
  810. pOptType = (POPTTYPE) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(OPTTYPE));
  811. if(NULL != pOptType)
  812. {
  813. // Initialize OPTTYPE.
  814. pOptType->cbSize = sizeof(OPTTYPE);
  815. pOptType->Count = wOptParams;
  816. // Allocate memory from the heap for the OPTPARAMs for the OPTTYPE.
  817. pOptType->pOptParam = (POPTPARAM) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, wOptParams * sizeof(OPTPARAM));
  818. if(NULL != pOptType->pOptParam)
  819. {
  820. // Initialize the OPTPARAMs.
  821. for(WORD wCount = 0; wCount < wOptParams; wCount++)
  822. {
  823. pOptType->pOptParam[wCount].cbSize = sizeof(OPTPARAM);
  824. }
  825. }
  826. else
  827. {
  828. ERR(ERRORTEXT("CreateOptType() failed to allocated memory for OPTPARAMs!\r\n"));
  829. // Free allocated memory and return NULL.
  830. HeapFree(hHeap, 0, pOptType);
  831. pOptType = NULL;
  832. }
  833. }
  834. else
  835. {
  836. ERR(ERRORTEXT("CreateOptType() failed to allocated memory for OPTTYPE!\r\n"));
  837. }
  838. return pOptType;
  839. }