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

对话框与窗口

开发平台:

Visual C++

  1. // EclipseHost.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 "gui_eclipse.h"
  22. #include "EclipseHost.h"
  23. #include "MainFrm.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CEclipseHost
  31. CEclipseHost::CEclipseHost()
  32. {
  33. LOGFONT lfIcon;
  34. VERIFY( ::SystemParametersInfo( SPI_GETICONTITLELOGFONT, sizeof( lfIcon ), &lfIcon, 0 ) );
  35. lfIcon.lfWeight = FW_NORMAL;
  36. VERIFY( m_fntNormal.CreateFontIndirect(&lfIcon  ) );
  37. m_bActive = FALSE;
  38. m_nID = 0;
  39. m_hIcon = 0;
  40. m_nHeaderHeight = m_szCaption.cy =  25;
  41. }
  42. CEclipseHost::~CEclipseHost()
  43. {
  44. }
  45. void CEclipseHost::SetHostParams(UINT nID, HICON hIcon)
  46. {
  47. m_nID = nID;
  48. m_strTitle.LoadString(nID);
  49. m_hIcon = hIcon;
  50. CBitmap bmp;
  51. if (bmp.LoadBitmap(nID))
  52. {
  53. m_wndToolBar.CreateToolBar(WS_CHILD|WS_VISIBLE|CBRS_TOOLTIPS, this, AFX_IDW_TOOLBAR);
  54. m_wndToolBar.LoadToolBar(nID);
  55. CMainFrame::AddIcons(nID);
  56. }
  57. m_wndHostBar.CreateToolBar(WS_CHILD|WS_VISIBLE|CBRS_TOOLTIPS, this, AFX_IDW_TOOLBAR + 1);
  58. m_wndHostBar.LoadToolBar(ID_PANE_HOST);
  59. }
  60. BEGIN_MESSAGE_MAP(CEclipseHost, CWnd)
  61. //{{AFX_MSG_MAP(CEclipseHost)
  62. ON_WM_SIZE()
  63. ON_WM_PAINT()
  64. ON_WM_ERASEBKGND()
  65. ON_WM_LBUTTONDOWN()
  66. ON_WM_LBUTTONDBLCLK()
  67. ON_COMMAND(ID_PANE_CLOSE, OnPaneClose)
  68. ON_COMMAND(ID_PANE_HIDE, OnPaneHide)
  69. //}}AFX_MSG_MAP
  70. ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CEclipseHost message handlers
  74. void CEclipseHost::OnLButtonDown(UINT /*nFlags*/, CPoint point)
  75. {
  76. if (point.y < m_szCaption.cy)
  77. {
  78. CXTPDockingPaneTabbedContainer* pContainer = DYNAMIC_DOWNCAST(CXTPDockingPaneTabbedContainer, GetParent());
  79. ASSERT(pContainer);
  80. if (pContainer)
  81. {
  82. ClientToScreen(&point);
  83. pContainer->OnCaptionLButtonDown(point);
  84. }
  85. }
  86. }
  87. void CEclipseHost::OnLButtonDblClk(UINT /*nFlags*/, CPoint point)
  88. {
  89. if (point.y < m_szCaption.cy)
  90. {
  91. CXTPDockingPaneTabbedContainer* pContainer = DYNAMIC_DOWNCAST(CXTPDockingPaneTabbedContainer, GetParent());
  92. ASSERT(pContainer);
  93. if (pContainer)
  94. {
  95. pContainer->GetDockingPaneManager()->ToggleDocking(pContainer);
  96. }
  97. }
  98. }
  99. void CEclipseHost::OnSize(UINT nType, int cx, int cy)
  100. {
  101. CWnd::OnSize(nType, cx, cy);
  102. if (!GetClientWnd() || !m_wndHostBar.GetSafeHwnd())
  103. return;
  104. CSize szToolBar(0);
  105. if (m_wndToolBar.GetSafeHwnd())
  106. szToolBar = m_wndToolBar.CalcDockingLayout(32000, LM_HORZDOCK|LM_HORZ | LM_COMMIT);
  107. CSize szHostBar = m_wndHostBar.CalcDockingLayout(32000, LM_HORZDOCK|LM_HORZ | LM_COMMIT);
  108. m_nHeaderHeight = m_szCaption.cy = szHostBar.cy + 1;
  109. m_szCaption.cx = cx - szToolBar.cx - szHostBar.cx;
  110. m_wndHostBar.MoveWindow(cx - szHostBar.cx, 0, szHostBar.cx, szHostBar.cy);
  111. CClientDC dc(this);
  112. CSize sz = dc.GetTextExtent(m_strTitle);
  113. if (m_wndToolBar.GetSafeHwnd())
  114. {
  115. if (szHostBar.cx + szToolBar.cx < cx - 5 - 16 - sz.cx)
  116. {
  117. m_wndToolBar.MoveWindow(cx - szToolBar.cx - szHostBar.cx, 0, szToolBar.cx, szToolBar.cy);
  118. } else
  119. {
  120. szToolBar = m_wndToolBar.CalcDockingLayout(cx, LM_HORZDOCK|LM_HORZ | LM_COMMIT);
  121. m_szCaption.cx = cx - szHostBar.cx;
  122. m_nHeaderHeight = m_szCaption.cy + szToolBar.cy;
  123. m_wndToolBar.MoveWindow(0, m_szCaption.cy, cx, szToolBar.cy);
  124. }
  125. m_wndToolBar.Invalidate(FALSE);
  126. }
  127. m_wndHostBar.Invalidate(FALSE);
  128. CWnd* pWnd = GetClientWnd();
  129. pWnd->MoveWindow(0, m_nHeaderHeight, cx, cy - m_nHeaderHeight);
  130. pWnd->Invalidate(FALSE);
  131. Invalidate(FALSE);
  132. }
  133. void CEclipseHost::OnPaint()
  134. {
  135. CPaintDC dcPaint(this); // device context for painting
  136. CXTPClientRect rc(this);
  137. CXTPBufferDC dc(dcPaint, rc);
  138. CXTPFontDC fnt(&dc, &m_fntNormal);
  139. dc.FillSolidRect(rc, GetXtremeColor(COLOR_WINDOW));
  140. CRect rcTitle(rc.left, rc.top, rc.right, rc.top + m_szCaption.cy);
  141. CRect rcFill(rc.left, rc.top, rc.left + m_szCaption.cx, rc.top + m_szCaption.cy);
  142. dc.FillSolidRect(rcTitle, XTPPaintManager()->GetXtremeColor(XPCOLOR_TOOLBAR_FACE));
  143. if (m_bActive)
  144. {
  145. XTPDrawHelpers()->GradientFill(&dc, rcFill, GetXtremeColor(COLOR_ACTIVECAPTION), XTPPaintManager()->GetXtremeColor(XPCOLOR_TOOLBAR_FACE), TRUE);
  146. }
  147. dc.FillSolidRect(rcTitle.left, rcTitle.bottom - 1, rcTitle.Width(), 1, RGB(132, 130, 132));
  148. if (m_hIcon)
  149. dc.DrawState(CPoint(rcTitle.left + 5, rcTitle.CenterPoint().y - 8), CSize(16, 16), m_hIcon, 0, (CBrush*)0);
  150. CRect rcText(rcTitle.left + 5 + 16 + 5, rcTitle.top, rcFill.right, rcTitle.bottom);
  151. dc.SetTextColor(!m_bActive? 0: GetXtremeColor(COLOR_CAPTIONTEXT));
  152. dc.SetBkMode(TRANSPARENT);
  153. dc.DrawText(m_strTitle, rcText, DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS);
  154. }
  155. BOOL CEclipseHost::OnEraseBkgnd(CDC* /*pDC*/)
  156. {
  157. return TRUE;
  158. }
  159. LRESULT CEclipseHost::OnIdleUpdateCmdUI(WPARAM, LPARAM)
  160. {
  161. CWnd* pFocus = GetFocus();
  162. BOOL bActive = (pFocus->GetSafeHwnd() && (pFocus == this || IsChild(pFocus)));
  163. if (bActive != m_bActive)
  164. {
  165. m_bActive = bActive;
  166. Invalidate(FALSE);
  167. }
  168. return 0L;
  169. }
  170. BOOL CEclipseHost::Create(CWnd* pParentWnd)
  171. {
  172. return CreateEx(0, _T("STATIC"), _T(""),
  173. SS_NOTIFY|WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0,200, 120), pParentWnd, 0);
  174. }
  175. void CEclipseHost::OnPaneClose()
  176. {
  177. CXTPDockingPaneTabbedContainer* pContainer = DYNAMIC_DOWNCAST(CXTPDockingPaneTabbedContainer, GetParent());
  178. if (pContainer && pContainer->GetSelected())
  179. {
  180. pContainer->GetSelected()->Close();
  181. }
  182. }
  183. void CEclipseHost::OnPaneHide()
  184. {
  185. CXTPDockingPaneTabbedContainer* pContainer = DYNAMIC_DOWNCAST(CXTPDockingPaneTabbedContainer, GetParent());
  186. if (pContainer && pContainer->GetSelected())
  187. {
  188. if (!pContainer->IsHidden()) pContainer->GetSelected()->Hide();
  189. else pContainer->GetDockingPaneManager()->ToggleDocking(pContainer);
  190. }
  191. }