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

对话框与窗口

开发平台:

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 "CommandBarsDesigner.h"
  22. #include "MainFrm.h"
  23. #include "CommandBarsDesignerDoc.h"
  24. #include "CommandBarsDesignerView.h"
  25. #include "ChildFrm.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMainFrame
  33. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  34. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  35. //{{AFX_MSG_MAP(CMainFrame)
  36. ON_WM_CREATE()
  37. ON_WM_DESTROY()
  38. ON_WM_CLOSE()
  39. ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
  40. ON_COMMAND(ID_VIEW_ACCELERATORS, OnViewAccelerators)
  41. ON_COMMAND(ID_VIEW_CONTROLSPANE, OnViewControlspane)
  42. ON_COMMAND(ID_VIEW_ICONSPANE, OnViewIconspane)
  43. ON_COMMAND(ID_VIEW_TOOLBARSPANE, OnViewToolbarspane)
  44. ON_COMMAND(ID_VIEW_LIBRARY, OnViewLibrary)
  45. ON_COMMAND(ID_FILE_IMPORT_XMLDOCUMENT, OnFileImportXmldocument)
  46. ON_UPDATE_COMMAND_UI(ID_FILE_IMPORT_XMLDOCUMENT, OnUpdateFileImportXmldocument)
  47. //}}AFX_MSG_MAP
  48. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  49. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  50. ON_XTP_CREATECONTROL()
  51. END_MESSAGE_MAP()
  52. static UINT indicators[] =
  53. {
  54. ID_SEPARATOR,           // status line indicator
  55. ID_INDICATOR_CAPS,
  56. ID_INDICATOR_NUM,
  57. ID_INDICATOR_SCRL,
  58. };
  59. static int nIDPaneIcons[] =
  60. {
  61. IDR_PANE_TOOLBARS, IDR_PANE_PROPERTIES, IDR_PANE_CONTROLS, IDR_PANE_ACCELERATORS, IDR_PANE_ICONS
  62. };
  63. static UINT nIDCommandsIcons[] =
  64. {
  65. ID_VIEW_TOOLBARSPANE, ID_VIEW_PROPERTIES, ID_VIEW_CONTROLSPANE, ID_VIEW_ACCELERATORS, ID_VIEW_ICONSPANE
  66. };
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CMainFrame construction/destruction
  69. CMainFrame::CMainFrame()
  70. {
  71. m_pActiveCommandBars = NULL;
  72. m_pActivePane = NULL;
  73. }
  74. CMainFrame::~CMainFrame()
  75. {
  76. }
  77. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  78. {
  79. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  80. return -1;
  81. if (!m_wndStatusBar.Create(this) ||
  82. !m_wndStatusBar.SetIndicators(indicators,
  83. sizeof(indicators)/sizeof(UINT)))
  84. {
  85. TRACE0("Failed to create status barn");
  86. return -1;      // fail to create
  87. }
  88. if (!InitCommandBars())
  89. return -1;
  90. CXTPPaintManager::SetTheme(xtpThemeWhidbey);
  91. CXTPCommandBars* pCommandBars = GetCommandBars();
  92. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  93. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage|xtpFlagHideMaximizeBox|xtpFlagHideMinimizeBox);
  94. CXTPImageManager* pImageManager = pCommandBars->GetImageManager();
  95. pImageManager->SetMaskColor(RGB(0, 0xFF, 0));
  96. CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  97. if (!pCommandBar ||
  98. !pCommandBar->LoadToolBar(IDR_MAINFRAME))
  99. {
  100. TRACE0("Failed to create toolbarn");
  101. return -1;
  102. }
  103. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  104. pImageManager->SetIcons(IDB_BITMAP_PANEICONS, nIDCommandsIcons, _countof(nIDCommandsIcons), CSize(16, 16));
  105. if (pImageManager->IsAlphaIconsSupported())
  106. {
  107. pImageManager->SetIcons(IDR_MAINFRAME, IDR_TOOLBAR_ALPHA);
  108. }
  109. m_paneManager.InstallDockingPanes(this);
  110. m_paneManager.SetTheme(xtpPaneThemeVisualStudio2005);
  111. // Create docking panes.
  112. CXTPDockingPane* pPaneToolbars = m_paneManager.CreatePane(
  113. IDR_PANE_TOOLBARS, CRect(0, 0,200, 120), xtpPaneDockRight);
  114. CXTPDockingPane* pPaneControls = m_paneManager.CreatePane(
  115. IDR_PANE_CONTROLS, CRect(0, 0,200, 120), xtpPaneDockRight);
  116. m_paneManager.AttachPane(pPaneControls, pPaneToolbars);
  117. m_paneManager.CreatePane(
  118. IDR_PANE_PROPERTIES, CRect(0, 0,200, 120), xtpPaneDockBottom, pPaneToolbars);
  119. CXTPDockingPane* pPaneAccelerators = m_paneManager.CreatePane(
  120. IDR_PANE_ACCELERATORS, CRect(0, 0,200, 120), xtpPaneDockLeft);
  121. CXTPDockingPane* pPaneIcons= m_paneManager.CreatePane(
  122. IDR_PANE_ICONS, CRect(0, 0,200, 120), xtpPaneDockLeft, pPaneAccelerators);
  123. CXTPDockingPane* pPaneLibrary = m_paneManager.CreatePane(
  124. IDR_PANE_LIBRARY, CRect(0, 0,200, 120), xtpPaneDockBottom, pPaneIcons);
  125. m_paneManager.AttachPane(pPaneAccelerators, pPaneIcons);
  126. pPaneAccelerators->Hide();
  127. pPaneLibrary->Hide();
  128. m_paneManager.SetIcons(IDB_BITMAP_PANEICONS, nIDPaneIcons, _countof(nIDPaneIcons), RGB(0, 255, 0));
  129. VERIFY(m_MTIClientWnd.Attach(this));
  130. m_MTIClientWnd.SetFlags(xtpWorkspaceHideArrowsAlways|xtpWorkspaceShowActiveFiles);
  131. // Load the previous state for docking panes.
  132. CXTPDockingPaneLayout layoutNormal(&m_paneManager);
  133. if (layoutNormal.Load(_T("StandardLayout")))
  134. {
  135. if (layoutNormal.GetPaneList().GetCount() == 6)
  136. {
  137. m_paneManager.SetLayout(&layoutNormal);
  138. }
  139. }
  140. m_paneManager.SetAlphaDockingContext(TRUE);
  141. m_paneManager.SetShowDockingContextStickers(TRUE);
  142. m_paneManager.SetDockingContextStickerStyle(xtpPaneStickerStyleVisualStudio2005);
  143. m_paneManager.SetShowContentsWhileDragging();
  144. // Load the previous state for toolbars and menus.
  145. LoadCommandBars(_T("CommandBars2"));
  146. return 0;
  147. }
  148. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  149. {
  150. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  151. return FALSE;
  152. cs.lpszClass = _T("XTPMainFrame");
  153. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  154. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  155. return TRUE;
  156. }
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CMainFrame diagnostics
  159. #ifdef _DEBUG
  160. void CMainFrame::AssertValid() const
  161. {
  162. CMDIFrameWnd::AssertValid();
  163. }
  164. void CMainFrame::Dump(CDumpContext& dc) const
  165. {
  166. CMDIFrameWnd::Dump(dc);
  167. }
  168. #endif //_DEBUG
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CMainFrame message handlers
  171. void CMainFrame::OnDestroy()
  172. {
  173. //m_MTIClientWnd.Detach();
  174. CMDIFrameWnd::OnDestroy();
  175. }
  176. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  177. {
  178. if (wParam == XTP_DPN_ACTION)
  179. {
  180. XTP_DOCKINGPANE_ACTION* pAction = (XTP_DOCKINGPANE_ACTION*)lParam;
  181. if (pAction->action == xtpPaneActionDocked || pAction->action == xtpPaneActionExpanding)
  182. {
  183. XTPMouseManager()->SendTrackLost();
  184. }
  185. }
  186. if (wParam == XTP_DPN_SHOWWINDOW)
  187. {
  188. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  189. if (!pPane->IsValid())
  190. {
  191. switch (pPane->GetID())
  192. {
  193. case IDR_PANE_TOOLBARS:
  194. {
  195. if (m_paneToolbars.GetSafeHwnd() == 0)
  196. {
  197. m_paneToolbars.Create(_T("STATIC"), NULL, WS_CHILD, CRect(0, 0, 0, 0), this, 0);
  198. }
  199. pPane->Attach(&m_paneToolbars);
  200. break;
  201. }
  202. case IDR_PANE_PROPERTIES:
  203. {
  204. if (m_paneProperties.GetSafeHwnd() == 0)
  205. {
  206. m_paneProperties.Create(_T("STATIC"), NULL, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  207. XTPMouseManager()->AddTrustedWindow(m_paneProperties);
  208. }
  209. pPane->Attach(&m_paneProperties);
  210. break;
  211. }
  212. case IDR_PANE_CONTROLS:
  213. {
  214. if (m_paneControls.GetSafeHwnd() == 0)
  215. {
  216. m_paneControls.Create(_T("STATIC"), NULL, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  217. }
  218. pPane->Attach(&m_paneControls);
  219. break;
  220. }
  221. case IDR_PANE_ACCELERATORS:
  222. {
  223. if (m_paneAccelerators.GetSafeHwnd() == 0)
  224. {
  225. m_paneAccelerators.Create(_T("STATIC"), NULL, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  226. }
  227. pPane->Attach(&m_paneAccelerators);
  228. break;
  229. }
  230. case IDR_PANE_ICONS:
  231. {
  232. if (m_paneIcons.GetSafeHwnd() == 0)
  233. {
  234. m_paneIcons.Create(_T("STATIC"), NULL, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  235. }
  236. pPane->Attach(&m_paneIcons);
  237. break;
  238. }
  239. case IDR_PANE_LIBRARY:
  240. {
  241. if (m_paneLibrary.GetSafeHwnd() == 0)
  242. {
  243. m_paneLibrary.Create(_T("STATIC"), NULL, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  244. }
  245. pPane->Attach(&m_paneLibrary);
  246. break;
  247. }
  248. }
  249. RefreshPanes();
  250. }
  251. return TRUE;
  252. }
  253. return FALSE;
  254. }
  255. void CMainFrame::RefreshPanes(BOOL bForceAll)
  256. {
  257. if (!AfxGetMainWnd())
  258. return;
  259. if (m_pActiveCommandBars != GetActiveCommandBars())
  260. {
  261. m_pActivePane = NULL;
  262. m_pActiveCommandBars = GetActiveCommandBars();
  263. }
  264. if (m_paneToolbars.GetSafeHwnd()) m_paneToolbars.Refresh();
  265. if (m_paneProperties.GetSafeHwnd()) m_paneProperties.Refresh(m_pActivePane);
  266. if (m_paneControls.GetSafeHwnd()) m_paneControls.Refresh(bForceAll);
  267. if (m_paneAccelerators.GetSafeHwnd()) m_paneAccelerators.Refresh(bForceAll);
  268. if (m_paneIcons.GetSafeHwnd()) m_paneIcons.Refresh(bForceAll);
  269. }
  270. CEmbeddedFrame* CMainFrame::GetActiveEmbeddedFrame()
  271. {
  272. CChildFrame* pChildFrame = DYNAMIC_DOWNCAST(CChildFrame, GetActiveFrame());
  273. if (!pChildFrame)
  274. return NULL;
  275. CCommandBarsDesignerDesignerView* pView = DYNAMIC_DOWNCAST(CCommandBarsDesignerDesignerView, pChildFrame->GetActiveView());
  276. if (!pView)
  277. return NULL;
  278. return  DYNAMIC_DOWNCAST(CEmbeddedFrame, pView->m_pFrame);
  279. }
  280. CXTPCommandBars* CMainFrame::GetActiveCommandBars()
  281. {
  282. CEmbeddedFrame* pFrame = GetActiveEmbeddedFrame();
  283. return pFrame? pFrame->GetCommandBars(): NULL;
  284. }
  285. void CMainFrame::OnClose()
  286. {
  287. CXTPDockingPaneLayout layoutNormal(&m_paneManager);
  288. m_paneManager.GetLayout(&layoutNormal);
  289. layoutNormal.Save(_T("StandardLayout"));
  290. // Save the current state for toolbars and menus.
  291. SaveCommandBars(_T("CommandBars2"));
  292. CMDIFrameWnd::OnClose();
  293. }
  294. void CMainFrame::OnViewProperties()
  295. {
  296. m_paneManager.ShowPane(IDR_PANE_PROPERTIES);
  297. }
  298. void CMainFrame::OnViewAccelerators()
  299. {
  300. m_paneManager.ShowPane(IDR_PANE_ACCELERATORS);
  301. }
  302. void CMainFrame::OnViewControlspane()
  303. {
  304. m_paneManager.ShowPane(IDR_PANE_CONTROLS);
  305. }
  306. void CMainFrame::OnViewIconspane()
  307. {
  308. m_paneManager.ShowPane(IDR_PANE_ICONS);
  309. }
  310. void CMainFrame::OnViewToolbarspane()
  311. {
  312. m_paneManager.ShowPane(IDR_PANE_TOOLBARS);
  313. }
  314. void CMainFrame::OnViewLibrary()
  315. {
  316. m_paneManager.ShowPane(IDR_PANE_LIBRARY);
  317. }
  318. void CMainFrame::OnCustomize()
  319. {
  320. // Get a pointer to the command bars object.
  321. CXTPCommandBars* pCommandBars = GetCommandBars();
  322. if(pCommandBars != NULL)
  323. {
  324. // Instanciate the customize dialog object.
  325. CXTPCustomizeSheet dlg(pCommandBars);
  326. // Add the options page to the customize dialog.
  327. CXTPCustomizeOptionsPage pageOptions(&dlg);
  328. dlg.AddPage(&pageOptions);
  329. // Add the commands page to the customize dialog.
  330. CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();
  331. pCommands->AddCategories(IDR_MAINFRAME);
  332. // Use the command bar manager to initialize the
  333. // customize dialog.
  334. pCommands->InsertAllCommandsCategory();
  335. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  336. pCommands->InsertNewMenuCategory();
  337. // Display the dialog.
  338. dlg.DoModal();
  339. }
  340. }
  341. void CMainFrame::OnFileImportXmldocument()
  342. {
  343. CString strFilter = _T("XML Document(*.xml)|*.xml|All files (*.*)|*.*||");
  344. CFileDialog fd(TRUE, _T("xml"), NULL, OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, strFilter);
  345. if (fd.DoModal() != IDOK)
  346. return;
  347. CXTPPropExchangeXMLNode px(TRUE, NULL, _T("DesignerFile"));
  348. if (!px.LoadFromFile(fd.GetPathName()))
  349. return;
  350. if (!px.OnBeforeExchange())
  351. {
  352. AfxMessageBox(_T("<DesignerFile> node not found"));
  353. return;
  354. }
  355. CDocument* pDocument = ((CCommandBarsDesignerApp*)AfxGetApp())->m_pDocTemplate->OpenDocumentFile(NULL);
  356. POSITION pos = pDocument->GetFirstViewPosition();
  357. CCommandBarsDesignerView* pView = (CCommandBarsDesignerView*)pDocument->GetNextView(pos);
  358. CEmbeddedFrame* pFrame = pView->GetEmbeddedFrame();
  359. pFrame->DoPropExchange(&px);
  360. pView->OnInitialUpdate();
  361. RefreshPanes(TRUE);
  362. }
  363. void CMainFrame::OnUpdateFileImportXmldocument(CCmdUI* pCmdUI)
  364. {
  365. pCmdUI->Enable(IsXMLEngineAvailable());
  366. }
  367. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  368. {
  369. if (lpCreateControl->nID == ID_DESIGN_MODE )
  370. {
  371. lpCreateControl->buttonStyle= xtpButtonIconAndCaption;
  372. return TRUE;
  373. }
  374. if (lpCreateControl->nID == ID_FILE_NEW && lpCreateControl->bToolBar)
  375. {
  376. CXTPControlPopup* pControl = CXTPControlPopup::CreateControlPopup(xtpControlSplitButtonPopup);
  377. CMenu mnu;
  378. mnu.LoadMenu(IDR_MENU_NEW);
  379. pControl->SetCommandBar(mnu.GetSubMenu(0));
  380. lpCreateControl->pControl = pControl;
  381. return TRUE;
  382. }
  383. return FALSE;
  384. }