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

对话框与窗口

开发平台:

Visual C++

  1. // XTPControlPopup.cpp : implementation of the CXTPControlPopup 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/XTPHookManager.h"
  22. #include "XTPControlPopup.h"
  23. #include "XTPCommandBar.h"
  24. #include "XTPControls.h"
  25. #include "XTPPopupBar.h"
  26. #include "XTPPaintManager.h"
  27. #include "XTPToolBar.h"
  28. #include "XTPCommandBars.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. IMPLEMENT_XTP_CONTROL(CXTPControlPopup, CXTPControlButton)
  35. CXTPControlPopup::CXTPControlPopup()
  36. {
  37. EnableAutomation();
  38. m_controlType = xtpControlPopup;
  39. m_bPopup = FALSE;
  40. m_pCommandBar = NULL;
  41. m_dwCommandBarID = 0;
  42. m_bShowShadow = TRUE;
  43. }
  44. CXTPControlPopup::~CXTPControlPopup()
  45. {
  46. if (m_pCommandBar)
  47. m_pCommandBar->InternalRelease();
  48. }
  49. CXTPControlPopup* CXTPControlPopup::CreateControlPopup(XTPControlType controlType)
  50. {
  51. ASSERT(IsPopupControlType(controlType));
  52. CXTPControlPopup* pControl = (CXTPControlPopup*)CXTPControlPopup::CreateObject();
  53. pControl->m_controlType = controlType;
  54. return pControl;
  55. }
  56. void CXTPControlPopup::OnUnderlineActivate()
  57. {
  58. if (m_pCommandBar)
  59. m_pParent->SetPopuped(m_nIndex, TRUE);
  60. else
  61. CXTPControlButton::OnUnderlineActivate();
  62. }
  63. void CXTPControlPopup::OnClick(BOOL bKeyboard, CPoint pt)
  64. {
  65. if (!GetEnabled())
  66. return;
  67. if (IsCustomizeMode())
  68. {
  69. ASSERT(m_pParent);
  70. if (!m_pParent)
  71. return;
  72. CXTPCommandBars* pCommandBars = m_pParent->GetCommandBars();
  73. ASSERT(pCommandBars);
  74. if (!pCommandBars)
  75. return;
  76. pCommandBars->SetDragControl(this);
  77. }
  78. if (m_bPopup && (GetParent()->GetPosition() != xtpBarPopup))
  79. m_pParent->SetTrackingMode(FALSE, FALSE);
  80. else
  81. {
  82. if (!IsCustomizeMode() && (m_controlType == xtpControlSplitButtonPopup))
  83. {
  84. if (bKeyboard)
  85. {
  86. if (GetEnabled() != TRUE_SPLITDROPDOWN)
  87. OnExecute();
  88. else
  89. m_pParent->SetPopuped(m_nIndex);
  90. return;
  91. }
  92. CRect rcCommandRect = GetPaintManager()->GetSplitButtonCommandRect(this);
  93. if ((m_pParent->GetType() == xtpBarTypePopup) && rcCommandRect.PtInRect(pt))
  94. {
  95. m_pParent->KillTimer(XTP_TID_HOVER);
  96. return;
  97. }
  98. if ((m_pParent->GetType() != xtpBarTypePopup) && rcCommandRect.PtInRect(pt))
  99. {
  100. if (GetEnabled() != TRUE_SPLITDROPDOWN)
  101. ClickToolBarButton(rcCommandRect);
  102. return;
  103. }
  104. if (GetEnabled() == TRUE_SPLITCOMMAND)
  105. return;
  106. }
  107. if (!(IsCustomizeMode() && m_pCommandBar && !m_pCommandBar->IsCustomizable()))
  108. {
  109. m_pParent->SetPopuped(m_nIndex);
  110. }
  111. }
  112. if (IsCustomizeMode())
  113. {
  114. CustomizeStartDrag(pt);
  115. }
  116. }
  117. void CXTPControlPopup::OnLButtonUp(CPoint point)
  118. {
  119. if (!m_pCommandBar)
  120. {
  121. CXTPControlButton::OnLButtonUp(point);
  122. return;
  123. }
  124. if (GetEnabled() && GetType() == xtpControlSplitButtonPopup && m_pParent->GetType() == xtpBarTypePopup)
  125. {
  126. if (m_rcControl.right > point.x + GetPaintManager()->m_nSplitButtonPopupWidth && GetEnabled() != TRUE_SPLITDROPDOWN)
  127. OnExecute();
  128. }
  129. }
  130. void CXTPControlPopup::OnMouseMove(CPoint point)
  131. {
  132. if (!m_pCommandBar)
  133. {
  134. CXTPControlButton::OnMouseMove(point);
  135. return;
  136. }
  137. if (GetEnabled() && GetType() == xtpControlSplitButtonPopup && m_bSelected)
  138. {
  139. CRect rcCommandRect = GetPaintManager()->GetSplitButtonCommandRect(this);
  140. if (rcCommandRect.PtInRect(point) && m_bSelected != TRUE_SPLITCOMMAND)
  141. {
  142. m_bSelected = TRUE_SPLITCOMMAND;
  143. RedrawParent(FALSE);
  144. }
  145. else if (!rcCommandRect.PtInRect(point) && m_bSelected != TRUE_SPLITDROPDOWN)
  146. {
  147. m_bSelected = TRUE_SPLITDROPDOWN;
  148. RedrawParent(FALSE);
  149. }
  150. }
  151. }
  152. BOOL CXTPControlPopup::OnSetSelected(int bSelected)
  153. {
  154. if (!CXTPControlButton::OnSetSelected(bSelected))
  155. return FALSE;
  156. if (!m_pCommandBar)
  157. return TRUE;
  158. if (m_controlType == xtpControlPopup || m_pParent->GetType() == xtpBarTypePopup)
  159. {
  160. if (GetEnabled() && bSelected && m_pParent->IsTrackingMode() == TRUE_POPUP && GetParent()->GetPosition() != xtpBarPopup)
  161. {
  162. m_pParent->SetPopuped(m_nIndex);
  163. }
  164. else if (!bSelected && m_bPopup && GetParent()->GetPosition() != xtpBarPopup)
  165. {
  166. m_pParent->SetPopuped(-1);
  167. }
  168. }
  169. else
  170. {
  171. if (GetEnabled() && IsKeyboardSelected(bSelected) && m_pParent->IsTrackingMode() == TRUE_POPUP)
  172. {
  173. m_pParent->SetPopuped(m_nIndex);
  174. }
  175. }
  176. return TRUE;
  177. }
  178. void CXTPControlPopup::UpdateShadow()
  179. {
  180. if (m_pCommandBar && m_pParent->GetPosition() != xtpBarPopup && IsPopupControlType(m_controlType))
  181. {
  182. if (m_pParent->GetPosition() == xtpBarFloating && m_pParent->GetType() == xtpBarTypePopup)
  183. return;
  184. CXTPPaintManager* pPaintManager = GetPaintManager();
  185. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, m_pCommandBar);
  186. if (pPaintManager && pPopupBar && pPopupBar->m_bShowShadow && m_bShowShadow && pPaintManager->m_bShowShadow && !m_pParent->IsCustomizeMode())
  187. {
  188. CRect rc = GetRect();
  189. GetParent()->ClientToScreen(&rc);
  190. pPaintManager->GetShadowManager()->SetShadow(rc, m_pCommandBar);
  191. }
  192. }
  193. }
  194. BOOL CXTPControlPopup::OnSetPopup(BOOL bPopup)
  195. {
  196. if (!m_pCommandBar)
  197. return FALSE;
  198. if (GetType() == xtpControlSplitButtonPopup && GetEnabled() == TRUE_SPLITCOMMAND)
  199. return FALSE;
  200. if (m_pParent->GetSafeHwnd() == NULL)
  201. return FALSE;
  202. m_bPopup = bPopup;
  203. if (bPopup)
  204. {
  205. RedrawParent(FALSE);
  206. m_pParent->GetSite()->UpdateWindow();
  207. m_pParent->UpdateWindow();
  208. if (!m_pCommandBar->IsTrackingMode())
  209. {
  210. if (!m_pCommandBar->Popup(this, IsKeyboardSelected(GetSelected())))
  211. return FALSE;
  212. UpdateShadow();
  213. }
  214. }
  215. else
  216. {
  217. m_pCommandBar->SetTrackingMode(FALSE);
  218. RedrawParent();
  219. }
  220. return TRUE;
  221. }
  222. void CXTPControlPopup::ExpandCommandBar()
  223. {
  224. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, m_pCommandBar);
  225. if (m_bPopup && pPopupBar && m_controlType == xtpControlPopup)
  226. {
  227. pPopupBar->ExpandBar();
  228. }
  229. }
  230. void CXTPControlPopup::OnMouseHover()
  231. {
  232. if (m_pCommandBar && GetEnabled() && (m_pParent->IsTrackingMode() == TRUE_POPUP || GetParent()->GetPosition() == xtpBarPopup))
  233. GetParent()->SetPopuped(m_nIndex);
  234. else CXTPControlButton::OnMouseHover();
  235. }
  236. BOOL CXTPControlPopup::OnLButtonDblClk(CPoint point)
  237. {
  238. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, m_pCommandBar);
  239. if (pPopupBar && (m_controlType == xtpControlPopup || m_controlType == xtpControlButtonPopup))
  240. {
  241. if (!m_bPopup)
  242. m_pParent->OnLButtonDown(0, point);
  243. if (m_pCommandBar != pPopupBar)
  244. return FALSE;
  245. if (m_bPopup && pPopupBar->GetDefaultItem(0, TRUE) != (UINT)-1)
  246. {
  247. CXTPControl* pControl = pPopupBar->GetControl(pPopupBar->GetDefaultItem(0, TRUE));
  248. pControl->OnExecute();
  249. return TRUE;
  250. }
  251. if (m_bPopup && pPopupBar->m_bCollapsed)
  252. {
  253. pPopupBar->ExpandBar();
  254. return TRUE;
  255. }
  256. }
  257. else
  258. {
  259. return CXTPControlButton::OnLButtonDblClk(point);
  260. }
  261. return FALSE;
  262. }
  263. void CXTPControlPopup::Copy(CXTPControl* pControl, BOOL bRecursive)
  264. {
  265. ASSERT(DYNAMIC_DOWNCAST(CXTPControlPopup, pControl));
  266. CXTPControlButton::Copy(pControl, bRecursive);
  267. if (bRecursive && ((CXTPControlPopup*)pControl)->m_pCommandBar)
  268. {
  269. CXTPCommandBar* pCommandBar = ((CXTPControlPopup*)pControl)->m_pCommandBar->Clone(bRecursive);
  270. SetCommandBar(pCommandBar);
  271. pCommandBar->InternalRelease();
  272. }
  273. else
  274. {
  275. SetCommandBar(((CXTPControlPopup*)pControl)->m_pCommandBar);
  276. }
  277. }
  278. void CXTPControlPopup::SetCommandBar(CXTPCommandBar* pBar)
  279. {
  280. if (m_pCommandBar)
  281. m_pCommandBar->InternalRelease();
  282. m_pCommandBar = pBar;
  283. if (m_pCommandBar)
  284. m_pCommandBar->InternalAddRef();
  285. }
  286. void CXTPControlPopup::SetCommandBar(CMenu* pMenu)
  287. {
  288. if (!m_pCommandBar)
  289. m_pCommandBar = CXTPPopupBar::CreatePopupBar(m_pParent ? m_pParent->GetCommandBars() : NULL);
  290. m_pCommandBar->LoadMenu(pMenu);
  291. }
  292. BOOL CXTPControlPopup::IsContainPopup(CXTPControlPopup* pControlPopup)
  293. {
  294. if (!m_pCommandBar || !pControlPopup->GetCommandBar())
  295. return FALSE;
  296. if (m_pCommandBar == pControlPopup->GetCommandBar()) return TRUE;
  297. for (int i = 0; i < m_pCommandBar->GetControlCount(); i++)
  298. {
  299. CXTPControlPopup* pControlChild = DYNAMIC_DOWNCAST(CXTPControlPopup, m_pCommandBar->GetControl(i));
  300. if (pControlChild)
  301. {
  302. if (pControlPopup->IsContainPopup(pControlChild))
  303. return TRUE;
  304. if (pControlChild->IsContainPopup(pControlPopup))
  305. return TRUE;
  306. }
  307. }
  308. return FALSE;
  309. }
  310. BOOL CXTPControlPopup::Compare(CXTPControl* pOther)
  311. {
  312. if (!CXTPControlButton::Compare(pOther))
  313. return FALSE;
  314. CXTPControlPopup* pPopup = DYNAMIC_DOWNCAST(CXTPControlPopup, pOther);
  315. if (!pPopup)
  316. return FALSE;
  317. if (m_pCommandBar != NULL && pPopup->m_pCommandBar != NULL)
  318. {
  319. if (!m_pCommandBar->GetControls()->Compare(pPopup->m_pCommandBar->GetControls()))
  320. return FALSE;
  321. }
  322. return TRUE;
  323. }
  324. BOOL CXTPControlPopup::IsCustomizeDragOverAvail(CXTPCommandBar* pCommandBar, CPoint /*point*/, DROPEFFECT& /*dropEffect*/)
  325. {
  326. while (pCommandBar != NULL)
  327. {
  328. if (pCommandBar == m_pCommandBar)
  329. return FALSE;
  330. pCommandBar = pCommandBar->GetParentCommandBar();
  331. }
  332. return TRUE;
  333. }
  334. void CXTPControlPopup::OnCustomizeDragOver(CXTPControl* pDataObject, CPoint /*point*/, DROPEFFECT& /*dropEffect*/)
  335. {
  336. if (m_pCommandBar && m_pCommandBar->IsCustomizable())
  337. {
  338. CXTPControlPopup* pControlPopup = DYNAMIC_DOWNCAST(CXTPControlPopup, pDataObject);
  339. if (!(pControlPopup && pControlPopup->IsContainPopup(this)))
  340. {
  341. m_pParent->SetPopuped(m_nIndex);
  342. }
  343. else
  344. {
  345. m_pParent->SetPopuped(-1);
  346. m_pParent->SetSelected(-1);
  347. }
  348. }
  349. }
  350. void CXTPControlPopup::AdjustExcludeRect(CRect& rc, BOOL bVertical)
  351. {
  352. GetPaintManager()->AdjustExcludeRect(rc, this, bVertical);
  353. }