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 "SplitterWindow.h"
  22. #include "MainFrm.h"
  23. #include "View1.h"
  24. #include "View2.h"
  25. #include "View3.h"
  26. #include "View4.h"
  27. #include "View5.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMainFrame
  35. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  36. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  37. //{{AFX_MSG_MAP(CMainFrame)
  38. ON_WM_CREATE()
  39. ON_COMMAND(ID_VIEW_THEME_OFFICEXP, OnViewThemeOfficeXP)
  40. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICEXP, OnUpdateViewThemeOfficeXP)
  41. ON_COMMAND(ID_SPLIT_SWAPVIEWS, OnSwapViews)
  42. ON_COMMAND(ID_SPLIT_REPLACEVIEW, OnReplaceView)
  43. ON_UPDATE_COMMAND_UI(ID_SPLIT_REPLACEVIEW, OnUpdateReplaceView)
  44. ON_UPDATE_COMMAND_UI(ID_SPLIT_SWAPVIEWS, OnUpdateSwapViews)
  45. ON_COMMAND(ID_SPLIT_HIDEFIRSTROW, OnHideFirstRow)
  46. ON_UPDATE_COMMAND_UI(ID_SPLIT_HIDEFIRSTROW, OnUpdateHideFirstRow)
  47. ON_COMMAND(ID_SPLIT_HIDEFIRSTCOL, OnHideFirstCol)
  48. ON_UPDATE_COMMAND_UI(ID_SPLIT_HIDEFIRSTCOL, OnUpdateHideFirstCol)
  49. ON_COMMAND(ID_SPLIT_FULLDRAG, OnSplitNofulldrag)
  50. ON_UPDATE_COMMAND_UI(ID_SPLIT_FULLDRAG, OnUpdateSplitNofulldrag)
  51. ON_COMMAND(ID_SPLIT_DOTTRACKER, OnSplitDottracker)
  52. ON_UPDATE_COMMAND_UI(ID_SPLIT_DOTTRACKER, OnUpdateSplitDottracker)
  53. ON_COMMAND(ID_SPLIT_NOSIZE, OnSplitNosize)
  54. ON_UPDATE_COMMAND_UI(ID_SPLIT_NOSIZE, OnUpdateSplitNosize)
  55. ON_COMMAND(ID_SPLIT_FLATSPLITTER, OnSplitFlatsplitter)
  56. ON_UPDATE_COMMAND_UI(ID_SPLIT_FLATSPLITTER, OnUpdateSplitFlatsplitter)
  57. //}}AFX_MSG_MAP
  58. ON_WM_CLOSE()
  59. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  60. END_MESSAGE_MAP()
  61. static UINT indicators[] =
  62. {
  63. ID_SEPARATOR,           // status line indicator
  64. ID_INDICATOR_CAPS,
  65. ID_INDICATOR_NUM,
  66. ID_INDICATOR_SCRL,
  67. };
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CMainFrame construction/destruction
  70. CMainFrame::CMainFrame()
  71. : m_pView1(0)
  72. , m_pView2(0)
  73. , m_pView3(0)
  74. , m_pView4(0)
  75. {
  76. m_bRowHidden = FALSE;
  77. m_bColHidden = FALSE;
  78. m_bSwapped   = FALSE;
  79. m_bReplaced  = FALSE;
  80. m_bFullDrag  = TRUE;
  81. m_bDotTrack  = FALSE;
  82. m_bNoSizing  = FALSE;
  83. m_bFlatSplit = TRUE;
  84. // initialize themes.
  85. m_iTheme = m_regMgr.GetProfileInt(
  86. _T("Settings"), _T("Theme"), xtThemeOfficeXP);
  87. }
  88. CMainFrame::~CMainFrame()
  89. {
  90. m_regMgr.WriteProfileInt(
  91. _T("Settings"), _T("Theme"), m_iTheme);
  92. }
  93. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  94. {
  95. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  96. return -1;
  97. if (!m_wndStatusBar.Create(this) ||
  98. !m_wndStatusBar.SetIndicators(indicators,
  99. sizeof(indicators)/sizeof(UINT)))
  100. {
  101. TRACE0("Failed to create status barn");
  102. return -1;      // fail to create
  103. }
  104. if (!InitCommandBars())
  105. return -1;
  106. CXTPCommandBars* pCommandBars = GetCommandBars();
  107. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  108. CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  109. if (!pCommandBar ||
  110. !pCommandBar->LoadToolBar(IDR_MAINFRAME))
  111. {
  112. TRACE0("Failed to create toolbarn");
  113. return -1;
  114. }
  115. // Load the previous state for command bars.
  116. LoadCommandBars(_T("CommandBars"));
  117. SetTheme(m_iTheme);
  118. return 0;
  119. }
  120. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  121. {
  122. if( !CFrameWnd::PreCreateWindow(cs) )
  123. return FALSE;
  124. cs.lpszClass = _T("XTPMainFrame");
  125. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  126. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  127. return TRUE;
  128. }
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CMainFrame diagnostics
  131. #ifdef _DEBUG
  132. void CMainFrame::AssertValid() const
  133. {
  134. CFrameWnd::AssertValid();
  135. }
  136. void CMainFrame::Dump(CDumpContext& dc) const
  137. {
  138. CFrameWnd::Dump(dc);
  139. }
  140. #endif //_DEBUG
  141. /////////////////////////////////////////////////////////////////////////////
  142. // CMainFrame message handlers
  143. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
  144. {
  145. // Create the splitter window with two columns
  146. if (!m_wndSplitter.CreateStatic(this, 2, 2))
  147. {
  148. TRACE0("Failed to create splitter windown");
  149. return FALSE;
  150. }
  151. if (!m_wndSplitter.CreateView(0,0, RUNTIME_CLASS(CView1),
  152. CSize(0, 0), pContext))
  153. {
  154. TRACE0("Failed to create CView1n");
  155. return FALSE;
  156. }
  157. if (!m_wndSplitter.CreateView(0,1, RUNTIME_CLASS(CView2),
  158. CSize(0, 0), pContext))
  159. {
  160. TRACE0("Failed to create CView2n");
  161. return FALSE;
  162. }
  163. if (!m_wndSplitter.CreateView(1,0, RUNTIME_CLASS(CView3),
  164. CSize(0, 0), pContext))
  165. {
  166. TRACE0("Failed to create CView3n");
  167. return FALSE;
  168. }
  169. if (!m_wndSplitter.CreateView(1,1, RUNTIME_CLASS(CView4),
  170. CSize(0, 0), pContext))
  171. {
  172. TRACE0("Failed to create CView4n");
  173. return FALSE;
  174. }
  175. CRect r;
  176. GetClientRect(&r);
  177. m_wndSplitter.SetRowInfo( 0, r.Height()/2, 0 );
  178. m_wndSplitter.SetColumnInfo( 0, r.Width()/2, 0 );
  179. return TRUE;
  180. }
  181. void CMainFrame::OnSwapViews()
  182. {
  183. m_wndSplitter.SwitchView(0,0, (CView*)m_wndSplitter.GetPane(0,1));
  184. m_bSwapped = !m_bSwapped;
  185. }
  186. void CMainFrame::OnUpdateSwapViews(CCmdUI* pCmdUI)
  187. {
  188. pCmdUI->SetCheck(m_bSwapped);
  189. pCmdUI->Enable(!m_bRowHidden && !m_bColHidden);
  190. }
  191. void CMainFrame::OnReplaceView()
  192. {
  193. if (m_wndSplitter.GetPane(1,0)->IsKindOf(RUNTIME_CLASS(CView3))) {
  194. m_wndSplitter.ReplaceView(1,0, RUNTIME_CLASS(CView5));
  195. }
  196. else {
  197. m_wndSplitter.ReplaceView(1,0, RUNTIME_CLASS(CView3));
  198. }
  199. m_bReplaced = !m_bReplaced;
  200. }
  201. void CMainFrame::OnUpdateReplaceView(CCmdUI* pCmdUI)
  202. {
  203. pCmdUI->SetCheck(m_bReplaced);
  204. pCmdUI->Enable(!m_bRowHidden && !m_bColHidden);
  205. }
  206. void CMainFrame::OnHideFirstRow()
  207. {
  208. m_bRowHidden = !m_bRowHidden;
  209. if (m_bRowHidden) {
  210. m_wndSplitter.HideRow(1);
  211. }
  212. else {
  213. m_wndSplitter.ShowRow();
  214. }
  215. }
  216. void CMainFrame::OnUpdateHideFirstRow(CCmdUI* pCmdUI)
  217. {
  218. pCmdUI->SetCheck(m_bRowHidden);
  219. }
  220. void CMainFrame::OnHideFirstCol()
  221. {
  222. m_bColHidden = !m_bColHidden;
  223. if (m_bColHidden) {
  224. m_wndSplitter.HideColumn(1);
  225. }
  226. else {
  227. m_wndSplitter.ShowColumn();
  228. }
  229. }
  230. void CMainFrame::OnUpdateHideFirstCol(CCmdUI* pCmdUI)
  231. {
  232. pCmdUI->SetCheck(m_bColHidden);
  233. }
  234. void CMainFrame::OnSplitNofulldrag()
  235. {
  236. m_bFullDrag = !m_bFullDrag;
  237. DWORD dw = m_wndSplitter.GetSplitterStyle();
  238. if (m_bFullDrag)
  239. dw &= ~XT_SPLIT_NOFULLDRAG;
  240. else
  241. dw |= XT_SPLIT_NOFULLDRAG;
  242. m_wndSplitter.SetSplitterStyle(dw);
  243. }
  244. void CMainFrame::OnUpdateSplitNofulldrag(CCmdUI* pCmdUI)
  245. {
  246. BOOL bEnable = FALSE;
  247. // Get system settings for full drag.
  248. ::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS,
  249. 0, &bEnable, 0);
  250. pCmdUI->SetCheck(m_bFullDrag);
  251. pCmdUI->Enable(bEnable && !m_bDotTrack);
  252. }
  253. void CMainFrame::OnSplitDottracker()
  254. {
  255. m_bDotTrack = !m_bDotTrack;
  256. DWORD dw = m_wndSplitter.GetSplitterStyle();
  257. if (m_bDotTrack)
  258. dw |= XT_SPLIT_DOTTRACKER;
  259. else
  260. dw &= ~XT_SPLIT_DOTTRACKER;
  261. m_wndSplitter.SetSplitterStyle(dw);
  262. }
  263. void CMainFrame::OnUpdateSplitDottracker(CCmdUI* pCmdUI)
  264. {
  265. BOOL bEnable = FALSE;
  266. // Get system settings for full drag.
  267. ::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS,
  268. 0, &bEnable, 0);
  269. pCmdUI->SetCheck(m_bDotTrack);
  270. if (bEnable)
  271. pCmdUI->Enable(!m_bFullDrag);
  272. }
  273. void CMainFrame::OnSplitNosize()
  274. {
  275. m_bNoSizing = !m_bNoSizing;
  276. DWORD dw = m_wndSplitter.GetSplitterStyle();
  277. if (m_bNoSizing)
  278. dw |= XT_SPLIT_NOSIZE;
  279. else
  280. dw &= ~XT_SPLIT_NOSIZE;
  281. m_wndSplitter.SetSplitterStyle(dw);
  282. }
  283. void CMainFrame::OnUpdateSplitNosize(CCmdUI* pCmdUI)
  284. {
  285. pCmdUI->SetCheck(m_bNoSizing);
  286. }
  287. void CMainFrame::OnSplitFlatsplitter()
  288. {
  289. m_bFlatSplit = !m_bFlatSplit;
  290. m_wndSplitter.EnableFlatLook(m_bFlatSplit);
  291. }
  292. void CMainFrame::OnUpdateSplitFlatsplitter(CCmdUI* pCmdUI)
  293. {
  294. pCmdUI->SetCheck(m_bFlatSplit);
  295. }
  296. void CMainFrame::SetTheme(int iTheme)
  297. {
  298. m_iTheme = iTheme;
  299. XTThemeManager()->SetTheme((XTThemeStyle)m_iTheme);
  300. XTPPaintManager()->SetTheme((XTPPaintTheme)m_iTheme);
  301. RedrawWindow( NULL, NULL,
  302. RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN );
  303. RecalcLayout();
  304. }
  305. void CMainFrame::OnViewThemeOfficeXP()
  306. {
  307. SetTheme((m_iTheme == xtThemeOfficeXP)? xtThemeDefault: xtThemeOfficeXP);
  308. }
  309. void CMainFrame::OnUpdateViewThemeOfficeXP(CCmdUI* pCmdUI)
  310. {
  311. pCmdUI->SetCheck(m_iTheme == xtThemeOfficeXP);
  312. }
  313. void CMainFrame::OnClose()
  314. {
  315. // Save the current state for command bars.
  316. SaveCommandBars(_T("CommandBars"));
  317. CFrameWnd::OnClose();
  318. }
  319. void CMainFrame::OnCustomize()
  320. {
  321. // get a pointer to the command bars object.
  322. CXTPCommandBars* pCommandBars = GetCommandBars();
  323. if (pCommandBars == NULL)
  324. return;
  325. // instantiate the customize dialog
  326. CXTPCustomizeSheet dlg(pCommandBars);
  327. // add the options page to the customize dialog.
  328. CXTPCustomizeOptionsPage pageOptions(&dlg);
  329. dlg.AddPage(&pageOptions);
  330. // add the commands page to the customize dialog.
  331. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  332. pPageCommands->AddCategories(IDR_MAINFRAME);
  333. // initialize the commands page page.
  334. pPageCommands->InsertAllCommandsCategory();
  335. pPageCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  336. pPageCommands->InsertNewMenuCategory();
  337. // display the customize dialog.
  338. dlg.DoModal();
  339. }