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

对话框与窗口

开发平台:

Visual C++

  1. // XTPDockingPaneManager.cpp : implementation of the CXTPDockingPaneManager class.
  2. //
  3. // This file is a part of the XTREME DOCKINGPANE MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPColorManager.h"
  22. #include "Common/XTPDrawHelpers.h"
  23. #include "Common/XTPImageManager.h"
  24. #include "Common/XTPToolTipContext.h"
  25. #include "Common/XTPPropExchange.h"
  26. #include "TabManager/XTPTabManager.h"
  27. #include "XTPDockingPaneManager.h"
  28. #include "XTPDockingPaneLayout.h"
  29. #include "XTPDockingPaneBase.h"
  30. #include "XTPDockingPane.h"
  31. #include "XTPDockingPaneSplitterContainer.h"
  32. #include "XTPDockingPaneTabbedContainer.h"
  33. #include "XTPDockingPaneMiniWnd.h"
  34. #include "XTPDockingPanePaintManager.h"
  35. #include "XTPDockingPaneLayout.h"
  36. #include "XTPDockingPaneAutoHidePanel.h"
  37. #include "XTPDockingPaneSidePanel.h"
  38. #include "XTPDockingPaneContext.h"
  39. #include "XTPDockingPaneKeyboardHook.h"
  40. #ifdef _DEBUG
  41. #define new DEBUG_NEW
  42. #undef THIS_FILE
  43. static char THIS_FILE[] = __FILE__;
  44. #endif
  45. CXTPDockingPaneManager::CXTPDockingPaneManager()
  46. {
  47. m_pSite = 0;
  48. m_pLayout = 0;
  49. m_nSplitterGap = 22;
  50. m_nClientMargin = 0;
  51. m_dwDefaultPaneOptions = 0;
  52. m_bAttachingPane = FALSE;
  53. m_bHideClient = FALSE;
  54. m_bUseSplitterTracker = TRUE;
  55. m_pPaintManager = NULL;
  56. SetTheme(xtpPaneThemeDefault);
  57. m_pImageManager = new CXTPImageManager();
  58. m_bLockSplitters = FALSE;
  59. m_bThemedFloatingFrames = FALSE;
  60. m_pDockingContext = new CXTPDockingPaneContext();
  61. m_pDockingContext->m_pManager = this;
  62. m_bAlphaDockingContext = FALSE;
  63. m_bShowDockingContextStickers = FALSE;
  64. m_nDockingContextStickerStyle = xtpPaneStickerStyleWhidbey;
  65. m_bCloseGroupOnButtonClick = FALSE;
  66. m_bHideGroupOnButtonClick = TRUE;
  67. m_pPreviewLayout = 0;
  68. m_bSyncActiveFloatingFrames = TRUE;
  69. m_captionDirection = xtpPaneCaptionHorizontal;
  70. m_pToolTipContext = new CXTPToolTipContext();
  71. m_pActivePane = 0;
  72. m_bShowMaximizeButton = FALSE;
  73. m_bLayoutCreated = FALSE;
  74. m_bShowContentsWhileDragging = FALSE;
  75. m_bShowSizeCursorWhileDragging = FALSE;
  76. m_bInitialUpdateCalled = FALSE;
  77. m_ptMinClientSize = CPoint(60, 60);
  78. m_hwndLastFocus = NULL;
  79. m_bStickyFloatingFrames = FALSE;
  80. m_nStickyGap = 15;
  81. m_nFloatingFramesOpacity = 255;
  82. m_rcSideDockingMargin.SetRect(0, 0, 0, 0);
  83. m_bSideDocking = FALSE;
  84. m_bKeyboardEnabled = xtpPaneKeyboardUnused;
  85. HMODULE hLib = GetModuleHandle(_T("USER32"));
  86. if (hLib)
  87. {
  88. m_pfnSetLayeredWindowAttributes = (PFNSETLAYEREDWINDOWATTRIBUTES)::GetProcAddress(hLib, "SetLayeredWindowAttributes");
  89. }
  90. XTPDrawHelpers()->RegisterWndClass(0, _T("XTPDockingPaneSplitter"), 0);
  91. XTPDrawHelpers()->RegisterWndClass(0, _T("XTPDockingPaneTabbedContainer"), CS_DBLCLKS);
  92. XTPDrawHelpers()->RegisterWndClass(0, _T("XTPDockingPaneManager"), 0);
  93. XTPDrawHelpers()->RegisterWndClass(0, _T("XTPDockingPaneAutoHidePanel"), 0);
  94. XTPDrawHelpers()->RegisterWndClass(0, _T("XTPDockingPaneMiniWnd"), CS_DBLCLKS);
  95. XTPDrawHelpers()->RegisterWndClass(0, _T("XTPDockingPaneSidePanel"), CS_DBLCLKS);
  96. m_pWindowSelectClass = RUNTIME_CLASS(CXTPDockingPaneWindowSelect);
  97. OleInitialize(NULL);
  98. EnableAutomation();
  99. }
  100. CXTPDockingPaneManager::~CXTPDockingPaneManager()
  101. {
  102. CMDTARGET_RELEASE(m_pLayout);
  103. CMDTARGET_RELEASE(m_pActivePane);
  104. CMDTARGET_RELEASE(m_pPaintManager);
  105. CMDTARGET_RELEASE(m_pToolTipContext);
  106. delete m_pDockingContext;
  107. CMDTARGET_RELEASE(m_pImageManager);
  108. OleUninitialize();
  109. }
  110. void CXTPDockingPaneManager::HideClient(BOOL bHide)
  111. {
  112. RecalcFrameLayout(NULL);
  113. m_bHideClient = bHide;
  114. m_pLayout->m_pTopContainer->OnParentContainerChanged(m_pLayout->m_pTopContainer);
  115. RedrawPanes();
  116. }
  117. BEGIN_MESSAGE_MAP(CXTPDockingPaneManager, CWnd)
  118. ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
  119. ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
  120. ON_WM_SYSCOLORCHANGE()
  121. ON_WM_SETTINGCHANGE()
  122. ON_MESSAGE_VOID(WM_INITIALUPDATE, OnInitialUpdate)
  123. ON_MESSAGE(WM_GETOBJECT, OnGetObject)
  124. END_MESSAGE_MAP()
  125. void CXTPDockingPaneManager::OnSysColorChange()
  126. {
  127. RefreshXtremeColors();
  128. m_pPaintManager->RefreshMetrics();
  129. _Redraw();
  130. }
  131. void CXTPDockingPaneManager::OnSettingChange(UINT /*uFlags*/, LPCTSTR /*lpszSection*/)
  132. {
  133. m_pPaintManager->RefreshMetrics();
  134. _Redraw();
  135. }
  136. void CXTPDockingPaneManager::SetFloatingFramesOpacity(int nOpacity)
  137. {
  138. m_nFloatingFramesOpacity = nOpacity;
  139. POSITION pos = GetPaneStack().GetHeadPosition();
  140. while (pos)
  141. {
  142. CXTPDockingPaneBase* pPane = GetPaneStack().GetNext(pos);
  143. if (pPane->GetType() == xtpPaneTypeMiniWnd)
  144. {
  145. ((CXTPDockingPaneMiniWnd*)pPane)->UpdateWindowOpacity();
  146. }
  147. }
  148. }
  149. void CXTPDockingPaneManager::UpdatePanes()
  150. {
  151. HWND hWndFocus = ::GetFocus();
  152. if (m_hwndLastFocus == hWndFocus)
  153. return;
  154. m_hwndLastFocus = hWndFocus;
  155. POSITION pos = GetPaneStack().GetHeadPosition();
  156. while (pos)
  157. {
  158. CXTPDockingPaneBase* pPane = GetPaneStack().GetNext(pos);
  159. if (pPane->GetType() == xtpPaneTypeTabbedContainer || pPane->GetType() == xtpPaneTypeMiniWnd  || pPane->GetType() == xtpPaneTypeSidePanel)
  160. {
  161. pPane->OnFocusChanged();
  162. }
  163. }
  164. }
  165. void CXTPDockingPaneManager::OnInitialUpdate()
  166. {
  167. if (m_pSite && m_pSite->IsFrameWnd() && ((CFrameWnd*)m_pSite)->m_nIdleFlags & CFrameWnd::idleLayout)
  168. {
  169. RecalcFrameLayout(NULL);
  170. }
  171. OnIdleUpdateCmdUI(TRUE, 0L);
  172. if (m_pLayout)
  173. {
  174. POSITION pos = m_pLayout->m_lstStack.GetHeadPosition();
  175. while (pos)
  176. {
  177. CXTPDockingPaneBase* pPane = m_pLayout->m_lstStack.GetNext(pos);
  178. if (pPane->GetType() == xtpPaneTypeMiniWnd)
  179. {
  180. CXTPDockingPaneMiniWnd* pMiniFrame = (CXTPDockingPaneMiniWnd*)pPane;
  181. if (pMiniFrame->GetSafeHwnd())
  182. {
  183. if (pMiniFrame->m_nIdleFlags & CFrameWnd::idleLayout)
  184. {
  185. pMiniFrame->RecalcLayout();
  186. }
  187. pMiniFrame->SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
  188. }
  189. }
  190. }
  191. }
  192. m_bInitialUpdateCalled = TRUE;
  193. }
  194. LRESULT CXTPDockingPaneManager::OnIdleUpdateCmdUI(WPARAM /*wParam*/, LPARAM /*lParam*/)
  195. {
  196. UpdatePanes();
  197. return 0;
  198. }
  199. void CXTPDockingPaneManager::SyncPanesState()
  200. {
  201. POSITION pos = GetPaneList().GetHeadPosition();
  202. while (pos)
  203. {
  204. XTP_DOCKINGPANE_INFO& info = GetPaneList().GetNext(pos);
  205. CXTPDockingPaneBase* pContainer = info.pPane->m_pParentContainer;
  206. if (info.pPane->GetDockingSite() && pContainer)
  207. {
  208. if (pContainer->m_pParentContainer == 0 || pContainer->m_pParentContainer->GetType() != xtpPaneTypeAutoHidePanel)
  209. {
  210. if (DYNAMIC_DOWNCAST(CXTPDockingPaneMiniWnd, info.pPane->GetDockingSite()))
  211. {
  212. info.pLastHolder = info.pFloatingHolder = pContainer;
  213. }
  214. else
  215. {
  216. info.pLastHolder = info.pDockingHolder = pContainer;
  217. }
  218. }
  219. }
  220. }
  221. }
  222. LRESULT CXTPDockingPaneManager::OnSizeParent(WPARAM, LPARAM lParam)
  223. {
  224. if (GetTopPane() != NULL)
  225. {
  226. AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam;
  227. m_pLayout->OnSizeParent(m_pSite, lpLayout->rect, lpLayout);
  228. SyncPanesState();
  229. m_bLayoutCreated = TRUE;
  230. }
  231. return 0;
  232. }
  233. CXTPDockingPaneBase* CXTPDockingPaneManager::_Clone(CXTPDockingPaneBase* pPane)
  234. {
  235. return (CXTPDockingPaneBase*)pPane->Clone(m_pLayout, 0);
  236. }
  237. BOOL CXTPDockingPaneManager::NotifyAction(XTPDockingPaneAction action, CXTPDockingPane* pPane, CXTPDockingPaneBase* pDockContainer /*= NULL*/, XTPDockingPaneDirection dockDirection /*= xtpPaneDockLeft*/)
  238. {
  239. XTP_DOCKINGPANE_ACTION dpAction(action);
  240. dpAction.pPane = pPane;
  241. dpAction.pDockContainer = pDockContainer;
  242. dpAction.dockDirection = dockDirection;
  243. if ((pPane->GetEnabled() & xtpPaneEnableActions) == 0)
  244. dpAction.bCancel = TRUE;
  245. NotifyOwner(XTP_DPN_ACTION, (LPARAM)&dpAction);
  246. return dpAction.bCancel;
  247. }
  248. void CXTPDockingPaneManager::LockSplitters(BOOL bLock /*= TRUE*/)
  249. {
  250. m_bLockSplitters = bLock;
  251. POSITION pos = GetPaneList().GetHeadPosition();
  252. while (pos)
  253. {
  254. CXTPDockingPane* pPane = GetPaneList().GetNext(pos);
  255. if (pPane->GetContainer())
  256. SAFE_CALLPTR(pPane->GetContainer()->GetContainer(), OnChildContainerChanged(pPane));
  257. }
  258. }
  259. CXTPDockingPaneSidePanel* CXTPDockingPaneManager::DockSidePane(CXTPDockingPaneBase* pPane, XTPDockingPaneDirection direction, CRect rc)
  260. {
  261. CXTPDockingPaneSidePanel* pMiniFrame = (CXTPDockingPaneSidePanel*)OnCreatePane(xtpPaneTypeSidePanel, m_pLayout);
  262. pMiniFrame->Init(pPane, direction, rc);
  263. SyncPanesState();
  264. m_hwndLastFocus = 0;
  265. RecalcFrameLayout(NULL, TRUE);
  266. return pMiniFrame;
  267. }
  268. CXTPDockingPaneMiniWnd* CXTPDockingPaneManager::FloatPane(CXTPDockingPaneBase* pPane, CRect rc)
  269. {
  270. ASSERT(pPane->GetType() == xtpPaneTypeDockingPane || pPane->GetType() == xtpPaneTypeTabbedContainer);
  271. if (pPane->GetType() == xtpPaneTypeDockingPane)
  272. {
  273. _RemovePane(pPane);
  274. }
  275. else
  276. {
  277. pPane = pPane->Clone(m_pLayout, 0);
  278. }
  279. CXTPDockingPaneMiniWnd* pMiniFrame = (CXTPDockingPaneMiniWnd*)OnCreatePane(xtpPaneTypeMiniWnd, m_pLayout);
  280. pMiniFrame->Init(pPane, rc);
  281. SyncPanesState();
  282. m_hwndLastFocus = 0;
  283. return pMiniFrame;
  284. }
  285. CXTPDockingPane* CXTPDockingPaneManager::CreatePane(UINT nID, CRect rc, XTPDockingPaneDirection direction, CXTPDockingPaneBase* pNeighbour)
  286. {
  287. ASSERT(GetTopPane());
  288. CXTPDockingPane* pPane = (CXTPDockingPane*)OnCreatePane(xtpPaneTypeDockingPane, m_pLayout);
  289. ASSERT(pPane);
  290. if (!pPane)
  291. return NULL;
  292. pPane->SetID(nID);
  293. pPane->SetWindowRect(rc);
  294. XTP_DOCKINGPANE_INFO pane(pPane);
  295. GetPaneList().AddTail(pane);
  296. _InsertPane(pPane, direction, pNeighbour);
  297. SyncPanesState();
  298. return pPane;
  299. }
  300. CXTPDockingPaneBase* CXTPDockingPaneManager::OnCreatePane(XTPDockingPaneType type, CXTPDockingPaneLayout* pLayout)
  301. {
  302. CXTPDockingPaneBase* pPane = NULL;
  303. switch (type)
  304. {
  305. case xtpPaneTypeDockingPane:
  306. pPane = new CXTPDockingPane(pLayout);
  307. break;
  308. case xtpPaneTypeSplitterContainer:
  309. pPane = new CXTPDockingPaneSplitterContainer(pLayout);
  310. break;
  311. case xtpPaneTypeTabbedContainer:
  312. pPane = new CXTPDockingPaneTabbedContainer(pLayout);
  313. break;
  314. case xtpPaneTypeClient:
  315. pPane = new CXTPDockingPaneClientContainer(pLayout);
  316. break;
  317. case xtpPaneTypeMiniWnd:
  318. pPane = new CXTPDockingPaneMiniWnd(pLayout);
  319. break;
  320. case xtpPaneTypeAutoHidePanel:
  321. pPane = new CXTPDockingPaneAutoHidePanel(pLayout);
  322. break;
  323. case xtpPaneTypeSidePanel:
  324. pPane = new CXTPDockingPaneSidePanel(pLayout);
  325. break;
  326. }
  327. ASSERT(pPane);
  328. return pPane;
  329. }
  330. void CXTPDockingPaneManager::DockPane(CXTPDockingPaneBase* pPane, XTPDockingPaneDirection direction, CXTPDockingPaneBase* pNeighbour)
  331. {
  332. if (pPane->GetType() == xtpPaneTypeSplitterContainer)
  333. {
  334. CXTPDockingPaneBaseList lst;
  335. pPane->FindPane(xtpPaneTypeTabbedContainer, &lst);
  336. if (lst.GetCount() == 1)
  337. {
  338. pPane = lst.GetHead();
  339. }
  340. }
  341. if (pPane->GetType() == xtpPaneTypeDockingPane)
  342. {
  343. _RemovePane(pPane);
  344. }
  345. else
  346. {
  347. pPane = _Clone((CXTPDockingPaneBase*)pPane);
  348. }
  349. _InsertPane(pPane, direction, pNeighbour);
  350. m_pLayout->_FreeEmptyPanes();
  351. m_hwndLastFocus = 0;
  352. }
  353. void CXTPDockingPaneManager::_RemovePane(CXTPDockingPaneBase* pPane)
  354. {
  355. if (!pPane)
  356. return;
  357. if (!pPane->m_pParentContainer)
  358. return;
  359. pPane->m_pParentContainer->RemovePane(pPane);
  360. }
  361. void CXTPDockingPaneManager::AttachPane(CXTPDockingPaneBase* pPane, CXTPDockingPaneBase* pNeighbour)
  362. {
  363. _AttachPane(pPane, pNeighbour);
  364. SyncPanesState();
  365. }
  366. void CXTPDockingPaneManager::_AttachPane(CXTPDockingPaneBase* pPane, CXTPDockingPaneBase* pNeighbour)
  367. {
  368. ASSERT(pNeighbour);
  369. if (!pNeighbour)
  370. return;
  371. if (pNeighbour->GetType() == xtpPaneTypeDockingPane)
  372. {
  373. pNeighbour = pNeighbour->m_pParentContainer;
  374. ASSERT(pNeighbour);
  375. }
  376. if (!pNeighbour)
  377. return;
  378. ASSERT(pNeighbour->GetType() == xtpPaneTypeTabbedContainer);
  379. if (pPane->GetType() == xtpPaneTypeDockingPane)
  380. {
  381. _RemovePane(pPane);
  382. ((CXTPDockingPaneTabbedContainer*)pNeighbour)->_InsertPane((CXTPDockingPane*)pPane);
  383. }
  384. else
  385. {
  386. ASSERT(pPane->GetType() == xtpPaneTypeSplitterContainer || pPane->GetType() == xtpPaneTypeTabbedContainer);
  387. CXTPDockingPaneBaseList lst;
  388. ((CXTPDockingPaneBase*)pPane)->FindPane(xtpPaneTypeDockingPane, &lst);
  389. ASSERT(lst.GetCount() > 0);
  390. POSITION pos = lst.GetHeadPosition();
  391. while (pos)
  392. {
  393. CXTPDockingPaneBase* pListPane = lst.GetNext(pos);
  394. ASSERT(pListPane->GetType() == xtpPaneTypeDockingPane);
  395. _RemovePane(pListPane);
  396. ((CXTPDockingPaneTabbedContainer*)pNeighbour)->_InsertPane((CXTPDockingPane*)pListPane);
  397. }
  398. }
  399. m_hwndLastFocus = NULL;
  400. }
  401. CRect CXTPDockingPaneManager::_CalculateResultDockingRect(CXTPDockingPaneBase* pPane, XTPDockingPaneDirection direction, CXTPDockingPaneBase* pNeighbour)
  402. {
  403. if (pNeighbour == NULL)
  404. {
  405. pNeighbour = GetTopPane();
  406. }
  407. ASSERT(pNeighbour);
  408. if (!pNeighbour)
  409. return CRect(0, 0, 0, 0);
  410. BOOL bHoriz = (direction == xtpPaneDockLeft || direction == xtpPaneDockRight);
  411. if (pNeighbour == GetTopPane())
  412. {
  413. CXTPDockingPaneSplitterContainer* pSplitter = (CXTPDockingPaneSplitterContainer*)pNeighbour;
  414. return CXTPDockingPaneSplitterContainer::_CalculateResultDockingRectChild(pSplitter, pPane, direction);
  415. }
  416. else
  417. {
  418. ASSERT(pNeighbour->m_pParentContainer);
  419. if (!pNeighbour->m_pParentContainer)
  420. return CRect(0, 0, 0, 0);
  421. if (pNeighbour->m_pParentContainer->GetType() == xtpPaneTypeTabbedContainer)
  422. {
  423. pNeighbour = pNeighbour->m_pParentContainer;
  424. ASSERT(pNeighbour->m_pParentContainer != NULL);
  425. if (!pNeighbour->m_pParentContainer)
  426. return CRect(0, 0, 0, 0);
  427. }
  428. ASSERT(pNeighbour->m_pParentContainer);
  429. ASSERT(pNeighbour->m_pParentContainer->GetType() == xtpPaneTypeSplitterContainer);
  430. CXTPDockingPaneSplitterContainer* pSplitter = (CXTPDockingPaneSplitterContainer*)pNeighbour->m_pParentContainer;
  431. if (pSplitter->m_bHoriz == bHoriz)
  432. return pSplitter->_CalculateResultDockingRectSelf(pPane, direction, pNeighbour);
  433. return CXTPDockingPaneSplitterContainer::_CalculateResultDockingRectChild(pNeighbour, pPane, direction);
  434. }
  435. }
  436. void CXTPDockingPaneManager::_InsertPane(CXTPDockingPaneBase* pPane, XTPDockingPaneDirection direction, CXTPDockingPaneBase* pNeighbour)
  437. {
  438. ASSERT(pPane->m_pParentContainer == NULL);
  439. if (pNeighbour == NULL || (pNeighbour->GetType() == xtpPaneTypeDockingPane &&
  440. (IsPaneHidden((CXTPDockingPane*)pNeighbour) || IsPaneClosed((CXTPDockingPane*)pNeighbour))))
  441. {
  442. pNeighbour = GetTopPane();
  443. }
  444. ASSERT(pNeighbour);
  445. if (!pNeighbour)
  446. return;
  447. CWnd* pParentFrame = pNeighbour->GetDockingSite();
  448. ASSERT(pParentFrame != NULL);
  449. BOOL bHoriz = (direction == xtpPaneDockLeft || direction == xtpPaneDockRight);
  450. BOOL bAfter = (direction == xtpPaneDockRight || direction == xtpPaneDockBottom);
  451. if (pPane->GetType() == xtpPaneTypeDockingPane)
  452. {
  453. CXTPDockingPaneTabbedContainer* pContainer = (CXTPDockingPaneTabbedContainer*)OnCreatePane(xtpPaneTypeTabbedContainer, m_pLayout);
  454. pContainer->Init((CXTPDockingPane*)pPane, pParentFrame);
  455. pPane = pContainer;
  456. }
  457. if (pNeighbour == GetTopPane())
  458. {
  459. CXTPDockingPaneSplitterContainer* pSplitter = (CXTPDockingPaneSplitterContainer*)pNeighbour;
  460. if (pSplitter->m_bHoriz == bHoriz)
  461. pSplitter->_InsertPane(pPane, NULL, bAfter);
  462. else
  463. {
  464. CXTPDockingPaneSplitterContainer* pChildSplitter = (CXTPDockingPaneSplitterContainer*)OnCreatePane(xtpPaneTypeSplitterContainer, m_pLayout);
  465. pChildSplitter->Init(pSplitter, bHoriz, pParentFrame);
  466. pChildSplitter->_InsertPane(pPane, NULL, bAfter);
  467. m_pLayout->m_pTopContainer = pChildSplitter;
  468. }
  469. }
  470. else
  471. {
  472. ASSERT(pNeighbour->m_pParentContainer);
  473. if (!pNeighbour->m_pParentContainer)
  474. return;
  475. if (pNeighbour->m_pParentContainer->GetType() == xtpPaneTypeTabbedContainer)
  476. {
  477. pNeighbour = pNeighbour->m_pParentContainer;
  478. ASSERT(pNeighbour->m_pParentContainer != NULL);
  479. if (!pNeighbour->m_pParentContainer)
  480. return;
  481. }
  482. ASSERT(pNeighbour->m_pParentContainer);
  483. ASSERT(pNeighbour->m_pParentContainer->GetType() == xtpPaneTypeSplitterContainer);
  484. CXTPDockingPaneSplitterContainer* pSplitter = (CXTPDockingPaneSplitterContainer*)pNeighbour->m_pParentContainer;
  485. if (pSplitter->m_bHoriz == bHoriz)
  486. {
  487. pSplitter->_InsertPane(pPane, pNeighbour, bAfter);
  488. }
  489. else
  490. {
  491. CXTPDockingPaneSplitterContainer* pChildSplitter = (CXTPDockingPaneSplitterContainer*)OnCreatePane(xtpPaneTypeSplitterContainer, m_pLayout);
  492. pChildSplitter->Init(pNeighbour, bHoriz, pParentFrame);
  493. pChildSplitter->_InsertPane(pPane, pNeighbour, bAfter);
  494. pSplitter->_Replace(pNeighbour, pChildSplitter);
  495. }
  496. }
  497. RecalcFrameLayout(pNeighbour, TRUE);
  498. }
  499. CXTPDockingPaneBase* CXTPDockingPaneManager::_GetHolder(CXTPDockingPaneBase* pPane, BOOL bFloating)
  500. {
  501. POSITION pos = GetPaneList().GetHeadPosition();
  502. while (pos)
  503. {
  504. XTP_DOCKINGPANE_INFO& info = GetPaneList().GetNext(pos);
  505. if (info.pPane == pPane)
  506. return bFloating ? info.pFloatingHolder : info.pDockingHolder;
  507. }
  508. return NULL;
  509. }
  510. void CXTPDockingPaneManager::ToggleAutoHide(CXTPDockingPaneBase* pPane)
  511. {
  512. if (pPane == NULL)
  513. return;
  514. if (pPane->IsHidden())
  515. {
  516. if (pPane->GetType() == xtpPaneTypeDockingPane && m_bHideGroupOnButtonClick)
  517. {
  518. pPane = pPane->m_pParentContainer;
  519. }
  520. ToggleDocking(pPane);
  521. }
  522. else
  523. {
  524. HidePane(pPane);
  525. }
  526. }
  527. void CXTPDockingPaneManager::ToggleDocking(CXTPDockingPaneBase* pPane)
  528. {
  529. ASSERT(pPane);
  530. if (!pPane)
  531. return;
  532. BOOL bFloating = DYNAMIC_DOWNCAST(CXTPDockingPaneMiniWnd, pPane->GetDockingSite()) != NULL;
  533. BOOL bHidden = pPane->IsHidden();
  534. BOOL bDocking = !bFloating && !bHidden;
  535. if (pPane->GetType() == xtpPaneTypeSplitterContainer || pPane->GetType() == xtpPaneTypeTabbedContainer)
  536. {
  537. CXTPDockingPaneBaseList lst;
  538. ((CXTPDockingPaneBase*)pPane)->FindPane(xtpPaneTypeDockingPane, &lst);
  539. int nIDSelected = 0, nIDFocused = 0;
  540. POSITION pos = lst.GetHeadPosition();
  541. while (pos)
  542. {
  543. CXTPDockingPane* pListPane = (CXTPDockingPane*)lst.GetNext(pos);
  544. if (pListPane->IsSelected()) nIDSelected = pListPane->GetID();
  545. if (pListPane->IsFocus()) nIDFocused = pListPane->GetID();
  546. }
  547. pos = lst.GetHeadPosition();
  548. CXTPDockingPaneBase* pLastHolder = NULL;
  549. while (pos)
  550. {
  551. CXTPDockingPane* pListPane = (CXTPDockingPane*)lst.GetNext(pos);
  552. CXTPDockingPaneTabbedContainer* pHolder = (CXTPDockingPaneTabbedContainer*)_GetHolder(pListPane, bDocking);
  553. if (!_ToggleDocking(pListPane, pHolder ? pHolder : pLastHolder))
  554. {
  555. if (pListPane->GetID() == nIDSelected) nIDSelected = 0;
  556. if (pListPane->GetID() == nIDFocused) nIDFocused = 0;
  557. }
  558. pLastHolder = pHolder ? pHolder : pListPane->GetContainer();
  559. }
  560. if (nIDFocused > 0)
  561. ShowPane(nIDFocused);
  562. else if (nIDSelected > 0)
  563. ShowPane(nIDSelected);
  564. }
  565. else if (pPane->GetType() == xtpPaneTypeDockingPane)
  566. {
  567. CXTPDockingPaneTabbedContainer* pHolder = (CXTPDockingPaneTabbedContainer*)_GetHolder(pPane, bDocking);
  568. _ToggleDocking((CXTPDockingPane*)pPane, pHolder);
  569. }
  570. else
  571. {
  572. ASSERT(FALSE);
  573. }
  574. m_pLayout->_FreeEmptyPanes();
  575. m_hwndLastFocus = 0;
  576. }
  577. BOOL CXTPDockingPaneManager::_ToggleDocking(CXTPDockingPane* pPane, CXTPDockingPaneBase* pHolder)
  578. {
  579. BOOL bFloating = DYNAMIC_DOWNCAST(CXTPDockingPaneMiniWnd, pPane->GetDockingSite()) != NULL;
  580. BOOL bHidden = pPane->IsHidden();
  581. BOOL bDocking = !bFloating && !bHidden;
  582. if (bFloating && (pPane->GetOptions() & xtpPaneNoDockable))
  583. return FALSE;
  584. if (bDocking && (pPane->GetOptions() & xtpPaneNoFloatable))
  585. return FALSE;
  586. if (NotifyAction(bHidden ? xtpPaneActionPinning : !bDocking ? xtpPaneActionDocking : xtpPaneActionFloating, pPane, pHolder))
  587. return FALSE;
  588. if (pHolder)
  589. {
  590. m_bAttachingPane = TRUE;
  591. AttachPane(pPane, pHolder);
  592. m_bAttachingPane = FALSE;
  593. }
  594. else
  595. {
  596. FloatPane(pPane, pPane->GetContainer()->GetPaneWindowRect());
  597. }
  598. NotifyAction(bHidden ? xtpPaneActionPinned : !bDocking ? xtpPaneActionDocked : xtpPaneActionFloated, pPane);
  599. return TRUE;
  600. }
  601. void CXTPDockingPaneManager::EnableKeyboardNavigate(DWORD options)
  602. {
  603. CXTPDockingPaneKeyboardHook::GetThreadState()->SetupKeyboardHook(this, options != xtpPaneKeyboardUnused);
  604. m_bKeyboardEnabled = options;
  605. }
  606. bool CXTPDockingPaneManager::InstallDockingPanes(CWnd* pSite, bool bClipChildren/*=true*/)
  607. {
  608. #ifdef _DEBUG
  609. // must be a valid frame window.
  610. ASSERT(::IsWindow(pSite->GetSafeHwnd()));
  611. // should not be initialized yet.
  612. ASSERT(m_pLayout == 0);
  613. ASSERT(m_pSite == 0);
  614. #endif
  615. if (!::IsWindow(pSite->GetSafeHwnd()) || m_pSite != 0)
  616. {
  617. // if the docking site is not a valid frame window handle,
  618. // or the docking site is already initialized, return false.
  619. return false;
  620. }
  621. // Frame windows must have the WS_CLIPCHILDREN and WS_CLIPSIBLINGS
  622. // styles for panes to be drawn correctly when they are displayed
  623. // from a hidden state. WS_CLIPSIBLINGS should already be set by
  624. // default for most frames, however we will include it here just
  625. // in case.
  626. if (bClipChildren /*&& DYNAMIC_DOWNCAST(CMDIFrameWnd, pSite) == 0*/)
  627. {
  628. long lStyle = ::GetWindowLong(pSite->GetSafeHwnd(), GWL_STYLE);
  629. if ((lStyle & WS_CLIPSIBLINGS) == 0 || (lStyle & WS_CLIPCHILDREN) == 0)
  630. {
  631. ::SetWindowLong(pSite->GetSafeHwnd(), GWL_STYLE,
  632. lStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
  633. }
  634. }
  635. if (!Create(_T("XTPDockingPaneManager"), _T(""), WS_CHILD, CRect(0, 0, 0, 0), pSite, 0))
  636. return false;
  637. m_pSite = pSite;
  638. m_pLayout = CreateLayout();
  639. m_pLayout->m_bUserLayout = FALSE;
  640. CMenu* pMenu = m_pSite->GetSystemMenu(FALSE);
  641. if (pMenu)
  642. {
  643. pMenu->GetMenuString(SC_MOVE, m_strMove, MF_BYCOMMAND);
  644. if (m_strMove.IsEmpty()) m_strMove = _T("&Move");
  645. }
  646. return true;
  647. }
  648. CXTPDockingPane* CXTPDockingPaneManager::FindPane(int nID) const
  649. {
  650. if (!m_pLayout)
  651. return NULL;
  652. POSITION pos = GetPaneList().GetHeadPosition();
  653. while (pos)
  654. {
  655. CXTPDockingPane* pPane = GetPaneList().GetNext(pos);
  656. if (pPane->GetID() == nID)
  657. return pPane;
  658. }
  659. return NULL;
  660. }
  661. BOOL CXTPDockingPaneManager::SetIcons(UINT nIDResource, const int* nIDs, int nCount, COLORREF clrMask)
  662. {
  663. CImageList il;
  664. il.Create(16, 16, ILC_COLOR24 | ILC_MASK, nCount, 1);
  665. CBitmap bmp;
  666. bmp.LoadBitmap(nIDResource);
  667. il.Add(&bmp, clrMask);
  668. ASSERT(il.GetImageCount() == nCount); // Icons must be 16x16.
  669. if (il.GetImageCount() != nCount)
  670. return FALSE;
  671. for (int i = 0; i < nCount; i++)
  672. {
  673. HICON hIcon = il.ExtractIcon(i);
  674. if (nIDs[i] > 0)
  675. {
  676. SetIcon(nIDs[i], hIcon);
  677. }
  678. DestroyIcon(hIcon);
  679. }
  680. return TRUE;
  681. }
  682. void CXTPDockingPaneManager::SetImageManager(CXTPImageManager* pImageManager)
  683. {
  684. if (pImageManager)
  685. {
  686. m_pImageManager->InternalRelease();
  687. m_pImageManager = pImageManager;
  688. }
  689. }
  690. void CXTPDockingPaneManager::ShowPane(CXTPDockingPane* pPane, BOOL bSetFocus /*= TRUE*/)
  691. {
  692. if (pPane == NULL || m_pLayout == NULL) return;
  693. if (pPane->m_pParentContainer == NULL)
  694. {
  695. POSITION pos = GetPaneList().GetHeadPosition();
  696. while (pos)
  697. {
  698. XTP_DOCKINGPANE_INFO& info = GetPaneList().GetNext(pos);
  699. if (info.pPane == pPane && info.pLastHolder != NULL)
  700. {
  701. ((CXTPDockingPaneTabbedContainer*)info.pLastHolder)->_InsertPane(pPane, bSetFocus);
  702. }
  703. }
  704. }
  705. else
  706. {
  707. ((CXTPDockingPaneTabbedContainer*)pPane->m_pParentContainer)->ShowPane(pPane, bSetFocus);
  708. }
  709. if (bSetFocus && m_bLayoutCreated)
  710. {
  711. pPane->ShowWindow(TRUE);
  712. }
  713. if (bSetFocus)
  714. {
  715. pPane->SetFocus();
  716. }
  717. }
  718. LRESULT CXTPDockingPaneManager::NotifyOwner(UINT nCode, LPARAM lParam)
  719. {
  720. CWnd* pOwner = m_hWndOwner != NULL ? GetOwner() : m_pSite;
  721. ASSERT_VALID(pOwner);
  722. return pOwner->SendMessage(XTPWM_DOCKINGPANE_NOTIFY,
  723. (WPARAM)nCode, lParam);
  724. }
  725. void CXTPDockingPaneManager::ClosePane(CXTPDockingPane* pPane)
  726. {
  727. if (pPane == NULL)
  728. return;
  729. pPane->InternalAddRef();
  730. if (NotifyOwner(XTP_DPN_CLOSEPANE, (LPARAM)pPane) != XTP_ACTION_NOCLOSE)
  731. {
  732. SAFE_CALLPTR(pPane->m_pParentContainer, RemovePane(pPane));
  733. }
  734. pPane->InternalRelease();
  735. }
  736. void CXTPDockingPaneManager::HidePane(CXTPDockingPaneBase* pPane)
  737. {
  738. if (pPane == NULL) return;
  739. if (pPane->GetType() == xtpPaneTypeDockingPane && m_bHideGroupOnButtonClick)
  740. {
  741. pPane = pPane->m_pParentContainer;
  742. }
  743. if (pPane == NULL || pPane->GetContainer() == NULL)
  744. return;
  745. if (pPane->GetContainer()->GetType() == xtpPaneTypeAutoHidePanel)
  746. {
  747. ((CXTPDockingPaneAutoHidePanel*)pPane->GetContainer())->CloseActiveWindow();
  748. return;
  749. }
  750. m_pLayout->HidePane(pPane);
  751. RecalcFrameLayout(NULL, TRUE);
  752. }
  753. void CXTPDockingPaneManager::DestroyPane(CXTPDockingPane* pPane)
  754. {
  755. if (m_pLayout && pPane)
  756. {
  757. m_pLayout->DestroyPane(pPane);
  758. RecalcFrameLayout(NULL);
  759. }
  760. }
  761. BOOL CXTPDockingPaneManager::IsPaneClosed(CXTPDockingPane* pPane) const
  762. {
  763. return pPane == NULL || pPane->IsClosed();
  764. }
  765. BOOL CXTPDockingPaneManager::IsPaneHidden(CXTPDockingPane* pPane) const
  766. {
  767. return pPane != NULL && pPane->IsHidden();
  768. }
  769. BOOL CXTPDockingPaneManager::IsPaneSelected(CXTPDockingPane* pPane) const
  770. {
  771. return pPane != NULL && pPane->IsSelected();
  772. }
  773. void CXTPDockingPaneManager::_Redraw()
  774. {
  775. if (!m_hWnd)
  776. return;
  777. POSITION pos = GetPaneList().GetHeadPosition();
  778. while (pos)
  779. {
  780. CXTPDockingPane* pPane = GetPaneList().GetNext(pos);
  781. RecalcFrameLayout(pPane, TRUE);
  782. CWnd* pFrame = pPane->GetDockingSite();
  783. if (DYNAMIC_DOWNCAST(CXTPDockingPaneMiniWnd, pFrame))
  784. {
  785. ((CXTPDockingPaneMiniWnd*)pFrame)->OnThemedChanged();
  786. }
  787. if (pPane->GetContainer())
  788. {
  789. pPane->GetContainer()->InvalidatePane(FALSE);
  790. }
  791. }
  792. }
  793. void CXTPDockingPaneManager::SyncActiveFloatingFrames(BOOL bSyncActiveFloatingFrames)
  794. {
  795. if (m_bSyncActiveFloatingFrames == bSyncActiveFloatingFrames)
  796. return;
  797. m_bSyncActiveFloatingFrames = bSyncActiveFloatingFrames;
  798. POSITION pos = GetPaneStack().GetHeadPosition();
  799. while (pos)
  800. {
  801. CXTPDockingPaneBase* pPane = GetPaneStack().GetNext(pos);
  802. if (pPane->GetType() == xtpPaneTypeMiniWnd)
  803. {
  804. CXTPDockingPaneMiniWnd* pFrame = (CXTPDockingPaneMiniWnd*)pPane;
  805. if (pFrame->m_hWnd)
  806. {
  807. pFrame->ModifyStyle(bSyncActiveFloatingFrames ? 0: MFS_SYNCACTIVE, bSyncActiveFloatingFrames ? MFS_SYNCACTIVE : SWP_FRAMECHANGED);
  808. }
  809. }
  810. }
  811. }
  812. void CXTPDockingPaneManager::SetTheme(XTPDockingPanePaintTheme paintTheme)
  813. {
  814. if (m_pPaintManager != NULL)
  815. m_pPaintManager->InternalRelease();
  816. if (paintTheme == xtpPaneThemeOffice) m_pPaintManager = new CXTPDockingPaneOfficeTheme();
  817. else if (paintTheme == xtpPaneThemeGrippered) m_pPaintManager = new CXTPDockingPaneGripperedTheme();
  818. else if (paintTheme == xtpPaneThemeVisio) m_pPaintManager = new CXTPDockingPaneVisioTheme();
  819. else if (paintTheme == xtpPaneThemeOffice2003) m_pPaintManager = new CXTPDockingPaneOffice2003Theme();
  820. else if (paintTheme == xtpPaneThemeNativeWinXP) m_pPaintManager = new CXTPDockingPaneNativeXPTheme();
  821. else if (paintTheme == xtpPaneThemeWhidbey) m_pPaintManager = new CXTPDockingPaneWhidbeyTheme();
  822. else if (paintTheme == xtpPaneThemeVisualStudio2005) m_pPaintManager = new CXTPDockingPaneVisualStudio2005Theme();
  823. else if (paintTheme == xtpPaneThemeShortcutBar2003) m_pPaintManager = new CXTPDockingPaneShortcutBar2003Theme();
  824. else if (paintTheme == xtpPaneThemeExplorer) m_pPaintManager = new CXTPDockingPaneExplorerTheme();
  825. else if (paintTheme == xtpPaneThemeOffice2007) m_pPaintManager = new CXTPDockingPaneOffice2007Theme();
  826. else if (paintTheme == xtpPaneThemeWord2007) m_pPaintManager = new CXTPDockingPaneWord2007Theme();
  827. else m_pPaintManager = new CXTPDockingPaneDefaultTheme();
  828. m_pPaintManager->m_themeCurrent = paintTheme;
  829. m_pPaintManager->RefreshMetrics();
  830. _Redraw();
  831. if (paintTheme == xtpPaneThemeVisualStudio2005)
  832. {
  833. SetDockingContextStickerStyle(xtpPaneStickerStyleVisualStudio2005);
  834. }
  835. }
  836. void CXTPDockingPaneManager::SetCustomTheme(CXTPDockingPanePaintManager* pTheme)
  837. {
  838. ASSERT(pTheme);
  839. if (!pTheme)
  840. return;
  841. if (m_pPaintManager != NULL)
  842. m_pPaintManager->InternalRelease();
  843. m_pPaintManager = pTheme;
  844. m_pPaintManager->m_themeCurrent = xtpPaneThemeCustom;
  845. m_pPaintManager->RefreshMetrics();
  846. _Redraw();
  847. }
  848. XTPDockingPanePaintTheme CXTPDockingPaneManager::GetCurrentTheme() const
  849. {
  850. return m_pPaintManager->m_themeCurrent;
  851. }
  852. CXTPDockingPaneLayout* CXTPDockingPaneManager::CreateLayout()
  853. {
  854. return new CXTPDockingPaneLayout(this);
  855. }
  856. void CXTPDockingPaneManager::GetLayout(CXTPDockingPaneLayout* pLayout) const
  857. {
  858. ASSERT(pLayout);
  859. if (!pLayout)
  860. return;
  861. pLayout->Copy(m_pLayout);
  862. }
  863. void CXTPDockingPaneManager::_DetachAll()
  864. {
  865. POSITION pos = GetPaneList().GetHeadPosition();
  866. while (pos)
  867. {
  868. CXTPDockingPane* pPane = GetPaneList().GetNext(pos);
  869. pPane->Detach();
  870. }
  871. }
  872. void CXTPDockingPaneManager::SetLayout(const CXTPDockingPaneLayout* pLayout)
  873. {
  874. ASSERT(pLayout);
  875. if (!pLayout || !pLayout->IsValid())
  876. return;
  877. _DetachAll();
  878. m_pLayout->Copy(pLayout);
  879. _Redraw();
  880. }
  881. void CXTPDockingPaneManager::DestroyAll()
  882. {
  883. if (m_pLayout)
  884. {
  885. m_pLayout->InternalRelease();
  886. m_pLayout = CreateLayout();
  887. m_pLayout->m_bUserLayout = FALSE;
  888. }
  889. }
  890. void CXTPDockingPaneManager::CloseAll()
  891. {
  892. CXTPDockingPaneInfoList& paneList = GetPaneList();
  893. POSITION pos = paneList.GetHeadPosition();
  894. while (pos)
  895. {
  896. CXTPDockingPane* pPane = paneList.GetNext(pos);
  897. pPane->Close();
  898. }
  899. }
  900. CXTPDockingPaneBaseList& CXTPDockingPaneManager::GetPaneStack() const
  901. {
  902. return m_pLayout->m_lstStack;
  903. }
  904. CXTPDockingPaneInfoList& CXTPDockingPaneManager::GetPaneList() const
  905. {
  906. return m_pLayout->m_lstPanes;
  907. }
  908. CXTPDockingPaneBase* CXTPDockingPaneManager::GetClientPane() const
  909. {
  910. return m_pLayout ? m_pLayout->m_pClient : NULL;
  911. }
  912. CXTPDockingPaneBase* CXTPDockingPaneManager::GetTopPane() const
  913. {
  914. return m_pLayout ? (CXTPDockingPaneBase*)m_pLayout->m_pTopContainer : NULL;
  915. }
  916. void CXTPDockingPaneManager::SetIcon(UINT nID, CXTPImageManagerIconHandle hIcon)
  917. {
  918. m_pImageManager->SetIcon(hIcon, nID, 0, xtpImageNormal);
  919. }
  920. CXTPImageManagerIcon* CXTPDockingPaneManager::GetIcon(UINT nID, int nWidth) const
  921. {
  922. return m_pImageManager->GetImage(nID, nWidth);
  923. }
  924. void CXTPDockingPaneManager::ClearIconMap()
  925. {
  926. m_pImageManager->RemoveAll();
  927. }
  928. void CXTPDockingPaneManager::SetThemedFloatingFrames(BOOL bThemedFloatingFrames)
  929. {
  930. m_bThemedFloatingFrames = bThemedFloatingFrames;
  931. if (!m_pLayout)
  932. return;
  933. POSITION pos = GetPaneList().GetHeadPosition();
  934. while (pos)
  935. {
  936. CXTPDockingPane* pPane = GetPaneList().GetNext(pos);
  937. CWnd* pFrame = pPane->GetDockingSite();
  938. if (DYNAMIC_DOWNCAST(CXTPDockingPaneMiniWnd, pFrame))
  939. {
  940. ((CXTPDockingPaneMiniWnd*)pFrame)->OnThemedChanged();
  941. }
  942. }
  943. }
  944. void CXTPDockingPaneManager::SetAnimationDelay(double dAnimationDelay /*= -1*/, int nAnimationDuration /*= 128*/, int nAnimationInterval /*= 16*/)
  945. {
  946. CXTPDockingPaneAutoHideWnd::m_dAnimationDelay = dAnimationDelay;
  947. CXTPDockingPaneAutoHideWnd::m_nAnimationDuration = nAnimationDuration;
  948. CXTPDockingPaneAutoHideWnd::m_nAnimationInterval = nAnimationInterval;
  949. }
  950. double CXTPDockingPaneManager::GetAnimationDelay(int* pAnimationDuration /*= NULL*/, int* pAnimationInterval /*= NULL*/) const
  951. {
  952. if (pAnimationDuration) *pAnimationDuration = CXTPDockingPaneAutoHideWnd::m_nAnimationDuration;
  953. if (pAnimationInterval) *pAnimationInterval = CXTPDockingPaneAutoHideWnd::m_nAnimationInterval;
  954. return CXTPDockingPaneAutoHideWnd::m_dAnimationDelay;
  955. }
  956. BOOL CXTPDockingPaneManager::IsLayoutRTL() const
  957. {
  958. return (GetSite()->GetExStyle() & WS_EX_LAYOUTRTL) != 0;
  959. }
  960. XTPDockingPaneDirection CXTPDockingPaneManager::GetRTLDirection(XTPDockingPaneDirection direction) const
  961. {
  962. if (IsLayoutRTL())
  963. {
  964. if (direction == xtpPaneDockLeft) direction = xtpPaneDockRight;
  965. else if (direction == xtpPaneDockRight) direction = xtpPaneDockLeft;
  966. }
  967. return direction;
  968. }
  969. XTPDockingPaneDirection CXTPDockingPaneManager::GetPaneDirection(const CXTPDockingPaneBase* pPane) const
  970. {
  971. ASSERT(m_pLayout);
  972. if (!m_pLayout)
  973. return xtpPaneDockTop;
  974. return m_pLayout->_GetPaneDirection(pPane);
  975. }
  976. void CXTPDockingPaneManager::SetDockingContext(CXTPDockingPaneContext* pDockingContext)
  977. {
  978. delete m_pDockingContext;
  979. m_pDockingContext = pDockingContext;
  980. m_pDockingContext->m_pManager = this;
  981. }
  982. void CXTPDockingPaneManager::NormalizeSplitters()
  983. {
  984. CXTPDockingPaneBaseList& lst = GetPaneStack();
  985. POSITION pos = lst.GetHeadPosition();
  986. while (pos)
  987. {
  988. CXTPDockingPaneBase* pPane = lst.GetNext(pos);
  989. if (pPane->GetType() == xtpPaneTypeSplitterContainer)
  990. {
  991. ((CXTPDockingPaneSplitterContainer*)pPane)->NormalizeDockingSize();
  992. }
  993. }
  994. }
  995. void CXTPDockingPaneManager::RecalcFramesLayout()
  996. {
  997. CXTPDockingPaneBaseList& lst = GetPaneStack();
  998. POSITION pos = lst.GetHeadPosition();
  999. while (pos)
  1000. {
  1001. CXTPDockingPaneBase* pPane = lst.GetNext(pos);
  1002. if (pPane->GetType() == xtpPaneTypeMiniWnd)
  1003. {
  1004. CXTPDockingPaneMiniWnd* pMiniWnd = (CXTPDockingPaneMiniWnd*)pPane;
  1005. if (pMiniWnd->m_hWnd && pMiniWnd->GetStyle() & WS_VISIBLE)
  1006. {
  1007. pMiniWnd->RecalcLayout(TRUE);
  1008. pMiniWnd->MoveWindow(CXTPWindowRect(pMiniWnd));
  1009. }
  1010. }
  1011. }
  1012. RecalcFrameLayout(NULL);
  1013. }
  1014. void CXTPDockingPaneManager::EnsureVisible(CXTPDockingPaneBase* pPane)
  1015. {
  1016. if (!pPane)
  1017. return;
  1018. if (pPane->GetType() == xtpPaneTypeDockingPane)
  1019. {
  1020. ShowPane((CXTPDockingPane*)pPane, FALSE);
  1021. pPane = pPane->GetContainer();
  1022. }
  1023. if (pPane->GetType() == xtpPaneTypeTabbedContainer)
  1024. {
  1025. ((CXTPDockingPaneTabbedContainer*)pPane)->Show(FALSE);
  1026. }
  1027. CWnd* pSite = pPane->GetDockingSite();
  1028. if (DYNAMIC_DOWNCAST(CXTPDockingPaneMiniWnd, pSite))
  1029. {
  1030. pSite->BringWindowToTop();
  1031. }
  1032. }
  1033. void CXTPDockingPaneManager::OnSetPreviewMode(BOOL bPreview)
  1034. {
  1035. // Toggle Docking Panes.
  1036. if (bPreview)
  1037. {
  1038. ASSERT(m_pPreviewLayout == NULL);
  1039. m_pPreviewLayout = CreateLayout();
  1040. GetLayout(m_pPreviewLayout);
  1041. CloseAll();
  1042. }
  1043. else
  1044. {
  1045. ASSERT(m_pPreviewLayout != NULL);
  1046. SetLayout(m_pPreviewLayout);
  1047. CMDTARGET_RELEASE(m_pPreviewLayout);
  1048. }
  1049. }
  1050. void CXTPDockingPaneManager::OnActivatePane(BOOL bActive, CXTPDockingPane* pPane)
  1051. {
  1052. if (bActive && m_pActivePane != pPane)
  1053. {
  1054. if (m_pActivePane)
  1055. {
  1056. NotifyAction(xtpPaneActionDeactivated, m_pActivePane);
  1057. m_pActivePane->InternalRelease();
  1058. }
  1059. m_pActivePane = pPane;
  1060. if (m_pActivePane)
  1061. {
  1062. m_pActivePane->InternalAddRef();
  1063. NotifyAction(xtpPaneActionActivated, m_pActivePane);
  1064. }
  1065. }
  1066. else if (!bActive && pPane && m_pActivePane == pPane)
  1067. {
  1068. m_pActivePane = 0;
  1069. NotifyAction(xtpPaneActionDeactivated, pPane);
  1070. pPane->InternalRelease();
  1071. }
  1072. }
  1073. BOOL CXTPDockingPaneManager::DoPropExchange(CXTPPropExchange* pPX)
  1074. {
  1075. if (pPX->IsStoring())
  1076. {
  1077. CXTPDockingPaneLayout layoutNormal(this);
  1078. GetLayout(&layoutNormal);
  1079. layoutNormal.DoPropExchange(pPX);
  1080. }
  1081. else
  1082. {
  1083. CXTPDockingPaneLayout layoutNormal(this);
  1084. if (!layoutNormal.DoPropExchange(pPX))
  1085. return FALSE;
  1086. SetLayout(&layoutNormal);
  1087. }
  1088. return TRUE;
  1089. }
  1090. void CXTPDockingPaneManager::RecalcFrameLayout(CXTPDockingPaneBase* pPane, BOOL bDelay)
  1091. {
  1092. CWnd* pSite = pPane ? pPane->GetDockingSite() : GetSite();
  1093. if (!pSite || !IsWindow(pSite->GetSafeHwnd()))
  1094. return;
  1095. CFrameWnd* pFrame = pSite->IsFrameWnd() ? (CFrameWnd*)pSite : NULL;
  1096. if (pFrame)
  1097. {
  1098. if (bDelay)
  1099. {
  1100. pFrame->DelayRecalcLayout(FALSE);
  1101. pFrame->PostMessage(WM_IDLEUPDATECMDUI);
  1102. }
  1103. else
  1104. pFrame->RecalcLayout(FALSE);
  1105. }
  1106. else
  1107. {
  1108. CXTPClientRect rc(pSite);
  1109. if (bDelay)
  1110. {
  1111. MSG msg;
  1112. if (PeekMessage(&msg, pSite->GetSafeHwnd(), WM_SIZE, WM_SIZE, PM_NOREMOVE))
  1113. return;
  1114. pSite->PostMessage(WM_SIZE, 0, MAKELPARAM(rc.Width(), rc.Height()));
  1115. }
  1116. else
  1117. pSite->SendMessage(WM_SIZE, 0, MAKELPARAM(rc.Width(), rc.Height()));
  1118. }
  1119. }
  1120. void CXTPDockingPaneManager::_TrackPopupContextMenu(CXTPDockingPane* pPane)
  1121. {
  1122. CPoint pt(0, 0);
  1123. CXTPDockingPaneBase* pContainer = pPane->GetContainer();
  1124. if (pPane->IsFloating())
  1125. {
  1126. pPane->GetDockingSite()->ClientToScreen(&pt);
  1127. pContainer = ((CXTPDockingPaneMiniWnd*)pPane->GetDockingSite())->GetTopPane();
  1128. }
  1129. else
  1130. {
  1131. CRect rc = pContainer->GetPaneWindowRect();
  1132. GetPaintManager()->AdjustCaptionRect((CXTPDockingPaneTabbedContainer*)pContainer, rc);
  1133. pt = rc.TopLeft();
  1134. }
  1135. CMenu menu;
  1136. menu.CreatePopupMenu();
  1137. menu.InsertMenu(0, MF_BYPOSITION | MF_STRING, SC_MOVE, m_strMove);
  1138. BOOL nCommand = TrackPopupMenu(menu, TPM_RETURNCMD, pt.x, pt.y, 0, GetSite()->GetSafeHwnd(), NULL);
  1139. if (nCommand == SC_MOVE)
  1140. {
  1141. CXTPDockingPaneContext* pContext = GetDockingContext();
  1142. pContext->Drag(pContainer, CPoint(-1, -1));
  1143. }
  1144. }
  1145. BOOL CXTPDockingPaneManager::ActivateNextPane(CXTPDockingPane* pPaneActive, BOOL bForward)
  1146. {
  1147. if (!m_pLayout)
  1148. return FALSE;
  1149. CXTPDockingPaneInfoList& paneList = m_pLayout->GetPaneList();
  1150. if (paneList.IsEmpty())
  1151. return FALSE;
  1152. BOOL bActive = (pPaneActive != NULL);
  1153. POSITION posFirst = bForward ? paneList.GetHeadPosition() : paneList.GetTailPosition();
  1154. POSITION pos = posFirst;
  1155. while (pos)
  1156. {
  1157. CXTPDockingPane* pPane = bForward ? paneList.GetNext(pos) : paneList.GetPrev(pos);
  1158. if (pos == NULL && bActive)
  1159. {
  1160. pos = posFirst;
  1161. bActive = FALSE;
  1162. }
  1163. if (!pPaneActive)
  1164. {
  1165. if ((pPane->GetEnabled() & xtpPaneEnableClient) == 0)
  1166. continue;
  1167. ShowPane(pPane);
  1168. return TRUE;
  1169. }
  1170. else if (pPane == pPaneActive)
  1171. {
  1172. pPaneActive = NULL;
  1173. }
  1174. }
  1175. return FALSE;
  1176. }
  1177. BOOL CXTPDockingPaneManager::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  1178. {
  1179. if (message == WM_DESTROY && m_bKeyboardEnabled)
  1180. {
  1181. m_bKeyboardEnabled = FALSE;
  1182. CXTPDockingPaneKeyboardHook::GetThreadState()->SetupKeyboardHook(this, FALSE);
  1183. }
  1184. if (message == WM_SYSCOMMAND && wParam == SC_KEYMENU && LOWORD(lParam) == TEXT('-'))
  1185. {
  1186. CXTPDockingPane* pPane = GetActivePane();
  1187. if (pPane && !pPane->IsClosed() && !pPane->IsHidden())
  1188. {
  1189. _TrackPopupContextMenu(pPane);
  1190. return TRUE;
  1191. }
  1192. }
  1193. if (message == WM_SYSCOMMAND && (wParam == SC_NEXTWINDOW || wParam == SC_PREVWINDOW))
  1194. {
  1195. return ActivateNextPane(GetActivePane(), wParam == SC_NEXTWINDOW);
  1196. }
  1197. return CWnd::OnWndMsg(message, wParam, lParam, pResult);
  1198. }
  1199. //////////////////////////////////////////////////////////////////////////
  1200. // Accessible
  1201. CCmdTarget* CXTPDockingPaneManager::GetAccessible()
  1202. {
  1203. return this;
  1204. }
  1205. HRESULT CXTPDockingPaneManager::GetAccessibleParent(IDispatch* FAR* ppdispParent)
  1206. {
  1207. if (GetSafeHwnd())
  1208. {
  1209. return AccessibleObjectFromWindow(GetSafeHwnd(), OBJID_WINDOW, IID_IDispatch, (void**)ppdispParent);
  1210. }
  1211. return E_FAIL;
  1212. }
  1213. HRESULT CXTPDockingPaneManager::GetAccessibleChildCount(long FAR* pChildCount)
  1214. {
  1215. if (pChildCount == 0)
  1216. return E_INVALIDARG;
  1217. *pChildCount = (long)m_pLayout->GetPaneList().GetCount();
  1218. return S_OK;
  1219. }
  1220. HRESULT CXTPDockingPaneManager::GetAccessibleChild(VARIANT varChild, IDispatch* FAR* ppdispChild)
  1221. {
  1222. *ppdispChild = NULL;
  1223. int nChild = GetChildIndex(&varChild);
  1224. if (nChild > 0 && nChild <= m_pLayout->GetPaneList().GetCount())
  1225. {
  1226. CXTPDockingPane* pPane = m_pLayout->GetPaneList().GetAt(m_pLayout->GetPaneList().FindIndex(nChild - 1));
  1227. if (pPane)
  1228. {
  1229. *ppdispChild = pPane->GetIDispatch(TRUE);
  1230. }
  1231. }
  1232. return S_OK;
  1233. }
  1234. HRESULT CXTPDockingPaneManager::GetAccessibleName(VARIANT varChild, BSTR* pszName)
  1235. {
  1236. int nChild = GetChildIndex(&varChild);
  1237. if (nChild == CHILDID_SELF || nChild == -1)
  1238. {
  1239. *pszName = SysAllocString(L"XTPDockingPaneManager");
  1240. return S_OK;
  1241. }
  1242. return E_INVALIDARG;
  1243. }
  1244. HRESULT CXTPDockingPaneManager::GetAccessibleRole(VARIANT varChild, VARIANT* pvarRole)
  1245. {
  1246. pvarRole->vt = VT_EMPTY;
  1247. int nChild = GetChildIndex(&varChild);
  1248. if (nChild == CHILDID_SELF)
  1249. {
  1250. pvarRole->vt = VT_I4;
  1251. pvarRole->lVal = ROLE_SYSTEM_PROPERTYPAGE;
  1252. return S_OK;
  1253. }
  1254. return E_INVALIDARG;
  1255. }
  1256. HRESULT CXTPDockingPaneManager::GetAccessibleState(VARIANT varChild, VARIANT* pvarState)
  1257. {
  1258. int nChild = GetChildIndex(&varChild);
  1259. if (nChild == CHILDID_SELF || nChild == -1)
  1260. {
  1261. pvarState->vt = VT_I4;
  1262. pvarState->lVal = 0;
  1263. return S_OK;
  1264. }
  1265. return E_INVALIDARG;
  1266. }
  1267. HRESULT CXTPDockingPaneManager::AccessibleLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT /*varChild*/)
  1268. {
  1269. *pxLeft = *pyTop = 0;
  1270. *pcxWidth = *pcyHeight = 10;
  1271. return S_OK;
  1272. }
  1273. HRESULT CXTPDockingPaneManager::AccessibleHitTest(long /*xLeft*/, long /*yTop*/, VARIANT* /*pvarID*/)
  1274. {
  1275. return S_FALSE;
  1276. }
  1277. LRESULT CXTPDockingPaneManager::OnGetObject(WPARAM wParam, LPARAM lParam)
  1278. {
  1279. if (lParam != OBJID_CLIENT)
  1280. return (LRESULT)Default();
  1281. LPUNKNOWN lpUnknown = GetInterface(&IID_IAccessible);
  1282. if (!lpUnknown)
  1283. return E_FAIL;
  1284. return LresultFromObject(IID_IAccessible, wParam, lpUnknown);
  1285. }
  1286. BEGIN_INTERFACE_MAP(CXTPDockingPaneManager, CCmdTarget)
  1287. INTERFACE_PART(CXTPDockingPaneManager, IID_IAccessible, ExternalAccessible)
  1288. END_INTERFACE_MAP()