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.

641 lines
18 KiB

  1. /*
  2. * frntpage.cpp
  3. *
  4. * Purpose:
  5. * Implements the Front Page IAthenaView object
  6. *
  7. * Owner:
  8. * EricAn
  9. *
  10. * Copyright (C) Microsoft Corp. 1997
  11. */
  12. #include "pch.hxx"
  13. #include "frntpage.h"
  14. #include "resource.h"
  15. #include "ourguid.h"
  16. #include "thormsgs.h"
  17. #include "goptions.h"
  18. #include "strconst.h"
  19. #include "frntbody.h"
  20. #include "acctutil.h"
  21. #include "newfldr.h"
  22. #include <wininet.h>
  23. #include <options.h>
  24. #include <layout.h>
  25. #include "finder.h"
  26. #include <inetcfg.h>
  27. #include "instance.h"
  28. #include "storutil.h"
  29. #include "menuutil.h"
  30. #include "menures.h"
  31. #include "statbar.h"
  32. ASSERTDATA
  33. /////////////////////////////////////////////////////////////////////////////
  34. //
  35. // Macros
  36. //
  37. #define FPDOUT(x) DOUTL(DOUT_LEVEL4, x)
  38. /////////////////////////////////////////////////////////////////////////////
  39. //
  40. // Global Data
  41. //
  42. static const TCHAR s_szFrontPageWndClass[] = TEXT("ThorFrontPageWndClass");
  43. /////////////////////////////////////////////////////////////////////////////
  44. //
  45. // Prototypes
  46. //
  47. /////////////////////////////////////////////////////////////////////////
  48. //
  49. // Constructors, Destructors, and Initialization
  50. //
  51. CFrontPage::CFrontPage()
  52. {
  53. m_cRef = 1;
  54. m_idFolder = FOLDERID_INVALID;
  55. m_pShellBrowser = NULL;
  56. m_fFirstActive = FALSE;
  57. m_uActivation = SVUIA_DEACTIVATE;
  58. m_hwndOwner = NULL;
  59. m_hwnd = NULL;
  60. m_hwndCtlFocus = NULL;
  61. m_pBodyObj = NULL;
  62. m_pBodyObjCT = NULL;
  63. #ifndef WIN16 // No RAS support in Win16
  64. m_hMenuConnect = 0;
  65. #endif
  66. m_pStatusBar = NULL;
  67. }
  68. CFrontPage::~CFrontPage()
  69. {
  70. SafeRelease(m_pShellBrowser);
  71. SafeRelease(m_pBodyObj);
  72. SafeRelease(m_pBodyObjCT);
  73. SafeRelease(m_pStatusBar);
  74. #ifndef WIN16 // No RAS support in Win16
  75. if (m_hMenuConnect)
  76. g_pConMan->FreeConnectMenu(m_hMenuConnect);
  77. #endif
  78. }
  79. HRESULT CFrontPage::HrInit(FOLDERID idFolder)
  80. {
  81. WNDCLASS wc;
  82. if (!GetClassInfo(g_hInst, s_szFrontPageWndClass, &wc))
  83. {
  84. wc.style = 0;
  85. wc.lpfnWndProc = CFrontPage::FrontPageWndProc;
  86. wc.cbClsExtra = 0;
  87. wc.cbWndExtra = 0;
  88. wc.hInstance = g_hInst;
  89. wc.hIcon = NULL;
  90. wc.hCursor = NULL;
  91. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  92. wc.lpszMenuName = NULL;
  93. wc.lpszClassName = s_szFrontPageWndClass;
  94. if (RegisterClass(&wc) == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
  95. return E_FAIL;
  96. }
  97. // Make copies of our pidls
  98. m_idFolder = idFolder;
  99. m_ftType = GetFolderType(m_idFolder);
  100. return NOERROR;
  101. }
  102. /////////////////////////////////////////////////////////////////////////
  103. //
  104. // OLE Interfaces
  105. //
  106. ////////////////////////////////////////////////////////////////////////
  107. //
  108. // IUnknown
  109. //
  110. ////////////////////////////////////////////////////////////////////////
  111. HRESULT STDMETHODCALLTYPE CFrontPage::QueryInterface(REFIID riid, void **ppvObj)
  112. {
  113. if (IsEqualIID(riid, IID_IUnknown))
  114. *ppvObj = (void*) (IUnknown *)(IViewWindow *) this;
  115. else if (IsEqualIID(riid, IID_IViewWindow))
  116. *ppvObj = (void*) (IViewWindow *) this;
  117. else if (IsEqualIID(riid, IID_IOleCommandTarget))
  118. *ppvObj = (void*) (IOleCommandTarget *) this;
  119. else
  120. {
  121. *ppvObj = NULL;
  122. return E_NOINTERFACE;
  123. }
  124. AddRef();
  125. return NOERROR;
  126. }
  127. ULONG STDMETHODCALLTYPE CFrontPage::AddRef()
  128. {
  129. DOUT(TEXT("CFrontPage::AddRef() - m_cRef = %d"), m_cRef + 1);
  130. return ++m_cRef;
  131. }
  132. ULONG STDMETHODCALLTYPE CFrontPage::Release()
  133. {
  134. DOUT(TEXT("CFrontPage::Release() - m_cRef = %d"), m_cRef - 1);
  135. if (--m_cRef == 0)
  136. {
  137. delete this;
  138. return 0;
  139. }
  140. return m_cRef;
  141. }
  142. ////////////////////////////////////////////////////////////////////////
  143. //
  144. // IOleWindow
  145. //
  146. ////////////////////////////////////////////////////////////////////////
  147. HRESULT STDMETHODCALLTYPE CFrontPage::GetWindow(HWND * lphwnd)
  148. {
  149. *lphwnd = m_hwnd;
  150. return (m_hwnd ? S_OK : E_FAIL);
  151. }
  152. HRESULT STDMETHODCALLTYPE CFrontPage::ContextSensitiveHelp(BOOL fEnterMode)
  153. {
  154. return E_NOTIMPL;
  155. }
  156. ////////////////////////////////////////////////////////////////////////
  157. //
  158. // IAthenaView
  159. //
  160. ////////////////////////////////////////////////////////////////////////
  161. HRESULT STDMETHODCALLTYPE CFrontPage::TranslateAccelerator(LPMSG lpmsg)
  162. {
  163. // see if the body obj wants to snag it.
  164. if (m_pBodyObj && m_pBodyObj->HrTranslateAccelerator(lpmsg) == S_OK)
  165. return S_OK;
  166. return E_NOTIMPL;
  167. }
  168. HRESULT STDMETHODCALLTYPE CFrontPage::UIActivate(UINT uActivation)
  169. {
  170. if (uActivation != SVUIA_DEACTIVATE)
  171. OnActivate(uActivation);
  172. else
  173. OnDeactivate();
  174. return NOERROR;
  175. }
  176. HRESULT STDMETHODCALLTYPE CFrontPage::CreateViewWindow(IViewWindow *lpPrevView, IAthenaBrowser *psb,
  177. RECT *prcView, HWND *phWnd)
  178. {
  179. m_pShellBrowser = psb;
  180. Assert(m_pShellBrowser);
  181. m_pShellBrowser->AddRef();
  182. m_pShellBrowser->GetWindow(&m_hwndOwner);
  183. Assert(IsWindow(m_hwndOwner));
  184. // Load our registry settings
  185. LoadBaseSettings();
  186. m_hwnd = CreateWindowEx(WS_EX_CONTROLPARENT|WS_EX_CLIENTEDGE,
  187. s_szFrontPageWndClass,
  188. NULL,
  189. WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
  190. prcView->left,
  191. prcView->top,
  192. prcView->right - prcView->left,
  193. prcView->bottom - prcView->top,
  194. m_hwndOwner,
  195. NULL,
  196. g_hInst,
  197. (LPVOID)this);
  198. if (!m_hwnd)
  199. return E_FAIL;
  200. *phWnd = m_hwnd;
  201. return NOERROR;
  202. }
  203. HRESULT STDMETHODCALLTYPE CFrontPage::DestroyViewWindow()
  204. {
  205. if (m_hwnd)
  206. {
  207. HWND hwndDest = m_hwnd;
  208. m_hwnd = NULL;
  209. DestroyWindow(hwndDest);
  210. }
  211. return NOERROR;
  212. }
  213. HRESULT STDMETHODCALLTYPE CFrontPage::SaveViewState()
  214. {
  215. // Save our registry settings
  216. SaveBaseSettings();
  217. return NOERROR;
  218. }
  219. //
  220. // FUNCTION: CFrontPage::OnInitMenuPopup
  221. //
  222. // PURPOSE: Called when the user is about to display a menu. We use this
  223. // to update the enabled or disabled status of many of the
  224. // commands on each menu.
  225. //
  226. // PARAMETERS:
  227. // hmenu - Handle of the main menu.
  228. // hmenuPopup - Handle of the popup menu being displayed.
  229. // uID - Specifies the id of the menu item that
  230. // invoked the popup.
  231. //
  232. // RETURN VALUE:
  233. // Returns S_OK if we process the message.
  234. //
  235. //
  236. #define MF_ENABLEFLAGS(b) (MF_BYCOMMAND|(b ? MF_ENABLED : MF_GRAYED|MF_DISABLED))
  237. #define MF_CHECKFLAGS(b) (MF_BYCOMMAND|(b ? MF_CHECKED : MF_UNCHECKED))
  238. HRESULT CFrontPage::OnPopupMenu(HMENU hmenu, HMENU hmenuPopup, UINT uID)
  239. {
  240. MENUITEMINFO mii;
  241. // give the docobj a chance to update its menu
  242. if (m_pBodyObj)
  243. m_pBodyObj->HrOnInitMenuPopup(hmenuPopup, uID);
  244. return S_OK;
  245. }
  246. HRESULT CFrontPage::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[],
  247. OLECMDTEXT *pCmdText)
  248. {
  249. // Let MimeEdit have a crack at them
  250. if (m_pBodyObjCT)
  251. {
  252. m_pBodyObjCT->QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
  253. }
  254. // handled
  255. return S_OK;
  256. }
  257. HRESULT CFrontPage::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt,
  258. VARIANTARG *pvaIn, VARIANTARG *pvaOut)
  259. {
  260. // make sure that the 'go to inbox' check is consistent with what is in the options dlg
  261. // but we'll still let the browser actually handle the command
  262. /*
  263. if (nCmdID == ID_OPTIONS)
  264. {
  265. if (m_ftType == FOLDER_ROOTNODE)
  266. {
  267. VARIANT_BOOL b;
  268. if (SUCCEEDED(m_pBodyObj->GetSetCheck(FALSE, &b)))
  269. SetDwOption(OPT_LAUNCH_INBOX, b ? TRUE : FALSE, m_hwnd, 0);
  270. }
  271. }
  272. */
  273. // check if the body wants to handle it
  274. if (m_pBodyObjCT && m_pBodyObjCT->Exec(pguidCmdGroup, nCmdID, nCmdExecOpt, pvaIn, pvaOut) == NOERROR)
  275. return S_OK;
  276. return E_FAIL;
  277. }
  278. HRESULT STDMETHODCALLTYPE CFrontPage::OnFrameWindowActivate(BOOL fActivate)
  279. {
  280. return m_pBodyObj ? m_pBodyObj->HrFrameActivate(fActivate) : S_OK;
  281. }
  282. HRESULT STDMETHODCALLTYPE CFrontPage::GetCurCharSet(UINT *cp)
  283. {
  284. *cp = GetACP();
  285. return (E_NOTIMPL);
  286. }
  287. HRESULT STDMETHODCALLTYPE CFrontPage::UpdateLayout(THIS_ BOOL fPreviewVisible,
  288. BOOL fPreviewHeader,
  289. BOOL fPreviewVert, BOOL fReload)
  290. {
  291. return (E_NOTIMPL);
  292. }
  293. ////////////////////////////////////////////////////////////////////////
  294. //
  295. // Message Handling
  296. //
  297. ////////////////////////////////////////////////////////////////////////
  298. LRESULT CALLBACK CFrontPage::FrontPageWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  299. {
  300. LRESULT lRet;
  301. CFrontPage *pThis;
  302. if (msg == WM_NCCREATE)
  303. {
  304. pThis = (CFrontPage*)((LPCREATESTRUCT)lParam)->lpCreateParams;
  305. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LPARAM)pThis);
  306. }
  307. else
  308. pThis = (CFrontPage*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  309. Assert(pThis);
  310. return pThis->WndProc(hwnd, msg, wParam, lParam);
  311. }
  312. LRESULT CFrontPage::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  313. {
  314. BOOL fTip;
  315. switch (msg)
  316. {
  317. HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
  318. HANDLE_MSG(hwnd, WM_SIZE, OnSize);
  319. HANDLE_MSG(hwnd, WM_NOTIFY, OnNotify);
  320. HANDLE_MSG(hwnd, WM_SETFOCUS, OnSetFocus);
  321. case WM_COMMAND:
  322. return SendMessage(m_hwndOwner, msg, wParam, lParam);
  323. case WM_MENUSELECT:
  324. HandleMenuSelect(m_pStatusBar, wParam, lParam);
  325. return 0;
  326. case NVM_INITHEADERS:
  327. PostCreate();
  328. return 0;
  329. /*
  330. case CM_OPTIONADVISE:
  331. if ((wParam == OPT_LAUNCH_INBOX || wParam == 0xffffffff) && m_ftType == FOLDER_ROOTNODE)
  332. {
  333. VARIANT_BOOL b = DwGetOption(OPT_LAUNCH_INBOX) ? VARIANT_TRUE : VARIANT_FALSE;
  334. m_pBodyObj->GetSetCheck(TRUE, &b);
  335. }
  336. case WM_UPDATELAYOUT:
  337. m_pShellBrowser->GetViewLayout(DISPID_MSGVIEW_TIPOFTHEDAY, 0, &fTip, 0, 0);
  338. m_pBodyObj->ShowTip(fTip);
  339. return 0;
  340. */
  341. case WM_ACTIVATE:
  342. {
  343. HWND hwndFocus;
  344. DOUT("CFrontPage - WM_ACTIVATE(%#x)", LOWORD(wParam));
  345. m_pShellBrowser->UpdateToolbar();
  346. if (LOWORD(wParam) != WA_INACTIVE)
  347. {
  348. // DefWindowProc will set the focus to our view window, which
  349. // is not what we want. Instead, we will let the explorer set
  350. // the focus to our view window if we should get it, at which
  351. // point we will set it to the proper control.
  352. return 0;
  353. }
  354. hwndFocus = GetFocus();
  355. if (IsChild(hwnd, hwndFocus))
  356. m_hwndCtlFocus = hwndFocus;
  357. else
  358. m_pBodyObj->HrGetWindow(&m_hwndCtlFocus);
  359. }
  360. break;
  361. case WM_CLOSE:
  362. // ignore CTRL-F4's
  363. return 0;
  364. case WM_DESTROY:
  365. OptionUnadvise(hwnd);
  366. SafeRelease(m_pStatusBar);
  367. if (m_pBodyObj)
  368. {
  369. m_pBodyObj->HrUnloadAll(NULL, 0);
  370. m_pBodyObj->HrClose();
  371. }
  372. return 0;
  373. #ifndef WIN16
  374. case WM_DISPLAYCHANGE:
  375. #endif
  376. case WM_WININICHANGE:
  377. case WM_SYSCOLORCHANGE:
  378. case WM_QUERYNEWPALETTE:
  379. case WM_PALETTECHANGED:
  380. if (m_pBodyObj)
  381. {
  382. HWND hwndBody;
  383. m_pBodyObj->HrGetWindow(&hwndBody);
  384. SendMessage(hwndBody, msg, wParam, lParam);
  385. }
  386. /* * * FALL THROUGH * * */
  387. case FTN_PRECHANGE:
  388. case FTN_POSTCHANGE:
  389. break;
  390. default:
  391. if (g_msgMSWheel && (msg == g_msgMSWheel))
  392. {
  393. HWND hwndFocus = GetFocus();
  394. if (IsChild(hwnd, hwndFocus))
  395. return SendMessage(hwndFocus, msg, wParam, lParam);
  396. }
  397. break;
  398. }
  399. return DefWindowProc(hwnd, msg, wParam, lParam);
  400. }
  401. //
  402. // FUNCTION: CFrontPage::OnCreate
  403. //
  404. // PURPOSE: Creates the child windows necessary for the view and
  405. // initializes the data in those child windows.
  406. //
  407. // PARAMETERS:
  408. // hwnd - Handle of the view being created.
  409. // lpCreateStruct - Pointer to the creation params passed to
  410. // CreateWindow().
  411. //
  412. // RETURN VALUE:
  413. // Returns TRUE if the initialization is successful.
  414. //
  415. BOOL CFrontPage::OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
  416. {
  417. // register for option update notification
  418. SideAssert(SUCCEEDED(OptionAdvise(hwnd)));
  419. m_pBodyObj = new CFrontBody(m_ftType, m_pShellBrowser);
  420. if (!m_pBodyObj)
  421. goto error;
  422. if (FAILED(m_pBodyObj->HrInit(hwnd)))
  423. goto error;
  424. if (FAILED(m_pBodyObj->HrShow(FALSE)))
  425. goto error;
  426. return TRUE;
  427. error:
  428. return FALSE;
  429. }
  430. //
  431. // FUNCTION: CFrontPage::OnSize
  432. //
  433. // PURPOSE: Notification that the view window has been resized. In
  434. // response we update the positions of our child windows and
  435. // controls.
  436. //
  437. // PARAMETERS:
  438. // hwnd - Handle of the view window being resized.
  439. // state - Type of resizing requested.
  440. // cxClient - New width of the client area.
  441. // cyClient - New height of the client area.
  442. //
  443. void CFrontPage::OnSize(HWND hwnd, UINT state, int cxClient, int cyClient)
  444. {
  445. RECT rcBody, rcFldr;
  446. GetClientRect(hwnd, &rcBody);
  447. m_pBodyObj->HrSetSize(&rcBody);
  448. }
  449. //
  450. // FUNCTION: CFrontPage::OnSetFocus
  451. //
  452. // PURPOSE: If the focus ever is set to the view window, we want to
  453. // make sure it goes to one of our child windows. Preferably
  454. // the focus will go to the last child to have the focus.
  455. //
  456. // PARAMETERS:
  457. // hwnd - Handle of the view window.
  458. // hwndOldFocus - Handle of the window losing focus.
  459. //
  460. void CFrontPage::OnSetFocus(HWND hwnd, HWND hwndOldFocus)
  461. {
  462. FPDOUT("CFrontPage - WM_SETFOCUS");
  463. // Check to see that we have a window stored to have focus. If not
  464. // default to the message list.
  465. if (!m_hwndCtlFocus || !IsWindow(m_hwndCtlFocus) || m_hwndCtlFocus == m_hwndOwner)
  466. {
  467. m_pBodyObj->HrGetWindow(&m_hwndCtlFocus);
  468. }
  469. if (m_hwndCtlFocus && IsWindow(m_hwndCtlFocus))
  470. SetFocus(m_hwndCtlFocus);
  471. }
  472. //
  473. // FUNCTION: CFrontPage::OnNotify
  474. //
  475. // PURPOSE: Processes the various notifications we receive from our child
  476. // controls.
  477. //
  478. // PARAMETERS:
  479. // hwnd - Handle of the view window.
  480. // idCtl - identifies the control sending the notification
  481. // pnmh - points to a NMHDR struct with more information regarding the
  482. // notification
  483. //
  484. // RETURN VALUE:
  485. // Dependant on the specific notification.
  486. //
  487. LRESULT CFrontPage::OnNotify(HWND hwnd, int idFrom, LPNMHDR pnmhdr)
  488. {
  489. if (pnmhdr->code == NM_SETFOCUS)
  490. {
  491. // if we get a setfocus from a kid, and it's not the
  492. // body, be sure to UIDeactivate the body
  493. HWND hwndBody = 0;
  494. m_pBodyObj->HrGetWindow(&hwndBody);
  495. if (pnmhdr->hwndFrom != hwndBody)
  496. m_pBodyObj->HrUIActivate(FALSE);
  497. m_pShellBrowser->OnViewWindowActive(this);
  498. }
  499. return 0;
  500. }
  501. BOOL CFrontPage::OnActivate(UINT uActivation)
  502. {
  503. // if focus stays within the frame, but goes outside our view.
  504. // ie.. TreeView gets focus then we get an activate nofocus. Be sure
  505. // to UIDeactivate the docobj in this case
  506. if (uActivation == SVUIA_ACTIVATE_NOFOCUS)
  507. m_pBodyObj->HrUIActivate(FALSE);
  508. if (m_uActivation != uActivation)
  509. {
  510. OnDeactivate();
  511. m_uActivation = uActivation;
  512. SafeRelease(m_pStatusBar);
  513. m_pShellBrowser->GetStatusBar(&m_pStatusBar);
  514. if (m_pBodyObj)
  515. m_pBodyObj->HrSetStatusBar(m_pStatusBar);
  516. if (!m_fFirstActive)
  517. {
  518. PostMessage(m_hwnd, NVM_INITHEADERS, 0, 0L);
  519. m_fFirstActive = TRUE;
  520. }
  521. }
  522. return TRUE;
  523. }
  524. BOOL CFrontPage::OnDeactivate()
  525. {
  526. if (m_uActivation != SVUIA_DEACTIVATE)
  527. {
  528. m_uActivation = SVUIA_DEACTIVATE;
  529. if (m_pBodyObj)
  530. m_pBodyObj->HrSetStatusBar(NULL);
  531. }
  532. return TRUE;
  533. }
  534. BOOL CFrontPage::LoadBaseSettings()
  535. {
  536. return TRUE;
  537. }
  538. BOOL CFrontPage::SaveBaseSettings()
  539. {
  540. return TRUE;
  541. }
  542. void CFrontPage::PostCreate()
  543. {
  544. Assert(m_pShellBrowser);
  545. m_pBodyObj->HrLoadPage();
  546. ProcessICW(m_hwndOwner, m_ftType);
  547. }