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

对话框与窗口

开发平台:

Visual C++

  1. // XTPCommandBars.cpp : implementation of the CXTPCommandBars 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/XTPResourceManager.h"
  23. #include "Common/XTPColorManager.h"
  24. #include "Common/XTPImageManager.h"
  25. #include "Common/XTPIntel80Helpers.h"
  26. #include "Common/XTPVc50Helpers.h"
  27. #include "Common/XTPPropExchange.h"
  28. #include "Common/XTPToolTipContext.h"
  29. #include "TabManager/XTPTabManager.h"
  30. #include "XTPDockBar.h"
  31. #include "XTPMenuBar.h"
  32. #include "XTPShortcutManager.h"
  33. #include "XTPPaintManager.h"
  34. #include "XTPKeyboardManager.h"
  35. #include "XTPMouseManager.h"
  36. #include "XTPControls.h"
  37. #include "XTPControlComboBox.h"
  38. #include "XTPCustomizeTools.h"
  39. #include "XTPCommandBars.h"
  40. #include "XTPSoundManager.h"
  41. #include "XTPControlExt.h"
  42. #include "XTPTabClientWnd.h"
  43. #include "XTPReBar.h"
  44. #ifdef _XTP_INCLUDE_RIBBON
  45. #include "Ribbon/XTPRibbonBar.h"
  46. #endif
  47. #ifdef _DEBUG
  48. #define new DEBUG_NEW
  49. #undef THIS_FILE
  50. static char THIS_FILE[] = __FILE__;
  51. #endif
  52. CRuntimeClass* CXTPCommandBars::m_pToolBarClass = RUNTIME_CLASS(CXTPToolBar);
  53. CRuntimeClass* CXTPCommandBars::m_pMenuBarClass = RUNTIME_CLASS(CXTPMenuBar);
  54. CRuntimeClass* CXTPCommandBars::m_pPopupBarClass = RUNTIME_CLASS(CXTPPopupBar);
  55. CRuntimeClass* CXTPCommandBars::m_pPopupToolBarClass = RUNTIME_CLASS(CXTPPopupToolBar);
  56. CRuntimeClass* CXTPCommandBars::m_pDockBarClass = RUNTIME_CLASS(CXTPDockBar);
  57. //////////////////////////////////////////////////////////////////////////
  58. CXTPCommandBarsContextMenus::CXTPCommandBarsContextMenus(CXTPCommandBars* pCommandBars)
  59. : CXTPCommandBarList(pCommandBars)
  60. {
  61. }
  62. CXTPCommandBar* CXTPCommandBarsContextMenus::Add(CXTPCommandBar* pPopupBar)
  63. {
  64. ASSERT_KINDOF(CXTPPopupBar, pPopupBar);
  65. m_arrBars.Add(pPopupBar);
  66. ((CXTPPopupBar*)pPopupBar)->m_bContextMenu = TRUE;
  67. return pPopupBar;
  68. }
  69. CXTPCommandBar* CXTPCommandBarsContextMenus::Add(UINT nIDBar, LPCTSTR strCaption, CMenu* pSubMenu)
  70. {
  71. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(m_pCommandBars);
  72. m_arrBars.Add(pPopupBar);
  73. pPopupBar->LoadMenu(pSubMenu);
  74. pPopupBar->SetBarID(nIDBar);
  75. pPopupBar->SetTitle(strCaption);
  76. pPopupBar->GetControls()->CreateOriginalControls();
  77. pPopupBar->m_bContextMenu = TRUE;
  78. return pPopupBar;
  79. }
  80. CXTPCommandBar* CXTPCommandBarsContextMenus::Add(UINT nIDBar)
  81. {
  82. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(m_pCommandBars);
  83. m_arrBars.Add(pPopupBar);
  84. CMenu menu;
  85. if (!menu.LoadMenu(nIDBar))
  86. return pPopupBar;
  87. CMenu* pSubMenu = menu.GetSubMenu(0);
  88. if (!pSubMenu)
  89. return pPopupBar;
  90. pPopupBar->LoadMenu(pSubMenu);
  91. pPopupBar->SetBarID(nIDBar);
  92. CString strCaption;
  93. XTPResourceManager()->GetMenuLocaleString(&menu, 0, strCaption, MF_BYPOSITION);
  94. CXTPDrawHelpers::StripMnemonics(strCaption);
  95. pPopupBar->SetTitle(strCaption);
  96. pPopupBar->GetControls()->CreateOriginalControls();
  97. pPopupBar->m_bContextMenu = TRUE;
  98. return pPopupBar;
  99. }
  100. //////////////////////////////////////////////////////////////////////////
  101. // CXTPCommandBarsOptions
  102. CXTPCommandBarsOptions::CXTPCommandBarsOptions()
  103. {
  104. bAlwaysShowFullMenus = TRUE;
  105. bShowFullAfterDelay = TRUE;
  106. bToolBarScreenTips = TRUE;
  107. bToolBarAccelTips = FALSE;
  108. bLargeIcons = FALSE;
  109. bShowExpandButtonAlways = TRUE;
  110. szIcons = szLargeIcons = CSize(0);
  111. szPopupIcons = CSize(0, 0);
  112. bSyncFloatingBars = TRUE;
  113. bDblClickFloat = FALSE;
  114. bShowTextBelowIcons = FALSE;
  115. animationType = xtpAnimateWindowsDefault;
  116. bAltDragCustomization = TRUE;
  117. bAutoHideUnusedPopups = TRUE;
  118. bDirtyState = FALSE;
  119. bShowPopupBarToolTips = FALSE;
  120. bAutoUpdateShortcuts = TRUE;
  121. keyboardCuesUse = xtpKeyboardCuesUseAll;
  122. keyboardCuesShow = xtpKeyboardCuesShowAlways;
  123. bFlyByStatus = TRUE;
  124. bUseAltNumPadKeys = FALSE;
  125. bUseSystemSaveBitsStyle = TRUE;
  126. bDisableCommandIfNoHandler = TRUE;
  127. bWrapLargePopups = FALSE;
  128. bShowKeyboardTips = FALSE;
  129. m_pCommandBars = 0;
  130. EnableAutomation();
  131. }
  132. #ifndef SPI_GETMENUUNDERLINES
  133. #define SPI_GETMENUUNDERLINES 0x100A
  134. #endif
  135. void CXTPCommandBarsOptions::ShowKeyboardCues(XTPKeyboardCuesShow keyboardCues)
  136. {
  137. keyboardCuesShow = keyboardCues;
  138. m_pCommandBars->m_bUseKeyboardCues = FALSE;
  139. m_pCommandBars->m_bKeyboardCuesVisible = keyboardCues != xtpKeyboardCuesShowNever;
  140. if (keyboardCues == xtpKeyboardCuesShowWindowsDefault)
  141. {
  142. BOOL bRetVal = TRUE;
  143. if (::SystemParametersInfo(SPI_GETMENUUNDERLINES, 0, &bRetVal, 0))
  144. {
  145. if (!bRetVal)
  146. {
  147. m_pCommandBars->m_bUseKeyboardCues = TRUE;
  148. m_pCommandBars->m_bKeyboardCuesVisible = FALSE;
  149. }
  150. }
  151. }
  152. }
  153. XTPKeyboardCuesShow CXTPCommandBarsOptions::GetShowKeyboardCues() const
  154. {
  155. return keyboardCuesShow;
  156. }
  157. CXTPCommandBars* CXTPCommandBars::CreateCommandBars()
  158. {
  159. CXTPCommandBars* pCommandBars = (CXTPCommandBars*)CXTPCommandBars::CreateObject();
  160. return pCommandBars;
  161. }
  162. // CXTPCommandBars
  163. IMPLEMENT_DYNCREATE(CXTPCommandBars, CCmdTarget)
  164. CXTPCommandBars::CXTPCommandBars()
  165. : m_pFrame (0)
  166. , m_nDefaultMenuID(0)
  167. {
  168. ZeroMemory(m_pDocks, 4 * sizeof(CXTPDockBar*));
  169. m_pDragSelected = NULL;
  170. m_bQuickCustomizeMode = m_bCustomizeMode = FALSE;
  171. m_bCustomizeAvail = FALSE;
  172. m_pDropSource = new CXTPCustomizeDropSource(this);
  173. m_pPaintManager = NULL;
  174. m_pImageManager = NULL;
  175. m_pMouseManager = NULL;
  176. m_pKeyboardManager = NULL;
  177. m_pOptions = new CXTPCommandBarsOptions;
  178. m_pOptions->m_pCommandBars = this;
  179. m_pDesignerControls = NULL;
  180. m_bIgnoreShiftMenuKey = FALSE;
  181. EnableAutomation();
  182. m_bRecalcLayout = FALSE;
  183. m_bRightToLeft = FALSE;
  184. m_pToolTipContext = new CXTPToolTipContext;
  185. m_pToolTipContext->ModifyToolTipStyle(TTS_NOPREFIX, 0);
  186. m_bUseKeyboardCues = FALSE;
  187. m_bKeyboardCuesVisible = TRUE;
  188. m_pShortcutManager = new CXTPShortcutManager(this);
  189. m_nIDHelpTracking = 0;
  190. m_bDesignerMode = FALSE;
  191. m_keyboardTips.pBar = NULL;
  192. m_keyboardTips.nLevel = 0;
  193. m_keyboardTips.nKey = 0;
  194. m_pActions = new CXTPControlActions(this);
  195. m_bEnableActions = FALSE;
  196. m_pContextMenus = new CXTPCommandBarsContextMenus(this);
  197. }
  198. CXTPCommandBars::~CXTPCommandBars()
  199. {
  200. CMDTARGET_RELEASE(m_pDragSelected);
  201. CMDTARGET_RELEASE(m_pDesignerControls);
  202. m_pContextMenus->RemoveAll();
  203. CMDTARGET_RELEASE(m_pContextMenus);
  204. RemoveAll();
  205. for (int i = 0; i < 4; i++)
  206. {
  207. if (m_pDocks[i])
  208. {
  209. m_pDocks[i]->DestroyWindow();
  210. delete m_pDocks[i];
  211. }
  212. }
  213. delete m_pDropSource;
  214. CMDTARGET_RELEASE(m_pPaintManager);
  215. CMDTARGET_RELEASE(m_pImageManager);
  216. CMDTARGET_RELEASE(m_pToolTipContext);
  217. CMDTARGET_RELEASE(m_pShortcutManager);
  218. CMDTARGET_RELEASE(m_pOptions);
  219. XTPSoundManager()->StopThread();
  220. if (m_pActions)
  221. {
  222. m_pActions->RemoveAll();
  223. CMDTARGET_RELEASE(m_pActions);
  224. }
  225. }
  226. BOOL IsToolBarVisible(CXTPToolBar* pCommandBar)
  227. {
  228. return pCommandBar&& pCommandBar->IsWindowVisible();
  229. }
  230. void CXTPCommandBars::EnableActions()
  231. {
  232. ASSERT(!m_bEnableActions);
  233. m_bEnableActions = TRUE;
  234. }
  235. CXTPControlAction* CXTPCommandBars::CreateAction(int nId)
  236. {
  237. return m_pActions->Add(nId);
  238. }
  239. CXTPControlAction* CXTPCommandBars::FindAction(int nId) const
  240. {
  241. return this == NULL ? NULL : m_pActions->FindAction(nId);
  242. }
  243. CXTPMenuBar* CXTPCommandBars::GetMenuBar() const
  244. {
  245. return DYNAMIC_DOWNCAST(CXTPMenuBar, GetToolBar(XTP_IDR_MENUBAR));
  246. }
  247. CXTPMenuBar* CXTPCommandBars::SetMenu(LPCTSTR strName, UINT nID)
  248. {
  249. CXTPMenuBar* pMenuBar = (CXTPMenuBar*) m_pMenuBarClass->CreateObject();
  250. ASSERT(pMenuBar);
  251. if (!pMenuBar)
  252. return NULL;
  253. pMenuBar->m_pCommandBars = this;
  254. pMenuBar->SetTitle(strName);
  255. pMenuBar->m_nBarID = XTP_IDR_MENUBAR;
  256. if (!pMenuBar->SetPosition(xtpBarTop) ||
  257. !pMenuBar->LoadMenuBar(nID))
  258. {
  259. delete pMenuBar;
  260. return NULL;
  261. }
  262. if (nID > 0)
  263. {
  264. pMenuBar->m_pControls->CreateOriginalControls();
  265. m_nDefaultMenuID = nID;
  266. }
  267. m_arrBars.Add(pMenuBar);
  268. return pMenuBar;
  269. }
  270. void CXTPCommandBars::RecalcFrameLayout(BOOL bDelay)
  271. {
  272. if (m_bRecalcLayout)
  273. return;
  274. if (!m_pFrame->GetSafeHwnd())
  275. return;
  276. CFrameWnd* pFrame = m_pFrame->IsFrameWnd() ? (CFrameWnd*)m_pFrame : NULL;
  277. if (pFrame)
  278. {
  279. if (bDelay)
  280. pFrame->DelayRecalcLayout(FALSE);
  281. else
  282. pFrame->RecalcLayout(FALSE);
  283. }
  284. else
  285. {
  286. CXTPClientRect rc(m_pFrame);
  287. m_pFrame->SendMessage(WM_SIZE, 0, MAKELPARAM(rc.Width(), rc.Height()));
  288. }
  289. }
  290. void CXTPCommandBars::IdleRecalcLayout()
  291. {
  292. CFrameWnd* pFrame = DYNAMIC_DOWNCAST(CFrameWnd, GetSite());
  293. if (pFrame)
  294. {
  295. if (pFrame->m_nIdleFlags & CFrameWnd::idleLayout)
  296. {
  297. pFrame->RecalcLayout(FALSE);
  298. pFrame->m_nIdleFlags &= ~CFrameWnd::idleLayout;
  299. }
  300. }
  301. }
  302. void CXTPCommandBars::OnToolBarAdded(CXTPToolBar* pToolBar)
  303. {
  304. ASSERT(pToolBar);
  305. CXTPReBar* pReBar = GetFrameReBar();
  306. if (pReBar)
  307. {
  308. pReBar->AddToolBar(pToolBar, RBBS_GRIPPERALWAYS | RBBS_BREAK);
  309. }
  310. }
  311. void CXTPCommandBars::OnToolBarRemoved(CXTPToolBar* pToolBar)
  312. {
  313. ASSERT(pToolBar);
  314. CXTPReBar* pReBar = GetFrameReBar();
  315. if (pReBar)
  316. {
  317. pReBar->DeleteToolBar(pToolBar);
  318. }
  319. }
  320. CXTPReBar* CXTPCommandBars::GetFrameReBar() const
  321. {
  322. if (!m_pFrame->GetSafeHwnd())
  323. return NULL;
  324. return DYNAMIC_DOWNCAST(CXTPReBar, m_pFrame->GetDlgItem(AFX_IDW_REBAR));
  325. }
  326. CXTPToolBar* CXTPCommandBars::AddCustomBar(LPCTSTR lpcstrCaption, UINT nID, BOOL bTearOffBar)
  327. {
  328. ASSERT(nID != 0);
  329. CXTPToolBar* pCommandBar = (CXTPToolBar*) m_pToolBarClass->CreateObject();
  330. pCommandBar->m_pCommandBars = this;
  331. XTP_COMMANDBARS_CREATEBAR cs;
  332. ZeroMemory(&cs, sizeof(cs));
  333. cs.bCustomBar = TRUE;
  334. cs.bTearOffBar = bTearOffBar;
  335. cs.lpcstrCaption = lpcstrCaption;
  336. cs.pCommandBar = pCommandBar;
  337. cs.nID = nID;
  338. m_pFrame->SendMessage(WM_XTP_CREATECOMMANDBAR, 0, (LPARAM)&cs);
  339. ASSERT(pCommandBar == cs.pCommandBar);
  340. ASSERT(pCommandBar);
  341. pCommandBar->m_strTitle = lpcstrCaption;
  342. if (!pCommandBar->SetPosition(bTearOffBar ? xtpBarFloating : xtpBarTop))
  343. {
  344. delete pCommandBar;
  345. return NULL;
  346. }
  347. m_arrBars.Add(pCommandBar);
  348. pCommandBar->SetBarID(nID);
  349. pCommandBar->m_bBuiltIn = FALSE;
  350. pCommandBar->m_bTearOff = bTearOffBar;
  351. if (!bTearOffBar) RecalcFrameLayout();
  352. OnToolBarAdded(pCommandBar);
  353. return pCommandBar;
  354. }
  355. CXTPShortcutManager* CXTPCommandBars::GetShortcutManager() const
  356. {
  357. return m_pShortcutManager;
  358. }
  359. void CXTPCommandBars::SetShortcutManager(CXTPShortcutManager* pShortcutManager)
  360. {
  361. CMDTARGET_RELEASE(m_pShortcutManager);
  362. m_pShortcutManager = pShortcutManager;
  363. }
  364. CXTPToolBar* CXTPCommandBars::Add(LPCTSTR strName, XTPBarPosition xtpPosition, CRuntimeClass* pToolbarClass)
  365. {
  366. if (!pToolbarClass)
  367. pToolbarClass = m_pToolBarClass;
  368. ASSERT(pToolbarClass && pToolbarClass->IsDerivedFrom(RUNTIME_CLASS(CXTPToolBar)));
  369. ASSERT(IsDockingPosition(xtpPosition) || xtpPosition == xtpBarFloating);
  370. if (!pToolbarClass)
  371. return NULL;
  372. CXTPToolBar* pCommandBar = (CXTPToolBar*) pToolbarClass->CreateObject();
  373. ASSERT(pCommandBar);
  374. if (!pCommandBar)
  375. return NULL;
  376. pCommandBar->m_pCommandBars = this;
  377. pCommandBar->m_strTitle = strName;
  378. if (!pCommandBar->SetPosition(xtpPosition))
  379. {
  380. delete pCommandBar;
  381. return NULL;
  382. }
  383. m_arrBars.Add(pCommandBar);
  384. return pCommandBar;
  385. }
  386. void CXTPCommandBars::EnableDocking()
  387. {
  388. const DWORD dwDockBarMap[4][2] =
  389. {
  390. { AFX_IDW_DOCKBAR_TOP, CBRS_TOP   },
  391. { AFX_IDW_DOCKBAR_BOTTOM, CBRS_BOTTOM },
  392. { AFX_IDW_DOCKBAR_LEFT, CBRS_LEFT   },
  393. { AFX_IDW_DOCKBAR_RIGHT, CBRS_RIGHT  },
  394. };
  395. CWnd* pParentFrame = GetSite();
  396. ASSERT(pParentFrame);
  397. for (int i = 0; i < 4; i++)
  398. {
  399. ASSERT(!m_pDocks[i]);
  400. CXTPDockBar* pDockBar = (CXTPDockBar*)m_pDockBarClass->CreateObject();
  401. pDockBar->m_pCommandBars = this;
  402. if (!pDockBar->Create(pParentFrame,
  403. WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE |
  404. dwDockBarMap[i][1], dwDockBarMap[i][0]))
  405. {
  406. AfxThrowResourceException();
  407. }
  408. m_pDocks[i] = pDockBar;
  409. }
  410. }
  411. CXTPDockBar* CXTPCommandBars::CanDock(CPoint pt, CXTPDockBar* pMainDock) const
  412. {
  413. CRect rc;
  414. if (pMainDock)
  415. {
  416. pMainDock->GetWindowRect(&rc);
  417. if (pMainDock->m_dwStyle & CBRS_ORIENT_HORZ &&
  418. rc.top - 20 < pt.y && rc.bottom + 20 > pt.y && rc.left - 20 < pt.x && rc.right + 20 > pt.x)
  419. return pMainDock;
  420. if (pMainDock->m_dwStyle & CBRS_ORIENT_VERT &&
  421. rc.left - 20 < pt.x && rc.right + 20 > pt.x && rc.top - 20 < pt.y && rc.bottom + 20 > pt.y)
  422. return pMainDock;
  423. }
  424. for (int i = 0; i < 4; i++)
  425. {
  426. m_pDocks[i]->GetWindowRect(&rc);
  427. if (m_pDocks[i]->m_dwStyle & CBRS_ORIENT_HORZ &&
  428. rc.top - 20 < pt.y && rc.bottom + 20 > pt.y && rc.left - 20 < pt.x && rc.right + 20 > pt.x)
  429. return m_pDocks[i];
  430. if (m_pDocks[i]->m_dwStyle & CBRS_ORIENT_VERT &&
  431. rc.left - 20 < pt.x && rc.right + 20 > pt.x && rc.top - 20 < pt.y && rc.bottom + 20 > pt.y)
  432. return m_pDocks[i];
  433. }
  434. return NULL;
  435. }
  436. BOOL CXTPCommandBars::DockCommandBar(CXTPToolBar* pBar, LPRECT lpRect, CXTPDockBar* pDockBar)
  437. {
  438. ASSERT(pDockBar);
  439. if (!pDockBar)
  440. return FALSE;
  441. if (!pBar->Create(m_pFrame, FALSE))
  442. return FALSE;
  443. pDockBar->DockCommandBar(pBar, lpRect);
  444. pBar->m_barPosition = pDockBar->GetPosition();
  445. return TRUE;
  446. }
  447. BOOL CXTPCommandBars::DockCommandBar(CXTPToolBar* pBar, XTPBarPosition xtpPosition)
  448. {
  449. CXTPDockBar* pDockBar = GetDockBar(xtpPosition);
  450. ASSERT(pDockBar);
  451. return DockCommandBar(pBar, NULL, pDockBar);
  452. }
  453. BOOL CXTPCommandBars::FloatCommandBar(CXTPToolBar* pBar)
  454. {
  455. if (!pBar->Create(m_pFrame, TRUE))
  456. {
  457. return FALSE;
  458. }
  459. if (pBar->m_pDockBar != NULL)
  460. {
  461. pBar->m_pDockBar->RemoveCommandBar(pBar);
  462. pBar->m_pDockBar = NULL;
  463. }
  464. pBar->m_barPosition = xtpBarFloating;
  465. return TRUE;
  466. }
  467. void CXTPCommandBars::DelayRedrawCommandBars()
  468. {
  469. for (int i = 0; i < GetCount(); i++)
  470. {
  471. CXTPToolBar* pBar = GetAt(i);
  472. if (pBar->IsVisible() && pBar->GetSafeHwnd())
  473. {
  474. pBar->DelayRedraw();
  475. }
  476. }
  477. }
  478. void CXTPCommandBars::InvalidateCommandBars()
  479. {
  480. for (int i = 0; i < GetCount(); i++)
  481. {
  482. CXTPToolBar* pBar = GetAt(i);
  483. if (pBar->IsVisible() && pBar->GetSafeHwnd())
  484. {
  485. pBar->Redraw();
  486. }
  487. }
  488. }
  489. void CXTPCommandBars::RedrawCommandBars()
  490. {
  491. m_bRecalcLayout = TRUE;
  492. for (int i = 0; i < GetCount(); i++)
  493. {
  494. CXTPToolBar* pBar = GetAt(i);
  495. for (int j = 0; j < pBar->GetControlCount(); j++)
  496. {
  497. pBar->GetControl(j)->OnThemeChanged();
  498. }
  499. if (pBar->IsVisible())
  500. {
  501. pBar->OnRecalcLayout();
  502. }
  503. }
  504. CWnd* pSite = GetSite();
  505. CMDIFrameWnd* pMDIFrame = DYNAMIC_DOWNCAST(CMDIFrameWnd, pSite);
  506. if (pMDIFrame)
  507. {
  508. CXTPTabClientWnd* pClient = DYNAMIC_DOWNCAST(CXTPTabClientWnd, CWnd::FromHandle(pMDIFrame->m_hWndMDIClient));
  509. if (pClient)
  510. pClient->Refresh();
  511. }
  512. for (HWND hWndChild = ::GetTopWindow(pSite->m_hWnd); hWndChild != NULL;
  513. hWndChild = GetWindow(hWndChild, GW_HWNDNEXT))
  514. {
  515. CWnd* pWnd = CWnd::FromHandlePermanent(hWndChild);
  516. if (pWnd != NULL)
  517. pWnd->Invalidate(FALSE);
  518. }
  519. m_bRecalcLayout = FALSE;
  520. RecalcFrameLayout();
  521. pSite->SetWindowPos(0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
  522. pSite->SendMessage(WM_NCPAINT);
  523. }
  524. BOOL CXTPCommandBar::IsKeyboardCuesVisible() const
  525. {
  526. CXTPCommandBars* pCommandBars = GetCommandBars();
  527. if (!pCommandBars)
  528. return TRUE;
  529. return pCommandBars->m_bKeyboardCuesVisible;
  530. }
  531. CXTPCommandBarKeyboardTip::CXTPCommandBarKeyboardTip(CXTPCommandBars* pCommandBars, CCmdTarget* pOwner, LPCTSTR lpszCaption, CPoint pt, DWORD dwAlign, BOOL bEnabled)
  532. {
  533. m_pOwner = pOwner;
  534. m_strCaption = lpszCaption;
  535. m_pCommandBars = pCommandBars;
  536. m_pt = pt;
  537. m_strTip.Empty();
  538. m_bEnabled = bEnabled;
  539. m_dwAlign = dwAlign;
  540. m_bVisible = TRUE;
  541. m_bExplicit = FALSE;
  542. }
  543. BEGIN_MESSAGE_MAP(CXTPCommandBarKeyboardTip, CWnd)
  544. ON_WM_PAINT()
  545. ON_WM_NCHITTEST_EX()
  546. END_MESSAGE_MAP()
  547. LRESULT CXTPCommandBarKeyboardTip::OnNcHitTest(CPoint /*point*/)
  548. {
  549. return (LRESULT)HTTRANSPARENT;
  550. }
  551. void CXTPCommandBarKeyboardTip::OnPaint()
  552. {
  553. CPaintDC dc(this);
  554. m_pCommandBars->GetPaintManager()->DrawKeyboardTip(&dc, this, FALSE);
  555. }
  556. BOOL CXTPCommandBar::IsKeyboardTipsVisible() const
  557. {
  558. CXTPCommandBars* pCommandBars = GetCommandBars();
  559. if (pCommandBars && pCommandBars->m_keyboardTips.pBar == this && pCommandBars->m_keyboardTips.nLevel > 0)
  560. return pCommandBars->m_keyboardTips.nLevel;
  561. return FALSE;
  562. }
  563. void CXTPCommandBar::CreateKeyboardTips()
  564. {
  565. CXTPCommandBars* pCommandBars = GetCommandBars();
  566. if (!pCommandBars)
  567. return;
  568. for (int i = 0; i < GetControlCount(); i++)
  569. {
  570. CXTPControl* pControl = GetControl(i);
  571. if (!pControl->IsVisible() || pControl->GetCaption().IsEmpty() || (pControl->GetFlags() & xtpFlagSkipFocus))
  572. continue;
  573. if (pControl->GetType() == xtpControlGallery)
  574. continue;
  575. CPoint pt(pControl->GetRect().left + 12, pControl->GetRect().bottom - 11);
  576. CXTPCommandBarKeyboardTip* pWnd = new CXTPCommandBarKeyboardTip(pCommandBars, pControl, pControl->GetCaption(), pt, DT_TOP, pControl->GetEnabled());
  577. if (!pControl->GetKeyboardTip().IsEmpty())
  578. {
  579. pWnd->m_strTip = pControl->GetKeyboardTip();
  580. }
  581. pCommandBars->m_keyboardTips.arr.Add(pWnd);
  582. }
  583. if (GetParentCommandBar() == 0)
  584. {
  585. for (int j = 0; j < pCommandBars->GetCount(); j++)
  586. {
  587. CXTPToolBar* pToolBar = pCommandBars->GetAt(j);
  588. if (pToolBar == this || !IsToolBarVisible(pToolBar))
  589. continue;
  590. CXTPWindowRect rc(pToolBar);
  591. CPoint pt(rc.left, rc.top);
  592. CXTPCommandBarKeyboardTip* pWnd = new CXTPCommandBarKeyboardTip(pCommandBars, pToolBar, pToolBar->GetTitle(), pt, DT_TOP | DT_LEFT, TRUE);
  593. pCommandBars->m_keyboardTips.arr.Add(pWnd);
  594. }
  595. }
  596. }
  597. #ifndef LWA_ALPHA
  598. #define LWA_ALPHA               0x00000002
  599. #endif
  600. #ifndef WS_EX_LAYERED
  601. #define WS_EX_LAYERED           0x00080000
  602. #endif
  603. typedef BOOL (WINAPI *PFNSETLAYEREDWINDOWATTRIBUTES) (HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
  604. void CXTPCommandBars::ShowKeyboardTips(CXTPCommandBar* pCommandBar, int nLevel)
  605. {
  606. HideKeyboardTips();
  607. if (!m_pOptions->bShowKeyboardTips)
  608. return;
  609. if (!pCommandBar->GetSafeHwnd())
  610. return;
  611. GetToolTipContext()->CancelToolTips();
  612. pCommandBar->UpdateWindow();
  613. m_keyboardTips.pBar = pCommandBar;
  614. m_keyboardTips.nLevel = nLevel;
  615. m_keyboardTips.nKey = 0;
  616. pCommandBar->CreateKeyboardTips();
  617. if (m_keyboardTips.arr.GetSize() == 0)
  618. {
  619. m_keyboardTips.pBar = NULL;
  620. return;
  621. }
  622. CXTPPaintManager* pPaintManager = GetPaintManager();
  623. CClientDC dc(pCommandBar);
  624. CXTPFontDC font(&dc, &pPaintManager->m_fontToolTip);
  625. int i;
  626. for (i = (int)m_keyboardTips.arr.GetSize() - 1; i >= 0; i--)
  627. {
  628. CXTPCommandBarKeyboardTip* pWnd = m_keyboardTips.arr[i];
  629. pWnd->m_bExplicit = !pWnd->m_strTip.IsEmpty();
  630. if (pWnd->m_bExplicit)
  631. continue;
  632. if (pWnd->m_strCaption.IsEmpty())
  633. {
  634. pWnd->DestroyWindow();
  635. delete pWnd;
  636. m_keyboardTips.arr.RemoveAt(i);
  637. continue;
  638. }
  639. pWnd->m_strCaption.MakeUpper();
  640. int nAmdIndex = pWnd->m_strCaption.Find(_T('&'));
  641. if (nAmdIndex != -1 && pWnd->m_strCaption[nAmdIndex + 1] == _T('&'))
  642. nAmdIndex = FIND_S(pWnd->m_strCaption, _T('&'), nAmdIndex + 2);
  643. if (pWnd->m_strPrefix.IsEmpty())
  644. pWnd->m_strTip = pWnd->m_strCaption.GetAt(nAmdIndex + 1); // nAmdIndex can be -1.
  645. else pWnd->m_strTip = pWnd->m_strPrefix;
  646. }
  647. int nCount = (int)m_keyboardTips.arr.GetSize();
  648. for (i = 0; i < nCount; i++)
  649. {
  650. CXTPCommandBarKeyboardTip* pWndBase = m_keyboardTips.arr[i];
  651. CString strTip = pWndBase->m_strTip;
  652. CArray<CXTPCommandBarKeyboardTip*, CXTPCommandBarKeyboardTip*> arr;
  653. arr.Add(pWndBase);
  654. int j;
  655. CString strUsed = _T("& ");
  656. for ( j = i + 1; j < nCount; j++)
  657. {
  658. CXTPCommandBarKeyboardTip* pWnd = m_keyboardTips.arr[j];
  659. if (pWnd->m_strTip[0] == strTip[0])
  660. {
  661. arr.Add(pWnd);
  662. if (pWnd->m_strTip.GetLength() == 2)
  663. {
  664. strUsed += pWnd->m_strTip[1];
  665. }
  666. }
  667. }
  668. if (arr.GetSize() < 2)
  669. continue;
  670. int k = 1;
  671. for (j = 0; j < (int)arr.GetSize(); j++)
  672. {
  673. CXTPCommandBarKeyboardTip* pWnd = arr[j];
  674. if (pWnd->m_strTip.GetLength() > 1)
  675. continue;
  676. TCHAR chAccel = 0;
  677. CString& strCaption = pWnd->m_strCaption;
  678. int n;
  679. for (n = 0; n < strCaption.GetLength() - 1; n++)
  680. {
  681. if ((strCaption[n] == ' ') && (strUsed.Find(strCaption[n + 1]) == -1))
  682. {
  683. chAccel = strCaption[n + 1];
  684. strUsed += chAccel;
  685. break;
  686. }
  687. }
  688. if (chAccel == 0)
  689. {
  690. int nStart = strCaption[0] == _T('&') ? 1 : 0;
  691. if (strCaption[nStart] == pWnd->m_strTip[0])
  692. nStart++;
  693. for (n = nStart; n < strCaption.GetLength(); n++)
  694. {
  695. if (strUsed.Find(strCaption[n]) == -1)
  696. {
  697. chAccel = pWnd->m_strCaption[n];
  698. strUsed += chAccel;
  699. break;
  700. }
  701. }
  702. }
  703. if (chAccel == 0)
  704. {
  705. CString str;
  706. str.Format(_T("%i"), k);
  707. chAccel = str[0];
  708. k++;
  709. }
  710. pWnd->m_strTip += chAccel;
  711. }
  712. }
  713. BOOL bLayoutRTL = IsLayoutRTL();
  714. for (i = 0; i < nCount; i++)
  715. {
  716. CXTPCommandBarKeyboardTip* pWnd = m_keyboardTips.arr[i];
  717. if (!pWnd->m_bVisible)
  718. continue;
  719. CSize sz = dc.GetTextExtent(pWnd->m_strTip);
  720. sz = CSize(max(sz.cx + 6, 16), max(sz.cy + 2, 15));
  721. CPoint pt = pWnd->m_pt;
  722. if (DYNAMIC_DOWNCAST(CWnd, pWnd->m_pOwner) == 0)
  723. pCommandBar->ClientToScreen(&pt);
  724. CRect rc(CPoint(pt.x - (pWnd->m_dwAlign & DT_CENTER ?  sz.cx / 2 : bLayoutRTL || (pWnd->m_dwAlign & DT_RIGHT) ? sz.cx : 0),
  725. pt.y - (pWnd->m_dwAlign & DT_VCENTER ?  sz.cy / 2 : pWnd->m_dwAlign & DT_BOTTOM ? sz.cy : 0)), sz);
  726. BOOL bLayered = pPaintManager->m_pfnSetLayeredWindowAttributes && !pWnd->m_bEnabled;
  727. pWnd->CreateEx((bLayered ? WS_EX_LAYERED : 0) | WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_SAVEBITS), 0, WS_POPUP, rc, pCommandBar, 0);
  728. pWnd->SetWindowPos(&CWnd::wndTop, rc.left, rc.top, rc.Width(), rc.Height(),  SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  729. pPaintManager->DrawKeyboardTip(0, pWnd, TRUE);
  730. if (bLayered)
  731. {
  732. ((PFNSETLAYEREDWINDOWATTRIBUTES)pPaintManager->m_pfnSetLayeredWindowAttributes)(pWnd->m_hWnd, 0x00, 150, LWA_ALPHA);
  733. }
  734. }
  735. for (i = 0; i < nCount; i++)
  736. {
  737. CXTPCommandBarKeyboardTip* pWnd = m_keyboardTips.arr[i];
  738. if (pWnd->m_bVisible)
  739. pWnd->SetWindowPos(0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  740. }
  741. }
  742. void CXTPCommandBars::HideKeyboardTips()
  743. {
  744. if (m_keyboardTips.arr.GetSize() == 0)
  745. return;
  746. for (int i = 0; i < (int)m_keyboardTips.arr.GetSize(); i++)
  747. {
  748. m_keyboardTips.arr[i]->DestroyWindow();
  749. delete m_keyboardTips.arr[i];
  750. }
  751. m_keyboardTips.arr.RemoveAll();
  752. m_keyboardTips.pBar = 0;
  753. m_keyboardTips.nLevel = 0;
  754. m_keyboardTips.nKey = 0;
  755. }
  756. void CXTPCommandBars::ShowKeyboardCues(BOOL bShow)
  757. {
  758. if (m_bCustomizeMode)
  759. bShow = TRUE;
  760. if (m_bUseKeyboardCues && m_bKeyboardCuesVisible != bShow)
  761. {
  762. m_bKeyboardCuesVisible = bShow;
  763. InvalidateCommandBars();
  764. }
  765. }
  766. void CXTPCommandBars::OnTrackingModeChanged(CXTPCommandBar* pCommandBar, int bMode)
  767. {
  768. pCommandBar;
  769. CXTPMouseManager* pMouseManager = GetMouseManager();
  770. if (bMode == FALSE && m_bUseKeyboardCues && !pMouseManager->IsTrackedLock(0))
  771. {
  772. ShowKeyboardCues(FALSE);
  773. }
  774. if (m_keyboardTips.nLevel > 0 && m_pOptions->bShowKeyboardTips)
  775. {
  776. HideKeyboardTips();
  777. if (pMouseManager->IsTrackedLock(0))
  778. {
  779. CXTPCommandBar* pCommandBarTop = pMouseManager->GetTrackArray().GetAt(pMouseManager->GetTrackArray().GetSize() - 1);
  780. if (pCommandBarTop->m_bKeyboardSelect)
  781. {
  782. pCommandBarTop->PostMessage(WM_TIMER, XTP_TID_SHOWKEYBOARDTIPS);
  783. }
  784. }
  785. }
  786. GetToolTipContext()->CancelToolTips();
  787. }
  788. CXTPMouseManager* CXTPCommandBars::GetMouseManager() const
  789. {
  790. if (this == NULL)
  791. return XTPMouseManager();
  792. if (m_pMouseManager != NULL)
  793. return m_pMouseManager;
  794. return m_pMouseManager = XTPMouseManager();
  795. }
  796. CXTPKeyboardManager* CXTPCommandBars::GetKeyboardManager() const
  797. {
  798. if (this == NULL)
  799. return XTPKeyboardManager();
  800. if (m_pKeyboardManager != NULL)
  801. return m_pKeyboardManager;
  802. return m_pKeyboardManager = XTPKeyboardManager();
  803. }
  804. CXTPControl* CXTPCommandBars::_GetNextControl(CXTPControls*& pControls, int nIndex) const
  805. {
  806. int nNextIndex = pControls->GetNext(nIndex, +1);
  807. if (m_pOptions->keyboardCuesUse & xtpKeyboardCuesUseAll
  808. && nNextIndex <= nIndex)
  809. {
  810. CXTPToolBar* pToolBar = (CXTPToolBar*)pControls->GetParent();
  811. CXTPToolBar* pStartBar = pToolBar;
  812. for (;;)
  813. {
  814. pToolBar = GetAt(GetNextVisible(FindIndex(pToolBar), +1));
  815. ASSERT(pToolBar);
  816. pControls = pToolBar->GetControls();
  817. nNextIndex = pControls->GetNext(-1, +1);
  818. if (nNextIndex != -1)
  819. break;
  820. if (pToolBar == pStartBar)
  821. return NULL;
  822. }
  823. }
  824. return pControls->GetAt(nNextIndex);
  825. }
  826. CXTPControl* CXTPCommandBars::FindAccel(CXTPCommandBar* pCommandBar, UINT chAccel, BOOL& bSelectOnly) const
  827. {
  828. ASSERT(pCommandBar->IsVisible());
  829. CXTPControls* pControls = pCommandBar->GetControls();
  830. CXTPControl* pControl = _GetNextControl(pControls, pCommandBar->m_nSelected);
  831. if (pControl == NULL)
  832. return NULL;
  833. bSelectOnly = FALSE;
  834. CXTPControl* pStart = pControl, *pAmpCondidate = NULL, *pCondidate = NULL;
  835. do
  836. {
  837. ASSERT(pControl);
  838. CString strCaption = pControl->IsCaptionVisible() ? pControl->GetCaption() : _T("");
  839. if (!strCaption.IsEmpty() && pControl->GetEnabled() && pControl->GetRibbonGroup() == NULL)
  840. {
  841. int nAmpIndex = strCaption.Find(_T('&'));
  842. BOOL bFound = nAmpIndex > -1 && nAmpIndex < strCaption.GetLength() - 1;
  843. if (CXTPShortcutManager::CompareAccelKey(strCaption[bFound ? nAmpIndex + 1 : 0], chAccel) &&
  844. (bFound || ((m_pOptions->keyboardCuesUse & xtpKeyboardCuesUseAmpersandOnly) == 0)))
  845. {
  846. if (bFound)
  847. {
  848. if (pAmpCondidate == NULL)
  849. pAmpCondidate = pControl;
  850. else
  851. {
  852. bSelectOnly = TRUE;
  853. return pAmpCondidate;
  854. }
  855. }
  856. else if (pControl->GetParent()->GetType() == xtpBarTypeMenuBar || pControl->GetParent()->IsTrackingMode())
  857. {
  858. if (pCondidate == NULL)
  859. pCondidate = pControl;
  860. else
  861. {
  862. bSelectOnly = TRUE;
  863. }
  864. }
  865. }
  866. }
  867. pControl = _GetNextControl(pControls, pControl->GetIndex());
  868. ASSERT(pControl != 0);
  869. if (pControl == NULL)
  870. break;
  871. }
  872. while (pControl != pStart);
  873. return pAmpCondidate ? pAmpCondidate : pCondidate;
  874. }
  875. void CXTPCommandBars::ClosePopups() const
  876. {
  877. CXTPMouseManager* pMouseManage = this == NULL ? XTPMouseManager() : GetMouseManager();
  878. pMouseManage->SendTrackLost();
  879. }
  880. BOOL CXTPCommandBars::OnFrameAccel(UINT chAccel)
  881. {
  882. if (m_pOptions->keyboardCuesUse == xtpKeyboardCuesUseNone)
  883. return FALSE;
  884. if ((chAccel >= VK_NUMPAD0 && chAccel <= VK_NUMPAD9) && !m_pOptions->bUseAltNumPadKeys)
  885. return FALSE;
  886. if (MapVirtualKey(chAccel, 2) == 0)
  887. return FALSE;
  888. CXTPToolBar* pMenuBar = GetMenuBar();
  889. CXTPToolBar* pCommandBar = IsToolBarVisible(pMenuBar) ? pMenuBar : NULL;
  890. for (int i = 0; i < GetCount(); i++)
  891. {
  892. CXTPToolBar* pToolBar = GetAt(i);
  893. if (pToolBar->IsTrackingMode())
  894. {
  895. pCommandBar = pToolBar;
  896. break;
  897. }
  898. if (m_pOptions->keyboardCuesUse & xtpKeyboardCuesUseAll && pCommandBar == NULL && IsToolBarVisible(pToolBar))
  899. pCommandBar = pToolBar;
  900. }
  901. if (!pCommandBar)
  902. return FALSE;
  903. if (IsToolBarVisible(pCommandBar))
  904. {
  905. if (pCommandBar->PreviewAccel(chAccel))
  906. {
  907. return TRUE;
  908. }
  909. BOOL bSelectOnly;
  910. CXTPControl* pControl = FindAccel(pCommandBar, chAccel, bSelectOnly);
  911. if (pControl)
  912. {
  913. int nIndex = pControl->GetIndex();
  914. pCommandBar = (CXTPToolBar*)pControl->GetParent();
  915. if (!pCommandBar->IsTrackingMode())
  916. ClosePopups();
  917. ShowKeyboardCues(TRUE);
  918. m_keyboardTips.nLevel = 1;
  919. pCommandBar->SetTrackingMode(TRUE, FALSE, TRUE);
  920. pCommandBar->SetSelected(nIndex, TRUE);
  921. if (!bSelectOnly)
  922. {
  923. pControl->OnUnderlineActivate();
  924. }
  925. return TRUE;
  926. }
  927. }
  928. return FALSE;
  929. }
  930. BOOL CXTPCommandBars::PreTranslateFrameMessage(MSG* pMsg)
  931. {
  932. if ((pMsg->message == WM_SYSKEYDOWN) && (HIWORD(pMsg->lParam) & KF_ALTDOWN)
  933. && !GetMouseManager()->IsMouseLocked() && !GetMouseManager()->IsTrackedLock(0)
  934. && GetMouseManager()->IsTopParentActive(m_pFrame->GetSafeHwnd()))
  935. {
  936. if (pMsg->wParam == VK_MENU)
  937. {
  938. ShowKeyboardCues(TRUE);
  939. return FALSE;
  940. }
  941. if ((!m_bIgnoreShiftMenuKey || !(::GetKeyState(VK_SHIFT) & 0x8000)))
  942. {
  943. UINT chAccel = (UINT)pMsg->wParam;
  944. if (chAccel)
  945. {
  946. if (OnFrameAccel(chAccel))
  947. return TRUE;
  948. }
  949. }
  950. }
  951. if ((pMsg->message == WM_SYSKEYUP || pMsg->message == WM_KEYUP) && m_bUseKeyboardCues && m_bKeyboardCuesVisible &&
  952. !GetMouseManager()->IsTrackedLock(0))
  953. {
  954. ShowKeyboardCues(FALSE);
  955. }
  956. if ((pMsg->message == WM_CONTEXTMENU || pMsg->message == WM_SYSKEYUP)
  957. && GetMouseManager()->IsTrackedLock(0))
  958. {
  959. XTPKeyboardManager()->ProcessKeyboardHooks(WM_CONTEXTMENU, pMsg->wParam, pMsg->lParam);
  960. return TRUE;
  961. }
  962. if (pMsg->message == WM_MOUSEWHEEL)
  963. {
  964. if (XTPKeyboardManager()->IsKeyboardHooked())
  965. {
  966. return XTPKeyboardManager()->ProcessKeyboardHooks(WM_MOUSEWHEEL, pMsg->wParam, pMsg->lParam);
  967. }
  968. #ifdef _XTP_INCLUDE_RIBBON
  969. else
  970. {
  971. CXTPCommandBar* pMenuBar = GetMenuBar();
  972. CPoint pt;
  973. GetCursorPos(&pt);
  974. if (pMenuBar && pMenuBar->GetType() == xtpBarTypeRibbon && CXTPWindowRect(pMenuBar).PtInRect(pt))
  975. {
  976. ((CXTPRibbonBar*)pMenuBar)->SelectNextTab((short)HIWORD(pMsg->wParam) <= 0);
  977. return TRUE;
  978. }
  979. }
  980. #endif
  981. }
  982. if (pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
  983. {
  984. if (GetShortcutManager()->TranslateAccelerator(pMsg))
  985. return TRUE;
  986. }
  987. return FALSE;
  988. }
  989. void CXTPCommandBars::UpdateCommandBars() const
  990. {
  991. for (int i = 0; i < GetCount(); i++)
  992. {
  993. CXTPCommandBar* pBar = GetAt(i);
  994. pBar->OnIdleUpdateCmdUI(TRUE, TRUE);
  995. }
  996. }
  997. BOOL CXTPCommandBars::OnFrameWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  998. {
  999. if (message == WM_IDLEUPDATECMDUI)
  1000. {
  1001. for (int i = 0; i < GetCount(); i++)
  1002. {
  1003. CXTPCommandBar* pBar = GetAt(i);
  1004. if (pBar->GetPosition() == xtpBarFloating)
  1005. {
  1006. pBar->OnIdleUpdateCmdUI(TRUE, TRUE);
  1007. }
  1008. }
  1009. }
  1010. if (message == WM_SYSCOLORCHANGE)
  1011. {
  1012. XTPColorManager()->RefreshColors();
  1013. GetPaintManager()->RefreshMetrics();
  1014. GetImageManager()->RefreshAll();
  1015. GetSite()->RedrawWindow(FALSE);
  1016. RedrawCommandBars();
  1017. }
  1018. if (message == WM_SETTINGCHANGE)
  1019. {
  1020. GetPaintManager()->RefreshMetrics();
  1021. GetSite()->RedrawWindow(FALSE);
  1022. RedrawCommandBars();
  1023. }
  1024. if (message == WM_CLOSE)
  1025. {
  1026. if (m_pDropSource->m_pSheet != NULL)
  1027. {
  1028. return TRUE;
  1029. }
  1030. }
  1031. if (message == WM_COMMAND)
  1032. {
  1033. CWnd* pWnd = CWnd::GetFocus();
  1034. if (pWnd && pWnd->IsKindOf(RUNTIME_CLASS(CXTPEdit)) && ((CXTPEdit*)pWnd)->OnCommand(wParam, lParam))
  1035. {
  1036. if (pResult != NULL)
  1037. *pResult = 1;
  1038. return TRUE;
  1039. }
  1040. if (LOWORD(wParam) == ID_HELP && GetHelpTrackingId() > 0)
  1041. {
  1042. AFX_CMDHANDLERINFO info;
  1043. info.pTarget = NULL;
  1044. if (GetSite()->OnCmdMsg(ID_HELP, CN_COMMAND, NULL, &info))
  1045. {
  1046. GetSite()->SendMessage(WM_COMMANDHELP, 0, HID_BASE_COMMAND +  GetHelpTrackingId());
  1047. return TRUE;
  1048. }
  1049. }
  1050. }
  1051. switch (message)
  1052. {
  1053. case WM_ACTIVATEAPP:
  1054. if (!wParam)
  1055. ClosePopups();
  1056. return FALSE;
  1057. case WM_SYSCOMMAND:
  1058. if ((wParam == 0 || LOWORD(wParam) != 0) && wParam != SC_KEYMENU && !IsCustomizeMode())
  1059. ClosePopups();
  1060. return FALSE;
  1061. }
  1062. return FALSE;
  1063. }
  1064. void CXTPCommandBars::SetLayoutRTL(CWnd* pWnd, BOOL bRTLLayout)
  1065. {
  1066. DWORD dwRTLStyle = WS_EX_LAYOUTRTL;
  1067. if (pWnd->IsKindOf(RUNTIME_CLASS(CXTPEdit)))
  1068. {
  1069. pWnd->ModifyStyleEx(0, dwRTLStyle);
  1070. return;
  1071. }
  1072. pWnd->ModifyStyleEx(bRTLLayout ? 0 : dwRTLStyle, !bRTLLayout ? 0 : dwRTLStyle);
  1073. // walk through HWNDs to avoid creating temporary CWnd objects
  1074. // unless we need to call this function recursively
  1075. for (CWnd* pChild = pWnd->GetWindow(GW_CHILD); pChild != NULL;
  1076. pChild = pChild->GetWindow(GW_HWNDNEXT))
  1077. {
  1078. // send to child windows after parent
  1079. SetLayoutRTL(pChild, bRTLLayout);
  1080. }
  1081. }
  1082. void CXTPCommandBars::SetLayoutRTL(BOOL bRightToLeft)
  1083. {
  1084. if (!XTPSystemVersion()->IsLayoutRTLSupported())
  1085. return;
  1086. if (m_bRightToLeft == bRightToLeft)
  1087. return;
  1088. m_bRightToLeft = bRightToLeft;
  1089. int i;
  1090. for (i = 0; i < 4; i++)
  1091. {
  1092. if (m_pDocks[i])
  1093. {
  1094. SetLayoutRTL(m_pDocks[i], m_bRightToLeft);
  1095. }
  1096. }
  1097. for (i = 0; i < GetCount(); i++)
  1098. {
  1099. CXTPToolBar* pToolBar = GetAt(i);
  1100. if (pToolBar->GetPosition() == xtpBarFloating)
  1101. {
  1102. SetLayoutRTL(pToolBar, m_bRightToLeft);
  1103. }
  1104. }
  1105. CWnd* pStatusBar = GetSite()->GetDlgItem(AFX_IDW_STATUS_BAR);
  1106. if (pStatusBar)
  1107. {
  1108. SetLayoutRTL(pStatusBar, m_bRightToLeft);
  1109. }
  1110. GetImageManager()->DrawReverted(2);
  1111. RedrawCommandBars();
  1112. }
  1113. BOOL CXTPCommandBars::IsLayoutRTL() const
  1114. {
  1115. if (GetSite()->GetExStyle() & WS_EX_LAYOUTRTL)
  1116. return TRUE;
  1117. return m_bRightToLeft;
  1118. }
  1119. CXTPControl* CXTPCommandBars::FindControl(XTPControlType type, UINT nId, BOOL bVisible, BOOL bRecursive) const
  1120. {
  1121. for (int i = GetCount() - 1; i >= 0; i--)
  1122. {
  1123. CXTPToolBar* pBar = GetAt(i);
  1124. if (!bVisible || pBar->IsVisible())
  1125. {
  1126. CXTPControl* pControl = pBar->GetControls()->FindControl(type, nId, bVisible, bRecursive);
  1127. if (pControl != NULL) return pControl;
  1128. }
  1129. }
  1130. return NULL;
  1131. }
  1132. void CXTPPopupBar::PumpMessage()
  1133. {
  1134. CXTPMouseManager* pMouseManager = XTPMouseManager();
  1135. while (IsTrackingMode())
  1136. {
  1137. MSG msg;
  1138. if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  1139. {
  1140. if (pMouseManager->PreviewTackLost(this, &msg))
  1141. {
  1142. SetTrackingMode(FALSE);
  1143. break;
  1144. }
  1145. if (!::GetMessage(&msg, NULL, 0, 0))
  1146. break;
  1147. if (!IsTrackingMode())
  1148. {
  1149. ::PostMessage(msg.hwnd, msg.message, msg.wParam, msg.lParam);
  1150. break;
  1151. }
  1152. if (msg.message != WM_KICKIDLE && !AfxGetThread()->PreTranslateMessage(&msg))
  1153. {
  1154. // process this message
  1155. ::TranslateMessage(&msg);
  1156. ::DispatchMessage(&msg);
  1157. }
  1158. }
  1159. else
  1160. {
  1161. WaitMessage();
  1162. }
  1163. }
  1164. }
  1165. BOOL CXTPCommandBars::TrackPopupMenu(UINT nBarID, UINT nFlags, int x, int y, LPCRECT rcExclude)
  1166. {
  1167. CXTPPopupBar* pPopup = (CXTPPopupBar*)m_pContextMenus->FindCommandBar(nBarID);
  1168. if (!pPopup)
  1169. return FALSE;
  1170. return TrackPopupMenu(pPopup, nFlags, x, y, GetSite(), rcExclude);
  1171. }
  1172. BOOL CXTPCommandBars::TrackPopupMenu(CXTPPopupBar* pPopup, UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT rcExclude, CWnd* pWndOwner)
  1173. {
  1174. ASSERT(pPopup);
  1175. if (!pPopup)
  1176. {
  1177. return FALSE;
  1178. }
  1179. const MSG& msg = AfxGetThreadState()->m_lastSentMsg;
  1180. if (msg.message == WM_CONTEXTMENU && msg.lParam == MAKELPARAM(-1, -1) && pPopup->GetCommandBars())
  1181. pPopup->GetCommandBars()->ShowKeyboardCues(TRUE);
  1182. if (!pWnd)
  1183. pWnd = pPopup->GetSite();
  1184. pPopup->m_pSite = pWnd ;
  1185. pPopup->m_pOwner = pWndOwner;
  1186. if (pWnd && pWnd->GetExStyle() & (WS_EX_LAYOUTRTL | WS_EX_RIGHT))
  1187. nFlags |= TPM_RIGHTALIGN;
  1188. UINT nReturn = TRUE;
  1189. pPopup->m_pReturnCmd = NULL;
  1190. if (nFlags & TPM_RETURNCMD)
  1191. {
  1192. pPopup->m_pReturnCmd = &nReturn;
  1193. nReturn = 0;
  1194. }
  1195. pPopup->m_bExecOnRButton = nFlags & TPM_RIGHTBUTTON;
  1196. pPopup->m_bIgnoreUpdateHandler = nFlags & TPM_NONOTIFY;
  1197. pPopup->m_popupFlags = (nFlags & TPM_RIGHTALIGN) ? xtpPopupLeft | xtpPopupDown : xtpPopupDown;
  1198. BOOL bRecurse = nFlags & TPM_RECURSE;
  1199. pPopup->m_bRecursePopup = bRecurse;
  1200. CXTPMouseManager* pMouseManager = XTPMouseManager();
  1201. if (!bRecurse)
  1202. {
  1203. pMouseManager->SendTrackLost();
  1204. ReleaseCapture();
  1205. }
  1206. else
  1207. {
  1208. pMouseManager->SendTrackLostRecurse();
  1209. pMouseManager->LockTrackRecurse(TRUE);
  1210. }
  1211. pMouseManager->IgnoreLButtonUp();
  1212. if (!pPopup->Popup(x, y, rcExclude))
  1213. {
  1214. return FALSE;
  1215. }
  1216. pPopup->PumpMessage();
  1217. if (bRecurse)
  1218. {
  1219. pMouseManager->LockTrackRecurse(FALSE);
  1220. }
  1221. return nReturn;
  1222. }
  1223. BOOL CXTPCommandBars::TrackPopupMenuEx(CMenu* pMenu, UINT nFlags, int x, int y, CWnd* pWndOwner, LPTPMPARAMS lptpm)
  1224. {
  1225. CXTPPopupBar* pPopup = CXTPPopupBar::CreatePopupBar(this);
  1226. pPopup->m_pSite = GetSite();
  1227. pPopup->m_pCommandBars = this;
  1228. CRect rcExclude;
  1229. rcExclude.SetRectEmpty();
  1230. if (lptpm) rcExclude = lptpm->rcExclude;
  1231. if (!pPopup->LoadMenu(pMenu))
  1232. {
  1233. pPopup->InternalRelease();
  1234. return FALSE;
  1235. }
  1236. BOOL bResult = TrackPopupMenu(pPopup, nFlags, x, y, GetSite(), rcExclude, pWndOwner);
  1237. pPopup->InternalRelease();
  1238. return bResult;
  1239. }
  1240. BOOL CXTPCommandBars::TrackPopupMenu(CMenu* pMenu, UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT rcExclude, CWnd* pWndOwner, CXTPCommandBars* pCommandBars)
  1241. {
  1242. CXTPPopupBar* pPopup = CXTPPopupBar::CreatePopupBar(pCommandBars);
  1243. pPopup->m_pSite = pWnd;
  1244. pPopup->m_pOwner = pWndOwner;
  1245. pPopup->m_pCommandBars = pCommandBars;
  1246. if (!pPopup->LoadMenu(pMenu))
  1247. {
  1248. pPopup->InternalRelease();
  1249. return FALSE;
  1250. }
  1251. if (pCommandBars)
  1252. {
  1253. const MSG& msg = AfxGetThreadState()->m_lastSentMsg;
  1254. if (msg.message == WM_CONTEXTMENU && msg.lParam == MAKELPARAM(-1, -1))
  1255. pCommandBars->ShowKeyboardCues(TRUE);
  1256. }
  1257. BOOL bResult = TrackPopupMenu(pPopup, nFlags, x, y, pWnd, rcExclude, pWndOwner);
  1258. pPopup->InternalRelease();
  1259. return bResult;
  1260. }
  1261. CXTPPopupBar* CXTPCommandBars::GetToolbarsPopup()
  1262. {
  1263. CXTPPopupBar* pPopup = CXTPPopupBar::CreatePopupBar(this);
  1264. CXTPControlToolbars::CreateToolbarMenu(pPopup, 0, ID_VIEW_TOOLBAR, TRUE);
  1265. return pPopup;
  1266. }
  1267. void CXTPCommandBars::ContextMenu(CXTPToolBar* pToolBar, CPoint point)
  1268. {
  1269. if (IsCustomizeMode())
  1270. return;
  1271. CXTPPopupBar* pPopup = GetToolbarsPopup();
  1272. GetSite()->SendMessage(WM_XTP_TOOLBARCONTEXTMENU, (WPARAM)pToolBar, (LPARAM)pPopup);
  1273. if (pPopup && pPopup->GetControlCount() > 0)
  1274. {
  1275. pPopup->m_popupFlags = IsLayoutRTL() ? xtpPopupLeft : xtpPopupRight;
  1276. ClosePopups();
  1277. pPopup->Popup(point.x, point.y, NULL);
  1278. pPopup->PumpMessage();
  1279. }
  1280. CMDTARGET_RELEASE(pPopup);
  1281. }
  1282. CXTPToolBar* CXTPCommandBars::GetAt(int nIndex) const
  1283. {
  1284. if (nIndex >= 0 && nIndex < GetCount())
  1285. return m_arrBars.GetAt(nIndex);
  1286. return 0;
  1287. }
  1288. void CXTPCommandBars::ToggleVisible(int nIndex)
  1289. {
  1290. ASSERT(nIndex >= 0 && nIndex < GetCount());
  1291. CXTPToolBar* pBar = GetAt(nIndex);
  1292. if (pBar)
  1293. {
  1294. pBar->SetVisible(!pBar->IsVisible());
  1295. }
  1296. m_pOptions->bDirtyState = TRUE;
  1297. }
  1298. CXTPToolBar* CXTPCommandBars::GetToolBar(UINT nID) const
  1299. {
  1300. if (nID == 0)
  1301. return NULL;
  1302. for (int i = 0; i < GetCount(); i++)
  1303. {
  1304. CXTPToolBar* pBar = GetAt(i);
  1305. ASSERT(pBar != NULL);
  1306. if (pBar && (pBar->m_nBarID == nID))
  1307. return pBar;
  1308. }
  1309. return NULL;
  1310. }
  1311. void CXTPToolBar::_GetHiddenControls(CXTPCommandBar* pExpandBar)
  1312. {
  1313. for (int j = 0; j < GetControlCount(); j++)
  1314. {
  1315. CXTPControl* pControl = GetControl(j);
  1316. if (pControl->GetHideFlags() == xtpHideWrap)
  1317. {
  1318. CXTPControl* pControlClone = pExpandBar->GetControls()->AddClone(pControl);
  1319. pControlClone->SetHideFlags(0);
  1320. pControlClone->SetBeginGroup(FALSE);
  1321. }
  1322. }
  1323. }
  1324. void CXTPCommandBars::GetHiddenControls(CXTPToolBar* pToolBar, CXTPCommandBar* pExpandBar)
  1325. {
  1326. if (pToolBar->m_pDockBar == 0) return;
  1327. CXTPDockBar* pDock = pToolBar->m_pDockBar;
  1328. int nPos = pDock->FindBar(pToolBar);
  1329. if (nPos == -1) return;
  1330. CXTPDockBar::CToolBarArray arrBars;
  1331. pDock->GetVisibleToolbars(nPos, arrBars);
  1332. for (int i = 0; i < arrBars.GetSize(); i++)
  1333. {
  1334. CXTPToolBar* pToolBarRow = arrBars[i];
  1335. pToolBarRow->_GetHiddenControls(pExpandBar);
  1336. }
  1337. }
  1338. void CXTPCommandBars::_GetAddOrRemovePopup(CXTPToolBar* pToolBar, CXTPCommandBar* pExpandBar)
  1339. {
  1340. CXTPControlPopup* pButton = (CXTPControlPopup*)pExpandBar->GetControls()->Add(xtpControlPopup, 0);
  1341. pButton->SetFlags(xtpFlagManualUpdate);
  1342. pButton->SetCaption(CXTPControlWindowList::ConstructCaption(pToolBar->GetTitle(), 0));
  1343. BOOL bEnabled = m_bCustomizeAvail && pToolBar->m_bBuiltIn && pToolBar->m_bCustomizable;
  1344. pButton->SetEnabled(bEnabled);
  1345. if (bEnabled)
  1346. {
  1347. pToolBar->BuildCustomizePopup(pButton->GetCommandBar());
  1348. ASSERT_KINDOF(CXTPPopupBar, pButton->GetCommandBar());
  1349. ((CXTPPopupBar*)pButton->GetCommandBar())->SetDoubleGripper();
  1350. }
  1351. }
  1352. void CXTPCommandBars::GetAddOrRemovePopup(CXTPToolBar* pToolBar, CXTPCommandBar* pExpandBar)
  1353. {
  1354. if (pToolBar->m_pDockBar == 0)
  1355. {
  1356. _GetAddOrRemovePopup(pToolBar, pExpandBar);
  1357. }
  1358. else
  1359. {
  1360. CXTPDockBar* pDock = pToolBar->m_pDockBar;
  1361. int nPos = pDock->FindBar(pToolBar);
  1362. if (nPos == -1)
  1363. {
  1364. _GetAddOrRemovePopup(pToolBar, pExpandBar);
  1365. }
  1366. else
  1367. {
  1368. CXTPDockBar::CToolBarArray arrBars;
  1369. pDock->GetVisibleToolbars(nPos, arrBars);
  1370. for (int i = 0; i < arrBars.GetSize(); i++)
  1371. {
  1372. _GetAddOrRemovePopup(arrBars[i], pExpandBar);
  1373. }
  1374. }
  1375. }
  1376. if (m_bCustomizeAvail)
  1377. {
  1378. CXTPControl* pControlCustomize = pExpandBar->GetControls()->Add(xtpControlButton, XTP_ID_CUSTOMIZE);
  1379. pControlCustomize->SetBeginGroup(TRUE);
  1380. }
  1381. }
  1382. void CXTPCommandBars::SetQuickCustomizeMode(BOOL bMode)
  1383. {
  1384. m_pOptions->bDirtyState = TRUE;
  1385. m_bCustomizeMode = m_bQuickCustomizeMode = bMode;
  1386. SetDragControl(NULL);
  1387. ShowKeyboardCues(m_bCustomizeMode);
  1388. }
  1389. void CXTPCommandBars::SetCustomizeMode(BOOL bMode)
  1390. {
  1391. m_pOptions->bDirtyState = TRUE;
  1392. m_bCustomizeMode = bMode;
  1393. SetDragControl(NULL);
  1394. for (int i = 0; i < GetCount(); i++)
  1395. {
  1396. CXTPToolBar* pBar = GetAt(i);
  1397. pBar->DelayRedraw();
  1398. pBar->OnIdleUpdateCmdUI(TRUE, TRUE);
  1399. }
  1400. RecalcFrameLayout();
  1401. ShowKeyboardCues(m_bCustomizeMode);
  1402. }
  1403. void CXTPCommandBars::SetDragControl(CXTPControl* pControl)
  1404. {
  1405. if (m_pDragSelected != pControl)
  1406. {
  1407. CXTPControl* pDragSelected = m_pDragSelected;
  1408. m_pDragSelected = pControl;
  1409. if (pDragSelected != NULL)
  1410. {
  1411. pDragSelected->RedrawParent();
  1412. pDragSelected->InternalRelease();
  1413. }
  1414. if (m_pDragSelected)
  1415. {
  1416. m_pDragSelected->RedrawParent(FALSE);
  1417. m_pDragSelected->InternalAddRef();
  1418. }
  1419. CWnd* pWnd = m_pDropSource->m_pSheet ? (CWnd*)m_pDropSource->m_pSheet : m_pFrame;
  1420. if (pWnd && pWnd->GetSafeHwnd())
  1421. {
  1422. pWnd->SendMessage(WM_XTP_DRAGCONTROLCHANGED);
  1423. }
  1424. }
  1425. }
  1426. void CXTPCommandBars::RemoveAll()
  1427. {
  1428. m_bRecalcLayout = TRUE;
  1429. for (int i = 0; i < GetCount(); i++)
  1430. {
  1431. CXTPToolBar* pToolBar = GetAt(i);
  1432. if (pToolBar->GetSafeHwnd())
  1433. {
  1434. pToolBar->ShowWindow(SW_HIDE);
  1435. pToolBar->m_bVisible = FALSE;
  1436. }
  1437. if (pToolBar->m_pDockBar != NULL)
  1438. {
  1439. pToolBar->m_pDockBar->RemoveCommandBar(pToolBar);
  1440. pToolBar->m_pDockBar = NULL;
  1441. }
  1442. OnToolBarRemoved(pToolBar);
  1443. pToolBar->OnRemoved();
  1444. pToolBar->InternalRelease();
  1445. }
  1446. m_arrBars.RemoveAll();
  1447. m_bRecalcLayout = FALSE;
  1448. RecalcFrameLayout(TRUE);
  1449. }
  1450. void CXTPCommandBars::Remove(CXTPToolBar* pToolBar)
  1451. {
  1452. ASSERT(pToolBar);
  1453. if (!pToolBar)
  1454. return;
  1455. int i = FindIndex(pToolBar);
  1456. if (i == -1)
  1457. return;
  1458. if (pToolBar->GetSafeHwnd())
  1459. {
  1460. pToolBar->ShowWindow(SW_HIDE);
  1461. }
  1462. pToolBar->m_bVisible = FALSE;
  1463. if (pToolBar->m_pDockBar != NULL)
  1464. {
  1465. pToolBar->m_pDockBar->RemoveCommandBar(pToolBar);
  1466. pToolBar->m_pDockBar = NULL;
  1467. RecalcFrameLayout();
  1468. }
  1469. OnToolBarRemoved(pToolBar);
  1470. pToolBar->OnRemoved();
  1471. m_arrBars.RemoveAt(i);
  1472. pToolBar->InternalRelease();
  1473. }
  1474. void CXTPCommandBars::SetSite(CWnd* pFrame)
  1475. {
  1476. m_pFrame = pFrame;
  1477. if (pFrame->GetSafeHwnd())
  1478. {
  1479. AFX_CMDHANDLERINFO info;
  1480. info.pTarget = NULL;
  1481. m_bCustomizeAvail = pFrame->CWnd::OnCmdMsg(XTP_ID_CUSTOMIZE, CN_COMMAND, this, &info);
  1482. }
  1483. m_bRightToLeft = m_pFrame->GetExStyle() & WS_EX_LAYOUTRTL;
  1484. }
  1485. void CXTPCommandBars::HideCommands(const UINT* pCommands, int nCount)
  1486. {
  1487. ASSERT(pCommands);
  1488. if (!pCommands)
  1489. return;
  1490. for (int i = 0; i < nCount; i++)
  1491. HideCommand(pCommands[i]);
  1492. }
  1493. void CXTPCommandBars::HideCommand(UINT nCommand)
  1494. {
  1495. m_pOptions->m_mapHiddenCommands.SetAt(nCommand, TRUE);
  1496. }
  1497. BOOL CXTPCommandBars::IsControlHidden(CXTPControl* pControl)
  1498. {
  1499. BOOL bCommandHidden = IsCommandHidden(pControl->GetID());
  1500. if (m_pOptions->bAutoHideUnusedPopups && !bCommandHidden && IsPopupControlType(pControl->GetType()))
  1501. {
  1502. CXTPCommandBar* pCommandBar = pControl->GetCommandBar();
  1503. if (!pCommandBar)
  1504. return FALSE;
  1505. int nCount = pCommandBar->GetControlCount();
  1506. if (nCount == 0)
  1507. return FALSE;
  1508. for (int i = 0; i < nCount; i++)
  1509. {
  1510. if (!IsControlHidden(pCommandBar->GetControl(i)))
  1511. return FALSE;
  1512. }
  1513. return TRUE;
  1514. }
  1515. return bCommandHidden;
  1516. }
  1517. BOOL CXTPCommandBars::IsCommandHidden(UINT nCommand)
  1518. {
  1519. BOOL bCommand;
  1520. if (!m_pOptions->m_mapHiddenCommands.Lookup(nCommand, bCommand))
  1521. return FALSE;
  1522. if (m_pOptions->m_mapUsedCommands.Lookup(nCommand, bCommand))
  1523. return FALSE;
  1524. return TRUE;
  1525. }
  1526. void CXTPCommandBars::SetCommandUsed(UINT nCommand)
  1527. {
  1528. if (IsCommandHidden(nCommand))
  1529. {
  1530. m_pOptions->m_mapUsedCommands.SetAt(nCommand, TRUE);
  1531. m_pOptions->bDirtyState = TRUE;
  1532. }
  1533. }
  1534. void CXTPCommandBars::ResetUsageData()
  1535. {
  1536. m_pOptions->m_mapUsedCommands.RemoveAll();
  1537. m_pOptions->bDirtyState = TRUE;
  1538. }
  1539. const TCHAR _xtpCommandBarOptionsSection[] = _T("%s-Options");
  1540. void PX_UintMap(CXTPPropExchange* pPX, LPCTSTR pszPropName, CMap<UINT, UINT, BOOL, BOOL>& mapValue)
  1541. {
  1542. if (pPX->IsAllowBlobValues())
  1543. {
  1544. PX_Serialize(pPX, pszPropName, &mapValue);
  1545. return;
  1546. }
  1547. CXTPPropExchangeSection secMap(pPX->GetSection(pszPropName));
  1548. UINT nID;
  1549. if (pPX->IsStoring())
  1550. {
  1551. secMap->WriteCount((DWORD)mapValue.GetCount());
  1552. BOOL bValue;
  1553. int i = 0;
  1554. POSITION pos = mapValue.GetStartPosition();
  1555. while (pos)
  1556. {
  1557. CString strSection;
  1558. strSection.Format(_T("Item%i"), i++);
  1559. mapValue.GetNextAssoc(pos, nID, bValue);
  1560. PX_Long(&secMap, strSection, (long&)nID, 0);
  1561. }
  1562. }
  1563. else
  1564. {
  1565. mapValue.RemoveAll();
  1566. int nCount = secMap->ReadCount();
  1567. for (int i = 0; i < nCount; i++)
  1568. {
  1569. CString strSection;
  1570. strSection.Format(_T("Item%i"), i);
  1571. PX_Long(&secMap, strSection, (long&)nID, 0);
  1572. mapValue.SetAt(nID, TRUE);
  1573. }
  1574. }
  1575. }
  1576. void CXTPCommandBarsOptions::DoPropExchange(CXTPPropExchange* pPX, BOOL bUserOptionsOnly)
  1577. {
  1578. pPX->UseDefaultOnLoad(FALSE);
  1579. pPX->UseDefaultOnSave(FALSE);
  1580. XTP_COMMANDBARS_ICONSINFO* pInfo = m_pCommandBars->GetPaintManager()->GetIconsInfo();
  1581. DWORD dwSchema = _XTP_SCHEMA_CURRENT;
  1582. PX_DWord(pPX, _T("Schema"), dwSchema, _XTP_SCHEMA_CURRENT);
  1583. PX_Bool(pPX, _T("AlwaysShowFullMenus"), bAlwaysShowFullMenus, TRUE);
  1584. PX_Bool(pPX, _T("ShowFullAfterDelay"), bShowFullAfterDelay, TRUE);
  1585. PX_Bool(pPX, _T("ToolBarScreenTips"), bToolBarScreenTips, TRUE);
  1586. PX_Bool(pPX, _T("ToolBarAccelTips"), bToolBarAccelTips, FALSE);
  1587. PX_Bool(pPX, _T("LargeIcons"), bLargeIcons, FALSE);
  1588. if ((dwSchema > _XTP_SCHEMA_875) && !(pPX->IsStoring() && pPX->IsAllowDefaultValues() && m_mapUsedCommands.IsEmpty()))
  1589. PX_UintMap(pPX, _T("UsedCommands"), m_mapUsedCommands);
  1590. if ((dwSchema > _XTP_SCHEMA_875) || bUserOptionsOnly)
  1591. PX_Enum(pPX, _T("Animation"), animationType, xtpAnimateWindowsDefault);
  1592. if (!bUserOptionsOnly)
  1593. {
  1594. PX_Bool(pPX, _T("SyncFloatingBars"), bSyncFloatingBars, TRUE);
  1595. PX_Bool(pPX, _T("ShowExpandButtonAlways"), bShowExpandButtonAlways, TRUE);
  1596. PX_Size(pPX, _T("IconsSize"), szIcons, CSize(0, 0));
  1597. PX_Size(pPX, _T("LargeIconsSize"), szLargeIcons, CSize(0, 0));
  1598. if (!(pPX->IsStoring() && pPX->IsAllowDefaultValues() && m_mapHiddenCommands.IsEmpty()))
  1599. PX_UintMap(pPX, _T("HiddenCommands"), m_mapHiddenCommands);
  1600. PX_Bool(pPX, _T("IconsWithShadow"), pInfo->bIconsWithShadow, FALSE);
  1601. PX_Bool(pPX, _T("UseDisabledIcons"), pInfo->bUseDisabledIcons, TRUE);
  1602. PX_Bool(pPX, _T("UseFadedIcons"), pInfo->bUseFadedIcons, TRUE);
  1603. if (dwSchema > _XTP_SCHEMA_875)
  1604. {
  1605. PX_Bool(pPX, _T("SyncFloatingBars"), bSyncFloatingBars, TRUE);
  1606. PX_Bool(pPX, _T("ShowExpandButtonAlways"), bShowExpandButtonAlways, TRUE);
  1607. PX_Bool(pPX, _T("DblClickFloat"), bDblClickFloat, FALSE);
  1608. PX_Bool(pPX, _T("ShowTextBelowIcons"), bShowTextBelowIcons, FALSE);
  1609. PX_Bool(pPX, _T("AltDragCustomization"), bAltDragCustomization, TRUE);
  1610. PX_Bool(pPX, _T("AutoHideUnusedPopups"), bAutoHideUnusedPopups, TRUE);
  1611. PX_Size(pPX, _T("PopupIconsSize"), szPopupIcons, CSize(0, 0));
  1612. }
  1613. if (dwSchema > _XTP_SCHEMA_95)
  1614. {
  1615. PX_DWord(pPX, _T("KeyboardCuesUse"), keyboardCuesUse, xtpKeyboardCuesUseAll);
  1616. PX_Enum(pPX, _T("KeyboardCuesShow"), keyboardCuesShow, xtpKeyboardCuesShowAlways);
  1617. if (pPX->IsLoading()) ShowKeyboardCues(keyboardCuesShow);
  1618. }
  1619. }
  1620. }
  1621. void CXTPCommandBarsOptions::Serialize(CArchive& ar)
  1622. {
  1623. CXTPPropExchangeArchive px(ar);
  1624. DoPropExchange(&px);
  1625. }
  1626. void CXTPCommandBars::SaveOptions(LPCTSTR lpszProfileName)
  1627. {
  1628. TCHAR szSection[256];
  1629. wsprintf(szSection, _xtpCommandBarOptionsSection, lpszProfileName);
  1630. CXTPPropExchangeSection px(FALSE, szSection);
  1631. px->EmptySection();
  1632. m_pOptions->DoPropExchange(&px, TRUE);
  1633. }
  1634. void CXTPCommandBars::LoadOptions(LPCTSTR lpszProfileName)
  1635. {
  1636. TCHAR szSection[256];
  1637. wsprintf(szSection, _xtpCommandBarOptionsSection, lpszProfileName);
  1638. CXTPPropExchangeSection px(TRUE, szSection);
  1639. m_pOptions->DoPropExchange(&px, TRUE);
  1640. }
  1641. void CXTPCommandBars::SetTheme(XTPPaintTheme paintTheme)
  1642. {
  1643. SetPaintManager(CXTPPaintManager::CreateTheme(paintTheme));
  1644. }
  1645. void CXTPCommandBars::SetPaintManager(CXTPPaintManager* pPaintManager)
  1646. {
  1647. if (m_pPaintManager)
  1648. m_pPaintManager->InternalRelease();
  1649. m_pPaintManager = pPaintManager;
  1650. if (m_pPaintManager)
  1651. {
  1652. m_pPaintManager->RefreshMetrics();
  1653. }
  1654. for (int i = 0; i < GetCount(); i++)
  1655. {
  1656. GetAt(i)->OnPaintManagerChanged();
  1657. }
  1658. GetImageManager()->RefreshAll();
  1659. RedrawCommandBars();
  1660. }
  1661. void CXTPCommandBars::SetImageManager(CXTPImageManager* pImageManager)
  1662. {
  1663. ASSERT(m_pImageManager == NULL);
  1664. m_pImageManager = pImageManager;
  1665. GetImageManager()->RefreshAll();
  1666. }
  1667. CXTPPaintManager* CXTPCommandBars::GetPaintManager() const
  1668. {
  1669. if (m_pPaintManager)
  1670. return m_pPaintManager;
  1671. return XTPPaintManager();
  1672. }
  1673. CXTPImageManager* CXTPCommandBars::GetImageManager() const
  1674. {
  1675. if (m_pImageManager)
  1676. return m_pImageManager;
  1677. return XTPImageManager();
  1678. }
  1679. void CXTPCommandBars::LoadDesignerBars(CArchive& ar)
  1680. {
  1681. CXTPPropExchangeArchive px(ar);
  1682. LoadDesignerBars(&px);
  1683. }
  1684. void CXTPCommandBars::LoadDesignerBars(CXTPPropExchange* pPX)
  1685. {
  1686. try
  1687. {
  1688. //////////////////////////////////////////////////////////////////////////
  1689. // Load Docking Position and Controls
  1690. XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
  1691. param.bSerializeControls = TRUE;
  1692. param.bSerializeDesignerControls = TRUE;
  1693. param.bSerializeImages = TRUE;
  1694. param.bSerializeOptions = TRUE;
  1695. param.bSerializeActions = TRUE;
  1696. DoPropExchange(pPX, &param);
  1697. }
  1698. catch (CMemoryException* pEx)
  1699. {
  1700. pEx->Delete ();
  1701. }
  1702. catch (CArchiveException* pEx)
  1703. {
  1704. pEx->Delete ();
  1705. }
  1706. }
  1707. CDocTemplate* CXTPCommandBars::FindDocTemplate(CMDIChildWnd* pChild)
  1708. {
  1709. USES_PROTECTED_ACCESS(CXTPCommandBars, CMDIChildWnd, HMENU, m_hMenuShared)
  1710. CMultiDocTemplate* pTemplate = DYNAMIC_DOWNCAST(CMultiDocTemplate, pChild->GetActiveDocument()->GetDocTemplate());
  1711. if (!pTemplate)
  1712. return NULL;
  1713. HMENU hMenuShared = PROTECTED_ACCESS(CMDIChildWnd, pChild, m_hMenuShared);
  1714. if ((hMenuShared == 0) || (pTemplate->m_hMenuShared == hMenuShared))
  1715. return pTemplate;
  1716. POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
  1717. while (pos)
  1718. {
  1719. pTemplate = DYNAMIC_DOWNCAST(CMultiDocTemplate, AfxGetApp()->GetNextDocTemplate(pos));
  1720. if (pTemplate && pTemplate->m_hMenuShared == hMenuShared)
  1721. return pTemplate;
  1722. }
  1723. return NULL;
  1724. }
  1725. UINT CXTPCommandBars::GetActiveDocTemplate()
  1726. {
  1727. #pragma warning(disable:4510)
  1728. #pragma warning(disable:4610)
  1729. USES_PROTECTED_ACCESS(CXTPCommandBars, CDocTemplate, UINT, m_nIDResource)
  1730. USES_PROTECTED_ACCESS(CXTPCommandBars, CFrameWnd, UINT, m_nIDHelp)
  1731. CMDIFrameWnd* pFrame = DYNAMIC_DOWNCAST(CMDIFrameWnd, GetSite());
  1732. if (!pFrame)
  1733. return 0;
  1734. UINT nIDResource = (WORD)m_nDefaultMenuID;
  1735. CMDIChildWnd* pChild = pFrame->MDIGetActive();
  1736. if (pChild)
  1737. {
  1738. if (pChild->GetActiveDocument())
  1739. {
  1740. CDocTemplate* pDocTemplate = FindDocTemplate(pChild);
  1741. if (!pDocTemplate)
  1742. return 0;
  1743. nIDResource = PROTECTED_ACCESS(CDocTemplate, pDocTemplate, m_nIDResource);
  1744. }
  1745. else
  1746. {
  1747. nIDResource = PROTECTED_ACCESS(CFrameWnd, pChild, m_nIDHelp);
  1748. }
  1749. }
  1750. return nIDResource;
  1751. }
  1752. void CXTPCommandBars::OnSetPreviewMode (BOOL bPreview)
  1753. {
  1754. GetShortcutManager()->DisableShortcuts(bPreview);
  1755. int nCount = GetCount();
  1756. for (int i = 0; i < nCount; i++)
  1757. {
  1758. CXTPToolBar* pBar = GetAt(i);
  1759. pBar->OnSetPreviewMode(bPreview);
  1760. }
  1761. }
  1762. CXTPToolTipContext* CXTPCommandBars::GetToolTipContext() const
  1763. {
  1764. return m_pToolTipContext;
  1765. }
  1766. int CXTPCommandBars::FindIndex(CXTPToolBar* pToolBar) const
  1767. {
  1768. int nCount = GetCount();
  1769. for (int i = 0; i < nCount; i++)
  1770. {
  1771. CXTPToolBar* pBar = GetAt(i);
  1772. if (pBar == pToolBar)
  1773. return i;
  1774. }
  1775. return -1;
  1776. }
  1777. int CXTPCommandBars::GetNextVisible(long nIndex, int nDirection) const
  1778. {
  1779. ASSERT(nDirection == +1 || nDirection == -1);
  1780. if (GetCount() == 0) return -1;
  1781. long nNext = nIndex + nDirection;
  1782. if (nDirection == -1 && nIndex == -1)
  1783. {
  1784. nNext = GetCount() - 1;
  1785. }
  1786. BOOL bCircle = FALSE;
  1787. while (nNext != nIndex)
  1788. {
  1789. if (nNext >= GetCount())
  1790. {
  1791. if ((nIndex == -1 && nDirection == +1) || bCircle) return -1;
  1792. nNext = 0;
  1793. bCircle = TRUE;
  1794. }
  1795. if (nNext < 0)
  1796. {
  1797. if ((nIndex == -1 && nDirection == -1) || bCircle) return -1;
  1798. nNext = GetCount() - 1;
  1799. bCircle = TRUE;
  1800. }
  1801. if (GetAt(nNext)->IsWindowVisible())
  1802. return nNext;
  1803. nNext += nDirection;
  1804. }
  1805. return nNext;
  1806. }
  1807. BOOL CXTPCommandBars::SetToolBarFocus(CXTPToolBar* pCommandBar, BOOL bNext /*= FALSE*/)
  1808. {
  1809. if (!pCommandBar)
  1810. return FALSE;
  1811. if (bNext)
  1812. {
  1813. if (GetCount() < 2)
  1814. return FALSE;
  1815. int nIndex = FindIndex(pCommandBar);
  1816. int nNextIndex = GetNextVisible(nIndex, bNext);
  1817. if (nIndex == nNextIndex || nNextIndex == -1)
  1818. return FALSE;
  1819. pCommandBar = GetAt(nNextIndex);
  1820. }
  1821. ClosePopups();
  1822. ShowKeyboardCues(TRUE);
  1823. m_keyboardTips.nLevel = 1;
  1824. pCommandBar->SetTrackingMode(TRUE, FALSE, TRUE);
  1825. pCommandBar->SetSelected(pCommandBar->GetControls()->GetNext(-1, +1, TRUE, pCommandBar->GetType() == xtpBarTypeMenuBar), TRUE_KEYBOARD_NEXT);
  1826. return TRUE;
  1827. }