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.

333 lines
6.5 KiB

  1. #include "devmgr.h"
  2. /*++
  3. Copyright (C) 1997-1999 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 = (ISnapinAbout*)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. ::InterlockedIncrement((LONG*)&m_Ref);
  60. return m_Ref;
  61. }
  62. ULONG
  63. CDevMgrPrintDialogCallback::Release()
  64. {
  65. ::InterlockedDecrement((LONG*)&m_Ref);
  66. if (!m_Ref)
  67. {
  68. delete this;
  69. return 0;
  70. }
  71. return m_Ref;
  72. }
  73. HRESULT
  74. CDevMgrPrintDialogCallback::InitDone()
  75. {
  76. return S_OK;
  77. }
  78. HRESULT
  79. CDevMgrPrintDialogCallback::SelectionChange()
  80. {
  81. return S_OK;
  82. }
  83. HRESULT
  84. CDevMgrPrintDialogCallback::HandleMessage(
  85. HWND hDlg,
  86. UINT uMsg,
  87. WPARAM wParam,
  88. LPARAM lParam,
  89. LRESULT *pResult
  90. )
  91. {
  92. *pResult = FALSE;
  93. switch (uMsg) {
  94. case WM_INITDIALOG:
  95. *pResult = OnInitDialog(hDlg);
  96. break;
  97. case WM_COMMAND:
  98. *pResult = OnCommand(hDlg, wParam, lParam);
  99. break;
  100. case WM_HELP:
  101. *pResult = OnHelp((LPHELPINFO)lParam);
  102. break;
  103. case WM_CONTEXTMENU:
  104. *pResult = OnContextMenu(hDlg, LOWORD(lParam), HIWORD(lParam), wParam);
  105. break;
  106. default:
  107. break;
  108. }
  109. return S_OK;
  110. }
  111. BOOL
  112. CDevMgrPrintDialogCallback::OnInitDialog(
  113. HWND hWnd
  114. )
  115. {
  116. int DefaultId = IDC_PRINT_SELECT_CLASSDEVICE;
  117. m_pPrintDialog->SetReportType(REPORT_TYPE_CLASSDEVICE);
  118. if (!(m_pPrintDialog->GetTypeEnableMask() & REPORT_TYPE_MASK_CLASSDEVICE))
  119. {
  120. EnableWindow(GetDlgItem(hWnd, IDC_PRINT_SELECT_CLASSDEVICE), FALSE);
  121. DefaultId = IDC_PRINT_SYSTEM_SUMMARY;
  122. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY);
  123. }
  124. if (!(m_pPrintDialog->GetTypeEnableMask() & REPORT_TYPE_MASK_SUMMARY))
  125. {
  126. EnableWindow(GetDlgItem(hWnd, IDC_PRINT_SYSTEM_SUMMARY), FALSE);
  127. if (IDC_PRINT_SYSTEM_SUMMARY == DefaultId)
  128. {
  129. DefaultId = IDC_PRINT_ALL;
  130. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY_CLASSDEVICE);
  131. }
  132. }
  133. if (!(m_pPrintDialog->GetTypeEnableMask() & REPORT_TYPE_MASK_SUMMARY_CLASSDEVICE))
  134. {
  135. EnableWindow(GetDlgItem(hWnd, IDC_PRINT_ALL), FALSE);
  136. }
  137. CheckDlgButton(hWnd, DefaultId, BST_CHECKED);
  138. return TRUE;
  139. }
  140. UINT_PTR
  141. CDevMgrPrintDialogCallback::OnCommand(
  142. HWND hWnd,
  143. WPARAM wParam,
  144. LPARAM lParam
  145. )
  146. {
  147. if (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_PRINT_SELECT_CLASSDEVICE))
  148. {
  149. m_pPrintDialog->SetReportType(REPORT_TYPE_CLASSDEVICE);
  150. }
  151. else if (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_PRINT_SYSTEM_SUMMARY))
  152. {
  153. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY);
  154. }
  155. else if (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_PRINT_ALL))
  156. {
  157. m_pPrintDialog->SetReportType(REPORT_TYPE_SUMMARY_CLASSDEVICE);
  158. }
  159. return FALSE;
  160. }
  161. BOOL
  162. CDevMgrPrintDialogCallback::OnHelp(
  163. LPHELPINFO pHelpInfo
  164. )
  165. {
  166. int id = GetDlgCtrlID((HWND)pHelpInfo->hItemHandle);
  167. //
  168. // We only want to intercept help messages for controls that we are
  169. // responsible for.
  170. //
  171. if ((IDC_PRINT_SYSTEM_SUMMARY == id) ||
  172. (IDC_PRINT_SELECT_CLASSDEVICE == id) ||
  173. (IDC_PRINT_ALL == id) ||
  174. (IDC_PRINT_REPORT_TYPE_TEXT == id)) {
  175. WinHelp((HWND)pHelpInfo->hItemHandle, DEVMGR_HELP_FILE_NAME, HELP_WM_HELP,
  176. (ULONG_PTR)g_a207HelpIDs);
  177. return TRUE;
  178. }
  179. //
  180. // If it is not one of the above controls then just let the normal help handle
  181. // the message. We do this by returning FALSE
  182. //
  183. return FALSE;
  184. }
  185. BOOL
  186. CDevMgrPrintDialogCallback::OnContextMenu(
  187. HWND hWnd,
  188. WORD xPos,
  189. WORD yPos,
  190. WPARAM wParam
  191. )
  192. {
  193. POINT pt;
  194. if (hWnd == (HWND)wParam) {
  195. GetCursorPos(&pt);
  196. ScreenToClient(hWnd, &pt);
  197. wParam = (WPARAM)ChildWindowFromPoint(hWnd, pt);
  198. }
  199. int id = GetDlgCtrlID((HWND)wParam);
  200. //
  201. // We only want to intercept help messages for controls that we are
  202. // responsible for.
  203. //
  204. if ((IDC_PRINT_SYSTEM_SUMMARY == id) ||
  205. (IDC_PRINT_SELECT_CLASSDEVICE == id) ||
  206. (IDC_PRINT_ALL == id) ||
  207. (IDC_PRINT_REPORT_TYPE_TEXT == id)) {
  208. WinHelp((HWND)wParam, DEVMGR_HELP_FILE_NAME, HELP_CONTEXTMENU,
  209. (ULONG_PTR)g_a207HelpIDs);
  210. return TRUE;
  211. }
  212. return FALSE;
  213. }
  214. BOOL
  215. CPrintDialog::PrintDlg(
  216. HWND hwndOwner,
  217. DWORD TypeEnableMask
  218. )
  219. {
  220. HRESULT hr;
  221. ASSERT(REPORT_TYPE_MASK_NONE != TypeEnableMask);
  222. memset(&m_PrintDlg, 0, sizeof(m_PrintDlg));
  223. CDevMgrPrintDialogCallback* pPrintDialogCallback = new CDevMgrPrintDialogCallback;
  224. if (!pPrintDialogCallback) {
  225. return FALSE;
  226. }
  227. pPrintDialogCallback->m_pPrintDialog = this;
  228. m_TypeEnableMask = TypeEnableMask;
  229. m_PrintDlg.lStructSize = sizeof(m_PrintDlg);
  230. m_PrintDlg.hwndOwner = hwndOwner;
  231. m_PrintDlg.hDC = NULL;
  232. m_PrintDlg.Flags = PD_ENABLEPRINTTEMPLATE | PD_RETURNDC | PD_NOPAGENUMS;
  233. m_PrintDlg.Flags2 = 0;
  234. m_PrintDlg.ExclusionFlags = 0;
  235. m_PrintDlg.hInstance = g_hInstance;
  236. m_PrintDlg.nCopies = 1;
  237. m_PrintDlg.nStartPage = START_PAGE_GENERAL;
  238. m_PrintDlg.lpCallback = (IUnknown*)pPrintDialogCallback;
  239. m_PrintDlg.lpPrintTemplateName = MAKEINTRESOURCE(IDD_PRINT);
  240. if (FAILED(hr = PrintDlgEx(&m_PrintDlg))) {
  241. return FALSE;
  242. }
  243. //
  244. // If the user did not want to print then return FALSE.
  245. // This can happen if the user hits Cancel on the print dialog.
  246. //
  247. if (m_PrintDlg.dwResultAction != PD_RESULT_PRINT) {
  248. return FALSE;
  249. }
  250. return TRUE;
  251. }