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.

474 lines
13 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. prnprop.c
  5. Abstract:
  6. Implementation of DDI entry points:
  7. DrvDevicePropertySheets
  8. PrinterProperties
  9. Environment:
  10. Fax driver user interface
  11. Revision History:
  12. 01/09/96 -davidx-
  13. Created it.
  14. mm/dd/yy -author-
  15. description
  16. --*/
  17. #include "faxui.h"
  18. #include <shlobjp.h>
  19. #include <shellapi.h>
  20. #include <faxreg.h>
  21. #include "resource.h"
  22. BOOL g_bUserCanChangeSettings = FALSE;
  23. BOOL g_bUserCanQuerySettings = FALSE;
  24. HANDLE g_hFaxSvcHandle = NULL; // global fax handle
  25. HANDLE g_hFaxActCtx = INVALID_HANDLE_VALUE;
  26. BOOL g_bLinkWindowRegistered = FALSE;
  27. PFAX_PORT_INFO_EX g_pFaxPortInfo = NULL;
  28. DWORD g_dwPortsNum = 0;
  29. BOOL g_bPortInfoChanged = FALSE;
  30. #define EXTRA_PAGES 3
  31. extern HANDLE g_hModule;
  32. HANDLE CreateActivationContextFromResource(LPCTSTR pszResourceName)
  33. {
  34. TCHAR tszModuleName[MAX_PATH * 2] = {0};
  35. ACTCTX act = {0};
  36. //
  37. // Get the name for the module that contains the manifest resource
  38. // to create the Activation Context from.
  39. //
  40. if (!GetModuleFileName(g_hModule, tszModuleName, ARR_SIZE(tszModuleName)-1))
  41. {
  42. return INVALID_HANDLE_VALUE;
  43. }
  44. //
  45. // Now let's try to create an activation context from manifest resource.
  46. //
  47. act.cbSize = sizeof(act);
  48. act.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
  49. act.lpResourceName = pszResourceName;
  50. act.lpSource = tszModuleName;
  51. return CreateActCtx(&act);
  52. } // CreateActivationContextFromResource
  53. void ReleaseActivationContext()
  54. {
  55. if (INVALID_HANDLE_VALUE != g_hFaxActCtx)
  56. {
  57. ReleaseActCtx(g_hFaxActCtx);
  58. g_hFaxActCtx = INVALID_HANDLE_VALUE;
  59. }
  60. } // ReleaseActivationContext
  61. BOOL CreateFaxActivationContext()
  62. {
  63. if(INVALID_HANDLE_VALUE != g_hFaxActCtx)
  64. {
  65. //
  66. // Already created
  67. //
  68. return TRUE;
  69. }
  70. g_hFaxActCtx = CreateActivationContextFromResource(MAKEINTRESOURCE(SXS_MANIFEST_RESOURCE_ID));
  71. return (INVALID_HANDLE_VALUE != g_hFaxActCtx);
  72. } // CreateFaxActivationContext
  73. HANDLE GetFaxActivationContext()
  74. {
  75. //
  76. // Make sure we've created our activation context.
  77. //
  78. CreateFaxActivationContext();
  79. // Return the global.
  80. return g_hFaxActCtx;
  81. } // GetFaxActivationContext
  82. HPROPSHEETPAGE
  83. AddPropertyPage(
  84. PPROPSHEETUI_INFO pPSUIInfo,
  85. PROPSHEETPAGE *psp
  86. )
  87. {
  88. HPROPSHEETPAGE hRes;
  89. hRes = (HPROPSHEETPAGE)(pPSUIInfo->pfnComPropSheet(
  90. pPSUIInfo->hComPropSheet,
  91. CPSFUNC_ADD_PROPSHEETPAGE,
  92. (LPARAM) psp,
  93. 0));
  94. return hRes;
  95. } // AddPropertyPage
  96. LONG
  97. DrvDevicePropertySheets(
  98. PPROPSHEETUI_INFO pPSUIInfo,
  99. LPARAM lParam
  100. )
  101. /*++
  102. Routine Description:
  103. Display "Printer Properties" dialog
  104. Arguments:
  105. pPSUIInfo - Pointer to a PROPSHEETUI_INFO structure
  106. lParam - Pointer to a DEVICEPROPERTYHEADER structure
  107. Return Value:
  108. > 0 if successful, <= 0 if failed
  109. [Note:]
  110. Please refer to WinNT DDK/SDK documentation for more details.
  111. --*/
  112. {
  113. PDEVICEPROPERTYHEADER pDPHdr;
  114. PROPSHEETPAGE psp[EXTRA_PAGES]={0};
  115. HPROPSHEETPAGE hPropSheetPage;
  116. DWORD dwRes = 0;
  117. int iRet = 1;
  118. HANDLE hActCtx = INVALID_HANDLE_VALUE;
  119. //
  120. // Do not execute any code before this initialization
  121. //
  122. if(!InitializeDll())
  123. {
  124. return -1;
  125. }
  126. //
  127. // Validate input parameters
  128. //
  129. if (!pPSUIInfo || !(pDPHdr = (PDEVICEPROPERTYHEADER) pPSUIInfo->lParamInit))
  130. {
  131. Assert(FALSE);
  132. return -1;
  133. }
  134. //
  135. // Handle various cases for which this function might be called
  136. //
  137. switch (pPSUIInfo->Reason)
  138. {
  139. case PROPSHEETUI_REASON_INIT:
  140. InitializeStringTable();
  141. memset(psp, 0, sizeof(psp));
  142. //
  143. // Need to add a Activation Context so that Compstui will create the property page using
  144. // ComCtl v6 (i.e. so it will / can be Themed).
  145. //
  146. hActCtx = GetFaxActivationContext();
  147. if (INVALID_HANDLE_VALUE != hActCtx)
  148. {
  149. pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet,
  150. CPSFUNC_SET_FUSION_CONTEXT,
  151. (LPARAM)hActCtx,
  152. 0);
  153. }
  154. //
  155. // if the printer is remote, show a simple page
  156. //
  157. if(!IsLocalPrinter(pDPHdr->pszPrinterName))
  158. {
  159. //
  160. // add a simple page because we need to add at least one page
  161. //
  162. psp[0].dwSize = sizeof(PROPSHEETPAGE);
  163. psp[0].hInstance = g_hResource;
  164. psp[0].lParam = (LPARAM)pDPHdr->pszPrinterName;
  165. psp[0].pszTemplate = MAKEINTRESOURCE(IDD_REMOTE_INFO);
  166. psp[0].pfnDlgProc = RemoteInfoDlgProc;
  167. if ( hPropSheetPage = AddPropertyPage(pPSUIInfo, &psp[0]) )
  168. {
  169. pPSUIInfo->UserData = 0;
  170. pPSUIInfo->Result = CPSUI_CANCEL;
  171. goto exit;
  172. }
  173. break;
  174. }
  175. //
  176. // check the user's right to query/modify device setting, if the user doesn't have
  177. // modify permission, all controls will be disabled.
  178. //
  179. if(Connect(NULL, TRUE))
  180. {
  181. g_bUserCanQuerySettings = FaxAccessCheckEx(g_hFaxSvcHandle, FAX_ACCESS_QUERY_CONFIG, NULL);
  182. if(ERROR_SUCCESS != GetLastError())
  183. {
  184. dwRes = GetLastError();
  185. Error(( "FaxAccessCheckEx(FAX_ACCESS_QUERY_CONFIG) failed with %d\n", dwRes));
  186. goto ConnectError;
  187. }
  188. g_bUserCanChangeSettings = FaxAccessCheckEx(g_hFaxSvcHandle, FAX_ACCESS_MANAGE_CONFIG, NULL);
  189. if(ERROR_SUCCESS != GetLastError())
  190. {
  191. dwRes = GetLastError();
  192. Error(( "FaxAccessCheckEx(FAX_ACCESS_MANAGE_CONFIG) failed with %d\n", dwRes));
  193. goto ConnectError;
  194. }
  195. if(g_bUserCanQuerySettings)
  196. {
  197. g_bPortInfoChanged = FALSE;
  198. if(!FaxEnumPortsEx(g_hFaxSvcHandle, &g_pFaxPortInfo, &g_dwPortsNum))
  199. {
  200. dwRes = GetLastError();
  201. Error(( "FaxEnumPortsEx failed with %d\n", dwRes));
  202. goto ConnectError;
  203. }
  204. }
  205. DisConnect();
  206. }
  207. //
  208. // Tracking page - added both in Desktop & Server SKU's
  209. //
  210. psp[1].dwSize = sizeof(PROPSHEETPAGE);
  211. psp[1].hInstance = g_hResource;
  212. psp[1].lParam = 0;
  213. psp[1].pszTemplate = MAKEINTRESOURCE(IDD_STATUS_OPTIONS);
  214. psp[1].pfnDlgProc = StatusOptionDlgProc;
  215. if (IsDesktopSKU())
  216. {
  217. //
  218. // Devices page
  219. //
  220. psp[0].dwSize = sizeof(PROPSHEETPAGE);
  221. psp[0].hInstance = g_hResource;
  222. psp[0].lParam = 0;
  223. psp[0].pszTemplate = MAKEINTRESOURCE(IDD_DEVICE_INFO);
  224. psp[0].pfnDlgProc = DeviceInfoDlgProc;
  225. //
  226. // Archives page
  227. //
  228. psp[2].dwSize = sizeof(PROPSHEETPAGE);
  229. psp[2].hInstance = g_hResource;
  230. psp[2].lParam = 0;
  231. psp[2].pszTemplate = MAKEINTRESOURCE(IDD_ARCHIVE_FOLDER);
  232. psp[2].pfnDlgProc = ArchiveInfoDlgProc;
  233. if(!IsSimpleUI())
  234. {
  235. //
  236. // Add Fax Security page
  237. //
  238. hPropSheetPage = CreateFaxSecurityPage();
  239. if(hPropSheetPage)
  240. {
  241. if(!pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet,
  242. CPSFUNC_ADD_HPROPSHEETPAGE,
  243. (LPARAM)hPropSheetPage,
  244. 0))
  245. {
  246. Error(("Failed to add Fax Security page.\n"));
  247. }
  248. }
  249. }
  250. if(g_bUserCanQuerySettings)
  251. {
  252. if (!AddPropertyPage(pPSUIInfo, &psp[0])) // Devices(desktop)
  253. {
  254. Error(("Failed to add property page"));
  255. goto exit;
  256. }
  257. if (!AddPropertyPage(pPSUIInfo, &psp[1])) // Tracking (desktop & server)
  258. {
  259. Error(("Failed to add Tracking property page"));
  260. goto exit;
  261. }
  262. if (!AddPropertyPage(pPSUIInfo, &psp[2])) // Archives(desktop)
  263. {
  264. Error(("Failed to add Archives property page"));
  265. goto exit;
  266. }
  267. }
  268. }
  269. else
  270. {
  271. //
  272. // Case of Server SKU
  273. // This page contains link to Admin Console
  274. //
  275. g_bLinkWindowRegistered = LinkWindow_RegisterClass();
  276. if(!g_bLinkWindowRegistered)
  277. {
  278. Error(("LinkWindow_RegisterClass() failed - unable to register link window class.\n"));
  279. goto exit;
  280. }
  281. psp[0].dwSize = sizeof(PROPSHEETPAGE);
  282. psp[0].hInstance = g_hResource;
  283. psp[0].lParam = 0;
  284. psp[0].pszTemplate = MAKEINTRESOURCE(IDD_CONFIG_PROP);
  285. psp[0].pfnDlgProc = ConfigOptionDlgProc;
  286. if (!AddPropertyPage(pPSUIInfo, &psp[0])) // Fax configuration
  287. {
  288. Error(("Failed to add property page"));
  289. goto exit;
  290. }
  291. if(g_bUserCanQuerySettings)
  292. {
  293. if (!AddPropertyPage(pPSUIInfo, &psp[1])) // always Tracking
  294. {
  295. Error(("Failed to add Tracking property page"));
  296. goto exit;
  297. }
  298. }
  299. }
  300. // Added all needed pages
  301. pPSUIInfo->UserData = 0;
  302. pPSUIInfo->Result = CPSUI_CANCEL;
  303. goto exit;
  304. break;
  305. ConnectError:
  306. DisConnect();
  307. DisplayErrorMessage(NULL, 0, dwRes);
  308. break;
  309. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  310. {
  311. PPROPSHEETUI_INFO_HEADER pPSUIHdr;
  312. pPSUIHdr = (PPROPSHEETUI_INFO_HEADER) lParam;
  313. pPSUIHdr->Flags = PSUIHDRF_PROPTITLE | PSUIHDRF_NOAPPLYNOW;
  314. pPSUIHdr->pTitle = pDPHdr->pszPrinterName;
  315. pPSUIHdr->hInst = g_hResource;
  316. pPSUIHdr->IconID = IDI_CPSUI_FAX;
  317. }
  318. goto exit;
  319. case PROPSHEETUI_REASON_SET_RESULT:
  320. pPSUIInfo->Result = ((PSETRESULT_INFO) lParam)->Result;
  321. goto exit;
  322. case PROPSHEETUI_REASON_DESTROY:
  323. DeInitializeStringTable();
  324. g_dwPortsNum = 0;
  325. FaxFreeBuffer(g_pFaxPortInfo);
  326. g_pFaxPortInfo = NULL;
  327. if(g_bLinkWindowRegistered )
  328. {
  329. LinkWindow_UnregisterClass( g_hResource );
  330. g_bLinkWindowRegistered = FALSE;
  331. }
  332. //
  333. // Release CFaxSecurity object
  334. //
  335. ReleaseFaxSecurity();
  336. DisConnect();
  337. goto exit;
  338. }
  339. exit:
  340. return iRet;
  341. } // DrvDevicePropertySheets
  342. BOOL
  343. PrinterProperties(
  344. HWND hwnd,
  345. HANDLE hPrinter
  346. )
  347. /*++
  348. Routine Description:
  349. Displays a printer-properties dialog box for the specified printer
  350. Arguments:
  351. hwnd - Identifies the parent window of the dialog box
  352. hPrinter - Identifies a printer object
  353. Return Value:
  354. If the function succeeds, the return value is TRUE.
  355. If the function fails, the return value is FALSE.
  356. [Note:]
  357. This is the old entry point for the spooler. Even though
  358. no one should be using this, do it for compatibility.
  359. --*/
  360. {
  361. DEVICEPROPERTYHEADER devPropHdr;
  362. DWORD result;
  363. //
  364. // Do not execute any code before this initialization
  365. //
  366. if(!InitializeDll())
  367. {
  368. return FALSE;
  369. }
  370. memset(&devPropHdr, 0, sizeof(devPropHdr));
  371. devPropHdr.cbSize = sizeof(devPropHdr);
  372. devPropHdr.hPrinter = hPrinter;
  373. devPropHdr.pszPrinterName = NULL;
  374. //
  375. // Decide if the caller has permission to change anything
  376. //
  377. if (! SetPrinterDataDWord(hPrinter, PRNDATA_PERMISSION, 1))
  378. devPropHdr.Flags |= DPS_NOPERMISSION;
  379. CallCompstui(hwnd, DrvDevicePropertySheets, (LPARAM) &devPropHdr, &result);
  380. return result > 0;
  381. }