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

对话框与窗口

开发平台:

Visual C++

  1. // XTPTabManager.cpp: implementation of the CXTPTabManager class.
  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 "Resource.h"
  22. #include "Common/XTPVC80Helpers.h"
  23. #include "Common/XTPDrawHelpers.h"
  24. #include "Common/XTPToolTipContext.h"
  25. #include "Common/XTPResourceManager.h"
  26. #include "Common/XTPImageManager.h"
  27. #include "Common/XTPMarkupRender.h"
  28. #include "XTPTabManager.h"
  29. #include "XTPTabPaintManager.h"
  30. #ifdef _DEBUG
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #define new DEBUG_NEW
  34. #endif
  35. IMPLEMENT_DYNAMIC(CXTPTabManagerItem, CCmdTarget)
  36. //////////////////////////////////////////////////////////////////////
  37. // CXTPTabManagerItem
  38. CXTPTabManagerItem::CXTPTabManagerItem()
  39. {
  40. EnableAutomation();
  41. m_bVisible = TRUE;
  42. m_bEnabled = TRUE;
  43. m_hIcon = 0;
  44. m_hWnd = 0;
  45. m_clrItem = 0;
  46. m_nIndex = -1;
  47. m_nImage = -1;
  48. m_dwData = 0;
  49. m_rcItem.SetRectEmpty();
  50. m_nItemRow = 0;
  51. m_nButtonLength = m_nContentLength = 0;
  52. m_bClosable = TRUE;
  53. m_pTabManager = NULL;
  54. m_bFound = FALSE;
  55. m_pMarkupUIElement = 0;
  56. }
  57. void CXTPTabManagerItem::OnRemoved()
  58. {
  59. for (int j = 0; j < m_arrNavigateButtons.GetSize(); j++)
  60. delete m_arrNavigateButtons[j];
  61. m_arrNavigateButtons.RemoveAll();
  62. }
  63. CXTPTabManagerItem::~CXTPTabManagerItem()
  64. {
  65. for (int j = 0; j < m_arrNavigateButtons.GetSize(); j++)
  66. delete m_arrNavigateButtons[j];
  67. XTPMarkupReleaseElement(m_pMarkupUIElement);
  68. }
  69. void CXTPTabManagerItem::Reposition()
  70. {
  71. if (m_pTabManager) m_pTabManager->Reposition();
  72. }
  73. void CXTPTabManagerItem::SetCaption(LPCTSTR lpszCaption)
  74. {
  75. if (m_strCaption != lpszCaption)
  76. {
  77. m_strCaption = lpszCaption;
  78. XTPMarkupReleaseElement(m_pMarkupUIElement);
  79. if (m_pTabManager && m_pTabManager->GetMarkupContext())
  80. {
  81. m_pMarkupUIElement = XTPMarkupParseText(m_pTabManager->GetMarkupContext(), lpszCaption);
  82. }
  83. Reposition();
  84. }
  85. }
  86. void CXTPTabManagerItem::SetColor(COLORREF clr)
  87. {
  88. m_clrItem = clr;
  89. m_pTabManager->RedrawControl(GetRect(), FALSE);
  90. }
  91. CString CXTPTabManagerItem::GetCaption() const
  92. {
  93. return m_pTabManager->GetItemCaption(this);
  94. }
  95. CString CXTPTabManagerItem::GetTooltip() const
  96. {
  97. return m_pTabManager->GetItemTooltip(this);
  98. }
  99. COLORREF CXTPTabManagerItem::GetColor()
  100. {
  101. return m_pTabManager->GetItemColor(this);
  102. }
  103. void CXTPTabManagerItem::SetHandle(HWND hWnd)
  104. {
  105. m_hWnd = hWnd;
  106. }
  107. void CXTPTabManagerItem::Remove()
  108. {
  109. m_pTabManager->DeleteItem(m_nIndex);
  110. }
  111. void CXTPTabManagerItem::Select()
  112. {
  113. m_pTabManager->OnItemClick(this);
  114. }
  115. HWND CXTPTabManagerItem::GetHandle() const
  116. {
  117. return m_hWnd;
  118. }
  119. BOOL CXTPTabManagerItem::IsVisible() const
  120. {
  121. return m_bVisible;
  122. }
  123. void CXTPTabManagerItem::SetVisible(BOOL bVisible)
  124. {
  125. if (m_bVisible != bVisible)
  126. {
  127. m_bVisible = bVisible;
  128. Reposition();
  129. }
  130. }
  131. BOOL CXTPTabManagerItem::IsEnabled() const
  132. {
  133. return m_bEnabled;
  134. }
  135. void CXTPTabManagerItem::SetEnabled(BOOL bEnabled)
  136. {
  137. if (m_bEnabled != bEnabled)
  138. {
  139. m_bEnabled = bEnabled;
  140. Reposition();
  141. }
  142. }
  143. void CXTPTabManagerItem::Move(int nIndex)
  144. {
  145. if (GetIndex() != nIndex)
  146. {
  147. m_pTabManager->MoveItem(this, nIndex);
  148. }
  149. }
  150. BOOL CXTPTabManagerItem::DrawRotatedImage(CDC* pDC, CRect rcItem, CXTPImageManagerIcon* pImage)
  151. {
  152. CXTPImageManagerIconHandle& imageHandle = !IsEnabled() ? pImage->GetDisabledIcon(): IsHighlighted() ? pImage->GetHotIcon() :
  153. IsSelected() ? pImage->GetCheckedIcon() : pImage->GetIcon();
  154. const int cx = rcItem.Width();
  155. const int cy = rcItem.Height();
  156. ASSERT(cx == cy);
  157. if (cx != cy)
  158. return FALSE;
  159. UINT* pSrcBits = NULL, *pDestBits = NULL;
  160. HBITMAP hbmSrc = CXTPImageManager::Create32BPPDIBSection(NULL, cx, cy, (LPBYTE*)&pSrcBits);
  161. if (!pSrcBits)
  162. return FALSE;
  163. HBITMAP hbmDest = CXTPImageManager::Create32BPPDIBSection(NULL, cx, cy, (LPBYTE*)&pDestBits);
  164. if (!pDestBits)
  165. return FALSE;
  166. CDC dc;
  167. dc.CreateCompatibleDC(NULL);
  168. HGDIOBJ hbmpOld = ::SelectObject(dc, hbmSrc);
  169. CRect rcDraw(0, 0, cx, cy);
  170. dc.BitBlt(0, 0, cx, cy, pDC, rcItem.left, rcItem.top, SRCCOPY);
  171. ::SelectObject(dc, hbmpOld);
  172. UINT* pSrcInv = pDestBits;
  173. UINT* pDestInv = pSrcBits;
  174. UINT* pDest = &pDestBits[cx];
  175. int i;
  176. for (i = 0; i < cy; i++)
  177. {
  178. pDest -= 1;
  179. pDestBits = pDest;
  180. for (int j = 0; j < cx; j++)
  181. {
  182. *pDestBits = *pSrcBits;
  183. pSrcBits += 1;
  184. pDestBits += cy;
  185. }
  186. }
  187. hbmpOld = ::SelectObject(dc, hbmDest);
  188. pImage->Draw(&dc, rcDraw.TopLeft(), imageHandle, rcDraw.Size());
  189. ::SelectObject(dc, hbmpOld);
  190. pDest = &pDestInv[cx * (cy - 1)];
  191. for (i = 0; i < cy; i++)
  192. {
  193. pDestInv = pDest;
  194. for (int j = 0; j < cx; j++)
  195. {
  196. *pDestInv = *pSrcInv;
  197. pSrcInv += 1;
  198. pDestInv -= cy;
  199. }
  200. pDest += 1;
  201. }
  202. pDC->DrawState(rcItem.TopLeft(), rcItem.Size(), hbmSrc, DST_BITMAP);
  203. DeleteObject(hbmSrc);
  204. DeleteObject(hbmDest);
  205. return TRUE;
  206. }
  207. void CXTPTabManagerItem::DrawImage(CDC* pDC, CRect rcIcon, CXTPImageManagerIcon* pImage)
  208. {
  209. if (rcIcon.Width() == rcIcon.Height() && GetTabManager()->GetPaintManager()->m_bRotateImageOnVerticalDraw
  210. && (GetTabManager()->GetPosition() == xtpTabPositionLeft || GetTabManager()->GetPosition() == xtpTabPositionRight)
  211. && DrawRotatedImage(pDC, rcIcon, pImage))
  212. {
  213. }
  214. else
  215. {
  216. CXTPImageManagerIconHandle& imageHandle = !IsEnabled() ? pImage->GetDisabledIcon(): IsHighlighted() ? pImage->GetHotIcon() :
  217. IsSelected() ? pImage->GetCheckedIcon() : pImage->GetIcon();
  218. pImage->Draw(pDC, rcIcon.TopLeft(), imageHandle, rcIcon.Size());
  219. }
  220. }
  221. void CXTPTabManagerItem::SetRect(CRect rcItem)
  222. {
  223. m_rcItem = rcItem;
  224. for (int i = (int)m_arrNavigateButtons.GetSize() - 1; i >= 0; i--)
  225. {
  226. CXTPTabManagerNavigateButton* pButton = m_arrNavigateButtons.GetAt(i);
  227. pButton->SetRect(CRect(0, 0, 0, 0));
  228. }
  229. }
  230. //////////////////////////////////////////////////////////////////////////
  231. // CXTPTabManagerNavigateButton
  232. CXTPTabManagerNavigateButton::CXTPTabManagerNavigateButton(CXTPTabManager* pManager, UINT nID, XTPTabNavigateButtonFlags dwFlags)
  233. {
  234. m_pManager = pManager;
  235. m_nID = nID;
  236. m_dwFlags = dwFlags;
  237. m_rcButton.SetRectEmpty();
  238. m_bEnabled = TRUE;
  239. m_bPressed = FALSE;
  240. m_pItem = NULL;
  241. }
  242. CXTPTabManagerNavigateButton::~CXTPTabManagerNavigateButton()
  243. {
  244. if (m_pManager->m_pHighlightedNavigateButton == this)
  245. m_pManager->m_pHighlightedNavigateButton = NULL;
  246. }
  247. CSize CXTPTabManagerNavigateButton::GetSize() const
  248. {
  249. return m_pManager->GetPaintManager()->m_szNavigateButton;
  250. }
  251. void CXTPTabManagerNavigateButton::AdjustWidth(int& nWidth)
  252. {
  253. if ((m_dwFlags == xtpTabNavigateButtonAlways) ||
  254. (m_dwFlags == xtpTabNavigateButtonAutomatic && m_pManager->IsNavigateButtonAutomaticVisible(this)))
  255. {
  256. if ((m_pManager->GetPosition() == xtpTabPositionTop) || (m_pManager->GetPosition() == xtpTabPositionBottom))
  257. {
  258. nWidth -= GetSize().cx;
  259. }
  260. else
  261. {
  262. nWidth -= GetSize().cy;
  263. }
  264. }
  265. }
  266. void CXTPTabManagerNavigateButton::SetRect(CRect rcButton)
  267. {
  268. m_rcButton = rcButton;
  269. }
  270. void CXTPTabManagerNavigateButton::Reposition(CRect& rcNavigateButtons)
  271. {
  272. if ((m_dwFlags == xtpTabNavigateButtonAlways) ||
  273. (m_dwFlags == xtpTabNavigateButtonAutomatic && m_pManager->IsNavigateButtonAutomaticVisible(this)))
  274. {
  275. CSize szButton = GetSize();
  276. if (m_pManager->IsHorizontalPosition())
  277. {
  278. m_rcButton.SetRect(rcNavigateButtons.right - szButton.cx, rcNavigateButtons.CenterPoint().y + szButton.cy / 2 - szButton.cy, rcNavigateButtons.right, rcNavigateButtons.CenterPoint().y + szButton.cy / 2);
  279. rcNavigateButtons.right -= szButton.cx;
  280. }
  281. else
  282. {
  283. m_rcButton.SetRect(rcNavigateButtons.CenterPoint().x - szButton.cx / 2, rcNavigateButtons.bottom - szButton.cy, rcNavigateButtons.CenterPoint().x - szButton.cx / 2 + szButton.cx, rcNavigateButtons.bottom);
  284. rcNavigateButtons.bottom -= szButton.cy;
  285. }
  286. }
  287. else
  288. m_rcButton.SetRectEmpty();
  289. }
  290. void CXTPTabManagerNavigateButton::Draw(CDC* pDC)
  291. {
  292. if (!m_rcButton.IsRectEmpty())
  293. {
  294. CRect rc(m_rcButton);
  295. m_pManager->GetPaintManager()->DrawNavigateButton(pDC, this, rc);
  296. }
  297. }
  298. void CXTPTabManagerNavigateButton::PerformClick(HWND hWnd, CPoint pt)
  299. {
  300. if ((::GetCapture() != NULL) || !m_bEnabled)
  301. return;
  302. ::SetCapture(hWnd);
  303. BOOL  bClick = FALSE;
  304. DWORD dwStart = GetTickCount();
  305. for (;;)
  306. {
  307. if (m_bEnabled && GetTickCount() - dwStart > 20)
  308. {
  309. dwStart = GetTickCount();
  310. OnExecute(TRUE);
  311. }
  312. BOOL bPressed = m_rcButton.PtInRect(pt);
  313. if (bPressed != m_bPressed)
  314. {
  315. m_bPressed = bPressed;
  316. m_pManager->RedrawControl(m_rcButton, TRUE);
  317. }
  318. MSG msg;
  319. if (!::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE))
  320. continue;
  321. VERIFY(::GetMessage(&msg, NULL, 0, 0));
  322. if (::GetCapture() != hWnd)
  323. {
  324. DispatchMessage (&msg);
  325. goto ExitLoop;
  326. }
  327. switch (msg.message)
  328. {
  329. case WM_MOUSEMOVE:
  330. pt = CPoint((short signed)LOWORD(msg.lParam), (short signed)HIWORD(msg.lParam));
  331. break;
  332. case WM_LBUTTONUP:
  333. bClick = m_bPressed;
  334. goto ExitLoop;
  335. case WM_KEYDOWN:
  336. if (msg.wParam != VK_ESCAPE)
  337. break;
  338. case WM_CANCELMODE:
  339. case WM_RBUTTONDOWN:
  340. goto ExitLoop;
  341. default:
  342. DispatchMessage (&msg);
  343. break;
  344. }
  345. }
  346. ExitLoop:
  347. ReleaseCapture();
  348. m_bPressed = FALSE;
  349. m_pManager->PerformMouseMove(hWnd, pt);
  350. m_pManager->RedrawControl(NULL, FALSE);
  351. if (bClick)
  352. {
  353. OnExecute(FALSE);
  354. }
  355. }
  356. void CXTPTabManagerNavigateButton::OnExecute(BOOL bTick)
  357. {
  358. if (!bTick)
  359. {
  360. m_pManager->OnNavigateButtonClick(this);
  361. }
  362. }
  363. //////////////////////////////////////////////////////////////////////////
  364. // CXTPTabManager::CRowIndexer
  365. CXTPTabManager::CRowIndexer::CRowIndexer(CXTPTabManager* pManager)
  366. {
  367. m_nRowCount = 0;
  368. m_pRowItems = 0;
  369. m_pManager = pManager;
  370. CreateIndexer(1);
  371. }
  372. CXTPTabManager::CRowIndexer::~CRowIndexer()
  373. {
  374. SAFE_DELETE_AR(m_pRowItems);
  375. }
  376. CXTPTabManager::ROW_ITEMS* CXTPTabManager::CRowIndexer::CreateIndexer(int nRowCount)
  377. {
  378. if (m_nRowCount != nRowCount)
  379. {
  380. SAFE_DELETE_AR(m_pRowItems);
  381. m_pRowItems = new ROW_ITEMS[nRowCount];
  382. m_nRowCount = nRowCount;
  383. }
  384. if (nRowCount > 0)
  385. {
  386. m_pRowItems[0].nFirstItem = 0;
  387. m_pRowItems[0].nLastItem = m_pManager->GetItemCount() - 1;
  388. }
  389. return m_pRowItems;
  390. }
  391. //////////////////////////////////////////////////////////////////////////
  392. // CXTPTabManager::CNavigateButtonArrow
  393. class CXTPTabManager::CNavigateButtonArrow : public CXTPTabManagerNavigateButton
  394. {
  395. protected:
  396. CNavigateButtonArrow(CXTPTabManager* pManager, XTPTabNavigateButton nID, XTPTabNavigateButtonFlags dwFlags)
  397. : CXTPTabManagerNavigateButton(pManager, nID, dwFlags)
  398. {
  399. }
  400. virtual void Reposition(CRect& rcNavigateButtons);
  401. virtual void AdjustWidth(int& nWidth);
  402. };
  403. class CXTPTabManager::CNavigateButtonArrowLeft : public CNavigateButtonArrow
  404. {
  405. public:
  406. CNavigateButtonArrowLeft(CXTPTabManager* pManager, XTPTabNavigateButtonFlags dwFlags)
  407. : CNavigateButtonArrow(pManager, xtpTabNavigateButtonLeft, dwFlags)
  408. {
  409. }
  410. protected:
  411. virtual void DrawEntry(CDC* pDC, CRect rc);
  412. virtual void Reposition(CRect& rcNavigateButtons);
  413. virtual void OnExecute(BOOL bTick);
  414. };
  415. class CXTPTabManager::CNavigateButtonArrowRight : public CNavigateButtonArrow
  416. {
  417. public:
  418. CNavigateButtonArrowRight(CXTPTabManager* pManager, XTPTabNavigateButtonFlags dwFlags)
  419. : CNavigateButtonArrow(pManager, xtpTabNavigateButtonRight, dwFlags)
  420. {
  421. }
  422. protected:
  423. virtual void DrawEntry(CDC* pDC, CRect rc);
  424. virtual void Reposition(CRect& rcNavigateButtons);
  425. virtual void OnExecute(BOOL bTick);
  426. };
  427. class CXTPTabManager::CNavigateButtonClose : public CXTPTabManagerNavigateButton
  428. {
  429. public:
  430. CNavigateButtonClose(CXTPTabManager* pManager, XTPTabNavigateButtonFlags dwFlags)
  431. : CXTPTabManagerNavigateButton(pManager, xtpTabNavigateButtonClose, dwFlags)
  432. {
  433. XTPResourceManager()->LoadString(&m_strToolTip, XTP_IDS_TABNAVIGATEBUTTON_CLOSE);
  434. }
  435. protected:
  436. virtual void DrawEntry(CDC* pDC, CRect rc);
  437. };
  438. class CXTPTabManager::CNavigateButtonTabClose : public CXTPTabManager::CNavigateButtonClose
  439. {
  440. public:
  441. CNavigateButtonTabClose(CXTPTabManagerItem* pItem, XTPTabNavigateButtonFlags dwFlags)
  442. : CXTPTabManager::CNavigateButtonClose(pItem->GetTabManager(), dwFlags)
  443. {
  444. m_pItem = pItem;
  445. }
  446. };
  447. void CXTPTabManager::CNavigateButtonClose::DrawEntry(CDC* pDC, CRect rc)
  448. {
  449. CPoint pt = rc.CenterPoint();
  450. pDC->MoveTo(pt.x - 4, pt.y - 3);
  451. pDC->LineTo(pt.x + 3, pt.y + 4);
  452. pDC->MoveTo(pt.x - 3, pt.y - 3);
  453. pDC->LineTo(pt.x + 4, pt.y + 4);
  454. pDC->MoveTo(pt.x - 4, pt.y + 3);
  455. pDC->LineTo(pt.x + 3, pt.y - 4);
  456. pDC->MoveTo(pt.x - 3, pt.y + 3);
  457. pDC->LineTo(pt.x + 4, pt.y - 4);
  458. }
  459. void CXTPTabManager::CNavigateButtonArrowRight::DrawEntry(CDC* pDC, CRect rc)
  460. {
  461. CPoint pt = rc.CenterPoint();
  462. if (m_pManager->IsHorizontalPosition())
  463. CXTPDrawHelpers::Triangle(pDC, CPoint(pt.x - 2, pt.y - 5), CPoint(pt.x + 2, pt.y - 1), CPoint(pt.x - 2, pt.y + 3));
  464. else
  465. CXTPDrawHelpers::Triangle(pDC, CPoint(pt.x - 5, pt.y - 2), CPoint(pt.x - 1, pt.y + 2), CPoint(pt.x + 3, pt.y - 2));
  466. }
  467. void CXTPTabManager::CNavigateButtonArrow::AdjustWidth(int& nWidth)
  468. {
  469. if (m_dwFlags == xtpTabNavigateButtonAlways)
  470. {
  471. if ((m_pManager->GetPosition() == xtpTabPositionTop) || (m_pManager->GetPosition() == xtpTabPositionBottom))
  472. {
  473. nWidth -= GetSize().cx;
  474. }
  475. else
  476. {
  477. nWidth -= GetSize().cy;
  478. }
  479. }
  480. }
  481. void CXTPTabManager::CNavigateButtonArrow::Reposition(CRect& rcNavigateButtons)
  482. {
  483. if (m_pManager->GetLayout() == xtpTabLayoutMultiRow)
  484. {
  485. m_rcButton.SetRectEmpty();
  486. return;
  487. }
  488. if (m_dwFlags == xtpTabNavigateButtonAutomatic)
  489. {
  490. if (m_pManager->GetLayout() == xtpTabLayoutSizeToFit)
  491. {
  492. m_rcButton.SetRectEmpty();
  493. return;
  494. }
  495. CRect rc = m_pManager->GetAppearanceSet()->GetHeaderMargin();
  496. if (!(m_pManager->GetItemsLength() + m_pManager->GetHeaderOffset() - rc.left - 1 > m_pManager->GetRectLength(rcNavigateButtons) - (rc.left + rc.right)
  497. || m_pManager->GetHeaderOffset() < 0))
  498. {
  499. m_rcButton.SetRectEmpty();
  500. return;
  501. }
  502. }
  503. CXTPTabManagerNavigateButton::Reposition(rcNavigateButtons);
  504. }
  505. void CXTPTabManager::CNavigateButtonArrowRight::Reposition(CRect& rcNavigateButtons)
  506. {
  507. XTPResourceManager()->LoadString(&m_strToolTip, m_pManager->IsHorizontalPosition() ? XTP_IDS_TABNAVIGATEBUTTON_RIGHT : XTP_IDS_TABNAVIGATEBUTTON_DOWN);
  508. CRect rcHeaderMargin = m_pManager->GetPaintManager()->GetAppearanceSet()->GetHeaderMargin();
  509. m_bEnabled = m_pManager->GetItemsLength() + m_pManager->GetHeaderOffset() >
  510. m_pManager->GetRectLength(rcNavigateButtons) - (rcHeaderMargin.left + rcHeaderMargin.right) - 28;
  511. CNavigateButtonArrow::Reposition(rcNavigateButtons);
  512. }
  513. void CXTPTabManager::CNavigateButtonArrowRight::OnExecute(BOOL bTick)
  514. {
  515. if (bTick)
  516. {
  517. m_pManager->OnScrollHeader(TRUE);
  518. }
  519. }
  520. void CXTPTabManager::OnScrollHeader(BOOL bRight)
  521. {
  522. if (bRight)
  523. {
  524. SetHeaderOffset(GetHeaderOffset() - m_nScrollDelta);
  525. }
  526. else
  527. {
  528. SetHeaderOffset(GetHeaderOffset() + m_nScrollDelta);
  529. }
  530. }
  531. void CXTPTabManager::CNavigateButtonArrowLeft::DrawEntry(CDC* pDC, CRect rc)
  532. {
  533. CPoint pt = rc.CenterPoint();
  534. if (m_pManager->IsHorizontalPosition())
  535. CXTPDrawHelpers::Triangle(pDC, CPoint(pt.x + 2, pt.y - 5), CPoint(pt.x - 2, pt.y - 1), CPoint(pt.x + 2, pt.y + 3));
  536. else
  537. CXTPDrawHelpers::Triangle(pDC, CPoint(pt.x - 5, pt.y + 2), CPoint(pt.x - 1, pt.y - 2), CPoint(pt.x + 3, pt.y + 2));
  538. }
  539. void CXTPTabManager::CNavigateButtonArrowLeft::Reposition(CRect& rcNavigateButtons)
  540. {
  541. XTPResourceManager()->LoadString(&m_strToolTip, m_pManager->IsHorizontalPosition() ? XTP_IDS_TABNAVIGATEBUTTON_LEFT : XTP_IDS_TABNAVIGATEBUTTON_UP);
  542. m_bEnabled = m_pManager->GetHeaderOffset() < 0;
  543. CNavigateButtonArrow::Reposition(rcNavigateButtons);
  544. }
  545. void CXTPTabManager::CNavigateButtonArrowLeft::OnExecute(BOOL bTick)
  546. {
  547. if (bTick)
  548. {
  549. m_pManager->OnScrollHeader(FALSE);
  550. }
  551. }
  552. //////////////////////////////////////////////////////////////////////
  553. // CXTPTabManager
  554. CXTPTabManager::CXTPTabManager()
  555. {
  556. m_pSelected = 0;
  557. m_pHighlighted = 0;
  558. m_pPressed = 0;
  559. m_nHeaderOffset = 0;
  560. m_bAllowReorder = TRUE;
  561. m_bActive = TRUE;
  562. m_nScrollDelta = 20;
  563. m_rcHeaderRect.SetRectEmpty();
  564. m_rcControl.SetRectEmpty();
  565. m_rcClient.SetRectEmpty();
  566. m_bCloseItemButton = xtpTabNavigateButtonNone;
  567. m_pHighlightedNavigateButton = NULL;
  568. m_pRowIndexer = new CRowIndexer(this);
  569. m_arrNavigateButtons.Add(new CNavigateButtonArrowLeft(this, xtpTabNavigateButtonAutomatic));
  570. m_arrNavigateButtons.Add(new CNavigateButtonArrowRight(this, xtpTabNavigateButtonAutomatic));
  571. m_arrNavigateButtons.Add(new CNavigateButtonClose(this, xtpTabNavigateButtonNone));
  572. m_pMarkupContext = NULL;
  573. }
  574. CXTPTabManager::~CXTPTabManager()
  575. {
  576. for (int i = 0; i < m_arrItems.GetSize(); i++)
  577. {
  578. CXTPTabManagerItem* pItem = m_arrItems[i];
  579. pItem->OnRemoved();
  580. pItem->InternalRelease();
  581. }
  582. for (int j = 0; j < m_arrNavigateButtons.GetSize(); j++)
  583. delete m_arrNavigateButtons[j];
  584. delete m_pRowIndexer;
  585. XTPMarkupReleaseContext(m_pMarkupContext);
  586. }
  587. void CXTPTabManager::EnableMarkup(BOOL bEnable)
  588. {
  589. BOOL bMarkupContext = m_pMarkupContext != NULL;
  590. if (bMarkupContext == bEnable)
  591. return;
  592. for (int i = 0; i < m_arrItems.GetSize(); i++)
  593. {
  594. XTPMarkupReleaseElement(m_arrItems[i]->m_pMarkupUIElement);
  595. }
  596. XTPMarkupReleaseContext(m_pMarkupContext);
  597. if (bEnable)
  598. {
  599. m_pMarkupContext = XTPMarkupCreateContext();
  600. }
  601. }
  602. void CXTPTabManager::SetActive(BOOL bActive)
  603. {
  604. if (m_bActive != bActive)
  605. {
  606. m_bActive = bActive;
  607. Reposition();
  608. }
  609. }
  610. BOOL CXTPTabManager::IsNavigateButtonAutomaticVisible(CXTPTabManagerNavigateButton* pButton)
  611. {
  612. if (pButton->GetID() == xtpTabNavigateButtonClose)
  613. {
  614. return m_pSelected ? m_pSelected->IsClosable() : FALSE;
  615. }
  616. return TRUE;
  617. }
  618. void CXTPTabManager::EnableTabThemeTexture(HWND hWnd, BOOL bEnable)
  619. {
  620. m_themeTabControl.OpenTheme(hWnd, L"TAB");
  621. m_themeTabControl.EnableThemeDialogTexture(hWnd, bEnable ? ETDT_ENABLETAB : ETDT_DISABLE | ETDT_USETABTEXTURE);
  622. }
  623. CXTPTabManagerNavigateButton* CXTPTabManager::FindNavigateButton(UINT nID) const
  624. {
  625. for (int i = 0; i < m_arrNavigateButtons.GetSize(); i++)
  626. {
  627. if (m_arrNavigateButtons[i]->m_nID == nID)
  628. return m_arrNavigateButtons[i];
  629. }
  630. return NULL;
  631. }
  632. void CXTPTabManager::SetHeaderOffset(int nOffset)
  633. {
  634. if (nOffset > 0) nOffset = 0;
  635. if (nOffset != m_nHeaderOffset)
  636. {
  637. m_nHeaderOffset = nOffset;
  638. Reposition();
  639. }
  640. }
  641. int CXTPTabManager::GetItemsLength() const
  642. {
  643. int nLength = 0;
  644. if (GetLayout() == xtpTabLayoutRotated)
  645. {
  646. nLength = GetPaintManager()->GetAppearanceSet()->GetButtonHeight(this)
  647. * GetItemCount();
  648. }
  649. else
  650. {
  651. for (int i = 0; i < GetItemCount(); i++)
  652. nLength += GetItem(i)->GetButtonLength();
  653. }
  654. return nLength;
  655. }
  656. void CXTPTabManager::DeleteAllItems()
  657. {
  658. for (int i = 0; i < m_arrItems.GetSize(); i++)
  659. {
  660. CXTPTabManagerItem* pItem = m_arrItems[i];
  661. pItem->OnRemoved();
  662. pItem->InternalRelease();
  663. }
  664. m_arrItems.RemoveAll();
  665. m_pHighlighted = m_pSelected = m_pPressed = NULL;
  666. OnItemsChanged();
  667. }
  668. BOOL CXTPTabManager::DeleteItem(int nItem)
  669. {
  670. if (nItem < 0 || nItem >= GetItemCount())
  671. return FALSE;
  672. CXTPTabManagerItem* pItem = m_arrItems[nItem];
  673. BOOL bSelected = (m_pSelected == pItem);
  674. if (m_pHighlighted == pItem)
  675. m_pHighlighted = NULL;
  676. m_arrItems.RemoveAt(nItem);
  677. pItem->OnRemoved();
  678. pItem->InternalRelease();
  679. if (bSelected)
  680. {
  681. SetCurSel(nItem);
  682. }
  683. OnItemsChanged();
  684. return TRUE;
  685. }
  686. CXTPTabManagerItem* CXTPTabManager::AddItem(int nItem, CXTPTabManagerItem* pItem /*= NULL*/)
  687. {
  688. if (!pItem)
  689. pItem = new CXTPTabManagerItem();
  690. pItem->m_pTabManager = this;
  691. if (nItem < 0 || nItem > GetItemCount())
  692. nItem = GetItemCount();
  693. m_arrItems.InsertAt(nItem, pItem);
  694. pItem->m_clrItem = xtpTabColorBlue + (GetPaintManager()->m_nItemColor++ % 8);
  695. if (m_bCloseItemButton != xtpTabNavigateButtonNone)
  696. {
  697. pItem->m_arrNavigateButtons.Add(new CNavigateButtonTabClose(pItem, m_bCloseItemButton));
  698. }
  699. OnItemsChanged();
  700. return pItem;
  701. }
  702. void CXTPTabManager::OnItemsChanged()
  703. {
  704. for (int i = 0; i < GetItemCount(); i++)
  705. {
  706. GetItem(i)->m_nIndex = i;
  707. }
  708. Reposition();
  709. }
  710. CString CXTPTabManager::GetItemCaption(const CXTPTabManagerItem* pItem) const
  711. {
  712. return pItem->m_strCaption;
  713. }
  714. HICON CXTPTabManager::GetItemIcon(const CXTPTabManagerItem* pItem) const
  715. {
  716. return pItem->m_hIcon;
  717. }
  718. void CXTPTabManager::ShowIcons(BOOL bShowIcons)
  719. {
  720. GetPaintManager()->m_bShowIcons = bShowIcons;
  721. Reposition();
  722. }
  723. COLORREF CXTPTabManager::GetItemColor(const CXTPTabManagerItem* pItem) const
  724. {
  725. COLORREF nColor = pItem->m_clrItem;
  726. if (nColor >= xtpTabColorBlue && nColor <= xtpTabColorMagenta)
  727. return CXTPTabPaintManager::GetOneNoteColor((XTPTabOneNoteColor)nColor);
  728. return nColor;
  729. }
  730. void CXTPTabManager::SetCurSel(int nIndex)
  731. {
  732. if (GetItemCount() != 0)
  733. {
  734. nIndex = nIndex < 0 ? 0: nIndex >= GetItemCount() ? GetItemCount() - 1 : nIndex;
  735. SetSelectedItem(GetItem(nIndex));
  736. }
  737. else
  738. {
  739. SetSelectedItem(NULL);
  740. }
  741. }
  742. int CXTPTabManager::GetCurSel() const
  743. {
  744. if (m_pSelected)
  745. {
  746. return m_pSelected->GetIndex();
  747. }
  748. return -1;
  749. }
  750. void CXTPTabManager::SetSelectedItem(CXTPTabManagerItem* pItem)
  751. {
  752. if (m_pSelected != pItem)
  753. {
  754. m_pSelected = pItem;
  755. Reposition();
  756. EnsureVisible(pItem);
  757. }
  758. }
  759. void CXTPTabManager::EnsureVisible(CXTPTabManagerItem* pItem)
  760. {
  761. if (!pItem)
  762. return;
  763. GetPaintManager()->EnsureVisible(this, pItem);
  764. }
  765. void CXTPTabManager::SetPosition(XTPTabPosition tabPosition)
  766. {
  767. GetPaintManager()->m_tabPosition = tabPosition;
  768. Reposition();
  769. }
  770. void CXTPTabManager::SetLayoutStyle(XTPTabLayoutStyle tabLayout)
  771. {
  772. GetPaintManager()->m_tabLayout = tabLayout;
  773. Reposition();
  774. }
  775. CXTPTabManagerItem* CXTPTabManager::HitTest(CPoint point) const
  776. {
  777. if (!m_rcControl.PtInRect(point))
  778. return NULL;
  779. if (!m_rcHeaderRect.IsRectEmpty() && !m_rcHeaderRect.PtInRect(point))
  780. return NULL;
  781. for (int i = 0; i < GetItemCount(); i++)
  782. {
  783. CXTPTabManagerItem* pItem = GetItem(i);
  784. if (pItem->GetRect().PtInRect(point) && pItem->IsEnabled() && pItem->IsVisible())
  785. {
  786. return pItem;
  787. }
  788. }
  789. return NULL;
  790. }
  791. XTPTabPosition CXTPTabManager::GetPosition() const
  792. {
  793. return GetPaintManager()->m_tabPosition;
  794. }
  795. XTPTabLayoutStyle CXTPTabManager::GetLayout() const
  796. {
  797. return GetPaintManager()->m_tabLayout;
  798. }
  799. void CXTPTabManager::MoveItem(CXTPTabManagerItem* pItem, int nIndex)
  800. {
  801. ASSERT(pItem && pItem->GetTabManager() == this);
  802. if (!pItem || pItem->GetTabManager() != this)
  803. return;
  804. int nOldIndex = pItem->GetIndex();
  805. if (nOldIndex == nIndex)
  806. return;
  807. ASSERT(nOldIndex >= 0);
  808. ASSERT(nIndex >= 0 && nIndex < GetItemCount());
  809. if (nIndex < 0 || nIndex >= GetItemCount())
  810. nIndex = GetItemCount() - 1;
  811. m_arrItems.RemoveAt(nOldIndex);
  812. m_arrItems.InsertAt(nIndex, pItem);
  813. OnItemsChanged();
  814. }
  815. void CXTPTabManager::TrackClick(HWND hWnd, CPoint pt, CXTPTabManagerItem* pItem)
  816. {
  817. if (GetPaintManager()->m_bHotTracking)
  818. m_pHighlighted = pItem;
  819. m_pPressed = pItem;
  820. BOOL bHighlighted = TRUE;
  821. Reposition();
  822. BOOL bAccept = FALSE;
  823. ::SetCapture(hWnd);
  824. while (::GetCapture() == hWnd)
  825. {
  826. MSG msg;
  827. VERIFY(::GetMessage(&msg, NULL, 0, 0));
  828. if (::GetCapture() != hWnd)
  829. {
  830. DispatchMessage (&msg);
  831. break;
  832. }
  833. switch (msg.message)
  834. {
  835. case WM_MOUSEMOVE:
  836. {
  837. pt = CPoint((short signed)LOWORD(msg.lParam), (short signed)HIWORD(msg.lParam));
  838. bHighlighted = pItem->GetRect().PtInRect(pt);
  839. if (GetPaintManager()->m_bHotTracking)
  840. {
  841. CXTPTabManagerItem* pHighlighted = bHighlighted ? pItem : NULL;
  842. if (pHighlighted != m_pHighlighted)
  843. {
  844. m_pHighlighted = pHighlighted;
  845. RedrawControl(pItem->GetRect(), TRUE);
  846. }
  847. }
  848. }
  849. break;
  850. case WM_KEYDOWN:
  851. if (msg.wParam != VK_ESCAPE)
  852. break;
  853. case WM_CANCELMODE:
  854. case WM_RBUTTONDOWN:
  855. goto ExitLoop;
  856. case WM_LBUTTONUP:
  857. bAccept = TRUE;
  858. goto ExitLoop;
  859. default:
  860. DispatchMessage (&msg);
  861. break;
  862. }
  863. }
  864. ExitLoop:
  865. ReleaseCapture();
  866. m_pPressed = FALSE;
  867. PerformMouseMove(hWnd, pt);
  868. RedrawControl(NULL, FALSE);
  869. if (bAccept && bHighlighted)
  870. {
  871. OnItemClick(pItem);
  872. }
  873. }
  874. void CXTPTabManager::ReOrder(HWND hWnd, CPoint pt, CXTPTabManagerItem* pItem)
  875. {
  876. CXTPTabManagerItem* pSelected = m_pSelected;
  877. m_pSelected = pItem;
  878. if (GetPaintManager()->m_bHotTracking)
  879. m_pHighlighted = pItem;
  880. Reposition();
  881. CArray<CRect, CRect&> arrRects;
  882. for (int j = 0; j < GetItemCount(); j++)
  883. {
  884. CRect rc = GetItem(j)->GetRect();
  885. arrRects.Add(rc);
  886. }
  887. ::SetCapture(hWnd);
  888. while (::GetCapture() == hWnd)
  889. {
  890. MSG msg;
  891. VERIFY(::GetMessage(&msg, NULL, 0, 0));
  892. if (::GetCapture() != hWnd)
  893. {
  894. DispatchMessage (&msg);
  895. break;
  896. }
  897. switch (msg.message)
  898. {
  899. case WM_MOUSEMOVE:
  900. {
  901. pt = CPoint((short signed)LOWORD(msg.lParam), (short signed)HIWORD(msg.lParam));
  902. for (int i = 0; i < arrRects.GetSize(); i++)
  903. {
  904. if (i != pItem->GetIndex() && arrRects[i].PtInRect(pt))
  905. {
  906. CXTPTabManagerItem* p = pItem;
  907. m_arrItems[pItem->GetIndex()] = m_arrItems[i];
  908. m_arrItems[i] = p;
  909. OnItemsChanged();
  910. break;
  911. }
  912. }
  913. }
  914. break;
  915. case WM_KEYDOWN:
  916. if (msg.wParam != VK_ESCAPE)
  917. break;
  918. case WM_CANCELMODE:
  919. case WM_LBUTTONUP:
  920. case WM_RBUTTONDOWN:
  921. goto ExitLoop;
  922. default:
  923. DispatchMessage (&msg);
  924. break;
  925. }
  926. }
  927. ExitLoop:
  928. ReleaseCapture();
  929. PerformMouseMove(hWnd, pt);
  930. m_pSelected = pSelected;
  931. OnItemClick(pItem);
  932. }
  933. void CXTPTabManager::OnItemClick(CXTPTabManagerItem* pItem)
  934. {
  935. SetSelectedItem(pItem);
  936. }
  937. void CXTPTabManager::SetFocusedItem(CXTPTabManagerItem* pItem)
  938. {
  939. if (!OnBeforeItemClick(pItem))
  940. return;
  941. if (pItem)
  942. {
  943. OnItemClick(pItem);
  944. }
  945. }
  946. CXTPTabManagerItem* CXTPTabManager::FindNextFocusable(int nIndex, int nDirection) const
  947. {
  948. CXTPTabManagerItem* pItem = NULL;
  949. do
  950. {
  951. nIndex += nDirection;
  952. pItem = GetItem(nIndex);
  953. if (!pItem)
  954. return NULL;
  955. }
  956. while (!(pItem->IsVisible() && pItem->IsEnabled()));
  957. return pItem;
  958. }
  959. BOOL CXTPTabManager::PerformKeyDown(HWND hWnd, UINT nChar)
  960. {
  961. const int nCount = GetItemCount();
  962. if (nCount < 1)
  963. return FALSE;
  964. if (nChar == VK_LEFT && (DWORD)GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
  965. nChar = VK_RIGHT;
  966. else if (nChar == VK_RIGHT && (DWORD)GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
  967. nChar = VK_LEFT;
  968. switch (nChar)
  969. {
  970. case VK_HOME:
  971. SetFocusedItem(FindNextFocusable(-1, +1));
  972. return TRUE;
  973. case VK_END:
  974. SetFocusedItem(FindNextFocusable(nCount, -1));
  975. return TRUE;
  976. case VK_LEFT:
  977. if (IsHorizontalPosition() && m_pSelected && m_pSelected->GetIndex() > 0)
  978. SetFocusedItem(FindNextFocusable(m_pSelected->GetIndex(), -1));
  979. return TRUE;
  980. case VK_UP:
  981. if (!IsHorizontalPosition() && m_pSelected && m_pSelected->GetIndex() > 0)
  982. SetFocusedItem(FindNextFocusable(m_pSelected->GetIndex(), -1));
  983. return TRUE;
  984. case VK_RIGHT:
  985. if (IsHorizontalPosition() && m_pSelected && m_pSelected->GetIndex() < nCount - 1)
  986. SetFocusedItem(FindNextFocusable(m_pSelected->GetIndex(), + 1));
  987. return TRUE;
  988. case VK_DOWN:
  989. if (!IsHorizontalPosition() && m_pSelected && m_pSelected->GetIndex() < nCount - 1)
  990. SetFocusedItem(FindNextFocusable(m_pSelected->GetIndex(), + 1));
  991. return TRUE;
  992. }
  993. return FALSE;
  994. }
  995. BOOL CXTPTabManager::OnBeforeItemClick(CXTPTabManagerItem* /*pItem*/)
  996. {
  997. return TRUE;
  998. }
  999. CXTPTabManagerNavigateButton* CXTPTabManager::HitTestNavigateButton(CPoint point, BOOL bHeaderOnly, int* pnIndex) const
  1000. {
  1001. int i;
  1002. for (i = 0; i < (int)m_arrNavigateButtons.GetSize(); i++)
  1003. {
  1004. CXTPTabManagerNavigateButton* pButton = m_arrNavigateButtons[i];
  1005. if (pButton->m_rcButton.PtInRect(point))
  1006. {
  1007. if (!pButton->IsEnabled())
  1008. return NULL;
  1009. if (pnIndex)
  1010. {
  1011. *pnIndex = i;
  1012. }
  1013. return pButton;
  1014. }
  1015. }
  1016. if (bHeaderOnly)
  1017. return NULL;
  1018. CXTPTabManagerItem* pItem = HitTest(point);
  1019. if (!pItem)
  1020. return NULL;
  1021. for (i = 0; i < (int)pItem->GetNavigateButtons()->GetSize(); i++)
  1022. {
  1023. CXTPTabManagerNavigateButton* pButton = pItem->GetNavigateButtons()->GetAt(i);
  1024. if (pButton->m_rcButton.PtInRect(point))
  1025. {
  1026. if (!pButton->IsEnabled())
  1027. return NULL;
  1028. if (pnIndex)
  1029. {
  1030. *pnIndex = i;
  1031. }
  1032. return pButton;
  1033. }
  1034. }
  1035. return NULL;
  1036. }
  1037. BOOL CXTPTabManager::PerformClick(HWND hWnd, CPoint pt, BOOL bNoItemClick)
  1038. {
  1039. CXTPTabManagerNavigateButton* pNavigateButton = HitTestNavigateButton(pt, FALSE);
  1040. if (pNavigateButton)
  1041. {
  1042. pNavigateButton->PerformClick(hWnd, pt);
  1043. return TRUE;
  1044. }
  1045. if (bNoItemClick)
  1046. return FALSE;
  1047. CXTPTabManagerItem* pItem = HitTest(pt);
  1048. if (pItem)
  1049. {
  1050. if (!OnBeforeItemClick(pItem))
  1051. return FALSE;
  1052. if (IsAllowReorder())
  1053. {
  1054. ReOrder(hWnd, pt, pItem);
  1055. }
  1056. else if (GetPaintManager()->m_bSelectOnButtonDown)
  1057. {
  1058. OnItemClick(pItem);
  1059. }
  1060. else
  1061. {
  1062. TrackClick(hWnd, pt, pItem);
  1063. }
  1064. return TRUE;
  1065. }
  1066. return FALSE;
  1067. }
  1068. void CXTPTabManager::PerformMouseMove(HWND hWnd, CPoint pt)
  1069. {
  1070.  CXTPTabPaintManager::CAppearanceSet* pAppearance = GetPaintManager()->GetAppearanceSet();
  1071.  if (!CXTPDrawHelpers::IsTopParentActive(hWnd) || IsMouseLocked())
  1072. {
  1073. if (m_pHighlighted)
  1074. {
  1075. CRect rcRedraw(pAppearance->GetButtonDrawRect(m_pHighlighted));
  1076. m_pHighlighted = NULL;
  1077. RedrawControl(rcRedraw, TRUE);
  1078. }
  1079. return;
  1080. }
  1081. if (GetPaintManager()->m_bHotTracking)
  1082. {
  1083. CXTPTabManagerItem* pItem = HitTest(pt);
  1084. if (pItem != m_pHighlighted)
  1085. {
  1086. if (m_pHighlighted)
  1087. {
  1088. CRect rcRedraw(pAppearance->GetButtonDrawRect(m_pHighlighted));
  1089. m_pHighlighted = NULL;
  1090. RedrawControl(rcRedraw, TRUE);
  1091. }
  1092. m_pHighlighted = pItem;
  1093. if (m_pHighlighted)
  1094. {
  1095. RedrawControl(pAppearance->GetButtonDrawRect(m_pHighlighted), FALSE);
  1096. }
  1097. if (pItem)
  1098. {
  1099. TRACKMOUSEEVENT tme =
  1100. {
  1101. sizeof(TRACKMOUSEEVENT), TME_LEAVE, hWnd
  1102. };
  1103. _TrackMouseEvent(&tme);
  1104. }
  1105. }
  1106. }
  1107. CXTPTabManagerNavigateButton* pNavigateButton = HitTestNavigateButton(pt, FALSE);
  1108. if (pNavigateButton != m_pHighlightedNavigateButton)
  1109. {
  1110. if (m_pHighlightedNavigateButton)
  1111. {
  1112. RedrawControl(m_pHighlightedNavigateButton->GetRect(), TRUE);
  1113. }
  1114. m_pHighlightedNavigateButton = pNavigateButton;
  1115. if (m_pHighlightedNavigateButton)
  1116. {
  1117. RedrawControl(m_pHighlightedNavigateButton->GetRect(), FALSE);
  1118. }
  1119. if (pNavigateButton)
  1120. {
  1121. TRACKMOUSEEVENT tme =
  1122. {
  1123. sizeof(TRACKMOUSEEVENT), TME_LEAVE, hWnd
  1124. };
  1125. _TrackMouseEvent(&tme);
  1126. }
  1127. }
  1128. }
  1129. CString CXTPTabManager::GetItemTooltip(const CXTPTabManagerItem* pItem) const
  1130. {
  1131. return pItem->m_strToolTip;
  1132. }
  1133. INT_PTR CXTPTabManager::PerformToolHitTest(HWND hWnd, CPoint point, TOOLINFO* pTI) const
  1134. {
  1135. if (IsMouseLocked())
  1136. return -1;
  1137. int nIndex = -1;
  1138. CXTPTabManagerNavigateButton* pNavigateButton = HitTestNavigateButton(point, FALSE, &nIndex);
  1139. if (pNavigateButton)
  1140. {
  1141. ASSERT(nIndex != -1);
  1142. CString strTip = pNavigateButton->GetTooltip();
  1143. if (strTip.IsEmpty())
  1144. return -1;
  1145. CXTPToolTipContext::FillInToolInfo(pTI, hWnd, pNavigateButton->GetRect(), nIndex, strTip);
  1146. return nIndex;
  1147. }
  1148. CXTPTabManagerItem* pItem = HitTest(point);
  1149. if (pItem)
  1150. {
  1151. if (GetPaintManager()->m_toolBehaviour == xtpTabToolTipNever)
  1152. return -1;
  1153. if (GetPaintManager()->m_toolBehaviour == xtpTabToolTipShrinkedOnly && !pItem->IsItemShrinked())
  1154. return -1;
  1155. CString strTip = GetItemTooltip(pItem);
  1156. if (strTip.IsEmpty())
  1157. return -1;
  1158. CXTPToolTipContext::FillInToolInfo(pTI, hWnd, pItem->GetRect(), pItem->GetIndex(), strTip, pItem->GetCaption(), strTip);
  1159. return pItem->GetIndex();
  1160. }
  1161. return -1;
  1162. }
  1163. void CXTPTabManager::GetItemMetrics(CSize* lpszNormal, CSize* lpszMin /*= NULL*/, CSize* lpszMax /*= NULL*/) const
  1164. {
  1165. CXTPTabPaintManager* pPaintManager = GetPaintManager();
  1166. if (lpszNormal) *lpszNormal = CSize(pPaintManager->m_nFixedTabWidth, 0);
  1167. if (lpszMin) *lpszMin = CSize(pPaintManager->m_nMinTabWidth, 0);
  1168. if (lpszMax) *lpszMax = CSize(pPaintManager->m_nMaxTabWidth, 0);
  1169. }
  1170. void CXTPTabManager::SetItemMetrics(CSize szNormal, CSize szMin /*= CSize(0, 0)*/, CSize szMax /*= CSize(0, 0)*/)
  1171. {
  1172. CXTPTabPaintManager* pPaintManager = GetPaintManager();
  1173. pPaintManager->m_nFixedTabWidth = szNormal.cx;
  1174. pPaintManager->m_nMinTabWidth = szMin.cx;
  1175. pPaintManager->m_nMaxTabWidth = szMax.cx;
  1176. Reposition();
  1177. }
  1178. BOOL CXTPTabManager::IsDrawStaticFrame() const
  1179. {
  1180. return GetPaintManager()->m_bStaticFrame;
  1181. }
  1182. CXTPTabPaintManager::CColorSet* CXTPTabManager::SetColor(XTPTabColorStyle tabColor)
  1183. {
  1184. CXTPTabPaintManager::CColorSet* pColorSet = GetPaintManager()->SetColor(tabColor);
  1185. Reposition();
  1186. return pColorSet;
  1187. }
  1188. CXTPTabPaintManager::CColorSet* CXTPTabManager::SetColorSet(CXTPTabPaintManager::CColorSet* pColorSet)
  1189. {
  1190. GetPaintManager()->SetColorSet(pColorSet);
  1191. Reposition();
  1192. return pColorSet;
  1193. }
  1194. CXTPTabPaintManager::CAppearanceSet* CXTPTabManager::SetAppearance(XTPTabAppearanceStyle tabAppearance)
  1195. {
  1196. CXTPTabPaintManager::CAppearanceSet* pAppearanceSet = GetPaintManager()->SetAppearance(tabAppearance);
  1197. Reposition();
  1198. return pAppearanceSet;
  1199. }
  1200. CXTPTabPaintManager::CAppearanceSet* CXTPTabManager::SetAppearanceSet(CXTPTabPaintManager::CAppearanceSet* pAppearanceSet)
  1201. {
  1202. GetPaintManager()->SetAppearanceSet(pAppearanceSet);
  1203. Reposition();
  1204. return pAppearanceSet;
  1205. }