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

对话框与窗口

开发平台:

Visual C++

  1. // CommandBarsDesignerView.cpp : implementation of the CCommandBarsDesignerView 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 "CommandBarsDesigner.h"
  22. #include "CommandBarsDesignerDoc.h"
  23. #include "CommandBarsDesignerView.h"
  24. #include "CommandBarsDesignerDesignerView.h"
  25. #include "EmbeddedFrame.h"
  26. #include "MainFrm.h"
  27. #include "DialogResourceSymbols.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. #define IDC_TABCONTROL 100
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CCommandBarsDesignerView
  36. IMPLEMENT_DYNCREATE(CCommandBarsDesignerView, CView)
  37. BEGIN_MESSAGE_MAP(CCommandBarsDesignerView, CView)
  38. //{{AFX_MSG_MAP(CCommandBarsDesignerView)
  39. ON_WM_CREATE()
  40. ON_WM_ERASEBKGND()
  41. ON_WM_PAINT()
  42. ON_WM_SIZE()
  43. //}}AFX_MSG_MAP
  44. ON_NOTIFY(TCN_SELCHANGE, IDC_TABCONTROL, OnSelectedChanged)
  45. ON_WM_MOUSEACTIVATE()
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CCommandBarsDesignerView construction/destruction
  49. CCommandBarsDesignerView::CCommandBarsDesignerView()
  50. {
  51. }
  52. CCommandBarsDesignerView::~CCommandBarsDesignerView()
  53. {
  54. }
  55. BOOL CCommandBarsDesignerView::PreCreateWindow(CREATESTRUCT& cs)
  56. {
  57. // TODO: Modify the Window class or styles here by modifying
  58. //  the CREATESTRUCT cs
  59. if (!CView::PreCreateWindow(cs))
  60. return FALSE;
  61. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  62. return TRUE;
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CCommandBarsDesignerView drawing
  66. void CCommandBarsDesignerView::OnDraw(CDC*)
  67. {
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CCommandBarsDesignerView diagnostics
  71. #ifdef _DEBUG
  72. void CCommandBarsDesignerView::AssertValid() const
  73. {
  74. CView::AssertValid();
  75. }
  76. void CCommandBarsDesignerView::Dump(CDumpContext& dc) const
  77. {
  78. CView::Dump(dc);
  79. }
  80. CCommandBarsDesignerDoc* CCommandBarsDesignerView::GetDocument() // non-debug version is inline
  81. {
  82. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCommandBarsDesignerDoc)));
  83. return (CCommandBarsDesignerDoc*)m_pDocument;
  84. }
  85. #endif //_DEBUG
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CCommandBarsDesignerView message handlers
  88. BOOL CCommandBarsDesignerView::AddView(CRuntimeClass* pViewClass, LPCTSTR lpszTitle, int nIcon)
  89. {
  90. CCreateContext contextT;
  91. contextT.m_pCurrentDoc     = GetDocument();
  92. contextT.m_pNewViewClass   = pViewClass;
  93. contextT.m_pNewDocTemplate = GetDocument()->GetDocTemplate();
  94. CWnd* pWnd;
  95. TRY
  96. {
  97. pWnd = (CWnd*)pViewClass->CreateObject();
  98. if (pWnd == NULL)
  99. {
  100. AfxThrowMemoryException();
  101. }
  102. }
  103. CATCH_ALL(e)
  104. {
  105. TRACE0( "Out of memory creating a view.n" );
  106. // Note: DELETE_EXCEPTION(e) not required
  107. return FALSE;
  108. }
  109. END_CATCH_ALL
  110. DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
  111. dwStyle &= ~WS_BORDER;
  112. int nTab = m_wndTabControl.GetItemCount();
  113. // Create with the right size (wrong position)
  114. CRect rect(0,0,0,0);
  115. if (!pWnd->Create(NULL, NULL, dwStyle,
  116. rect, &m_wndTabControl, (AFX_IDW_PANE_FIRST + nTab), &contextT))
  117. {
  118. TRACE0( "Warning: couldn't create client tab for view.n" );
  119. // pWnd will be cleaned up by PostNcDestroy
  120. return NULL;
  121. }
  122. m_wndTabControl.InsertItem(nTab, lpszTitle, pWnd->GetSafeHwnd(), nIcon);
  123. pWnd->SendMessage(WM_INITIALUPDATE);
  124. pWnd->SetOwner(this);
  125. return TRUE;
  126. }
  127. int CCommandBarsDesignerView::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(xtpTabAppearanceStateButtons);
  133. m_wndTabControl.GetPaintManager()->SetPosition(xtpTabPositionBottom);
  134. m_wndTabControl.GetPaintManager()->m_bShowIcons = TRUE;
  135. AddView(RUNTIME_CLASS(CCommandBarsDesignerDesignerView), _T("Designer"), 3);
  136. AddView(RUNTIME_CLASS(CCommandBarsDesignerEditView), _T("XML"), 0);
  137. if (!IsXMLEngineAvailable())
  138. {
  139. m_wndTabControl.GetItem(1)->SetEnabled(FALSE);
  140. }
  141. return 0;
  142. }
  143. BOOL CCommandBarsDesignerView::OnEraseBkgnd(CDC*)
  144. {
  145. return TRUE;
  146. }
  147. void CCommandBarsDesignerView::OnPaint()
  148. {
  149. CPaintDC dc(this);
  150. }
  151. void CCommandBarsDesignerView::OnSize(UINT nType, int cx, int cy)
  152. {
  153. CView::OnSize(nType, cx, cy);
  154. if (m_wndTabControl.GetSafeHwnd())
  155. {
  156. m_wndTabControl.MoveWindow(0, 0, cx, cy);
  157. }
  158. }
  159. void CCommandBarsDesignerView::OnInitialUpdate()
  160. {
  161. CCommandBarsDesignerDesignerView* pView =  DYNAMIC_DOWNCAST(CCommandBarsDesignerDesignerView,
  162. CWnd::FromHandlePermanent(m_wndTabControl.GetItem(0)->GetHandle()));
  163. pView->OnInitialUpdate();
  164. }
  165. void CCommandBarsDesignerView::UpdateDocTitle()
  166. {
  167. GetDocument()->UpdateFrameCounts();
  168. }
  169. void CCommandBarsDesignerView::OnSelectedChanged(NMHDR* pNMHDR, LRESULT* pResult)
  170. {
  171. UNUSED_ALWAYS(pNMHDR);
  172. *pResult = 0;
  173. UpdateDocTitle();
  174. CFrameWnd* pFrame = GetParentFrame();
  175. CView* pView = DYNAMIC_DOWNCAST(CView, CWnd::FromHandle(m_wndTabControl.GetSelectedItem()->GetHandle()));
  176. ASSERT_KINDOF(CView, pView);
  177. if (m_wndTabControl.GetItemCount() == 2)
  178. {
  179. if (pView->IsKindOf(RUNTIME_CLASS(CCommandBarsDesignerEditView)))
  180. {
  181. GetEmbeddedFrame()->GetCommandBars()->SetDragControl(0);
  182. CXTPPropExchangeXMLNode px(FALSE, 0, _T("DesignerFile"));
  183. if (!px.OnBeforeExchange())
  184. {
  185. m_wndTabControl.SetCurSel(0);
  186. return;
  187. }
  188. GetEmbeddedFrame()->DoPropExchange(&px);
  189. CString str = px.GetXML(TRUE);
  190. ((CEditView*)pView)->SetWindowText(str);
  191. ((CEditView*)pView)->GetEditCtrl().SetModify(FALSE);
  192. }
  193. else
  194. {
  195. CCommandBarsDesignerEditView* pEditView =  DYNAMIC_DOWNCAST(CCommandBarsDesignerEditView,
  196. CWnd::FromHandlePermanent(m_wndTabControl.GetItem(1)->GetHandle()));
  197. if (pEditView->GetEditCtrl().GetModify())
  198. {
  199. CString str;
  200. pEditView->GetWindowText(str);
  201. CXTPPropExchangeXMLNode px(TRUE, NULL, _T("DesignerFile"));
  202. if (px.LoadFromString(str))
  203. {
  204. GetEmbeddedFrame()->DoPropExchange(&px);
  205. OnInitialUpdate();
  206. ((CMainFrame*)AfxGetMainWnd())->RefreshPanes();
  207. }
  208. }
  209. }
  210. }
  211. pFrame->SetActiveView(pView);
  212. }
  213. int CCommandBarsDesignerView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
  214. {
  215. return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
  216. }
  217. void CCommandBarsDesignerView::OnUpdateFrameTitle()
  218. {
  219. }
  220. void CCommandBarsDesignerView::Serialize(CArchive& ar)
  221. {
  222. GetEmbeddedFrame()->Serialize(ar);
  223. }
  224. CEmbeddedFrame* CCommandBarsDesignerView::GetEmbeddedFrame()
  225. {
  226. CCommandBarsDesignerDesignerView* pView =  DYNAMIC_DOWNCAST(CCommandBarsDesignerDesignerView,
  227. CWnd::FromHandlePermanent(m_wndTabControl.GetItem(0)->GetHandle()));
  228. ASSERT(pView);
  229. if (pView)
  230. return pView->m_pFrame;
  231. return 0;
  232. }