Source code of Windows XP (NT5)
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.

455 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxui.c
  5. Abstract:
  6. Common routines for fax driver user interface
  7. Environment:
  8. Fax driver user interface
  9. Revision History:
  10. 01/09/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxui.h"
  16. #include "forms.h"
  17. #include <shlobj.h>
  18. CRITICAL_SECTION faxuiSemaphore; // Semaphore for protecting critical sections
  19. HANDLE ghInstance; // DLL instance handle
  20. PUSERMEM gUserMemList; // Global list of user mode memory structures
  21. INT _debugLevel = 1; // for debuggping purposes
  22. PVOID
  23. PrMemAlloc(
  24. DWORD size
  25. )
  26. {
  27. return (PVOID)LocalAlloc(LPTR, size);
  28. }
  29. VOID
  30. PrMemFree(
  31. PVOID ptr
  32. )
  33. {
  34. if (ptr) {
  35. LocalFree((HLOCAL) ptr);
  36. }
  37. }
  38. BOOL
  39. DllEntryPoint(
  40. HANDLE hModule,
  41. ULONG ulReason,
  42. PCONTEXT pContext
  43. )
  44. /*++
  45. Routine Description:
  46. DLL initialization procedure.
  47. Arguments:
  48. hModule - DLL instance handle
  49. ulReason - Reason for the call
  50. pContext - Pointer to context (not used by us)
  51. Return Value:
  52. TRUE if DLL is initialized successfully, FALSE otherwise.
  53. --*/
  54. {
  55. WCHAR DllName[MAX_PATH];
  56. INITCOMMONCONTROLSEX CommonControlsEx = {sizeof(INITCOMMONCONTROLSEX),
  57. ICC_WIN95_CLASSES|ICC_DATE_CLASSES };
  58. switch (ulReason) {
  59. case DLL_PROCESS_ATTACH:
  60. //
  61. // Keep our driver UI dll always loaded in memory
  62. //
  63. if (! GetModuleFileName(hModule, DllName, MAX_PATH) ||
  64. ! LoadLibrary(DllName))
  65. {
  66. return FALSE;
  67. }
  68. ghInstance = hModule;
  69. gUserMemList = NULL;
  70. HeapInitialize( NULL, PrMemAlloc, PrMemFree, HEAPINIT_NO_VALIDATION | HEAPINIT_NO_STRINGS );
  71. InitializeCriticalSection(&faxuiSemaphore);
  72. InitCommonControlsEx(&CommonControlsEx);
  73. break;
  74. case DLL_PROCESS_DETACH:
  75. while (gUserMemList != NULL) {
  76. PUSERMEM pUserMem;
  77. pUserMem = gUserMemList;
  78. gUserMemList = gUserMemList->pNext;
  79. FreePDEVUserMem(pUserMem);
  80. }
  81. DeleteCriticalSection(&faxuiSemaphore);
  82. break;
  83. }
  84. return TRUE;
  85. }
  86. LONG
  87. CallCompstui(
  88. HWND hwndOwner,
  89. PFNPROPSHEETUI pfnPropSheetUI,
  90. LPARAM lParam,
  91. PDWORD pResult
  92. )
  93. /*++
  94. Routine Description:
  95. Calling common UI DLL entry point dynamically
  96. Arguments:
  97. hwndOwner, pfnPropSheetUI, lParam, pResult - Parameters passed to common UI DLL
  98. Return Value:
  99. Return value from common UI library
  100. --*/
  101. {
  102. HINSTANCE hInstCompstui;
  103. FARPROC pProc;
  104. LONG Result = ERR_CPSUI_GETLASTERROR;
  105. //
  106. // Only need to call the ANSI version of LoadLibrary
  107. //
  108. static const CHAR szCompstui[] = "compstui.dll";
  109. static const CHAR szCommonPropSheetUI[] = "CommonPropertySheetUIW";
  110. if ((hInstCompstui = LoadLibraryA(szCompstui)) &&
  111. (pProc = GetProcAddress(hInstCompstui, szCommonPropSheetUI)))
  112. {
  113. Result = (LONG)(*pProc)(hwndOwner, pfnPropSheetUI, lParam, pResult);
  114. }
  115. if (hInstCompstui)
  116. FreeLibrary(hInstCompstui);
  117. return Result;
  118. }
  119. VOID
  120. GetCombinedDevmode(
  121. PDRVDEVMODE pdmOut,
  122. PDEVMODE pdmIn,
  123. HANDLE hPrinter,
  124. PPRINTER_INFO_2 pPrinterInfo2,
  125. BOOL publicOnly
  126. )
  127. /*++
  128. Routine Description:
  129. Combine DEVMODE information:
  130. start with the driver default
  131. then merge with the system default
  132. then merge with the user default
  133. finally merge with the input devmode
  134. Arguments:
  135. pdmOut - Pointer to the output devmode buffer
  136. pdmIn - Pointer to an input devmode
  137. hPrinter - Handle to a printer object
  138. pPrinterInfo2 - Point to a PRINTER_INFO_2 structure or NULL
  139. publicOnly - Only merge the public portion of the devmode
  140. Return Value:
  141. TRUE
  142. --*/
  143. {
  144. PPRINTER_INFO_2 pAlloced = NULL;
  145. PDEVMODE pdmUser;
  146. //
  147. // Get a PRINTER_INFO_2 structure if one is not provided
  148. //
  149. if (! pPrinterInfo2)
  150. pPrinterInfo2 = pAlloced = MyGetPrinter(hPrinter, 2);
  151. //
  152. // Start with driver default devmode
  153. //
  154. if (! publicOnly) {
  155. DriverDefaultDevmode(pdmOut,
  156. pPrinterInfo2 ? pPrinterInfo2->pPrinterName : NULL,
  157. hPrinter);
  158. }
  159. //
  160. // Merge with the system default devmode and user default devmode
  161. //
  162. if (pPrinterInfo2) {
  163. #if 0
  164. //
  165. // Since we have per-user devmode and there is no way to
  166. // change the printer's default devmode, there is no need
  167. // to merge it here.
  168. //
  169. if (! MergeDevmode(pdmOut, pPrinterInfo2->pDevMode, publicOnly))
  170. Error(("Invalid system default devmode\n"));
  171. #endif
  172. if (pdmUser = GetPerUserDevmode(pPrinterInfo2->pPrinterName)) {
  173. if (! MergeDevmode(pdmOut, pdmUser, publicOnly))
  174. Error(("Invalid user devmode\n"));
  175. MemFree(pdmUser);
  176. }
  177. }
  178. MemFree(pAlloced);
  179. //
  180. // Merge with the input devmode
  181. //
  182. if (! MergeDevmode(pdmOut, pdmIn, publicOnly))
  183. Error(("Invalid input devmode\n"));
  184. }
  185. PUIDATA
  186. FillUiData(
  187. HANDLE hPrinter,
  188. PDEVMODE pdmInput
  189. )
  190. /*++
  191. Routine Description:
  192. Fill in the data structure used by the fax driver user interface
  193. Arguments:
  194. hPrinter - Handle to the printer
  195. pdmInput - Pointer to input devmode, NULL if there is none
  196. Return Value:
  197. Pointer to UIDATA structure, NULL if error.
  198. --*/
  199. {
  200. PRINTER_INFO_2 *pPrinterInfo2 = NULL;
  201. PUIDATA pUiData = NULL;
  202. HANDLE hheap = NULL;
  203. //
  204. // Create a heap to manage memory
  205. // Allocate memory to hold UIDATA structure
  206. // Get printer info from the spooler
  207. // Copy the driver name
  208. //
  209. if (! (hheap = HeapCreate(0, 4096, 0)) ||
  210. ! (pUiData = HeapAlloc(hheap, HEAP_ZERO_MEMORY, sizeof(UIDATA))) ||
  211. ! (pPrinterInfo2 = MyGetPrinter(hPrinter, 2)))
  212. {
  213. if (hheap)
  214. HeapDestroy(hheap);
  215. MemFree(pPrinterInfo2);
  216. return NULL;
  217. }
  218. pUiData->startSign = pUiData->endSign = pUiData;
  219. pUiData->hPrinter = hPrinter;
  220. pUiData->hheap = hheap;
  221. //
  222. // Combine various devmode information
  223. //
  224. GetCombinedDevmode(&pUiData->devmode, pdmInput, hPrinter, pPrinterInfo2, FALSE);
  225. //
  226. // Validate the form requested by the input devmode
  227. //
  228. if (! ValidDevmodeForm(hPrinter, &pUiData->devmode.dmPublic, NULL))
  229. Error(("Invalid form specification\n"));
  230. MemFree(pPrinterInfo2);
  231. return pUiData;
  232. }
  233. INT
  234. DisplayMessageDialog(
  235. HWND hwndParent,
  236. UINT type,
  237. INT titleStrId,
  238. INT formatStrId,
  239. ...
  240. )
  241. /*++
  242. Routine Description:
  243. Display a message dialog box
  244. Arguments:
  245. hwndParent - Specifies a parent window for the error message dialog
  246. titleStrId - Title string (could be a string resource ID)
  247. formatStrId - Message format string (could be a string resource ID)
  248. ...
  249. Return Value:
  250. NONE
  251. --*/
  252. {
  253. LPTSTR pTitle, pFormat, pMessage;
  254. INT result;
  255. va_list ap;
  256. pTitle = pFormat = pMessage = NULL;
  257. if ((pTitle = AllocStringZ(MAX_TITLE_LEN)) &&
  258. (pFormat = AllocStringZ(MAX_STRING_LEN)) &&
  259. (pMessage = AllocStringZ(MAX_MESSAGE_LEN)))
  260. {
  261. //
  262. // Load dialog box title string resource
  263. //
  264. if (titleStrId == 0)
  265. titleStrId = IDS_ERROR_DLGTITLE;
  266. LoadString(ghInstance, titleStrId, pTitle, MAX_TITLE_LEN);
  267. //
  268. // Load message format string resource
  269. //
  270. LoadString(ghInstance, formatStrId, pFormat, MAX_STRING_LEN);
  271. //
  272. // Compose the message string
  273. //
  274. va_start(ap, formatStrId);
  275. wvsprintf(pMessage, pFormat, ap);
  276. va_end(ap);
  277. //
  278. // Display the message box
  279. //
  280. if (type == 0)
  281. type = MB_OK | MB_ICONERROR;
  282. result = MessageBox(hwndParent, pMessage, pTitle, type);
  283. } else {
  284. MessageBeep(MB_ICONHAND);
  285. result = 0;
  286. }
  287. MemFree(pTitle);
  288. MemFree(pFormat);
  289. MemFree(pMessage);
  290. return result;
  291. }
  292. BOOL
  293. DevQueryPrintEx(
  294. PDEVQUERYPRINT_INFO pDQPInfo
  295. )
  296. /*++
  297. Routine Description:
  298. Implementation of DDI entry point DevQueryPrintEx. Even though we don't
  299. really need this entry point, we must export it so that the spooler
  300. will load our driver UI.
  301. Arguments:
  302. pDQPInfo - Points to a DEVQUERYPRINT_INFO structure
  303. Return Value:
  304. TRUE if there is no conflicts, FALSE otherwise
  305. --*/
  306. {
  307. return TRUE;
  308. }