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.

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