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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCommandBar.cpp : implementation of the CXTPCommandBar class.
  2. //
  3. // This file is a part of the XTREME COMMANDBARS MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Resource.h"
  22. #include "Common/XTPDrawHelpers.h"
  23. #include "Common/XTPImageManager.h"
  24. #include "Common/XTPToolTipContext.h"
  25. #include "XTPCommandBar.h"
  26. #include "XTPControls.h"
  27. #include "XTPControl.h"
  28. #include "XTPMouseManager.h"
  29. #include "XTPKeyboardManager.h"
  30. #include "XTPPopupBar.h"
  31. #include "XTPControlPopup.h"
  32. #include "XTPPaintManager.h"
  33. #include "XTPShortcutManager.h"
  34. #include "XTPCustomizeTools.h"
  35. #include "XTPToolBar.h"
  36. #include "XTPCommandBars.h"
  37. #include "XTPCustomizeSheet.h"
  38. #include "XTPCommandBarAnimation.h"
  39. #ifdef _DEBUG
  40. #define new DEBUG_NEW
  41. #undef THIS_FILE
  42. static char THIS_FILE[] = __FILE__;
  43. #endif
  44. #ifndef CBRS_GRIPPER
  45. #define CBRS_GRIPPER                    0x00400000L
  46. #endif
  47. int CXTPCommandBar::s_nHoverDelay = 300;
  48. int CXTPCommandBar::s_nExpandDelay = 5000;
  49. int CXTPCommandBar::s_nExpandHoverDelay = 900;
  50. //////////////////////////////////////////////////////////////////////////
  51. // CXTPCommandBarList
  52. CXTPCommandBarList::~CXTPCommandBarList()
  53. {
  54. RemoveAll();
  55. }
  56. CXTPCommandBar* CXTPCommandBarList::GetAt(int nIndex) const
  57. {
  58. return nIndex >= 0 && nIndex < m_arrBars.GetSize() ? m_arrBars[nIndex] : NULL;
  59. }
  60. int CXTPCommandBarList::GetCount() const
  61. {
  62. return (int)m_arrBars.GetSize();
  63. }
  64. CXTPCommandBar* CXTPCommandBarList::Add(CXTPCommandBar* pCommandBar)
  65. {
  66. m_arrBars.Add(pCommandBar);
  67. return pCommandBar;
  68. }
  69. BOOL CXTPCommandBarList::Lookup(CXTPCommandBar* pCommandBar) const
  70. {
  71. for (int i = 0; i < GetCount(); i++)
  72. {
  73. if (GetAt(i) == pCommandBar)
  74. return TRUE;
  75. }
  76. return FALSE;
  77. }
  78. void CXTPCommandBarList::RemoveAll()
  79. {
  80. for (int i = 0; i < GetCount(); i++)
  81. {
  82. CXTPCommandBar* pBar = GetAt(i);
  83. pBar->InternalRelease();
  84. }
  85. m_arrBars.RemoveAll();
  86. }
  87. void CXTPCommandBarList::Remove(CXTPCommandBar* pCommandBar)
  88. {
  89. for (int i = 0; i < GetCount(); i++)
  90. {
  91. if (GetAt(i) == pCommandBar)
  92. {
  93. m_arrBars.RemoveAt(i);
  94. pCommandBar->InternalRelease();
  95. }
  96. }
  97. }
  98. CXTPCommandBar* CXTPCommandBarList::FindCommandBar(UINT nBarID) const
  99. {
  100. for (int i = 0; i < GetCount(); i++)
  101. {
  102. CXTPCommandBar* pBar = GetAt(i);
  103. if (pBar->GetBarID() == nBarID)
  104. return pBar;
  105. }
  106. return NULL;
  107. }
  108. //////////////////////////////////////////////////////////////////////////
  109. // CXTPCommandBar
  110. IMPLEMENT_XTP_COMMANDBAR(CXTPCommandBar, CWnd)
  111. CXTPCommandBar::CXTPCommandBar()
  112. {
  113. EnableAutomation();
  114. m_pCommandBars = 0;
  115. m_nIdleFlags = 0;
  116. m_barType = xtpBarTypeNormal;
  117. m_buttonStyle = xtpButtonAutomatic;
  118. m_pControls = (CXTPControls*) CXTPControls::CreateObject();
  119. m_pControls->SetParent(this);
  120. m_barPosition = xtpBarNone;
  121. m_bTracking = FALSE;
  122. m_nClickedControl = -1;
  123. m_nSelected = -1;
  124. m_nPopuped = -1;
  125. m_hwndFocus = 0;
  126. m_dwFlags = 0;
  127. m_bVisible = TRUE;
  128. m_pOwner = NULL;
  129. m_bGrabFocus = TRUE;
  130. m_nBarID = 0;
  131. m_pSite = 0;
  132. m_nWrapMargin = 0;
  133. m_szIcons = CSize(0, 0);
  134. m_szButtons = CSize(0, 0);
  135. m_nMRUWidth = 32767;
  136. m_dwStyle = CBRS_GRIPPER;
  137. m_bCustomizable = TRUE;
  138. m_nStateFlags = 0;
  139. m_rcMarker.SetRectEmpty();
  140. m_dwData = 0;
  141. m_pReturnCmd = NULL;
  142. m_bTrackOnHover = TRUE;
  143. m_bCustomizeDialogPresent = TRUE;
  144. m_bTextBelow = XTP_BOOL_DEFAULT;
  145. m_bExecOnRButton = FALSE;
  146. m_bIgnoreUpdateHandler = FALSE;
  147. m_bRecursePopup = FALSE;
  148. m_nLockRecurse = 0;
  149. m_pPaintManager = NULL;
  150. m_pImageManager = NULL;
  151. m_bKeyboardSelect = FALSE;
  152. m_nLockRedraw = 0;
  153. m_pToolTipContext = 0;
  154. m_bComboBar = FALSE;
  155. m_bMultiLine = FALSE;
  156. m_bAnimatePopup = FALSE;
  157. m_bVerticalMarker = FALSE;
  158. m_pAnimation = new CXTPCommandBarAnimation(this);
  159. }
  160. CXTPCommandBar::~CXTPCommandBar()
  161. {
  162. if (IsTrackingMode()) SetTrackingMode(FALSE);
  163. XTPHookManager()->RemoveAll(this);
  164. XTPMouseManager()->RemoveSelected(this);
  165. if (m_pControls)
  166. {
  167. m_pControls->RemoveAll();
  168. m_pControls->SetParent(NULL);
  169. CMDTARGET_RELEASE(m_pControls);
  170. }
  171. CMDTARGET_RELEASE(m_pPaintManager);
  172. CMDTARGET_RELEASE(m_pImageManager)
  173. CMDTARGET_RELEASE(m_pToolTipContext);
  174. delete m_pAnimation;
  175. }
  176. void CXTPCommandBar::SetControls(CXTPControls* pControls)
  177. {
  178. CMDTARGET_RELEASE(m_pControls);
  179. m_pControls = pControls;
  180. if (m_pControls)
  181. {
  182. m_pControls->SetParent(this);
  183. }
  184. }
  185. void CXTPCommandBar::OnRemoved()
  186. {
  187. if (IsTrackingMode()) SetTrackingMode(FALSE);
  188. XTPHookManager()->RemoveAll(this);
  189. XTPMouseManager()->RemoveSelected(this);
  190. if (m_pControls)
  191. {
  192. m_pControls->RemoveAll();
  193. }
  194. DestroyWindow();
  195. }
  196. void CXTPCommandBar::OnFinalRelease()
  197. {
  198. if (m_hWnd != NULL)
  199. DestroyWindow();
  200. CCmdTarget::OnFinalRelease();
  201. }
  202. BEGIN_MESSAGE_MAP(CXTPCommandBar, CWnd)
  203. ON_WM_MOUSEMOVE()
  204. ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
  205. ON_MESSAGE_VOID(WM_INITIALUPDATE, OnInitialUpdate)
  206. ON_WM_CREATE()
  207. ON_WM_DESTROY()
  208. ON_WM_LBUTTONDOWN()
  209. ON_WM_LBUTTONDBLCLK()
  210. ON_WM_ERASEBKGND()
  211. ON_WM_PAINT()
  212. ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
  213. ON_MESSAGE_VOID(WM_MOUSELEAVE, OnMouseLeave)
  214. ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
  215. ON_WM_NCHITTEST_EX()
  216. ON_WM_NCLBUTTONDOWN()
  217. ON_WM_TIMER()
  218. ON_WM_LBUTTONUP()
  219. ON_WM_RBUTTONUP()
  220. ON_WM_RBUTTONDOWN()
  221. ON_WM_NCMOUSEMOVE()
  222. ON_MESSAGE(WM_GETOBJECT, OnGetObject)
  223. END_MESSAGE_MAP()
  224. // CXTPCommandBar message handlers
  225. int CXTPCommandBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  226. {
  227. if (CWnd::OnCreate(lpCreateStruct) == -1)
  228. return -1;
  229. CXTPCommandBars* pCommandBars = GetCommandBars() ;
  230. if (m_barPosition != xtpBarListBox && pCommandBars)
  231. {
  232. pCommandBars->GetDropSource()->Register(this);
  233. }
  234. if (pCommandBars)
  235. {
  236. CMDTARGET_RELEASE(m_pToolTipContext);
  237. m_pToolTipContext = pCommandBars->GetToolTipContext();
  238. CMDTARGET_ADDREF(m_pToolTipContext);
  239. }
  240. else if (m_barType != xtpBarTypePopup)
  241. {
  242. EnableToolTips();
  243. }
  244. return 0;
  245. }
  246. void CXTPCommandBar::OnDestroy()
  247. {
  248. if (m_barPosition != xtpBarListBox)
  249. {
  250. CXTPCommandBars* pCommandBars = GetCommandBars();
  251. if (pCommandBars)
  252. {
  253. pCommandBars->GetDropSource()->UnRegister(this);
  254. }
  255. }
  256. if (IsTrackingMode()) SetTrackingMode(FALSE);
  257. m_pAnimation->OnDestroy();
  258. CWnd::OnDestroy();
  259. }
  260. BOOL CXTPCommandBar::IsMouseLocked() const
  261. {
  262. return !m_bComboBar && (GetCommandBars()->GetMouseManager()->IsMouseLocked());
  263. }
  264. void CXTPCommandBar::OnMouseMove(UINT /*nFlags*/, CPoint point)
  265. {
  266. CXTPCommandBars* pCommandBars = GetCommandBars ();
  267. CXTPMouseManager* pMouseManager = pCommandBars->GetMouseManager();
  268. BOOL bActive = IsTrackingMode() || pMouseManager->IsTopParentActive(m_hWnd);
  269. if (!m_hWnd || pMouseManager->IsTrackedLock(this) ||
  270. (!bActive && GetPosition() != xtpBarPopup) || IsMouseLocked())
  271. return;
  272. if (pCommandBars && pCommandBars->IsCustomizeMode())
  273. {
  274. CXTPControl* pControl = pCommandBars->m_pDragSelected;
  275. if (pControl)
  276. pControl->OnCustomizeMouseMove(point);
  277. return;
  278. }
  279. if (m_nPopuped != -1 && !m_bTrackOnHover)
  280. return;
  281. BOOL bLockSelected = ((GetPosition() != xtpBarPopup) || m_nPopuped != -1) || m_bKeyboardSelect;
  282. int nSelected = (IsTrackingMode() && bLockSelected) ? m_nSelected : -1;
  283. CXTPControl* pControl = m_pControls->HitTest(point);
  284. if (pControl)
  285. {
  286. nSelected = pControl->GetIndex();
  287. pMouseManager->TrackMouseLeave(*this);
  288. pControl->OnMouseMove(point);
  289. }
  290. SetSelected(nSelected);
  291. }
  292. void CXTPCommandBar::OnMouseLeave()
  293. {
  294. if (!IsMouseLocked() && !(IsTrackingMode() && (GetPosition() != xtpBarPopup || m_nPopuped != -1)) && (m_nLockRecurse == 0))
  295. SetSelected(-1);
  296. }
  297. void CXTPCommandBar::OnNcMouseMove(UINT nHitTest, CPoint point)
  298. {
  299. OnMouseLeave();
  300. CWnd::OnNcMouseMove(nHitTest, point);
  301. }
  302. void CXTPCommandBar::OnTrackEnter()
  303. {
  304. SetSelected(-1);
  305. }
  306. void CXTPCommandBar::OnLButtonDown(UINT nFlags, CPoint point)
  307. {
  308. CXTPControl* pControl = m_pControls->HitTest(point);
  309. if ((m_nPopuped != -1) && (GetPosition() == xtpBarPopup && GetType() == xtpBarTypeNormal)
  310. && (!pControl || pControl->GetIndex() != m_nPopuped))
  311. {
  312. if (m_nPopuped == m_nSelected) SetSelected(-1);
  313. SetPopuped(-1);
  314. }
  315. if (pControl)
  316. {
  317. if (!IsCustomizeMode() && (pControl->IsCustomizeMovable()) &&
  318. DYNAMIC_DOWNCAST(CXTPToolBar, this) && (GetKeyState(VK_MENU) < 0))
  319. {
  320. CXTPCommandBars* pCommandBars = GetCommandBars();
  321. if (pCommandBars && pCommandBars->IsCustomizeAvail() && pCommandBars->GetCommandBarsOptions()->bAltDragCustomization)
  322. {
  323. pCommandBars->SetQuickCustomizeMode(TRUE);
  324. SetPopuped(-1);
  325. SetSelected(-1);
  326. pControl->CustomizeStartDrag(point);
  327. pCommandBars->SetQuickCustomizeMode(FALSE);
  328. pCommandBars->RecalcFrameLayout();
  329. pCommandBars->ClosePopups();
  330. return;
  331. }
  332. }
  333. if (!IsCustomizeMode() || pControl->IsCustomizeMovable())
  334. pControl->OnClick(FALSE, point);
  335. return;
  336. }
  337. CWnd::OnLButtonDown(nFlags, point);
  338. }
  339. void CXTPCommandBar::OnLButtonDblClk(UINT /*nFlags*/, CPoint point)
  340. {
  341. if (IsCustomizeMode())
  342. return;
  343. CXTPControl* pControl = m_pControls->HitTest(point);
  344. if (pControl)
  345. {
  346. pControl->OnLButtonDblClk(point);
  347. }
  348. }
  349. void CXTPCommandBar::OnLButtonUp(UINT nFlags, CPoint point)
  350. {
  351. if (IsCustomizeMode())
  352. return;
  353. CXTPControl* pControl = m_pControls->HitTest(point);
  354. if (pControl)
  355. {
  356. pControl->OnLButtonUp(point);
  357. return;
  358. }
  359. CWnd::OnLButtonUp(nFlags, point);
  360. }
  361. void CXTPCommandBar::OnRButtonUp(UINT /*nFlags*/, CPoint point)
  362. {
  363. if (IsCustomizeMode())
  364. return;
  365. CXTPControl* pControl = m_pControls->HitTest(point);
  366. if (pControl)
  367. {
  368. if (GetSite()->SendMessage(WM_XTP_CONTROLRBUTTONUP, (WPARAM)(LPPOINT)&point, (LPARAM)pControl) == TRUE)
  369. return;
  370. if (GetRootParent()->m_bExecOnRButton)
  371. {
  372. pControl->OnLButtonUp(point);
  373. return;
  374. }
  375. if (pControl->OnRButtonUp(point))
  376. return;
  377. }
  378. CXTPCommandBar* pCommandBar = GetRootParent();
  379. if (pCommandBar && pCommandBar != this)
  380. {
  381. pCommandBar->OnPopupRButtonUp(this, point);
  382. }
  383. }
  384. void CXTPCommandBar::EnsureVisible(CXTPControl* /*pControl*/)
  385. {
  386. }
  387. BOOL CXTPCommandBar::SetSelected(int nSelected, BOOL bKeyboard)
  388. {
  389. if (m_nSelected == nSelected)
  390. return FALSE;
  391. m_bKeyboardSelect = bKeyboard;
  392. if (!GetSafeHwnd())
  393. return FALSE;
  394. if (m_nSelected != -1)
  395. {
  396. CXTPControl* pSelected = GetControl(m_nSelected);
  397. if (pSelected) pSelected->OnMouseMove(CPoint(-1, -1));
  398. if (pSelected) pSelected->OnSetSelected(FALSE);
  399. }
  400. m_nSelected = nSelected;
  401. if (m_nSelected != -1)
  402. {
  403. CXTPControl* pSelected = GetControl(nSelected);
  404. ASSERT(pSelected);
  405. if (!pSelected)
  406. return FALSE;
  407. if (bKeyboard)
  408. EnsureVisible(pSelected);
  409. pSelected->OnSetSelected(bKeyboard ? max(TRUE_KEYBOARD_NEXT, bKeyboard) : TRUE);
  410. if (IsTrackingMode()) AccessibleNotifyWinEvent(EVENT_OBJECT_FOCUS , m_hWnd, OBJID_MENU, m_nSelected + 1);
  411. XTPMouseManager()->SetSelected(this);
  412. if (!bKeyboard && m_bTrackOnHover) SetTimer(XTP_TID_HOVER, s_nHoverDelay, NULL);
  413. }
  414. else
  415. {
  416. KillTimer(XTP_TID_HOVER);
  417. }
  418. return TRUE;
  419. }
  420. BOOL CXTPCommandBar::SetPopuped(int nPopuped, BOOL bKeyboard)
  421. {
  422. if (m_nPopuped == nPopuped)
  423. return FALSE;
  424. if (m_nPopuped != -1)
  425. {
  426. CXTPControl* pControl = GetControl(m_nPopuped);
  427. m_nPopuped = -1;
  428. pControl->OnSetPopup(FALSE);
  429. }
  430. if (nPopuped != -1)
  431. {
  432. CXTPControl* pControl = GetControl(nPopuped);
  433. if (!pControl || !pControl->GetEnabled())
  434. {
  435. return FALSE;
  436. }
  437. m_nPopuped = nPopuped;
  438. SetTrackingMode(TRUE_POPUP, FALSE, bKeyboard);
  439. SetSelected(nPopuped, bKeyboard);
  440. if (!pControl->OnSetPopup(TRUE))
  441. {
  442. m_nPopuped = -1;
  443. return FALSE;
  444. }
  445. CXTPCommandBars* pCommandBars = GetCommandBars();
  446. if (pCommandBars && pCommandBars->GetCommandBarsOptions()->bShowFullAfterDelay && m_hWnd)
  447. {
  448. SetTimer(XTP_TID_EXPANDED_POPUP, s_nExpandDelay, NULL);
  449. }
  450. }
  451. return TRUE;
  452. }
  453. LRESULT CXTPCommandBar::OnIdleUpdateCmdUI(WPARAM, LPARAM)
  454. {
  455. if (GetSafeHwnd() && (GetStyle() & WS_VISIBLE))
  456. {
  457. UpdateDocTemplateControls();
  458. OnUpdateCmdUI();
  459. if (m_nIdleFlags & xtpIdleRedraw)
  460. {
  461. Redraw();
  462. }
  463. if (m_nIdleFlags & xtpIdleLayout)
  464. {
  465. OnRecalcLayout();
  466. m_nIdleFlags &= ~xtpIdleLayout;
  467. }
  468. }
  469. return 0L;
  470. }
  471. class CXTPCommandBar::CCommandBarCmdUI : public CCmdUI
  472. {
  473. public:
  474. CCommandBarCmdUI()
  475. {
  476. m_bCheckedChanged = FALSE;
  477. m_pControl = 0;
  478. }
  479. public: // re-implementations only
  480. virtual void Enable(BOOL bOn);
  481. virtual void SetCheck(int nCheck);
  482. virtual void SetText(LPCTSTR lpszText);
  483. public:
  484. CXTPControl* m_pControl;
  485. BOOL m_bCheckedChanged;
  486. };
  487. void CXTPCommandBar::CCommandBarCmdUI::Enable(BOOL bOn)
  488. {
  489. m_bEnableChanged = TRUE;
  490. ASSERT(m_pControl != NULL);
  491. if (!m_pControl)
  492. return;
  493. if (m_pControl->GetAction())
  494. {
  495. m_pControl->SetEnabled(bOn ? -1 : FALSE);
  496. }
  497. else
  498. {
  499. m_pControl->SetEnabled(bOn);
  500. if (!bOn && !m_bCheckedChanged) m_pControl->SetChecked(FALSE);
  501. }
  502. }
  503. void CXTPCommandBar::CCommandBarCmdUI::SetCheck(int nCheck)
  504. {
  505. ASSERT(nCheck >= 0 && nCheck <= 2); // 0 =>off, 1 =>on, 2 =>indeterminate
  506. m_bCheckedChanged = TRUE;
  507. ASSERT(m_pControl != NULL);
  508. if (!m_pControl)
  509. return;
  510. m_pControl->SetChecked(nCheck);
  511. }
  512. void CXTPCommandBar::CCommandBarCmdUI::SetText(LPCTSTR lpszCaption)
  513. {
  514. ASSERT(m_pControl != NULL);
  515. if (!m_pControl)
  516. return;
  517. m_pControl->SetCaption(lpszCaption);
  518. }
  519. void CXTPCommandBar::OnInitialUpdate()
  520. {
  521. // update the indicators before becoming visible
  522. OnIdleUpdateCmdUI(TRUE, 0L);
  523. }
  524. void CXTPCommandBar::OnUpdateCmdUI()
  525. {
  526. if (!GetSafeHwnd())
  527. return;
  528. CWnd* pTarget = GetOwnerSite();
  529. CXTPCommandBars* pCommandBars = GetCommandBars();
  530. BOOL bDisableIfNoHndler = pCommandBars ? pCommandBars->GetCommandBarsOptions()->bDisableCommandIfNoHandler : FALSE;
  531. if (!pTarget)
  532. return;
  533. CXTPControl* pControl;
  534. BOOL bIgnoreUpdateHandler = GetRootParent()->m_bIgnoreUpdateHandler;
  535. CCommandBarCmdUI state;
  536. state.m_pOther = this;
  537. for (state.m_nIndex = 0; (int)state.m_nIndex < GetControlCount(); state.m_nIndex++)
  538. {
  539. pControl = m_pControls->GetAt(state.m_nIndex);
  540. if (!pControl->IsVisible(xtpHideScroll | xtpHideGeneric | xtpHideExpand))
  541. continue;
  542. pControl->OnIdleUpdate();
  543. if (bIgnoreUpdateHandler || (pControl->m_dwFlags & xtpFlagManualUpdate))
  544. continue;
  545. state.m_pControl = pControl;
  546. state.m_nID = pControl->GetID();
  547. state.m_bCheckedChanged = FALSE;
  548. state.m_bEnableChanged = FALSE;
  549. if (CWnd::OnCmdMsg(0,
  550. MAKELONG((int)CN_UPDATE_COMMAND_UI, WM_COMMAND + WM_REFLECT_BASE),
  551. &state, NULL))
  552. continue;
  553. // allow the toolbar itself to have update handlers
  554. if (CWnd::OnCmdMsg(state.m_nID, (int)CN_UPDATE_COMMAND_UI, &state, NULL))
  555. continue;
  556. if (pCommandBars && pCommandBars->IsCustomizeMode())
  557. {
  558. if (pControl->m_bEnabled != (BOOL)-1)
  559. {
  560. state.Enable(TRUE);
  561. }
  562. }
  563. else
  564. // allow the owner to process the update
  565. state.DoUpdate(pTarget, bDisableIfNoHndler);
  566. }
  567. // update the dialog controls added to the toolbar
  568. UpdateDialogControls(pTarget, bDisableIfNoHndler);
  569. }
  570. BOOL CXTPControls::LoadMenu(CMenu* pMenu)
  571. {
  572. if (!pMenu)
  573. return FALSE;
  574. BOOL bSeparator = FALSE;
  575. int nCount = ::GetMenuItemCount(pMenu->m_hMenu);
  576. MENUITEMINFO info;
  577. for (int i = 0; i < nCount; i++)
  578. {
  579. ZeroMemory(&info, sizeof(MENUITEMINFO));
  580. info.cbSize = sizeof(MENUITEMINFO);
  581. info.fMask = MIIM_TYPE | MIIM_STATE;
  582. // Check to see if the item is a separator, we don't want
  583. // to use GetMenuItemID(i) because it may not equal zero.
  584. ::GetMenuItemInfo(pMenu->m_hMenu, i, TRUE, &info);
  585. if (((info.fType & MFT_SEPARATOR) == MFT_SEPARATOR) || (pMenu->GetMenuItemID(i) == 0))
  586. bSeparator = TRUE;
  587. else
  588. {
  589. CXTPControl* pControl = AddMenuItem(pMenu, i);
  590. if (!pControl)
  591. continue;
  592. if (((info.fType & MFT_MENUBARBREAK) == MFT_MENUBARBREAK) || ((info.fType & MFT_MENUBREAK) == MFT_MENUBREAK))
  593. {
  594. pControl->SetFlags(pControl->GetFlags() | xtpFlagWrapRow);
  595. pControl->SetBeginGroup((info.fType & MFT_MENUBARBREAK) ? TRUE : FALSE);
  596. }
  597. if (bSeparator)
  598. {
  599. pControl->SetBeginGroup(TRUE);
  600. bSeparator = FALSE;
  601. }
  602. if (pControl->GetAction() == NULL && info.fState & MFS_CHECKED)
  603. {
  604. pControl->SetChecked(TRUE);
  605. }
  606. if (pControl->GetAction() == NULL && info.fState & MFS_DISABLED)
  607. {
  608. pControl->SetEnabled(FALSE);
  609. }
  610. }
  611. }
  612. return TRUE;
  613. }
  614. BOOL CXTPCommandBar::LoadMenu(CMenu* pMenu, BOOL bRemoveControls)
  615. {
  616. if (!pMenu || !::IsMenu(pMenu->m_hMenu))
  617. return FALSE;
  618. if (bRemoveControls)
  619. m_pControls->RemoveAll();
  620. if (!m_pControls->LoadMenu(pMenu))
  621. return FALSE;
  622. CFrameWnd* pFrame = GetParentFrame();
  623. if (pFrame) pFrame->DelayRecalcLayout();
  624. return TRUE;
  625. }
  626. BOOL CXTPCommandBar::ProcessSpecialKey(XTPSpecialKey key)
  627. {
  628. if (key == xtpKeySpace)
  629. {
  630. if (GetType() == xtpBarTypeMenuBar)
  631. {
  632. GetCommandBars()->ClosePopups();
  633. GetSite()->PostMessage(WM_SYSCOMMAND, SC_KEYMENU, (LPARAM)_T(' '));
  634. return TRUE;
  635. }
  636. return FALSE;
  637. }
  638. if (key == xtpKeyLeft) key = xtpKeyPrev;
  639. if (key == xtpKeyRight) key = xtpKeyNext;
  640. BOOL bPopupToolBar = (GetPosition() == xtpBarPopup && GetType() == xtpBarTypeNormal);
  641. if (key == xtpKeyNext || key == xtpKeyPrev)
  642. HideKeyboardTips();
  643. if (m_nSelected != -1 && m_nSelected == m_nPopuped && bPopupToolBar)
  644. {
  645. if (key == xtpKeyNext)
  646. return FALSE;
  647. if (key == xtpKeyPrev)
  648. key = xtpKeyBack;
  649. }
  650. else if (key == xtpKeyBack && m_nPopuped == -1 && m_nSelected != -1 && (bPopupToolBar || !GetParentCommandBar()))
  651. {
  652. CXTPControlPopup* pControlPopup = DYNAMIC_DOWNCAST(CXTPControlPopup, GetControl(m_nSelected));
  653. if (pControlPopup && pControlPopup->GetEnabled())
  654. key = xtpKeyPopup;
  655. }
  656. if (((key == xtpKeyPopup) || (key == xtpKeyBack)) && m_nPopuped == -1 && (bPopupToolBar || (GetPosition() == xtpBarFloating)))
  657. {
  658. int nDirection = key == xtpKeyPopup ? +1 : -1;
  659. if (m_nSelected == -1)
  660. {
  661. SetSelected(m_pControls->GetNext(-1, nDirection), nDirection ? TRUE_KEYBOARD_NEXT : TRUE_KEYBOARD_PREV);
  662. return TRUE;
  663. }
  664. CXTPControlPopup* pControlPopup = DYNAMIC_DOWNCAST(CXTPControlPopup, GetControl(m_nSelected));
  665. if (!pControlPopup || !pControlPopup->GetEnabled())
  666. {
  667. CXTPControl* pSelected = GetControl(m_nSelected), *pNextSelected = NULL;
  668. int nSelected = m_nSelected;
  669. ASSERT(pSelected);
  670. CRect rcSelected = pSelected->GetRect();
  671. CRect rcSelectedRow = pSelected->m_rcRow;
  672. do
  673. {
  674. nSelected = m_pControls->GetNext(nSelected, nDirection);
  675. ASSERT(nSelected != -1);
  676. CXTPControl* pCondidate = GetControl(nSelected);
  677. CRect rcNextSelected = pCondidate->GetRect(), rcNextSelectedRow = pCondidate->GetRowRect();
  678. if (pNextSelected && (pNextSelected->m_rcRow.top == rcNextSelectedRow.top)
  679. && ((rcNextSelected.left <= rcSelected.left && (rcNextSelected.left > pNextSelected->GetRect().left))
  680. || (rcNextSelected.left >= rcSelected.left && (pNextSelected->GetRect().left > rcNextSelected.left))))
  681. {
  682. pNextSelected = pCondidate;
  683. }
  684. else if (!pNextSelected && rcNextSelectedRow.top != rcSelectedRow.top && !rcNextSelectedRow.IsRectEmpty())
  685. {
  686. pNextSelected = pCondidate;
  687. }
  688. else if (pNextSelected)
  689. {
  690. SetSelected(pNextSelected->GetIndex(), nDirection > 0 ? TRUE_KEYBOARD_NEXT : TRUE_KEYBOARD_PREV);
  691. break;
  692. }
  693. }
  694. while ((nSelected != m_nSelected) && (nSelected != -1));
  695. return TRUE;
  696. }
  697. }
  698. switch (key)
  699. {
  700. case xtpKeyNext:
  701. SetSelected(m_pControls->GetNext(m_nSelected, +1), TRUE_KEYBOARD_NEXT);
  702. return TRUE;
  703. case xtpKeyPrev:
  704. SetSelected(m_pControls->GetNext(m_nSelected, -1), TRUE_KEYBOARD_PREV);
  705. return TRUE;
  706. case xtpKeyHome:
  707. SetSelected(m_pControls->GetNext(-1, +1), TRUE_KEYBOARD_NEXT);
  708. return TRUE;
  709. case xtpKeyEnd:
  710. SetSelected(m_pControls->GetNext(GetControlCount(), -1), TRUE_KEYBOARD_PREV);
  711. return TRUE;
  712. case xtpKeyPopup:
  713. if (m_nSelected != -1 && m_nSelected != m_nPopuped)
  714. {
  715. GetControl(m_nSelected)->OnSetSelected(TRUE_KEYBOARD_NEXT);
  716. return SetPopuped(m_nSelected);
  717. }
  718. break;
  719. case xtpKeyBack:
  720. if (m_nPopuped != -1)
  721. {
  722. SetPopuped(-1);
  723. SetTrackingMode(TRUE, FALSE);
  724. return TRUE;
  725. }
  726. break;
  727. case xtpKeyEscape:
  728. {
  729. int nLevel = IsKeyboardTipsVisible();
  730. if (nLevel > 1)
  731. {
  732. GetCommandBars()->ShowKeyboardTips(this, nLevel - 1);
  733. return TRUE;
  734. }
  735. if (GetParentCommandBar() != NULL)
  736. GetParentCommandBar()->SetTrackingMode(TRUE, FALSE);
  737. SetTrackingMode(FALSE);
  738. }
  739. return TRUE;
  740. case xtpKeyReturn:
  741. if (m_nSelected != -1)
  742. {
  743. GetControl(m_nSelected)->OnSetSelected(TRUE_KEYBOARD_NEXT);
  744. GetControl(m_nSelected)->OnClick(TRUE);
  745. }
  746. return TRUE;
  747. }
  748. return FALSE;
  749. }
  750. BOOL CXTPCommandBar::IsHelpMode() const
  751. {
  752. CFrameWnd* pFrame = GetFrameSite();
  753. return pFrame && pFrame->m_bHelpMode;
  754. }
  755. BOOL CXTPCommandBar::OnHookKeyDown(UINT nChar, LPARAM lParam)
  756. {
  757. CXTPCommandBars* pCommandBars = GetCommandBars();
  758. if (pCommandBars && pCommandBars->IsCustomizeMode())
  759. {
  760. return FALSE_EXIT;
  761. }
  762. if (IsHelpMode())
  763. return FALSE_EXIT;
  764. if (m_nLockRecurse > 0)
  765. return TRUE;
  766. InternalAddRef();
  767. GetSite()->SendMessage(WM_XTP_COMMANDBARKEYDOWN, (WPARAM)&nChar, (LPARAM)this);
  768. if (InternalRelease() == 0)
  769. return TRUE;
  770. CXTPControl* pControl = GetControl(m_nSelected);
  771. if (pControl && pControl->IsFocused())
  772. {
  773. BOOL bResult = pControl->OnHookKeyDown(nChar, lParam);
  774. if ((bResult == TRUE) || (bResult == FALSE_EXIT))
  775. return bResult;
  776. }
  777. if (!GetSafeHwnd())
  778. return TRUE;
  779. switch (nChar)
  780. {
  781. case VK_TAB:
  782. {
  783. if ((GetKeyState(VK_CONTROL) < 0) && pCommandBars)
  784. {
  785. CXTPCommandBar* pToolBar = GetRootParent();
  786. if (DYNAMIC_DOWNCAST(CXTPToolBar, pToolBar))
  787. {
  788. if (pCommandBars->SetToolBarFocus((CXTPToolBar*)pToolBar, GetKeyState(VK_SHIFT) >= 0 ? +1 : -1))
  789. return TRUE;
  790. }
  791. }
  792. ProcessSpecialKey(GetKeyState(VK_SHIFT) >= 0 ? xtpKeyNext : xtpKeyPrev);
  793. pControl = GetControl(m_nSelected);
  794. if (pControl && pControl->IsFocusable())
  795. pControl->SetFocused(TRUE);
  796. return TRUE;
  797. }
  798. case VK_RETURN: return ProcessSpecialKey(xtpKeyReturn);
  799. case VK_ESCAPE: return ProcessSpecialKey(xtpKeyEscape);
  800. case VK_SPACE:
  801. if (ProcessSpecialKey(xtpKeySpace))
  802. return TRUE;
  803. }
  804. if (::GetFocus() && ::IsChild(m_hWnd, ::GetFocus()))
  805. return FALSE_EXIT;
  806. BOOL bHoriz = m_barPosition == xtpBarTop || m_barPosition == xtpBarBottom || m_barPosition == xtpBarFloating
  807. || (m_barPosition == xtpBarPopup && m_barType == xtpBarTypeNormal) ;
  808. BOOL bLayoutRTL = IsLayoutRTL();
  809. switch (nChar)
  810. {
  811. case VK_LEFT: return ProcessSpecialKey(bHoriz ? (bLayoutRTL ? xtpKeyRight: xtpKeyLeft) : (bLayoutRTL ? xtpKeyPopup : xtpKeyBack));
  812. case VK_RIGHT: return ProcessSpecialKey(bHoriz ? (bLayoutRTL ? xtpKeyLeft : xtpKeyRight) : (!bLayoutRTL ? xtpKeyPopup : xtpKeyBack));
  813. case VK_UP: return ProcessSpecialKey(bHoriz ? xtpKeyBack : xtpKeyPrev);
  814. case VK_DOWN: return ProcessSpecialKey(bHoriz ? xtpKeyPopup : xtpKeyNext);
  815. case VK_HOME: return ProcessSpecialKey(xtpKeyHome);
  816. case VK_END: return ProcessSpecialKey(xtpKeyEnd);
  817. }
  818. if (nChar && MapVirtualKey(nChar, 2))
  819. {
  820. if (IsKeyboardTipsVisible() && GetKeyState(VK_CONTROL) >= 0)
  821. {
  822. OnKeyboardTipChar(nChar);
  823. return TRUE;
  824. }
  825. if (pCommandBars && DYNAMIC_DOWNCAST(CXTPToolBar, this))
  826. {
  827. if (pCommandBars->OnFrameAccel(nChar))
  828. return TRUE;
  829. }
  830. BOOL bSelectOnly = FALSE;
  831. int nIndex = GetKeyState(VK_CONTROL) < 0 ? -1 : FindAccelEx(nChar, bSelectOnly);
  832. if (nIndex != -1)
  833. {
  834. SetSelected(nIndex, TRUE_KEYBOARD_NEXT);
  835. if (!bSelectOnly)
  836. {
  837. GetControl(nIndex)->OnUnderlineActivate();
  838. }
  839. return TRUE;
  840. }
  841. if (nChar != VK_SHIFT && nChar != VK_CONTROL) MessageBeep(0);
  842. }
  843. return TRUE;
  844. }
  845. void CXTPCommandBar::HideKeyboardTips()
  846. {
  847. CXTPCommandBars* pCommandBars = GetCommandBars();
  848. if (pCommandBars) pCommandBars->HideKeyboardTips();
  849. }
  850. void CXTPCommandBar::OnKeyboardTip(CXTPCommandBarKeyboardTip* pTip)
  851. {
  852. CXTPControl* pControl = DYNAMIC_DOWNCAST(CXTPControl, pTip->m_pOwner);
  853. if (pControl)
  854. {
  855. pControl->OnUnderlineActivate();
  856. return;
  857. }
  858. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, pTip->m_pOwner);
  859. if (pToolBar)
  860. {
  861. pToolBar->GetCommandBars()->SetToolBarFocus(pToolBar, FALSE);
  862. }
  863. }
  864. void CXTPCommandBar::OnKeyboardTipChar(UINT chAccel)
  865. {
  866. CXTPCommandBars* pCommandBars = GetCommandBars();
  867. if (!pCommandBars)
  868. return;
  869. for (int i = 0; i < (int)pCommandBars->m_keyboardTips.arr.GetSize(); i++)
  870. {
  871. CXTPCommandBarKeyboardTip* pTip = pCommandBars->m_keyboardTips.arr[i];
  872. if (pTip->m_strTip.GetLength() > pCommandBars->m_keyboardTips.nKey)
  873. {
  874. if (CXTPShortcutManager::CompareAccelKey(pTip->m_strTip[pCommandBars->m_keyboardTips.nKey], chAccel))
  875. {
  876. if (pTip->m_strTip.GetLength() - 1 > pCommandBars->m_keyboardTips.nKey)
  877. {
  878. pCommandBars->m_keyboardTips.nKey++;
  879. CString str = pTip->m_strTip.Left(pCommandBars->m_keyboardTips.nKey);
  880. for (int j = (int)pCommandBars->m_keyboardTips.arr.GetSize() - 1; j >= 0; j--)
  881. {
  882. pTip = pCommandBars->m_keyboardTips.arr[j];
  883. if (pTip->m_strTip.Left(pCommandBars->m_keyboardTips.nKey) != str)
  884. {
  885. pCommandBars->m_keyboardTips.arr.RemoveAt(j);
  886. pTip->DestroyWindow();
  887. delete pTip;
  888. }
  889. }
  890. }
  891. else
  892. {
  893. if (pTip->m_bEnabled)
  894. OnKeyboardTip(pTip);
  895. else
  896. MessageBeep(0);
  897. }
  898. return;
  899. }
  900. }
  901. }
  902. if (chAccel != VK_SHIFT && chAccel != VK_CONTROL) MessageBeep(0);
  903. }
  904. BOOL CXTPCommandBar::Popup(CXTPControlPopup* /*pControlPopup*/, BOOL)
  905. {
  906. return FALSE;
  907. }
  908. BOOL CXTPCommandBar::OnEraseBkgnd(CDC* /*pDC*/)
  909. {
  910. return TRUE;
  911. }
  912. int CXTPCommandBar::OnHookMessage(HWND /*hWnd*/, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& /*lResult*/)
  913. {
  914. if (IsTrackingMode())
  915. {
  916. switch (nMessage)
  917. {
  918. case WM_KEYDOWN:
  919. return OnHookKeyDown((UINT)wParam, lParam);
  920. case WM_MOUSEWHEEL:
  921. {
  922. CXTPControl* pControl = GetControl(m_nSelected);
  923. if (pControl && pControl->IsFocused())
  924. {
  925. pControl->OnHookMouseWheel(LOWORD(wParam), (short) HIWORD(wParam),
  926. CPoint(LOWORD(lParam), HIWORD(lParam)));
  927. }
  928. return TRUE;
  929. }
  930. }
  931. }
  932. return FALSE;
  933. }
  934. void CXTPCommandBar::OnTrackLost()
  935. {
  936. SetTrackingMode(FALSE);
  937. }
  938. BOOL CXTPCommandBar::SetTrackingMode(int bMode, BOOL bSelectFirst, BOOL bKeyboard)
  939. {
  940. if (m_bTracking && bMode || m_bTracking == bMode)
  941. {
  942. m_bTracking = bMode;
  943. return FALSE;
  944. }
  945. m_bTracking = bMode;
  946. CXTPCommandBars* pCommandBars = GetCommandBars();
  947. CXTPMouseManager* pMouseManager = pCommandBars->GetMouseManager();
  948. if (bMode)
  949. {
  950. if (GetType() == xtpBarTypeMenuBar)
  951. GetSite()->SendMessage(WM_XTP_INITMENU, (WPARAM)this);
  952. m_bAnimatePopup = !bSelectFirst && !bKeyboard;
  953. m_bKeyboardSelect = bKeyboard;
  954. if (m_bGrabFocus)
  955. {
  956. if (m_hwndFocus == 0)
  957. m_hwndFocus = ::GetFocus() ? ::GetFocus() : GetSite()->GetSafeHwnd();
  958. ::HideCaret(m_hwndFocus);
  959. }
  960. pMouseManager->SetTrack(this, FALSE);
  961. XTPKeyboardManager()->HookKeyboard(this);
  962. ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  963. if (bSelectFirst)
  964. {
  965. SetSelected(m_pControls->GetNext(-1, +1), TRUE_KEYBOARD_NEXT);
  966. }
  967. }
  968. else
  969. {
  970. m_bAnimatePopup = FALSE;
  971. m_bKeyboardSelect = FALSE;
  972. pMouseManager->RemoveTrack(this);
  973. XTPKeyboardManager()->UnhookKeyboard(this);
  974. SetPopuped(-1);
  975. if (bSelectFirst) SetSelected(-1);
  976. if (m_hwndFocus && m_bGrabFocus)
  977. {
  978. ::ShowCaret(m_hwndFocus);
  979. m_hwndFocus = 0;
  980. }
  981. Redraw();
  982. if (!pMouseManager->IsTrackedLock())
  983. pMouseManager->SetForceExpanded(FALSE);
  984. if (m_hWnd && GetFocus() == this && GetParent())
  985. {
  986. CWnd* pWndNext = GetParent()->GetNextDlgTabItem(this);
  987. if (pWndNext != NULL)
  988. pWndNext->SetFocus();
  989. }
  990. m_nLockRecurse = 0;
  991. }
  992. if (pCommandBars)
  993. {
  994. pCommandBars->OnTrackingModeChanged(this, bMode);
  995. }
  996. return TRUE;
  997. }
  998. int CXTPCommandBar::GetControlCount() const
  999. {
  1000. return m_pControls->GetCount();
  1001. }
  1002. CXTPControl* CXTPCommandBar::GetControl(int nIndex) const
  1003. {
  1004. //Ensure the index falls within the correct range.
  1005. if ((nIndex >= 0) && (nIndex < GetControlCount()))
  1006. {
  1007. return m_pControls->GetAt(nIndex);
  1008. }
  1009. return NULL;
  1010. }
  1011. void CXTPCommandBar::OnTimer(UINT_PTR nIDEvent)
  1012. {
  1013. CWnd::OnTimer(nIDEvent);
  1014. if (nIDEvent == XTP_TID_SHOWKEYBOARDTIPS)
  1015. {
  1016. CXTPMouseManager* pMouseManager = GetCommandBars()->GetMouseManager();
  1017. int nCount = (int)pMouseManager->GetTrackArray().GetSize();
  1018. CXTPCommandBar* pCommandBar = nCount > 0 ? pMouseManager->GetTrackArray().GetAt(nCount - 1) : 0;
  1019. if (pCommandBar == this && !IsKeyboardTipsVisible()) GetCommandBars()->ShowKeyboardTips(this);
  1020. }
  1021. if (nIDEvent == XTP_TID_ANIMATION)
  1022. {
  1023. m_pAnimation->OnAnimate();
  1024. return;
  1025. }
  1026. if (nIDEvent == XTP_TID_HOVER && m_nLockRecurse == 0)
  1027. {
  1028. KillTimer(XTP_TID_HOVER);
  1029. if (m_nSelected != -1)
  1030. GetControl(m_nSelected)->OnMouseHover();
  1031. }
  1032. if (nIDEvent == XTP_TID_EXPANDED_POPUP && m_nLockRecurse == 0)
  1033. {
  1034. KillTimer(XTP_TID_EXPANDED_POPUP);
  1035. if (m_nPopuped != -1 && m_nSelected == m_nPopuped)
  1036. {
  1037. CXTPControlPopup* pControl = DYNAMIC_DOWNCAST(CXTPControlPopup, GetControl(m_nSelected));
  1038. if (pControl && pControl->IsCursorOver())
  1039. {
  1040. pControl->ExpandCommandBar();
  1041. }
  1042. }
  1043. }
  1044. }
  1045. void CXTPCommandBar::OnControlsChanged()
  1046. {
  1047. m_nSelected = -1;
  1048. m_nPopuped = -1;
  1049. DelayLayout();
  1050. }
  1051. void CXTPCommandBar::Redraw(LPCRECT lpRect, BOOL bAnimate)
  1052. {
  1053. if (m_nLockRedraw > 0)
  1054. {
  1055. m_nIdleFlags |= xtpIdleRedraw;
  1056. return;
  1057. }
  1058. if (lpRect == NULL)
  1059. {
  1060. m_nIdleFlags &= ~xtpIdleRedraw;
  1061. }
  1062. if (m_hWnd && IsVisible())
  1063. {
  1064. m_pAnimation->RedrawRect(lpRect, bAnimate);
  1065. }
  1066. }
  1067. void CXTPCommandBar::EnableAnimation(BOOL bEnable)
  1068. {
  1069. m_pAnimation->m_bAnimation = bEnable;
  1070. Redraw();
  1071. }
  1072. BOOL CXTPCommandBar::IsAnimationEnabled() const
  1073. {
  1074. return m_pAnimation->m_bAnimation;
  1075. }
  1076. void CXTPCommandBar::EnableDoubleBuffer(BOOL bEnable)
  1077. {
  1078. m_pAnimation->m_bDoubleBuffer = bEnable;
  1079. }
  1080. void CXTPCommandBar::SetShowGripper(BOOL bShow)
  1081. {
  1082. if (bShow)
  1083. m_dwStyle |= CBRS_GRIPPER;
  1084. else
  1085. m_dwStyle &= ~CBRS_GRIPPER;
  1086. }
  1087. BOOL CXTPCommandBar::GetShowGripper() const
  1088. {
  1089. return m_dwStyle & CBRS_GRIPPER ? TRUE : FALSE;
  1090. }
  1091. void CXTPCommandBar::OnPaint()
  1092. {
  1093. CPaintDC paintDC(this);
  1094. m_pAnimation->OnPaint(paintDC);
  1095. }
  1096. LRESULT CXTPCommandBar::OnPrintClient(WPARAM wParam, LPARAM)
  1097. {
  1098. CDC* pDC = CDC::FromHandle((HDC)wParam);
  1099. if (pDC)
  1100. {
  1101. DrawCommandBar(pDC, CXTPClientRect(this));
  1102. }
  1103. return TRUE;
  1104. }
  1105. CRect CXTPCommandBar::GetBorders()
  1106. {
  1107. return GetPaintManager()->GetCommandBarBorders(this);
  1108. }
  1109. void CXTPCommandBar::FillCommandBarEntry(CDC* pDC)
  1110. {
  1111. CXTPPaintManager* pPaintManager = GetPaintManager();
  1112. pPaintManager->FillCommandBarEntry(pDC, this);
  1113. }
  1114. void CXTPCommandBar::DrawCommandBar(CDC* pDC, CRect rcClipBox)
  1115. {
  1116. #if 0
  1117. _int64 nPerfomanceEnd;
  1118. _int64 nPerfomanceStart;
  1119. QueryPerformanceCounter((LARGE_INTEGER*)&nPerfomanceStart);
  1120. #endif
  1121. if (!pDC || !pDC->GetSafeHdc())
  1122. return;
  1123. CXTPPaintManager* pPaintManager = GetPaintManager();
  1124. CXTPCommandBars* pCommandBars = GetCommandBars();
  1125. FillCommandBarEntry(pDC);
  1126. if (GetShowGripper() || GetPosition() == xtpBarFloating)
  1127. pPaintManager->DrawCommandBarGripper(pDC, this);
  1128. pDC->SetBkMode (TRANSPARENT);
  1129. BOOL bFirst = TRUE;
  1130. for (int i = 0; i < GetControlCount(); i++)
  1131. {
  1132. CXTPControl* pControl = GetControl(i);
  1133. if (!pControl || pControl->GetParent() != this || !pControl->IsVisible())
  1134. continue;
  1135. if (pControl->GetBeginGroup() && !bFirst)
  1136. {
  1137. pPaintManager->DrawCommandBarSeparator(pDC, this, pControl);
  1138. }
  1139. bFirst = FALSE;
  1140. if (CRect().IntersectRect(rcClipBox, pControl->GetRect()))
  1141. {
  1142. CXTPFontDC font(pDC, pPaintManager->GetCommandBarFont(this, pControl->IsItemDefault()));
  1143. pControl->Draw(pDC);
  1144. }
  1145. if (pCommandBars && pCommandBars->IsCustomizeMode() && (pCommandBars->m_pDragSelected == pControl))
  1146. {
  1147. CRect rc = pControl->GetRect();
  1148. pDC->Draw3dRect(rc, 0, 0);
  1149. rc.DeflateRect(1, 1);
  1150. pDC->Draw3dRect(rc, 0, 0);
  1151. }
  1152. }
  1153. if (pCommandBars && pCommandBars->IsCustomizeMode() && !m_rcMarker.IsRectEmpty())
  1154. {
  1155. CustomizeDrawMarker(pDC);
  1156. }
  1157. #if 0
  1158. QueryPerformanceCounter((LARGE_INTEGER*)&nPerfomanceEnd);
  1159. TRACE(_T("TotalCounter = %i n"), int(nPerfomanceEnd - nPerfomanceStart));
  1160. #endif
  1161. }
  1162. void CXTPCommandBar::CustomizeDrawMarker(CDC* pDC)
  1163. {
  1164. CBrush brush(GetXtremeColor(COLOR_3DFACE));
  1165. CBrush* pBrush = (CBrush*)pDC->SelectObject(&brush);
  1166. if (m_bVerticalMarker)
  1167. {
  1168. pDC->PatBlt(m_rcMarker.left, m_rcMarker.top, 1, m_rcMarker.Height(), PATINVERT);
  1169. pDC->PatBlt(m_rcMarker.left + 1, m_rcMarker.top + 1, 1, m_rcMarker.Height() - 2, PATINVERT);
  1170. pDC->PatBlt(m_rcMarker.left + 2, m_rcMarker.top + 2, m_rcMarker.Width() - 4, 2, PATINVERT);
  1171. pDC->PatBlt(m_rcMarker.right - 1, m_rcMarker.top, 1, m_rcMarker.Height(), PATINVERT);
  1172. pDC->PatBlt(m_rcMarker.right - 2, m_rcMarker.top + 1, 1, m_rcMarker.Height() - 2, PATINVERT);
  1173. }
  1174. else
  1175. {
  1176. pDC->PatBlt(m_rcMarker.left, m_rcMarker.top, m_rcMarker.Width(), 1, PATINVERT);
  1177. pDC->PatBlt(m_rcMarker.left + 1, m_rcMarker.top + 1, m_rcMarker.Width() - 2, 1, PATINVERT);
  1178. pDC->PatBlt(m_rcMarker.left + 2, m_rcMarker.top + 2, 2, m_rcMarker.Height() - 4, PATINVERT);
  1179. pDC->PatBlt(m_rcMarker.left, m_rcMarker.bottom - 1, m_rcMarker.Width(), 1, PATINVERT);
  1180. pDC->PatBlt(m_rcMarker.left + 1, m_rcMarker.bottom - 2, m_rcMarker.Width() - 2, 1, PATINVERT);
  1181. }
  1182. pDC->SelectObject(pBrush);
  1183. }
  1184. int CXTPCommandBar::FindAccel(TCHAR chAccel) const
  1185. {
  1186. for (int i = 0; i < GetControlCount(); i++)
  1187. {
  1188. CXTPControl* pControl = GetControl(i);
  1189. if (!pControl || pControl->GetParent() != this || !pControl->IsVisible())
  1190. continue;
  1191. CString strCaption = pControl->GetCaption();
  1192. int nAmdIndex = strCaption.Find(_T('&'));
  1193. if (nAmdIndex == -1 || nAmdIndex == strCaption.GetLength() - 1)
  1194. continue;
  1195. TCHAR ch = CXTPShortcutManager::ToUpper(strCaption[nAmdIndex + 1]);
  1196. if (chAccel == ch)
  1197. {
  1198. return pControl->GetIndex();
  1199. }
  1200. }
  1201. return -1;
  1202. }
  1203. int CXTPCommandBar::FindAccelEx(UINT chAccel, BOOL& bSelectOnly) const
  1204. {
  1205. int nItem = m_pControls->GetNext(m_nSelected, +1);
  1206. if (nItem == -1)
  1207. return -1;
  1208. bSelectOnly = FALSE;
  1209. int nStart = nItem;
  1210. int nAmpCondidate = -1, nCondidate = -1;
  1211. do
  1212. {
  1213. CXTPControl* pControl = GetControl(nItem);
  1214. ASSERT(pControl);
  1215. if (!pControl)
  1216. return -1;
  1217. CString strCaption = pControl->GetCaption();
  1218. if (!strCaption.IsEmpty() && pControl->GetEnabled())
  1219. {
  1220. int nAmpIndex = strCaption.Find(_T('&'));
  1221. BOOL bFound = nAmpIndex > -1 && nAmpIndex < strCaption.GetLength() - 1;
  1222. if (CXTPShortcutManager::CompareAccelKey(strCaption[bFound ? nAmpIndex + 1 : 0], chAccel))
  1223. {
  1224. if (bFound)
  1225. {
  1226. if (nAmpCondidate == -1)
  1227. nAmpCondidate = pControl->GetIndex();
  1228. else
  1229. {
  1230. bSelectOnly = TRUE;
  1231. return nAmpCondidate;
  1232. }
  1233. }
  1234. else
  1235. {
  1236. if (nCondidate == -1)
  1237. nCondidate = pControl->GetIndex();
  1238. else
  1239. {
  1240. bSelectOnly = TRUE;
  1241. }
  1242. }
  1243. }
  1244. }
  1245. nItem = m_pControls->GetNext(nItem, +1, TRUE, FALSE, FALSE);
  1246. }
  1247. while (nItem != nStart);
  1248. return nAmpCondidate != -1 ? nAmpCondidate : nCondidate;
  1249. }
  1250. CFrameWnd* CXTPCommandBar::GetFrameSite() const
  1251. {
  1252. CWnd* pSite = GetSite();
  1253. return pSite && pSite->IsFrameWnd() ? (CFrameWnd*)pSite : NULL;
  1254. }
  1255. CWnd* CXTPCommandBar::GetSite() const
  1256. {
  1257. CXTPCommandBars* pCommandBars = GetCommandBars();
  1258. if (pCommandBars)
  1259. return pCommandBars->GetSite();
  1260. CXTPCommandBar* pRoot = GetRootParent();
  1261. if (pRoot->m_pSite) return pRoot->m_pSite;
  1262. if (pRoot->m_hWnd) return pRoot->GetOwner();
  1263. return AfxGetMainWnd();
  1264. }
  1265. CWnd* CXTPCommandBar::GetOwnerSite() const
  1266. {
  1267. CXTPCommandBar* pRoot = (CXTPCommandBar*)this;
  1268. CXTPCommandBar* pParent = pRoot->GetParentCommandBar();
  1269. while (pRoot)
  1270. {
  1271. if (pRoot->m_pOwner != NULL)
  1272. return pRoot->m_pOwner;
  1273. if (pRoot->m_hWndOwner != NULL)
  1274. return CWnd::FromHandle(pRoot->m_hWndOwner);
  1275. if (!pParent)
  1276. return pRoot->GetSite();
  1277. pRoot = pParent;
  1278. pParent = pRoot->GetParentCommandBar();
  1279. }
  1280. ASSERT(FALSE);
  1281. return NULL;
  1282. }
  1283. CXTPCommandBar* CXTPCommandBar::GetRootParent() const
  1284. {
  1285. CXTPCommandBar* pRoot = (CXTPCommandBar*)this;
  1286. CXTPCommandBar* pParent = pRoot->GetParentCommandBar();
  1287. while (pParent != NULL)
  1288. {
  1289. pRoot = pParent;
  1290. pParent = pRoot->GetParentCommandBar();
  1291. }
  1292. return pRoot;
  1293. }
  1294. CXTPCommandBars* CXTPCommandBar::GetCommandBars() const
  1295. {
  1296. const CXTPCommandBar* pCommandBar = this;
  1297. do
  1298. {
  1299. if (pCommandBar->m_pCommandBars)
  1300. return pCommandBar->m_pCommandBars;
  1301. pCommandBar = pCommandBar->GetParentCommandBar();
  1302. }
  1303. while (pCommandBar != NULL);
  1304. return NULL;
  1305. }
  1306. BOOL CXTPCommandBar::IsCustomizeMode() const
  1307. {
  1308. CXTPCommandBars* pCommandBars = GetCommandBars();
  1309. return pCommandBars ? pCommandBars->IsCustomizeMode() : FALSE;
  1310. }
  1311. DROPEFFECT CXTPCommandBar::OnCustomizeDragEnter(CXTPControl* pDataObject, CPoint point)
  1312. {
  1313. m_rcMarker.SetRectEmpty();
  1314. return OnCustomizeDragOver(pDataObject, point);
  1315. }
  1316. void CXTPCommandBar::OnCustomizeDragLeave()
  1317. {
  1318. if (!m_rcMarker.IsRectEmpty())
  1319. {
  1320. m_rcMarker.SetRectEmpty();
  1321. Redraw();
  1322. }
  1323. }
  1324. void CXTPCommandBar::CustomizeFindDropIndex(CXTPControl* pDataObject, const CPoint& point,
  1325. CRect& rcMarker, int& nDropIndex, BOOL& bDropAfter)
  1326. {
  1327. CXTPControl* pControlMarker = NULL;
  1328. int nOffset = -1;
  1329. int nCount = GetControlCount();
  1330. BOOL bVert = (m_barPosition == xtpBarLeft || m_barPosition == xtpBarRight || m_barType == xtpBarTypePopup);
  1331. for (int i = 0; i < nCount; i++)
  1332. {
  1333. CXTPControl* pControl = GetControl(i);
  1334. if (!pControl->IsVisible() || !pControl->IsCustomizeMovable())
  1335. continue;
  1336. CRect rc = pControl->GetRect();
  1337. if (!m_bMultiLine)
  1338. {
  1339. if (pControl->GetWrap())
  1340. {
  1341. nOffset = -1;
  1342. if (!bVert && rc.top > point.y) break;
  1343. else if (bVert && rc.right < point.x) break;
  1344. }
  1345. }
  1346. else if (!bVert)
  1347. {
  1348. if (point.y < rc.top || point. y > rc.bottom)
  1349. continue;
  1350. }
  1351. else
  1352. {
  1353. if (point.x < rc.left || point. x > rc.right)
  1354. continue;
  1355. }
  1356. if (bVert)
  1357. {
  1358. if (nOffset == -1 || nOffset > abs(rc.CenterPoint().y - point.y))
  1359. {
  1360. nOffset = abs(rc.CenterPoint().y - point.y);
  1361. pControlMarker = pControl;
  1362. bDropAfter = rc.CenterPoint().y < point.y;
  1363. if (bDropAfter)
  1364. {
  1365. if (i >= nCount - 1 || GetControl(i + 1)->GetBeginGroup())
  1366. rcMarker.SetRect(rc.left, rc.bottom - 6, rc.right, rc.bottom);
  1367. else
  1368. rcMarker.SetRect(rc.left, rc.bottom, rc.right, rc.bottom + 6);
  1369. }
  1370. else
  1371. {
  1372. rcMarker.SetRect(rc.left, rc.top, rc.right, rc.top + 6);
  1373. }
  1374. }
  1375. }
  1376. else
  1377. {
  1378. if (nOffset == -1 || nOffset > abs(rc.CenterPoint().x - point.x))
  1379. {
  1380. nOffset = abs(rc.CenterPoint().x - point.x);
  1381. pControlMarker = pControl;
  1382. bDropAfter = rc.CenterPoint().x < point.x;
  1383. if (bDropAfter)
  1384. {
  1385. if (i >= nCount - 1 || GetControl(i + 1)->GetBeginGroup() || GetControl(i + 1)->GetWrap())
  1386. rcMarker.SetRect(rc.right - 6, rc.top, rc.right, rc.bottom);
  1387. else
  1388. rcMarker.SetRect(rc.right, rc.top, rc.right + 6, rc.bottom);
  1389. }
  1390. else
  1391. {
  1392. rcMarker.SetRect(rc.left, rc.top, rc.left + 6, rc.bottom);
  1393. }
  1394. }
  1395. }
  1396. m_bVerticalMarker = bVert;
  1397. }
  1398. if (pControlMarker == NULL)
  1399. {
  1400. CRect rc;
  1401. GetClientRect(&rc);
  1402. if (IsRibbonBar())
  1403. {
  1404. rcMarker.SetRectEmpty();
  1405. }
  1406. else
  1407. {
  1408. rcMarker.SetRect(rc.left + 2, rc.top + 2, rc.left + 8, rc.bottom - 2);
  1409. bDropAfter = TRUE;
  1410. }
  1411. nDropIndex = -1;
  1412. m_bVerticalMarker = FALSE;
  1413. }
  1414. else
  1415. {
  1416. nDropIndex = pControlMarker->GetIndex();
  1417. }
  1418. if (pDataObject == pControlMarker)
  1419. rcMarker.SetRectEmpty();
  1420. }
  1421. DROPEFFECT CXTPCommandBar::OnCustomizeDragOver(CXTPControl* pDataObject, CPoint point)
  1422. {
  1423. if (!IsCustomizable() || !(GetStyle() & WS_VISIBLE))
  1424. return DROPEFFECT_NONE;
  1425. ASSERT(pDataObject);
  1426. CRect rcMarker;
  1427. int nDropIndex;
  1428. BOOL bDropAfter;
  1429. CustomizeFindDropIndex (pDataObject, point, rcMarker, nDropIndex, bDropAfter);
  1430. DROPEFFECT dropEffect = (DROPEFFECT)-1;
  1431. CXTPControl* pControl = m_pControls->HitTest(point);
  1432. if (pControl)
  1433. {
  1434. if (GetParentCommandBar() == NULL && m_nPopuped != pControl->GetIndex())
  1435. {
  1436. XTPMouseManager()->SendTrackLost();
  1437. }
  1438. pControl->OnCustomizeDragOver(pDataObject, point, dropEffect);
  1439. }
  1440. if (!pDataObject->IsCustomizeDragOverAvail(this, point, dropEffect))
  1441. return DROPEFFECT_NONE;
  1442. m_rcMarker = rcMarker;
  1443. Redraw();
  1444. return dropEffect;
  1445. }
  1446. void CXTPCommandBar::OnCustomizeDrop(CXTPControl* pDataObject, DROPEFFECT& dropEffect, CPoint ptDrop, CPoint ptDrag)
  1447. {
  1448. CXTPCommandBars* pCommandBars = GetCommandBars();
  1449. ASSERT(pCommandBars);
  1450. if (!pCommandBars)
  1451. return;
  1452. CRect rcMarker;
  1453. int nDropIndex;
  1454. BOOL bDropAfter;
  1455. CustomizeFindDropIndex (pDataObject, ptDrop, rcMarker, nDropIndex, bDropAfter);
  1456. if (nDropIndex == -1 || pDataObject != GetControl(nDropIndex))
  1457. {
  1458. if (bDropAfter) nDropIndex++;
  1459. SetPopuped(-1);
  1460. SetSelected(-1);
  1461. BOOL bBeginGroup = FALSE;
  1462. if (bDropAfter == FALSE && nDropIndex >= 0 && nDropIndex < GetControlCount())
  1463. {
  1464. bBeginGroup = GetControl(nDropIndex)->GetBeginGroup();
  1465. if (bBeginGroup)
  1466. {
  1467. GetControl(nDropIndex)->SetBeginGroup(FALSE);
  1468. }
  1469. }
  1470. CXTPControl* pClone = m_pControls->AddClone(pDataObject, nDropIndex);
  1471. pClone->SetBeginGroup(bBeginGroup);
  1472. pCommandBars->SetDragControl(pClone);
  1473. }
  1474. else
  1475. {
  1476. if (abs(ptDrag.x - ptDrop.x) > 4 || abs(ptDrag.y - ptDrop.y) > 4)
  1477. {
  1478. CXTPControl* pControl = GetControl(nDropIndex);
  1479. ASSERT(pDataObject == pControl);
  1480. pControl->SetBeginGroup(bDropAfter && nDropIndex != 0);
  1481. }
  1482. dropEffect = DROPEFFECT_CANCEL;
  1483. }
  1484. OnRecalcLayout();
  1485. m_rcMarker.SetRectEmpty();
  1486. Redraw();
  1487. }
  1488. void CXTPCommandBar::OnRButtonDown(UINT nFlags, CPoint point)
  1489. {
  1490. CXTPControl* pControl = m_pControls->HitTest(point);
  1491. if (pControl && pControl->OnRButtonDown(point))
  1492. return;
  1493. if (pControl && m_bCustomizable && IsCustomizeMode())
  1494. {
  1495. if (pControl->IsVisible() && pControl->IsCustomizeMovable())
  1496. {
  1497. SetPopuped(-1);
  1498. SetSelected(-1);
  1499. CXTPCommandBars* pCommandBars = GetCommandBars();
  1500. ASSERT(pCommandBars);
  1501. CXTPCustomizeDropSource* pDropSource = pCommandBars->GetDropSource();
  1502. ASSERT(pDropSource);
  1503. pCommandBars->SetDragControl(pControl);
  1504. if (pDropSource->GetSheet())
  1505. {
  1506. ClientToScreen(&point);
  1507. pDropSource->GetSheet()->ContextMenu(point);
  1508. }
  1509. }
  1510. return;
  1511. }
  1512. CWnd::OnRButtonDown(nFlags, point);
  1513. }
  1514. void CXTPCommandBar::InvalidateParents()
  1515. {
  1516. Redraw();
  1517. CXTPCommandBar* pCommandBar = GetParentCommandBar();
  1518. if (pCommandBar) pCommandBar->InvalidateParents();
  1519. }
  1520. void CXTPCommandBar::OnControlSelected(BOOL bSelected, CXTPControl* pControl)
  1521. {
  1522. if (!pControl)
  1523. return;
  1524. GetSite()->SendMessage(WM_XTP_CONTROLSELECTED, bSelected ? (WPARAM)pControl : 0);
  1525. CXTPCommandBars* pCommandBars = GetCommandBars();
  1526. if (pCommandBars)
  1527. {
  1528. pCommandBars->m_nIDHelpTracking = bSelected ? pControl->GetHelpId() : 0;
  1529. }
  1530. if (pControl && (pControl->GetIndex() == m_nClickedControl))
  1531. {
  1532. if (!bSelected)
  1533. m_nClickedControl = -1;
  1534. return;
  1535. }
  1536. m_nClickedControl = -1;
  1537. SetStatusText(bSelected ? pControl->GetDescription() : _T(""));
  1538. }
  1539. BOOL CXTPCommandBar::SetStatusText(const CString& strDescription)
  1540. {
  1541. CXTPCommandBars* pCommandBars = GetCommandBars();
  1542. CWnd* pOwner = pCommandBars ? pCommandBars->GetSite() : GetSite();
  1543. if (pCommandBars && !pCommandBars->GetCommandBarsOptions()->bFlyByStatus)
  1544. return TRUE;
  1545. if (strDescription.IsEmpty())
  1546. {
  1547. pOwner->SendMessage(WM_POPMESSAGESTRING, AFX_IDS_IDLEMESSAGE);
  1548. }
  1549. else
  1550. {
  1551. pOwner->SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)(LPCTSTR)strDescription);
  1552. }
  1553. return TRUE;
  1554. }
  1555. void CXTPCommandBar::SetPaintManager(CXTPPaintManager* pPaintManager)
  1556. {
  1557. if (m_pPaintManager)
  1558. m_pPaintManager->InternalRelease();
  1559. m_pPaintManager = pPaintManager;
  1560. if (m_pPaintManager)
  1561. {
  1562. m_pPaintManager->RefreshMetrics();
  1563. }
  1564. }
  1565. CXTPPaintManager* CXTPCommandBar::GetPaintManager() const
  1566. {
  1567. if (m_pPaintManager)
  1568. return m_pPaintManager;
  1569. CXTPCommandBars* pCommandBars = GetCommandBars();
  1570. if (pCommandBars)
  1571. return pCommandBars->GetPaintManager();
  1572. CXTPCommandBar* pRoot = GetRootParent();
  1573. if (pRoot->m_pPaintManager)
  1574. return pRoot->m_pPaintManager;
  1575. return XTPPaintManager();
  1576. }
  1577. void CXTPCommandBar::SetImageManager(CXTPImageManager* pImageManager)
  1578. {
  1579. if (m_pImageManager)
  1580. m_pImageManager->InternalRelease();
  1581. m_pImageManager = pImageManager;
  1582. }
  1583. CXTPImageManager* CXTPCommandBar::GetImageManager() const
  1584. {
  1585. if (m_pImageManager)
  1586. return m_pImageManager;
  1587. CXTPCommandBars* pCommandBars = GetCommandBars();
  1588. if (pCommandBars)
  1589. return pCommandBars->GetImageManager();
  1590. CXTPCommandBar* pRoot = GetRootParent();
  1591. if (pRoot->m_pImageManager)
  1592. return pRoot->m_pImageManager;
  1593. return XTPImageManager();
  1594. }
  1595. void CXTPCommandBar::Copy(CXTPCommandBar* pCommandBar, BOOL bRecursive)
  1596. {
  1597. m_barType = pCommandBar->m_barType;
  1598. m_barPosition = pCommandBar->m_barPosition;
  1599. m_nBarID = pCommandBar->m_nBarID;
  1600. m_dwFlags = pCommandBar->m_dwFlags;
  1601. m_dwStyle = pCommandBar->m_dwStyle;
  1602. m_strTitle = pCommandBar->m_strTitle;
  1603. m_bCustomizable = pCommandBar->m_bCustomizable;
  1604. m_nMRUWidth = pCommandBar->m_nMRUWidth;
  1605. m_szIcons = pCommandBar->m_szIcons;
  1606. m_szButtons = pCommandBar->m_szButtons;
  1607. m_pCommandBars = pCommandBar->m_pCommandBars;
  1608. m_buttonStyle = pCommandBar->m_buttonStyle;
  1609. m_pControls->Copy(pCommandBar->GetControls(), bRecursive);
  1610. }
  1611. UINT CXTPCommandBar::GetActiveDocTemplate() const
  1612. {
  1613. CXTPCommandBars* pCommandBars = GetCommandBars();
  1614. if (!pCommandBars)
  1615. return 0;
  1616. return pCommandBars->GetActiveDocTemplate();
  1617. }
  1618. void CXTPCommandBar::UpdateDocTemplateControls()
  1619. {
  1620. UINT nIDResource = GetActiveDocTemplate();
  1621. if (nIDResource == 0)
  1622. return;
  1623. BOOL bRecalcLayout = FALSE;
  1624. BOOL bValue;
  1625. for (int i = 0; i < GetControlCount(); i++)
  1626. {
  1627. CXTPControl* pControl = GetControl(i);
  1628. if (!pControl || pControl->GetParent() != this)
  1629. continue;
  1630. if (pControl->m_mapDocTemplatesAssigned.GetCount() > 0)
  1631. {
  1632. BOOL bVisible = pControl->m_mapDocTemplatesAssigned.Lookup(nIDResource, bValue);
  1633. if (pControl->SetHideFlag(xtpHideDocTemplate, !bVisible)) bRecalcLayout = TRUE;
  1634. }
  1635. if (pControl->m_mapDocTemplatesExcluded.GetCount() > 0)
  1636. {
  1637. BOOL bVisible = !pControl->m_mapDocTemplatesExcluded.Lookup(nIDResource, bValue);
  1638. if (pControl->SetHideFlag(xtpHideDocTemplate, !bVisible)) bRecalcLayout = TRUE;
  1639. }
  1640. }
  1641. if (bRecalcLayout)
  1642. m_nIdleFlags |= xtpIdleLayout;
  1643. }
  1644. void CXTPCommandBar::SetFlags(DWORD dwFlagsAdd, DWORD dwFlagsRemove)
  1645. {
  1646. m_dwFlags |= dwFlagsAdd;
  1647. m_dwFlags &= ~dwFlagsRemove;
  1648. }
  1649. LRESULT CXTPCommandBar::OnHelpHitTest(WPARAM, LPARAM lParam)
  1650. {
  1651. ASSERT_VALID(this);
  1652. CXTPControl* pControl = m_pControls->HitTest(CPoint((DWORD)lParam));
  1653. if (pControl != NULL)
  1654. return HID_BASE_COMMAND + pControl->GetHelpId();
  1655. UINT nID = _AfxGetDlgCtrlID(m_hWnd);
  1656. return nID != 0 ? HID_BASE_CONTROL + nID : 0;
  1657. }
  1658. LRESULT CXTPCommandBar::OnNcHitTest(CPoint point)
  1659. {
  1660. if (IsHelpMode())
  1661. {
  1662. ScreenToClient(&point);
  1663. CXTPControl* pControl = m_pControls->HitTest(point);
  1664. if (pControl && pControl->GetID() <= 0 && IsPopupControlType(pControl->GetType()))
  1665. return HTMENU;
  1666. return HTCLIENT;
  1667. }
  1668. return (LRESULT)CWnd::OnNcHitTest(point);
  1669. }
  1670. void CXTPCommandBar::OnNcLButtonDown(UINT nHitTest, CPoint point)
  1671. {
  1672. if (IsHelpMode())
  1673. {
  1674. ScreenToClient(&point);
  1675. OnLButtonDown(0, point);
  1676. return;
  1677. }
  1678. CWnd::OnNcLButtonDown(nHitTest, point);
  1679. }
  1680. void CXTPCommandBar::SetWidth(int nWidth)
  1681. {
  1682. m_nMRUWidth = nWidth;
  1683. }
  1684. int CXTPCommandBar::GetWidth() const
  1685. {
  1686. return m_nMRUWidth;
  1687. }
  1688. BOOL CXTPCommandBar::IsLayoutRTL() const
  1689. {
  1690. return m_hWnd && GetExStyle() & (WS_EX_LAYOUTRTL | WS_EX_RTLREADING);
  1691. }
  1692. int CXTPCommandBar::OnMouseHitTest(CPoint pt)
  1693. {
  1694. CXTPWindowRect rcWindow(this);
  1695. if (!rcWindow.PtInRect(pt))
  1696. return HTNOWHERE;
  1697. if (GetPosition() != xtpBarPopup)
  1698. return HTCLIENT;
  1699. CRgn rgn;
  1700. rgn.CreateRectRgn(0, 0, 0, 0);
  1701. int nRegion = GetWindowRgn(rgn);
  1702. if (nRegion == ERROR || nRegion == NULLREGION)
  1703. return HTCLIENT;
  1704. pt.Offset(-rcWindow.TopLeft());
  1705. if (!::PtInRegion(rgn, pt.x, pt.y))
  1706. return HTNOWHERE;
  1707. return HTCLIENT;
  1708. }
  1709. //////////////////////////////////////////////////////////////////////////
  1710. //
  1711. CCmdTarget* CXTPCommandBar::GetAccessible()
  1712. {
  1713. return this;
  1714. }
  1715. HRESULT CXTPCommandBar::GetAccessibleParent(IDispatch* FAR* ppdispParent)
  1716. {
  1717. *ppdispParent = NULL;
  1718. CXTPPopupBar* pPopupBar = DYNAMIC_DOWNCAST(CXTPPopupBar, this);
  1719. if (pPopupBar)
  1720. {
  1721. if (pPopupBar->m_pControlPopup)
  1722. {
  1723. *ppdispParent = pPopupBar->m_pControlPopup->GetIDispatch(TRUE);
  1724. return S_OK;
  1725. }
  1726. }
  1727. else if (GetSafeHwnd())
  1728. {
  1729. return AccessibleObjectFromWindow(GetSafeHwnd(), OBJID_WINDOW, IID_IDispatch, (void**)ppdispParent);
  1730. }
  1731. return E_FAIL;
  1732. }
  1733. HRESULT CXTPCommandBar::GetAccessibleChildCount(long FAR* pChildCount)
  1734. {
  1735. if (pChildCount == 0)
  1736. return E_INVALIDARG;
  1737. *pChildCount = GetControlCount();
  1738. return S_OK;
  1739. }
  1740. HRESULT CXTPCommandBar::GetAccessibleChild(VARIANT varChild, IDispatch* FAR* ppdispChild)
  1741. {
  1742. *ppdispChild = NULL;
  1743. int nChild = GetChildIndex(&varChild);
  1744. if (nChild > 0 && nChild <= GetControlCount())
  1745. {
  1746. CXTPControl* pControl = GetControl(nChild - 1);
  1747. if (pControl)
  1748. {
  1749. *ppdispChild = pControl->GetIDispatch(TRUE);
  1750. }
  1751. }
  1752. return S_OK;
  1753. }
  1754. HRESULT CXTPCommandBar::GetAccessibleName(VARIANT varChild, BSTR* pszName)
  1755. {
  1756. int nChild = GetChildIndex(&varChild);
  1757. if (nChild == CHILDID_SELF || nChild == -1)
  1758. {
  1759. CString strCaption = GetTitle();
  1760. *pszName = strCaption.AllocSysString();
  1761. return S_OK;
  1762. }
  1763. if (nChild > 0 && nChild <= GetControlCount())
  1764. {
  1765. CXTPControl* pControl = GetControl(nChild - 1);
  1766. CString strCaption = pControl->GetCaption();
  1767. CXTPPaintManager::StripMnemonics(strCaption);
  1768. if (!pControl->GetShortcutText().IsEmpty())
  1769. strCaption = strCaption + _T('t') + pControl->GetShortcutText();
  1770. *pszName = strCaption.AllocSysString();
  1771. return S_OK;
  1772. }
  1773. return E_INVALIDARG;
  1774. }
  1775. HRESULT CXTPCommandBar::GetAccessibleRole(VARIANT varChild, VARIANT* pvarRole)
  1776. {
  1777. pvarRole->vt = VT_EMPTY;
  1778. int nChild = GetChildIndex(&varChild);
  1779. if (nChild == CHILDID_SELF)
  1780. {
  1781. pvarRole->vt = VT_I4;
  1782. pvarRole->lVal = GetType() == xtpBarTypeMenuBar ? ROLE_SYSTEM_MENUBAR :
  1783. GetType() == xtpBarTypePopup ? ROLE_SYSTEM_MENUPOPUP : ROLE_SYSTEM_TOOLBAR;
  1784. return S_OK;
  1785. }
  1786. if (nChild > 0)
  1787. {
  1788. pvarRole->vt = VT_I4;
  1789. pvarRole->lVal = ROLE_SYSTEM_MENUITEM;
  1790. return S_OK;
  1791. }
  1792. return E_INVALIDARG;
  1793. }
  1794. HRESULT CXTPCommandBar::GetAccessibleState(VARIANT varChild, VARIANT* pvarState)
  1795. {
  1796. pvarState->vt = VT_I4;
  1797. pvarState->lVal = 0;
  1798. int nChild = GetChildIndex(&varChild);
  1799. if (!IsVisible())
  1800. pvarState->lVal |= STATE_SYSTEM_INVISIBLE;
  1801. if (nChild > 0 && nChild <= GetControlCount())
  1802. {
  1803. pvarState->lVal |= STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_SELECTABLE |
  1804. (m_nSelected == nChild - 1 ? STATE_SYSTEM_FOCUSED | STATE_SYSTEM_SELECTED | STATE_SYSTEM_HOTTRACKED : 0);
  1805. }
  1806. return S_OK;
  1807. }
  1808. HRESULT CXTPCommandBar::AccessibleLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild)
  1809. {
  1810. *pxLeft = *pyTop = *pcxWidth = *pcyHeight = 0;
  1811. if (!GetSafeHwnd())
  1812. return S_OK;
  1813. CRect rc;
  1814. GetWindowRect(&rc);
  1815. int nChild = GetChildIndex(&varChild);
  1816. if (nChild > 0 && nChild <= GetControlCount())
  1817. {
  1818. CXTPControl* pControl = GetControl(nChild - 1);
  1819. CRect rcControl = pControl->GetRect();
  1820. rc = CRect(CPoint(rc.left + rcControl.left, rc.top + rcControl.top), rcControl.Size());
  1821. }
  1822. *pxLeft = rc.left;
  1823. *pyTop = rc.top;
  1824. *pcxWidth = rc.Width();
  1825. *pcyHeight = rc.Height();
  1826. return S_OK;
  1827. }
  1828. HRESULT CXTPCommandBar::AccessibleHitTest(long xLeft, long yTop, VARIANT* pvarID)
  1829. {
  1830. if (pvarID == NULL)
  1831. return E_INVALIDARG;
  1832. pvarID->vt = VT_EMPTY;
  1833. if (!GetSafeHwnd())
  1834. return S_FALSE;
  1835. if (!CXTPWindowRect(this).PtInRect(CPoint(xLeft, yTop)))
  1836. return S_FALSE;
  1837. pvarID->vt = VT_I4;
  1838. pvarID->lVal = 0;
  1839. CPoint pt(xLeft, yTop);
  1840. ScreenToClient(&pt);
  1841. CXTPControl* pControl = GetControls()->HitTest(pt);
  1842. if (pControl)
  1843. {
  1844. pvarID->vt = VT_DISPATCH;
  1845. pvarID->pdispVal = pControl->GetIDispatch(TRUE);
  1846. }
  1847. return S_OK;
  1848. }
  1849. LRESULT CXTPCommandBar::OnGetObject(WPARAM wParam, LPARAM lParam)
  1850. {
  1851. if (lParam > 0 && lParam < 0xFFFFFF)
  1852. {
  1853. CXTPControl* pControl = GetControls()->FindControl((int)lParam);
  1854. if (pControl)
  1855. {
  1856. LPUNKNOWN lpUnknown = pControl->GetInterface(&IID_IAccessible);
  1857. if (!lpUnknown)
  1858. return E_FAIL;
  1859. return LresultFromObject(IID_IAccessible, wParam, lpUnknown);
  1860. }
  1861. }
  1862. if (lParam != OBJID_CLIENT && lParam != OBJID_MENU)
  1863. return (LRESULT)Default();
  1864. LPUNKNOWN lpUnknown = GetInterface(&IID_IAccessible);
  1865. if (!lpUnknown)
  1866. return E_FAIL;
  1867. return LresultFromObject(IID_IAccessible, wParam, lpUnknown);
  1868. }
  1869. void CXTPCommandBar::FilterToolTipMessage(UINT message, WPARAM wParam, LPARAM lParam)
  1870. {
  1871. if (m_pToolTipContext)
  1872. {
  1873. m_pToolTipContext->FilterToolTipMessage(this, message, wParam, lParam);
  1874. }
  1875. }
  1876. BOOL CXTPCommandBar::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  1877. {
  1878. FilterToolTipMessage(message, wParam, lParam);
  1879. return CWnd::OnWndMsg(message, wParam, lParam, pResult);
  1880. }
  1881. BEGIN_INTERFACE_MAP(CXTPCommandBar, CCmdTarget)
  1882. INTERFACE_PART(CXTPCommandBar, IID_IAccessible, ExternalAccessible)
  1883. END_INTERFACE_MAP()