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

对话框与窗口

开发平台:

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 "TabManager.h"
  22. #include "MainFrm.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CMainFrame
  30. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  31. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  32. //{{AFX_MSG_MAP(CMainFrame)
  33. ON_WM_CREATE()
  34. ON_COMMAND(ID_VIEW_THEME_OFFICE2000, OnViewThemeOffice2000)
  35. ON_COMMAND(ID_VIEW_THEME_OFFICEXP, OnViewThemeOfficexp)
  36. ON_COMMAND(ID_VIEW_THEME_OFFICE2003, OnViewThemeOffice2003)
  37. ON_COMMAND(ID_VIEW_THEME_NATIVEXP, OnViewThemeNativexp)
  38. ON_COMMAND(ID_VIEW_THEME_WHIDBEY, OnViewThemeWhidbey)
  39. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICE2000, OnUpdateViewThemeOffice2000)
  40. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICEXP, OnUpdateViewThemeOfficexp)
  41. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICE2003, OnUpdateViewThemeOffice2003)
  42. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_NATIVEXP, OnUpdateViewThemeNativexp)
  43. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_WHIDBEY, OnUpdateViewThemeWhidbey)
  44. ON_WM_CLOSE()
  45. ON_COMMAND(ID_VIEW_SWITCH_THEME, OnSwitchTheme)
  46. ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
  47. //}}AFX_MSG_MAP
  48. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  49. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  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. /////////////////////////////////////////////////////////////////////////////
  60. // CMainFrame construction/destruction
  61. CMainFrame::CMainFrame()
  62. {
  63. }
  64. CMainFrame::~CMainFrame()
  65. {
  66. }
  67. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  68. {
  69. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  70. return -1;
  71. // Create Status bar.
  72. // Important: All control bars including the Status Bar
  73. // must be created before CommandBars....
  74. if (!m_wndStatusBar.Create(this) ||
  75. !m_wndStatusBar.SetIndicators(indicators,
  76. sizeof(indicators)/sizeof(UINT)))
  77. {
  78. TRACE0("Failed to create status barn");
  79. return -1;      // fail to create
  80. }
  81. // Initialize the command bars
  82. if (!InitCommandBars())
  83. return -1;
  84. // Get a pointer to the command bars object.
  85. CXTPCommandBars* pCommandBars = GetCommandBars();
  86. if(pCommandBars == NULL)
  87. {
  88. TRACE0("Failed to create command bars object.n");
  89. return -1;      // fail to create
  90. }
  91. // Add the menu bar
  92. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
  93. _T("Menu Bar"), IDR_MAINFRAME);
  94. if(pMenuBar == NULL)
  95. {
  96. TRACE0("Failed to create menu bar.n");
  97. return -1;      // fail to create
  98. }
  99. // Create ToolBar
  100. CXTPToolBar* pToolBar = (CXTPToolBar*)
  101. pCommandBars->Add(_T("Standard"), xtpBarTop);
  102. if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
  103. {
  104. TRACE0("Failed to create toolbarn");
  105. return -1;
  106. }
  107. m_MTIClientWnd.Attach(this, TRUE);
  108. m_paneManager.InstallDockingPanes(this);
  109. m_paneManager.SetTheme(xtpPaneThemeDefault);
  110. // Create docking panes.
  111. CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane(
  112. IDR_PANE1, CRect(0, 0,200, 120), xtpPaneDockLeft);
  113. CXTPDockingPane* pwndPane2 = m_paneManager.CreatePane(
  114. IDR_PANE2, CRect(0, 0,200, 120), xtpPaneDockTop, pwndPane1);
  115. CXTPDockingPane* pwndPane3 = m_paneManager.CreatePane(
  116. IDR_PANE3, CRect(0, 0,200, 120), xtpPaneDockLeft, pwndPane2);
  117. m_paneManager.AttachPane(pwndPane2, pwndPane1);
  118. m_paneManager.AttachPane(pwndPane3, pwndPane1);
  119. CXTPDockingPane* pwndPane4 = m_paneManager.CreatePane(
  120. IDR_PANE4, CRect(0, 0,200, 120), xtpPaneDockRight);
  121. CXTPDockingPane* pwndPane5 = m_paneManager.CreatePane(
  122. IDR_PANE5, CRect(0, 0,200, 120), xtpPaneDockBottom, pwndPane4);
  123. CXTPDockingPane* pwndPane6 = m_paneManager.CreatePane(
  124. IDR_PANE6, CRect(0, 0,200, 120), xtpPaneDockBottom, pwndPane5);
  125. pwndPane6->SetIconID(IDR_PANE1);
  126. m_paneManager.AttachPane(pwndPane5, pwndPane4);
  127. m_paneManager.AttachPane(pwndPane6, pwndPane4);
  128. m_paneManager.HidePane(pwndPane6);
  129. // Set the icons for the docking pane tabs.
  130. int nIDs1[] = {IDR_PANE1, IDR_PANE2, IDR_PANE3, IDR_PANE4, IDR_PANE5};
  131. m_paneManager.SetIcons(IDB_BITMAP1, nIDs1, 5, RGB(0, 255, 0));
  132. m_wndProperties.Create(this);
  133. m_wndProperties.CenterWindow(this);
  134. m_wndProperties.ShowWindow(SW_SHOW);
  135. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  136. // Load the previous state for command bars.
  137. LoadCommandBars(_T("CommandBars"));
  138. return 0;
  139. }
  140. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  141. {
  142. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  143. return FALSE;
  144. cs.lpszClass = _T("XTPMainFrame");
  145. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  146. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  147. return TRUE;
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. // CMainFrame diagnostics
  151. #ifdef _DEBUG
  152. void CMainFrame::AssertValid() const
  153. {
  154. CMDIFrameWnd::AssertValid();
  155. }
  156. void CMainFrame::Dump(CDumpContext& dc) const
  157. {
  158. CMDIFrameWnd::Dump(dc);
  159. }
  160. #endif //_DEBUG
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CMainFrame message handlers
  163. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  164. {
  165. if (wParam == XTP_DPN_SHOWWINDOW)
  166. {
  167. // get a pointer to the docking pane being shown.
  168. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  169. if (!pPane->IsValid())
  170. {
  171. int nIndex = pPane->GetID() - IDR_PANE1;
  172. ASSERT(nIndex >=0 &&  nIndex < sizeof(m_wndPanes) / sizeof(m_wndPanes[0]));
  173. // create and attach the edit control for this pane.
  174. if (!::IsWindow(m_wndPanes[nIndex].m_hWnd))
  175. {
  176. if (!m_wndPanes[nIndex].CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""),
  177. WS_CHILD|ES_AUTOVSCROLL|ES_MULTILINE, CRect(0, 0,200, 120), this, 0))
  178. {
  179. TRACE0( "Error creating pane edit control.n" );
  180. }
  181. //AdjustStyle(GetDockingPaneManager()->GetCurrentTheme());
  182. }
  183. pPane->Attach(&m_wndPanes[nIndex]);
  184. }
  185. return TRUE; // handled
  186. }
  187. return FALSE;
  188. }
  189. void CMainFrame::OnThemeChanged()
  190. {
  191. GetCommandBars()->RedrawCommandBars();
  192. m_paneManager.RedrawPanes();
  193. m_MTIClientWnd.UpdateContents();
  194. m_wndProperties.UpdateAll();
  195. }
  196. void CMainFrame::OnSwitchTheme()
  197. {
  198. switch(XTPPaintManager()->GetCurrentTheme())
  199. {
  200. case xtpThemeOffice2000:
  201. OnViewThemeOfficexp();
  202. break;
  203. case xtpThemeOfficeXP:
  204. OnViewThemeOffice2003();
  205. break;
  206. case xtpThemeOffice2003:
  207. OnViewThemeNativexp();
  208. break;
  209. case xtpThemeNativeWinXP:
  210. OnViewThemeWhidbey();
  211. break;
  212. case xtpThemeWhidbey:
  213. OnViewThemeOffice2000();
  214. break;
  215. }
  216. }
  217. void CMainFrame::OnViewThemeOffice2000()
  218. {
  219. CXTPPaintManager::SetTheme(xtpThemeOffice2000);
  220. m_paneManager.SetTheme(xtpPaneThemeDefault);
  221. OnThemeChanged();
  222. }
  223. void CMainFrame::OnViewThemeOfficexp()
  224. {
  225. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  226. m_paneManager.SetTheme(xtpPaneThemeOffice);
  227. OnThemeChanged();
  228. }
  229. void CMainFrame::OnViewThemeOffice2003()
  230. {
  231. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  232. m_paneManager.SetTheme(xtpPaneThemeOffice2003);
  233. OnThemeChanged();
  234. }
  235. void CMainFrame::OnViewThemeNativexp()
  236. {
  237. CXTPPaintManager::SetTheme(xtpThemeNativeWinXP);
  238. m_paneManager.SetTheme(xtpPaneThemeNativeWinXP);
  239. OnThemeChanged();
  240. }
  241. void CMainFrame::OnViewThemeWhidbey()
  242. {
  243. CXTPPaintManager::SetTheme(xtpThemeWhidbey);
  244. m_paneManager.SetTheme(xtpPaneThemeVisualStudio2005);
  245. OnThemeChanged();
  246. }
  247. void CMainFrame::OnUpdateViewThemeOffice2000(CCmdUI* pCmdUI)
  248. {
  249. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2000);
  250. }
  251. void CMainFrame::OnUpdateViewThemeOfficexp(CCmdUI* pCmdUI)
  252. {
  253. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOfficeXP);
  254. }
  255. void CMainFrame::OnUpdateViewThemeOffice2003(CCmdUI* pCmdUI)
  256. {
  257. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003);
  258. }
  259. void CMainFrame::OnUpdateViewThemeNativexp(CCmdUI* pCmdUI)
  260. {
  261. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeNativeWinXP);
  262. }
  263. void CMainFrame::OnUpdateViewThemeWhidbey(CCmdUI* pCmdUI)
  264. {
  265. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeWhidbey);
  266. }
  267. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  268. {
  269. if (lpCreateControl->bToolBar)
  270. {
  271. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  272. if (!pToolBar)
  273. return FALSE;
  274. if (lpCreateControl->nID == ID_VIEW_SWITCH_THEME)
  275. {
  276. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  277. lpCreateControl->buttonStyle = xtpButtonIconAndCaption;
  278. return TRUE;
  279. }
  280. if (lpCreateControl->nID == ID_VIEW_PROPERTIES)
  281. {
  282. lpCreateControl->buttonStyle = xtpButtonIconAndCaption;
  283. return TRUE;
  284. }
  285. }
  286. return FALSE;
  287. }
  288. void CMainFrame::OnClose()
  289. {
  290. // Save the current state for command bars.
  291. SaveCommandBars(_T("CommandBars"));
  292. // TODO: Add your message handler code here and/or call default
  293. CMDIFrameWnd::OnClose();
  294. }
  295. void CMainFrame::OnCustomize()
  296. {
  297. // get a pointer to the command bars object.
  298. CXTPCommandBars* pCommandBars = GetCommandBars();
  299. if (pCommandBars == NULL)
  300. return;
  301. // instanciate the customize dialog
  302. CXTPCustomizeSheet dlg(pCommandBars);
  303. // add the options page to the customize dialog.
  304. CXTPCustomizeOptionsPage pageOptions(&dlg);
  305. dlg.AddPage(&pageOptions);
  306. // add the commands page to the customize dialog.
  307. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  308. pPageCommands->AddCategories(IDR_TABMANTYPE);
  309. // initialize the commands page page.
  310. pPageCommands->InsertAllCommandsCategory();
  311. pPageCommands->InsertBuiltInMenus(IDR_TABMANTYPE);
  312. pPageCommands->InsertNewMenuCategory();
  313. // display the customize dialog.
  314. dlg.DoModal();
  315. }
  316. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  317. {
  318. // Toggle CommandBars
  319. GetCommandBars()->OnSetPreviewMode(bPreview);
  320. // Toggle Tab Client
  321. m_MTIClientWnd.ShowWorkspace(!bPreview);
  322. // Toggle Docking Panes.
  323. m_paneManager.OnSetPreviewMode(bPreview);
  324. CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
  325. }
  326. void CMainFrame::OnViewProperties() 
  327. {
  328. if (!m_wndProperties.IsWindowVisible())
  329. {
  330. m_wndProperties.ShowWindow(SW_SHOW);
  331. }
  332. }