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.

926 lines
26 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: childfrm.cpp
  7. //
  8. // Contents: Child frame implementation
  9. //
  10. // History: 01-Jan-96 TRomano Created
  11. // 16-Jul-96 WayneSc Add code to switch views
  12. //
  13. //--------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "AMC.h"
  16. #include "ChildFrm.h"
  17. #include "AMCDoc.h"
  18. #include "AMCView.h"
  19. #include "treectrl.h"
  20. #include "afxpriv.h"
  21. #include "mainfrm.h"
  22. #include "amcpriv.h"
  23. #include "sysmenu.h"
  24. #include "amcmsgid.h"
  25. #include "caption.h"
  26. #include "strings.h"
  27. #include "menubtns.h"
  28. bool CanCloseDoc(void);
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CChildFrame
  31. IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
  32. BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
  33. //{{AFX_MSG_MAP(CChildFrame)
  34. ON_WM_CREATE()
  35. ON_WM_SIZE()
  36. ON_WM_DESTROY()
  37. ON_WM_CLOSE()
  38. ON_WM_MDIACTIVATE()
  39. ON_COMMAND(ID_CUSTOMIZE_VIEW, OnCustomizeView)
  40. ON_WM_NCPAINT()
  41. ON_WM_NCACTIVATE()
  42. ON_WM_SYSCOMMAND()
  43. ON_WM_INITMENUPOPUP()
  44. //}}AFX_MSG_MAP
  45. ON_MESSAGE(WM_SETTEXT, OnSetText)
  46. ON_MESSAGE(WM_GETICON, OnGetIcon)
  47. ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString)
  48. ON_COMMAND_RANGE(ID_MMC_MAXIMIZE, ID_MMC_RESTORE, OnMaximizeOrRestore)
  49. ON_UPDATE_COMMAND_UI(ID_CUSTOMIZE_VIEW, OnUpdateCustomizeView)
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CChildFrame construction/destruction
  53. CChildFrame::CChildFrame()
  54. {
  55. m_pAMCView = NULL;
  56. m_fDestroyed = false;
  57. m_fCurrentlyMinimized = false;
  58. m_fCurrentlyActive = false;
  59. m_fCreateVisible = true;
  60. m_fEmptyAMCView = false;
  61. }
  62. CChildFrame::~CChildFrame()
  63. {
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CChildFrame diagnostics
  67. #ifdef _DEBUG
  68. void CChildFrame::AssertValid() const
  69. {
  70. CMDIChildWnd::AssertValid();
  71. }
  72. void CChildFrame::Dump(CDumpContext& dc) const
  73. {
  74. CMDIChildWnd::Dump(dc);
  75. }
  76. #endif //_DEBUG
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CChildFrame message handlers
  79. BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
  80. {
  81. BOOL bSuccess=FALSE;
  82. // Let default implementation fill in most of the details
  83. if (!CMDIChildWnd::PreCreateWindow(cs))
  84. return (FALSE);
  85. // Remove the edge from the window so the splitter can paint it.
  86. cs.dwExStyle &=~WS_EX_CLIENTEDGE;
  87. WNDCLASS wc;
  88. LPCTSTR pszChildFrameClassName = g_szChildFrameClassName;
  89. if (::GetClassInfo(AfxGetInstanceHandle(), cs.lpszClass, &wc))
  90. {
  91. // Clear the H and V REDRAW flags
  92. wc.style &= ~(CS_HREDRAW | CS_VREDRAW);
  93. wc.hIcon = AfxGetApp()->LoadIcon(IDR_AMCTYPE);
  94. wc.lpszClassName = pszChildFrameClassName;
  95. // Register this new style;
  96. bSuccess=AfxRegisterClass(&wc);
  97. }
  98. // Use the new child frame window class
  99. cs.lpszClass = pszChildFrameClassName;
  100. //cs.style &= ~FWS_ADDTOTITLE;
  101. // force maximized if in SDI User mode
  102. if (AMCGetApp()->GetMode() == eMode_User_SDI)
  103. cs.style |= WS_MAXIMIZE;
  104. // do not paint over the children
  105. cs.style |= WS_CLIPCHILDREN;
  106. return bSuccess;
  107. }
  108. /*+-------------------------------------------------------------------------*
  109. *
  110. * CChildFrame::OnUpdateFrameTitle
  111. *
  112. * PURPOSE: Sets the window title. It might be possible to short out this
  113. * function.
  114. *
  115. * PARAMETERS:
  116. * BOOL bAddToTitle :
  117. *
  118. * RETURNS:
  119. * void
  120. *
  121. *+-------------------------------------------------------------------------*/
  122. void
  123. CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
  124. {
  125. DECLARE_SC(sc,TEXT("CChildFrame::OnUpdateFrameTitle"));
  126. if ((GetStyle() & FWS_ADDTOTITLE) == 0)
  127. return; // leave child window alone!
  128. CDocument* pDocument = GetActiveDocument();
  129. if (bAddToTitle && pDocument != NULL)
  130. {
  131. sc = ScCheckPointers(m_pAMCView, E_UNEXPECTED);
  132. if(sc)
  133. return;
  134. sc = ScCheckPointers(m_pAMCView->GetWindowTitle());
  135. if(sc)
  136. return;
  137. // set title if changed, but don't remove completely
  138. AfxSetWindowText(m_hWnd, m_pAMCView->GetWindowTitle());
  139. }
  140. // update our parent window last
  141. GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);
  142. }
  143. int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  144. {
  145. static UINT anIndicators[] =
  146. {
  147. ID_SEPARATOR, // status line indicator
  148. IDS_PROGRESS, // place holder for progress bar
  149. IDS_STATUS_STATIC, // place holder for static control
  150. };
  151. DECLARE_SC (sc, _T("CChildFrame::OnCreate"));
  152. if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
  153. {
  154. sc = E_UNEXPECTED;
  155. return -1;
  156. }
  157. /*
  158. * status bar should be themed (block controls the scope of activator)
  159. */
  160. {
  161. CThemeContextActivator activator;
  162. // Create the status bar and panes
  163. m_wndStatusBar.Create(this, WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0x1003);
  164. m_wndStatusBar.CreatePanes(anIndicators, countof(anIndicators));
  165. }
  166. // Add the control to the dock site
  167. m_StatusDockSite.Create(CDockSite::DSS_BOTTOM);
  168. m_StatusDockSite.Attach(&m_wndStatusBar);
  169. m_StatusDockSite.Show();
  170. // Tell the dock manager about the site.
  171. m_DockingManager.Attach(&m_StatusDockSite);
  172. CAMCView* const pAMCView = GetAMCView();
  173. if (pAMCView == NULL)
  174. {
  175. sc = E_UNEXPECTED;
  176. return -1;
  177. }
  178. pAMCView->SetChildFrameWnd(m_hWnd);
  179. SViewData* pVD = pAMCView->GetViewData();
  180. if (NULL == pVD)
  181. {
  182. sc = E_UNEXPECTED;
  183. return -1;
  184. }
  185. // Create the menubuttons manager and toolbars manager (one per view).
  186. m_spMenuButtonsMgr = std::auto_ptr<CMenuButtonsMgrImpl>(new CMenuButtonsMgrImpl());
  187. if (NULL == m_spMenuButtonsMgr.get())
  188. {
  189. sc = E_UNEXPECTED;
  190. return -1;
  191. }
  192. // Let SViewData be aware of the CMenuButtonsMgr.
  193. pVD->SetMenuButtonsMgr(static_cast<CMenuButtonsMgr*>(m_spMenuButtonsMgr.get()));
  194. CMainFrame* pFrame = AMCGetMainWnd();
  195. sc = ScCheckPointers (pFrame, E_UNEXPECTED);
  196. if (sc)
  197. return -1;
  198. ASSERT_KINDOF (CMainFrame, pFrame);
  199. // Init the CMenuButtonsMgr.
  200. sc = m_spMenuButtonsMgr->ScInit(pFrame, this);
  201. if (sc)
  202. return -1;
  203. // Create the Standard toolbar UI.
  204. pVD->m_spNodeManager->InitViewData(reinterpret_cast<LONG_PTR>(pVD));
  205. ASSERT(pVD->m_spVerbSet != NULL);
  206. AppendToSystemMenu (this, eMode_User_SDI);
  207. RenderDockSites();
  208. return 0;
  209. }
  210. void CChildFrame::RenderDockSites()
  211. {
  212. CRect clientRect;
  213. GetClientRect(&clientRect);
  214. CWnd* pWnd=GetWindow(GW_CHILD);
  215. if(pWnd)
  216. {
  217. m_DockingManager.BeginLayout();
  218. m_DockingManager.RenderDockSites(pWnd->m_hWnd, clientRect);
  219. m_DockingManager.EndLayout();
  220. }
  221. }
  222. bool CChildFrame::IsCustomizeViewEnabled()
  223. {
  224. bool fEnable = false;
  225. CAMCDoc* pDoc = CAMCDoc::GetDocument();
  226. if (pDoc != NULL)
  227. {
  228. fEnable = (AMCGetApp()->GetMode() == eMode_Author) ||
  229. pDoc->AllowViewCustomization();
  230. }
  231. return (fEnable);
  232. }
  233. void CChildFrame::OnUpdateCustomizeView(CCmdUI* pCmdUI)
  234. {
  235. pCmdUI->Enable (IsCustomizeViewEnabled());
  236. }
  237. // Display Customize View dialog
  238. // When a child window is maximized, then it becomes a CMainFrame so the handler is
  239. // necessary here to process the Scope Pane command on the system menu
  240. void CChildFrame::OnCustomizeView()
  241. {
  242. CAMCView* pView = GetAMCView();
  243. if (pView != NULL)
  244. {
  245. INodeCallback* pCallback = pView->GetNodeCallback();
  246. SViewData* pViewData = pView->GetViewData();
  247. ASSERT (pCallback != NULL);
  248. ASSERT (pViewData != NULL);
  249. pCallback->OnCustomizeView (reinterpret_cast<LONG_PTR>(pViewData));
  250. }
  251. }
  252. /*+-------------------------------------------------------------------------*
  253. * CChildFrame::OnInitMenuPopup
  254. *
  255. * WM_INITMENUPOPUP handler for CChildFrame.
  256. *--------------------------------------------------------------------------*/
  257. void CChildFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
  258. {
  259. /*
  260. * Bug 201113: don't allow child system menus in SDI mode
  261. */
  262. if (bSysMenu && (AMCGetApp()->GetMode() == eMode_User_SDI))
  263. {
  264. SendMessage (WM_CANCELMODE);
  265. return;
  266. }
  267. CMDIChildWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  268. /*
  269. * CFrameWnd::OnInitMenuPopup doesn't do UI updates for system menus,
  270. * so we have to do it here
  271. */
  272. if (bSysMenu)
  273. {
  274. int nEnable = IsCustomizeViewEnabled() ? MF_ENABLED : MF_GRAYED;
  275. pPopupMenu->EnableMenuItem (ID_CUSTOMIZE_VIEW, MF_BYCOMMAND | nEnable);
  276. }
  277. }
  278. /*+-------------------------------------------------------------------------*
  279. * CChildFrame::OnSize
  280. *
  281. * WM_SIZE handler for CChildFrame.
  282. *--------------------------------------------------------------------------*/
  283. void CChildFrame::OnSize(UINT nType, int cx, int cy)
  284. {
  285. DECLARE_SC(sc, TEXT("CChildFrame::OnSize"));
  286. // bypass CMDIChildWnd::OnSize so we won't get MFC's docking stuff
  287. // (we still need to call Default so Windows' MDI stuff will work right)
  288. CWnd::OnSize(nType, cx, cy);
  289. if (nType != SIZE_MINIMIZED)
  290. {
  291. RenderDockSites();
  292. CAMCView* pAMCView = GetAMCView();
  293. ASSERT (pAMCView != NULL);
  294. if (pAMCView)
  295. pAMCView->AdjustTracker (cx, cy);
  296. }
  297. // update our parent frame - in case we are now maximized or not
  298. CMDIFrameWnd* pwndMDIFrame = GetMDIFrame();
  299. if (pwndMDIFrame)
  300. pwndMDIFrame->OnUpdateFrameTitle(TRUE);
  301. /*
  302. * If we're moving to or from the minimized state, notify snap-ins.
  303. * We don't need to send the notification if we're only creating a
  304. * temporary view that will never be shown.
  305. */
  306. if (m_fCurrentlyMinimized != (nType == SIZE_MINIMIZED) && m_fCreateVisible)
  307. {
  308. m_fCurrentlyMinimized = (nType == SIZE_MINIMIZED);
  309. SendMinimizeNotification (m_fCurrentlyMinimized);
  310. }
  311. // send the size notification to the view.
  312. if(GetAMCView())
  313. {
  314. sc = GetAMCView()->ScOnSize(nType, cx, cy);
  315. if(sc)
  316. return;
  317. }
  318. }
  319. BOOL CChildFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CMDIFrameWnd* pParentWnd, CCreateContext* pContext)
  320. {
  321. if (pParentWnd == NULL)
  322. {
  323. CWnd* pMainWnd = AfxGetThread()->m_pMainWnd;
  324. ASSERT(pMainWnd != NULL);
  325. ASSERT_KINDOF(CMDIFrameWnd, pMainWnd);
  326. pParentWnd = (CMDIFrameWnd*)pMainWnd;
  327. }
  328. ASSERT(::IsWindow(pParentWnd->m_hWndMDIClient));
  329. // first copy into a CREATESTRUCT for PreCreate
  330. CREATESTRUCT cs;
  331. cs.dwExStyle = 0L;
  332. cs.lpszClass = lpszClassName;
  333. cs.lpszName = lpszWindowName;
  334. cs.style = dwStyle;
  335. cs.x = rect.left;
  336. cs.y = rect.top;
  337. cs.cx = rect.right - rect.left;
  338. cs.cy = rect.bottom - rect.top;
  339. cs.hwndParent = pParentWnd->m_hWnd;
  340. cs.hMenu = NULL;
  341. cs.hInstance = AfxGetInstanceHandle();
  342. cs.lpCreateParams = (LPVOID)pContext;
  343. if (!PreCreateWindow(cs))
  344. {
  345. PostNcDestroy();
  346. return FALSE;
  347. }
  348. // extended style must be zero for MDI Children (except under Win4)
  349. // ASSERT(afxData.bWin4 || cs.dwExStyle == 0);
  350. ASSERT(cs.hwndParent == pParentWnd->m_hWnd); // must not change
  351. // now copy into a MDICREATESTRUCT for real create
  352. MDICREATESTRUCT mcs;
  353. mcs.szClass = cs.lpszClass;
  354. mcs.szTitle = cs.lpszName;
  355. mcs.hOwner = cs.hInstance;
  356. mcs.x = cs.x;
  357. mcs.y = cs.y;
  358. mcs.cx = cs.cx;
  359. mcs.cy = cs.cy;
  360. mcs.style = cs.style & ~(WS_MAXIMIZE | WS_VISIBLE);
  361. mcs.lParam = reinterpret_cast<LPARAM>(cs.lpCreateParams);
  362. // create the window through the MDICLIENT window
  363. AfxHookWindowCreate(this);
  364. HWND hWnd = (HWND)::SendMessage(pParentWnd->m_hWndMDIClient,
  365. WM_MDICREATE, 0, (LPARAM)&mcs);
  366. if (!AfxUnhookWindowCreate())
  367. PostNcDestroy(); // cleanup if MDICREATE fails too soon
  368. if (hWnd == NULL)
  369. return FALSE;
  370. // special handling of visibility (always created invisible)
  371. if (cs.style & WS_VISIBLE)
  372. {
  373. // place the window on top in z-order before showing it
  374. ::BringWindowToTop(hWnd);
  375. // show it as specified
  376. if (cs.style & WS_MINIMIZE)
  377. ShowWindow(SW_SHOWMINIMIZED);
  378. else if (cs.style & WS_MAXIMIZE)
  379. ShowWindow(SW_SHOWMAXIMIZED);
  380. else
  381. ShowWindow(SW_SHOWNORMAL);
  382. // make sure it is active (visibility == activation)
  383. pParentWnd->MDIActivate(this);
  384. // refresh MDI Window menu
  385. ::SendMessage(pParentWnd->m_hWndMDIClient, WM_MDIREFRESHMENU, 0, 0);
  386. }
  387. ASSERT(hWnd == m_hWnd);
  388. return TRUE;
  389. }
  390. void CChildFrame::OnDestroy()
  391. {
  392. // NOTE - The un-hooking of the dock manager stops the rebar sending a height change
  393. // when the rebar goes away.
  394. m_DockingManager.RemoveAll();
  395. m_fDestroyed = true;
  396. CMDIChildWnd::OnDestroy();
  397. }
  398. void CChildFrame::OnMaximizeOrRestore(UINT nID)
  399. {
  400. ASSERT(nID == ID_MMC_MAXIMIZE || nID == ID_MMC_RESTORE);
  401. WINDOWPLACEMENT wp;
  402. wp.length = sizeof(wp);
  403. GetWindowPlacement(&wp);
  404. UINT newShowCmd = (nID == ID_MMC_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
  405. if (wp.showCmd != newShowCmd)
  406. {
  407. wp.showCmd = newShowCmd;
  408. SetWindowPlacement(&wp);
  409. }
  410. }
  411. void CChildFrame::OnClose()
  412. {
  413. CAMCDoc* pDoc = CAMCDoc::GetDocument();
  414. ASSERT(pDoc != NULL);
  415. if (pDoc)
  416. {
  417. int cViews = 0;
  418. CAMCViewPosition pos = pDoc->GetFirstAMCViewPosition();
  419. while (pos != NULL)
  420. {
  421. CAMCView* pView = pDoc->GetNextAMCView(pos);
  422. if ((pView != NULL) && ++cViews >= 2)
  423. break;
  424. }
  425. if (cViews == 1)
  426. {
  427. if (!CanCloseDoc())
  428. return;
  429. }
  430. else
  431. {
  432. // if not closing last view, then give it
  433. // a chance to clean up first.
  434. // (if whole doc is closing CAMCDoc will handle
  435. // closing all the views.)
  436. CAMCView* pView = GetAMCView();
  437. if (pView != NULL)
  438. {
  439. CAMCDoc* pAMCDoc = CAMCDoc::GetDocument();
  440. /*
  441. * Don't allow the user to close the last persisted view.
  442. */
  443. if (pView->IsPersisted() &&
  444. (pAMCDoc != NULL) &&
  445. (pAMCDoc->GetNumberOfPersistedViews() == 1))
  446. {
  447. MMCMessageBox (IDS_CantCloseLastPersistableView);
  448. return;
  449. }
  450. pView->CloseView();
  451. }
  452. }
  453. }
  454. CMDIChildWnd::OnClose();
  455. }
  456. /*+-------------------------------------------------------------------------*
  457. * CChildFrame::OnUpdateFrameMenu
  458. *
  459. * WM_UPDATEFRAMEMENU handler for CChildFrame.
  460. *--------------------------------------------------------------------------*/
  461. void CChildFrame::OnUpdateFrameMenu(BOOL bActivate, CWnd* pActivateWnd,
  462. HMENU hMenuAlt)
  463. {
  464. ASSERT_VALID (this);
  465. DECLARE_SC (sc, _T("CChildFrame::OnUpdateFrameMenu"));
  466. // let the base class select the right menu
  467. CMDIChildWnd::OnUpdateFrameMenu (bActivate, pActivateWnd, hMenuAlt);
  468. // make sure the child has the WS_SYSMENU bit
  469. // (it won't if it's created maximized)
  470. ModifyStyle (0, WS_SYSMENU);
  471. // by now, the right menu is selected; reflect it to the toolbar
  472. CMainFrame* pFrame = static_cast<CMainFrame *>(GetParentFrame ());
  473. ASSERT_KINDOF (CMainFrame, pFrame);
  474. pFrame->NotifyMenuChanged ();
  475. // Add the menubuttons only on activate, the CMenubar
  476. // removes all menus during deactivate.
  477. if (bActivate)
  478. {
  479. ASSERT(NULL != m_spMenuButtonsMgr.get());
  480. if (NULL != m_spMenuButtonsMgr.get())
  481. {
  482. // Now add the menu buttons to main menu
  483. sc = m_spMenuButtonsMgr->ScAddMenuButtonsToMainMenu();
  484. }
  485. }
  486. }
  487. /*+-------------------------------------------------------------------------*
  488. * CChildFrame::OnGetIcon
  489. *
  490. * WM_GETICON handler for CChildFrame.
  491. *
  492. * NOTE: the control over the icon remains with the callee - it is responsible
  493. * for releasing the resource. Coller should never release the returned
  494. * handle
  495. *--------------------------------------------------------------------------*/
  496. LRESULT CChildFrame::OnGetIcon (WPARAM wParam, LPARAM lParam)
  497. {
  498. CAMCDoc* pDoc = CAMCDoc::GetDocument();
  499. /*
  500. * use the custom icon if we have one
  501. */
  502. if ((pDoc != NULL) && pDoc->HasCustomIcon())
  503. return ((LRESULT) pDoc->GetCustomIcon ((wParam == ICON_BIG)));
  504. /*
  505. * no custom icon, use the default icon
  506. */
  507. const int cxIcon = GetSystemMetrics ((wParam == ICON_BIG) ? SM_CXICON : SM_CXSMICON);
  508. const int cyIcon = GetSystemMetrics ((wParam == ICON_BIG) ? SM_CYICON : SM_CYSMICON);
  509. // use cached copy - it never changes
  510. // do not delete this ever - since we only have one copy,
  511. // we do not leak. releassing is expensive and does not pay off
  512. static HICON s_hMMCIcon = (HICON)::LoadImage (AfxGetResourceHandle(),
  513. MAKEINTRESOURCE (IDR_AMCTYPE),
  514. IMAGE_ICON, cxIcon, cyIcon, 0);
  515. return (LRESULT)s_hMMCIcon;
  516. }
  517. /*+-------------------------------------------------------------------------*
  518. * CChildFrame::OnSysCommand
  519. *
  520. * WM_SYSCOMMAND handler for CChildFrame.
  521. *--------------------------------------------------------------------------*/
  522. void CChildFrame::OnSysCommand(UINT nID, LPARAM lParam)
  523. {
  524. switch (nID)
  525. {
  526. case ID_CUSTOMIZE_VIEW:
  527. OnCustomizeView();
  528. break;
  529. case SC_CLOSE:
  530. {
  531. // windows bug#470429(9/24/2001)
  532. // do extra check only if it is worth keeping the window
  533. if ( !m_fEmptyAMCView )
  534. {
  535. // eat Ctrl+F4 in SDI simulation mode...
  536. if (AMCGetApp()->GetMode() == eMode_User_SDI)
  537. break;
  538. // ...or if Close is disabled or doesn't exist on the system menu
  539. CMenu* pSysMenu = GetSystemMenu (FALSE);
  540. UINT nCloseState = pSysMenu->GetMenuState (SC_CLOSE, MF_BYCOMMAND);
  541. if ((nCloseState == 0xFFFFFFFF) ||
  542. (nCloseState & (MF_GRAYED | MF_DISABLED)))
  543. break;
  544. }
  545. // all systems go, let MDI have it
  546. CMDIChildWnd::OnSysCommand(nID, lParam);
  547. break;
  548. }
  549. case SC_NEXTWINDOW:
  550. case SC_PREVWINDOW:
  551. // eat Ctrl+(Shift+)Tab and Ctrl+(Shift+)F6 in SDI simulation mode
  552. if (AMCGetApp()->GetMode() != eMode_User_SDI)
  553. CMDIChildWnd::OnSysCommand(nID, lParam);
  554. break;
  555. default:
  556. CMDIChildWnd::OnSysCommand(nID, lParam);
  557. break;
  558. }
  559. }
  560. /*+-------------------------------------------------------------------------*
  561. * CChildFrame::GetDefaultAccelerator
  562. *
  563. *
  564. *--------------------------------------------------------------------------*/
  565. HACCEL CChildFrame::GetDefaultAccelerator()
  566. {
  567. // use document specific accelerator table ONLY
  568. // Dont use CFrameWnd::m_hAccel, because we don't base accelerators
  569. // on document type but rather on mode. This is taken care of
  570. // in CAMCDoc.
  571. return (NULL);
  572. }
  573. /*+-------------------------------------------------------------------------*
  574. * CChildFrame::OnSetMessageString
  575. *
  576. * WM_SETMESSAGESTRING handler for CChildFrame.
  577. *--------------------------------------------------------------------------*/
  578. LRESULT CChildFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam)
  579. {
  580. /*
  581. * if this we're going to set the idle message string and we've
  582. * been given a custom status line string, use that one instead
  583. */
  584. if ((wParam == AFX_IDS_IDLEMESSAGE) && !m_strStatusText.IsEmpty())
  585. {
  586. ASSERT (lParam == 0);
  587. wParam = 0;
  588. lParam = (LPARAM)(LPCTSTR) m_strStatusText;
  589. }
  590. // sometimes we'll get a WM_SETMESSAGESTRING after being destroyed,
  591. // don't pass it through or we'll crash inside the status bar code
  592. if (m_fDestroyed)
  593. return (0);
  594. return (CMDIChildWnd::OnSetMessageString (wParam, lParam));
  595. }
  596. void CChildFrame::ToggleStatusBar ()
  597. {
  598. m_StatusDockSite.Toggle();
  599. RenderDockSites();
  600. if (m_StatusDockSite.IsVisible())
  601. UpdateStatusText ();
  602. }
  603. /*+-------------------------------------------------------------------------*
  604. * CChildFrame::OnMDIActivate
  605. *
  606. * WM_MDIACTIVATE handler for CChildFrame.
  607. *--------------------------------------------------------------------------*/
  608. void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
  609. {
  610. DECLARE_SC (sc, _T("CChildFrame::OnMDIActivate"));
  611. SetChildFrameActive(bActivate);
  612. CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
  613. sc = ScCheckPointers(m_pAMCView, E_UNEXPECTED);
  614. if (sc)
  615. return;
  616. if (bActivate)
  617. {
  618. // If the window being de-activated is not of childframe type then this
  619. // is the first active view (childframe).
  620. bool bFirstActiveView = pDeactivateWnd ? (FALSE == pDeactivateWnd->IsKindOf (RUNTIME_CLASS (CChildFrame)))
  621. : true;
  622. sc = m_pAMCView->ScFireEvent(CAMCViewObserver::ScOnActivateView, m_pAMCView, bFirstActiveView);
  623. // if activation changes - need to set frame to dirty
  624. CAMCDoc* pDoc = CAMCDoc::GetDocument ();
  625. if (pDoc == NULL)
  626. (sc = E_UNEXPECTED).TraceAndClear();
  627. else
  628. {
  629. pDoc->SetFrameModifiedFlag (true);
  630. }
  631. }
  632. else
  633. {
  634. // If the window being activated is not of childframe type then this is
  635. // the last active view (childframe).
  636. bool bLastActiveView = pActivateWnd ? (FALSE == pActivateWnd->IsKindOf (RUNTIME_CLASS (CChildFrame)))
  637. : true;
  638. sc = m_pAMCView->ScFireEvent(CAMCViewObserver::ScOnDeactivateView, m_pAMCView, bLastActiveView);
  639. }
  640. if (sc)
  641. return;
  642. /*
  643. * Notify snap-ins of an activation change
  644. */
  645. NotifyCallback (NCLBK_ACTIVATE, bActivate, 0);
  646. }
  647. /*+-------------------------------------------------------------------------*
  648. * CChildFrame::SendMinimizeNotification
  649. *
  650. *
  651. *--------------------------------------------------------------------------*/
  652. void CChildFrame::SendMinimizeNotification (bool fMinimized) const
  653. {
  654. if(m_pAMCView != NULL)
  655. m_pAMCView->ScOnMinimize(m_fCurrentlyMinimized);
  656. }
  657. /*+-------------------------------------------------------------------------*
  658. * CChildFrame::NotifyCallback
  659. *
  660. *
  661. *--------------------------------------------------------------------------*/
  662. HRESULT CChildFrame::NotifyCallback (
  663. NCLBK_NOTIFY_TYPE event,
  664. LONG_PTR arg,
  665. LPARAM param) const
  666. {
  667. if (m_pAMCView == NULL)
  668. return (E_FAIL);
  669. HNODE hNode = m_pAMCView->GetSelectedNode();
  670. if (hNode == NULL)
  671. return (E_FAIL);
  672. INodeCallback* pNodeCallback = m_pAMCView->GetNodeCallback();
  673. if (pNodeCallback == NULL)
  674. return (E_FAIL);
  675. return (pNodeCallback->Notify (hNode, event, arg, param));
  676. }
  677. /*+-------------------------------------------------------------------------*
  678. * CChildFrame::OnNcPaint
  679. *
  680. * WM_NCPAINT handler for CChildFrame.
  681. *--------------------------------------------------------------------------*/
  682. void CChildFrame::OnNcPaint()
  683. {
  684. Default();
  685. DrawFrameCaption (this, m_fCurrentlyActive);
  686. }
  687. /*+-------------------------------------------------------------------------*
  688. * CChildFrame::OnNcActivate
  689. *
  690. * WM_NCACTIVATE handler for CChildFrame.
  691. *--------------------------------------------------------------------------*/
  692. BOOL CChildFrame::OnNcActivate(BOOL bActive)
  693. {
  694. BOOL rc = CMDIChildWnd::OnNcActivate(bActive);
  695. m_fCurrentlyActive = bActive;
  696. DrawFrameCaption (this, m_fCurrentlyActive);
  697. return (rc);
  698. }
  699. /*+-------------------------------------------------------------------------*
  700. * CChildFrame::OnSetText
  701. *
  702. * WM_SETTEXT handler for CChildFrame.
  703. *--------------------------------------------------------------------------*/
  704. LRESULT CChildFrame::OnSetText (WPARAM wParam, LPARAM lParam)
  705. {
  706. LRESULT rc = Default();
  707. DrawFrameCaption (this, m_fCurrentlyActive);
  708. return (rc);
  709. }
  710. /*+-------------------------------------------------------------------------*
  711. * CChildFrame::ActivateFrame
  712. *
  713. *
  714. *--------------------------------------------------------------------------*/
  715. void CChildFrame::ActivateFrame(int nCmdShow /*= -1*/)
  716. {
  717. if ((nCmdShow == -1) && !m_fCreateVisible)
  718. nCmdShow = SW_SHOWNOACTIVATE;
  719. /*
  720. * When this flag [m_fCreateVisible] is set, the frame will show itself with the
  721. * SW_SHOWMINNOACTIVE flag instead of the default flag. Doing this will
  722. * avoid the side effect of restoring the currently active child frame
  723. * if it is maximized at the time the new frame is created invisibly.
  724. */
  725. // The SW_SHOWMINNOACTIVE was changed to SW_SHOWNOACTIVATE.
  726. // It does preserve the active window from mentioned side effect,
  727. // plus it also allows scripts (using Object Moded) to create invisible views,
  728. // position and then show them as normal (not minimized) windows,
  729. // thus providing same result as creating visible and then hiding the view.
  730. // While minimized window must be restored first in order to change their position.
  731. CMDIChildWnd::ActivateFrame (nCmdShow);
  732. }
  733. /*+-------------------------------------------------------------------------*
  734. * CChildFrame::SetCreateVisible
  735. *
  736. *
  737. *--------------------------------------------------------------------------*/
  738. bool CChildFrame::SetCreateVisible (bool fCreateVisible)
  739. {
  740. bool fOldState = m_fCreateVisible;
  741. m_fCreateVisible = fCreateVisible;
  742. return (fOldState);
  743. }