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 "GUI_Eclipse.h"
  22. #include <math.h>
  23. #include "MainFrm.h"
  24. #include "AppearanceSetEclipse.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_DYNAMIC(CMainFrame, CMDIFrameWnd)
  33. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  34. //{{AFX_MSG_MAP(CMainFrame)
  35. ON_WM_CREATE()
  36. ON_COMMAND(ID_RUN_EXTERNALTOOLS, OnEmptyCommand)
  37. ON_COMMAND(ID_VIEW_BASETHEME_OFFICE2000, OnViewBasethemeOffice2000)
  38. ON_COMMAND(ID_VIEW_BASETHEME_OFFICEXP, OnViewBasethemeOfficexp)
  39. ON_COMMAND(ID_VIEW_BASETHEME_OFFICE2003, OnViewBasethemeOffice2003)
  40. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  41. ON_WM_CLOSE()
  42. //}}AFX_MSG_MAP
  43. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  44. ON_XTP_CREATECONTROL()
  45. END_MESSAGE_MAP()
  46. static UINT indicators[] =
  47. {
  48. ID_SEPARATOR,           // status line indicator
  49. ID_INDICATOR_CAPS,
  50. ID_INDICATOR_NUM,
  51. ID_INDICATOR_SCRL,
  52. };
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CMainFrame construction/destruction
  55. CMainFrame::CMainFrame()
  56. {
  57. m_ilIcons.Create(IDB_PANEICONS, 16, 1, RGB(0, 0xFF, 0));
  58. }
  59. CMainFrame::~CMainFrame()
  60. {
  61. }
  62. void CreateGreyBitmap(UINT nID, CBitmap& bmp)
  63. {
  64. if (!bmp.LoadBitmap(nID))
  65. return;
  66. CXTPCompatibleDC dc(NULL, &bmp);
  67. BITMAP bitmap;
  68. bmp.GetObject(sizeof (BITMAP), &bitmap);
  69. COLORREF clrMask = dc.GetPixel(0, 0);
  70. for(int i = 0; i < bitmap.bmWidth; i++)
  71. for(int j = 0; j < bitmap.bmHeight; j++)
  72. {
  73. COLORREF clr = dc.GetPixel(i, j);
  74. if (clr != clrMask)
  75. {
  76. double dGray = GetRValue(clr) * 0.299 + GetGValue(clr) * 0.587 + GetBValue(clr) * 0.114;
  77. int nGray = (BYTE)(pow(dGray / 255.0, 0.9) * 255.0);
  78. dc.SetPixel(i, j, RGB(nGray, nGray, nGray));
  79. }
  80. }
  81. }
  82. void CMainFrame::AddIcons(UINT nID)
  83. {
  84. CBitmap bmp;
  85. CreateGreyBitmap(nID, bmp);
  86. XTPImageManager()->SetIcons(nID, bmp);
  87. CBitmap bmpHot;
  88. bmpHot.LoadBitmap(nID);
  89. XTPImageManager()->SetIcons(nID, bmpHot, xtpImageHot);
  90. }
  91. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  92. {
  93. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  94. return -1;
  95. if (!m_wndStatusBar.Create(this) ||
  96. !m_wndStatusBar.SetIndicators(indicators,
  97.   sizeof(indicators)/sizeof(UINT)))
  98. {
  99. TRACE0("Failed to create status barn");
  100. return -1;      // fail to create
  101. }
  102. if (!InitCommandBars())
  103. return -1;
  104. CXTPPaintManager::SetCustomTheme(new CEclipseCommandBarsPaintManager<CXTPOfficeTheme>);
  105. CXTPCommandBars* pCommandBars = GetCommandBars();
  106. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  107. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  108. if (!pStandardBar ||
  109. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  110. {
  111. TRACE0("Failed to create toolbarn");
  112. return -1;
  113. }
  114. XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
  115. XTPPaintManager()->GetIconsInfo()->bUseDisabledIcons = TRUE;
  116. XTPPaintManager()->GetIconsInfo()->bIconsWithShadow = FALSE;
  117. CXTPImageManager::m_dDisabledBrightnessFactor = 0.3;
  118. AddIcons(IDR_MAINFRAME);
  119. AddIcons(IDR_EXTENDED);
  120. m_MTIClientWnd.Attach(this);
  121. m_MTIClientWnd.SetPaintManager(new CEclipseTabPaintManager());
  122. //////////////////////////////////////////////////////////////////////////
  123. m_paneManager.InstallDockingPanes(this);
  124. // Create docking panes.
  125. CXTPDockingPane* pPaneNavigator = m_paneManager.CreatePane(
  126. ID_PANE_NAVIGATOR, CRect(0, 0,220, 120), xtpPaneDockLeft);
  127. CXTPDockingPane* pPaneTasks = m_paneManager.CreatePane(
  128. ID_PANE_TASKS, CRect(0, 0,220, 120), xtpPaneDockTop, pPaneNavigator);
  129. CXTPDockingPane* pPaneOutline = m_paneManager.CreatePane(
  130. ID_PANE_OUTLINE, CRect(0, 0,220, 120), xtpPaneDockLeft, pPaneNavigator);
  131. m_paneManager.AttachPane(pPaneTasks, pPaneNavigator);
  132. m_paneManager.AttachPane(pPaneOutline, pPaneNavigator);
  133. m_paneManager.CreatePane(ID_PANE_BOOKMARKS, CRect(0, 0,220, 120), xtpPaneDockBottom, pPaneNavigator);
  134. pPaneNavigator->Select();
  135. m_paneManager.SetCustomTheme(new CEclipseDockingPanePaintManager<CXTPDockingPaneOfficeTheme>());
  136. int nIDPanes[] = {ID_PANE_NAVIGATOR, ID_PANE_BOOKMARKS, ID_PANE_TASKS, ID_PANE_OUTLINE};
  137. m_paneManager.SetIcons(IDB_PANEICONS, nIDPanes, 4, RGB(0, 255, 0));
  138. RecalcLayout();
  139. // Load the previous state for command bars.
  140. LoadCommandBars(_T("CommandBars"));
  141. return 0;
  142. }
  143. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  144. {
  145. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  146. return FALSE;
  147. cs.lpszClass = _T("XTPMainFrame");
  148. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  149. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  150. return TRUE;
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CMainFrame diagnostics
  154. #ifdef _DEBUG
  155. void CMainFrame::AssertValid() const
  156. {
  157. CMDIFrameWnd::AssertValid();
  158. }
  159. void CMainFrame::Dump(CDumpContext& dc) const
  160. {
  161. CMDIFrameWnd::Dump(dc);
  162. }
  163. #endif //_DEBUG
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CMainFrame message handlers
  166. void CMainFrame::OnEmptyCommand()
  167. {
  168. // TODO: Add your command handler code here
  169. }
  170. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  171. {
  172. if (lpCreateControl->bToolBar)
  173. {
  174. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  175. if (!pToolBar)
  176. return FALSE;
  177. if (lpCreateControl->nID == ID_RUN_EXTERNALTOOLS)
  178. {
  179. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  180. return TRUE;
  181. }
  182. if (lpCreateControl->nID == ID_FILE_NEW_PROJECT)
  183. {
  184. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  185. return TRUE;
  186. }
  187. if (lpCreateControl->nID == ID_EDIT_SEARCH)
  188. {
  189. lpCreateControl->buttonStyle = xtpButtonIconAndCaption;
  190. return TRUE;
  191. }
  192. }
  193. return FALSE;
  194. }
  195. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  196. {
  197. if (wParam == XTP_DPN_SHOWWINDOW)
  198. {
  199. // get a pointer to the docking pane being shown.
  200. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  201. if (!pPane->IsValid())
  202. {
  203. switch(pPane->GetID())
  204. {
  205. case ID_PANE_NAVIGATOR:
  206. if (!::IsWindow(m_wndNavigator.m_hWnd))
  207. {
  208. if (!m_wndNavigator.Create(this))
  209. {
  210. TRACE0( "Error creating pane edit control.n" );
  211. }
  212. m_wndNavigator.SetHostParams(pPane->GetID(), m_ilIcons.ExtractIcon(0));
  213. }
  214. pPane->Attach(&m_wndNavigator);
  215. break;
  216. case ID_PANE_OUTLINE:
  217. if (!::IsWindow(m_wndOutline.m_hWnd))
  218. {
  219. if (!m_wndOutline.Create(this))
  220. {
  221. TRACE0( "Error creating pane edit control.n" );
  222. }
  223. m_wndOutline.SetHostParams(pPane->GetID(), m_ilIcons.ExtractIcon(3));
  224. }
  225. pPane->Attach(&m_wndOutline);
  226. break;
  227. case ID_PANE_TASKS:
  228. if (!::IsWindow(m_wndTasks.m_hWnd))
  229. {
  230. if (!m_wndTasks.Create(this))
  231. {
  232. TRACE0( "Error creating pane edit control.n" );
  233. }
  234. m_wndTasks.SetHostParams(pPane->GetID(), m_ilIcons.ExtractIcon(2));
  235. }
  236. pPane->Attach(&m_wndTasks);
  237. break;
  238. case ID_PANE_BOOKMARKS:
  239. if (!::IsWindow(m_wndBookmarks.m_hWnd))
  240. {
  241. if (!m_wndBookmarks.Create(this))
  242. {
  243. TRACE0( "Error creating pane edit control.n" );
  244. }
  245. m_wndBookmarks.SetHostParams(pPane->GetID(), m_ilIcons.ExtractIcon(1));
  246. }
  247. pPane->Attach(&m_wndBookmarks);
  248. break;
  249. }
  250. }
  251. return TRUE; // handled
  252. }
  253. return FALSE;
  254. }
  255. void CMainFrame::OnThemeChanged()
  256. {
  257. XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
  258. XTPPaintManager()->GetIconsInfo()->bUseDisabledIcons = TRUE;
  259. XTPPaintManager()->GetIconsInfo()->bIconsWithShadow = FALSE;
  260. m_paneManager.GetPaintManager()->RefreshMetrics();
  261. m_MTIClientWnd.GetPaintManager()->RefreshMetrics();
  262. GetCommandBars()->RedrawCommandBars();
  263. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_ALLCHILDREN);
  264. }
  265. void CMainFrame::OnViewBasethemeOffice2000()
  266. {
  267. CXTPPaintManager::SetCustomTheme(new CEclipseCommandBarsPaintManager<CXTPDefaultTheme>);
  268. m_paneManager.SetCustomTheme(new CEclipseDockingPanePaintManager<CXTPDockingPaneDefaultTheme>);
  269. m_paneManager.GetPaintManager()->GetPanelPaintManager()->SetAppearance(xtpTabAppearanceStateButtons);
  270. m_paneManager.GetPaintManager()->GetPanelPaintManager()->SetColor(xtpTabColorDefault);
  271. OnThemeChanged();
  272. }
  273. void CMainFrame::OnViewBasethemeOfficexp()
  274. {
  275. CXTPPaintManager::SetCustomTheme(new CEclipseCommandBarsPaintManager<CXTPOfficeTheme>);
  276. m_paneManager.SetCustomTheme(new CEclipseDockingPanePaintManager<CXTPDockingPaneOfficeTheme>);
  277. m_paneManager.GetPaintManager()->GetPanelPaintManager()->SetAppearance(xtpTabAppearanceFlat);
  278. OnThemeChanged();
  279. }
  280. void CMainFrame::OnViewBasethemeOffice2003()
  281. {
  282. CXTPPaintManager::SetCustomTheme(new CEclipseCommandBarsPaintManager<CXTPOffice2003Theme>);
  283. m_paneManager.SetCustomTheme(new CEclipseDockingPanePaintManager<CXTPDockingPaneOffice2003Theme>);
  284. m_paneManager.GetPaintManager()->GetPanelPaintManager()->SetAppearance(xtpTabAppearancePropertyPageFlat);
  285. m_paneManager.GetPaintManager()->GetPanelPaintManager()->SetColor(xtpTabColorOffice2003);
  286. OnThemeChanged();
  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_GUI_ECTYPE);
  309. // initialize the commands page page.
  310. pPageCommands->InsertAllCommandsCategory();
  311. pPageCommands->InsertBuiltInMenus(IDR_GUI_ECTYPE);
  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. }