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

对话框与窗口

开发平台:

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 "ShortcutBar.h"
  22. #include "MainFrm.h"
  23. #include "ShortcutBarDoc.h"
  24. #include "ShortcutBarView.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_THEME_OFFICE2000, OnThemeOffice2000)
  37. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2000, OnUpdateThemeOffice2000)
  38. ON_COMMAND(ID_THEME_OFFICEXP, OnThemeOfficexp)
  39. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICEXP, OnUpdateThemeOfficexp)
  40. ON_COMMAND(ID_THEME_OFFICE2003, OnThemeOffice2003)
  41. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2003, OnUpdateThemeOffice2003)
  42. ON_COMMAND(ID_THEME_OFFICE2007, OnThemeOffice2007)
  43. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2007, OnUpdateThemeOffice2007)
  44. ON_WM_CLOSE()
  45. ON_COMMAND(ID_THEME_CLIENTPANE, OnThemeClientpane)
  46. ON_UPDATE_COMMAND_UI(ID_THEME_CLIENTPANE, OnUpdateThemeClientpane)
  47. ON_COMMAND(ID_THEME_SHOWEXPANDBUTTON, OnThemeShowexpandbutton)
  48. ON_UPDATE_COMMAND_UI(ID_THEME_SHOWEXPANDBUTTON, OnUpdateThemeShowexpandbutton)
  49. ON_COMMAND(ID_THEME_SHOWACTIVEITEMONTOP, OnThemeShowactiveitemontop)
  50. ON_UPDATE_COMMAND_UI(ID_THEME_SHOWACTIVEITEMONTOP, OnUpdateThemeShowactiveitemontop)
  51. ON_MESSAGE(XTPWM_SHORTCUTBAR_NOTIFY, OnShortcutBarNotify)
  52. ON_COMMAND(ID_THEME_ALLOWFREERESIZE, OnThemeAllowfreeresize)
  53. ON_UPDATE_COMMAND_UI(ID_THEME_ALLOWFREERESIZE, OnUpdateThemeAllowfreeresize)
  54. //}}AFX_MSG_MAP
  55. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  56. END_MESSAGE_MAP()
  57. static UINT indicators[] =
  58. {
  59. ID_SEPARATOR,           // status line indicator
  60. ID_INDICATOR_CAPS,
  61. ID_INDICATOR_NUM,
  62. ID_INDICATOR_SCRL,
  63. };
  64. static UINT shortcuts[] =
  65. {
  66. ID_SHORTCUT_MAIL,
  67. ID_SHORTCUT_CALENDAR,
  68. ID_SHORTCUT_CONTACTS,
  69. ID_SHORTCUT_TASKS,
  70. ID_SHORTCUT_NOTES,
  71. ID_SHORTCUT_FOLDERS,
  72. ID_SHORTCUT_SHORTCUTS,
  73. ID_SHORTCUT_JOURNAL
  74. };
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CMainFrame construction/destruction
  77. CMainFrame::CMainFrame()
  78. {
  79. m_bClientPane = TRUE;
  80. }
  81. CMainFrame::~CMainFrame()
  82. {
  83. }
  84. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  85. {
  86. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  87. return -1;
  88. if (!m_wndStatusBar.Create(this) ||
  89. !m_wndStatusBar.SetIndicators(indicators,
  90.   sizeof(indicators)/sizeof(UINT)))
  91. {
  92. TRACE0("Failed to create status barn");
  93. return -1;      // fail to create
  94. }
  95. if (!InitCommandBars())
  96. return -1;
  97. CXTPCommandBars* pCommandBars = GetCommandBars();
  98. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  99. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  100. if (!pStandardBar ||
  101. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  102. {
  103. TRACE0("Failed to create toolbarn");
  104. }
  105. pCommandBars->GetToolTipContext()->SetStyle(xtpToolTipOffice);
  106. // Load the previous state for command bars.
  107. LoadCommandBars(_T("CommandBars"));
  108. CXTPPaintManager::SetTheme(xtpThemeRibbon);
  109. m_wndShortcutBar.SetTheme(xtpShortcutThemeOffice2007);
  110. EnableOffice2007Frame(GetCommandBars());
  111. return 0;
  112. }
  113. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  114. {
  115. if( !CFrameWnd::PreCreateWindow(cs) )
  116. return FALSE;
  117. cs.lpszClass = _T("XTPMainFrame");
  118. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  119. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  120. cs.style |= WS_CLIPSIBLINGS|WS_CLIPCHILDREN;
  121. return TRUE;
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CMainFrame diagnostics
  125. #ifdef _DEBUG
  126. void CMainFrame::AssertValid() const
  127. {
  128. CFrameWnd::AssertValid();
  129. }
  130. void CMainFrame::Dump(CDumpContext& dc) const
  131. {
  132. CFrameWnd::Dump(dc);
  133. }
  134. #endif //_DEBUG
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CMainFrame message handlers
  137. void CMainFrame::CreateShortcutBar()
  138. {
  139. m_wndShortcutBar.Create(WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0),
  140. &m_wndSplitter,  m_wndSplitter.IdFromRowCol(0, 0));
  141. m_wndShortcutBar.SetOwner(this);
  142. m_wndShortcutBar.GetToolTipContext()->SetStyle(xtpToolTipOffice);
  143. BOOL bUseAlphaIcons = XTPImageManager()->IsAlphaIconsSupported();
  144. XTPImageManager()->SetIcons(bUseAlphaIcons ? IDB_SHORTCUTS_SMALL_ALPHA : IDB_SHORTCUTS_SMALL, 
  145. shortcuts, sizeof(shortcuts)/sizeof(UINT), CSize(16, 16));
  146. XTPImageManager()->SetIcons(bUseAlphaIcons ? IDB_SHORTCUTS_BIG_ALPHA : IDB_SHORTCUTS_BIG, 
  147. shortcuts, sizeof(shortcuts)/sizeof(UINT), CSize(24, 24));
  148. VERIFY(m_paneMail.Create(_T("Mail"), &m_wndShortcutBar));
  149. VERIFY(m_paneCalendar.Create(_T("Calendar"), &m_wndShortcutBar));
  150. VERIFY(m_paneFolders.Create(_T("Folders"), &m_wndShortcutBar));
  151. VERIFY(m_paneContacts.Create(_T("Contacts"), &m_wndShortcutBar));
  152. CXTPShortcutBarItem* pItemMail = m_wndShortcutBar.AddItem(ID_SHORTCUT_MAIL, &m_paneMail);
  153. m_wndShortcutBar.AddItem(ID_SHORTCUT_CALENDAR, &m_paneCalendar);
  154. m_wndShortcutBar.AddItem(ID_SHORTCUT_CONTACTS, &m_paneContacts);
  155. m_wndShortcutBar.AddItem(ID_SHORTCUT_TASKS);
  156. m_wndShortcutBar.AddItem(ID_SHORTCUT_NOTES);
  157. m_wndShortcutBar.AddItem(ID_SHORTCUT_FOLDERS, &m_paneFolders);
  158. m_wndShortcutBar.AddItem(ID_SHORTCUT_SHORTCUTS);
  159. m_wndShortcutBar.AddItem(ID_SHORTCUT_JOURNAL);
  160. m_wndShortcutBar.SelectItem(pItemMail);
  161. m_wndShortcutBar.LoadState(_T("ShortcutBar"));
  162. }
  163. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
  164. {
  165. m_wndSplitter.CreateStatic(this, 1, 2);
  166. CreateShortcutBar();
  167. m_wndSplitter.SetColumnInfo(0, 250,50);
  168. m_wndSplitter2.CreateStatic(&m_wndSplitter, 2, 1, WS_CHILD|WS_VISIBLE, m_wndSplitter.IdFromRowCol(0, 1));
  169. m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CShortcutBarView), CSize(0, 200), pContext);
  170. m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CShortcutBarView), CSize(0, 0), pContext);
  171. XTThemeManager()->SetTheme(xtThemeOffice2003);
  172. return TRUE;
  173. }
  174. void CMainFrame::OnThemeOffice2000()
  175. {
  176. EnableOffice2007Frame(NULL);
  177. XTPPaintManager()->SetTheme(xtpThemeOffice2000);
  178. XTThemeManager()->SetTheme(xtThemeDefault);
  179. GetCommandBars()->RedrawCommandBars();
  180. m_wndShortcutBar.SetTheme(xtpShortcutThemeOffice2000);
  181. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  182. }
  183. void CMainFrame::OnUpdateThemeOffice2000(CCmdUI* pCmdUI)
  184. {
  185. pCmdUI->SetCheck(m_wndShortcutBar.GetCurrentTheme() == xtpShortcutThemeOffice2000);
  186. }
  187. void CMainFrame::OnThemeOfficexp()
  188. {
  189. EnableOffice2007Frame(NULL);
  190. XTPPaintManager()->SetTheme(xtpThemeOfficeXP);
  191. XTThemeManager()->SetTheme(xtThemeOfficeXP);
  192. GetCommandBars()->RedrawCommandBars();
  193. m_wndShortcutBar.SetTheme(xtpShortcutThemeOfficeXP);
  194. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  195. }
  196. void CMainFrame::OnUpdateThemeOfficexp(CCmdUI* pCmdUI)
  197. {
  198. pCmdUI->SetCheck(m_wndShortcutBar.GetCurrentTheme() == xtpShortcutThemeOfficeXP);
  199. }
  200. void CMainFrame::OnThemeOffice2003()
  201. {
  202. EnableOffice2007Frame(NULL);
  203. XTPPaintManager()->SetTheme(xtpThemeOffice2003);
  204. XTThemeManager()->SetTheme(xtThemeOffice2003);
  205. GetCommandBars()->RedrawCommandBars();
  206. m_wndShortcutBar.SetTheme(xtpShortcutThemeOffice2003);
  207. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  208. }
  209. void CMainFrame::OnUpdateThemeOffice2003(CCmdUI* pCmdUI)
  210. {
  211. pCmdUI->SetCheck(m_wndShortcutBar.GetCurrentTheme() == xtpShortcutThemeOffice2003);
  212. }
  213. void CMainFrame::OnThemeOffice2007()
  214. {
  215. XTPPaintManager()->SetTheme(xtpThemeOffice2007);
  216. EnableOffice2007Frame(GetCommandBars());
  217. XTThemeManager()->SetTheme(xtThemeOffice2003);
  218. GetCommandBars()->RedrawCommandBars();
  219. m_wndShortcutBar.SetTheme(xtpShortcutThemeOffice2007);
  220. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  221. }
  222. void CMainFrame::OnUpdateThemeOffice2007(CCmdUI* pCmdUI)
  223. {
  224. pCmdUI->SetCheck(m_wndShortcutBar.GetCurrentTheme() == xtpShortcutThemeOffice2007);
  225. }
  226. void CMainFrame::OnClose()
  227. {
  228. // Save the current state for command bars.
  229. SaveCommandBars(_T("CommandBars"));
  230. m_wndShortcutBar.SaveState(_T("ShortcutBar"));
  231. CFrameWnd::OnClose();
  232. }
  233. LRESULT CMainFrame::OnShortcutBarNotify(WPARAM wParam, LPARAM lParam)
  234. {
  235. switch (wParam)
  236. {
  237. case XTP_SBN_SELECTION_CHANGING:
  238. {
  239. CXTPShortcutBarItem* pItem = (CXTPShortcutBarItem*)lParam;
  240. TRACE(_T("Selection Changing. Item.Caption = %sn"), pItem->GetCaption());
  241. // TODO: You can return -1 to ignore changing
  242. }
  243. return TRUE;
  244. case XTP_SBN_RCLICK:
  245. {
  246. CPoint point(lParam);
  247. CXTPShortcutBarItem* pItem = m_wndShortcutBar.HitTest(point);
  248. if (pItem)
  249. {
  250. TRACE(_T("RClick. Item.ID = %in"), pItem->GetID());
  251. CMenu mnu;
  252. mnu.LoadMenu(IDR_POPUP_MENU);
  253. m_wndShortcutBar.ClientToScreen(&point);
  254. CXTPCommandBars::TrackPopupMenu(mnu.GetSubMenu(0), 0, point.x, point.y, AfxGetMainWnd());
  255. }
  256. }
  257. return TRUE;
  258. }
  259. return 0;
  260. }
  261. void CMainFrame::OnThemeClientpane()
  262. {
  263. m_bClientPane = !m_bClientPane;
  264. m_wndShortcutBar.SetClientPaneVisible(m_bClientPane);
  265. }
  266. void CMainFrame::OnUpdateThemeClientpane(CCmdUI* pCmdUI)
  267. {
  268. pCmdUI->SetCheck(m_bClientPane);
  269. }
  270. void CMainFrame::OnCustomize()
  271. {
  272. // get a pointer to the command bars object.
  273. CXTPCommandBars* pCommandBars = GetCommandBars();
  274. if (pCommandBars == NULL)
  275. return;
  276. // instanciate the customize dialog
  277. CXTPCustomizeSheet dlg(pCommandBars);
  278. // add the options page to the customize dialog.
  279. CXTPCustomizeOptionsPage pageOptions(&dlg);
  280. dlg.AddPage(&pageOptions);
  281. // add the commands page to the customize dialog.
  282. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  283. pPageCommands->AddCategories(IDR_MAINFRAME);
  284. // initialize the commands page page.
  285. pPageCommands->InsertAllCommandsCategory();
  286. pPageCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  287. pPageCommands->InsertNewMenuCategory();
  288. // display the customize dialog.
  289. dlg.DoModal();
  290. }
  291. void CMainFrame::OnThemeShowexpandbutton() 
  292. {
  293. m_wndShortcutBar.ShowExpandButton(!m_wndShortcutBar.IsExpandButtonVisible());
  294. }
  295. void CMainFrame::OnUpdateThemeShowexpandbutton(CCmdUI* pCmdUI) 
  296. {
  297. pCmdUI->SetCheck(m_wndShortcutBar.IsExpandButtonVisible()? TRUE: FALSE);
  298. }
  299. void CMainFrame::OnThemeShowactiveitemontop() 
  300. {
  301. BOOL bShowActiveItemOnTop = !m_wndShortcutBar.IsShowActiveItemOnTop();
  302. m_paneMail.ShowCaption(!bShowActiveItemOnTop);
  303. m_paneCalendar.ShowCaption(!bShowActiveItemOnTop);
  304. m_paneFolders.ShowCaption(!bShowActiveItemOnTop);
  305. m_paneMail.ShowCaption(!bShowActiveItemOnTop);
  306. m_paneContacts.ShowCaption(!bShowActiveItemOnTop);
  307. m_wndShortcutBar.ShowActiveItemOnTop(bShowActiveItemOnTop);
  308. }
  309. void CMainFrame::OnUpdateThemeShowactiveitemontop(CCmdUI* pCmdUI) 
  310. {
  311. pCmdUI->SetCheck(m_wndShortcutBar.IsShowActiveItemOnTop()? TRUE: FALSE);
  312. }
  313. void CMainFrame::OnThemeAllowfreeresize() 
  314. {
  315. m_wndShortcutBar.AllowFreeResize(!m_wndShortcutBar.IsAllowFreeResize());
  316. }
  317. void CMainFrame::OnUpdateThemeAllowfreeresize(CCmdUI* pCmdUI) 
  318. {
  319. pCmdUI->SetCheck(m_wndShortcutBar.IsAllowFreeResize()? TRUE: FALSE);
  320. }