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

对话框与窗口

开发平台:

Visual C++

  1. // CommandBarsDesignerDesignerView.cpp : implementation file
  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 "CommandBarsDesignerDesignerView.h"
  24. #include "EmbeddedFrame.h"
  25. #include "MainFrm.h"
  26. #include "DialogResourceSymbols.h"
  27. #include "DialogMenuGrabber.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CCommandBarsDesignerDesignerView
  35. IMPLEMENT_DYNCREATE(CCommandBarsDesignerDesignerView, CView)
  36. BEGIN_MESSAGE_MAP(CCommandBarsDesignerDesignerView, CView)
  37. //{{AFX_MSG_MAP(CCommandBarsDesignerDesignerView)
  38. ON_WM_SETCURSOR()
  39. ON_WM_LBUTTONDOWN()
  40. ON_WM_CREATE()
  41. ON_COMMAND(ID_COMMANDBARS_SETTINGS, OnCommandbarsSettings)
  42. ON_COMMAND(ID_COMMANDBARS_RESOURCESYMBOLS, OnCommandbarsResourcesymbols)
  43. ON_COMMAND(ID_FILE_EXPORT_XMLDOCUMENT, OnFileExportXmldocument)
  44. ON_COMMAND(ID_DESIGN_MODE, OnDesignMode)
  45. ON_UPDATE_COMMAND_UI(ID_DESIGN_MODE, OnUpdateDesignMode)
  46. ON_UPDATE_COMMAND_UI(ID_FILE_EXPORT_XMLDOCUMENT, OnUpdateFileExportXmldocument)
  47. ON_COMMAND(ID_COMMANDBARS_MENUGRABBER, OnCommandbarsMenugrabber)
  48. //}}AFX_MSG_MAP
  49. // Standard printing commands
  50. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  51. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  52. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CCommandBarsDesignerDesignerView construction/destruction
  56. CCommandBarsDesignerDesignerView::CCommandBarsDesignerDesignerView()
  57. {
  58. m_pFrame  = NULL;
  59. }
  60. CCommandBarsDesignerDesignerView::~CCommandBarsDesignerDesignerView()
  61. {
  62. }
  63. BOOL CCommandBarsDesignerDesignerView::PreCreateWindow(CREATESTRUCT& cs)
  64. {
  65. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  66. return CView::PreCreateWindow(cs);
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CCommandBarsDesignerDesignerView drawing
  70. void CCommandBarsDesignerDesignerView::OnDraw(CDC* pDC)
  71. {
  72. CCommandBarsDesignerDoc* pDoc = GetDocument();
  73. ASSERT_VALID(pDoc);
  74. // TODO: add draw code for native data here
  75. //CRect rcFrame;
  76. //m_pFrame->GetWindowRect(&rcFrame);
  77. //ScreenToClient(&rcFrame);
  78. m_rectTracker.Draw(pDC);
  79. }
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CCommandBarsDesignerDesignerView printing
  82. BOOL CCommandBarsDesignerDesignerView::OnPreparePrinting(CPrintInfo* pInfo)
  83. {
  84. // default preparation
  85. return DoPreparePrinting(pInfo);
  86. }
  87. void CCommandBarsDesignerDesignerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  88. {
  89. // TODO: add extra initialization before printing
  90. }
  91. void CCommandBarsDesignerDesignerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  92. {
  93. // TODO: add cleanup after printing
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CCommandBarsDesignerDesignerView diagnostics
  97. #ifdef _DEBUG
  98. void CCommandBarsDesignerDesignerView::AssertValid() const
  99. {
  100. CView::AssertValid();
  101. }
  102. void CCommandBarsDesignerDesignerView::Dump(CDumpContext& dc) const
  103. {
  104. CView::Dump(dc);
  105. }
  106. CCommandBarsDesignerDoc* CCommandBarsDesignerDesignerView::GetDocument() // non-debug version is inline
  107. {
  108. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCommandBarsDesignerDoc)));
  109. return (CCommandBarsDesignerDoc*)m_pDocument;
  110. }
  111. #endif //_DEBUG
  112. /////////////////////////////////////////////////////////////////////////////
  113. // CCommandBarsDesignerDesignerView message handlers
  114. int CCommandBarsDesignerDesignerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  115. {
  116. if (CView::OnCreate(lpCreateStruct) == -1)
  117. return -1;
  118. if (m_pFrame == NULL)
  119. {
  120. m_pFrame = new CEmbeddedFrame();
  121. VERIFY(m_pFrame->LoadFrame(IDR_EMBEDDEDFRAME,
  122. WS_CHILD|WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, AfxGetMainWnd(), NULL));
  123. ((CEmbeddedFrame*)m_pFrame)->m_pHostView = this;
  124. }
  125. return 0;
  126. }
  127. void CCommandBarsDesignerDesignerView::OnInitialUpdate()
  128. {
  129. CView::OnInitialUpdate();
  130. ASSERT(m_pFrame);
  131. m_pFrame->SetParent(this);
  132. CRect rc (m_rectTracker.m_rect);
  133. m_pFrame->SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_SHOWWINDOW|SWP_NOZORDER|SWP_NOACTIVATE);
  134. OnUpdateFrameTitle();
  135. }
  136. void CCommandBarsDesignerDesignerView::OnUpdateFrameTitle()
  137. {
  138. m_pFrame->SetWindowText(GetDocument()->GetTitle());
  139. }
  140. BOOL CCommandBarsDesignerDesignerView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  141. {
  142. // convert cursor position to client co-ordinates
  143. CPoint point;
  144. GetCursorPos(&point);
  145. pWnd->ScreenToClient(&point);
  146. int nHit = m_rectTracker.HitTest(point);
  147. switch(nHit) {
  148. case CRectTracker::hitRight:
  149. ::SetCursor(::LoadCursor(0, IDC_SIZEWE));
  150. return TRUE;
  151. case CRectTracker::hitBottom:
  152. ::SetCursor(::LoadCursor(0, IDC_SIZENS));
  153. return TRUE;
  154. case CRectTracker::hitBottomRight:
  155. ::SetCursor(::LoadCursor(0, IDC_SIZENWSE));
  156. return TRUE;
  157. }
  158. return CView::OnSetCursor(pWnd, nHitTest, message);
  159. }
  160. void CCommandBarsDesignerDesignerView::OnLButtonDown(UINT nFlags, CPoint point)
  161. {
  162. int nHit = m_rectTracker.HitTest(point);
  163. if (nHit != CRectTracker::hitMiddle)
  164. {
  165. ASSERT(m_pFrame);
  166. if (m_rectTracker.Track(this, point))
  167. {
  168. CRect rc (m_rectTracker.m_rect);
  169. m_pFrame->SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER);
  170. Invalidate(TRUE);
  171. }
  172. }
  173. CView::OnLButtonDown(nFlags, point);
  174. }
  175. void CCommandBarsDesignerDesignerView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
  176. {
  177. // TODO: Add your specialized code here and/or call the base class
  178. CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  179. ((CMainFrame*)AfxGetMainWnd())->RefreshPanes();
  180. }
  181. void CCommandBarsDesignerDesignerView::OnCommandbarsSettings()
  182. {
  183. m_pFrame->ShowPropertyPage();
  184. }
  185. void CCommandBarsDesignerDesignerView::OnCommandbarsResourcesymbols()
  186. {
  187. CDialogResourceSymbols ds(m_pFrame);
  188. ds.DoModal();
  189. }
  190. void CCommandBarsDesignerDesignerView::OnFileExportXmldocument()
  191. {
  192. CString strFilter = _T("XML Document(*.xml)|*.xml|All files (*.*)|*.*||");
  193. CFileDialog fd(FALSE, _T("xml"), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
  194. if (fd.DoModal() != IDOK)
  195. return;
  196. CXTPPropExchangeXMLNode px(FALSE, 0, _T("DesignerFile"));
  197. m_pFrame->DoPropExchange(&px);
  198. px.SaveToFile(fd.GetFileName());
  199. }
  200. void CCommandBarsDesignerDesignerView::OnUpdateFileExportXmldocument(CCmdUI* pCmdUI)
  201. {
  202. pCmdUI->Enable(IsXMLEngineAvailable());
  203. }
  204. void CCommandBarsDesignerDesignerView::OnDesignMode()
  205. {
  206. CXTPCommandBars* pCommandBars = m_pFrame->GetCommandBars();
  207. BOOL bCustomizeMode = !pCommandBars->IsCustomizeMode();
  208. pCommandBars->SetCustomizeMode(bCustomizeMode);
  209. pCommandBars->m_bDesignerMode = bCustomizeMode;
  210. }
  211. void CCommandBarsDesignerDesignerView::OnUpdateDesignMode(CCmdUI* pCmdUI)
  212. {
  213. pCmdUI->SetCheck(m_pFrame->GetCommandBars()->IsCustomizeMode()? TRUE: FALSE);
  214. }
  215. void CCommandBarsDesignerDesignerView::OnCommandbarsMenugrabber() 
  216. {
  217. CXTPCommandBars* pCommandBars = m_pFrame->GetCommandBars();
  218. if (!pCommandBars)
  219. return;
  220. BOOL bCustomizeMode = pCommandBars->IsCustomizeMode();
  221. pCommandBars->SetCustomizeMode(FALSE);
  222. CDialogMenuGrabber ds(m_pFrame);
  223. if (ds.DoModal() == IDOK)
  224. {
  225. if (ds.m_wndMenuBar.GetControls()->GetCount() > 0)
  226. {
  227. CXTPMenuBar* pMenuBar = pCommandBars->GetMenuBar();
  228. if (!pMenuBar)
  229. return;
  230. pMenuBar->GetControls()->RemoveAll();
  231. pMenuBar->GetControls()->Copy(ds.m_wndMenuBar.GetControls());
  232. }
  233. }
  234. pCommandBars->SetCustomizeMode(bCustomizeMode);
  235. }