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

对话框与窗口

开发平台:

Visual C++

  1. // XTPControlCustom.cpp : implementation of the CXTPControlCustom class.
  2. //
  3. // This file is a part of the XTREME COMMANDBARS 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 "Common/XTPDrawHelpers.h"
  22. #include "Common/XTPPropExchange.h"
  23. #include "Common/XTPHookManager.h"
  24. #include "XTPCommandBar.h"
  25. #include "XTPToolBar.h"
  26. #include "XTPCommandBars.h"
  27. #include "XTPControlCustom.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. ////////////////////////////
  34. IMPLEMENT_XTP_CONTROL(CXTPControlCustom, CXTPControlButton)
  35. CXTPControlCustom::CXTPControlCustom()
  36. {
  37. m_hwndControl = NULL;
  38. m_rcBorders.SetRectEmpty();
  39. m_verticalOptions = xtpVerticalHide;
  40. m_bControlVisible = TRUE;
  41. m_dwFlags = xtpFlagNoMovable;
  42. m_nControlID = 0;
  43. EnableAutomation();
  44. }
  45. CXTPControlCustom::~CXTPControlCustom()
  46. {
  47. XTPHookManager()->RemoveAll(this);
  48. }
  49. void CXTPControlCustom::SetControl(CWnd* pWnd)
  50. {
  51. XTPHookManager()->RemoveAll(this);
  52. m_hwndControl = pWnd->GetSafeHwnd();
  53. if (m_hwndControl)
  54. {
  55. XTPHookManager()->SetHook(m_hwndControl, this);
  56. CXTPWindowRect rc(m_hwndControl);
  57. m_szControl = CSize(rc.Width(), rc.Height());
  58. }
  59. }
  60. int CXTPControlCustom::OnHookMessage(HWND hWnd, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& /*lResult*/)
  61. {
  62. if (nMessage == WM_MOUSEMOVE)
  63. {
  64. CPoint point(lParam);
  65. MapWindowPoints(hWnd, m_pParent->GetSafeHwnd(), &point, 1);
  66. GetParent()->OnMouseMove((UINT)wParam, point);
  67. }
  68. return FALSE;
  69. }
  70. void CXTPControlCustom::SetSize(CSize szControl)
  71. {
  72. m_szControl = szControl;
  73. }
  74. CWnd* CXTPControlCustom::GetControl()
  75. {
  76. return CWnd::FromHandle(m_hwndControl);
  77. }
  78. CSize CXTPControlCustom::GetSize(CDC* pDC)
  79. {
  80. if (m_hwndControl && m_bControlVisible)
  81. {
  82. return CSize(m_szControl.cx + m_rcBorders.left + m_rcBorders.right, m_szControl.cy + m_rcBorders.top + m_rcBorders.bottom);
  83. }
  84. return CXTPControlButton::GetSize(pDC);
  85. }
  86. void CXTPControlCustom::SetRect(CRect rcControl)
  87. {
  88. if (m_rcControl == rcControl && !(m_hwndControl && ::GetParent(m_hwndControl) != m_pParent->GetSafeHwnd()))
  89. return;
  90. m_rcControl = rcControl;
  91. CWnd* pControlWnd = CWnd::FromHandle(m_hwndControl);
  92. if (pControlWnd && pControlWnd->GetSafeHwnd() && ::IsWindow(pControlWnd->GetSafeHwnd()))
  93. {
  94. pControlWnd->SetParent(m_pParent);
  95. pControlWnd->ModifyStyle(WS_POPUP, WS_CHILD);
  96. rcControl.DeflateRect(m_rcBorders);
  97. pControlWnd->MoveWindow(rcControl);
  98. ShowHideChildControl();
  99. }
  100. }
  101. void CXTPControlCustom::SetEnabled(BOOL bEnabled)
  102. {
  103. if (bEnabled != m_bEnabled)
  104. {
  105. m_bEnabled = bEnabled;
  106. if (m_hwndControl)
  107. {
  108. ::EnableWindow(m_hwndControl, bEnabled);
  109. }
  110. RedrawParent();
  111. }
  112. }
  113. void CXTPControlCustom::ShowHideChildControl()
  114. {
  115. if (m_pControls && m_pControls->IsOriginalControls())
  116. return;
  117. if (!m_pParent || (::GetParent(m_hwndControl) != m_pParent->GetSafeHwnd()))
  118. return;
  119. if (m_hwndControl)
  120. {
  121. ::SetWindowPos(m_hwndControl, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE
  122. | (m_pParent && m_bControlVisible && IsVisible() && m_pParent->GetSafeHwnd() ? SWP_SHOWWINDOW : SWP_HIDEWINDOW));
  123. }
  124. }
  125. void CXTPControlCustom::OnRemoved()
  126. {
  127. m_bControlVisible = FALSE;
  128. ShowHideChildControl();
  129. CXTPControlButton::OnRemoved();
  130. }
  131. void CXTPControlCustom::SetHideFlags(DWORD dwFlags)
  132. {
  133. if (m_dwHideFlags != dwFlags)
  134. {
  135. m_dwHideFlags = dwFlags;
  136. ShowHideChildControl();
  137. DelayLayoutParent();
  138. }
  139. }
  140. void CXTPControlCustom::OnActionChanged(int nProperty)
  141. {
  142. if (nProperty == 2 && m_hwndControl)
  143. {
  144. ShowHideChildControl();
  145. }
  146. }
  147. void CXTPControlCustom::OnCalcDynamicSize(DWORD dwMode)
  148. {
  149. if (m_verticalOptions == xtpVerticalHide)
  150. {
  151. if (dwMode & LM_VERTDOCK) SetHideFlags(m_dwHideFlags | xtpHideDockingPosition);
  152. else SetHideFlags(m_dwHideFlags & ~xtpHideDockingPosition);
  153. }
  154. if (m_verticalOptions == xtpVerticalButton)
  155. {
  156. m_bControlVisible = (dwMode & LM_VERTDOCK) == 0;
  157. ShowHideChildControl();
  158. }
  159. }
  160. void CXTPControlCustom::Copy(CXTPControl* pControl, BOOL bRecursive)
  161. {
  162. ASSERT(DYNAMIC_DOWNCAST(CXTPControlCustom, pControl));
  163. m_rcBorders = ((CXTPControlCustom*)pControl)->m_rcBorders;
  164. m_verticalOptions = ((CXTPControlCustom*)pControl)->m_verticalOptions;
  165. m_szControl = ((CXTPControlCustom*)pControl)->m_szControl;
  166. m_hwndControl = ((CXTPControlCustom*)pControl)->m_hwndControl;
  167. m_nControlID = ((CXTPControlCustom*)pControl)->m_nControlID;
  168. CXTPControl::Copy(pControl, bRecursive);
  169. }
  170. BOOL CXTPControlCustom::IsCustomizeDragOverAvail(CXTPCommandBar* pCommandBar, CPoint /*point*/, DROPEFFECT& dropEffect)
  171. {
  172. if (pCommandBar->GetType() != xtpBarTypePopup)
  173. {
  174. dropEffect = DROPEFFECT_NONE;
  175. return FALSE;
  176. }
  177. return TRUE;
  178. }
  179. void CXTPControlCustom::Draw(CDC* pDC)
  180. {
  181. if (m_hwndControl && ::IsWindowVisible(m_hwndControl))
  182. return;
  183. CXTPControlButton::Draw(pDC);
  184. }
  185. void CXTPControlCustom::OnClick(BOOL bKeyboard, CPoint pt)
  186. {
  187. if (m_hwndControl && ::IsWindowVisible(m_hwndControl) && !IsCustomizeMode())
  188. return;
  189. CXTPControlButton::OnClick(bKeyboard, pt);
  190. }
  191. void CXTPControlCustom::SetBorders(int cxRight, int cxTop, int cxLeft, int cxBottom)
  192. {
  193. m_rcBorders.SetRect(cxRight, cxTop, cxLeft, cxBottom);
  194. }
  195. void CXTPControlCustom::SetVerticalPositionOption(XTPControlCustomVerticalOptions options)
  196. {
  197. m_verticalOptions = options;
  198. }
  199. CWnd* CXTPControlCustom::FindChildWindow(CXTPCommandBars* pCommandBars, UINT nID)
  200. {
  201. CWnd* pWndSite = pCommandBars->GetSite();
  202. if (pWndSite->GetDlgItem(nID) != NULL)
  203. return pWndSite->GetDlgItem(nID);
  204. for (int i = 0; i < pCommandBars->GetCount(); i++)
  205. {
  206. CXTPToolBar* pToolBar = pCommandBars->GetAt(i);
  207. if (pToolBar->GetDlgItem(nID) != NULL)
  208. return pToolBar->GetDlgItem(nID);
  209. }
  210. return NULL;
  211. }
  212. void CXTPControlCustom::DoPropExchange(CXTPPropExchange* pPX)
  213. {
  214. CXTPControlButton::DoPropExchange(pPX);
  215. PX_Rect(pPX, _T("Borders"), m_rcBorders, CRect(0, 0, 0, 0));
  216. PX_Size(pPX, _T("ControlSize"), m_szControl, CSize(0, 0));
  217. PX_Enum(pPX, _T("VerticalOptions"), m_verticalOptions, xtpVerticalHide);
  218. if (pPX->GetSchema() > _XTP_SCHEMA_861)
  219. {
  220. PX_Int(pPX, _T("ControlId"), m_nControlID, 0);
  221. }
  222. if (pPX->IsLoading() && m_nControlID != 0)
  223. {
  224. CXTPCommandBars* pCommandBars = ((XTP_COMMANDBARS_PROPEXCHANGE_PARAM*)pPX->m_dwData)->pCommandBars;
  225. ASSERT(pCommandBars->IsKindOf(RUNTIME_CLASS(CXTPCommandBars)));
  226. ASSERT(pCommandBars && pCommandBars->GetSite());
  227. CWnd* pWnd = FindChildWindow(pCommandBars, m_nControlID);
  228. if (pWnd)
  229. {
  230. m_hwndControl = pWnd->GetSafeHwnd();
  231. }
  232. }
  233. }
  234. CXTPControlCustom* CXTPControlCustom::CreateControlCustom(CWnd* pWndChild)
  235. {
  236. CXTPControlCustom* pControlCustom = (CXTPControlCustom*)CreateObject();
  237. pControlCustom->SetControl(pWndChild);
  238. pControlCustom->m_nControlID = pWndChild->GetDlgCtrlID();
  239. return pControlCustom;
  240. }