Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

360 lines
8.6 KiB

  1. // LeftView.cpp : implementation of the CLeftView class
  2. //
  3. #include "stdafx.h"
  4. #include "FileSpyApp.h"
  5. #include "FileSpyDoc.h"
  6. #include "LeftView.h"
  7. #include "global.h"
  8. #include "protos.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CLeftView
  16. IMPLEMENT_DYNCREATE(CLeftView, CTreeView)
  17. BEGIN_MESSAGE_MAP(CLeftView, CTreeView)
  18. //{{AFX_MSG_MAP(CLeftView)
  19. ON_WM_RBUTTONDOWN()
  20. ON_WM_RBUTTONUP()
  21. ON_COMMAND(IDR_MENUATTACH, OnMenuattach)
  22. ON_COMMAND(IDR_MENUDETACH, OnMenudetach)
  23. ON_COMMAND(IDR_MENUATTACHALL, OnMenuattachall)
  24. ON_COMMAND(IDR_MENUDETACHALL, OnMenudetachall)
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CLeftView construction/destruction
  29. CLeftView::CLeftView()
  30. {
  31. // TODO: add construction code here
  32. m_pImageList = new CImageList;
  33. m_pImageList->Create(IDB_DRIVEIMAGELIST,16,0,RGB(255,255,255));
  34. nRButtonSet = 0;
  35. pLeftView = (LPVOID) this;
  36. }
  37. CLeftView::~CLeftView()
  38. {
  39. if (m_pImageList)
  40. {
  41. delete m_pImageList;
  42. }
  43. }
  44. BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
  45. {
  46. // TODO: Modify the Window class or styles here by modifying
  47. // the CREATESTRUCT cs
  48. cs.style |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS;
  49. return CTreeView::PreCreateWindow(cs);
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CLeftView drawing
  53. void CLeftView::OnDraw(CDC* pDC)
  54. {
  55. UNREFERENCED_PARAMETER( pDC );
  56. CFileSpyDoc* pDoc = GetDocument();
  57. ASSERT_VALID(pDoc);
  58. // TODO: add draw code for native data here
  59. }
  60. void CLeftView::OnInitialUpdate()
  61. {
  62. CTreeView::OnInitialUpdate();
  63. // TODO: You may populate your TreeView with items by directly accessing
  64. // its tree control through a call to GetTreeCtrl().
  65. USHORT ti;
  66. WCHAR sDriveString[30];
  67. //
  68. // Set the image list first
  69. //
  70. GetTreeCtrl().SetImageList(m_pImageList, TVSIL_NORMAL);
  71. //
  72. // Add a root node and name it "FileSpy"
  73. //
  74. hRootItem = GetTreeCtrl().InsertItem(L"FileSpy", IMAGE_SPY, IMAGE_SPY);
  75. //
  76. // Add drive names to LeftView
  77. //
  78. for (ti = 0; ti < nTotalDrives; ti++)
  79. {
  80. switch (VolInfo[ti].nType)
  81. {
  82. case DRIVE_FIXED:
  83. wcscpy( sDriveString, L"[ :] Local Disk" );
  84. break;
  85. case DRIVE_REMOTE:
  86. wcscpy( sDriveString, L"[ :] Remote" );
  87. break;
  88. case DRIVE_REMOVABLE:
  89. wcscpy( sDriveString, L"[ :] Removable" );
  90. break;
  91. case DRIVE_CDROM:
  92. wcscpy( sDriveString, L"[ :] CD-ROM" );
  93. break;
  94. default:
  95. wcscpy( sDriveString, L"[ :] Unknown" );
  96. break;
  97. }
  98. sDriveString[1] = VolInfo[ti].nDriveName;
  99. GetTreeCtrl().InsertItem( sDriveString,
  100. VolInfo[ti].nImage,
  101. VolInfo[ti].nImage,
  102. hRootItem );
  103. }
  104. GetTreeCtrl().Expand(hRootItem, TVE_EXPAND);
  105. }
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CLeftView diagnostics
  108. #ifdef _DEBUG
  109. void CLeftView::AssertValid() const
  110. {
  111. CTreeView::AssertValid();
  112. }
  113. void CLeftView::Dump(CDumpContext& dc) const
  114. {
  115. CTreeView::Dump(dc);
  116. }
  117. CFileSpyDoc* CLeftView::GetDocument() // non-debug version is inline
  118. {
  119. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFileSpyDoc)));
  120. return (CFileSpyDoc*)m_pDocument;
  121. }
  122. #endif //_DEBUG
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CLeftView message handlers
  125. void CLeftView::OnRButtonDown(UINT nFlags, CPoint point)
  126. {
  127. UNREFERENCED_PARAMETER( nFlags );
  128. UNREFERENCED_PARAMETER( point );
  129. // TODO: Add your message handler code here and/or call default
  130. nRButtonSet = 1;
  131. // CTreeView::OnRButtonDown(nFlags, point);
  132. }
  133. void CLeftView::OnRButtonUp(UINT nFlags, CPoint point)
  134. {
  135. // TODO: Add your message handler code here and/or call default
  136. HTREEITEM hItem;
  137. CMenu menu, *menupopup;
  138. RECT rect;
  139. UINT ret;
  140. hItem = GetTreeCtrl().HitTest(point);
  141. if (hItem != NULL && hItem != hRootItem && nRButtonSet)
  142. {
  143. GetTreeCtrl().SelectItem(hItem);
  144. menu.LoadMenu(IDR_LEFTVIEWMENU);
  145. menupopup = menu.GetSubMenu(0);
  146. GetWindowRect(&rect);
  147. if (VolInfo[GetAssociatedVolumeIndex(hItem)].bHook)
  148. {
  149. ret = menupopup->EnableMenuItem(IDR_MENUATTACH, MF_DISABLED|MF_GRAYED);
  150. ret = menupopup->EnableMenuItem(IDR_MENUDETACH, MF_ENABLED);
  151. }
  152. else
  153. {
  154. ret = menupopup->EnableMenuItem(IDR_MENUATTACH, MF_ENABLED);
  155. ret = menupopup->EnableMenuItem(IDR_MENUDETACH, MF_DISABLED|MF_GRAYED);
  156. }
  157. menupopup->TrackPopupMenu(TPM_LEFTALIGN, rect.left+point.x, rect.top+point.y, this);
  158. CTreeView::OnRButtonUp(nFlags, point);
  159. }
  160. else
  161. {
  162. if (hItem != NULL && hItem == hRootItem && nRButtonSet)
  163. {
  164. GetTreeCtrl().SelectItem(hItem);
  165. menu.LoadMenu(IDR_LEFTVIEWSPYMENU);
  166. menupopup = menu.GetSubMenu(0);
  167. GetWindowRect(&rect);
  168. ret = menupopup->EnableMenuItem(IDR_MENUATTACHALL, MF_ENABLED);
  169. ret = menupopup->EnableMenuItem(IDR_MENUDETACHALL, MF_ENABLED);
  170. menupopup->TrackPopupMenu(TPM_LEFTALIGN, rect.left+point.x, rect.top+point.y, this);
  171. CTreeView::OnRButtonUp(nFlags, point);
  172. }
  173. }
  174. nRButtonSet = 0;
  175. }
  176. void CLeftView::OnMenuattach()
  177. {
  178. // TODO: Add your command handler code here
  179. HTREEITEM hItem;
  180. hItem = GetTreeCtrl().GetSelectedItem();
  181. if (AttachToDrive(VolInfo[GetAssociatedVolumeIndex(hItem)].nDriveName))
  182. {
  183. VolInfo[GetAssociatedVolumeIndex(hItem)].bHook = TRUE;
  184. GetTreeCtrl().SetItemImage( hItem,
  185. VolInfo[GetAssociatedVolumeIndex(hItem)].nImage+IMAGE_ATTACHSTART,
  186. VolInfo[GetAssociatedVolumeIndex(hItem)].nImage+IMAGE_ATTACHSTART );
  187. }
  188. }
  189. void CLeftView::OnMenudetach()
  190. {
  191. // TODO: Add your command handler code here
  192. HTREEITEM hItem;
  193. hItem = GetTreeCtrl().GetSelectedItem();
  194. if (DetachFromDrive(VolInfo[GetAssociatedVolumeIndex(hItem)].nDriveName))
  195. {
  196. VolInfo[GetAssociatedVolumeIndex(hItem)].bHook = 0;
  197. GetTreeCtrl().SetItemImage(hItem,
  198. VolInfo[GetAssociatedVolumeIndex(hItem)].nImage, \
  199. VolInfo[GetAssociatedVolumeIndex(hItem)].nImage);
  200. }
  201. }
  202. void CLeftView::OnMenuattachall()
  203. {
  204. // TODO: Add your command handler code here
  205. USHORT ti;
  206. HTREEITEM hItem;
  207. for (ti = 0; ti < nTotalDrives; ti++)
  208. {
  209. if (AttachToDrive(VolInfo[ti].nDriveName))
  210. {
  211. VolInfo[ti].bHook = TRUE;
  212. hItem = GetAssociatedhItem(VolInfo[ti].nDriveName);
  213. if (hItem)
  214. {
  215. GetTreeCtrl().SetItemImage(hItem,
  216. VolInfo[ti].nImage+IMAGE_ATTACHSTART, \
  217. VolInfo[ti].nImage+IMAGE_ATTACHSTART);
  218. }
  219. }
  220. }
  221. }
  222. void CLeftView::OnMenudetachall()
  223. {
  224. // TODO: Add your command handler code here
  225. USHORT ti;
  226. HTREEITEM hItem;
  227. for (ti = 0; ti < nTotalDrives; ti++)
  228. {
  229. if (DetachFromDrive(VolInfo[ti].nDriveName))
  230. {
  231. VolInfo[ti].bHook = FALSE;
  232. hItem = GetAssociatedhItem(VolInfo[ti].nDriveName);
  233. if (hItem)
  234. {
  235. GetTreeCtrl().SetItemImage(hItem, VolInfo[ti].nImage, VolInfo[ti].nImage);
  236. }
  237. }
  238. }
  239. }
  240. /*
  241. void CLeftView::OnMenuscannewvolume()
  242. {
  243. // TODO: Add your command handler code here
  244. VOLINFO NewVol[26];
  245. DWORD nNewTotalDrives;
  246. USHORT ti, tj;
  247. HTREEITEM hItem;
  248. BuildDriveTable(NewVol, nNewTotalDrives);
  249. // We should remember the old hook status
  250. for (ti = 0; ti < nNewTotalDrives; ti++)
  251. {
  252. for (tj = 0; tj < nTotalDrives; tj++)
  253. {
  254. if (NewVol[ti].nDriveName == VolInfo[tj].nDriveName)
  255. {
  256. NewVol[ti].nHook = VolInfo[tj].nHook;
  257. break;
  258. }
  259. }
  260. }
  261. }
  262. */
  263. USHORT CLeftView::GetAssociatedVolumeIndex(HTREEITEM hItem)
  264. {
  265. CString cs;
  266. USHORT ti;
  267. PWCHAR sDriveString;
  268. cs = GetTreeCtrl().GetItemText(hItem);
  269. sDriveString = cs.GetBuffer(20);
  270. for (ti = 0; ti < nTotalDrives; ti++)
  271. {
  272. if (VolInfo[ti].nDriveName == sDriveString[1])
  273. {
  274. return ti;
  275. }
  276. }
  277. return 0; // still a valid value but this will not happen
  278. }
  279. HTREEITEM CLeftView::GetAssociatedhItem(WCHAR cDriveName)
  280. {
  281. HTREEITEM hItem;
  282. CString cs;
  283. PWCHAR sDriveString;
  284. hItem = GetTreeCtrl().GetChildItem(hRootItem);
  285. while (hItem)
  286. {
  287. cs = GetTreeCtrl().GetItemText(hItem);
  288. sDriveString = cs.GetBuffer(20);
  289. if (cDriveName == sDriveString[1])
  290. {
  291. break;
  292. }
  293. hItem = GetTreeCtrl().GetNextSiblingItem(hItem);
  294. }
  295. return hItem;
  296. }
  297. void CLeftView::UpdateImage(void)
  298. {
  299. USHORT ti;
  300. HTREEITEM hItem;
  301. for (ti = 0; ti < nTotalDrives; ti++)
  302. {
  303. hItem = GetAssociatedhItem(VolInfo[ti].nDriveName);
  304. GetTreeCtrl().SetItemImage(hItem, VolInfo[ti].nImage, VolInfo[ti].nImage);
  305. }
  306. }