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.

332 lines
6.9 KiB

  1. #include "devmgr.h"
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name:
  5. prndlg.cpp
  6. Abstract:
  7. This module implements CPrintDialog, the class that processes
  8. printer dialog
  9. Author:
  10. William Hsieh (williamh) created
  11. Revision History:
  12. --*/
  13. //
  14. // CPrintDialog implementation
  15. //
  16. //
  17. // help topic ids
  18. //
  19. const DWORD g_a207HelpIDs[]=
  20. {
  21. IDC_PRINT_SYSTEM_SUMMARY, idh_devmgr_print_system,
  22. IDC_PRINT_SELECT_CLASSDEVICE, idh_devmgr_print_device,
  23. IDC_PRINT_ALL, idh_devmgr_print_both,
  24. IDC_PRINT_REPORT_TYPE_TEXT, idh_devmgr_print_report,
  25. 0, 0
  26. };
  27. HRESULT
  28. CDevMgrPrintDialogCallback::QueryInterface(
  29. REFIID riid,
  30. void** ppv
  31. )
  32. {
  33. if (!ppv) {
  34. return E_INVALIDARG;
  35. }
  36. HRESULT hr = S_OK;
  37. if (IsEqualIID(riid, IID_IUnknown))
  38. {
  39. *ppv = (IUnknown*)this;
  40. }
  41. else if (IsEqualIID(riid, IID_IPrintDialogCallback))
  42. {
  43. *ppv = (IPrintDialogCallback*)this;
  44. }
  45. else
  46. {
  47. *ppv = NULL;
  48. hr = E_NOINTERFACE;
  49. }
  50. if (SUCCEEDED(hr))
  51. {
  52. AddRef();
  53. }
  54. return hr;
  55. }
  56. ULONG
  57. CDevMgrPrintDialogCallback::AddRef()
  58. {
  59. return ::InterlockedIncrement(&m_Ref);
  60. }
  61. ULONG
  62. CDevMgrPrintDialogCallback::Release()
  63. {
  64. ASSERT( 0 != m_Ref );
  65. ULONG cRef = ::InterlockedDecrement(&m_Ref);
  66. if ( 0 == cRef )
  67. {
  68. delete this;
  69. }
  70. return cRef;
  71. }
  72. HRESULT
  73. CDevMgrPrintDialogCallback::InitDone()
  74. {
  75. return S_OK;
  76. }
  77. HRESULT
  78. CDevMgrPrintDialogCallback::SelectionChange()
  79. {
  80. return S_OK;
  81. }
  82. HRESULT
  83. CDevMgrPrintDialogCallback::HandleMessage(
  84. HWND hDlg,
  85. UINT uMsg,
  86. WPARAM wParam,
  87. LPARAM lParam,
  88. LRESULT *pResult
  89. )
  90. {
  91. *pResult = FALSE;
  92. switch (uMsg) {
  93. case WM_INITDIALOG:
  94. *pResult = OnInitDialog(hDlg);
  95. break;
  96. case WM_COMMAND:
  97. *pResult = OnCommand(hDlg, wParam, lParam);
  98. break;
  99. case WM_HELP:
  100. *pResult = OnHelp((LPHELPINFO)lParam);
  101. break;
  102. case WM_CONTEXTMENU:
  103. *pResult = OnContextMenu(hDlg, LOWORD(lParam), HIWORD(lParam), wParam);
  104. break;
  105. default:
  106. break;
  107. }
  108. return S_OK;
  109. }
  110. BOOL
  111. CDevMgrPrintDialogCallback::OnInitDialog(
  112. HWND hWnd
  113. )
  114. {
  115. int DefaultId = IDC_PRINT_SELECT_CLASSDEVICE;
  116. m_pPrintDialog->SetReportType(REPORT_TYPE_CLASSDEVICE);
  117. if (!(m_pPrintDialog->GetTypeEnableMask() & REPORT_TYPE_MASK_CLASSDEVICE))
  118. {
  119. EnableWindow(GetDlgItem(hWnd, IDC_PRINT_SELECT_CLASSDEVICE), FALSE);
  120. DefaultId = IDC_PRINT_SYSTEM_SUMMARY;
  121. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY);
  122. }
  123. if (!(m_pPrintDialog->GetTypeEnableMask() & REPORT_TYPE_MASK_SUMMARY))
  124. {
  125. EnableWindow(GetDlgItem(hWnd, IDC_PRINT_SYSTEM_SUMMARY), FALSE);
  126. if (IDC_PRINT_SYSTEM_SUMMARY == DefaultId)
  127. {
  128. DefaultId = IDC_PRINT_ALL;
  129. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY_CLASSDEVICE);
  130. }
  131. }
  132. if (!(m_pPrintDialog->GetTypeEnableMask() & REPORT_TYPE_MASK_SUMMARY_CLASSDEVICE))
  133. {
  134. EnableWindow(GetDlgItem(hWnd, IDC_PRINT_ALL), FALSE);
  135. }
  136. CheckDlgButton(hWnd, DefaultId, BST_CHECKED);
  137. return TRUE;
  138. }
  139. UINT_PTR
  140. CDevMgrPrintDialogCallback::OnCommand(
  141. HWND hWnd,
  142. WPARAM wParam,
  143. LPARAM lParam
  144. )
  145. {
  146. UNREFERENCED_PARAMETER(wParam);
  147. UNREFERENCED_PARAMETER(lParam);
  148. if (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_PRINT_SELECT_CLASSDEVICE))
  149. {
  150. m_pPrintDialog->SetReportType(REPORT_TYPE_CLASSDEVICE);
  151. }
  152. else if (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_PRINT_SYSTEM_SUMMARY))
  153. {
  154. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY);
  155. }
  156. else if (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_PRINT_ALL))
  157. {
  158. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY_CLASSDEVICE);
  159. }
  160. return FALSE;
  161. }
  162. BOOL
  163. CDevMgrPrintDialogCallback::OnHelp(
  164. LPHELPINFO pHelpInfo
  165. )
  166. {
  167. int id = GetDlgCtrlID((HWND)pHelpInfo->hItemHandle);
  168. //
  169. // We only want to intercept help messages for controls that we are
  170. // responsible for.
  171. //
  172. if ((IDC_PRINT_SYSTEM_SUMMARY == id) ||
  173. (IDC_PRINT_SELECT_CLASSDEVICE == id) ||
  174. (IDC_PRINT_ALL == id) ||
  175. (IDC_PRINT_REPORT_TYPE_TEXT == id)) {
  176. WinHelp((HWND)pHelpInfo->hItemHandle, DEVMGR_HELP_FILE_NAME, HELP_WM_HELP,
  177. (ULONG_PTR)g_a207HelpIDs);
  178. return TRUE;
  179. }
  180. //
  181. // If it is not one of the above controls then just let the normal help handle
  182. // the message. We do this by returning FALSE
  183. //
  184. return FALSE;
  185. }
  186. BOOL
  187. CDevMgrPrintDialogCallback::OnContextMenu(
  188. HWND hWnd,
  189. WORD xPos,
  190. WORD yPos,
  191. WPARAM wParam
  192. )
  193. {
  194. POINT pt;
  195. UNREFERENCED_PARAMETER(xPos);
  196. UNREFERENCED_PARAMETER(yPos);
  197. if (hWnd == (HWND)wParam) {
  198. GetCursorPos(&pt);
  199. ScreenToClient(hWnd, &pt);
  200. wParam = (WPARAM)ChildWindowFromPoint(hWnd, pt);
  201. }
  202. int id = GetDlgCtrlID((HWND)wParam);
  203. //
  204. // We only want to intercept help messages for controls that we are
  205. // responsible for.
  206. //
  207. if ((IDC_PRINT_SYSTEM_SUMMARY == id) ||
  208. (IDC_PRINT_SELECT_CLASSDEVICE == id) ||
  209. (IDC_PRINT_ALL == id) ||
  210. (IDC_PRINT_REPORT_TYPE_TEXT == id)) {
  211. WinHelp((HWND)wParam, DEVMGR_HELP_FILE_NAME, HELP_CONTEXTMENU,
  212. (ULONG_PTR)g_a207HelpIDs);
  213. return TRUE;
  214. }
  215. return FALSE;
  216. }
  217. BOOL
  218. CPrintDialog::PrintDlg(
  219. HWND hwndOwner,
  220. DWORD TypeEnableMask
  221. )
  222. {
  223. ASSERT(REPORT_TYPE_MASK_NONE != TypeEnableMask);
  224. memset(&m_PrintDlg, 0, sizeof(m_PrintDlg));
  225. CDevMgrPrintDialogCallback* pPrintDialogCallback = new CDevMgrPrintDialogCallback;
  226. if (!pPrintDialogCallback) {
  227. return FALSE;
  228. }
  229. pPrintDialogCallback->m_pPrintDialog = this;
  230. m_TypeEnableMask = TypeEnableMask;
  231. m_PrintDlg.lStructSize = sizeof(m_PrintDlg);
  232. m_PrintDlg.hwndOwner = hwndOwner;
  233. m_PrintDlg.hDC = NULL;
  234. m_PrintDlg.Flags = PD_ENABLEPRINTTEMPLATE | PD_RETURNDC | PD_NOPAGENUMS;
  235. m_PrintDlg.Flags2 = 0;
  236. m_PrintDlg.ExclusionFlags = 0;
  237. m_PrintDlg.hInstance = g_hInstance;
  238. m_PrintDlg.nCopies = 1;
  239. m_PrintDlg.nStartPage = START_PAGE_GENERAL;
  240. m_PrintDlg.lpCallback = (IUnknown*)pPrintDialogCallback;
  241. m_PrintDlg.lpPrintTemplateName = MAKEINTRESOURCE(IDD_PRINT);
  242. if (FAILED(PrintDlgEx(&m_PrintDlg))) {
  243. return FALSE;
  244. }
  245. //
  246. // If the user did not want to print then return FALSE.
  247. // This can happen if the user hits Cancel on the print dialog.
  248. //
  249. if (m_PrintDlg.dwResultAction != PD_RESULT_PRINT) {
  250. return FALSE;
  251. }
  252. return TRUE;
  253. }