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

对话框与窗口

开发平台:

Visual C++

  1. // TabbedViewView.cpp : implementation of the CTabbedViewView 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 "TabbedView.h"
  22. #include "TabbedViewDoc.h"
  23. #include "TabbedViewView.h"
  24. #include "FileTreeView.h"
  25. #include "ClassTreeView.h"
  26. #include "ResourceTreeView.h"
  27. #include "PropertiesView.h"
  28. #include "EditControlView.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. #define IDC_TABCONTROL 100
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CTabbedViewView
  37. IMPLEMENT_DYNCREATE(CTabbedViewView, CView)
  38. BEGIN_MESSAGE_MAP(CTabbedViewView, CView)
  39. //{{AFX_MSG_MAP(CTabbedViewView)
  40. ON_WM_CREATE()
  41. ON_WM_ERASEBKGND()
  42. ON_WM_PAINT()
  43. ON_WM_SIZE()
  44. //}}AFX_MSG_MAP
  45. ON_NOTIFY(TCN_SELCHANGE, IDC_TABCONTROL, OnSelectedChanged)
  46. ON_WM_MOUSEACTIVATE()
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CTabbedViewView construction/destruction
  50. CTabbedViewView::CTabbedViewView()
  51. {
  52. }
  53. CTabbedViewView::~CTabbedViewView()
  54. {
  55. }
  56. BOOL CTabbedViewView::PreCreateWindow(CREATESTRUCT& cs)
  57. {
  58. // TODO: Modify the Window class or styles here by modifying
  59. //  the CREATESTRUCT cs
  60. if (!CView::PreCreateWindow(cs))
  61. return FALSE;
  62. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  63. return TRUE;
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CTabbedViewView drawing
  67. void CTabbedViewView::OnDraw(CDC*)
  68. {
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CTabbedViewView diagnostics
  72. #ifdef _DEBUG
  73. void CTabbedViewView::AssertValid() const
  74. {
  75. CView::AssertValid();
  76. }
  77. void CTabbedViewView::Dump(CDumpContext& dc) const
  78. {
  79. CView::Dump(dc);
  80. }
  81. CTabbedViewDoc* CTabbedViewView::GetDocument() // non-debug version is inline
  82. {
  83. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTabbedViewDoc)));
  84. return (CTabbedViewDoc*)m_pDocument;
  85. }
  86. #endif //_DEBUG
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CTabbedViewView message handlers
  89. BOOL CTabbedViewView::AddView(CRuntimeClass* pViewClass, LPCTSTR lpszTitle, int nIcon)
  90. {
  91. CCreateContext contextT;
  92. contextT.m_pCurrentDoc     = GetDocument();
  93. contextT.m_pNewViewClass   = pViewClass;
  94. contextT.m_pNewDocTemplate = GetDocument()->GetDocTemplate();
  95. CWnd* pWnd;
  96. TRY
  97. {
  98. pWnd = (CWnd*)pViewClass->CreateObject();
  99. if (pWnd == NULL)
  100. {
  101. AfxThrowMemoryException();
  102. }
  103. }
  104. CATCH_ALL(e)
  105. {
  106. TRACE0( "Out of memory creating a view.n" );
  107. // Note: DELETE_EXCEPTION(e) not required
  108. return FALSE;
  109. }
  110. END_CATCH_ALL
  111. DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
  112. dwStyle &= ~WS_BORDER;
  113. int nTab = m_wndTabControl.GetItemCount();
  114. // Create with the right size (wrong position)
  115. CRect rect(0,0,0,0);
  116. if (!pWnd->Create(NULL, NULL, dwStyle,
  117. rect, &m_wndTabControl, (AFX_IDW_PANE_FIRST + nTab), &contextT))
  118. {
  119. TRACE0( "Warning: couldn't create client tab for view.n" );
  120. // pWnd will be cleaned up by PostNcDestroy
  121. return NULL;
  122. }
  123. m_wndTabControl.InsertItem(nTab, lpszTitle, pWnd->GetSafeHwnd(), nIcon);
  124. pWnd->SetOwner(this);
  125. return TRUE;
  126. }
  127. int CTabbedViewView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  128. {
  129. if (CView::OnCreate(lpCreateStruct) == -1)
  130. return -1;
  131. m_wndTabControl.Create(WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, IDC_TABCONTROL);
  132. m_wndTabControl.GetPaintManager()->SetAppearance(xtpTabAppearancePropertyPage2003);
  133. m_wndTabControl.GetPaintManager()->m_bHotTracking = TRUE;
  134. m_wndTabControl.GetPaintManager()->m_bShowIcons = TRUE;
  135. m_wndTabControl.GetPaintManager()->DisableLunaColors(FALSE);
  136. m_wndTabControl.GetImageManager()->SetIcons(IDB_TAB_ICONS, NULL, 0, CSize(16, 16), xtpImageNormal);
  137. AddView(RUNTIME_CLASS(CEditControlView), _T("Edit Control"), 3);
  138. AddView(RUNTIME_CLASS(CFileTreeView), _T("File Tree"), 0);
  139. AddView(RUNTIME_CLASS(CClassTreeView), _T("Class Tree"), 4);
  140. AddView(RUNTIME_CLASS(CResourceTreeView), _T("Resource Tree"), 2);
  141. AddView(RUNTIME_CLASS(CPropertiesView), _T("Properties"), 1);
  142. return 0;
  143. }
  144. BOOL CTabbedViewView::OnEraseBkgnd(CDC*)
  145. {
  146. return TRUE;
  147. }
  148. void CTabbedViewView::OnPaint()
  149. {
  150. CPaintDC dc(this);
  151. }
  152. void CTabbedViewView::OnSize(UINT nType, int cx, int cy)
  153. {
  154. CView::OnSize(nType, cx, cy);
  155. if (m_wndTabControl.GetSafeHwnd())
  156. {
  157. m_wndTabControl.MoveWindow(0, 0, cx, cy);
  158. }
  159. }
  160. void CTabbedViewView::UpdateDocTitle()
  161. {
  162. GetDocument()->UpdateFrameCounts();
  163. }
  164. void CTabbedViewView::OnSelectedChanged(NMHDR* pNMHDR, LRESULT* pResult)
  165. {
  166. UNUSED_ALWAYS(pNMHDR);
  167. *pResult = 0;
  168. UpdateDocTitle();
  169. CFrameWnd* pFrame = GetParentFrame();
  170. CView* pView = DYNAMIC_DOWNCAST(CView, CWnd::FromHandle(m_wndTabControl.GetSelectedItem()->GetHandle()));
  171. ASSERT_KINDOF(CView, pView);
  172. pFrame->SetActiveView(pView);
  173. }
  174. int CTabbedViewView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
  175. {
  176. return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
  177. }