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

对话框与窗口

开发平台:

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 "DynamicPanes.h"
  22. #include "MainFrm.h"
  23. #include "SimpleForm.h"
  24. #include "SimpleListView.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMainFrame
  32. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  33. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  34. //{{AFX_MSG_MAP(CMainFrame)
  35. ON_WM_CREATE()
  36. ON_COMMAND(ID_MANAGER_CREATEFORM, OnManagerCreateform)
  37. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  38. ON_COMMAND(ID_MANAGER_CREATEEDIT, OnManagerCreateedit)
  39. ON_COMMAND(ID_MANAGER_CREATELISTCONTROL, OnManagerCreatelistcontrol)
  40. ON_COMMAND(ID_MANAGER_CREATE3INROW, OnManagerCreate3inrow)
  41. ON_COMMAND(ID_MANAGER_CREATE3INCOLUMN, OnManagerCreate3incolumn)
  42. ON_COMMAND(ID_MANAGER_CREATE3INWINDOW, OnManagerCreate3inwindow)
  43. ON_COMMAND(ID_MANAGER_HIDEALL, OnManagerHideall)
  44. ON_COMMAND(ID_MANAGER_SHOWALL, OnManagerShowall)
  45. ON_COMMAND(ID_MANAGER_DESTOYALL, OnManagerDestoyall)
  46. ON_UPDATE_COMMAND_UI(ID_MANAGER_DESTOYALL, OnUpdateManagerAll)
  47. ON_COMMAND(ID_TOOLS_ALLOWCONTEXTMENU, OnToolsAllowcontextmenu)
  48. ON_UPDATE_COMMAND_UI(ID_TOOLS_ALLOWCONTEXTMENU, OnUpdateToolsAllowcontextmenu)
  49. ON_COMMAND(ID_TOOLS_FORBIDEDITCLOSING, OnToolsForbideditclosing)
  50. ON_UPDATE_COMMAND_UI(ID_TOOLS_FORBIDEDITCLOSING, OnUpdateToolsForbideditclosing)
  51. ON_COMMAND(ID_TOOLS_FORBIDFORMCLOSING, OnToolsForbidformclosing)
  52. ON_UPDATE_COMMAND_UI(ID_TOOLS_FORBIDFORMCLOSING, OnUpdateToolsForbidformclosing)
  53. ON_COMMAND(ID_TOOLS_FORBIDLISTCLOSING, OnToolsForbidlistclosing)
  54. ON_UPDATE_COMMAND_UI(ID_TOOLS_FORBIDLISTCLOSING, OnUpdateToolsForbidlistclosing)
  55. ON_COMMAND(ID_TOOLS_THEME_OFFICE2000, OnToolsThemeOffice2000)
  56. ON_COMMAND(ID_TOOLS_THEME_OFFICE2003, OnToolsThemeOffice2003)
  57. ON_COMMAND(ID_TOOLS_THEME_OFFICEXP, OnToolsThemeOfficexp)
  58. ON_UPDATE_COMMAND_UI(ID_TOOLS_THEME_OFFICE2000, OnUpdateToolsThemeOffice2000)
  59. ON_UPDATE_COMMAND_UI(ID_TOOLS_THEME_OFFICE2003, OnUpdateToolsThemeOffice2003)
  60. ON_UPDATE_COMMAND_UI(ID_TOOLS_THEME_OFFICEXP, OnUpdateToolsThemeOfficexp)
  61. ON_UPDATE_COMMAND_UI(ID_MANAGER_SHOWALL, OnUpdateManagerAll)
  62. ON_UPDATE_COMMAND_UI(ID_MANAGER_HIDEALL, OnUpdateManagerAll)
  63. //}}AFX_MSG_MAP
  64. ON_WM_CLOSE()
  65. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  66. END_MESSAGE_MAP()
  67. static UINT indicators[] =
  68. {
  69. ID_SEPARATOR,           // status line indicator
  70. ID_INDICATOR_CAPS,
  71. ID_INDICATOR_NUM,
  72. ID_INDICATOR_SCRL,
  73. };
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CMainFrame construction/destruction
  76. CMainFrame::CMainFrame()
  77. {
  78. m_nCount = 0;
  79. m_bContextMenu = TRUE;
  80. m_bForbidEditClosing = m_bForbidFormClosing = m_bForbidListClosing = FALSE;
  81. }
  82. CMainFrame::~CMainFrame()
  83. {
  84. }
  85. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  86. {
  87. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  88. return -1;
  89. if (!m_wndStatusBar.Create(this) ||
  90. !m_wndStatusBar.SetIndicators(indicators,
  91.   sizeof(indicators)/sizeof(UINT)))
  92. {
  93. TRACE0("Failed to create status barn");
  94. return -1;      // fail to create
  95. }
  96. if (!InitCommandBars())
  97. return -1;
  98. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  99. CXTPCommandBars* pCommandBars = GetCommandBars();
  100. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  101. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  102. if (!pStandardBar ||
  103. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  104. {
  105. TRACE0("Failed to create toolbarn");
  106. return -1;
  107. }
  108. // Load the previous state for command bars.
  109. LoadCommandBars(_T("CommandBars"));
  110. m_paneManager.InstallDockingPanes(this);
  111. m_paneManager.SetTheme(xtpPaneThemeOffice);
  112. int nIDIcons[] = {1, 2, 3, 4, 5, 6};
  113. m_paneManager.SetIcons(IDB_BITMAP_ICONS, nIDIcons, 7, RGB(255, 0, 255));
  114. XTPPaintManager()->RefreshMetrics();
  115. return 0;
  116. }
  117. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  118. {
  119. if( !CFrameWnd::PreCreateWindow(cs) )
  120. return FALSE;
  121. cs.lpszClass = _T("XTPMainFrame");
  122. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  123. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  124. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  125. return TRUE;
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CMainFrame diagnostics
  129. #ifdef _DEBUG
  130. void CMainFrame::AssertValid() const
  131. {
  132. CFrameWnd::AssertValid();
  133. }
  134. void CMainFrame::Dump(CDumpContext& dc) const
  135. {
  136. CFrameWnd::Dump(dc);
  137. }
  138. #endif //_DEBUG
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CMainFrame message handlers
  141. void CMainFrame::ShowContextMenu(CPoint pos, CXTPDockingPane* pPopupPane)
  142. {
  143. if (!pPopupPane) 
  144. return;
  145. CMenu menu;
  146. VERIFY(menu.LoadMenu(IDR_POPUP_PANES));
  147. CMenu* pPopup = menu.GetSubMenu(0);
  148. if (pPopupPane->IsHidden())
  149. {
  150. pPopup->CheckMenuItem(ID_POPUP_HIDE, MF_BYCOMMAND|MF_CHECKED);
  151. }
  152. int nCommand = CXTPCommandBars::TrackPopupMenu(pPopup, TPM_RIGHTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD, pos.x, pos.y, this);
  153. switch (nCommand)
  154. {
  155. case ID_POPUP_CLOSE:
  156. pPopupPane->Close();
  157. break;
  158. case ID_POPUP_DESTROY:
  159. if (pPopupPane->GetChild())
  160. {
  161. pPopupPane->GetChild()->DestroyWindow();
  162. }
  163. m_paneManager.DestroyPane(pPopupPane);
  164. break;
  165. case ID_POPUP_HIDE:
  166. m_paneManager.ToggleAutoHide(pPopupPane);
  167. break;
  168. }
  169. }
  170. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  171. {
  172. if (wParam == XTP_DPN_SHOWWINDOW)
  173. {
  174. // get a pointer to the docking pane being shown.
  175. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  176. if (!pPane->IsValid())
  177. {
  178. CWnd* pWnd = NULL;
  179. if (m_mapPanes.Lookup(pPane->GetID(), pWnd))
  180. {
  181. pPane->Attach(pWnd);
  182. }
  183. }
  184. return TRUE; // handled
  185. }
  186. if (wParam == XTP_DPN_CONTEXTMENU)
  187. {
  188. XTP_DOCKINGPANE_CLICK* pClick = (XTP_DOCKINGPANE_CLICK*)lParam;
  189. if (m_bContextMenu && pClick->pPane) ShowContextMenu(pClick->pt, pClick->pPane);
  190. return TRUE;
  191. }
  192. if (wParam == XTP_DPN_CLOSEPANE)
  193. {
  194. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  195. CWnd* pWnd =NULL;
  196. if (!m_mapPanes.Lookup(pPane->GetID(), pWnd))
  197. return FALSE;
  198. CFrameWnd* pFrame = DYNAMIC_DOWNCAST(CFrameWnd, pWnd);
  199. if (pFrame)
  200. {
  201. CView* pView = (CView*)pFrame->GetWindow(GW_CHILD);
  202. if (pView && m_bForbidEditClosing && pView->IsKindOf(RUNTIME_CLASS(CEditView)))
  203. return XTP_ACTION_NOCLOSE;
  204. if (pView && m_bForbidListClosing && pView->IsKindOf(RUNTIME_CLASS(CSimpleListView)))
  205. return XTP_ACTION_NOCLOSE;
  206. if (pView && m_bForbidFormClosing && pView->IsKindOf(RUNTIME_CLASS(CSimpleForm)))
  207. return XTP_ACTION_NOCLOSE;
  208. }
  209. return TRUE;
  210. }
  211. return FALSE;
  212. }
  213. CXTPDockingPane* CMainFrame::CreatePane(CRuntimeClass* pNewViewClass, CString strFormat, XTPDockingPaneDirection direction, CXTPDockingPane* pNeighbour)
  214. {
  215. int nID = ++m_nCount;
  216. CXTPDockingPane* pwndPane = m_paneManager.CreatePane(
  217. nID, CRect(0, 0,200, 120), direction, pNeighbour);
  218. CString strTitle;
  219. strTitle.Format(strFormat, nID);
  220. pwndPane->SetTitle(strTitle);
  221. pwndPane->SetIconID(nID % 6 + 1);
  222. CFrameWnd* pFrame = new CFrameWnd;
  223. CCreateContext context;
  224. context.m_pNewViewClass = pNewViewClass;
  225. context.m_pCurrentDoc = GetActiveView()->GetDocument();
  226. pFrame->Create(NULL, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, NULL, 0, &context);
  227. pFrame->ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
  228. m_mapPanes.SetAt(nID, pFrame);
  229. return pwndPane;
  230. }
  231. void CMainFrame::OnManagerCreateform()
  232. {
  233. CreatePane(RUNTIME_CLASS(CSimpleForm), _T("Form %i"), xtpPaneDockRight);
  234. }
  235. void CMainFrame::OnManagerCreateedit()
  236. {
  237. CreatePane(RUNTIME_CLASS(CEditView), _T("Edit %i"), xtpPaneDockBottom);
  238. }
  239. void CMainFrame::OnManagerCreatelistcontrol()
  240. {
  241. CreatePane(RUNTIME_CLASS(CSimpleListView), _T("List %i"), xtpPaneDockLeft);
  242. }
  243. void CMainFrame::OnManagerCreate3inrow()
  244. {
  245. CXTPDockingPane* pwndPaneForm = CreatePane(RUNTIME_CLASS(CSimpleForm), _T("Form %i"), xtpPaneDockBottom);
  246. CXTPDockingPane* pwndPaneEdit = CreatePane(RUNTIME_CLASS(CEditView), _T("Edit %i"), xtpPaneDockRight, pwndPaneForm);
  247. CreatePane(RUNTIME_CLASS(CSimpleListView), _T("List %i"), xtpPaneDockRight, pwndPaneEdit);
  248. }
  249. void CMainFrame::OnManagerCreate3incolumn()
  250. {
  251. CXTPDockingPane* pwndPaneForm = CreatePane(RUNTIME_CLASS(CSimpleForm), _T("Form %i"), xtpPaneDockLeft);
  252. CXTPDockingPane* pwndPaneEdit = CreatePane(RUNTIME_CLASS(CEditView), _T("Edit %i"), xtpPaneDockBottom, pwndPaneForm);
  253. CreatePane(RUNTIME_CLASS(CSimpleListView), _T("List %i"), xtpPaneDockBottom, pwndPaneEdit);
  254. }
  255. void CMainFrame::OnManagerCreate3inwindow()
  256. {
  257. CXTPDockingPane* pwndPaneForm = CreatePane(RUNTIME_CLASS(CSimpleForm), _T("Form %i"), xtpPaneDockRight);
  258. CXTPDockingPane* pwndPaneEdit = CreatePane(RUNTIME_CLASS(CEditView), _T("Edit %i"), xtpPaneDockRight);
  259. CXTPDockingPane* pwndPaneList = CreatePane(RUNTIME_CLASS(CSimpleListView), _T("List %i"), xtpPaneDockRight);
  260. m_paneManager.AttachPane(pwndPaneEdit, pwndPaneForm);
  261. m_paneManager.AttachPane(pwndPaneList, pwndPaneForm);
  262. }
  263. void CMainFrame::OnManagerHideall()
  264. {
  265. CXTPDockingPaneInfoList& lstPanes = m_paneManager.GetPaneList();
  266. POSITION pos = lstPanes.GetHeadPosition();
  267. while (pos)
  268. {
  269. CXTPDockingPane* pPane = lstPanes.GetNext(pos);
  270. if (!pPane->IsHidden())
  271. pPane->Close();
  272. }
  273. }
  274. void CMainFrame::OnManagerShowall()
  275. {
  276. CXTPDockingPaneInfoList& lstPanes = m_paneManager.GetPaneList();
  277. POSITION pos = lstPanes.GetHeadPosition();
  278. while (pos)
  279. {
  280. CXTPDockingPane* pPane = lstPanes.GetNext(pos);
  281. if (pPane->IsClosed())
  282. m_paneManager.ShowPane(pPane);
  283. }
  284. }
  285. void CMainFrame::OnManagerDestoyall()
  286. {
  287. POSITION pos = m_mapPanes.GetStartPosition();
  288. UINT nID; CWnd* pWnd;
  289. while (pos)
  290. {
  291. m_mapPanes.GetNextAssoc(pos, nID, pWnd);
  292. pWnd->DestroyWindow();
  293. }
  294. m_mapPanes.RemoveAll();
  295. m_paneManager.DestroyAll();
  296. }
  297. void CMainFrame::OnUpdateManagerAll(CCmdUI* pCmdUI)
  298. {
  299. pCmdUI->Enable(m_paneManager.GetPaneList().GetCount() > 0);
  300. }
  301. void CMainFrame::OnToolsAllowcontextmenu()
  302. {
  303. m_bContextMenu = !m_bContextMenu;
  304. }
  305. void CMainFrame::OnUpdateToolsAllowcontextmenu(CCmdUI* pCmdUI)
  306. {
  307. pCmdUI->SetCheck(m_bContextMenu);
  308. }
  309. void CMainFrame::OnToolsForbideditclosing()
  310. {
  311. m_bForbidEditClosing = !m_bForbidEditClosing;
  312. }
  313. void CMainFrame::OnUpdateToolsForbideditclosing(CCmdUI* pCmdUI)
  314. {
  315. pCmdUI->SetCheck(m_bForbidEditClosing);
  316. }
  317. void CMainFrame::OnToolsForbidformclosing()
  318. {
  319. m_bForbidFormClosing = !m_bForbidFormClosing;
  320. }
  321. void CMainFrame::OnUpdateToolsForbidformclosing(CCmdUI* pCmdUI)
  322. {
  323. pCmdUI->SetCheck(m_bForbidFormClosing);
  324. }
  325. void CMainFrame::OnToolsForbidlistclosing()
  326. {
  327. m_bForbidListClosing = !m_bForbidListClosing;
  328. }
  329. void CMainFrame::OnUpdateToolsForbidlistclosing(CCmdUI* pCmdUI)
  330. {
  331. pCmdUI->SetCheck(m_bForbidListClosing);
  332. }
  333. void CMainFrame::OnToolsThemeOffice2000()
  334. {
  335. m_paneManager.SetTheme(xtpPaneThemeDefault);
  336. CXTPPaintManager::SetTheme(xtpThemeOffice2000);
  337. GetCommandBars()->RedrawCommandBars();
  338. }
  339. void CMainFrame::OnToolsThemeOffice2003()
  340. {
  341. m_paneManager.SetTheme(xtpPaneThemeOffice2003);
  342. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  343. GetCommandBars()->RedrawCommandBars();
  344. }
  345. void CMainFrame::OnToolsThemeOfficexp()
  346. {
  347. m_paneManager.SetTheme(xtpPaneThemeOffice);
  348. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  349. GetCommandBars()->RedrawCommandBars();
  350. }
  351. void CMainFrame::OnUpdateToolsThemeOffice2000(CCmdUI* pCmdUI)
  352. {
  353. pCmdUI->SetCheck(m_paneManager.GetCurrentTheme() == xtpPaneThemeDefault? TRUE: FALSE);
  354. }
  355. void CMainFrame::OnUpdateToolsThemeOffice2003(CCmdUI* pCmdUI)
  356. {
  357. pCmdUI->SetCheck(m_paneManager.GetCurrentTheme() == xtpPaneThemeOffice2003? TRUE: FALSE);
  358. }
  359. void CMainFrame::OnUpdateToolsThemeOfficexp(CCmdUI* pCmdUI)
  360. {
  361. pCmdUI->SetCheck(m_paneManager.GetCurrentTheme() == xtpPaneThemeOffice? TRUE: FALSE);
  362. }
  363. void CMainFrame::OnClose()
  364. {
  365. // Save the current state for command bars.
  366. SaveCommandBars(_T("CommandBars"));
  367. // TODO: Add your message handler code here and/or call default
  368. CFrameWnd::OnClose();
  369. }
  370. void CMainFrame::OnCustomize()
  371. {
  372. // get a pointer to the command bars object.
  373. CXTPCommandBars* pCommandBars = GetCommandBars();
  374. if (pCommandBars == NULL)
  375. return;
  376. // instanciate the customize dialog
  377. CXTPCustomizeSheet dlg(pCommandBars);
  378. // add the options page to the customize dialog.
  379. CXTPCustomizeOptionsPage pageOptions(&dlg);
  380. dlg.AddPage(&pageOptions);
  381. // add the commands page to the customize dialog.
  382. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  383. pPageCommands->AddCategories(IDR_MAINFRAME);
  384. // initialize the commands page page.
  385. pPageCommands->InsertAllCommandsCategory();
  386. pPageCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  387. pPageCommands->InsertNewMenuCategory();
  388. // display the customize dialog.
  389. dlg.DoModal();
  390. }