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

对话框与窗口

开发平台:

Visual C++

  1. // XTPTaskPanel.cpp : implementation of the CXTPTaskPanel class.
  2. //
  3. // This file is a part of the XTREME TASKPANEL 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/Resource.h"
  23. #include "Common/XTPVC80Helpers.h"
  24. #include "Common/XTPDrawHelpers.h"
  25. #include "Common/XTPImageManager.h"
  26. #include "Common/XTPToolTipContext.h"
  27. #include "Common/XTPResourceManager.h"
  28. #include "Common/XTPMarkupRender.h"
  29. #if !defined(_XTP_ACTIVEX) && defined(_XTP_INCLUDE_COMMANDBARS)
  30. #include "CommandBars/XTPCommandBar.h"
  31. #include "CommandBars/XTPMouseManager.h"
  32. #endif
  33. #include "XTPTaskPanelItems.h"
  34. #include "XTPTaskPanelGroup.h"
  35. #include "XTPTaskPanel.h"
  36. #include "XTPTaskPanelPaintManager.h"
  37. #include "XTPTaskPanelGroupItem.h"
  38. #include "XTPTaskPanelAnimation.h"
  39. #ifdef _DEBUG
  40. #define new DEBUG_NEW
  41. #undef THIS_FILE
  42. static char THIS_FILE[] = __FILE__;
  43. #endif
  44. #ifndef SPI_GETMOUSEHOVERTIME
  45. #define SPI_GETMOUSEHOVERTIME 102
  46. #endif
  47. #define TID_REPOSITION 200
  48. #define TID_SCROLLBARS 201
  49. #define TID_SCROLLGROUP 202
  50. #define TID_GROUPHOVER 203
  51. #define IsItemLink(pItem) (pItem && pItem->GetType() == xtpTaskItemTypeLink)
  52. #define IsItemGroup(pItem) (pItem && pItem->GetType() == xtpTaskItemTypeGroup)
  53. CLIPFORMAT CXTPTaskPanel::m_cfItem = (CLIPFORMAT)::RegisterClipboardFormat(_T("TaskPanelGroupItem"));
  54. BOOL CXTPTaskPanel::GetMessageExt(MSG& msg)
  55. {
  56. while (::PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE))
  57. {
  58. if (!GetMessage(&msg, NULL, WM_PAINT, WM_PAINT))
  59. break;
  60. DispatchMessage(&msg);
  61. }
  62. if (!::GetMessage(&msg, NULL, 0, 0))
  63. {
  64. AfxPostQuitMessage((int)msg.wParam);
  65. return FALSE;
  66. }
  67. return TRUE;
  68. }
  69. //////////////////////////////////////////////////////////////////////////
  70. // CPanelDropTarget
  71. class CXTPTaskPanel::CPanelDropTarget : public COleDropTarget
  72. {
  73. public:
  74. virtual DROPEFFECT OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
  75. {
  76. CXTPTaskPanel* pPanel = DYNAMIC_DOWNCAST(CXTPTaskPanel, pWnd);
  77. if (!pPanel)
  78. return DROPEFFECT_NONE;
  79. return pPanel->OnDragOver(pDataObject, dwKeyState, point);
  80. }
  81. virtual void OnDragLeave(CWnd* pWnd)
  82. {
  83. CXTPTaskPanel* pPanel = DYNAMIC_DOWNCAST(CXTPTaskPanel, pWnd);
  84. if (pPanel)
  85. {
  86. pPanel->OnDragOver(NULL, 0, CPoint(-1, -1));
  87. }
  88. }
  89. virtual BOOL OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
  90. DROPEFFECT dropEffect, CPoint point)
  91. {
  92. CXTPTaskPanel* pPanel = DYNAMIC_DOWNCAST(CXTPTaskPanel, pWnd);
  93. if (pPanel)
  94. {
  95. return pPanel->OnDrop(pDataObject, dropEffect, point);
  96. }
  97. return FALSE;
  98. }
  99. };
  100. //////////////////////////////////////////////////////////////////////////
  101. // CXTPTaskPanelScrollButton
  102. CXTPTaskPanelScrollButton::CXTPTaskPanelScrollButton(BOOL bScrollUp)
  103. {
  104. this->bScrollUp = bScrollUp;
  105. bEnabled = FALSE;
  106. bPressed = FALSE;
  107. bHot = FALSE;
  108. rcButton.SetRectEmpty();
  109. pGroupScroll = pGroupCaption = NULL;
  110. }
  111. BOOL CXTPTaskPanelScrollButton::IsVisible() const
  112. {
  113. if (rcButton.IsRectEmpty())
  114. return FALSE;
  115. if (pGroupScroll == NULL)
  116. return FALSE;
  117. if (!bEnabled && !pGroupScroll->GetTaskPanel()->GetPaintManager()->m_bCaptionScrollButton)
  118. return FALSE;
  119. return TRUE;
  120. }
  121. //////////////////////////////////////////////////////////////////////////
  122. // CXTPTaskPanelEditItem
  123. class CXTPTaskPanelEditItem : public CEdit
  124. {
  125. public:
  126. CXTPTaskPanelEditItem();
  127. public:
  128. BOOL Create(CXTPTaskPanelItem* pItem);
  129. protected:
  130. virtual void PostNcDestroy();
  131. protected:
  132. afx_msg void OnKillFocus(CWnd* pNewWnd);
  133. afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  134. afx_msg UINT OnGetDlgCode();
  135. protected:
  136. BOOL m_bEscapeKey;
  137. CXTPTaskPanelItem* m_pItem;
  138. private:
  139. BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
  140. BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  141. protected:
  142. DECLARE_MESSAGE_MAP()
  143. DECLARE_DYNAMIC(CXTPTaskPanelEditItem)
  144. };
  145. AFX_INLINE BOOL CXTPTaskPanelEditItem::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  146. {
  147. return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  148. }
  149. AFX_INLINE BOOL CXTPTaskPanelEditItem::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  150. {
  151. return CEdit::Create(dwStyle, rect, pParentWnd, nID);
  152. }
  153. IMPLEMENT_DYNAMIC(CXTPTaskPanelEditItem, CEdit)
  154. CXTPTaskPanelEditItem::CXTPTaskPanelEditItem()
  155. {
  156. m_bEscapeKey = FALSE;
  157. m_pItem = NULL;
  158. }
  159. BEGIN_MESSAGE_MAP(CXTPTaskPanelEditItem, CEdit)
  160. //{{AFX_MSG_MAP(CXTPTaskPanelEditItem)
  161. ON_WM_KILLFOCUS()
  162. ON_WM_CHAR()
  163. ON_WM_GETDLGCODE()
  164. //}}AFX_MSG_MAP
  165. END_MESSAGE_MAP()
  166. UINT CXTPTaskPanelEditItem::OnGetDlgCode()
  167. {
  168. return DLGC_WANTALLKEYS;
  169. }
  170. void CXTPTaskPanelEditItem::OnKillFocus(CWnd* /*pNewWnd*/)
  171. {
  172. PostMessage(WM_CLOSE);
  173. if (!m_pItem)
  174. return;
  175. if (!m_bEscapeKey)
  176. {
  177. CString str;
  178. GetWindowText(str);
  179. m_pItem->GetTaskPanel()->OnEndLabelEdit(m_pItem, str);
  180. }
  181. else
  182. {
  183. m_pItem->GetTaskPanel()->OnEndLabelEdit(m_pItem, m_pItem->GetCaption());
  184. }
  185. m_pItem = NULL;
  186. }
  187. void CXTPTaskPanelEditItem::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  188. {
  189. if (nChar == VK_ESCAPE || nChar == VK_RETURN)
  190. {
  191. m_bEscapeKey = (nChar == VK_ESCAPE);
  192. OnKillFocus(NULL);
  193. return;
  194. }
  195. CEdit::OnChar(nChar, nRepCnt, nFlags);
  196. }
  197. void CXTPTaskPanelEditItem::PostNcDestroy()
  198. {
  199. delete this;
  200. }
  201. BOOL CXTPTaskPanelEditItem::Create(CXTPTaskPanelItem* pItem)
  202. {
  203. m_pItem = pItem;
  204. CXTPTaskPanel* pPanel = pItem->GetTaskPanel();
  205. CFont* pFont = m_pItem->GetItemFont();
  206. UINT nFormat = 0;
  207. CRect rc = pItem->GetTextRect(&nFormat);
  208. rc.OffsetRect(0, -pPanel->GetScrollOffset());
  209. CString strText = pItem->GetCaption();
  210. UINT nCenter = nFormat & DT_CENTER ? ES_CENTER : 0;
  211. if (!CEdit::Create(WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | nCenter, rc, pPanel, 0))
  212. return FALSE;
  213. SetFont(pFont);
  214. SetMargins(0, 0);
  215. SetWindowText(strText);
  216. SetFocus();
  217. SetSel(0, -1);
  218. return TRUE;
  219. }
  220. void CXTPTaskPanel::EnableMarkup(BOOL bEnable)
  221. {
  222. XTPMarkupReleaseContext(m_pMarkupContext);
  223. if (bEnable)
  224. {
  225. m_pMarkupContext = XTPMarkupCreateContext();
  226. }
  227. }
  228. void CXTPTaskPanel::RenameItem(CXTPTaskPanelItem* pItem)
  229. {
  230. Reposition(FALSE);
  231. EnsureVisible(pItem);
  232. UpdateWindow();
  233. CXTPTaskPanelEditItem* pEditItem = new CXTPTaskPanelEditItem;
  234. pEditItem->Create(pItem);
  235. }
  236. void CXTPTaskPanel::OnEndLabelEdit(CXTPTaskPanelItem* pItem, LPCTSTR str)
  237. {
  238. XTP_TPNENDLABELEDIT ele;
  239. ele.pItem = pItem;
  240. ele.strNewString = str;
  241. if (NotifyOwner(XTP_TPN_ENDLABELEDIT, (LPARAM)&ele) == XTP_ACTION_CANCEL)
  242. return;
  243. pItem->SetCaption(ele.strNewString);
  244. }
  245. /////////////////////////////////////////////////////////////////////////////
  246. // CXTPTaskPanel
  247. IMPLEMENT_DYNAMIC(CXTPTaskPanel, CWnd)
  248. CXTPTaskPanel::CXTPTaskPanel()
  249. {
  250. RegisterWindowClass();
  251. m_pPaintManager = NULL;
  252. SetTheme(xtpTaskPanelThemeNativeWinXP);
  253. m_pGroups = new CXTPTaskPanelGroups(this);
  254. m_pGroups->m_pOwner = this;
  255. m_nClientHeight = m_nOldClientHeight = 0;
  256. m_rcMargins = CXTPTaskPanelPaintManager::rectDefault;
  257. m_nGroupSpacing = CW_USEDEFAULT;
  258. m_szItemIcon = CSize(16, 16);
  259. m_szGroupIcon = CSize(32, 32);
  260. m_bGrabbingFocus = FALSE;
  261. m_pItemHot = 0;
  262. m_pItemFocused = 0;
  263. m_pItemPressed = 0;
  264. m_nAnimateTimer = 0;
  265. m_bScrollVisible = FALSE;
  266. m_bPreSubclassWindow = TRUE;
  267. m_hHandCursor = AfxGetApp()->LoadStandardCursor(MAKEINTRESOURCE(32649));
  268. if (m_hHandCursor == 0)
  269. m_hHandCursor = XTPResourceManager()->LoadCursor(XTP_IDC_HAND);
  270. m_bExpandable = TRUE;
  271. SetAnimation(xtpTaskPanelAnimationYes);
  272. m_nLockRedraw = 0;
  273. m_nOLEDropMode = 0;
  274. m_bAcceptFocus = TRUE;
  275. m_bDrawFocusRect = FALSE;
  276. m_pImageManager = new CXTPImageManager();
  277. m_itemLayout = xtpTaskItemLayoutDefault;
  278. m_hotTrackStyle = xtpTaskPanelHighlightDefault;
  279. m_panelBehaviour = xtpTaskPanelBehaviourExplorer;
  280. m_pActiveGroup = NULL;
  281. m_bSelectItemOnFocus = FALSE;
  282. m_bSingleSelection = FALSE;
  283. m_nAllowDrag = xtpTaskItemAllowDragNone;
  284. m_bAllowDrop = TRUE;
  285. m_ptPressed = CPoint(0, 0);
  286. m_pItemDragging = m_pItemDragOver = NULL;
  287. OleInitialize(NULL);
  288. m_pDropTarget = new CPanelDropTarget();
  289. m_pScrollButton[TRUE] = new CXTPTaskPanelScrollButton(TRUE);
  290. m_pScrollButton[FALSE] = new CXTPTaskPanelScrollButton(FALSE);
  291. m_bTimerGroupHover = FALSE;
  292. m_pToolTipContext = new CXTPToolTipContext;
  293. m_bMultiColumn = FALSE;
  294. m_nColumnWidth = 100;
  295. m_nGroupMinClientHeight = 0;
  296. m_bInUpdateScrollBar = FALSE;
  297. m_bTabItems = FALSE;
  298. m_pAnimation = new CXTPTaskPanelAnimation(this);
  299. m_pMarkupContext = NULL;
  300. EnableAutomation();
  301. }
  302. BOOL CXTPTaskPanel::RegisterWindowClass(HINSTANCE hInstance /*= NULL*/)
  303. {
  304. return XTPDrawHelpers()->RegisterWndClass(hInstance, _T("XTPTaskPanel"), CS_DBLCLKS);
  305. }
  306. CXTPTaskPanel::~CXTPTaskPanel()
  307. {
  308. CMDTARGET_RELEASE(m_pItemHot);
  309. CMDTARGET_RELEASE(m_pItemFocused);
  310. CMDTARGET_RELEASE(m_pActiveGroup);
  311. if (m_pGroups)
  312. {
  313. m_pGroups->Clear(FALSE);
  314. CMDTARGET_RELEASE(m_pGroups);
  315. }
  316. CMDTARGET_RELEASE(m_pImageManager);
  317. CMDTARGET_RELEASE(m_pToolTipContext);
  318. delete m_pPaintManager;
  319. delete m_pDropTarget;
  320. delete m_pScrollButton[TRUE];
  321. delete m_pScrollButton[FALSE];
  322. delete m_pAnimation;
  323. XTPMarkupReleaseContext(m_pMarkupContext);
  324. OleUninitialize();
  325. }
  326. void CXTPTaskPanel::EnableAnimation(BOOL bEnable)
  327. {
  328. m_pAnimation->m_bAnimation = bEnable;
  329. Redraw();
  330. }
  331. void CXTPTaskPanel::AllowDrag(long nAllowDrag /* = xtpTaskItemAllowDragDefault */)
  332. {
  333. m_nAllowDrag = nAllowDrag;
  334. }
  335. void CXTPTaskPanel::SetImageList(CImageList* pImageList, CSize szItemIcon)
  336. {
  337. if (pImageList)
  338. {
  339. m_pImageManager->SetIcons(*pImageList, 0, 0, 0, xtpImageNormal);
  340. }
  341. m_szItemIcon = szItemIcon;
  342. }
  343. void CXTPTaskPanel::SetGroupImageList(CImageList* pImageList, CSize szGroupIcon /* = CSize */)
  344. {
  345. if (pImageList)
  346. {
  347. m_pImageManager->SetIcons(*pImageList, 0, 0, 0, xtpImageNormal);
  348. }
  349. m_szGroupIcon = szGroupIcon;
  350. }
  351. CXTPImageManager* CXTPTaskPanel::GetImageManager() const
  352. {
  353. return m_pImageManager ? m_pImageManager : XTPImageManager();
  354. }
  355. void CXTPTaskPanel::SetImageManager(CXTPImageManager* pImageManager)
  356. {
  357. if (m_pImageManager)
  358. m_pImageManager->InternalRelease();
  359. m_pImageManager = pImageManager;
  360. Reposition();
  361. }
  362. void CXTPTaskPanel::SetHotItem(CXTPTaskPanelItem* pItem)
  363. {
  364. if (m_pItemHot == pItem)
  365. return;
  366. CXTPTaskPanelItem* pItemHot = m_pItemHot;
  367. m_pItemHot = pItem;
  368. if (pItemHot)
  369. {
  370. pItemHot->RedrawPanel(TRUE);
  371. pItemHot->InternalRelease();
  372. }
  373. if (m_pItemHot)
  374. {
  375. m_pItemHot->RedrawPanel(FALSE);
  376. m_pItemHot->InternalAddRef();
  377. }
  378. if (m_pItemHot)
  379. {
  380. TRACKMOUSEEVENT tme =
  381. {
  382. sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd
  383. };
  384. _TrackMouseEvent(&tme);
  385. }
  386. NotifyOwner(XTP_TPN_HOTITEMCHANGED, 0);
  387. }
  388. void CXTPTaskPanel::EnsureVisibleRect(const CRect& rc)
  389. {
  390. CXTPClientRect rcClient(this);
  391. if (rc.bottom > rcClient.bottom + GetScrollOffset())
  392. {
  393. OnSrollChanged(min(rc.top, rc.bottom - rcClient.Height()));
  394. }
  395. else if (rc.top < GetScrollOffset())
  396. {
  397. OnSrollChanged(rc.top);
  398. }
  399. }
  400. void CXTPTaskPanel::EnsureVisible(CXTPTaskPanelItem* pItem)
  401. {
  402. if (!pItem || !pItem->IsVisible())
  403. return;
  404. CXTPTaskPanelGroup* pGroup = pItem->GetItemGroup();
  405. if (!pGroup)
  406. return;
  407. if (pItem->IsGroup())
  408. {
  409. CRect rc = pGroup->GetCaptionRect();
  410. EnsureVisibleRect(rc);
  411. }
  412. else
  413. {
  414. if (!pGroup->IsExpanded())
  415. pGroup->SetExpanded(TRUE);
  416. CRect rc = pGroup->GetTargetClientRect();
  417. if (IsExplorerBehaviour())
  418. {
  419. CRect rcItem(((CXTPTaskPanelGroupItem*)pItem)->GetItemRect());
  420. rcItem.OffsetRect(0, rc.top);
  421. EnsureVisibleRect(rcItem);
  422. }
  423. else
  424. {
  425. rc.top -= pGroup->GetTargetCaptionRect().Height();
  426. EnsureVisibleRect(rc);
  427. pGroup->EnsureVisible((CXTPTaskPanelGroupItem*)pItem);
  428. }
  429. }
  430. }
  431. void CXTPTaskPanel::GrabFocus()
  432. {
  433. if (m_bAcceptFocus && ::GetFocus() != m_hWnd && m_hWnd)
  434. {
  435. m_bGrabbingFocus = TRUE;
  436. SetFocus();
  437. m_bGrabbingFocus = FALSE;
  438. }
  439. }
  440. void CXTPTaskPanel::SetFocusedItem(CXTPTaskPanelItem* pItem, BOOL bDrawFocusRect, BOOL bSetFocus)
  441. {
  442. if (bDrawFocusRect)
  443. m_bDrawFocusRect = m_bAcceptFocus;
  444. if (bSetFocus) GrabFocus();
  445. if (m_pItemFocused == pItem)
  446. return;
  447. if (m_hWnd) EnsureVisible(pItem);
  448. CXTPTaskPanelItem* pItemFocused = m_pItemFocused;
  449. m_pItemFocused = pItem;
  450. if (pItemFocused)
  451. {
  452. pItemFocused->RedrawPanel(FALSE);
  453. pItemFocused->InternalRelease();
  454. }
  455. if (m_pItemFocused)
  456. {
  457. m_pItemFocused->RedrawPanel(FALSE);
  458. m_pItemFocused->InternalAddRef();
  459. }
  460. if (m_bSelectItemOnFocus && IsItemLink(pItem) && !m_bSingleSelection)
  461. {
  462. pItem->GetItemGroup()->SetSelectedItem(((CXTPTaskPanelGroupItem*)pItem));
  463. }
  464. if (!GetSafeHwnd())
  465. return;
  466. NotifyOwner(XTP_TPN_FOCUSEDITEMCHANGED, 0);
  467. if (m_pItemFocused)
  468. {
  469. AccessibleNotifyWinEvent(EVENT_OBJECT_FOCUS, m_hWnd, OBJID_CLIENT, GetAccessibleIndex(m_pItemFocused));
  470. }
  471. if (bSetFocus && m_pItemFocused && m_pItemFocused->GetType() == xtpTaskItemTypeControl)
  472. {
  473. ::SetFocus(((CXTPTaskPanelGroupItem*)m_pItemFocused)->GetControlHandle());
  474. }
  475. }
  476. int CXTPTaskPanel::GetGroupCount() const
  477. {
  478. return m_pGroups->GetCount();
  479. }
  480. BOOL CXTPTaskPanel::IsDirty() const
  481. {
  482. for (int i = 0; i < GetGroupCount(); i++)
  483. {
  484. if (GetAt(i)->IsDirty())
  485. return TRUE;
  486. }
  487. return FALSE;
  488. }
  489. void CXTPTaskPanel::SetMargins(long nLeft, long nTop, long nRight, long nBottom, long nMiddle)
  490. {
  491. m_rcMargins.SetRect(nLeft, nTop, nRight, nBottom);
  492. m_nGroupSpacing = nMiddle;
  493. Reposition();
  494. }
  495. BOOL CXTPTaskPanel::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  496. {
  497. if (!CreateEx(0, _T("XTPTaskPanel"), NULL, dwStyle, rect, pParentWnd, nID))
  498. {
  499. return FALSE;
  500. }
  501. m_pDropTarget->Register(this);
  502. m_nAnimateTimer = 0;
  503. return TRUE;
  504. }
  505. CXTPTaskPanelGroup* CXTPTaskPanel::AddGroup(UINT nID, int nImage)
  506. {
  507. CXTPTaskPanelGroup* pGroup = (CXTPTaskPanelGroup*)m_pGroups->Add(new CXTPTaskPanelGroup(this), nID);
  508. pGroup->SetIconIndex(nImage);
  509. return pGroup;
  510. }
  511. CXTPTaskPanelGroup* CXTPTaskPanel::FindGroup(UINT nID) const
  512. {
  513. return (CXTPTaskPanelGroup*)m_pGroups->Find(nID);
  514. }
  515. CXTPTaskPanelGroupItem* CXTPTaskPanel::FindItem(UINT nID) const
  516. {
  517. for (int i = 0; i < GetGroupCount(); i++)
  518. {
  519. CXTPTaskPanelGroupItem* pItem = GetAt(i)->FindItem(nID);
  520. if (pItem)
  521. {
  522. return pItem;
  523. }
  524. }
  525. return NULL;
  526. }
  527. CXTPTaskPanelGroup* CXTPTaskPanel::GetAt(int nIndex) const
  528. {
  529. return (CXTPTaskPanelGroup*)m_pGroups->GetAt(nIndex);
  530. }
  531. void CXTPTaskPanel::SetTheme(XTPTaskPanelPaintTheme paintTheme)
  532. {
  533. if (m_pPaintManager)
  534. {
  535. delete m_pPaintManager;
  536. }
  537. if (paintTheme == xtpTaskPanelThemeOfficeXPPlain) m_pPaintManager = new CXTPTaskPanelOfficeXPThemePlain();
  538. else if (paintTheme == xtpTaskPanelThemeToolbox) m_pPaintManager = new CXTPTaskPanelToolboxTheme();
  539. else if (paintTheme == xtpTaskPanelThemeToolboxWhidbey) m_pPaintManager = new CXTPTaskPanelToolboxWhidbeyTheme();
  540. else if (paintTheme == xtpTaskPanelThemeListView) m_pPaintManager = new CXTPTaskPanelListViewTheme();
  541. else if (paintTheme == xtpTaskPanelThemeListViewOfficeXP) m_pPaintManager = new CXTPTaskPanelListViewOfficeXPTheme();
  542. else if (paintTheme == xtpTaskPanelThemeListViewOffice2003) m_pPaintManager = new CXTPTaskPanelListViewOffice2003Theme();
  543. else if (paintTheme == xtpTaskPanelThemeOffice2000Plain) m_pPaintManager = new CXTPTaskPanelPaintManagerPlain();
  544. else if (paintTheme == xtpTaskPanelThemeOffice2003Plain) m_pPaintManager = new CXTPTaskPanelOffice2003ThemePlain();
  545. else if (paintTheme == xtpTaskPanelThemeNativeWinXPPlain) m_pPaintManager = new CXTPTaskPanelExplorerThemePlain();
  546. else if (paintTheme == xtpTaskPanelThemeOffice2000) m_pPaintManager = new CXTPTaskPanelPaintManager();
  547. else if (paintTheme == xtpTaskPanelThemeOffice2003) m_pPaintManager = new CXTPTaskPanelOffice2003Theme();
  548. else if (paintTheme == xtpTaskPanelThemeShortcutBarOffice2003) m_pPaintManager = new CXTPTaskPanelShortcutBarOffice2003Theme();
  549. else if (paintTheme == xtpTaskPanelThemeShortcutBarOffice2007) m_pPaintManager = new CXTPTaskPanelShortcutBarOffice2007Theme();
  550. else m_pPaintManager = new CXTPTaskPanelExplorerTheme();
  551. m_paintTheme = paintTheme;
  552. m_pPaintManager->RefreshMetrics();
  553. Reposition();
  554. }
  555. void CXTPTaskPanel::SetCustomTheme(CXTPTaskPanelPaintManager* pPaintManager)
  556. {
  557. delete m_pPaintManager;
  558. m_pPaintManager = pPaintManager;
  559. if (m_pPaintManager)
  560. {
  561. m_pPaintManager->RefreshMetrics();
  562. }
  563. m_paintTheme = xtpTaskPanelThemeCustom;
  564. Reposition();
  565. }
  566. BEGIN_MESSAGE_MAP(CXTPTaskPanel, CWnd)
  567. //{{AFX_MSG_MAP(CXTPTaskPanel)
  568. ON_WM_ERASEBKGND()
  569. ON_WM_PAINT()
  570. ON_WM_SIZE()
  571. ON_WM_VSCROLL()
  572. ON_WM_MOUSEMOVE()
  573. ON_WM_SETCURSOR()
  574. ON_WM_LBUTTONUP()
  575. ON_WM_DESTROY()
  576. ON_WM_TIMER()
  577. ON_WM_SYSCOLORCHANGE()
  578. ON_WM_SETTINGCHANGE()
  579. ON_WM_RBUTTONDOWN()
  580. ON_WM_RBUTTONUP()
  581. ON_WM_SETFOCUS()
  582. ON_WM_KILLFOCUS()
  583. ON_WM_KEYDOWN()
  584. ON_WM_KEYUP()
  585. ON_WM_SYSKEYDOWN()
  586. ON_WM_SYSKEYUP()
  587. ON_WM_LBUTTONDOWN()
  588. ON_WM_LBUTTONDBLCLK()
  589. ON_WM_MOUSEWHEEL()
  590. ON_WM_GETDLGCODE()
  591. ON_WM_CAPTURECHANGED()
  592. //}}AFX_MSG_MAP
  593. ON_MESSAGE_VOID(WM_MOUSELEAVE, OnMouseLeave)
  594. ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
  595. ON_MESSAGE(WM_GETOBJECT, OnGetObject)
  596. END_MESSAGE_MAP()
  597. /////////////////////////////////////////////////////////////////////////////
  598. // CXTPTaskPanel message handlers
  599. BOOL CXTPTaskPanel::OnEraseBkgnd(CDC* /*pDC*/)
  600. {
  601. return TRUE;
  602. }
  603. void CXTPTaskPanel::OnPaint()
  604. {
  605. CPaintDC paintDC(this);
  606. m_pAnimation->OnPaint(paintDC);
  607. }
  608. LRESULT CXTPTaskPanel::OnPrintClient(WPARAM wParam, LPARAM /*lParam*/)
  609. {
  610. CDC* pDC = CDC::FromHandle((HDC)wParam);
  611. if (pDC)
  612. {
  613. OnDraw(pDC, CXTPClientRect(this));
  614. }
  615. return TRUE;
  616. }
  617. void CXTPTaskPanel::Redraw(LPCRECT lpRect, BOOL bAnimate)
  618. {
  619. if (m_nLockRedraw > 0)
  620. {
  621. return;
  622. }
  623. if (m_hWnd && IsWindowVisible())
  624. {
  625. m_pAnimation->RedrawRect(lpRect, bAnimate);
  626. }
  627. }
  628. void CXTPTaskPanel::OnDraw(CDC* pDC, CRect rcClipBox)
  629. {
  630. CPoint pt = pDC->GetViewportOrg();
  631. pDC->SetViewportOrg(pt.x, pt.y - GetScrollOffset());
  632. m_pPaintManager->FillTaskPanel(pDC, this);
  633. for (int i = 0; i < GetGroupCount(); i++)
  634. {
  635. CXTPTaskPanelGroup* pGroup = GetAt(i);
  636. if (!pGroup->IsVisible())
  637. continue;
  638. if (CRect().IntersectRect(pGroup->GetInvalidateRect(), rcClipBox))
  639. {
  640. pGroup->OnPaint(pDC);
  641. }
  642. }
  643. m_pPaintManager->DrawScrollButton(pDC, m_pScrollButton[TRUE]);
  644. m_pPaintManager->DrawScrollButton(pDC, m_pScrollButton[FALSE]);
  645. pDC->SetViewportOrg(pt);
  646. }
  647. void CXTPTaskPanel::SetLockRedraw(BOOL bLockRedraw)
  648. {
  649. m_nLockRedraw += bLockRedraw ? +1 : -1;
  650. ASSERT(m_nLockRedraw >= 0);
  651. if (m_nLockRedraw == 0)
  652. Reposition();
  653. }
  654. void CXTPTaskPanel::UpdateScrollButtons()
  655. {
  656. m_pScrollButton[TRUE]->bEnabled = m_pScrollButton[TRUE]->pGroupScroll ? m_pScrollButton[TRUE]->pGroupScroll->IsScrollButtonEnabled(TRUE) : FALSE;
  657. m_pScrollButton[FALSE]->bEnabled = m_pScrollButton[FALSE]->pGroupScroll ? m_pScrollButton[FALSE]->pGroupScroll->IsScrollButtonEnabled(FALSE) : FALSE;
  658. }
  659. void CXTPTaskPanel::OnClickScrollButton(CXTPTaskPanelScrollButton* pScrollButton)
  660. {
  661. if (!pScrollButton->bEnabled)
  662. return;
  663. pScrollButton->bPressed = TRUE;
  664. SetCapture();
  665. CXTPTaskPanelGroup* pActiveGroup = m_pActiveGroup;
  666. int nScrollOffset = (pScrollButton->bScrollUp ? -1 : +1) * pActiveGroup->GetItemsInRow();
  667. pActiveGroup->Scroll(nScrollOffset);
  668. Redraw();
  669. SetTimer(TID_SCROLLGROUP, 500, NULL);
  670. BOOL bQuick = FALSE;
  671. while (CWnd::GetCapture() == this && pScrollButton->bEnabled)
  672. {
  673. MSG msg;
  674. if (!GetMessageExt(msg))
  675. break;
  676. if (msg.message == WM_TIMER && msg.wParam == TID_SCROLLGROUP)
  677. {
  678. pActiveGroup->Scroll(nScrollOffset);
  679. Redraw();
  680. if (!bQuick)
  681. {
  682. KillTimer(TID_SCROLLGROUP);
  683. SetTimer(TID_SCROLLGROUP, 50, NULL);
  684. bQuick = TRUE;
  685. }
  686. }
  687. else if (msg.message == WM_LBUTTONUP) break;
  688. else if (msg.message == WM_MOUSEMOVE)
  689. {
  690. }
  691. else if (msg.message == WM_KEYDOWN)
  692. {
  693. if (msg.wParam == VK_ESCAPE)
  694. break;
  695. }
  696. else
  697. DispatchMessage(&msg);
  698. }
  699. pScrollButton->bPressed = FALSE;
  700. ReleaseCapture();
  701. Redraw();
  702. }
  703. void CXTPTaskPanel::RepositionScrollButtons()
  704. {
  705. m_pScrollButton[FALSE]->rcButton.SetRectEmpty();
  706. m_pScrollButton[TRUE]->rcButton.SetRectEmpty();
  707. m_pScrollButton[TRUE]->pGroupCaption = m_pScrollButton[FALSE]->pGroupCaption = NULL;
  708. if (IsExplorerBehaviour() || !m_pActiveGroup || !m_pActiveGroup->IsVisible())
  709. return;
  710. m_pScrollButton[TRUE]->pGroupScroll = m_pScrollButton[FALSE]->pGroupScroll = m_pActiveGroup;
  711. if (GetPaintManager()->m_bCaptionScrollButton)
  712. {
  713. CXTPClientRect rc(this);
  714. rc.bottom = max(rc.bottom, m_nClientHeight);
  715. CRect rcMargins = GetPaintManager()->GetControlMargins(this);
  716. m_pScrollButton[TRUE]->pGroupCaption = m_pActiveGroup;
  717. CRect rcCaption = m_pActiveGroup->GetCaptionRect();
  718. int nRight = rc.right - rcMargins.right - GetPaintManager()->GetGroupOuterMargins(m_pActiveGroup).right;
  719. int nHeight = rcCaption.Height();
  720. m_pScrollButton[TRUE]->rcButton.SetRect(nRight - nHeight, rcCaption.top, nRight, rcCaption.bottom);
  721. CXTPTaskPanelGroup* pGroupNext = GetNextVisibleGroup(m_pActiveGroup->GetIndex());
  722. if (pGroupNext == 0)
  723. {
  724. m_pScrollButton[FALSE]->rcButton.SetRect(nRight - nHeight, rc.bottom - rcMargins.bottom - nHeight,
  725. nRight, rc.bottom - rcMargins.bottom);
  726. }
  727. else
  728. {
  729. m_pScrollButton[FALSE]->pGroupCaption = pGroupNext;
  730. CRect rcNextCaption = pGroupNext->GetCaptionRect();
  731. int nButtonRight = rc.right - rcMargins.right - GetPaintManager()->GetGroupOuterMargins(pGroupNext).right;
  732. m_pScrollButton[FALSE]->rcButton.SetRect(nButtonRight - rcNextCaption.Height(), rcNextCaption.top, nButtonRight, rcNextCaption.bottom);
  733. }
  734. }
  735. else
  736. {
  737. CRect rc = m_pActiveGroup->GetClientRect();
  738. rc.DeflateRect(4, 4);
  739. int nHeight = 16;
  740. m_pScrollButton[TRUE]->rcButton.SetRect(rc.right - nHeight, rc.top, rc.right, rc.top + nHeight);
  741. m_pScrollButton[FALSE]->rcButton.SetRect(rc.right - nHeight, rc.bottom - nHeight, rc.right, rc.bottom);
  742. }
  743. UpdateScrollButtons();
  744. }
  745. void CXTPTaskPanel::Reposition(BOOL bRecalcOnly)
  746. {
  747. if (!GetSafeHwnd())
  748. return;
  749. if (m_nLockRedraw > 0)
  750. return;
  751. CXTPClientRect rc(this);
  752. CRect rcMargins = GetPaintManager()->GetControlMargins(this);
  753. int nGroupSpacing = GetPaintManager()->GetGroupSpacing(this);
  754. int nCurPos = rcMargins.top, nGroupCount = GetGroupCount(), i;
  755. rc.DeflateRect(rcMargins.left, 0, rcMargins.right, 0);
  756. {
  757. CClientDC dc(this);
  758. for (i = 0; i < nGroupCount; i++)
  759. {
  760. CXTPTaskPanelGroup* pGroup = GetAt(i);
  761. if (!pGroup->IsVisible())
  762. continue;
  763. pGroup->OnCalcClientHeight(&dc, rc);
  764. }
  765. }
  766. BOOL bFirstVisbleGroup = TRUE;
  767. for (i = 0; i < nGroupCount; i++)
  768. {
  769. CXTPTaskPanelGroup* pGroup = GetAt(i);
  770. if (!pGroup->IsVisible())
  771. {
  772. pGroup->OnAnimate(0);
  773. continue;
  774. }
  775. if (!bFirstVisbleGroup)
  776. {
  777. nCurPos += nGroupSpacing;
  778. }
  779. else bFirstVisbleGroup = FALSE;
  780. CRect rcGroup = pGroup->OnReposition(CRect(rc.left, nCurPos, rc.right, nCurPos), bRecalcOnly);
  781. nCurPos = rcGroup.bottom + GetPaintManager()->GetGroupOuterMargins(pGroup).bottom;
  782. }
  783. nCurPos += rcMargins.bottom;
  784. m_nClientHeight = nCurPos;
  785. RepositionScrollButtons();
  786. m_nAnimationStep = 10;
  787. BOOL bDirty = IsDirty();
  788. if (m_nAnimateTimer == 0 && bDirty)
  789. {
  790. m_nAnimateTimer = SetTimer(TID_REPOSITION, 30, NULL);
  791. }
  792. else if (m_nAnimateTimer != 0 && !bDirty)
  793. {
  794. KillTimer(m_nAnimateTimer);
  795. m_nAnimateTimer = 0;
  796. }
  797. UpdateScrollBar();
  798. if (!m_bAnimation)
  799. AnimateGroups(FALSE);
  800. Redraw();
  801. }
  802. void CXTPTaskPanel::OnClientHeightChanged()
  803. {
  804. }
  805. void CXTPTaskPanel::UpdateScrollBar()
  806. {
  807. if (m_bInUpdateScrollBar)
  808. return;
  809. m_bInUpdateScrollBar = TRUE;
  810. if (m_nClientHeight != m_nOldClientHeight)
  811. {
  812. m_nOldClientHeight = m_nClientHeight;
  813. OnClientHeightChanged();
  814. }
  815. CXTPClientRect rc(this);
  816. m_bScrollVisible = rc.Height() < m_nClientHeight;
  817. ShowScrollBar(SB_VERT, m_bScrollVisible);
  818. if (m_bScrollVisible)
  819. {
  820. SCROLLINFO  si ;
  821. si.cbSize = sizeof(SCROLLINFO) ;
  822. si.fMask = SIF_PAGE | SIF_RANGE ;
  823. GetScrollInfo(SB_VERT, &si, si.fMask);
  824. UINT nControlHeight = (UINT)rc.Height();
  825. if (si.nPage != nControlHeight || si.nMax != m_nClientHeight - 1 || si.nMin != 0)
  826. {
  827. si.nPage = nControlHeight ;
  828. si.nMax = m_nClientHeight - 1;
  829. si.nMin = 0 ;
  830. si.fMask = SIF_PAGE | SIF_RANGE ;
  831. SetScrollInfo(SB_VERT, &si) ;
  832. AnimateGroups(FALSE);
  833. }
  834. EnableScrollBarCtrl(SB_VERT, TRUE);
  835. }
  836. m_bInUpdateScrollBar = FALSE;
  837. if (::GetWindow(m_hWnd, GW_CHILD))
  838. {
  839. RedrawWindow(0, 0, RDW_INVALIDATE | RDW_ALLCHILDREN);
  840. }
  841. }
  842. void CXTPTaskPanel::OnSize(UINT nType, int cx, int cy)
  843. {
  844. Reposition(IsExplorerBehaviour());
  845. CWnd::OnSize(nType, cx, cy);
  846. }
  847. int CXTPTaskPanel::GetScrollOffset() const
  848. {
  849. if (!m_bScrollVisible)
  850. return 0;
  851. return GetScrollPos(SB_VERT);
  852. }
  853. int CXTPTaskPanel::GetClientHeight() const
  854. {
  855. return m_nClientHeight;
  856. }
  857. void CXTPTaskPanel::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  858. {
  859. if (pScrollBar != NULL)
  860. {
  861. CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  862. return;
  863. }
  864. // its horizontal scroll bar
  865. int nCurPos = GetScrollPos(SB_VERT);
  866. // decide what to do for each diffrent scroll event
  867. switch (nSBCode)
  868. {
  869. case SB_LEFT: nCurPos = 0; break;
  870. case SB_RIGHT: nCurPos = GetScrollLimit(SB_VERT); break;
  871. case SB_LINELEFT: nCurPos = max(nCurPos - 6, 0); break;
  872. case SB_LINERIGHT: nCurPos = min(nCurPos + 6, GetScrollLimit(SB_VERT)); break;
  873. case SB_PAGELEFT: nCurPos = max(nCurPos - CXTPClientRect(this).Height(), 0); break;
  874. case SB_PAGERIGHT: nCurPos = min(nCurPos + CXTPClientRect(this).Height(), GetScrollLimit(SB_VERT)); break;
  875. case SB_THUMBTRACK:
  876. case SB_THUMBPOSITION:  nCurPos = nPos; break;
  877. }
  878. OnSrollChanged(nCurPos);
  879. }
  880. void CXTPTaskPanel::OnSrollChanged(int nCurPos)
  881. {
  882. SetScrollPos(SB_VERT, nCurPos);
  883. AnimateGroups(FALSE);
  884. Redraw();
  885. if (::GetWindow(m_hWnd, GW_CHILD))
  886. {
  887. RedrawWindow(0, 0, RDW_INVALIDATE | RDW_ALLCHILDREN);
  888. }
  889. }
  890. CXTPTaskPanelScrollButton* CXTPTaskPanel::HitTestScrollButton(CPoint point) const
  891. {
  892. point.y += GetScrollOffset();
  893. for (int i = 0; i < 2; i++)
  894. {
  895. if (m_pScrollButton[i]->IsVisible() && m_pScrollButton[i]->rcButton.PtInRect(point))
  896. return m_pScrollButton[i];
  897. }
  898. return 0;
  899. }
  900. CXTPTaskPanelGroup* CXTPTaskPanel::HitTestGroup(CPoint point, BOOL* pbCaption) const
  901. {
  902. if (HitTestScrollButton(point))
  903. return 0;
  904. point.y += GetScrollOffset();
  905. int nGroupCount = GetGroupCount();
  906. for (int i = 0; i < nGroupCount; i++)
  907. {
  908. CXTPTaskPanelGroup* pGroup = GetAt(i);
  909. if (!pGroup->IsVisible())
  910. continue;
  911. if (pGroup->GetClientRect().PtInRect(point))
  912. {
  913. if (pbCaption) *pbCaption = FALSE;
  914. return pGroup;
  915. }
  916. if (pGroup->IsCaptionVisible() && pGroup->GetCaptionRect().PtInRect(point))
  917. {
  918. if (pbCaption) *pbCaption = TRUE;
  919. return pGroup;
  920. }
  921. }
  922. return NULL;
  923. }
  924. CXTPTaskPanelItem* CXTPTaskPanel::HitTestItem(CPoint point, BOOL bClientAvail) const
  925. {
  926. BOOL bCaption;
  927. CXTPTaskPanelGroup* pGroup = HitTestGroup(point, &bCaption);
  928. if (!pGroup)
  929. return NULL;
  930. if (bCaption)
  931. return pGroup;
  932. CXTPTaskPanelGroupItem* pItem = pGroup->HitTest(point);
  933. if (pItem)
  934. return pItem;
  935. if (bClientAvail)
  936. return pGroup;
  937. return NULL;
  938. }
  939. void CXTPTaskPanel::OnClick(CXTPTaskPanelGroupItem* pItem)
  940. {
  941. ASSERT(pItem);
  942. NotifyOwner(XTP_TPN_CLICK, (LPARAM)pItem);
  943. }
  944. void CXTPTaskPanel::OnRButtonDown(UINT nFlags, CPoint point)
  945. {
  946. CXTPTaskPanelItem* pItem = HitTestItem(point);
  947. if (pItem && pItem->IsAcceptFocus())
  948. {
  949. SetFocusedItem(pItem);
  950. }
  951. if (pItem)
  952. {
  953. NotifyOwner(XTP_TPN_RCLICK, (LPARAM)pItem);
  954. }
  955. CWnd::OnRButtonDown(nFlags, point);
  956. }
  957. void CXTPTaskPanel::OnRButtonUp(UINT nFlags, CPoint point)
  958. {
  959. CWnd::OnRButtonUp(nFlags, point);
  960. }
  961. void CXTPTaskPanel::OnLButtonDown(UINT nFlags, CPoint point)
  962. {
  963. CXTPTaskPanelItem* pItem = HitTestItem(point);
  964. if (pItem && pItem->IsAcceptFocus())
  965. {
  966. SetFocusedItem(pItem);
  967. }
  968. else
  969. {
  970. GrabFocus();
  971. }
  972. if (pItem && pItem->IsAcceptFocus())
  973. {
  974. SetCapture();
  975. m_pItemPressed = pItem;
  976. m_ptPressed = point;
  977. m_pItemPressed->RedrawPanel();
  978. }
  979. CXTPTaskPanelScrollButton* pScrollButton = HitTestScrollButton(point);
  980. if (pScrollButton)
  981. {
  982. OnClickScrollButton(pScrollButton);
  983. }
  984. CWnd::OnLButtonDown(nFlags, point);
  985. }
  986. void CXTPTaskPanel::OnLButtonDblClk(UINT nFlags, CPoint point)
  987. {
  988. OnLButtonDown(nFlags, point);
  989. if (m_pItemHot && m_pItemPressed == m_pItemHot && !m_pItemHot->IsGroup())
  990. {
  991. NotifyOwner(XTP_TPN_DBLCLICK, (LPARAM)(CXTPTaskPanelGroupItem*)m_pItemPressed);
  992. }
  993. }
  994. void CXTPTaskPanel::OnLButtonUp(UINT /*nFlags*/, CPoint point)
  995. {
  996. UNREFERENCED_PARAMETER(point);
  997. if (m_pItemPressed == NULL)
  998. {
  999. return;
  1000. }
  1001. CXTPTaskPanelItem* pItemPressed = m_pItemPressed;
  1002. m_pItemPressed = NULL;
  1003. ReleaseCapture();
  1004. pItemPressed->RedrawPanel();
  1005. if (pItemPressed == m_pItemHot)
  1006. {
  1007. if (IsItemGroup(pItemPressed))
  1008. {
  1009. CXTPTaskPanelGroup* pGroup = (CXTPTaskPanelGroup*)pItemPressed;
  1010. pGroup->SetExpanded(!pGroup->IsExpanded());
  1011. }
  1012. else
  1013. {
  1014. OnClick((CXTPTaskPanelGroupItem*)pItemPressed);
  1015. }
  1016. }
  1017. }
  1018. void CXTPTaskPanel::OnCaptureChanged(CWnd* pWnd)
  1019. {
  1020. if (m_pItemPressed)
  1021. {
  1022. m_pItemPressed = NULL;
  1023. Redraw();
  1024. }
  1025. CWnd::OnCaptureChanged(pWnd);
  1026. }
  1027. void CXTPTaskPanel::OnStartItemDrag(CXTPTaskPanelGroupItem* pItem)
  1028. {
  1029. BOOL bAllowDrag = pItem->IsAllowDrag();
  1030. if (bAllowDrag == xtpTaskItemAllowDragNone)
  1031. return;
  1032. ASSERT(pItem);
  1033. ReleaseCapture();
  1034. BOOL bAllowDragOutsideControl = (bAllowDrag & xtpTaskItemAllowDragMoveOutsideControl) ||
  1035. (bAllowDrag & xtpTaskItemAllowDragCopyOutsideControl);
  1036. if (NotifyOwner(XTP_TPN_STARTDRAG, (LPARAM)pItem) == XTP_ACTION_CANCEL)
  1037. return;
  1038. COleDataSource ds;
  1039. if (!pItem->PrepareDrag(ds, bAllowDragOutsideControl))
  1040. return;
  1041. m_pItemDragging = pItem;
  1042. DROPEFFECT dropEffectMask =
  1043. ((bAllowDrag & xtpTaskItemAllowDragCopyWithinGroup) ||
  1044. (bAllowDrag & xtpTaskItemAllowDragCopy) ? DROPEFFECT_COPY : 0) +
  1045. ((bAllowDrag & xtpTaskItemAllowDragMoveWithinGroup) ||
  1046. (bAllowDrag & xtpTaskItemAllowDragMove) ? DROPEFFECT_MOVE : 0);
  1047. DROPEFFECT dropEffect = ds.DoDragDrop(dropEffectMask);
  1048. if ((dropEffect == DROPEFFECT_MOVE) && (dropEffectMask & DROPEFFECT_MOVE))
  1049. {
  1050. m_pItemDragging->Remove();
  1051. }
  1052. m_pItemDragOver = m_pItemDragging = NULL;
  1053. }
  1054. DROPEFFECT CXTPTaskPanel::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
  1055. {
  1056. DROPEFFECT dropEffectMask = DROPEFFECT_COPY + DROPEFFECT_MOVE;
  1057. BOOL bCaption;
  1058. CXTPTaskPanelGroup* pGroup = HitTestGroup(point, &bCaption);
  1059. CXTPTaskPanelItem* pItemDragOverOld = m_pItemDragOver;
  1060. if (pGroup && pGroup->IsAllowDrop())
  1061. {
  1062. m_pItemDragOver = pGroup;
  1063. if (!bCaption)
  1064. {
  1065. CRect rcItem;
  1066. CXTPTaskPanelItem* pItem = pGroup->HitTest(point, &rcItem);
  1067. if (pItem && pItem->IsAllowDrop())
  1068. {
  1069. if (!GetPaintManager()->m_bInvertDragRect)
  1070. {
  1071. pItem = rcItem.CenterPoint().y > point.y ? pItem : pGroup->GetNextVisibleItem(pItem->GetIndex());
  1072. }
  1073. if (pItem)
  1074. {
  1075. m_pItemDragOver = pItem;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. else
  1081. {
  1082. m_pItemDragOver = NULL;
  1083. }
  1084. DROPEFFECT dropEffect = DROPEFFECT_NONE;
  1085. if (m_pItemDragOver && m_nOLEDropMode)
  1086. {
  1087. dropEffect = DROPEFFECT_MOVE;
  1088. if (dropEffect == DROPEFFECT_NONE)
  1089. m_pItemDragOver = 0;
  1090. }
  1091. else
  1092. {
  1093. if (!pDataObject || !pDataObject->IsDataAvailable(GetClipboardFormat()))
  1094. m_pItemDragOver = NULL;
  1095. if (pDataObject && !pDataObject->IsDataAvailable(CF_TEXT) && (m_pItemDragging == 0))
  1096. m_pItemDragOver = NULL;
  1097. if (m_pItemDragging)
  1098. {
  1099. BOOL bAllowDrag = m_pItemDragging->IsAllowDrag();
  1100. if (((bAllowDrag & xtpTaskItemAllowDragMoveWithinGroup) == 0) &&
  1101. ((bAllowDrag & xtpTaskItemAllowDragMoveWithinControl) == 0))
  1102. dropEffectMask &= ~DROPEFFECT_MOVE;
  1103. if (((bAllowDrag & xtpTaskItemAllowDragCopyWithinGroup) == 0) &&
  1104. ((bAllowDrag & xtpTaskItemAllowDragCopyWithinControl) == 0))
  1105. dropEffectMask &= ~DROPEFFECT_COPY;
  1106. if (m_pItemDragOver && m_pItemDragging->GetItemGroup() != pGroup)
  1107. {
  1108. if (bAllowDrag & xtpTaskItemAllowDragMoveWithinGroup)
  1109. dropEffectMask &= ~DROPEFFECT_MOVE;
  1110. if (bAllowDrag & xtpTaskItemAllowDragCopyWithinGroup)
  1111. dropEffectMask &= ~DROPEFFECT_COPY;
  1112. }
  1113. if (m_pItemDragOver)
  1114. {
  1115. if (((bAllowDrag & xtpTaskItemAllowDragMoveWithinControl) == 0) &&
  1116. ((bAllowDrag & xtpTaskItemAllowDragMoveWithinGroup) == 0))
  1117. dropEffectMask &= ~DROPEFFECT_MOVE;
  1118. if (((bAllowDrag & xtpTaskItemAllowDragCopyWithinControl) == 0) &&
  1119. ((bAllowDrag & xtpTaskItemAllowDragCopyWithinGroup) == 0))
  1120. dropEffectMask &= ~DROPEFFECT_COPY;
  1121. }
  1122. if (dropEffectMask == 0)
  1123. m_pItemDragOver = 0;
  1124. }
  1125. }
  1126. if (pItemDragOverOld != m_pItemDragOver)
  1127. {
  1128. Redraw();
  1129. }
  1130. BOOL bGroupHover = IsItemGroup(m_pItemDragOver) && !((CXTPTaskPanelGroup*)m_pItemDragOver)->IsExpanded();
  1131. if (bGroupHover && !m_bTimerGroupHover)
  1132. {
  1133. UINT nHoverTime = 500;
  1134. SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &nHoverTime, 0);
  1135. SetTimer(TID_GROUPHOVER, nHoverTime, NULL);
  1136. m_bTimerGroupHover = TRUE;
  1137. }
  1138. if (!bGroupHover && m_bTimerGroupHover)
  1139. {
  1140. KillTimer(TID_GROUPHOVER);
  1141. m_bTimerGroupHover = FALSE;
  1142. }
  1143. if (!m_pItemDragOver)
  1144. return DROPEFFECT_NONE;
  1145. if (dropEffect != DROPEFFECT_NONE)
  1146. return dropEffect;
  1147. if (dropEffectMask & DROPEFFECT_COPY)
  1148. {
  1149. if (((dwKeyState & MK_CONTROL) == MK_CONTROL) || ((dropEffectMask & DROPEFFECT_MOVE) == 0))
  1150. return DROPEFFECT_COPY;
  1151. }
  1152. return dropEffectMask & DROPEFFECT_MOVE ? DROPEFFECT_MOVE : DROPEFFECT_NONE;
  1153. }
  1154. BOOL CXTPTaskPanel::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)
  1155. {
  1156. point;
  1157. if (!m_pItemDragOver)
  1158. return FALSE;
  1159. CXTPTaskPanelItem* pItemDragOver = m_pItemDragOver;
  1160. m_pItemDragOver = NULL;
  1161. Redraw();
  1162. if (dropEffect != DROPEFFECT_COPY && dropEffect != DROPEFFECT_MOVE)
  1163. return FALSE;
  1164. if (m_nOLEDropMode && pDataObject)
  1165. {
  1166. return dropEffect != DROPEFFECT_NONE;
  1167. }
  1168. if (!pDataObject || !pDataObject->IsDataAvailable(GetClipboardFormat()))
  1169. return FALSE;
  1170. CXTPTaskPanelItem* pItemDrop = CXTPTaskPanelItem::CreateFromOleData(pDataObject);
  1171. if (!pItemDrop)
  1172. return FALSE;
  1173. if (IsItemGroup(pItemDragOver))
  1174. {
  1175. CXTPTaskPanelItems* pItems = ((CXTPTaskPanelGroup*)pItemDragOver)->GetItems();
  1176. pItems->InsertAt(pItems->GetCount(), pItemDrop);
  1177. }
  1178. else
  1179. {
  1180. CXTPTaskPanelItems* pItems = pItemDragOver->GetParentItems();
  1181. int nIndex = pItemDragOver->GetIndex();
  1182. if (GetPaintManager()->m_bInvertDragRect)
  1183. {
  1184. nIndex++;
  1185. if (m_pItemDragging && m_pItemDragging->GetParentItems() == pItems)
  1186. {
  1187. if (m_pItemDragging->GetIndex() >= nIndex)
  1188. nIndex--;
  1189. }
  1190. }
  1191. pItems->InsertAt(nIndex, pItemDrop);
  1192. }
  1193. if (pItemDrop->IsAcceptFocus())
  1194. {
  1195. SetFocusedItem(pItemDrop);
  1196. }
  1197. NotifyOwner(XTP_TPN_ITEMDROP, (LPARAM)pItemDrop);
  1198. return TRUE;
  1199. }
  1200. void CXTPTaskPanel::OnStartGroupDrag(CXTPTaskPanelItem* pItem)
  1201. {
  1202. if (!pItem->IsAllowDrag())
  1203. return;
  1204. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS));
  1205. m_pItemDragging = pItem;
  1206. Redraw();
  1207. while (CWnd::GetCapture() == this)
  1208. {
  1209. MSG msg;
  1210. if (!GetMessageExt(msg))
  1211. break;
  1212. if (msg.message == WM_LBUTTONUP)
  1213. break;
  1214. else if (msg.message == WM_MOUSEMOVE)
  1215. {
  1216. CPoint pt(msg.pt);
  1217. ScreenToClient(&pt);
  1218. BOOL bCaption;
  1219. CXTPTaskPanelGroup* pHTGroup = HitTestGroup(pt, &bCaption);
  1220. if (pHTGroup && bCaption && pHTGroup != pItem)
  1221. {
  1222. m_pGroups->Move(pItem, pHTGroup->GetIndex());
  1223. }
  1224. }
  1225. else if (msg.message == WM_KEYDOWN)
  1226. {
  1227. if (msg.wParam == VK_ESCAPE)
  1228. {
  1229. break;
  1230. }
  1231. }
  1232. else
  1233. DispatchMessage(&msg);
  1234. }
  1235. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  1236. m_pItemDragging = NULL;
  1237. ReleaseCapture();
  1238. }
  1239. void CXTPTaskPanel::CheckScrollButtonMouseOver(CPoint point)
  1240. {
  1241. CXTPTaskPanelScrollButton* pButtonHot = HitTestScrollButton(point);
  1242. for (int i = 0; i < 2; i++)
  1243. {
  1244. BOOL bHot = (pButtonHot == m_pScrollButton[i]);
  1245. if ((m_pScrollButton[i]->bHot && !bHot) || (!m_pScrollButton[i]->bHot && bHot))
  1246. {
  1247. m_pScrollButton[i]->bHot = bHot;
  1248. Redraw();
  1249. if (bHot)
  1250. {
  1251. TRACKMOUSEEVENT tme =
  1252. {
  1253. sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd
  1254. };
  1255. _TrackMouseEvent(&tme);
  1256. }
  1257. }
  1258. }
  1259. }
  1260. void CXTPTaskPanel::OnMouseMove(UINT nFlags, CPoint point)
  1261. {
  1262. CWnd::OnMouseMove(nFlags, point);
  1263. #if !defined(_XTP_ACTIVEX) && defined(_XTP_INCLUDE_COMMANDBARS)
  1264. if (XTPMouseManager()->IsTrackedLock(NULL) || XTPMouseManager()->IsMouseLocked())
  1265. return;
  1266. #endif
  1267. CXTPTaskPanelItem* pItem = HitTestItem(point);
  1268. BOOL bAccept = pItem && pItem->IsAcceptFocus() && CXTPDrawHelpers::IsTopParentActive(m_hWnd) &&
  1269. ((m_pItemPressed == NULL) || (m_pItemPressed == pItem));
  1270. SetHotItem(bAccept ? pItem : NULL);
  1271. if (m_pItemPressed && (abs(m_ptPressed.x - point.x) + abs(m_ptPressed.y - point.y) > 4))
  1272. {
  1273. if (IsItemGroup(m_pItemPressed)) OnStartGroupDrag(m_pItemPressed);
  1274. else OnStartItemDrag((CXTPTaskPanelGroupItem*)m_pItemPressed);
  1275. }
  1276. CheckScrollButtonMouseOver(point);
  1277. }
  1278. void CXTPTaskPanel::OnMouseLeave()
  1279. {
  1280. SetHotItem(NULL);
  1281. CheckScrollButtonMouseOver(CPoint(-1, -1));
  1282. }
  1283. BOOL CXTPTaskPanel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  1284. {
  1285. if (m_pItemHot)
  1286. {
  1287. ::SetCursor(m_hHandCursor);
  1288. return TRUE;
  1289. }
  1290. return CWnd::OnSetCursor(pWnd, nHitTest, message);
  1291. }
  1292. void CXTPTaskPanel::OnDestroy()
  1293. {
  1294. m_pAnimation->OnDestroy();
  1295. CWnd::OnDestroy();
  1296. }
  1297. BOOL CXTPTaskPanel::AnimateGroups(BOOL bCheckDirty)
  1298. {
  1299. BOOL bDirty = FALSE;
  1300. for (int i = 0; i < GetGroupCount(); i++)
  1301. {
  1302. CXTPTaskPanelGroup* pGroup = GetAt(i);
  1303. if (!bCheckDirty || pGroup->IsDirty())
  1304. {
  1305. bDirty = TRUE;
  1306. pGroup->OnAnimate(m_nAnimationStep);
  1307. }
  1308. }
  1309. RepositionScrollButtons();
  1310. if (DYNAMIC_DOWNCAST(CXTPTaskPanelEditItem, GetFocus()) != 0)
  1311. GrabFocus();
  1312. return bDirty;
  1313. }
  1314. void CXTPTaskPanel::OnTimer(UINT_PTR nIDEvent)
  1315. {
  1316. switch (nIDEvent)
  1317. {
  1318. case TID_REPOSITION:
  1319. {
  1320. BOOL bDirty = AnimateGroups();
  1321. Redraw();
  1322. m_nAnimationStep--;
  1323. if (!bDirty)
  1324. {
  1325. KillTimer(m_nAnimateTimer);
  1326. m_nAnimateTimer = 0;
  1327. }
  1328. }
  1329. break;
  1330. case TID_GROUPHOVER:
  1331. if (IsItemGroup(m_pItemDragOver) && m_bTimerGroupHover)
  1332. {
  1333. ((CXTPTaskPanelGroup*)m_pItemDragOver)->SetExpanded(TRUE);
  1334. }
  1335. m_bTimerGroupHover = FALSE;
  1336. KillTimer(TID_GROUPHOVER);
  1337. break;
  1338. case XTP_TID_ANIMATION:
  1339. m_pAnimation->OnAnimate();
  1340. return;
  1341. }
  1342. CWnd::OnTimer(nIDEvent);
  1343. }
  1344. void CXTPTaskPanel::OnSysColorChange()
  1345. {
  1346. m_pPaintManager->RefreshMetrics();
  1347. Reposition();
  1348. CWnd::OnSysColorChange();
  1349. }
  1350. #ifndef SPI_GETMENUANIMATION
  1351. #define SPI_GETMENUANIMATION 0x1002
  1352. #endif
  1353. void CXTPTaskPanel::SetAnimation(XTPTaskPanelAnimation panelAnimation)
  1354. {
  1355. m_eAnimation = panelAnimation;
  1356. if (m_eAnimation == xtpTaskPanelAnimationYes) m_bAnimation = TRUE;
  1357. else if (m_eAnimation == xtpTaskPanelAnimationNo) m_bAnimation = FALSE;
  1358. else
  1359. {
  1360. m_bAnimation = FALSE;
  1361. ::SystemParametersInfo(SPI_GETMENUANIMATION, 0, &m_bAnimation, 0);
  1362. }
  1363. }
  1364. void CXTPTaskPanel::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
  1365. {
  1366. CWnd::OnSettingChange(uFlags, lpszSection);
  1367. if (m_eAnimation == xtpTaskPanelAnimationSystem)
  1368. SetAnimation(xtpTaskPanelAnimationSystem);
  1369. m_pPaintManager->RefreshMetrics();
  1370. Reposition();
  1371. }
  1372. CXTPTaskPanelItem* CXTPTaskPanel::GetFocusedItem() const
  1373. {
  1374. return m_pItemFocused;
  1375. }
  1376. BOOL CXTPTaskPanel::IsDrawFocusRect() const
  1377. {
  1378. return m_bDrawFocusRect && (::GetFocus() == m_hWnd);
  1379. }
  1380. HWND CXTPTaskPanel::GetNextControl(BOOL bForward) const
  1381. {
  1382. HWND hWnd = m_hWnd;
  1383. HWND hWndParent = ::GetParent(hWnd);
  1384. if (!hWnd || !hWndParent)
  1385. {
  1386. ASSERT(FALSE);
  1387. return 0;
  1388. }
  1389. if ((GetWindowLong(hWndParent, GWL_EXSTYLE) & WS_EX_CONTROLPARENT) &&
  1390. (GetWindowLong(hWndParent, GWL_STYLE) & WS_CHILD))
  1391. {
  1392. hWndParent = ::GetParent(hWndParent);
  1393. }
  1394. HWND hwndNextItem = ::GetNextDlgTabItem(hWndParent, hWnd, bForward);
  1395. if (hwndNextItem == hWnd)
  1396. return 0;
  1397. return hwndNextItem;
  1398. }
  1399. void CXTPTaskPanel::CheckOldFocus(CWnd* pOldWnd)
  1400. {
  1401. if (!m_bGrabbingFocus && pOldWnd)
  1402. {
  1403. BOOL bShiftPressed = GetKeyState(VK_SHIFT) < 0;
  1404. if (pOldWnd->m_hWnd == GetNextControl(!bShiftPressed))
  1405. {
  1406. CXTPTaskPanelItem* pItem = GetNextItem(0, bShiftPressed ? -1 : 1, !m_bTabItems);
  1407. if (pItem)
  1408. {
  1409. SetFocusedItem(pItem, TRUE);
  1410. }
  1411. }
  1412. }
  1413. }
  1414. void CXTPTaskPanel::OnSetFocus(CWnd* pOldWnd)
  1415. {
  1416. CWnd::OnSetFocus(pOldWnd);
  1417. CheckOldFocus(pOldWnd);
  1418. Redraw();
  1419. }
  1420. void CXTPTaskPanel::OnKillFocus(CWnd* pNewWnd)
  1421. {
  1422. CWnd::OnKillFocus(pNewWnd);
  1423. m_bDrawFocusRect = FALSE;
  1424. Redraw();
  1425. }
  1426. CXTPTaskPanelGroup* CXTPTaskPanel::GetNextVisibleGroup(int nIndex, int nDirection) const
  1427. {
  1428. return GetAt(m_pGroups->GetNextVisibleIndex(nIndex, nDirection));
  1429. }
  1430. CXTPTaskPanelItem* CXTPTaskPanel::GetNextItem(CXTPTaskPanelItem* pItem, int nDirection, BOOL bTab, BOOL bSkipRowItems) const
  1431. {
  1432. if (GetGroupCount() == 0)
  1433. return NULL;
  1434. CXTPTaskPanelGroup* pGroupCheck = NULL;
  1435. do
  1436. {
  1437. if (nDirection > 0)
  1438. {
  1439. if (pItem)
  1440. {
  1441. pGroupCheck = pItem->GetItemGroup();
  1442. if (IsItemGroup(pItem))
  1443. pItem = pGroupCheck->GetItems()->GetFirstVisibleItem();
  1444. else
  1445. {
  1446. if (bTab) pItem = NULL; else pItem = pGroupCheck->GetNextVisibleItem(pItem->GetIndex(), bSkipRowItems ? pGroupCheck->GetItemsInRow() : 1);
  1447. }
  1448. }
  1449. if (!pItem)
  1450. {
  1451. pItem = GetNextVisibleGroup(pGroupCheck ? pGroupCheck->GetIndex() : -1);
  1452. }
  1453. }
  1454. else
  1455. {
  1456. if (!pItem && !pGroupCheck)
  1457. {
  1458. pGroupCheck = GetNextVisibleGroup(GetGroupCount(), - 1);
  1459. pItem = pGroupCheck ? pGroupCheck->GetItems()->GetLastVisibleItem() : 0;
  1460. }
  1461. else if (IsItemGroup(pItem))
  1462. {
  1463. pGroupCheck = GetNextVisibleGroup(pItem->GetIndex(), - 1);
  1464. pItem = pGroupCheck ? pGroupCheck->GetItems()->GetLastVisibleItem() : NULL;
  1465. }
  1466. else if (pItem)
  1467. {
  1468. pGroupCheck = pItem->GetItemGroup();
  1469. if (bTab) pItem = NULL; else pItem = pGroupCheck->GetNextVisibleItem(pItem->GetIndex(), -(bSkipRowItems ? pGroupCheck->GetItemsInRow() : 1));
  1470. }
  1471. if (!pItem) pItem = pGroupCheck;
  1472. }
  1473. if (!(IsItemLink(pItem) && pGroupCheck && !pGroupCheck->IsExpanded()))
  1474. if (pItem && pItem->IsAcceptFocus())
  1475. return pItem;
  1476. }
  1477. while (pItem);
  1478. return NULL;
  1479. }
  1480. void CXTPTaskPanel::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  1481. {
  1482. CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
  1483. CXTPDrawHelpers::KeyToLayout(this, nChar);
  1484. switch (nChar)
  1485. {
  1486. case VK_HOME:
  1487. case VK_END:
  1488. if (m_pItemFocused)
  1489. {
  1490. CXTPTaskPanelItems* pItems = m_pItemFocused->GetParentItems();
  1491. CXTPTaskPanelItem* pItem = nChar == VK_HOME ? pItems->GetFirstVisibleItem() : pItems->GetLastVisibleItem();
  1492. if (pItem && pItem->IsAcceptFocus()) SetFocusedItem(pItem, TRUE);
  1493. }
  1494. break;
  1495. case VK_DOWN:
  1496. case VK_UP:
  1497. case VK_RIGHT:
  1498. case VK_LEFT:
  1499. {
  1500. BOOL bSkipRowItems = (nChar == VK_DOWN || nChar == VK_UP);
  1501. int nDirection = (nChar == VK_DOWN || nChar == VK_RIGHT ? +1 : -1);
  1502. if (!IsExplorerBehaviour() && GetKeyState(VK_CONTROL) < 0 && m_pActiveGroup)
  1503. {
  1504. CXTPTaskPanelGroup* pActiveGroup = GetNextVisibleGroup(m_pActiveGroup->GetIndex(), nDirection);
  1505. if (pActiveGroup && pActiveGroup->IsAcceptFocus())
  1506. {
  1507. pActiveGroup->SetExpanded(TRUE);
  1508. SetFocusedItem(pActiveGroup);
  1509. }
  1510. return;
  1511. }
  1512. CXTPTaskPanelItem* pItem = GetNextItem(m_pItemFocused, nDirection, FALSE, bSkipRowItems);
  1513. if (pItem) SetFocusedItem(pItem, TRUE);
  1514. }
  1515. break;
  1516. case VK_TAB:
  1517. {
  1518. BOOL bShiftPressed = GetKeyState(VK_SHIFT) < 0;
  1519. CXTPTaskPanelItem* pItem = GetNextItem(m_pItemFocused, bShiftPressed ? -1 : +1, !m_bTabItems);
  1520. if (pItem)
  1521. {
  1522. SetFocusedItem(pItem, TRUE);
  1523. }
  1524. else
  1525. {
  1526. HWND hWnd = GetNextControl(bShiftPressed);
  1527. if (hWnd)
  1528. {
  1529. ::SetFocus(hWnd);
  1530. }
  1531. }
  1532. }
  1533. break;
  1534. case VK_RETURN:
  1535. case VK_SPACE:
  1536. if (m_pItemFocused && m_pItemFocused->IsAcceptFocus())
  1537. {
  1538. if (IsItemGroup(m_pItemFocused))
  1539. {
  1540. ((CXTPTaskPanelGroup*)m_pItemFocused)->SetExpanded(!((CXTPTaskPanelGroup*)m_pItemFocused)->IsExpanded());
  1541. }
  1542. else if (IsItemLink(m_pItemFocused))
  1543. {
  1544. OnClick((CXTPTaskPanelGroupItem*)m_pItemFocused);
  1545. }
  1546. }
  1547. break;
  1548. }
  1549. }
  1550. void CXTPTaskPanel::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  1551. {
  1552. CWnd::OnKeyUp(nChar, nRepCnt, nFlags);
  1553. }
  1554. void CXTPTaskPanel::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  1555. {
  1556. CWnd::OnSysKeyUp(nChar, nRepCnt, nFlags);
  1557. }
  1558. void CXTPTaskPanel::OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
  1559. {
  1560. CWnd::OnSysKeyUp(nChar, nRepCnt, nFlags);
  1561. }
  1562. BOOL CXTPTaskPanel::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  1563. {
  1564. if (m_bScrollVisible)
  1565. {
  1566. // its horizontal scroll bar
  1567. int nCurPos = GetScrollPos(SB_VERT);
  1568. if (zDelta > 0) nCurPos = max(nCurPos - 10, 0);
  1569. else nCurPos = min(nCurPos + 10, GetScrollLimit(SB_VERT));
  1570. OnSrollChanged(nCurPos);
  1571. Redraw();
  1572. }
  1573. else if (GetBehaviour() != xtpTaskPanelBehaviourExplorer && m_pActiveGroup)
  1574. {
  1575. BOOL bScrollButtonUp = zDelta > 0;
  1576. for (int i = 0; i < 3; i++)
  1577. {
  1578. if (!m_pActiveGroup->IsScrollButtonEnabled(bScrollButtonUp))
  1579. break;
  1580. int nScrollOffset = (bScrollButtonUp ? -1 : +1) * m_pActiveGroup->GetItemsInRow();
  1581. m_pActiveGroup->Scroll(nScrollOffset);
  1582. }
  1583. Redraw();
  1584. }
  1585. return CWnd::OnMouseWheel(nFlags, zDelta, pt);
  1586. }
  1587. BOOL CXTPTaskPanel::PreCreateWindow(CREATESTRUCT& cs)
  1588. {
  1589. if (!CWnd::PreCreateWindow(cs))
  1590. return FALSE;
  1591. //
  1592. // PreCreateWindow is called when a control is dynamically
  1593. // created. We want to set m_bPreSubclassWindow to FALSE
  1594. // here so the control is initialized from CWnd::Create and
  1595. // not CWnd::PreSubclassWindow.
  1596. //
  1597. m_bPreSubclassWindow = FALSE;
  1598. return TRUE;
  1599. }
  1600. void CXTPTaskPanel::PreSubclassWindow()
  1601. {
  1602. if (m_bPreSubclassWindow)
  1603. {
  1604. m_pDropTarget->Register(this);
  1605. }
  1606. }
  1607. INT_PTR CXTPTaskPanel::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
  1608. {
  1609. ASSERT_VALID(this);
  1610. ASSERT(::IsWindow(m_hWnd));
  1611. // check child windows first by calling CControlBar
  1612. INT_PTR nHit = CWnd::OnToolHitTest(point, pTI);
  1613. if (nHit != -1)
  1614. return nHit;
  1615. #if !defined(_XTP_ACTIVEX) && defined(_XTP_INCLUDE_COMMANDBARS)
  1616. if (XTPMouseManager()->IsTrackedLock(NULL) || XTPMouseManager()->IsMouseLocked())
  1617. return -1;
  1618. #endif
  1619. if (m_pItemHot)
  1620. {
  1621. nHit = m_pItemHot->GetID();
  1622. CString strTip = m_pItemHot->GetTooltip();
  1623. if (strTip.GetLength() == 0)
  1624. return -1;
  1625. CXTPToolTipContext::FillInToolInfo(pTI, m_hWnd, m_pItemHot->GetHitTestRect(),
  1626. nHit, strTip, m_pItemHot->GetCaption(), strTip, GetImageManager());
  1627. return nHit;
  1628. }
  1629. return -1;
  1630. }
  1631. UINT CXTPTaskPanel::OnGetDlgCode()
  1632. {
  1633. return DLGC_WANTARROWS | DLGC_WANTTAB | DLGC_WANTCHARS;
  1634. }
  1635. LRESULT CXTPTaskPanel::NotifyOwner(WPARAM wParam, LPARAM lParam)
  1636. {
  1637. if (!m_hWnd)
  1638. return 0;
  1639. return GetOwner()->SendMessage(XTPWM_TASKPANEL_NOTIFY, wParam, lParam);
  1640. }
  1641. void CXTPTaskPanel::ExpandGroup(CXTPTaskPanelGroup* pGroup, BOOL bExpanded)
  1642. {
  1643. ASSERT(pGroup);
  1644. if (!pGroup)
  1645. return;
  1646. if (IsExplorerBehaviour())
  1647. {
  1648. XTP_TPNGROUPEXPANDING NMGROUPEXPANDING;
  1649. NMGROUPEXPANDING.bExpanding = bExpanded;
  1650. NMGROUPEXPANDING.pGroup = pGroup;
  1651. if (NotifyOwner(XTP_TPN_GROUPEXPANDING, (LPARAM)&NMGROUPEXPANDING) == XTP_ACTION_CANCEL)
  1652. return;
  1653. pGroup->m_bExpanded = bExpanded;
  1654. pGroup->m_bExpanding = TRUE;
  1655. }
  1656. else if (bExpanded)
  1657. {
  1658. XTP_TPNGROUPEXPANDING NMGROUPEXPANDING;
  1659. NMGROUPEXPANDING.bExpanding = TRUE;
  1660. NMGROUPEXPANDING.pGroup = pGroup;
  1661. if (NotifyOwner(XTP_TPN_GROUPEXPANDING, (LPARAM)&NMGROUPEXPANDING) == XTP_ACTION_CANCEL)
  1662. return;
  1663. if (m_pActiveGroup)
  1664. {
  1665. if (m_pActiveGroup->IsExpandable())
  1666. {
  1667. m_pActiveGroup->m_bExpanded = FALSE;
  1668. m_pActiveGroup->m_bExpanding = TRUE;
  1669. }
  1670. m_pActiveGroup->InternalRelease();
  1671. }
  1672. m_pActiveGroup = pGroup;
  1673. m_pActiveGroup->InternalAddRef();
  1674. m_pActiveGroup->m_bExpanding = TRUE;
  1675. m_pActiveGroup->m_bExpanded = TRUE;
  1676. }
  1677. Reposition();
  1678. }
  1679. BOOL CXTPTaskPanel::IsGroupExpanded(const CXTPTaskPanelGroup* pGroup) const
  1680. {
  1681. return IsExplorerBehaviour() ? pGroup->m_bExpanded :
  1682. (m_pActiveGroup == pGroup) || (pGroup->m_bExpanded && !pGroup->m_bExpandable);
  1683. }
  1684. XTPTaskPanelHotTrackStyle CXTPTaskPanel::GetHotTrackStyle() const
  1685. {
  1686. if (m_hotTrackStyle != xtpTaskPanelHighlightDefault)
  1687. return m_hotTrackStyle;
  1688. if (m_panelBehaviour == xtpTaskPanelBehaviourExplorer)
  1689. return xtpTaskPanelHighlightText;
  1690. if (m_panelBehaviour == xtpTaskPanelBehaviourToolbox)
  1691. return xtpTaskPanelHighlightItem;
  1692. return xtpTaskPanelHighlightImage;
  1693. }
  1694. void CXTPTaskPanel::SetHotTrackStyle(XTPTaskPanelHotTrackStyle hotTrackStyle)
  1695. {
  1696. m_hotTrackStyle = hotTrackStyle;
  1697. Reposition();
  1698. }
  1699. XTPTaskPanelItemLayout CXTPTaskPanel::GetItemLayout() const
  1700. {
  1701. if (m_itemLayout != xtpTaskItemLayoutDefault)
  1702. return m_itemLayout;
  1703. if (m_panelBehaviour == xtpTaskPanelBehaviourList)
  1704. return xtpTaskItemLayoutImagesWithTextBelow;
  1705. return xtpTaskItemLayoutImagesWithText;
  1706. }
  1707. void CXTPTaskPanel::SetItemLayout(XTPTaskPanelItemLayout itemLayout)
  1708. {
  1709. m_itemLayout = itemLayout;
  1710. Reposition();
  1711. }
  1712. void CXTPTaskPanel::SetBehaviour(XTPTaskPanelBehaviour panelBehaviour)
  1713. {
  1714. m_panelBehaviour = panelBehaviour;
  1715. Reposition();
  1716. }
  1717. XTPTaskPanelBehaviour CXTPTaskPanel::GetBehaviour() const
  1718. {
  1719. return m_panelBehaviour;
  1720. }
  1721. void CXTPTaskPanel::OnItemRemoved(CXTPTaskPanelItem* pItem)
  1722. {
  1723. ASSERT(pItem);
  1724. if (!pItem)
  1725. return;
  1726. if (m_pActiveGroup == pItem)
  1727. {
  1728. m_pActiveGroup->InternalRelease();
  1729. m_pActiveGroup = NULL;
  1730. }
  1731. if (m_pItemHot == pItem)
  1732. {
  1733. m_pItemHot->InternalRelease();
  1734. m_pItemHot = NULL;
  1735. }
  1736. if (m_pItemFocused == pItem)
  1737. {
  1738. m_pItemFocused->InternalRelease();
  1739. m_pItemFocused = NULL;
  1740. }
  1741. if (m_pScrollButton[TRUE]->pGroupCaption == pItem)
  1742. m_pScrollButton[TRUE]->pGroupCaption = NULL;
  1743. if (m_pScrollButton[TRUE]->pGroupScroll == pItem)
  1744. m_pScrollButton[TRUE]->pGroupScroll = NULL;
  1745. if (m_pScrollButton[FALSE]->pGroupCaption == pItem)
  1746. m_pScrollButton[FALSE]->pGroupCaption = NULL;
  1747. if (m_pScrollButton[FALSE]->pGroupScroll == pItem)
  1748. m_pScrollButton[FALSE]->pGroupScroll = NULL;
  1749. NotifyOwner(XTP_TPN_ITEMREMOVED, (LPARAM)pItem);
  1750. }
  1751. BOOL CXTPTaskPanel::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  1752. {
  1753. if (m_pToolTipContext)
  1754. {
  1755. m_pToolTipContext->FilterToolTipMessage(this, message, wParam, lParam);
  1756. }
  1757. return CWnd::OnWndMsg(message, wParam, lParam, pResult);
  1758. }
  1759. HWND CXTPTaskPanel::GetRootChild(HWND hWndTaskPanel, HWND hWnd)
  1760. {
  1761. HWND hwndParent = ::GetParent(hWnd);
  1762. while (hwndParent != hWndTaskPanel)
  1763. {
  1764. hWnd = hwndParent;
  1765. hwndParent = ::GetParent(hWnd);
  1766. if (hwndParent == NULL)
  1767. return NULL;
  1768. }
  1769. return hWnd;
  1770. }
  1771. CXTPTaskPanelGroupItem* CXTPTaskPanel::FindControlItem(HWND hWnd)
  1772. {
  1773. for (int i = 0; i < GetGroupCount(); i++)
  1774. {
  1775. CXTPTaskPanelGroup* pGroup = GetAt(i);
  1776. for (int j = 0; j < pGroup->GetItemCount(); j++)
  1777. {
  1778. if (pGroup->GetAt(j)->GetControlHandle() == hWnd)
  1779. return pGroup->GetAt(j);
  1780. }
  1781. }
  1782. return NULL;
  1783. }
  1784. BOOL CXTPTaskPanel::PreTranslateMessage(MSG* pMsg)
  1785. {
  1786. if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB && m_bTabItems)
  1787. {
  1788. HWND hWnd = ::GetFocus();
  1789. if (hWnd && hWnd != m_hWnd && ::IsChild(m_hWnd, hWnd))
  1790. {
  1791. HWND hWndDlg = GetRootChild(m_hWnd, hWnd);
  1792. if (!hWndDlg)
  1793. return CWnd::PreTranslateMessage(pMsg);
  1794. BOOL bShiftPressed = GetKeyState(VK_SHIFT) < 0;
  1795. HWND hWndFirst = ::GetNextDlgTabItem(hWndDlg, NULL, FALSE);
  1796. if (bShiftPressed) hWndFirst = ::GetNextDlgTabItem(hWndDlg, hWndFirst, TRUE);
  1797. HWND hWndNext = ::GetNextDlgTabItem(hWndDlg, hWnd, bShiftPressed);
  1798. if (hWndNext && hWndNext != hWnd && hWndNext != hWndDlg && hWndNext != hWndFirst)
  1799. {
  1800. ::SetFocus(hWndNext);
  1801. return TRUE;
  1802. }
  1803. CXTPTaskPanelGroupItem* pItemFocused = FindControlItem(hWndDlg);
  1804. if (pItemFocused)
  1805. {
  1806. CXTPTaskPanelItem* pItem = GetNextItem(pItemFocused, bShiftPressed ? -1 : +1, !m_bTabItems);
  1807. if (pItem)
  1808. {
  1809. SetFocusedItem(pItem, TRUE);
  1810. }
  1811. else
  1812. {
  1813. hWndNext = GetNextControl(bShiftPressed);
  1814. if (hWndNext)
  1815. {
  1816. ::SetFocus(hWndNext);
  1817. }
  1818. }
  1819. return TRUE;
  1820. }
  1821. }
  1822. }
  1823. return CWnd::PreTranslateMessage(pMsg);
  1824. }
  1825. CXTPToolTipContext* CXTPTaskPanel::GetToolTipContext() const
  1826. {
  1827. return m_pToolTipContext;
  1828. }
  1829. void CXTPTaskPanel::SetLayoutRTL(BOOL bRightToLeft)
  1830. {
  1831. if (!XTPSystemVersion()->IsLayoutRTLSupported())
  1832. return;
  1833. if (!m_hWnd)
  1834. return;
  1835. ModifyStyleEx(bRightToLeft ? 0 : WS_EX_LAYOUTRTL, !bRightToLeft ? 0 : WS_EX_LAYOUTRTL);
  1836. GetImageManager()->DrawReverted(bRightToLeft);
  1837. Reposition();
  1838. }
  1839. LRESULT CXTPTaskPanel::OnGetObject(WPARAM wParam, LPARAM lParam)
  1840. {
  1841. if (lParam != OBJID_CLIENT)
  1842. return (LRESULT)Default();
  1843. LPUNKNOWN lpUnknown = GetInterface(&IID_IAccessible);
  1844. if (!lpUnknown)
  1845. return E_FAIL;
  1846. return LresultFromObject(IID_IAccessible, wParam, lpUnknown);
  1847. }
  1848. BEGIN_INTERFACE_MAP(CXTPTaskPanel, CCmdTarget)
  1849. INTERFACE_PART(CXTPTaskPanel, IID_IAccessible, ExternalAccessible)
  1850. END_INTERFACE_MAP()
  1851. CCmdTarget* CXTPTaskPanel::GetAccessible()
  1852. {
  1853. return this;
  1854. }
  1855. HRESULT CXTPTaskPanel::GetAccessibleParent(IDispatch* FAR* ppdispParent)
  1856. {
  1857. *ppdispParent = NULL;
  1858. if (GetSafeHwnd())
  1859. {
  1860. return AccessibleObjectFromWindow(GetSafeHwnd(), OBJID_WINDOW, IID_IDispatch, (void**)ppdispParent);
  1861. }
  1862. return E_FAIL;
  1863. }
  1864. int CXTPTaskPanel::GetAccessibleIndex(CXTPTaskPanelItem* pItem)
  1865. {
  1866. int nCount = 0;
  1867. for (int i = 0; i < GetGroupCount(); i++)
  1868. {
  1869. CXTPTaskPanelGroup* pGroup = GetAt(i);
  1870. nCount++;
  1871. if (pItem)
  1872. {
  1873. if (pGroup == pItem)
  1874. return nCount;
  1875. if (pItem->GetItemGroup() == pGroup)
  1876. return nCount + pItem->GetIndex() + 1;
  1877. }
  1878. nCount += pGroup->GetItemCount();
  1879. }
  1880. return nCount;
  1881. }
  1882. CXTPTaskPanelItem* CXTPTaskPanel::GetAccessibleItem(int nIndex)
  1883. {
  1884. for (int i = 0; i < GetGroupCount(); i++)
  1885. {
  1886. CXTPTaskPanelGroup* pGroup = GetAt(i);
  1887. nIndex--;
  1888. if (nIndex == 0)
  1889. return pGroup;
  1890. if (nIndex <= pGroup->GetItemCount())
  1891. return pGroup->GetAt(nIndex - 1);
  1892. nIndex -= pGroup->GetItemCount();
  1893. }
  1894. return NULL;
  1895. }
  1896. HRESULT CXTPTaskPanel::GetAccessibleChildCount(long FAR* pChildCount)
  1897. {
  1898. if (pChildCount == 0)
  1899. {
  1900. return E_INVALIDARG;
  1901. }
  1902. *pChildCount = GetAccessibleIndex(NULL);
  1903. return S_OK;
  1904. }
  1905. HRESULT CXTPTaskPanel::GetAccessibleChild(VARIANT varChild, IDispatch* FAR* ppdispChild)
  1906. {
  1907. *ppdispChild = NULL;
  1908. int nChild = GetChildIndex(&varChild);
  1909. if (nChild <= 0)
  1910. {
  1911. return E_INVALIDARG;
  1912. }
  1913. CXTPTaskPanelItem* pItem = GetAccessibleItem(nChild);
  1914. if (!pItem)
  1915. {
  1916. return E_INVALIDARG;
  1917. }
  1918. *ppdispChild = pItem->GetIDispatch(TRUE);
  1919. return S_OK;
  1920. }
  1921. HRESULT CXTPTaskPanel::GetAccessibleName(VARIANT varChild, BSTR* pszName)
  1922. {
  1923. int nChild = GetChildIndex(&varChild);
  1924. if (nChild == CHILDID_SELF || nChild == -1)
  1925. {
  1926. CString strCaption;
  1927. GetWindowText(strCaption);
  1928. *pszName = strCaption.AllocSysString();
  1929. return S_OK;
  1930. }
  1931. return E_INVALIDARG;
  1932. }
  1933. HRESULT CXTPTaskPanel::GetAccessibleRole(VARIANT varChild, VARIANT* pvarRole)
  1934. {
  1935. pvarRole->vt = VT_EMPTY;
  1936. int nChild = GetChildIndex(&varChild);
  1937. if (nChild == CHILDID_SELF)
  1938. {
  1939. pvarRole->vt = VT_I4;
  1940. pvarRole->lVal = ROLE_SYSTEM_OUTLINE;
  1941. return S_OK;
  1942. }
  1943. return E_INVALIDARG;
  1944. }
  1945. HRESULT CXTPTaskPanel::GetAccessibleState(VARIANT varChild, VARIANT* pvarState)
  1946. {
  1947. pvarState->vt = VT_I4;
  1948. pvarState->lVal = 0;
  1949. int nChild = GetChildIndex(&varChild);
  1950. if (nChild == CHILDID_SELF)
  1951. {
  1952. pvarState->lVal = STATE_SYSTEM_FOCUSABLE;
  1953. }
  1954. return S_OK;
  1955. }
  1956. HRESULT CXTPTaskPanel::AccessibleLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild)
  1957. {
  1958. *pxLeft = *pyTop = *pcxWidth = *pcyHeight = 0;
  1959. if (!GetSafeHwnd())
  1960. return S_OK;
  1961. CRect rc;
  1962. GetWindowRect(&rc);
  1963. int nChild = GetChildIndex(&varChild);
  1964. if (nChild > 0)
  1965. {
  1966. CXTPTaskPanelItem* pItem = GetAccessibleItem(nChild);
  1967. if (pItem)
  1968. {
  1969. CRect rcItem = pItem->GetHitTestRect();
  1970. rc = CRect(CPoint(rc.left + rcItem.left, rc.top + rcItem.top), rcItem.Size());
  1971. }
  1972. }
  1973. *pxLeft = rc.left;
  1974. *pyTop = rc.top;
  1975. *pcxWidth = rc.Width();
  1976. *pcyHeight = rc.Height();
  1977. return S_OK;
  1978. }
  1979. HRESULT CXTPTaskPanel::AccessibleHitTest(long xLeft, long yTop, VARIANT* pvarID)
  1980. {
  1981. if (pvarID == NULL)
  1982. return E_INVALIDARG;
  1983. pvarID->vt = VT_EMPTY;
  1984. if (!GetSafeHwnd())
  1985. return S_FALSE;
  1986. if (!CXTPWindowRect(this).PtInRect(CPoint(xLeft, yTop)))
  1987. return S_FALSE;
  1988. pvarID->vt = VT_I4;
  1989. pvarID->lVal = 0;
  1990. CPoint pt(xLeft, yTop);
  1991. ScreenToClient(&pt);
  1992. CXTPTaskPanelItem* pItem = HitTestItem(pt);
  1993. if (pItem)
  1994. {
  1995. pvarID->vt = VT_DISPATCH;
  1996. pvarID->pdispVal = pItem->GetIDispatch(TRUE);
  1997. }
  1998. return S_OK;
  1999. }