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.

216 lines
6.6 KiB

  1. // Copyright (C) 1992-1999 Microsoft Corporation
  2. //
  3. // This file is a snapshot of the version in MFC. It contains fixes for dialog
  4. // initialization that are not yet in the main version.
  5. #include <afx.h>
  6. #include <afxwin.h>
  7. #include <afxdisp.h>
  8. #include <afxole.h>
  9. #include <afxpriv.h>
  10. #include "afxprntx.h"
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. #define new DEBUG_NEW
  16. INT_PTR CALLBACK AfxDlgProc(HWND, UINT, WPARAM, LPARAM);
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Private class to support new NT5 printing user interface
  19. //
  20. // IPrintDialogCallback interface id used by PrintDlgEx.
  21. //
  22. // {5852A2C3-6530-11D1-B6A3-0000F8757BF9}
  23. //
  24. extern "C" const __declspec(selectany) IID IID_IPrintDialogCallback =
  25. {0x5852a2c3, 0x6530, 0x11d1, {0xb6, 0xa3, 0x0, 0x0, 0xf8, 0x75, 0x7b, 0xf9}};
  26. BEGIN_INTERFACE_MAP(C_PrintDialogEx, CPrintDialog)
  27. INTERFACE_PART(C_PrintDialogEx, IID_IPrintDialogCallback, PrintDialogCallback)
  28. END_INTERFACE_MAP()
  29. C_PrintDialogEx::C_PrintDialogEx(BOOL bPrintSetupOnly,
  30. DWORD dwFlags, CWnd* pParentWnd)
  31. : CPrintDialog(bPrintSetupOnly, dwFlags, pParentWnd)
  32. {
  33. memset(&m_pdex, 0, sizeof(m_pdex));
  34. m_pdex.lStructSize = sizeof(m_pdex);
  35. m_pdex.Flags = dwFlags;
  36. }
  37. INT_PTR C_PrintDialogEx::DoModal()
  38. {
  39. ASSERT_VALID(this);
  40. m_pd.hwndOwner = PreModal();
  41. AfxUnhookWindowCreate();
  42. // expand m_pd data into the PRINTDLGEX structure
  43. m_pdex.hwndOwner = m_pd.hwndOwner;
  44. m_pdex.hDevMode = m_pd.hDevMode;
  45. m_pdex.hDevNames = m_pd.hDevNames;
  46. m_pdex.hDC = m_pd.hDC;
  47. // m_pdex.Flags = (m_pd.Flags & ~(PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP));
  48. m_pdex.nMinPage = m_pd.nMinPage;
  49. m_pdex.nMaxPage = m_pd.nMaxPage;
  50. m_pdex.hInstance = m_pd.hInstance;
  51. m_pdex.nStartPage = START_PAGE_GENERAL;
  52. m_pdex.nCopies = m_pd.nCopies;
  53. m_pdex.lpCallback = &m_xPrintDialogCallback;
  54. // initialize page ranges
  55. PRINTPAGERANGE ourPageRange;
  56. if (m_pdex.Flags & PD_NOPAGENUMS)
  57. {
  58. m_pdex.lpPageRanges = NULL;
  59. m_pdex.nPageRanges = 0;
  60. m_pdex.nMaxPageRanges = 0;
  61. }
  62. else
  63. {
  64. ourPageRange.nFromPage = m_pd.nFromPage;
  65. ourPageRange.nToPage = m_pd.nToPage;
  66. m_pdex.nPageRanges = 1;
  67. m_pdex.nMaxPageRanges = 1;
  68. m_pdex.lpPageRanges = &ourPageRange;
  69. }
  70. HMODULE hCommDlg = GetModuleHandleA("COMDLG32.DLL");
  71. HRESULT (STDAPICALLTYPE* pfn)(LPPRINTDLGEX);
  72. #ifdef UNICODE
  73. pfn = (HRESULT (STDAPICALLTYPE*)(LPPRINTDLGEX))
  74. GetProcAddress(hCommDlg, "PrintDlgExW");
  75. #else
  76. pfn = (HRESULT (STDAPICALLTYPE*)(LPPRINTDLGEX))
  77. GetProcAddress(hCommDlg, "PrintDlgExA");
  78. #endif
  79. HRESULT hResult = E_NOTIMPL;
  80. if (pfn != NULL)
  81. {
  82. _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  83. ASSERT(pThreadState->m_pAlternateWndInit == NULL);
  84. // pThreadState->m_pAlternateWndInit = this;
  85. hResult = pfn(&m_pdex);
  86. if (SUCCEEDED(hResult))
  87. ASSERT(pThreadState->m_pAlternateWndInit == NULL);
  88. pThreadState->m_pAlternateWndInit = NULL;
  89. }
  90. // pull data back...
  91. PostModal();
  92. if (!(m_pdex.Flags & PD_NOPAGENUMS))
  93. {
  94. m_pd.nToPage = (WORD) m_pdex.lpPageRanges->nToPage;
  95. m_pd.nFromPage = (WORD) m_pdex.lpPageRanges->nFromPage;
  96. m_pd.nMinPage = (WORD) m_pdex.nMinPage;
  97. m_pd.nMaxPage = (WORD) m_pdex.nMaxPage;
  98. }
  99. m_pd.hDevMode = m_pdex.hDevMode;
  100. m_pd.hDevNames = m_pdex.hDevNames;
  101. m_pd.hDC = m_pdex.hDC;
  102. m_pd.nCopies = (WORD)m_pdex.nCopies;
  103. // calculate return code
  104. int nResult = IDCANCEL;
  105. if (SUCCEEDED(hResult))
  106. {
  107. if (m_pdex.dwResultAction == PD_RESULT_PRINT)
  108. nResult = IDOK;
  109. }
  110. return nResult;
  111. }
  112. STDMETHODIMP_(ULONG) C_PrintDialogEx::XPrintDialogCallback::AddRef()
  113. {
  114. METHOD_PROLOGUE_EX_(C_PrintDialogEx, PrintDialogCallback)
  115. return (ULONG)pThis->ExternalAddRef();
  116. }
  117. STDMETHODIMP_(ULONG) C_PrintDialogEx::XPrintDialogCallback::Release()
  118. {
  119. METHOD_PROLOGUE_EX_(C_PrintDialogEx, PrintDialogCallback)
  120. return (ULONG)pThis->ExternalRelease();
  121. }
  122. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::QueryInterface(
  123. REFIID iid, LPVOID* ppvObj)
  124. {
  125. METHOD_PROLOGUE_EX_(C_PrintDialogEx, PrintDialogCallback)
  126. return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
  127. }
  128. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::InitDone()
  129. {
  130. METHOD_PROLOGUE_EX(C_PrintDialogEx, PrintDialogCallback)
  131. return pThis->OnInitDone();
  132. }
  133. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::SelectionChange()
  134. {
  135. METHOD_PROLOGUE_EX(C_PrintDialogEx, PrintDialogCallback)
  136. return pThis->OnSelectionChange();
  137. }
  138. STDMETHODIMP C_PrintDialogEx::XPrintDialogCallback::HandleMessage(HWND hDlg,
  139. UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  140. {
  141. METHOD_PROLOGUE_EX(C_PrintDialogEx, PrintDialogCallback)
  142. return pThis->OnHandleMessage(hDlg, uMsg, wParam, lParam, pResult);
  143. }
  144. HRESULT C_PrintDialogEx::OnInitDone()
  145. {
  146. return S_FALSE;
  147. }
  148. HRESULT C_PrintDialogEx::OnSelectionChange()
  149. {
  150. return S_FALSE;
  151. }
  152. HRESULT C_PrintDialogEx::OnHandleMessage(HWND hDlg, UINT uMsg,
  153. WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  154. {
  155. // UNUSED_ALWAYS(hDlg);
  156. HRESULT hResult = S_FALSE;
  157. /*
  158. _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  159. if (pThreadState->m_pAlternateWndInit != NULL)
  160. {
  161. ASSERT_KINDOF(C_PrintDialogEx, pThreadState->m_pAlternateWndInit);
  162. pThreadState->m_pAlternateWndInit->SubclassWindow(hDlg);
  163. pThreadState->m_pAlternateWndInit = NULL;
  164. }
  165. ASSERT(pThreadState->m_pAlternateWndInit == NULL);
  166. */
  167. if (uMsg == WM_INITDIALOG)
  168. {
  169. SubclassWindow(hDlg);
  170. *pResult = AfxDlgProc(hDlg, uMsg, wParam, lParam);
  171. hResult = S_FALSE;
  172. }
  173. return hResult;
  174. }
  175. IMPLEMENT_DYNAMIC(C_PrintDialogEx, CPrintDialog)