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.

284 lines
6.2 KiB

  1. // ItemPropSheet.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #define __FILE_ID__ 42
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CItemPropSheet
  12. IMPLEMENT_DYNAMIC(CItemPropSheet, CPropertySheet)
  13. CItemPropSheet::CItemPropSheet(
  14. UINT nIDCaption, // sheet caption id
  15. CWnd* pParentWnd, // parent window
  16. UINT iSelectPage // initialy selected page
  17. ):
  18. CPropertySheet(nIDCaption, pParentWnd, iSelectPage),
  19. m_dwLastError(ERROR_SUCCESS),
  20. m_pMsg(NULL)
  21. {
  22. //
  23. // no Help button
  24. //
  25. m_psh.dwFlags &= ~PSH_HASHELP;
  26. //
  27. // no Apply button
  28. //
  29. m_psh.dwFlags |= PSH_NOAPPLYNOW;
  30. }
  31. DWORD
  32. CItemPropSheet::Init(
  33. CFolder* pFolder, // folder
  34. CFaxMsg* pMsg // pointer to CJob or CArchiveMsg
  35. )
  36. {
  37. m_dwLastError = ERROR_SUCCESS;
  38. DBG_ENTER(TEXT("CItemPropSheet::Init"), m_dwLastError);
  39. ASSERTION(pFolder);
  40. ASSERTION(pMsg);
  41. //
  42. // init page array
  43. //
  44. for(DWORD dw=0; dw < PROP_SHEET_PAGES_NUM; ++dw)
  45. {
  46. m_pPages[dw] = NULL;
  47. }
  48. //
  49. // create pages according to FolderType
  50. //
  51. FolderType type = pFolder->Type();
  52. BOOL bCreatePersonalInfo = TRUE;
  53. if(pMsg->IsKindOf(RUNTIME_CLASS(CArchiveMsg)))
  54. {
  55. try
  56. {
  57. m_pMsg = new CArchiveMsg;
  58. }
  59. catch(...)
  60. {
  61. m_dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  62. CALL_FAIL (MEM_ERR, TEXT ("new CArchiveMsg"), m_dwLastError);
  63. goto exit;
  64. }
  65. m_dwLastError = ((CArchiveMsg*)m_pMsg)->Copy(*((CArchiveMsg*)pMsg));
  66. if(ERROR_SUCCESS != m_dwLastError)
  67. {
  68. return m_dwLastError;
  69. }
  70. }
  71. else if(pMsg->IsKindOf(RUNTIME_CLASS(CJob)))
  72. {
  73. try
  74. {
  75. m_pMsg = new CJob;
  76. }
  77. catch(...)
  78. {
  79. m_dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  80. CALL_FAIL (MEM_ERR, TEXT ("new CJob"), m_dwLastError);
  81. goto exit;
  82. }
  83. m_dwLastError = ((CJob*)m_pMsg)->Copy(*((CJob*)pMsg));
  84. if(ERROR_SUCCESS != m_dwLastError)
  85. {
  86. return m_dwLastError;
  87. }
  88. }
  89. else
  90. {
  91. ASSERTION_FAILURE
  92. }
  93. try
  94. {
  95. switch(type)
  96. {
  97. case FOLDER_TYPE_INCOMING:
  98. bCreatePersonalInfo = FALSE;
  99. m_pPages[0] = new CIncomingGeneralPg(m_pMsg);
  100. m_pPages[1] = new CIncomingDetailsPg(m_pMsg);
  101. break;
  102. case FOLDER_TYPE_INBOX:
  103. bCreatePersonalInfo = FALSE;
  104. m_pPages[0] = new CInboxGeneralPg(m_pMsg);
  105. m_pPages[1] = new CInboxDetailsPg(m_pMsg);
  106. break;
  107. case FOLDER_TYPE_OUTBOX:
  108. m_pPages[0] = new COutboxGeneralPg(m_pMsg);
  109. m_pPages[1] = new COutboxDetailsPg(m_pMsg);
  110. break;
  111. case FOLDER_TYPE_SENT_ITEMS:
  112. m_pPages[0] = new CSentItemsGeneralPg(m_pMsg);
  113. m_pPages[1] = new CSentItemsDetailsPg(m_pMsg);
  114. break;
  115. default:
  116. ASSERTION_FAILURE;
  117. break;
  118. };
  119. if(bCreatePersonalInfo)
  120. {
  121. //
  122. // create sender info page
  123. //
  124. m_pPages[2] = new CPersonalInfoPg(IDS_SENDER_INFO_CAPTION,
  125. PERSON_SENDER,
  126. m_pMsg,
  127. pFolder);
  128. m_dwLastError = ((CPersonalInfoPg*)m_pPages[2])->Init();
  129. if(ERROR_SUCCESS != m_dwLastError)
  130. {
  131. CALL_FAIL (GENERAL_ERR, TEXT ("CPersonalInfoPg::Init"), m_dwLastError);
  132. }
  133. }
  134. }
  135. catch(...)
  136. {
  137. m_dwLastError = ERROR_NOT_ENOUGH_MEMORY;
  138. CALL_FAIL (MEM_ERR, TEXT ("new CPropertyPage"), m_dwLastError);
  139. goto exit;
  140. }
  141. //
  142. // add pages to sheet
  143. //
  144. for(dw=0; dw < PROP_SHEET_PAGES_NUM; ++dw)
  145. {
  146. if(NULL != m_pPages[dw])
  147. {
  148. AddPage(m_pPages[dw]);
  149. }
  150. }
  151. exit:
  152. if(ERROR_SUCCESS != m_dwLastError)
  153. {
  154. for(DWORD dw=0; dw < PROP_SHEET_PAGES_NUM; ++dw)
  155. {
  156. SAFE_DELETE(m_pPages[dw]);
  157. }
  158. }
  159. return m_dwLastError;
  160. }
  161. CItemPropSheet::~CItemPropSheet()
  162. {
  163. for(DWORD dw=0; dw < PROP_SHEET_PAGES_NUM; ++dw)
  164. {
  165. SAFE_DELETE(m_pPages[dw]);
  166. }
  167. SAFE_DELETE(m_pMsg);
  168. }
  169. BEGIN_MESSAGE_MAP(CItemPropSheet, CPropertySheet)
  170. //{{AFX_MSG_MAP(CItemPropSheet)
  171. ON_WM_ACTIVATE()
  172. ON_MESSAGE(WM_SET_SHEET_FOCUS, OnSetSheetFocus)
  173. ON_WM_CREATE()
  174. ON_MESSAGE(WM_HELP, OnHelp)
  175. //}}AFX_MSG_MAP
  176. END_MESSAGE_MAP()
  177. /////////////////////////////////////////////////////////////////////////////
  178. // CItemPropSheet message handlers
  179. void
  180. CItemPropSheet::OnActivate(
  181. UINT nState,
  182. CWnd* pWndOther,
  183. BOOL bMinimized
  184. )
  185. {
  186. DBG_ENTER(TEXT("CItemPropSheet::OnActivate"));
  187. CPropertySheet::OnActivate(nState, pWndOther, bMinimized);
  188. //
  189. // hide OK button
  190. //
  191. CWnd *pWnd = GetDlgItem( IDOK );
  192. ASSERTION(NULL != pWnd);
  193. pWnd->ShowWindow( FALSE );
  194. //
  195. // rename Cancel button
  196. //
  197. CString cstrText;
  198. DWORD dwRes = LoadResourceString (cstrText, IDS_BUTTON_CLOSE);
  199. if (ERROR_SUCCESS != dwRes)
  200. {
  201. CALL_FAIL (RESOURCE_ERR, TEXT("LoadResourceString"), dwRes);
  202. return;
  203. }
  204. pWnd = GetDlgItem( IDCANCEL );
  205. ASSERT(NULL != pWnd);
  206. pWnd->SetWindowText(cstrText);
  207. }
  208. LONG
  209. CItemPropSheet::OnSetSheetFocus(
  210. UINT wParam,
  211. LONG lParam
  212. )
  213. {
  214. //
  215. // set focus on Close button
  216. //
  217. CWnd *pWnd = GetDlgItem( IDCANCEL );
  218. ASSERT(NULL != pWnd);
  219. pWnd->SetFocus();
  220. return 0;
  221. }
  222. int
  223. CItemPropSheet::OnCreate(
  224. LPCREATESTRUCT lpCreateStruct
  225. )
  226. {
  227. if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
  228. return -1;
  229. ModifyStyleEx(0, WS_EX_CONTEXTHELP);
  230. return 0;
  231. }
  232. LONG
  233. CItemPropSheet::OnHelp(
  234. UINT wParam,
  235. LONG lParam
  236. )
  237. {
  238. return TRUE;
  239. }