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

对话框与窗口

开发平台:

Visual C++

  1. // XTPRibbonTab.cpp: implementation of the CXTPRibbonTab class.
  2. //
  3. // This file is a part of the XTREME RIBBON 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/XTPImageManager.h"
  22. #include "Common/XTPDrawHelpers.h"
  23. #include "Common/XTPToolTipContext.h"
  24. #include "Common/XTPPropExchange.h"
  25. #include "CommandBars/XTPCommandBars.h"
  26. #include "CommandBars/XTPMouseManager.h"
  27. #include "XTPRibbonControlTab.h"
  28. #include "XTPRibbonBar.h"
  29. #include "XTPRibbonTab.h"
  30. #include "XTPRibbonTheme.h"
  31. #include "XTPRibbonGroups.h"
  32. #include "XTPRibbonGroup.h"
  33. #ifdef _DEBUG
  34. #undef THIS_FILE
  35. static char THIS_FILE[]=__FILE__;
  36. #define new DEBUG_NEW
  37. #endif
  38. IMPLEMENT_XTP_CONTROL(CXTPRibbonControlTab, CXTPControl)
  39. //////////////////////////////////////////////////////////////////////
  40. // Construction/Destruction
  41. //////////////////////////////////////////////////////////////////////
  42. CXTPRibbonControlTab::CXTPRibbonControlTab()
  43. {
  44. m_bAllowReorder = FALSE;
  45. m_bFocused = FALSE;
  46. m_bTemporary = TRUE;
  47. SetFlags(xtpFlagNoMovable);
  48. }
  49. CXTPRibbonControlTab::~CXTPRibbonControlTab()
  50. {
  51. }
  52. CXTPRibbonTab* CXTPRibbonControlTab::FindTab(int nID) const
  53. {
  54. for (int i = 0; i < GetItemCount(); i++)
  55. {
  56. CXTPRibbonTab* pTab = (CXTPRibbonTab*)GetItem(i);
  57. if (pTab->GetID() == nID)
  58. return pTab;
  59. }
  60. return NULL;
  61. }
  62. CXTPRibbonTab* CXTPRibbonControlTab::GetTab(int nIndex) const
  63. {
  64. return (CXTPRibbonTab*)GetItem(nIndex);
  65. }
  66. void CXTPRibbonControlTab::Reposition()
  67. {
  68. if (!m_pParent->GetSafeHwnd())
  69. return;
  70. m_pParent->OnRecalcLayout();
  71. }
  72. BOOL CXTPRibbonControlTab::IsMouseLocked() const
  73. {
  74. return GetRibbonBar()->GetCommandBars()->GetMouseManager()->IsMouseLocked();
  75. }
  76. CXTPTabPaintManager* CXTPRibbonControlTab::GetPaintManager() const
  77. {
  78. return GetRibbonBar()->GetTabPaintManager();
  79. }
  80. void CXTPRibbonControlTab::ShowPopupBar(BOOL bKeyboard)
  81. {
  82. if (!GetSelectedItem())
  83. return;
  84. CXTPRibbonBar* pRibbonBar = GetRibbonBar();
  85. if (!pRibbonBar->IsRibbonMinimized())
  86. return;
  87. if (pRibbonBar->m_nPopuped == m_nIndex)
  88. {
  89. pRibbonBar->m_nPopuped = -1;
  90. if (m_pCommandBar) m_pCommandBar->SetTrackingMode(FALSE);
  91. }
  92. pRibbonBar->SetTrackingMode(TRUE, FALSE);
  93. pRibbonBar->SetPopuped(m_nIndex, bKeyboard);
  94. }
  95. void CXTPRibbonControlTab::SetEnabled(BOOL /*bEnabled*/)
  96. {
  97. }
  98. CString CXTPRibbonControlTab::GetItemTooltip(const CXTPTabManagerItem* pItem) const
  99. {
  100. CString strToolTip = CXTPTabManager::GetItemTooltip(pItem);
  101. if (!strToolTip.IsEmpty())
  102. return strToolTip;
  103. return pItem->GetCaption();
  104. }
  105. void CXTPRibbonControlTab::SetSelectedItem(CXTPTabManagerItem* pItem)
  106. {
  107. if (!m_pParent->GetSafeHwnd())
  108. {
  109. CXTPTabManager::SetSelectedItem(pItem);
  110. return;
  111. }
  112. if (!IsFocused() && pItem && !GetRibbonBar()->IsRibbonMinimized())
  113. m_pParent->GetCommandBars()->ClosePopups();
  114. if (m_pSelected == pItem)
  115. return;
  116. if (m_pParent->GetCommandBars()->m_keyboardTips.nLevel > 1)
  117. m_pParent->GetCommandBars()->HideKeyboardTips();
  118. CXTPRibbonTab* pTab = (CXTPRibbonTab*)pItem;
  119. CXTPRibbonBar* pRibbonBar = GetRibbonBar();
  120. if (pRibbonBar->OnTabChanging(pTab))
  121. return;
  122. pRibbonBar->LockRedraw();
  123. pRibbonBar->RebuildControls(pTab);
  124. CXTPTabManager::SetSelectedItem(pTab);
  125. pRibbonBar->OnIdleUpdateCmdUI(0, 0);
  126. pRibbonBar->UnlockRedraw();
  127. pRibbonBar->OnTabChanged(pTab);
  128. NotifySite(CBN_XTP_EXECUTE);
  129. if (pItem)
  130. {
  131. AccessibleNotifyWinEvent(EVENT_OBJECT_FOCUS , GetParent()->GetSafeHwnd(), GetID(), pItem->GetIndex() + 1);
  132. }
  133. }
  134. void CXTPRibbonControlTab::AdjustExcludeRect(CRect& rc, BOOL /*bVertical*/)
  135. {
  136. rc.bottom--;
  137. }
  138. BOOL CXTPRibbonControlTab::DrawIcon(CDC* pDC, CPoint pt, CXTPTabManagerItem* pItem, BOOL bDraw, CSize& szIcon) const
  139. {
  140. if (!pItem)
  141. return GetPaintManager()->m_bShowIcons;
  142. if (pItem->GetImageIndex() == -1 || GetPaintManager()->m_bShowIcons == FALSE)
  143. return FALSE;
  144. CXTPImageManagerIcon* pImage = GetImageManager()->GetImage(pItem->GetImageIndex(), szIcon.cx);
  145. if (!pImage)
  146. return FALSE;
  147. if (!bDraw)
  148. {
  149. return TRUE;
  150. }
  151. pItem->DrawImage(pDC, CRect(pt, szIcon), pImage);
  152. return TRUE;
  153. }
  154. void CXTPRibbonControlTab::RedrawControl(LPCRECT lpRect, BOOL bAnimate)
  155. {
  156. m_pParent->Redraw(lpRect, bAnimate);
  157. }
  158. void CXTPRibbonControlTab::OnUnderlineActivate()
  159. {
  160. SetFocused(TRUE);
  161. }
  162. BOOL CXTPRibbonControlTab::HeaderHasFocus() const
  163. {
  164. return IsFocused() && m_pParent->IsTrackingMode();
  165. }
  166. BOOL  CXTPRibbonControlTab::OnSetSelected(int bSelected)
  167. {
  168. if (bSelected == m_bSelected)
  169. return FALSE;
  170. if (IsKeyboardSelected(bSelected) && !GetRibbonBar()->IsRibbonMinimized())
  171. m_pParent->SetPopuped(-1);
  172. m_bSelected = bSelected;
  173. m_pParent->OnControlSelected(bSelected, this);
  174. if (IsKeyboardSelected(bSelected))
  175. {
  176. SetFocused(TRUE);
  177. }
  178. if (!bSelected)
  179. {
  180. SetFocused(FALSE);
  181. PerformMouseMove(m_pParent->GetSafeHwnd(), CPoint(-1, -1));
  182. }
  183. else
  184. {
  185. AccessibleNotifyWinEvent(EVENT_OBJECT_FOCUS , GetParent()->GetSafeHwnd(), GetID(), GetCurSel() + 1);
  186. }
  187. return TRUE;
  188. }
  189. BOOL CXTPRibbonControlTab::IsFocusable() const
  190. {
  191. return TRUE;
  192. }
  193. BOOL CXTPRibbonControlTab::IsFocused() const
  194. {
  195. return m_bFocused;
  196. }
  197. void CXTPRibbonControlTab::Draw(CDC* /*pDC*/)
  198. {
  199. }
  200. BOOL CXTPRibbonControlTab::IsPopupBarTracking() const
  201. {
  202. return m_pCommandBar && m_pCommandBar->IsTrackingMode();
  203. }
  204. void CXTPRibbonControlTab::SetFocused(BOOL bFocused)
  205. {
  206. if (m_bFocused == bFocused)
  207. return;
  208. m_bFocused = bFocused;
  209. if (m_bFocused && GetSelectedItem() == NULL)
  210. {
  211. SetSelectedItem(FindNextFocusable(-1, +1));
  212. }
  213. RedrawParent();
  214. }
  215. BOOL CXTPRibbonControlTab::OnHookKeyDown(UINT nChar, LPARAM /*lParam*/)
  216. {
  217. if (!IsFocused())
  218. return FALSE;
  219. UINT nCharLayout(nChar);
  220. CXTPDrawHelpers::KeyToLayout(m_pParent, nCharLayout);
  221. if (nCharLayout == VK_UP || nCharLayout == VK_DOWN || nCharLayout == VK_LEFT || nCharLayout == VK_RIGHT)
  222. {
  223. m_pParent->HideKeyboardTips();
  224. }
  225. if (nCharLayout == VK_LEFT && FindNextFocusable(GetCurSel(), -1))
  226. {
  227. if (PerformKeyDown(m_pParent->GetSafeHwnd(), nChar))
  228. return TRUE;
  229. }
  230. if (nCharLayout == VK_RIGHT && FindNextFocusable(GetCurSel(), +1))
  231. {
  232. if (PerformKeyDown(m_pParent->GetSafeHwnd(), nChar))
  233. return TRUE;
  234. }
  235. if (nCharLayout == VK_DOWN)
  236. {
  237. m_pParent->SetSelected(m_pControls->GetNext(CXTPControl::GetIndex(), +1), TRUE_KEYBOARD_NEXT);
  238. return TRUE;
  239. }
  240. if (nCharLayout == VK_RETURN || nCharLayout == VK_SPACE && GetRibbonBar()->IsRibbonMinimized())
  241. {
  242. ShowPopupBar(TRUE);
  243. return TRUE;
  244. }
  245. return FALSE;
  246. }
  247. void CXTPRibbonControlTab::OnClick(BOOL /*bKeyboard*/, CPoint /*pt*/)
  248. {
  249. // Do Nothing
  250. }
  251. BOOL CXTPRibbonControlTab::OnSetPopup(BOOL bPopup)
  252. {
  253. m_bPopup = bPopup;
  254. if (bPopup)
  255. {
  256. ASSERT(GetSelectedItem());
  257. CXTPRibbonTab* pSelectedTab = (CXTPRibbonTab*)GetSelectedItem();
  258. if (!pSelectedTab || !GetRibbonBar()->IsRibbonMinimized())
  259. {
  260. m_bPopup = FALSE;
  261. return FALSE;
  262. }
  263. if (m_pCommandBar)
  264. m_pCommandBar->InternalRelease();
  265. CXTPCommandBars* pCommandBars = GetRibbonBar()->GetCommandBars();
  266. ASSERT(pCommandBars);
  267. m_pCommandBar = new CXTPRibbonTabPopupToolBar(pSelectedTab);
  268. m_pCommandBar->SetCommandBars(pCommandBars);
  269. m_pCommandBar->EnableCustomization(FALSE);
  270. m_pCommandBar->Popup(this, IsKeyboardSelected(GetSelected()));
  271. }
  272. else if (m_pCommandBar)
  273. {
  274. ASSERT(m_pCommandBar);
  275. m_pCommandBar->SetTrackingMode(FALSE);
  276. }
  277. RedrawParent();
  278. return TRUE;
  279. }
  280. void CXTPRibbonControlTab::Copy(CXTPControl* pControl, BOOL /*bRecursive = FALSE*/)
  281. {
  282. DeleteAllItems();
  283. CXTPRibbonControlTab* pControlTab = (CXTPRibbonControlTab*)pControl;
  284. for (int i = 0; i < pControlTab->GetItemCount(); i++)
  285. {
  286. CXTPRibbonTab* pTab = pControlTab->GetTab(i);
  287. CXTPRibbonTab* pTabClone = (CXTPRibbonTab*)pTab->GetRuntimeClass()->CreateObject();
  288. pTabClone->m_pRibbonBar = (CXTPRibbonBar*)GetParent();
  289. pTabClone->m_pParent = (CXTPRibbonBar*)GetParent();
  290. AddItem(i, pTabClone);
  291. pTabClone->Copy(pTab);
  292. }
  293. }
  294. void CXTPRibbonControlTab::DoPropExchange(CXTPPropExchange* pPX)
  295. {
  296. if (pPX->IsStoring())
  297. {
  298. long nCount = (long)m_arrItems.GetSize();
  299. int i;
  300. CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Tab")));
  301. POSITION posEnum = pEnumerator->GetPosition(nCount, FALSE);
  302. for (i = 0; i < nCount; i++)
  303. {
  304. CXTPRibbonTab* pTab = (CXTPRibbonTab*)GetItem(i);
  305. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  306. PX_Object(&secItem, pTab, RUNTIME_CLASS(CXTPRibbonTab));
  307. }
  308. }
  309. else
  310. {
  311. CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Tab")));
  312. POSITION posEnum = pEnumerator->GetPosition(0, FALSE);
  313. DeleteAllItems();
  314. while (posEnum)
  315. {
  316. CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum));
  317. secItem->m_pOwner = this;
  318. CXTPRibbonTab* pTab = NULL;
  319. PX_Object(&secItem, pTab, RUNTIME_CLASS(CXTPRibbonTab));
  320. if (!pTab)
  321. AfxThrowArchiveException(CArchiveException::badClass);
  322. AddItem(GetItemCount(), pTab);
  323. }
  324. }
  325. }
  326. //////////////////////////////////////////////////////////////////////////
  327. // Accessible
  328. HRESULT CXTPRibbonControlTab::GetAccessibleChildCount(long FAR* pChildCount)
  329. {
  330. if (pChildCount == 0)
  331. return E_INVALIDARG;
  332. *pChildCount = GetItemCount();
  333. return S_OK;
  334. }
  335. HRESULT CXTPRibbonControlTab::GetAccessibleChild(VARIANT /*varChild*/, IDispatch* FAR* ppdispChild)
  336. {
  337. SAFE_MANAGE_STATE(m_pModuleState);
  338. *ppdispChild = NULL;
  339. return S_FALSE;
  340. }
  341. HRESULT CXTPRibbonControlTab::GetAccessibleName(VARIANT varChild, BSTR* pszName)
  342. {
  343. SAFE_MANAGE_STATE(m_pModuleState);
  344. int nIndex = GetChildIndex(&varChild);
  345. if (nIndex == CHILDID_SELF)
  346. return CXTPControl::GetAccessibleName(varChild, pszName);
  347. CXTPTabManagerItem* pItem = GetItem(nIndex - 1);
  348. if (!pItem)
  349. return E_INVALIDARG;
  350. CString strCaption = pItem->GetCaption();
  351. CXTPDrawHelpers::StripMnemonics(strCaption);
  352. *pszName = strCaption.AllocSysString();
  353. return S_OK;
  354. }
  355. HRESULT CXTPRibbonControlTab::GetAccessibleRole(VARIANT varChild, VARIANT* pvarRole)
  356. {
  357. pvarRole->vt = VT_I4;
  358. pvarRole->lVal = GetChildIndex(&varChild) == CHILDID_SELF ? ROLE_SYSTEM_PAGETABLIST : ROLE_SYSTEM_PAGETAB;
  359. return S_OK;
  360. }
  361. HRESULT CXTPRibbonControlTab::AccessibleSelect(long flagsSelect, VARIANT varChild)
  362. {
  363. SAFE_MANAGE_STATE(m_pModuleState);
  364. int nIndex = GetChildIndex(&varChild);
  365. if (nIndex == CHILDID_SELF)
  366. return CXTPControl::AccessibleSelect(flagsSelect, varChild);
  367. SetCurSel(nIndex - 1);
  368. return S_OK;
  369. }
  370. HRESULT CXTPRibbonControlTab::GetAccessibleState(VARIANT varChild, VARIANT* pvarState)
  371. {
  372. int nIndex = GetChildIndex(&varChild);
  373. if (nIndex == CHILDID_SELF)
  374. {
  375. pvarState->vt = VT_I4;
  376. pvarState->lVal = STATE_SYSTEM_FOCUSABLE;
  377. if (!m_pParent->IsVisible() || !IsVisible())
  378. pvarState->lVal |= STATE_SYSTEM_INVISIBLE;
  379. return S_OK;
  380. }
  381. CXTPTabManagerItem* pItem = GetItem(nIndex - 1);
  382. if (!pItem)
  383. return E_INVALIDARG;
  384. pvarState->vt = VT_I4;
  385. pvarState->lVal = STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_SELECTABLE;
  386. if (pItem->IsSelected())
  387. pvarState->lVal |= STATE_SYSTEM_SELECTED | STATE_SYSTEM_FOCUSED;
  388. if (!pItem->IsVisible())
  389. pvarState->lVal |= STATE_SYSTEM_INVISIBLE;
  390. return S_OK;
  391. }
  392. HRESULT CXTPRibbonControlTab::GetAccessibleDefaultAction(VARIANT varChild, BSTR* pszDefaultAction)
  393. {
  394. if (GetChildIndex(&varChild) == CHILDID_SELF)
  395. return CXTPControl::GetAccessibleDefaultAction(varChild, pszDefaultAction);
  396. *pszDefaultAction = SysAllocString(L"Switch");
  397. return S_OK;
  398. }
  399. HRESULT CXTPRibbonControlTab::AccessibleDoDefaultAction(VARIANT varChild)
  400. {
  401. SAFE_MANAGE_STATE(m_pModuleState);
  402. int nIndex = GetChildIndex(&varChild);
  403. if (nIndex == CHILDID_SELF)
  404. return CXTPControl::AccessibleDoDefaultAction(varChild);
  405. CXTPTabManagerItem* pItem = GetItem(nIndex - 1);
  406. if (!pItem)
  407. return E_INVALIDARG;
  408. pItem->Select();
  409. return S_OK;
  410. }
  411. HRESULT CXTPRibbonControlTab::AccessibleLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild)
  412. {
  413. *pxLeft = *pyTop = *pcxWidth = *pcyHeight = 0;
  414. int nIndex = GetChildIndex(&varChild);
  415. if (!m_pParent->GetSafeHwnd())
  416. return S_OK;
  417. if (!IsVisible())
  418. return S_OK;
  419. CRect rcControl = GetRect();
  420. if (nIndex != CHILDID_SELF)
  421. {
  422. rcControl = GetItem(nIndex - 1)->GetRect();
  423. }
  424. m_pParent->ClientToScreen(&rcControl);
  425. *pxLeft = rcControl.left;
  426. *pyTop = rcControl.top;
  427. *pcxWidth = rcControl.Width();
  428. *pcyHeight = rcControl.Height();
  429. return S_OK;
  430. }
  431. HRESULT CXTPRibbonControlTab::AccessibleHitTest(long xLeft, long yTop, VARIANT* pvarID)
  432. {
  433. if (pvarID == NULL)
  434. return E_INVALIDARG;
  435. pvarID->vt = VT_EMPTY;
  436. if (!m_pParent->GetSafeHwnd())
  437. return S_FALSE;
  438. if (!CXTPWindowRect(m_pParent).PtInRect(CPoint(xLeft, yTop)))
  439. return S_FALSE;
  440. pvarID->vt = VT_I4;
  441. pvarID->lVal = CHILDID_SELF;
  442. CPoint pt(xLeft, yTop);
  443. m_pParent->ScreenToClient(&pt);
  444. if (!GetRect().PtInRect(pt))
  445. return S_FALSE;
  446. CXTPTabManagerItem* pItem = HitTest(pt);
  447. if (pItem)
  448. {
  449. pvarID->lVal = pItem->GetIndex() + 1;
  450. }
  451. return S_OK;
  452. }