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.

211 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. prnevent.c
  5. Abstract:
  6. Implementation of DrvPrinterEvent
  7. Environment:
  8. Fax driver user interface
  9. Revision History:
  10. 05/10/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxui.h"
  16. #include <crtdbg.h>
  17. DWORD
  18. GetLocaleDefaultPaperSize(
  19. VOID
  20. )
  21. /*++
  22. Routine Description:
  23. Retrieves the current locale defualt paper size.
  24. Arguments:
  25. NONE
  26. Return Value:
  27. One of the following values: 1 = letter, 5 = legal, 9 = a4
  28. --*/
  29. {
  30. WCHAR szMeasure[2] = TEXT("9"); // 2 is maximum size for the LOCALE_IPAPERSIZE
  31. // value as defined is MSDN.
  32. if (!GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_IPAPERSIZE, szMeasure,2))
  33. {
  34. Error(("GetLocaleDefaultPaperSize: GetLocaleInfo() failed (ec: %ld)",GetLastError()));
  35. }
  36. if (!wcscmp(szMeasure,TEXT("9")))
  37. {
  38. // A4
  39. return DMPAPER_A4;
  40. }
  41. if (!wcscmp(szMeasure,TEXT("5")))
  42. {
  43. // legal
  44. return DMPAPER_LEGAL;
  45. }
  46. //
  47. // Defualt value is Letter. We do not support A3.
  48. //
  49. return DMPAPER_LETTER;
  50. }
  51. BOOL
  52. DrvPrinterEvent(
  53. LPWSTR pPrinterName,
  54. int DriverEvent,
  55. DWORD Flags,
  56. LPARAM lParam
  57. )
  58. /*++
  59. Routine Description:
  60. Implementation of DrvPrinterEvent entrypoint
  61. Arguments:
  62. pPrinterName - Specifies the name of the printer involved
  63. DriverEvent - Specifies what happened
  64. Flags - Specifies misc. flag bits
  65. lParam - Event specific parameters
  66. Return Value:
  67. TRUE if successful, FALSE otherwise
  68. --*/
  69. {
  70. #define FUNCTION_NAME "DrvPrinterEvent()"
  71. HKEY hRegKey = NULL;
  72. HANDLE hPrinter = NULL;
  73. PDRIVER_INFO_2 pDriverInfo2 = NULL;
  74. PPRINTER_INFO_2 pPrinterInfo2 = NULL;
  75. HINSTANCE hInstFaxOcm = NULL;
  76. LPTSTR pClientSetupDir = NULL;
  77. INT status = 0;
  78. TCHAR DestPath[MAX_PATH] = {0};
  79. BOOL bFaxAlreadyInstalled = FALSE;
  80. BOOL bRes = FALSE;
  81. TCHAR FaxOcmPath[MAX_PATH] = {0};
  82. Verbose(("DrvPrinterEvent: %d\n", DriverEvent));
  83. DestPath[0] = 0;
  84. //
  85. // Do not execute any code before this initialization
  86. //
  87. if(!InitializeDll())
  88. {
  89. return FALSE;
  90. }
  91. //
  92. // Ignore any event other than Initialize and AddConnection
  93. //
  94. if (DriverEvent == PRINTER_EVENT_INITIALIZE)
  95. {
  96. static PRINTER_DEFAULTS printerDefault = {NULL, NULL, PRINTER_ALL_ACCESS};
  97. if (OpenPrinter(pPrinterName, &hPrinter, &printerDefault))
  98. {
  99. SetPrinterDataDWord(hPrinter, PRNDATA_PAPER_SIZE, GetLocaleDefaultPaperSize());
  100. ClosePrinter(hPrinter);
  101. }
  102. else
  103. {
  104. Error(("OpenPrinter failed: %d\n", GetLastError()));
  105. }
  106. }
  107. else if (DriverEvent == PRINTER_EVENT_ADD_CONNECTION)
  108. {
  109. if (Flags & PRINTER_EVENT_FLAG_NO_UI)
  110. {
  111. Verbose(("PRINTER_EVENT_FLAG_NO_UI is set, disable Point and Print\n"));
  112. return TRUE;
  113. }
  114. //
  115. // client 'point and print' setup
  116. //
  117. if (FaxPointAndPrintSetup(pPrinterName,TRUE, g_hModule))
  118. {
  119. Verbose(("FaxPointAndPrintSetup succeeded\n"));
  120. }
  121. else
  122. {
  123. Error(("FaxPointAndPrintSetup failed: %d\n", GetLastError()));
  124. }
  125. return TRUE;
  126. }
  127. else if (DriverEvent == PRINTER_EVENT_ATTRIBUTES_CHANGED)
  128. {
  129. //
  130. // Printer attributes changed.
  131. // Check if the printer is now shared.
  132. //
  133. PPRINTER_EVENT_ATTRIBUTES_INFO pAttributesInfo = (PPRINTER_EVENT_ATTRIBUTES_INFO)lParam;
  134. Assert (pAttributesInfo);
  135. if (pAttributesInfo->cbSize >= (3 * sizeof(DWORD)))
  136. {
  137. //
  138. // We are dealing with the correct structure - see DDK
  139. //
  140. if (!(pAttributesInfo->dwOldAttributes & PRINTER_ATTRIBUTE_SHARED) && // The printer was not shared
  141. (pAttributesInfo->dwNewAttributes & PRINTER_ATTRIBUTE_SHARED)) // The printer is now shared
  142. {
  143. //
  144. // We shouls start the fax service
  145. //
  146. Assert (IsFaxShared()); // The fax printer can be shared
  147. if (!EnsureFaxServiceIsStarted (NULL))
  148. {
  149. Error(("EnsureFaxServiceIsStarted failed: %d\n", GetLastError()));
  150. }
  151. }
  152. }
  153. }
  154. return TRUE;
  155. }