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

对话框与窗口

开发平台:

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 "TearOffPopups.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_THEMES_OFFICE2000, OnThemesOffice2000)
  35. ON_UPDATE_COMMAND_UI(ID_THEMES_OFFICE2000, OnUpdateThemesOffice2000)
  36. ON_COMMAND(ID_THEMES_OFFICEXP, OnThemesOfficexp)
  37. ON_UPDATE_COMMAND_UI(ID_THEMES_OFFICEXP, OnUpdateThemesOfficexp)
  38. ON_COMMAND(ID_THEMES_OFFICE2003, OnThemesOffice2003)
  39. ON_UPDATE_COMMAND_UI(ID_THEMES_OFFICE2003, OnUpdateThemesOffice2003)
  40. ON_COMMAND(ID_THEMES_NATIVEXPTHEME, OnThemesNativexptheme)
  41. ON_UPDATE_COMMAND_UI(ID_THEMES_NATIVEXPTHEME, OnUpdateThemesNativexptheme)
  42. ON_WM_CLOSE()
  43. //}}AFX_MSG_MAP
  44. ON_XTP_CREATECOMMANDBAR()
  45. ON_XTP_CREATECONTROL()
  46. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  47. ON_COMMAND_RANGE(ID_BDR_OUTSIDE, ID_BDR_INSIDE_VERT, OnBorders)
  48. ON_UPDATE_COMMAND_UI_RANGE(ID_BDR_OUTSIDE, ID_BDR_INSIDE_VERT, OnUpdateBorders)
  49. END_MESSAGE_MAP()
  50. static UINT indicators[] =
  51. {
  52. ID_SEPARATOR,           // status line indicator
  53. ID_INDICATOR_CAPS,
  54. ID_INDICATOR_NUM,
  55. ID_INDICATOR_SCRL,
  56. };
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMainFrame construction/destruction
  59. CMainFrame::CMainFrame()
  60. {
  61. m_dwBorders = 0;
  62. }
  63. CMainFrame::~CMainFrame()
  64. {
  65. }
  66. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  67. {
  68. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  69. return -1;
  70. if (!m_wndStatusBar.Create(this) ||
  71. !m_wndStatusBar.SetIndicators(indicators,
  72. sizeof(indicators)/sizeof(UINT)))
  73. {
  74. TRACE0("Failed to create status barn");
  75. return -1;      // fail to create
  76. }
  77. if (!InitCommandBars())
  78. return -1;
  79. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  80. CXTPCommandBars* pCommandBars = GetCommandBars();
  81. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_TEAROFTYPE);
  82. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage|xtpFlagAddMDISysPopup);
  83. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  84. if (!pStandardBar ||
  85. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  86. {
  87. TRACE0("Failed to create toolbarn");
  88. return -1;
  89. }
  90. CXTPToolBar* pBordersBar = (CXTPToolBar*)pCommandBars->Add(_T("Borders"), xtpBarTop);
  91. if (!pBordersBar ||
  92. !pBordersBar->LoadToolBar(IDR_BORDERS))
  93. {
  94. TRACE0("Failed to create toolbarn");
  95. return -1;
  96. }
  97. XTPImageManager()->SetIcons(IDR_TOOLBAR_ICONS);
  98. LoadCommandBars(_T("CommandBars2"));
  99. return 0;
  100. }
  101. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  102. {
  103. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  104. return FALSE;
  105. cs.lpszClass = _T("XTPMainFrame");
  106. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  107. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  108. return TRUE;
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CMainFrame diagnostics
  112. #ifdef _DEBUG
  113. void CMainFrame::AssertValid() const
  114. {
  115. CMDIFrameWnd::AssertValid();
  116. }
  117. void CMainFrame::Dump(CDumpContext& dc) const
  118. {
  119. CMDIFrameWnd::Dump(dc);
  120. }
  121. #endif //_DEBUG
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CMainFrame message handlers
  124. int CMainFrame::OnCreateCommandBar(LPCREATEBARSTRUCT lpCreatePopup)
  125. {
  126. if (lpCreatePopup->bTearOffBar && lpCreatePopup->nID == 1005)
  127. {
  128. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreatePopup->pCommandBar);
  129. ASSERT(pToolBar);
  130. pToolBar->EnableDocking(xtpFlagFloating);
  131. pToolBar->EnableCustomization(FALSE);
  132. return TRUE;
  133. }
  134. if (lpCreatePopup->bPopup && _tcscmp(lpCreatePopup->lpcstrCaption, _T("Find")) == 0)
  135. {
  136. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  137. pPopupBar->SetTearOffPopup(_T("Find Bar"), 1000);
  138. lpCreatePopup->pCommandBar = pPopupBar;
  139. return TRUE;
  140. }
  141. if (lpCreatePopup->bPopup && _tcscmp(lpCreatePopup->lpcstrCaption, _T("Styles")) == 0)
  142. {
  143. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  144. pPopupBar->SetTearOffPopup(_T("Styles Bar"), 1001);
  145. lpCreatePopup->pCommandBar = pPopupBar;
  146. return TRUE;
  147. }
  148. if (lpCreatePopup->bPopup && _tcscmp(lpCreatePopup->lpcstrCaption, _T("Themes")) == 0)
  149. {
  150. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  151. pPopupBar->SetTearOffPopup(_T("Themes Bar"), 1003);
  152. lpCreatePopup->pCommandBar = pPopupBar;
  153. return TRUE;
  154. }
  155. if (lpCreatePopup->bPopup && lpCreatePopup->nID == ID_BDR_NONE)
  156. {
  157. CXTPPopupToolBar* pPopupBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  158. pPopupBar->LoadToolBar(IDR_BORDERS);
  159. pPopupBar->SetWidth(23 * 5);
  160. pPopupBar->SetTearOffPopup(_T("Borders"), IDR_BORDERS, 23 * 5);
  161. lpCreatePopup->pCommandBar = pPopupBar;
  162. return TRUE;
  163. }
  164. return FALSE;
  165. }
  166. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  167. {
  168. if (lpCreateControl->bToolBar)
  169. {
  170. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  171. if (!pToolBar)
  172. return FALSE;
  173. if (lpCreateControl->nID == ID_BDR_NONE && pToolBar->GetBarID() == IDR_MAINFRAME)
  174. {
  175. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  176. return TRUE;
  177. }
  178. if (lpCreateControl->nID == ID_BUTTON_TEXT && pToolBar->GetBarID() == IDR_MAINFRAME)
  179. {
  180. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  181. CXTPPopupBar* pColorBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  182. pPopupColor->SetCommandBar(pColorBar);
  183. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), XTP_IDS_AUTOMATIC);
  184. pColorBar->GetControls()->Add(new CXTPControlColorSelector(), ID_SELECTOR_TEXT);
  185. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), XTP_IDS_MORE_COLORS);
  186. pColorBar->SetTearOffPopup(_T("Text Color"), 1005, 0);
  187. pColorBar->EnableCustomization(FALSE);
  188. pColorBar->InternalRelease();
  189. lpCreateControl->pControl = pPopupColor;
  190. return TRUE;
  191. }
  192. }
  193. return FALSE;
  194. }
  195. void CMainFrame::SwitchBorders(DWORD dwState)
  196. {
  197. if (m_dwBorders & dwState) m_dwBorders &= ~dwState; else m_dwBorders |= dwState;
  198. }
  199. void CMainFrame::OnBorders(UINT nID)
  200. {
  201. switch (nID)
  202. {
  203. case ID_BDR_TOP: SwitchBorders(borderTop); break;
  204. case ID_BDR_LEFT: SwitchBorders(borderLeft); break;
  205. case ID_BDR_RIGHT: SwitchBorders(borderRight); break;
  206. case ID_BDR_BOTTOM: SwitchBorders(borderBottom); break;
  207. case ID_BDR_NONE: m_dwBorders = 0; break;
  208. case ID_BDR_OUTSIDE: SwitchBorders(borderOutside); break;
  209. case ID_BDR_ALL: SwitchBorders(borderAll); break;
  210. case ID_BDR_INSIDE_VERT: SwitchBorders(borderInsideVert); break;
  211. case ID_BDR_INSIDE_HORZ: SwitchBorders(borderInsideHorz); break;
  212. case ID_BDR_INSIDE: SwitchBorders(borderInside); break;
  213. }
  214. }
  215. void CMainFrame::OnUpdateBorders(CCmdUI* pCmdUI)
  216. {
  217. switch (pCmdUI->m_nID)
  218. {
  219. case ID_BDR_TOP: pCmdUI->SetCheck(m_dwBorders & borderTop? TRUE: FALSE); break;
  220. case ID_BDR_LEFT: pCmdUI->SetCheck(m_dwBorders & borderLeft? TRUE: FALSE); break;
  221. case ID_BDR_RIGHT: pCmdUI->SetCheck(m_dwBorders & borderRight? TRUE: FALSE); break;
  222. case ID_BDR_BOTTOM: pCmdUI->SetCheck(m_dwBorders & borderBottom? TRUE: FALSE); break;
  223. case ID_BDR_OUTSIDE : pCmdUI->SetCheck((m_dwBorders & borderOutside) == borderOutside? TRUE: FALSE); break;
  224. case ID_BDR_ALL : pCmdUI->SetCheck((m_dwBorders & borderAll) == borderAll? TRUE: FALSE); break;
  225. case ID_BDR_INSIDE_VERT: pCmdUI->SetCheck(m_dwBorders & borderInsideVert? TRUE: FALSE); break;
  226. case ID_BDR_INSIDE_HORZ: pCmdUI->SetCheck(m_dwBorders & borderInsideHorz? TRUE: FALSE); break;
  227. case ID_BDR_INSIDE: pCmdUI->SetCheck((m_dwBorders & borderInside) == borderInside? TRUE: FALSE); break;
  228. }
  229. }
  230. void CMainFrame::OnCustomize()
  231. {
  232. CXTPCustomizeSheet cs(GetCommandBars());
  233. CXTPCustomizeOptionsPage pageOptions(&cs);
  234. cs.AddPage(&pageOptions);
  235. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  236. pCommands->AddCategories(IDR_TEAROFTYPE);
  237. pCommands->AddToolbarCategory(_T("Borders"), IDR_BORDERS);
  238. pCommands->InsertAllCommandsCategory();
  239. pCommands->InsertNewMenuCategory();
  240. cs.DoModal();
  241. }
  242. void CMainFrame::OnThemesOffice2000()
  243. {
  244. CXTPPaintManager::SetTheme(xtpThemeOffice2000);
  245. GetCommandBars()->RedrawCommandBars();
  246. }
  247. void CMainFrame::OnUpdateThemesOffice2000(CCmdUI* pCmdUI)
  248. {
  249. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2000);
  250. }
  251. void CMainFrame::OnThemesOfficexp()
  252. {
  253. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  254. GetCommandBars()->RedrawCommandBars();
  255. }
  256. void CMainFrame::OnUpdateThemesOfficexp(CCmdUI* pCmdUI)
  257. {
  258. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOfficeXP);
  259. }
  260. void CMainFrame::OnThemesOffice2003()
  261. {
  262. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  263. GetCommandBars()->RedrawCommandBars();
  264. }
  265. void CMainFrame::OnUpdateThemesOffice2003(CCmdUI* pCmdUI)
  266. {
  267. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003);
  268. }
  269. void CMainFrame::OnThemesNativexptheme()
  270. {
  271. CXTPPaintManager::SetTheme(xtpThemeNativeWinXP);
  272. GetCommandBars()->RedrawCommandBars();
  273. }
  274. void CMainFrame::OnUpdateThemesNativexptheme(CCmdUI* pCmdUI)
  275. {
  276. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeNativeWinXP);
  277. }
  278. void CMainFrame::OnClose()
  279. {
  280. SaveCommandBars(_T("CommandBars2"));
  281. CMDIFrameWnd::OnClose();
  282. }