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

对话框与窗口

开发平台:

Visual C++

  1. // XTShellTreeCtrl.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME CONTROLS 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/XTPSystemHelpers.h"
  22. #include "XTDefines.h"
  23. #include "XTGlobal.h"
  24. #include "XTVC50Helpers.h"
  25. #include "XTShellPidl.h"
  26. #include "XTShellSettings.h"
  27. #include "XTTreeBase.h"
  28. #include "XTShellTreeBase.h"
  29. #include "XTShellTreeCtrlView.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CXTShellTreeView
  37. CXTShellTreeView::CXTShellTreeView()
  38. {
  39. m_pTreeCtrl = (CTreeCtrl_Friendly*)&GetTreeCtrl();
  40. }
  41. CXTShellTreeView::~CXTShellTreeView()
  42. {
  43. }
  44. IMPLEMENT_DYNCREATE(CXTShellTreeView, CTreeView)
  45. BEGIN_MESSAGE_MAP(CXTShellTreeView, CTreeView)
  46. ON_SHELLTREE_REFLECT()
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CXTShellTreeView message handlers
  50. void CXTShellTreeView::SelectionChanged(HTREEITEM hItem, CString strFolderPath)
  51. {
  52. if (hItem != NULL && !m_bTunneling)
  53. {
  54. CDocument* pDoc = GetDocument();
  55. if (pDoc != NULL)
  56. {
  57. pDoc->UpdateAllViews(this, SHN_XT_TREESELCHANGE,
  58. (CObject*)GetTreeCtrl().GetItemData(hItem));
  59. }
  60. }
  61. CXTShellTreeBase::SelectionChanged(hItem, strFolderPath);
  62. }
  63. void CXTShellTreeView::OnInitialUpdate()
  64. {
  65. CTreeView::OnInitialUpdate();
  66. DWORD dwStyle = (TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
  67. if (XTOSVersionInfo()->IsWinXPOrGreater())
  68. dwStyle = (TVS_HASBUTTONS | TVS_SINGLEEXPAND | TVS_TRACKSELECT | TVS_SHOWSELALWAYS);
  69. if (InitializeTree(dwStyle))
  70. {
  71. PopulateTreeView();
  72. }
  73. // make the parent of the selected item visible if found.
  74. HTREEITEM hItem = GetTreeCtrl().GetSelectedItem();
  75. HTREEITEM hItemParent = GetTreeCtrl().GetParentItem(hItem);
  76. GetTreeCtrl().EnsureVisible(hItemParent ? hItemParent : hItem);
  77. }
  78. void CXTShellTreeView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* pHint)
  79. {
  80. switch (lHint)
  81. {
  82. // Update selection of tree view to the
  83. case SHN_XT_SELECTCHILD:
  84. {
  85. XT_LVITEMDATA*  lplvid = (XT_LVITEMDATA*)pHint;
  86. ASSERT(lplvid != NULL);
  87. LockWindowUpdate();
  88. if (!FindTreeItem(GetTreeCtrl().GetSelectedItem(), lplvid, FALSE))
  89. {
  90. // The folder was not found so we send back a message
  91. // to the listview to execute the itemid
  92. CDocument* pDoc = GetDocument();
  93. pDoc->UpdateAllViews(this, SHN_XT_NOFOLDER, (CObject*)lplvid);
  94. }
  95. UnlockWindowUpdate();
  96. }
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CXTShellTreeCtrl
  104. IMPLEMENT_DYNAMIC(CXTShellTreeCtrl, CTreeCtrl)
  105. CXTShellTreeCtrl::CXTShellTreeCtrl()
  106. {
  107. m_pListCtrl = NULL;
  108. m_bAutoInit = TRUE;
  109. m_pTreeCtrl = (CTreeCtrl_Friendly*)this;
  110. }
  111. CXTShellTreeCtrl::~CXTShellTreeCtrl()
  112. {
  113. }
  114. BEGIN_MESSAGE_MAP(CXTShellTreeCtrl, CTreeCtrl)
  115. ON_SHELLTREE_REFLECT()
  116. ON_MESSAGE(XTWM_SHELL_NOTIFY, OnUpdateShell)
  117. END_MESSAGE_MAP()
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CXTShellTreeCtrl message handlers
  120. void CXTShellTreeCtrl::SelectionChanged(HTREEITEM hItem, CString strFolderPath)
  121. {
  122. if (hItem != NULL && !m_bTunneling)
  123. {
  124. CWnd* pWndNotify = (CWnd*)m_pListCtrl;
  125. if (!::IsWindow(pWndNotify->GetSafeHwnd()))
  126. {
  127. pWndNotify = GetOwner();
  128. }
  129. // notify list control of selection change.
  130. if (::IsWindow(pWndNotify->GetSafeHwnd()))
  131. {
  132. pWndNotify->SendMessage(XTWM_SHELL_NOTIFY,
  133. (WPARAM)SHN_XT_TREESELCHANGE,
  134. (LPARAM)(CObject*)GetItemData(hItem));
  135. }
  136. }
  137. CXTShellTreeBase::SelectionChanged(hItem, strFolderPath);
  138. }
  139. LRESULT CXTShellTreeCtrl::OnUpdateShell(WPARAM wParam, LPARAM lParam)
  140. {
  141. switch (wParam)
  142. {
  143. // Update selection of tree view to the
  144. case SHN_XT_SELECTCHILD:
  145. {
  146. XT_LVITEMDATA*  lplvid = (XT_LVITEMDATA*)lParam;
  147. ASSERT(lplvid != NULL);
  148. LockWindowUpdate();
  149. if (!FindTreeItem(GetSelectedItem(), lplvid, FALSE) && m_pListCtrl != NULL)
  150. {
  151. // The folder was not found so we send back a message
  152. // to the listview to execute the itemid
  153. m_pListCtrl->SendMessage(XTWM_SHELL_NOTIFY,
  154. (WPARAM)SHN_XT_NOFOLDER,
  155. (LPARAM)(CObject*)lplvid);
  156. }
  157. UnlockWindowUpdate();
  158. }
  159. break;
  160. default:
  161. break;
  162. }
  163. return 0;
  164. }
  165. bool CXTShellTreeCtrl::Init()
  166. {
  167. if (!CXTShellTreeCtrlBase::Init())
  168. return false;
  169. if (m_bAutoInit)
  170. {
  171. DWORD dwStyle = (TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
  172. if (XTOSVersionInfo()->IsWinXPOrGreater())
  173. dwStyle = (TVS_HASBUTTONS | TVS_SINGLEEXPAND | TVS_TRACKSELECT | TVS_SHOWSELALWAYS);
  174. if (InitializeTree(dwStyle))
  175. {
  176. PopulateTreeView();
  177. }
  178. // make the parent of the selected item visible if found.
  179. HTREEITEM hItem = GetSelectedItem();
  180. HTREEITEM hItemParent = GetParentItem(hItem);
  181. EnsureVisible(hItemParent ? hItemParent : hItem);
  182. }
  183. return true;
  184. }
  185. void CXTShellTreeCtrl::AssociateList(CWnd* pWnd)
  186. {
  187. ASSERT_VALID(pWnd); // must be a valid window.
  188. if (::IsWindow(pWnd->GetSafeHwnd()))
  189. {
  190. m_pListCtrl = pWnd;
  191. // make sure list gets updated.
  192. m_pListCtrl->SendMessage(XTWM_SHELL_NOTIFY,
  193. (WPARAM)SHN_XT_TREESELCHANGE,
  194. (LPARAM)(CObject*)GetItemData(GetSelectedItem()));
  195. }
  196. }
  197. void CXTShellTreeCtrl::AssociateCombo(CWnd* pWnd)
  198. {
  199. CXTShellTreeBase::AssociateCombo(pWnd);
  200. if (::IsWindow(pWnd->GetSafeHwnd()))
  201. {
  202. CString strSelectedPath;
  203. GetSelectedFolderPath(strSelectedPath);
  204. // make sure list gets updated.
  205. CXTShellTreeBase::SelectionChanged(
  206. GetSelectedItem(), strSelectedPath);
  207. }
  208. }