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

对话框与窗口

开发平台:

Visual C++

  1. // XTPDockingPane.cpp : implementation of the CXTPDockingPaneclass.
  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 "TabManager/XTPTabManager.h"
  22. #include "Common/XTPDrawHelpers.h"
  23. #include "XTPDockingPane.h"
  24. #include "XTPDockingPaneContext.h"
  25. #include "XTPDockingPaneManager.h"
  26. #include "XTPDockingPaneTabbedContainer.h"
  27. #include "XTPDockingPaneAutoHidePanel.h"
  28. #include "XTPDockingPaneMiniWnd.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. CXTPDockingPane::CXTPDockingPane(CXTPDockingPaneLayout* pLayout)
  35. : CXTPDockingPaneBase(xtpPaneTypeDockingPane, pLayout)
  36. {
  37. m_dwOptions = 0;
  38. m_hwndChild = 0;
  39. m_nID = 0;
  40. m_nIconID = -1;
  41. m_dwData = 0;
  42. m_clrItemTab = COLORREF_NULL;
  43. m_nIDHelp = 0;
  44. m_bEnabled = xtpPaneEnabled;
  45. m_ptMinTrackSize = CPoint(0, 0);
  46. m_ptMaxTrackSize = CPoint(32000, 32000);
  47. EnableAutomation();
  48. }
  49. CXTPDockingPane::~CXTPDockingPane()
  50. {
  51. }
  52. void CXTPDockingPane::SetID(int nID)
  53. {
  54. ASSERT(nID != 0);
  55. m_nID = nID;
  56. CString strTitle;
  57. if (strTitle.LoadString(nID))
  58. {
  59. m_strTitle = strTitle;
  60. }
  61. }
  62. void CXTPDockingPane::SetWindowRect(CRect rc)
  63. {
  64. m_rcWindow = rc;
  65. m_szDocking = m_rcWindow.Size();
  66. }
  67. XTPXTPDockingPaneEnableOptions CXTPDockingPane::GetEnabled() const
  68. {
  69. return m_bEnabled;
  70. }
  71. void CXTPDockingPane::SetEnabled(XTPXTPDockingPaneEnableOptions bEnabled)
  72. {
  73. if (m_bEnabled != bEnabled)
  74. {
  75. m_bEnabled = bEnabled;
  76. InvalidatePane(TRUE);
  77. }
  78. }
  79. void CXTPDockingPane::OnSizeParent(CWnd* pParent, CRect rect, LPVOID lParam)
  80. {
  81. AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam;
  82. SetDockingSite(pParent);
  83. if (lpLayout == 0 || lpLayout->hDWP != NULL)
  84. {
  85. m_rcWindow = rect;
  86. if (pParent && m_pParentContainer)
  87. {
  88. MapWindowPoints(pParent->GetSafeHwnd(), m_pParentContainer->GetPaneHwnd(), (LPPOINT)&rect, 2);
  89. if (m_hwndChild) ::MoveWindow(m_hwndChild, rect.left, rect.top, rect.Width(), rect.Height(), TRUE);
  90. if (m_hwndChild) ::EnableWindow(m_hwndChild, m_bEnabled & xtpPaneEnableClient ? TRUE : FALSE);
  91. }
  92. }
  93. }
  94. void CXTPDockingPane::SetFocus()
  95. {
  96. if (m_hwndChild)
  97. {
  98. if (!IsChild(m_hwndChild, ::GetFocus()))
  99. ::SetFocus(m_hwndChild);
  100. }
  101. }
  102. BOOL CXTPDockingPane::IsFocus() const
  103. {
  104. HWND hwndFocus = ::GetFocus();
  105. return (m_hwndChild != 0) && (hwndFocus == m_hwndChild || IsChild(m_hwndChild, hwndFocus));
  106. }
  107. void CXTPDockingPane::SetParentContainer(CXTPDockingPaneBase* pContainer)
  108. {
  109. m_pParentContainer = pContainer;
  110. if (m_hwndChild == 0)
  111. return;
  112. if (pContainer)
  113. {
  114. ASSERT(pContainer->GetType() == xtpPaneTypeTabbedContainer);
  115. ::SetParent(m_hwndChild, pContainer->GetPaneHwnd());
  116. }
  117. else
  118. {
  119. ::ShowWindow(m_hwndChild, SW_HIDE);
  120. ::SetParent(m_hwndChild, GetDockingPaneManager()->GetSafeHwnd());
  121. m_pDockingSite = NULL;
  122. }
  123. }
  124. void CXTPDockingPane::ShowWindow(BOOL bShow)
  125. {
  126. if (bShow)
  127. {
  128. GetDockingPaneManager()->NotifyOwner(XTP_DPN_SHOWWINDOW, (LPARAM)this);
  129. }
  130. if (m_hwndChild)
  131. {
  132. ::ShowWindow(m_hwndChild, bShow ? SW_SHOW : SW_HIDE);
  133. }
  134. }
  135. void CXTPDockingPane::Close()
  136. {
  137. GetDockingPaneManager()->ClosePane(this);
  138. }
  139. void CXTPDockingPane::Hide()
  140. {
  141. GetDockingPaneManager()->HidePane(this);
  142. }
  143. void CXTPDockingPane::Select()
  144. {
  145. GetDockingPaneManager()->ShowPane(this);
  146. }
  147. CWnd* CXTPDockingPane::GetDockingSite() const
  148. {
  149. return m_pParentContainer ? m_pParentContainer->m_pDockingSite : 0;
  150. }
  151. CFrameWnd* CXTPDockingPane::GetParentFrame() const
  152. {
  153. CWnd* pSite = GetDockingSite();
  154. return pSite && pSite->IsFrameWnd() ? (CFrameWnd*)pSite : NULL;
  155. }
  156. void CXTPDockingPane::Copy(CXTPDockingPaneBase* pCloneBase, CXTPPaneToPaneMap* /*pMap*/, DWORD /*dwIgnoredOptions*/)
  157. {
  158. Copy((CXTPDockingPane*)pCloneBase);
  159. }
  160. void CXTPDockingPane::Copy(CXTPDockingPane* pClone)
  161. {
  162. m_szDocking = pClone->m_szDocking;
  163. m_strTitle = pClone->m_strTitle;
  164. m_nIconID = pClone->m_nIconID;
  165. m_dwOptions = pClone->m_dwOptions;
  166. m_dwData = pClone->m_dwData;
  167. m_nID = pClone->m_nID;
  168. m_bEnabled = pClone->m_bEnabled;
  169. m_ptMinTrackSize = pClone->m_ptMinTrackSize;
  170. m_ptMaxTrackSize = pClone->m_ptMaxTrackSize;
  171. m_hwndChild = 0;
  172. }
  173. BOOL CXTPDockingPane::IsValid() const
  174. {
  175. return m_hwndChild != NULL;
  176. }
  177. void CXTPDockingPane::Attach(CWnd* pWnd)
  178. {
  179. if (pWnd)
  180. {
  181. m_hwndChild = pWnd->GetSafeHwnd();
  182. GetDockingPaneManager()->_Redraw();
  183. if (m_pParentContainer)
  184. {
  185. ::SetParent(m_hwndChild, m_pParentContainer->GetPaneHwnd());
  186. }
  187. if (GetDockingPaneManager()->m_bInitialUpdateCalled)
  188. {
  189. pWnd->SendMessage(WM_INITIALUPDATE, 0, 0);
  190. pWnd->SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
  191. }
  192. }
  193. }
  194. CWnd* CXTPDockingPane::AttachView(CWnd* pParentWnd, CRuntimeClass* pViewClass, CDocument* pDocument/*= NULL*/, CCreateContext* pContext/*= NULL*/)
  195. {
  196. if (!pContext && !pViewClass)
  197. return NULL;
  198. #ifdef _DEBUG
  199. ASSERT(pContext != NULL || pViewClass != NULL);
  200. ASSERT(pContext != NULL || pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
  201. ASSERT(pContext != NULL || AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
  202. #endif
  203. CCreateContext contextT;
  204. if (pContext == NULL)
  205. {
  206. // if no context specified, generate one from the
  207. // currently selected client if possible.
  208. contextT.m_pLastView = NULL;
  209. contextT.m_pCurrentFrame = NULL;
  210. contextT.m_pNewDocTemplate = NULL;
  211. contextT.m_pCurrentDoc = pDocument;
  212. contextT.m_pNewViewClass = pViewClass;
  213. if (pDocument != NULL)
  214. contextT.m_pNewDocTemplate = pDocument->GetDocTemplate();
  215. pContext = &contextT;
  216. }
  217. CFrameWnd* pFrame = new CFrameWnd;
  218. pFrame->Create(NULL, NULL, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  219. CRect(0, 0, 0, 0), pParentWnd, NULL, 0, pContext);
  220. pFrame->ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
  221. Attach(pFrame);
  222. CWnd* pView = pFrame->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
  223. if (DYNAMIC_DOWNCAST(CView, pView))
  224. {
  225. pFrame->SetActiveView((CView*)pView);
  226. }
  227. return pView;
  228. }
  229. void CXTPDockingPane::Detach()
  230. {
  231. if (m_hwndChild)
  232. {
  233. ::ShowWindow(m_hwndChild, SW_HIDE);
  234. ::SetParent(m_hwndChild, GetDockingPaneManager()->GetSite()->GetSafeHwnd());
  235. m_hwndChild = 0;
  236. }
  237. GetDockingPaneManager()->_Redraw();
  238. }
  239. CString CXTPDockingPane::GetTitle() const
  240. {
  241. int nIndex = m_strTitle.Find('n');
  242. if (nIndex == -1)
  243. return m_strTitle;
  244. return m_strTitle.Left(nIndex);
  245. }
  246. CString CXTPDockingPane::GetShortTitle() const
  247. {
  248. int nIndex = m_strTitle.Find('n');
  249. if (nIndex == -1)
  250. return m_strTitle;
  251. return m_strTitle.Mid(nIndex + 1);
  252. }
  253. void CXTPDockingPane::SetTitle(LPCTSTR lpszTitle)
  254. {
  255. m_strTitle = lpszTitle;
  256. InvalidatePane(FALSE);
  257. }
  258. BOOL CXTPDockingPane::IsClosed() const
  259. {
  260. return m_pParentContainer == NULL;
  261. }
  262. BOOL CXTPDockingPane::IsHidden() const
  263. {
  264. if (m_pParentContainer == NULL)
  265. return FALSE;
  266. return m_pParentContainer->IsHidden();
  267. }
  268. BOOL CXTPDockingPane::IsSelected() const
  269. {
  270. if (m_pParentContainer == NULL) return FALSE;
  271. ASSERT(m_pParentContainer->GetType() == xtpPaneTypeTabbedContainer);
  272. return ((CXTPDockingPaneTabbedContainer*)m_pParentContainer)->GetSelected() == this;
  273. }
  274. BOOL CXTPDockingPane::IsFloating() const
  275. {
  276. if (m_pParentContainer == NULL) return FALSE;
  277. if (IsHidden()) return FALSE;
  278. ASSERT(m_pParentContainer->GetType() == xtpPaneTypeTabbedContainer);
  279. if (m_pParentContainer->GetPaneHwnd() == 0) return FALSE;
  280. CWnd* pFrame = m_pParentContainer->GetDockingSite();
  281. return pFrame && pFrame->IsKindOf(RUNTIME_CLASS(CXTPDockingPaneMiniWnd));
  282. }
  283. CXTPImageManagerIcon* CXTPDockingPane::GetIcon(int nWidth) const
  284. {
  285. return GetDockingPaneManager()->GetIcon(GetIconID(), nWidth);
  286. }
  287. void CXTPDockingPane::SetItemColor(COLORREF clr)
  288. {
  289. m_clrItemTab = clr;
  290. InvalidatePane(FALSE);
  291. }
  292. COLORREF CXTPDockingPane::GetItemColor() const
  293. {
  294. if (m_clrItemTab != COLORREF_NULL)
  295. return m_clrItemTab;
  296. if (m_hwndChild)
  297. {
  298. COLORREF clr = (COLORREF)::SendMessage(m_hwndChild, WM_XTP_GETTABCOLOR, 0, 0);
  299. if (clr != 0)
  300. return clr;
  301. }
  302. return xtpTabColorBlue + GetID() % 8;
  303. }
  304. void CXTPDockingPane::GetMinMaxInfo(LPMINMAXINFO pMinMaxInfo) const
  305. {
  306. ZeroMemory(pMinMaxInfo, sizeof(MINMAXINFO));
  307. pMinMaxInfo->ptMinTrackSize = m_ptMinTrackSize;
  308. pMinMaxInfo->ptMaxTrackSize = m_ptMaxTrackSize;
  309. }
  310. DWORD CXTPDockingPane::GetOptions() const
  311. {
  312. return GetDockingPaneManager()->m_dwDefaultPaneOptions | m_dwOptions;
  313. }
  314. void CXTPDockingPane::DeletePane()
  315. {
  316. InternalRelease();
  317. }
  318. //////////////////////////////////////////////////////////////////////////
  319. // Accessible
  320. CCmdTarget* CXTPDockingPane::GetAccessible()
  321. {
  322. return this;
  323. }
  324. HRESULT CXTPDockingPane::GetAccessibleParent(IDispatch* FAR* ppdispParent)
  325. {
  326. SAFE_MANAGE_STATE(m_pModuleState);
  327. *ppdispParent = NULL;
  328. if (m_pParentContainer)
  329. {
  330. *ppdispParent = ((CXTPDockingPaneTabbedContainer*)m_pParentContainer)->GetIDispatch(TRUE);
  331. return S_OK;
  332. }
  333. return E_FAIL;
  334. }
  335. HRESULT CXTPDockingPane::GetAccessibleChildCount(long FAR* pChildCount)
  336. {
  337. if (pChildCount == 0)
  338. return E_INVALIDARG;
  339. *pChildCount = m_hwndChild ? 1 : 0;
  340. return S_OK;
  341. }
  342. HRESULT CXTPDockingPane::GetAccessibleChild(VARIANT varChild, IDispatch* FAR* ppdispChild)
  343. {
  344. SAFE_MANAGE_STATE(m_pModuleState);
  345. *ppdispChild = NULL;
  346. if (GetChildIndex(&varChild) == 1)
  347. {
  348. return AccessibleObjectFromWindow(m_hwndChild, OBJID_WINDOW, IID_IDispatch, (void**)ppdispChild);
  349. }
  350. return S_OK;
  351. }
  352. HRESULT CXTPDockingPane::GetAccessibleName(VARIANT varChild, BSTR* pszName)
  353. {
  354. if (GetChildIndex(&varChild) != CHILDID_SELF)
  355. return E_INVALIDARG;
  356. *pszName = GetShortTitle().AllocSysString();
  357. return S_OK;
  358. }
  359. HRESULT CXTPDockingPane::GetAccessibleDescription(VARIANT varChild, BSTR* pszDescription)
  360. {
  361. if (GetChildIndex(&varChild) != CHILDID_SELF)
  362. return E_INVALIDARG;
  363. *pszDescription = GetTitle().AllocSysString();
  364. return S_OK;
  365. }
  366. HRESULT CXTPDockingPane::GetAccessibleRole(VARIANT varChild, VARIANT* pvarRole)
  367. {
  368. pvarRole->vt = VT_EMPTY;
  369. if (GetChildIndex(&varChild) == CHILDID_SELF)
  370. {
  371. pvarRole->vt = VT_I4;
  372. pvarRole->lVal = ROLE_SYSTEM_PAGETAB;
  373. return S_OK;
  374. }
  375. return E_INVALIDARG;
  376. }
  377. HRESULT CXTPDockingPane::AccessibleSelect(long /*flagsSelect*/, VARIANT varChild)
  378. {
  379. SAFE_MANAGE_STATE(m_pModuleState);
  380. if (GetChildIndex(&varChild) != CHILDID_SELF)
  381. return E_INVALIDARG;
  382. Select();
  383. return S_OK;
  384. }
  385. HRESULT CXTPDockingPane::GetAccessibleState(VARIANT varChild, VARIANT* pvarState)
  386. {
  387. if (GetChildIndex(&varChild) != CHILDID_SELF)
  388. return E_INVALIDARG;
  389. pvarState->vt = VT_I4;
  390. pvarState->lVal = STATE_SYSTEM_SELECTABLE;
  391. if (!m_pParentContainer)
  392. pvarState->lVal |= STATE_SYSTEM_INVISIBLE;
  393. if (m_pParentContainer && ((CXTPDockingPaneTabbedContainer*)m_pParentContainer)->GetSelected() == this)
  394. pvarState->lVal |= STATE_SYSTEM_SELECTED;
  395. return S_OK;
  396. }
  397. HRESULT CXTPDockingPane::GetAccessibleDefaultAction(VARIANT varChild, BSTR* pszDefaultAction)
  398. {
  399. if (GetChildIndex(&varChild) != CHILDID_SELF)
  400. return E_INVALIDARG;
  401. *pszDefaultAction = SysAllocString(L"Switch");
  402. return S_OK;
  403. }
  404. HRESULT CXTPDockingPane::AccessibleDoDefaultAction(VARIANT varChild)
  405. {
  406. SAFE_MANAGE_STATE(m_pModuleState);
  407. if (GetChildIndex(&varChild) != CHILDID_SELF)
  408. return E_INVALIDARG;
  409. Select();
  410. return S_OK;
  411. }
  412. HRESULT CXTPDockingPane::AccessibleLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild)
  413. {
  414. CRect rc;
  415. if (GetChildIndex(&varChild) == 1)
  416. {
  417. GetWindowRect(m_hwndChild, &rc);
  418. }
  419. else if (GetChildIndex(&varChild) != CHILDID_SELF)
  420. {
  421. return E_INVALIDARG;
  422. }
  423. else
  424. {
  425. CXTPDockingPaneTabbedContainer* pContainer = (CXTPDockingPaneTabbedContainer*)m_pParentContainer;
  426. if (!pContainer)
  427. return S_FALSE;
  428. pContainer->GetWindowRect(&rc);
  429. if (pContainer->GetItemCount() > 1)
  430. {
  431. for (int i = 0; i < pContainer->GetItemCount(); i++)
  432. {
  433. CXTPTabManagerItem* pItem = pContainer->GetItem(i);
  434. if (pItem->GetData() == (DWORD_PTR)this)
  435. {
  436. CRect rcItem = pItem->GetRect();
  437. rc = CRect(CPoint(rc.left + rcItem.left, rc.top + rcItem.top), rcItem.Size());
  438. break;
  439. }
  440. }
  441. }
  442. }
  443. *pxLeft = rc.left;
  444. *pyTop = rc.top;
  445. *pcxWidth = rc.Width();
  446. *pcyHeight = rc.Height();
  447. return S_OK;
  448. }
  449. HRESULT CXTPDockingPane::AccessibleHitTest(long /*xLeft*/, long /*yTop*/, VARIANT* pvarID)
  450. {
  451. pvarID->vt = VT_I4;
  452. pvarID->lVal = 0;
  453. return S_OK;
  454. }
  455. BEGIN_INTERFACE_MAP(CXTPDockingPane, CCmdTarget)
  456. INTERFACE_PART(CXTPDockingPane, IID_IAccessible, ExternalAccessible)
  457. END_INTERFACE_MAP()