MainFrm.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:18k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "MDITabWindow.h"
  22. #include "MainFrm.h"
  23. #pragma warning(disable:4510)
  24. #pragma warning(disable:4610)
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. class CCommandBars : public CXTPCommandBars
  31. {
  32. DECLARE_DYNCREATE(CCommandBars)
  33. UINT GetActiveDocTemplate()
  34. {
  35. CXTPDockingPaneManager& paneManage = ((CMainFrame*)GetSite())->m_paneManager;
  36. if (paneManage.GetActivePane())
  37. {
  38. CFrameWnd* pActiveFrame = DYNAMIC_DOWNCAST(CFrameWnd, paneManage.GetActivePane()->GetChild());
  39. if (pActiveFrame)
  40. {
  41. CString str;
  42. pActiveFrame->GetActiveDocument()->GetDocTemplate()->GetDocString(str, CDocTemplate::docName);
  43. return str == _T("Bounce") ? IDR_BOUNCETYPE : IDR_HELLOTYPE;
  44. }
  45. }
  46. return CXTPCommandBars::GetActiveDocTemplate();
  47. }
  48. };
  49. IMPLEMENT_DYNCREATE(CCommandBars, CXTPCommandBars);
  50. class CDockingFrameWnd : public CFrameWnd
  51. {
  52. public:
  53. CDockingFrameWnd(){};
  54. DECLARE_DYNAMIC(CDockingFrameWnd);
  55. };
  56. IMPLEMENT_DYNAMIC(CDockingFrameWnd, CFrameWnd);
  57. CFrameWnd* CMainFrame::GetParentDockingFrame(CWnd* pWnd)
  58. {
  59. if (pWnd)
  60. {
  61. return DYNAMIC_DOWNCAST(CDockingFrameWnd, pWnd->GetParentFrame());
  62. }
  63. return NULL;
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CMainFrame
  67. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  68. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  69. //{{AFX_MSG_MAP(CMainFrame)
  70. ON_WM_CREATE()
  71. ON_WM_DESTROY()
  72. ON_COMMAND(ID_VIEW_THEME_OFFICE2000, OnViewThemeOffice2000)
  73. ON_COMMAND(ID_VIEW_THEME_OFFICEXP, OnViewThemeOfficexp)
  74. ON_COMMAND(ID_VIEW_THEME_OFFICE2003, OnViewThemeOffice2003)
  75. ON_COMMAND(ID_VIEW_THEME_NATIVEXP, OnViewThemeNativexp)
  76. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICE2000, OnUpdateViewThemeOffice2000)
  77. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICEXP, OnUpdateViewThemeOfficexp)
  78. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICE2003, OnUpdateViewThemeOffice2003)
  79. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_NATIVEXP, OnUpdateViewThemeNativexp)
  80. ON_MESSAGE(WM_XTP_PRETRANSLATEMOUSEMSG, OnTabbarMouseMsg)
  81. ON_COMMAND(ID_TOGGLE_DOCK, OnToggleTabsTopBottom)
  82. ON_COMMAND(ID_WINDOW_CLOSE_ALL, OnWindowCloseAll)
  83. ON_UPDATE_COMMAND_UI(ID_WINDOW_CLOSE_ALL, OnUpdateWindowCloseAll)
  84. ON_COMMAND(ID_WINDOW_DOCKABLE, OnWindowDockable)
  85. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  86. ON_UPDATE_COMMAND_UI(ID_WINDOW_DOCKABLE, OnUpdateWindowDockable)
  87. ON_COMMAND(ID_WINDOW_HIDE, OnWindowHide)
  88. ON_COMMAND(ID_WINDOW_HIDEALL, OnWindowHideall)
  89. ON_COMMAND(ID_WINDOW_AUTOHIDE, OnWindowAutohide)
  90. ON_UPDATE_COMMAND_UI(ID_WINDOW_AUTOHIDE, OnUpdateWindowAutohide)
  91. ON_UPDATE_COMMAND_UI(ID_WINDOW_HIDEALL, OnUpdateWindowHideall)
  92. ON_COMMAND(ID_TOGGLE_TABS, OnToggleTabs)
  93. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  94. ON_WM_CLOSE()
  95. ON_UPDATE_COMMAND_UI(ID_TOGGLE_TABS, OnUpdateToggleTabs)
  96. //}}AFX_MSG_MAP
  97. ON_XTP_CREATECONTROL()
  98. END_MESSAGE_MAP()
  99. static UINT indicators[] =
  100. {
  101. ID_SEPARATOR,           // status line indicator
  102. ID_INDICATOR_CAPS,
  103. ID_INDICATOR_NUM,
  104. ID_INDICATOR_SCRL,
  105. };
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CMainFrame construction/destruction
  108. CMainFrame::CMainFrame()
  109. {
  110. m_nCount = 0;
  111. }
  112. CMainFrame::~CMainFrame()
  113. {
  114. }
  115. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  116. {
  117. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  118. return -1;
  119. if (!m_wndStatusBar.Create(this) ||
  120. !m_wndStatusBar.SetIndicators(indicators,
  121. sizeof(indicators)/sizeof(UINT)))
  122. {
  123. TRACE0("Failed to create status barn");
  124. return -1;      // fail to create
  125. }
  126. if (!InitCommandBars( RUNTIME_CLASS(CCommandBars)))
  127. return -1;
  128. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  129. CXTPCommandBars* pCommandBars = GetCommandBars();
  130. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  131. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  132. if (!pStandardBar ||
  133. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  134. {
  135. TRACE0("Failed to create toolbarn");
  136. }
  137. XTPImageManager()->SetIcons(IDR_COLORS);
  138. m_paneManager.InstallDockingPanes(this);
  139. m_paneManager.SetTheme(xtpPaneThemeOffice);
  140. int nIDIcons[] = {1, 2};
  141. m_paneManager.SetIcons(IDB_BITMAP_ICONS, nIDIcons, 2, RGB(255, 255, 255));
  142. VERIFY(m_MTIClientWnd.Attach(this, TRUE));
  143. m_MTIClientWnd.EnableToolTips();
  144. LoadCommandBars(_T("CommandBars2"));
  145. return 0;
  146. }
  147. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  148. {
  149. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  150. return FALSE;
  151. cs.lpszClass = _T("XTPMainFrame");
  152. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  153. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  154. return TRUE;
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. // CMainFrame diagnostics
  158. #ifdef _DEBUG
  159. void CMainFrame::AssertValid() const
  160. {
  161. CMDIFrameWnd::AssertValid();
  162. }
  163. void CMainFrame::Dump(CDumpContext& dc) const
  164. {
  165. CMDIFrameWnd::Dump(dc);
  166. }
  167. #endif //_DEBUG
  168. /////////////////////////////////////////////////////////////////////////////
  169. // CMainFrame message handlers
  170. void CMainFrame::OnDestroy()
  171. {
  172. CMDIFrameWnd::OnDestroy();
  173. m_MTIClientWnd.Detach();
  174. }
  175. void CMainFrame::OnViewThemeOffice2000()
  176. {
  177. m_paneManager.SetTheme(xtpPaneThemeDefault);
  178. CXTPPaintManager::SetTheme(xtpThemeOffice2000);
  179. GetCommandBars()->RedrawCommandBars();
  180. }
  181. void CMainFrame::OnViewThemeOfficexp()
  182. {
  183. m_paneManager.SetTheme(xtpPaneThemeOffice);
  184. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  185. GetCommandBars()->RedrawCommandBars();
  186. }
  187. void CMainFrame::OnViewThemeOffice2003()
  188. {
  189. m_paneManager.SetTheme(xtpPaneThemeOffice2003);
  190. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  191. GetCommandBars()->RedrawCommandBars();
  192. }
  193. void CMainFrame::OnViewThemeNativexp()
  194. {
  195. m_paneManager.SetTheme(xtpPaneThemeDefault);
  196. CXTPPaintManager::SetTheme(xtpThemeNativeWinXP);
  197. GetCommandBars()->RedrawCommandBars();
  198. }
  199. void CMainFrame::OnUpdateViewThemeOffice2000(CCmdUI* pCmdUI)
  200. {
  201. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2000);
  202. }
  203. void CMainFrame::OnUpdateViewThemeOfficexp(CCmdUI* pCmdUI)
  204. {
  205. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOfficeXP);
  206. }
  207. void CMainFrame::OnUpdateViewThemeOffice2003(CCmdUI* pCmdUI)
  208. {
  209. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003);
  210. }
  211. void CMainFrame::OnUpdateViewThemeNativexp(CCmdUI* pCmdUI)
  212. {
  213. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeNativeWinXP);
  214. }
  215. LRESULT CMainFrame::OnTabbarMouseMsg(WPARAM wParam,LPARAM lParam)
  216. {
  217. if (wParam != WM_RBUTTONDOWN)
  218. return FALSE;
  219. CPoint point = CPoint((DWORD)lParam);
  220. CXTPTabManagerItem* pItem =  m_MTIClientWnd.HitTest(point);
  221. if (pItem)
  222. {
  223. CFrameWnd* pFrame = DYNAMIC_DOWNCAST(CMDIChildWnd, CWnd::FromHandle(pItem->GetHandle()));
  224. if (!pFrame)
  225. return FALSE;
  226. MDIActivate(pFrame);
  227. pFrame->GetActiveView()->SetFocus();
  228. m_MTIClientWnd.Refresh();
  229. CMenu menu;
  230. VERIFY(menu.LoadMenu(IDR_POPUP_TABS));
  231. CMenu* pPopup = menu.GetSubMenu(0);
  232. m_MTIClientWnd.WorkspaceToScreen(&point);
  233. CXTPPopupBar* pPopupBar = (CXTPPopupBar*) CXTPPopupBar::CreatePopupBar(GetCommandBars());
  234. VERIFY(pPopupBar->LoadMenu(pPopup));
  235. pPopupBar->GetControls()->FindControl(xtpControlPopup, -1, TRUE, FALSE)->SetEnabled(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003);
  236. VERIFY(pPopupBar->Popup(point.x, point.y, NULL));
  237. while ( pPopupBar->IsTrackingMode() )
  238. {
  239. AfxGetApp()->PumpMessage();
  240. }
  241. pPopupBar->InternalRelease();
  242. m_MTIClientWnd.Refresh();
  243. return TRUE;
  244. }
  245. CMenu menuPopup;
  246. menuPopup.CreatePopupMenu();
  247. menuPopup.AppendMenu(MF_STRING, ID_WINDOW_CLOSE_ALL, _T("&Close All"));
  248. menuPopup.AppendMenu(MF_STRING, ID_TOGGLE_DOCK, _T("&Toggle Docking"));
  249. m_MTIClientWnd.WorkspaceToScreen(&point);
  250. CXTPCommandBars::TrackPopupMenu(&menuPopup, TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd());
  251. m_MTIClientWnd.Refresh();
  252. return TRUE;
  253. }
  254. void CMainFrame::OnToggleTabsTopBottom(void)
  255. {
  256. if (m_MTIClientWnd.GetPaintManager()->GetPosition() == xtpTabPositionTop)
  257. m_MTIClientWnd.GetPaintManager()->SetPosition(xtpTabPositionBottom);
  258. else
  259. m_MTIClientWnd.GetPaintManager()->SetPosition(xtpTabPositionTop);
  260. m_MTIClientWnd.Refresh();
  261. }
  262. void CMainFrame::OnToggleTabs()
  263. {
  264. }
  265. void CMainFrame::OnUpdateToggleTabs(CCmdUI* pCmdUI)
  266. {
  267. pCmdUI->SetCheck(m_MTIClientWnd.IsAttached());
  268. }
  269. void CMainFrame::OnWindowCloseAll()
  270. {
  271. CXTPDockingPaneInfoList& lstPanes = m_paneManager.GetPaneList();
  272. POSITION pos = lstPanes.GetHeadPosition();
  273. while (pos)
  274. {
  275. CXTPDockingPane* pPane = lstPanes.GetNext(pos);
  276. m_paneManager.DestroyPane(pPane);
  277. }
  278. AfxGetApp()->CloseAllDocuments(FALSE);
  279. }
  280. void CMainFrame::ReparentAllChildren(CFrameWnd *pFrameOld, CFrameWnd* pFrameNew)
  281. {
  282. CPtrList childList;
  283. CWnd* pChild;
  284. for (pChild = pFrameOld->GetTopWindow(); pChild != NULL; pChild = pChild->GetNextWindow(GW_HWNDNEXT))
  285. childList.AddTail(pChild);
  286. POSITION pos = childList.GetHeadPosition();
  287. while (pos != NULL)
  288. {
  289. pChild = (CWnd*)childList.GetNext(pos);
  290. pChild->SetParent(pFrameNew);
  291. }
  292. }
  293. BOOL CMainFrame::ActivateDockableFrame(CFrameWnd* pFrameNew)
  294. {
  295. if(!pFrameNew) return FALSE;
  296. pFrameNew->SendMessage(WM_ACTIVATE, WA_ACTIVE);
  297. pFrameNew->ActivateFrame(-1);
  298. pFrameNew->OnUpdateFrameTitle(TRUE);
  299. return TRUE;
  300. }
  301. void CMainFrame::OnUpdateWindowDockable(CCmdUI* pCmdUI)
  302. {
  303. pCmdUI->SetCheck(GetParentDockingFrame(GetFocus()) !=NULL);
  304. }
  305. void CMainFrame::UnDockFrame(CFrameWnd* pFrameOld, CXTPDockingPane* pPane)
  306. {
  307. class CFriendlyDocTemplate: private CMultiDocTemplate
  308. {
  309. friend class CMainFrame;
  310. };
  311. CDocument* pDocument = pFrameOld->GetActiveDocument();
  312. if (!pDocument)
  313. return;
  314. CFriendlyDocTemplate* pTemplate = (CFriendlyDocTemplate*)pDocument->GetDocTemplate();
  315. // Create frame without any child view
  316. CRuntimeClass* pViewClassSave = pTemplate->m_pViewClass;
  317. pTemplate->m_pViewClass = NULL;
  318. CFrameWnd* pFrameNew = pTemplate->CreateNewFrame(pDocument, NULL);
  319. pTemplate->m_pViewClass = pViewClassSave;
  320. ReparentAllChildren(pFrameOld, pFrameNew);
  321. pFrameOld->DestroyWindow();
  322. // activate the first view.
  323. CView* pView = NULL;
  324. if (pFrameNew->GetActiveView() == NULL)
  325. {
  326. CPtrList childList;
  327. CWnd* pChild = pFrameNew->GetTopWindow();
  328. while ( pChild != NULL && pView == NULL)
  329. {
  330. ASSERT_KINDOF(CWnd, pChild);
  331. if (pChild->IsKindOf(RUNTIME_CLASS(CView)))
  332. {
  333. pView = (CView*)pChild;
  334. pFrameNew->SetActiveView(pView,FALSE);
  335. }
  336. pChild = pChild->GetNextWindow(GW_HWNDNEXT);
  337. }
  338. }
  339. ActivateDockableFrame(pFrameNew);
  340. pFrameNew->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED);
  341. pPane->Detach();
  342. m_paneManager.ClosePane(pPane);
  343. m_MTIClientWnd.Refresh();
  344. }
  345. void CMainFrame::DockFrame(CFrameWnd* pFrameOld)
  346. {
  347. CDocument* pDocument = pFrameOld->GetActiveDocument();
  348. if (!pDocument)
  349. return;
  350. CString strTitle = pDocument->GetTitle();
  351. CFrameWnd* pFrameNew = new CDockingFrameWnd;
  352. CCreateContext context;
  353. context.m_pCurrentDoc = pDocument;
  354. pFrameNew->Create(NULL, NULL, WS_CHILD, CRect(0, 0, 0, 0), this, NULL, 0, &context);
  355. ReparentAllChildren(pFrameOld, pFrameNew);
  356. pFrameOld->DestroyWindow();
  357. CView* pView = NULL;
  358. if (pFrameNew->GetActiveView() == NULL)
  359. {
  360. CPtrList childList;
  361. CWnd* pChild = pFrameNew->GetTopWindow();
  362. while ( pChild != NULL && pView == NULL)
  363. {
  364. ASSERT_KINDOF(CWnd, pChild);
  365. if (pChild->IsKindOf(RUNTIME_CLASS(CView)))
  366. {
  367. pView = (CView*)pChild;
  368. pFrameNew->SetActiveView(pView,FALSE);
  369. }
  370. pChild = pChild->GetNextWindow(GW_HWNDNEXT);
  371. }
  372. }
  373. ActivateDockableFrame(pFrameNew);
  374. pFrameNew->ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
  375. int nID = ++m_nCount;
  376. CXTPDockingPane* pwndPane = m_paneManager.CreatePane(
  377. nID, CRect(0, 0,200, 120), (XTPDockingPaneDirection)(RAND_S()%4), m_paneManager.GetClientPane());
  378. pwndPane->SetTitle(strTitle);
  379. CString str;
  380. pDocument->GetDocTemplate()->GetDocString(str, CDocTemplate::docName);
  381. pwndPane->SetIconID(str == _T("Bounce")? 2: 1);
  382. m_mapPanes.SetAt(nID, pFrameNew);
  383. m_MTIClientWnd.UpdateContents();
  384. }
  385. void CMainFrame::OnWindowDockable()
  386. {
  387. CFrameWnd* pFrame = GetParentDockingFrame(GetFocus());
  388. if (pFrame)
  389. {
  390. CXTPDockingPaneTabbedContainer* pContainer = (CXTPDockingPaneTabbedContainer*)pFrame->GetParent();
  391. CXTPDockingPane* pPane = pContainer->GetSelected();
  392. ASSERT(pPane);
  393. ASSERT(pPane->GetChild() == pFrame);
  394. UnDockFrame(pFrame, pPane);
  395. }
  396. else
  397. {
  398. CMDIChildWnd* pFrameOld = MDIGetActive();
  399. if (pFrameOld) DockFrame(pFrameOld);
  400. }
  401. }
  402. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  403. {
  404. if (wParam == XTP_DPN_SHOWWINDOW)
  405. {
  406. // get a pointer to the docking pane being shown.
  407. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  408. if (!pPane->IsValid())
  409. {
  410. CWnd* pWnd = NULL;
  411. if (m_mapPanes.Lookup(pPane->GetID(), pWnd))
  412. {
  413. pPane->Attach(pWnd);
  414. }
  415. }
  416. return TRUE; // handled
  417. }
  418. if (wParam == XTP_DPN_CONTEXTMENU)
  419. {
  420. XTP_DOCKINGPANE_CLICK* pClick = (XTP_DOCKINGPANE_CLICK*)lParam;
  421. CXTPDockingPane* pPopupPane = pClick->pPane;
  422. if (!pPopupPane) 
  423. return FALSE;
  424. CPoint pos;
  425. GetCursorPos(&pos);
  426. CMenu menu;
  427. VERIFY(menu.LoadMenu(IDR_POPUP_PANES));
  428. CMenu* pPopup = menu.GetSubMenu(0);
  429. pPopupPane->SetFocus();
  430. CXTPCommandBars::TrackPopupMenu(pPopup, TPM_RIGHTBUTTON, pos.x, pos.y, this);
  431. return TRUE;
  432. }
  433. if (wParam == XTP_DPN_ACTION)
  434. {
  435. XTP_DOCKINGPANE_ACTION* pAction = (XTP_DOCKINGPANE_ACTION*)lParam;
  436. if (pAction->action == xtpPaneActionActivated)
  437. {
  438. CFrameWnd* pFrame = DYNAMIC_DOWNCAST(CFrameWnd, pAction->pPane->GetChild());
  439. if (pFrame)
  440. {
  441. CDocument* pDocument = pFrame->GetActiveDocument();
  442. if (pDocument)
  443. {
  444. HMENU hMenuAlt = ((CMultiDocTemplate*)pDocument->GetDocTemplate())->m_hMenuShared;
  445. ::SendMessage(m_hWndMDIClient, WM_MDISETMENU, (WPARAM)hMenuAlt, NULL);
  446. }
  447. }
  448. return TRUE;
  449. }
  450. if (pAction->action == xtpPaneActionDeactivated)
  451. {
  452. CMDIChildWnd* pFrame = MDIGetActive();
  453. if (pFrame)
  454. {
  455. pFrame->OnUpdateFrameMenu(TRUE, pFrame, 0);
  456. }
  457. else
  458. {
  459. OnUpdateFrameMenu(0);
  460. }
  461. }
  462. return TRUE;
  463. }
  464. return FALSE;
  465. }
  466. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  467. {
  468. CFrameWnd* pFrame = GetParentDockingFrame(GetFocus());
  469. if (pFrame)
  470. {
  471. // let the view have first crack at the command
  472. if (pFrame->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  473. return TRUE;
  474. return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  475. }
  476. return CXTPMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  477. }
  478. BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
  479. {
  480. CFrameWnd* pFrame = GetParentDockingFrame(GetFocus());
  481. if (pFrame)
  482. {
  483. // let the view have first crack at the command
  484. if (AfxCallWndProc(pFrame,
  485. pFrame->m_hWnd,
  486. WM_COMMAND, wParam, lParam) != 0)
  487. return TRUE; // handled by child
  488. }
  489. return CMDIFrameWnd::OnCommand(wParam, lParam);
  490. }
  491. void CMainFrame::OnWindowHide()
  492. {
  493. CFrameWnd* pFrame = GetParentDockingFrame(GetFocus());
  494. if (pFrame)
  495. {
  496. CXTPDockingPaneTabbedContainer* pContainer = (CXTPDockingPaneTabbedContainer*)pFrame->GetParent();
  497. CXTPDockingPane* pPane = pContainer->GetSelected();
  498. pPane->Close();
  499. }
  500. else
  501. {
  502. CWnd* pActiveChildWnd = MDIGetActive(NULL);
  503. if (pActiveChildWnd)
  504. pActiveChildWnd->SendMessage(WM_COMMAND, ID_FILE_CLOSE);
  505. }
  506. }
  507. void CMainFrame::OnWindowHideall()
  508. {
  509. CXTPDockingPaneInfoList& lstPanes = m_paneManager.GetPaneList();
  510. POSITION pos = lstPanes.GetHeadPosition();
  511. while (pos)
  512. {
  513. CXTPDockingPane* pPane = lstPanes.GetNext(pos);
  514. if (!pPane->IsClosed() && !pPane->IsHidden())
  515. m_paneManager.HidePane(pPane);
  516. }
  517. }
  518. void CMainFrame::OnWindowAutohide()
  519. {
  520. CFrameWnd* pFrame = GetParentDockingFrame(GetFocus());
  521. if (pFrame)
  522. {
  523. CXTPDockingPaneTabbedContainer* pContainer = (CXTPDockingPaneTabbedContainer*)pFrame->GetParent();
  524. CXTPDockingPane* pPane = pContainer->GetSelected();
  525. pPane->Hide();
  526. }
  527. }
  528. void CMainFrame::OnUpdateWindowAutohide(CCmdUI* pCmdUI)
  529. {
  530. pCmdUI->Enable(GetParentDockingFrame(GetFocus()) != NULL);
  531. }
  532. void CMainFrame::OnUpdateWindowCloseAll(CCmdUI *pCmdUI)
  533. {
  534. pCmdUI->Enable(MDIGetActive() != NULL);
  535. }
  536. void CMainFrame::OnUpdateWindowHideall(CCmdUI* pCmdUI)
  537. {
  538. pCmdUI->Enable(m_paneManager.GetPaneList().GetCount() > 0);
  539. }
  540. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT /*lpCreateControl*/)
  541. {
  542. return FALSE;
  543. }
  544. void CMainFrame::OnCustomize()
  545. {
  546. CXTPCustomizeSheet cs(GetCommandBars());
  547. CXTPCustomizeOptionsPage pageOptions(&cs);
  548. cs.AddPage(&pageOptions);
  549. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  550. pCommands->AddCategories(IDR_MAINFRAME);
  551. pCommands->InsertAllCommandsCategory();
  552. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  553. pCommands->InsertNewMenuCategory();
  554. cs.DoModal();
  555. }
  556. void CMainFrame::OnClose()
  557. {
  558. SaveCommandBars(_T("CommandBars2"));
  559. CFrameWnd::OnClose();
  560. }