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

对话框与窗口

开发平台:

Visual C++

  1. // WorkspaceView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ribbonsample.h"
  5. #include "WorkspaceView.h"
  6. #include "RibbonSampleView.h"
  7. #include "MainFrm.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CWorkspaceView
  15. IMPLEMENT_DYNCREATE(CWorkspaceView, CView)
  16. CWorkspaceView::CWorkspaceView()
  17. {
  18. m_pView = 0;
  19. }
  20. CWorkspaceView::~CWorkspaceView()
  21. {
  22. }
  23. BEGIN_MESSAGE_MAP(CWorkspaceView, CView)
  24. //{{AFX_MSG_MAP(CWorkspaceView)
  25. ON_WM_CREATE()
  26. ON_WM_SIZE()
  27. ON_WM_ERASEBKGND()
  28. ON_WM_PAINT()
  29. ON_WM_VSCROLL()
  30. ON_WM_MOUSEACTIVATE()
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CWorkspaceView drawing
  35. void CWorkspaceView::OnDraw(CDC* /*pDC*/)
  36. {
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CWorkspaceView diagnostics
  40. #ifdef _DEBUG
  41. void CWorkspaceView::AssertValid() const
  42. {
  43. CView::AssertValid();
  44. }
  45. void CWorkspaceView::Dump(CDumpContext& dc) const
  46. {
  47. CView::Dump(dc);
  48. }
  49. #endif //_DEBUG
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CWorkspaceView message handlers
  52. int CWorkspaceView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  53. {
  54. if (CView::OnCreate(lpCreateStruct) == -1)
  55. return -1;
  56. ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
  57. CCreateContext contextT;
  58. contextT.m_pCurrentDoc     = GetDocument();
  59. contextT.m_pNewViewClass   = RUNTIME_CLASS(CRibbonSampleView);
  60. contextT.m_pNewDocTemplate = GetDocument()->GetDocTemplate();
  61. TRY
  62. {
  63. m_pView = (CRibbonSampleView*)contextT.m_pNewViewClass->CreateObject();
  64. if (m_pView == NULL)
  65. {
  66. AfxThrowMemoryException();
  67. }
  68. }
  69. CATCH_ALL(e)
  70. {
  71. TRACE0( "Out of memory creating a view.n" );
  72. // Note: DELETE_EXCEPTION(e) not required
  73. return FALSE;
  74. }
  75. END_CATCH_ALL
  76. DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
  77. dwStyle &= ~WS_BORDER;
  78. // Create with the right size (wrong position)
  79. CRect rect(0,0,0,0);
  80. if (!m_pView->Create(NULL, NULL, dwStyle,
  81. rect, this, AFX_IDW_PANE_FIRST, &contextT))
  82. {
  83. TRACE0( "Warning: couldn't create client tab for view.n" );
  84. // pWnd will be cleaned up by PostNcDestroy
  85. return NULL;
  86. }
  87. m_pView->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED);
  88. m_pView->ModifyStyle(0, WS_BORDER, SWP_FRAMECHANGED);
  89. m_pView->SetOwner(this);
  90. GetParentFrame()->SetActiveView(m_pView);
  91. m_wndScrollBar[SB_VERT].Create(WS_CHILD | WS_VISIBLE | SBS_VERT, CRect(10, 10, 50, 50), this, 100);
  92. m_wndScrollBar[SB_VERT].SetScrollBarStyle(xtpScrollStyleOffice2007Dark);
  93. //m_wndScrollBar[SB_HORZ].Create(WS_CHILD | WS_VISIBLE | SBS_HORZ, CRect(10, 10, 50, 50), this, 100);
  94. //m_wndScrollBar[SB_HORZ].SetScrollBarStyle(xtpScrollStyleOffice2007Dark);
  95. return 0;
  96. }
  97. void CWorkspaceView::Reposition(CSize sz)
  98. {
  99. BOOL bBothVisible = m_wndScrollBar[SB_VERT].GetSafeHwnd() && m_wndScrollBar[SB_HORZ].GetSafeHwnd();
  100. if (m_wndScrollBar[SB_VERT].GetSafeHwnd())
  101. {
  102. int nWidth = GetSystemMetrics(SM_CXVSCROLL);
  103. m_wndScrollBar[SB_VERT].MoveWindow(sz.cx - nWidth, 0, nWidth, sz.cy - (bBothVisible ? GetSystemMetrics(SM_CYHSCROLL) : 0));
  104. }
  105. if (m_wndScrollBar[SB_HORZ].GetSafeHwnd())
  106. {
  107. int nHeight = GetSystemMetrics(SM_CYHSCROLL);
  108. m_wndScrollBar[SB_HORZ].MoveWindow(0, sz.cy - nHeight, sz.cx - (bBothVisible ? GetSystemMetrics(SM_CXVSCROLL) : 0), nHeight);
  109. }
  110. if (m_pView)
  111. {
  112. CRect rc(GetViewRect(CRect(0, 0, sz.cx, sz.cy)));
  113. m_pView->MoveWindow(rc);
  114. }
  115. }
  116. void CWorkspaceView::OnSize(UINT nType, int cx, int cy) 
  117. {
  118. CView::OnSize(nType, cx, cy);
  119. Reposition(CSize(cx, cy));
  120. }
  121. CRect CWorkspaceView::GetViewRect(CRect rc)
  122. {
  123. if (m_wndScrollBar[SB_VERT].GetSafeHwnd())
  124. {
  125. int nWidth = GetSystemMetrics(SM_CXVSCROLL);
  126. rc.right -= nWidth;
  127. }
  128. if (m_wndScrollBar[SB_HORZ].GetSafeHwnd())
  129. {
  130. int nHeight = GetSystemMetrics(SM_CYHSCROLL);
  131. rc.bottom -= nHeight;
  132. }
  133. m_pView->CalcWindowRect(&rc, 0);
  134. return rc;
  135. }
  136. BOOL CWorkspaceView::OnEraseBkgnd(CDC* /*pDC*/) 
  137. {
  138. return TRUE;
  139. }
  140. void CWorkspaceView::OnPaint() 
  141. {
  142. CPaintDC dc(this);
  143. CXTPClientRect rc(this);
  144. if (m_wndScrollBar[SB_VERT].GetSafeHwnd())
  145. {
  146. rc.right -= CXTPWindowRect(&m_wndScrollBar[SB_VERT]).Width();
  147. }
  148. if (m_wndScrollBar[SB_HORZ].GetSafeHwnd())
  149. {
  150. rc.bottom -= CXTPWindowRect(&m_wndScrollBar[SB_HORZ]).Height();
  151. }
  152. CXTPWindowRect rcClient(GetDlgItem(AFX_IDW_PANE_FIRST));
  153. ScreenToClient(&rcClient);
  154. CXTPCommandBars* pCommandBars = ((CMainFrame*)GetParentFrame())->GetCommandBars();
  155. ((CXTPOffice2007Theme*)(pCommandBars->GetPaintManager()))->FillWorkspace(&dc, rc, rcClient);
  156. }
  157. void CWorkspaceView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  158. {
  159. m_pView->OnVScroll(nSBCode, nPos, pScrollBar);
  160. }
  161. BOOL CWorkspaceView::PreCreateWindow(CREATESTRUCT& cs) 
  162. {
  163. return CView::PreCreateWindow(cs);
  164. }
  165. void CWorkspaceView::SetLayoutRTL(BOOL bRTLLayout)
  166. {
  167. ModifyStyleEx(bRTLLayout ? 0 : WS_EX_LAYOUTRTL, !bRTLLayout ? 0 : WS_EX_LAYOUTRTL);
  168. Reposition(CXTPClientRect(this).Size());
  169. Invalidate(FALSE);
  170. }
  171. int CWorkspaceView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) 
  172. {
  173. // Don't call CView::OnMouseActivate.
  174. return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
  175. }