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.

2342 lines
69 KiB

  1. /*******************************************************************************
  2. *
  3. * treeview.cpp
  4. *
  5. * implementation of the CAdminTreeView class
  6. *
  7. * copyright notice: Copyright 1997, Citrix Systems Inc.
  8. * Copyright (c) 1998 - 1999 Microsoft Corporation
  9. * $Author: donm $ Don Messerli
  10. *
  11. * $Log: N:\nt\private\utils\citrix\winutils\tsadmin\VCS\treeview.cpp $
  12. *
  13. *******************************************************************************/
  14. #include "stdafx.h"
  15. #include "winadmin.h"
  16. #include "admindoc.h"
  17. #include "treeview.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. extern DWORD g_dwTreeViewExpandedStates;
  24. #define DISPLAY_NAME_SIZE 128
  25. /////////////////////////////
  26. // MESSAGE MAP: CAdminTreeView
  27. //
  28. IMPLEMENT_DYNCREATE(CAdminTreeView, CBaseTreeView)
  29. BEGIN_MESSAGE_MAP(CAdminTreeView, CBaseTreeView)
  30. //{{AFX_MSG_MAP(CAdminTreeView)
  31. ON_MESSAGE(WM_ADMIN_ADD_SERVER, OnAdminAddServer)
  32. ON_MESSAGE(WM_ADMIN_REMOVE_SERVER, OnAdminRemoveServer)
  33. ON_MESSAGE(WM_ADMIN_UPDATE_SERVER, OnAdminUpdateServer)
  34. ON_MESSAGE(WM_ADMIN_ADD_WINSTATION, OnAdminAddWinStation)
  35. ON_MESSAGE(WM_ADMIN_UPDATE_WINSTATION, OnAdminUpdateWinStation)
  36. ON_MESSAGE(WM_ADMIN_REMOVE_WINSTATION, OnAdminRemoveWinStation)
  37. ON_MESSAGE(WM_ADMIN_UPDATE_DOMAIN, OnAdminUpdateDomain)
  38. ON_MESSAGE(WM_ADMIN_ADD_DOMAIN, OnAdminAddDomain)
  39. ON_MESSAGE(WM_ADMIN_VIEWS_READY, OnAdminViewsReady)
  40. ON_MESSAGE( WM_ADMIN_ADDSERVERTOFAV , OnAdminAddServerToFavs )
  41. ON_MESSAGE( WM_ADMIN_REMOVESERVERFROMFAV , OnAdminRemoveServerFromFavs )
  42. ON_MESSAGE( WM_ADMIN_GOTO_SERVER , OnAdminGotoServer )
  43. ON_MESSAGE( WM_ADMIN_DELTREE_NODE , OnAdminDelFavServer )
  44. ON_MESSAGE( WM_ADMIN_GET_TV_STATES , OnGetTVStates )
  45. ON_MESSAGE( WM_ADMIN_UPDATE_TVSTATE , OnUpdateTVState )
  46. ON_MESSAGE( IDM_ALLSERVERS_EMPTYFAVORITES , OnEmptyFavorites )
  47. ON_MESSAGE( WM_ISFAVLISTEMPTY , OnIsFavListEmpty )
  48. ON_MESSAGE( WM_ADMIN_CONNECT_TO_SERVER, OnAdminConnectToServer )
  49. ON_MESSAGE( WM_ADMIN_FORCE_SEL_CHANGE, OnAdminForceSelChange )
  50. ON_WM_CONTEXTMENU()
  51. /*
  52. ON_WM_LBUTTONUP( )
  53. ON_WM_MOUSEMOVE( )
  54. ON_WM_TIMER( )
  55. ON_NOTIFY( TVN_BEGINDRAG , AFX_IDW_PANE_FIRST , OnBeginDrag )
  56. */
  57. ON_NOTIFY( NM_RCLICK , AFX_IDW_PANE_FIRST , OnRClick )
  58. ON_WM_LBUTTONDBLCLK()
  59. ON_COMMAND( ID_ENTER , OnEnterKey )
  60. ON_WM_SETFOCUS( )
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. //////////////////////////
  64. // F'N: CAdminTreeView ctor
  65. //
  66. CAdminTreeView::CAdminTreeView()
  67. {
  68. m_pimgDragList = NULL;
  69. m_hDragItem = NULL;
  70. } // end CAdminTreeView ctor
  71. //////////////////////////
  72. // F'N: CAdminTreeView dtor
  73. //
  74. CAdminTreeView::~CAdminTreeView()
  75. {
  76. } // end CAdminTreeView dtor
  77. #ifdef _DEBUG
  78. //////////////////////////////////
  79. // F'N: CAdminTreeView::AssertValid
  80. //
  81. void CAdminTreeView::AssertValid() const
  82. {
  83. CBaseTreeView::AssertValid();
  84. } // end CAdminTreeView::AssertValid
  85. ///////////////////////////
  86. // F'N: CAdminTreeView::Dump
  87. //
  88. void CAdminTreeView::Dump(CDumpContext& dc) const
  89. {
  90. CBaseTreeView::Dump(dc);
  91. } // end CAdminTreeView::Dump
  92. #endif
  93. /////////////////////////////////////
  94. // F'N: CAdminTreeView::BuildImageList
  95. //
  96. // - calls m_imageList.Create(..) to create the image list
  97. // - calls AddIconToImageList(..) to add the icons themselves and save
  98. // off their indices
  99. // - attaches the image list to the CTreeCtrl
  100. //
  101. void CAdminTreeView::BuildImageList()
  102. {
  103. m_ImageList.Create(16, 16, TRUE, 19, 0);
  104. m_idxBlank = AddIconToImageList(IDI_BLANK);
  105. m_idxCitrix = AddIconToImageList(IDI_WORLD);
  106. m_idxServer = AddIconToImageList(IDI_SERVER);
  107. m_idxConsole = AddIconToImageList(IDI_CONSOLE);
  108. m_idxNet = AddIconToImageList(IDI_NET);
  109. m_idxNotSign = AddIconToImageList(IDI_NOTSIGN);
  110. m_idxQuestion = AddIconToImageList(IDI_QUESTIONMARK);
  111. m_idxUser = AddIconToImageList(IDI_USER);
  112. m_idxAsync = AddIconToImageList(IDI_ASYNC);
  113. m_idxCurrentServer = AddIconToImageList(IDI_CURRENT_SERVER);
  114. m_idxCurrentNet = AddIconToImageList(IDI_CURRENT_NET);
  115. m_idxCurrentConsole = AddIconToImageList(IDI_CURRENT_CONSOLE);
  116. m_idxCurrentAsync = AddIconToImageList(IDI_CURRENT_ASYNC);
  117. m_idxDirectAsync = AddIconToImageList(IDI_DIRECT_ASYNC);
  118. m_idxCurrentDirectAsync = AddIconToImageList(IDI_CURRENT_DIRECT_ASYNC);
  119. m_idxDomain = AddIconToImageList(IDI_DOMAIN);
  120. m_idxCurrentDomain = AddIconToImageList(IDI_CURRENT_DOMAIN);
  121. m_idxDomainNotConnected = AddIconToImageList(IDI_DOMAIN_NOT_CONNECTED);
  122. m_idxServerNotConnected = AddIconToImageList(IDI_SERVER_NOT_CONNECTED);
  123. // Overlay for Servers we can't talk to
  124. m_ImageList.SetOverlayImage(m_idxNotSign, 1);
  125. // Overlay for Servers we are currently gathering information about
  126. m_ImageList.SetOverlayImage(m_idxQuestion, 2);
  127. GetTreeCtrl().SetImageList(&m_ImageList, TVSIL_NORMAL);
  128. } // end CAdminTreeView::BuildImageList
  129. /////////////////////////////////////////
  130. // F'N: CAdminTreeView::DetermineWinStationText
  131. //
  132. // determines the appropriate text to display for
  133. // a WinStation in the tree
  134. //
  135. void CAdminTreeView::DetermineWinStationText(CWinStation *pWinStation, TCHAR *NameToDisplay)
  136. {
  137. ASSERT(pWinStation);
  138. ASSERT(NameToDisplay);
  139. CString NameString;
  140. const TCHAR *pState = StrConnectState(pWinStation->GetState(), FALSE);
  141. switch(pWinStation->GetState()) {
  142. case State_Active: // user logged on to WinStation
  143. case State_Connected: // WinStation connected to client
  144. case State_ConnectQuery: // in the process of connecting to client
  145. case State_Shadow: // shadowing another WinStation
  146. if(wcslen(pWinStation->GetUserName())) {
  147. NameString.Format(TEXT("%s (%s)"), pWinStation->GetName(), pWinStation->GetUserName());
  148. lstrcpyn(NameToDisplay, NameString, DISPLAY_NAME_SIZE);
  149. }
  150. else
  151. {
  152. if( pWinStation->GetState() == State_ConnectQuery )
  153. {
  154. CString ConnQ;
  155. ConnQ.LoadString( IDS_CONNQ );
  156. lstrcpyn(NameToDisplay , ConnQ, DISPLAY_NAME_SIZE);
  157. }
  158. else
  159. {
  160. lstrcpyn(NameToDisplay, pWinStation->GetName(), DISPLAY_NAME_SIZE);
  161. }
  162. }
  163. break;
  164. case State_Disconnected: // WinStation logged on without client
  165. if(wcslen(pWinStation->GetUserName())) {
  166. NameString.Format(TEXT("%s (%s)"), pState, pWinStation->GetUserName());
  167. }
  168. else NameString.Format(TEXT("%s (%lu)"), pState, pWinStation->GetLogonId());
  169. lstrcpyn(NameToDisplay, NameString, DISPLAY_NAME_SIZE);
  170. break;
  171. case State_Idle: // waiting for client to connect
  172. if(pWinStation->GetServer()->GetCTXVersionNum() < 0x200) {
  173. NameString.Format(TEXT("%s (%s)"), pWinStation->GetName(), pState);
  174. lstrcpyn(NameToDisplay, NameString, DISPLAY_NAME_SIZE);
  175. } else {
  176. NameString.Format(TEXT("%s (%lu)"), pState, pWinStation->GetLogonId());
  177. lstrcpyn(NameToDisplay, NameString, DISPLAY_NAME_SIZE);
  178. }
  179. break;
  180. case State_Down: // WinStation is down due to error
  181. NameString.Format(TEXT("%s (%lu)"), pState, pWinStation->GetLogonId());
  182. lstrcpyn(NameToDisplay, NameString, DISPLAY_NAME_SIZE);
  183. break;
  184. case State_Listen: // WinStation is listening for connection
  185. {
  186. CString ListenString;
  187. ListenString.LoadString(IDS_LISTENER);
  188. NameString.Format(TEXT("%s (%s)"), pWinStation->GetName(), ListenString);
  189. lstrcpyn(NameToDisplay, NameString, DISPLAY_NAME_SIZE);
  190. }
  191. break;
  192. case State_Reset: // WinStation is being reset
  193. case State_Init: // WinStation in initialization
  194. lstrcpyn(NameToDisplay, pWinStation->GetName(), DISPLAY_NAME_SIZE);
  195. break;
  196. }
  197. } // end CAdminTreeView::DetermineWinStationText
  198. /////////////////////////////////////////
  199. // F'N: CAdminTreeView::DetermineWinStationIcon
  200. //
  201. // determines which icon to display for a WinStation
  202. // in the tree
  203. //
  204. int CAdminTreeView::DetermineWinStationIcon(CWinStation *pWinStation)
  205. {
  206. ASSERT(pWinStation);
  207. int WhichIcon = m_idxBlank;
  208. BOOL CurrentWinStation = pWinStation->IsCurrentWinStation();
  209. if(pWinStation->GetState() != State_Disconnected
  210. && pWinStation->GetState() != State_Idle) {
  211. switch(pWinStation->GetSdClass()) {
  212. case SdAsync:
  213. if(pWinStation->IsDirectAsync())
  214. WhichIcon = CurrentWinStation ? m_idxCurrentDirectAsync : m_idxDirectAsync;
  215. else
  216. WhichIcon = CurrentWinStation ? m_idxCurrentAsync : m_idxAsync;
  217. break;
  218. case SdNetwork:
  219. WhichIcon = CurrentWinStation ? m_idxCurrentNet : m_idxNet;
  220. break;
  221. default:
  222. WhichIcon = CurrentWinStation ? m_idxCurrentConsole : m_idxConsole;
  223. break;
  224. }
  225. }
  226. return WhichIcon;
  227. } // end CAdminTreeView::DetermineWinStationIcon
  228. /////////////////////////////////////////
  229. // F'N: CAdminTreeView::DetermineDomainIcon
  230. //
  231. // determines which icon to display for a Domain
  232. // in the tree
  233. //
  234. int CAdminTreeView::DetermineDomainIcon(CDomain *pDomain)
  235. {
  236. ASSERT(pDomain);
  237. int WhichIcon = m_idxDomain;
  238. if(pDomain->IsCurrentDomain()) return m_idxCurrentDomain;
  239. if(pDomain->GetState() != DS_ENUMERATING && pDomain->GetState() != DS_INITIAL_ENUMERATION)
  240. WhichIcon = m_idxDomainNotConnected;
  241. return WhichIcon;
  242. } // end CAdminTreeView::DetermineDomainIcon
  243. /////////////////////////////////////////
  244. // F'N: CAdminTreeView::DetermineServerIcon
  245. //
  246. // determines which icon to display for a Server
  247. // in the tree
  248. //
  249. int CAdminTreeView::DetermineServerIcon(CServer *pServer)
  250. {
  251. ASSERT(pServer);
  252. int WhichIcon = m_idxServer;
  253. // Is this the current server?
  254. if(pServer->IsCurrentServer()) {
  255. if(pServer->IsState(SS_NONE) || pServer->IsState(SS_NOT_CONNECTED))
  256. WhichIcon = m_idxServerNotConnected;
  257. else
  258. WhichIcon = m_idxCurrentServer;
  259. } else { // not the current server
  260. if(pServer->IsState(SS_NONE) || pServer->IsState(SS_NOT_CONNECTED))
  261. WhichIcon = m_idxServerNotConnected;
  262. }
  263. return WhichIcon;
  264. } // end CAdminTreeView::DetermineServerIcon
  265. /////////////////////////////////////////
  266. // F'N: CAdminTreeView::AddServerChildren
  267. //
  268. // Adds the WinStations attached to a given Server
  269. // to the tree
  270. //
  271. void CAdminTreeView::AddServerChildren(HTREEITEM hServer, CServer *pServer , NODETYPE nt)
  272. {
  273. ASSERT(hServer);
  274. ASSERT(pServer);
  275. if(pServer->IsServerSane()) {
  276. LockTreeControl();
  277. HTREEITEM hLastNode = hServer;
  278. pServer->LockWinStationList();
  279. // Get a pointer to the server's list of WinStations
  280. CObList *pWinStationList = pServer->GetWinStationList();
  281. // Iterate through the WinStation list
  282. POSITION pos = pWinStationList->GetHeadPosition();
  283. while(pos)
  284. {
  285. CWinStation *pWinStation = (CWinStation*)pWinStationList->GetNext(pos);
  286. // Figure out which icon to use
  287. int WhichIcon = DetermineWinStationIcon(pWinStation);
  288. // Figure out what text to display
  289. TCHAR NameToDisplay[DISPLAY_NAME_SIZE];
  290. DetermineWinStationText(pWinStation, NameToDisplay);
  291. CTreeNode *pNode = new CTreeNode(NODE_WINSTATION, pWinStation);
  292. if( pNode != NULL )
  293. {
  294. pNode->SetSortOrder(pWinStation->GetSortOrder());
  295. hLastNode = AddItemToTree(hServer, NameToDisplay, hLastNode, WhichIcon, (LPARAM)pNode);
  296. if( hLastNode == NULL )
  297. {
  298. delete pNode;
  299. }
  300. }
  301. // The WinStation wants to know his tree item handle
  302. if( nt == NODE_FAV_LIST )
  303. {
  304. pWinStation->SetTreeItemForFav(hLastNode);
  305. }
  306. else if( nt == NODE_SERVER )
  307. {
  308. pWinStation->SetTreeItem(hLastNode);
  309. }
  310. else if( nt == NODE_THIS_COMP )
  311. {
  312. pWinStation->SetTreeItemForThisComputer( hLastNode );
  313. }
  314. }
  315. pServer->UnlockWinStationList();
  316. UnlockTreeControl();
  317. } // end if(pServer->IsServerSane())
  318. } // end CAdminTreeView::AddServerChildren
  319. /////////////////////////////////////////
  320. // F'N: CAdminTreeView::AddDomainToTree
  321. //
  322. // Adds a domain to the tree
  323. //
  324. HTREEITEM CAdminTreeView::AddDomainToTree(CDomain *pDomain)
  325. {
  326. ASSERT(pDomain);
  327. LockTreeControl();
  328. HTREEITEM hDomain = NULL;
  329. // this points to this computer root
  330. HTREEITEM hR2 = GetTreeCtrl().GetRootItem();
  331. // this points to favorite list
  332. hR2 = GetTreeCtrl().GetNextItem( hR2 , TVGN_NEXT );
  333. // this points to All servers
  334. HTREEITEM hRoot = GetTreeCtrl().GetNextItem( hR2 , TVGN_NEXT );
  335. // Add the domain to the tree
  336. // Create a CTreeNode object with info about this tree node
  337. CTreeNode* pNode = new CTreeNode(NODE_DOMAIN, pDomain);
  338. if(pNode) {
  339. hDomain = AddItemToTree(hRoot, pDomain->GetName(), TVI_SORT, DetermineDomainIcon(pDomain), (LPARAM)pNode);
  340. if(!hDomain) delete pNode;
  341. // Change the icon/overlay for the domain
  342. if(pDomain->GetState() == DS_INITIAL_ENUMERATION)
  343. GetTreeCtrl().SetItemState(hDomain, STATE_QUESTION, 0x0F00);
  344. // The domain wants to know his tree item handle
  345. pDomain->SetTreeItem(hDomain);
  346. }
  347. UnlockTreeControl();
  348. return(hDomain);
  349. } // end CAdminTreeView::AddDomainToTree
  350. //////////////////////////////////
  351. // F'N: CAdminTreeView::OnAdminViewsReady
  352. //
  353. LRESULT CAdminTreeView::OnAdminViewsReady(WPARAM wParam, LPARAM lParam)
  354. {
  355. LockTreeControl();
  356. // Get a pointer to our document
  357. CWinAdminDoc *doc = (CWinAdminDoc*)GetDocument();
  358. // We want to remember the tree item of the current server for later
  359. HTREEITEM hCurrentServer = NULL;
  360. HTREEITEM hThisComputerRootItem = NULL;
  361. HTREEITEM hThisComputer = NULL;
  362. HTREEITEM hFavRoot = NULL;
  363. // add enum for fav node
  364. CString cstrThisComputer;
  365. CString cstrFavSrv;
  366. CNodeType *pNodeType = new CNodeType( NODE_THIS_COMP );
  367. // ok to pass in null
  368. CTreeNode *pThisComp = new CTreeNode( NODE_THIS_COMP , pNodeType );
  369. if( pThisComp != NULL )
  370. {
  371. cstrThisComputer.LoadString( IDS_THISCOMPUTER );
  372. hThisComputerRootItem = AddItemToTree( NULL , cstrThisComputer , TVI_ROOT , m_idxDomain , ( LPARAM )pThisComp );
  373. }
  374. // ok to overrun
  375. pNodeType = new CNodeType( NODE_FAV_LIST );
  376. // it's ok to pass null here
  377. CTreeNode *pFavNode = new CTreeNode( NODE_FAV_LIST , pNodeType );
  378. if( pFavNode != NULL )
  379. {
  380. cstrFavSrv.LoadString( IDS_FAVSERVERS );
  381. hFavRoot = AddItemToTree( NULL , cstrFavSrv , TVI_ROOT , m_idxCitrix, ( LPARAM )pFavNode );
  382. }
  383. // add the root to the tree
  384. CString citrix;
  385. citrix.LoadString(IDS_TREEROOT);
  386. CTreeNode* pRootNode = new CTreeNode(NODE_ALL_SERVERS, NULL);
  387. if(!pRootNode) {
  388. UnlockTreeControl();
  389. return 0;
  390. }
  391. HTREEITEM hRoot = AddItemToTree(NULL, citrix, TVI_ROOT, m_idxCitrix, (LPARAM)pRootNode);
  392. if(!hRoot) delete pRootNode;
  393. // set up some 'placeholder'-style vars
  394. HTREEITEM hCurrParent = hRoot;
  395. HTREEITEM hLastConnection = hRoot;
  396. HTREEITEM hLastNode = hRoot;
  397. HTREEITEM hDomain = NULL;
  398. // Get a pointer to the list of domains
  399. CObList *pDomainList = doc->GetDomainList();
  400. POSITION dpos = pDomainList->GetHeadPosition();
  401. while(dpos) {
  402. CDomain *pDomain = (CDomain*)pDomainList->GetNext(dpos);
  403. AddDomainToTree(pDomain);
  404. }
  405. // Get a pointer to the list of servers
  406. doc->LockServerList();
  407. CObList *pServerList = doc->GetServerList();
  408. // Iterate through the server list
  409. POSITION pos = pServerList->GetHeadPosition();
  410. CServer *pCurrentServer;
  411. while(pos) {
  412. // Go to the next server in the list
  413. CServer *pServer = (CServer*)pServerList->GetNext(pos);
  414. if( pServer == NULL )
  415. {
  416. continue;
  417. }
  418. // If this Server's domain isn't in the tree, add it
  419. CDomain *pDomain = pServer->GetDomain();
  420. if(pDomain != NULL )
  421. {
  422. hDomain = pDomain->GetTreeItem();
  423. ASSERT(hDomain);
  424. }
  425. else
  426. {
  427. // server is not in a domain
  428. hDomain = hRoot;
  429. }
  430. // Add the server to the tree
  431. // Create a CTreeNode object with info about this tree node
  432. CTreeNode* pNode = new CTreeNode(NODE_SERVER, pServer);
  433. if(pNode) {
  434. if( !pServer->IsCurrentServer() )
  435. {
  436. // If the server is the current server, use a different icon
  437. hLastConnection = AddItemToTree(hDomain,
  438. pServer->GetName(),
  439. hLastConnection,
  440. DetermineServerIcon(pServer),
  441. (LPARAM)pNode);
  442. if(!hLastConnection) delete pNode;
  443. // The server wants to know his tree item handle
  444. pServer->SetTreeItem(hLastConnection);
  445. // If the server isn't sane, put a not sign over the icon
  446. if(!pServer->IsServerSane()) GetTreeCtrl().SetItemState(hLastConnection, STATE_NOT, 0x0F00);
  447. // If we aren't done getting all the information about this server,
  448. // put a question mark over the icon
  449. else if(pServer->IsState(SS_GETTING_INFO)) GetTreeCtrl().SetItemState(hLastConnection, STATE_QUESTION, 0x0F00);
  450. AddServerChildren(hLastConnection, pServer , NODE_SERVER );
  451. }
  452. // Remember if this is the current server
  453. else
  454. {
  455. hCurrentServer = hLastConnection;
  456. /* Add this item under the this computer root */
  457. hThisComputer = AddItemToTree( hThisComputerRootItem ,
  458. pServer->GetName() ,
  459. TVI_FIRST ,
  460. DetermineServerIcon(pServer),
  461. (LPARAM)pNode );
  462. CTreeNode* pItem = new CTreeNode(NODE_SERVER, pServer);
  463. // uncomment this line if you want this computer to be part of the domain tree list
  464. /*
  465. hLastConnection = AddItemToTree( hDomain,
  466. pServer->GetName(),
  467. hLastConnection,
  468. DetermineServerIcon(pServer),
  469. (LPARAM)pItem);
  470. */
  471. pServer->SetTreeItemForThisComputer( hThisComputer );
  472. // uncomment this line if you want this computer to be part of the domain tree list
  473. // pServer->SetTreeItem( hLastConnection );
  474. if( !pServer->IsServerSane() )
  475. {
  476. GetTreeCtrl().SetItemState(hThisComputer, STATE_NOT, 0x0F00);
  477. // uncomment this line if you want this computer to be part of the domain tree list
  478. // GetTreeCtrl().SetItemState(hLastConnection, STATE_NOT, 0x0F00);
  479. }
  480. // uncomment this line if you want this computer to be part of the domain tree list
  481. // AddServerChildren( hLastConnection, pServer , NODE_SERVER );
  482. AddServerChildren( hThisComputer , pServer , NODE_SERVER );
  483. }
  484. }
  485. } // end while(pos)
  486. doc->UnlockServerList();
  487. // We want to show the main server in this computer node
  488. //GetTreeCtrl().Expand(hRoot, TVE_EXPAND);
  489. GetTreeCtrl().Expand( hThisComputerRootItem , TVE_COLLAPSE );
  490. /*
  491. LRESULT lResult = 0xc0;
  492. // We want to default to having the current server being the
  493. // currently selected item in the tree and be expanded
  494. if( hThisComputerRootItem != NULL && ( g_dwTreeViewExpandedStates & TV_THISCOMP ) )
  495. {
  496. if( hThisComputer != NULL )
  497. {
  498. GetTreeCtrl().SelectItem(hThisComputer);
  499. GetTreeCtrl().Expand(hThisComputer, TVE_EXPAND);
  500. // GetTreeCtrl().Expand(hDomain, TVE_EXPAND);
  501. //lResult = 0xc0;
  502. OnSelChange( NULL , &lResult );
  503. }
  504. }
  505. if( hFavRoot != NULL && ( g_dwTreeViewExpandedStates & TV_FAVS ) )
  506. {
  507. GetTreeCtrl().SelectItem( hFavRoot );
  508. GetTreeCtrl().Expand( hFavRoot , TVE_EXPAND );
  509. OnSelChange( NULL , &lResult );
  510. }
  511. if( hRoot != NULL && ( g_dwTreeViewExpandedStates & TV_ALLSERVERS ) )
  512. {
  513. GetTreeCtrl().SelectItem( hRoot );
  514. GetTreeCtrl().Expand( hRoot , TVE_EXPAND );
  515. OnSelChange( NULL , &lResult );
  516. }
  517. */
  518. UnlockTreeControl();
  519. return 0;
  520. } // end CAdminTreeView::OnAdminViewsReady
  521. ////////////////////////////////
  522. // F'N: CAdminTreeView::OnAdminAddServer
  523. //
  524. // Message Handler to add a Server to the tree
  525. // Pointer to CServer to add is in lParam
  526. //
  527. LRESULT CAdminTreeView::OnAdminAddServer(WPARAM wParam, LPARAM lParam)
  528. {
  529. ASSERT(lParam);
  530. CServer *pServer = (CServer*)lParam;
  531. LockTreeControl();
  532. CTreeCtrl &tree = GetTreeCtrl();
  533. // If this Server's domain isn't in the tree, add it
  534. HTREEITEM hDomain = NULL;
  535. CDomain *pDomain = pServer->GetDomain();
  536. if(pDomain) {
  537. hDomain = pDomain->GetTreeItem();
  538. ASSERT(hDomain);
  539. } else {
  540. // server is not in a domain
  541. hDomain = tree.GetRootItem();
  542. }
  543. // First make sure the server isn't already in the tree
  544. // Get the first server under the domain
  545. HTREEITEM hItem = tree.GetNextItem(hDomain, TVGN_CHILD);
  546. while(hItem) {
  547. // Get the data attached to the tree item
  548. CTreeNode *node = (CTreeNode*)tree.GetItemData(hItem);
  549. if(node) {
  550. // Is this the server we want to add
  551. CServer *pNewServer = (CServer*)node->GetTreeObject();
  552. if(pNewServer == (CServer*)lParam) {
  553. UnlockTreeControl();
  554. return 0;
  555. }
  556. }
  557. hItem = tree.GetNextItem(hItem, TVGN_NEXT);
  558. }
  559. // Add the server to the tree
  560. // Create a CTreeNode object with info about this tree node
  561. CTreeNode* pNode = new CTreeNode(NODE_SERVER, pServer);
  562. if(pNode)
  563. {
  564. // If the server is the current server, use a different icon
  565. HTREEITEM hServer = AddItemToTree(hDomain, pServer->GetName(), (HTREEITEM)wParam,
  566. DetermineServerIcon(pServer), (LPARAM)pNode);
  567. if( !hServer )
  568. {
  569. delete pNode;
  570. }
  571. // The server wants to know his tree item handle
  572. pServer->SetTreeItem(hServer);
  573. // If the server isn't sane, put a not sign over the icon
  574. if( !pServer->IsServerSane() )
  575. {
  576. tree.SetItemState(hServer, STATE_NOT, 0x0F00);
  577. }
  578. // If we aren't done getting all the information about this server,
  579. // put a question mark over the icon
  580. else if(pServer->IsState(SS_GETTING_INFO))
  581. {
  582. tree.SetItemState(hServer, STATE_QUESTION, 0x0F00);
  583. }
  584. AddServerChildren(hServer, pServer , NODE_SERVER );
  585. }
  586. UnlockTreeControl();
  587. return 0;
  588. } // end CAdminTreeView::OnAdminAddServer
  589. //----------------------------------------------------------------------
  590. // ok if you traced me to here you are almost there
  591. // 1) now we need to update the server item and place it under the favorites
  592. // folder
  593. // 2) inform the server child items that it will have a new parent
  594. //
  595. LRESULT CAdminTreeView::OnAdminAddServerToFavs( WPARAM wp , LPARAM lp )
  596. {
  597. CServer *pServer = ( CServer* )lp;
  598. if( pServer == NULL )
  599. {
  600. ODS( L"CAdminTreeView::OnAdminAddServerToFavs invalid arg\n");
  601. return ( LRESULT )-1;
  602. }
  603. LockTreeControl( );
  604. if( pServer->IsServerInactive() || pServer->IsState( SS_DISCONNECTING ) )
  605. {
  606. UnlockTreeControl( );
  607. return 0;
  608. }
  609. CTreeCtrl &tree = GetTreeCtrl();
  610. HTREEITEM hFavs = GetTreeCtrl().GetRootItem( );
  611. HTREEITEM hItem;
  612. hFavs = tree.GetNextItem( hFavs , TVGN_NEXT );
  613. hItem = tree.GetNextItem( hFavs , TVGN_CHILD );
  614. // check for duplicate entry
  615. while( hItem != NULL )
  616. {
  617. // Get the data attached to the tree item
  618. CTreeNode *pTreenode = (CTreeNode*)tree.GetItemData( hItem );
  619. if( pTreenode != NULL )
  620. {
  621. // Is this the server we want to add
  622. CServer *pSvr = (CServer*)pTreenode->GetTreeObject();
  623. if( pSvr == pServer )
  624. {
  625. UnlockTreeControl();
  626. return 0;
  627. }
  628. }
  629. hItem = tree.GetNextItem(hItem, TVGN_NEXT);
  630. }
  631. CTreeNode* pNode = new CTreeNode(NODE_SERVER, pServer);
  632. if( pNode != NULL )
  633. {
  634. HTREEITEM hServer = AddItemToTree( hFavs,
  635. pServer->GetName(),
  636. TVI_SORT,
  637. DetermineServerIcon(pServer),
  638. (LPARAM)pNode);
  639. if( hServer == NULL )
  640. {
  641. delete pNode;
  642. }
  643. // The server wants to know his tree item handle
  644. pServer->SetTreeItemForFav( hServer );
  645. // If the server isn't sane, put a not sign over the icon
  646. if( !pServer->IsServerSane() )
  647. {
  648. tree.SetItemState(hServer, STATE_NOT, 0x0F00);
  649. }
  650. // If we aren't done getting all the information about this server,
  651. // put a question mark over the icon
  652. else if( pServer->IsState( SS_GETTING_INFO ) )
  653. {
  654. tree.SetItemState(hServer, STATE_QUESTION, 0x0F00);
  655. }
  656. AddServerChildren( hServer , pServer , NODE_FAV_LIST );
  657. }
  658. UnlockTreeControl();
  659. tree.Invalidate( );
  660. return 0;
  661. }
  662. //=----------------------------------------------------------------------------------
  663. LRESULT CAdminTreeView::OnAdminRemoveServerFromFavs( WPARAM wp , LPARAM lp )
  664. {
  665. LockTreeControl();
  666. CServer *pServer = ( CServer* )lp;
  667. DBGMSG( L"CAdminTreeView::OnAdminRemoveServerFromFavs -- %s\n" , pServer->GetName( ) );
  668. HTREEITEM hFavServer = pServer->GetTreeItemFromFav();
  669. #ifdef _STRESS_BUILD
  670. DBGMSG( L"Handle to hFavServer 0x%x\n" , hFavServer );
  671. #endif
  672. if( hFavServer == NULL )
  673. {
  674. UnlockTreeControl();
  675. return 0;
  676. }
  677. // Get the data attached to this tree node
  678. CTreeNode *pNode = (CTreeNode*)GetTreeCtrl().GetItemData( hFavServer );
  679. if( pNode != NULL && pNode->GetNodeType( ) == NODE_SERVER )
  680. {
  681. // Is this the server we want to update
  682. CServer *pTreeServer = ( CServer* )pNode->GetTreeObject();
  683. if( pTreeServer != pServer)
  684. {
  685. UnlockTreeControl();
  686. return 0;
  687. }
  688. }
  689. else
  690. {
  691. UnlockTreeControl();
  692. return 0;
  693. }
  694. // Loop through it's children and delete their data
  695. pServer->LockWinStationList( );
  696. HTREEITEM hChild = GetTreeCtrl().GetNextItem( hFavServer , TVGN_CHILD );
  697. while( hChild != NULL )
  698. {
  699. CTreeNode *pChildNode = ( CTreeNode* )GetTreeCtrl().GetItemData( hChild );
  700. if( pChildNode != NULL && pChildNode->GetNodeType( ) == NODE_WINSTATION )
  701. {
  702. // Tell the WinStation it is no longer in the tree
  703. CWinStation *pWinStation = ( CWinStation* )pChildNode->GetTreeObject();
  704. if( pWinStation != NULL )
  705. {
  706. pWinStation->SetTreeItemForFav(NULL);
  707. }
  708. delete pChildNode;
  709. }
  710. hChild = GetTreeCtrl().GetNextItem( hChild , TVGN_NEXT );
  711. }
  712. // Delete the data attached to the tree item
  713. delete pNode;
  714. // Let the server know he is no longer in the tree
  715. pServer->SetTreeItemForFav(NULL);
  716. GetTreeCtrl().DeleteItem( hFavServer );
  717. pServer->UnlockWinStationList( );
  718. UnlockTreeControl();
  719. return 0;
  720. }
  721. ////////////////////////////////
  722. // F'N: CAdminTreeView::OnAdminRemoveServer
  723. //
  724. // Message Handler to remove a Server from the tree
  725. // Pointer to CServer of server to remove is in lParam
  726. //
  727. LRESULT CAdminTreeView::OnAdminRemoveServer(WPARAM wParam, LPARAM lParam)
  728. {
  729. ASSERT(lParam);
  730. CServer *pServer = (CServer*)lParam;
  731. HTREEITEM hServer = pServer->GetTreeItem();
  732. if(!hServer) return 0;
  733. LockTreeControl();
  734. // Get the data attached to this tree node
  735. CTreeNode *node = (CTreeNode*)GetTreeCtrl().GetItemData(hServer);
  736. if(node) {
  737. // Is this the server we want to update
  738. CServer *pTreeServer = (CServer*)node->GetTreeObject();
  739. // Make sure the tree node is correct
  740. if(pTreeServer != pServer) {
  741. UnlockTreeControl();
  742. return 0;
  743. }
  744. }
  745. else {
  746. UnlockTreeControl();
  747. return 0;
  748. }
  749. // Loop through it's children and delete their data
  750. HTREEITEM hChild = GetTreeCtrl().GetNextItem(hServer, TVGN_CHILD);
  751. while(hChild) {
  752. CTreeNode *ChildNode = (CTreeNode*)GetTreeCtrl().GetItemData(hChild);
  753. if(ChildNode) {
  754. // Tell the WinStation it is no longer in the tree
  755. CWinStation *pWinStation = (CWinStation*)ChildNode->GetTreeObject();
  756. if(pWinStation)
  757. pWinStation->SetTreeItem(NULL);
  758. delete ChildNode;
  759. }
  760. hChild = GetTreeCtrl().GetNextItem(hChild, TVGN_NEXT);
  761. }
  762. // Delete the data attached to the tree item
  763. delete node;
  764. // Let the server know he is no longer in the tree
  765. pServer->SetTreeItem(NULL);
  766. // Remove the server from the tree
  767. // This SHOULD remove all it's children
  768. GetTreeCtrl().DeleteItem(hServer);
  769. // TODO
  770. // if this means that CServer does not exist we need to remove this from the favorite list
  771. UnlockTreeControl();
  772. return 0;
  773. } // end CAdminTreeView::OnAdminRemoveServer
  774. /*=--------------------------------------------------------------------------------------
  775. OnAdminUpdateServer
  776. Message handler to update a Server in the tree
  777. Pointer to CServer to update is in lParam
  778. Updates server item in favorites folder
  779. and if server item is this computer it gets updated as well.
  780. *=------------------------------------------------------------------------------------*/
  781. LRESULT CAdminTreeView::OnAdminUpdateServer(WPARAM wParam, LPARAM lParam)
  782. {
  783. ASSERT(lParam);
  784. LockTreeControl( );
  785. // If favorite folders is expanded don't forget to update the tree item
  786. CServer *pServer = (CServer*)lParam;
  787. HTREEITEM hServer = pServer->GetTreeItem();
  788. if( hServer != NULL )
  789. {
  790. UpdateServerTreeNodeState( hServer , pServer , NODE_SERVER );
  791. }
  792. hServer = pServer->GetTreeItemFromFav( );
  793. if( hServer != NULL )
  794. {
  795. UpdateServerTreeNodeState( hServer , pServer , NODE_FAV_LIST );
  796. }
  797. hServer = pServer->GetTreeItemFromThisComputer( );
  798. if( hServer != NULL )
  799. {
  800. UpdateServerTreeNodeState( hServer , pServer , NODE_THIS_COMP );
  801. }
  802. UnlockTreeControl( );
  803. return 0;
  804. }
  805. /*=--------------------------------------------------------------------------------------
  806. UpdateServerTreeNodeState
  807. hServer -- tree item that needs updating
  808. pServer -- server object
  809. *=------------------------------------------------------------------------------------*/
  810. LRESULT CAdminTreeView::UpdateServerTreeNodeState( HTREEITEM hServer , CServer *pServer , NODETYPE nt )
  811. {
  812. LockTreeControl( );
  813. if( hServer == NULL )
  814. {
  815. UnlockTreeControl( );
  816. return 0;
  817. }
  818. // Get the data attached to this tree node
  819. CTreeNode *node = (CTreeNode*)GetTreeCtrl().GetItemData(hServer);
  820. if( node != NULL && node->GetNodeType( ) == NODE_SERVER )
  821. {
  822. // Is this the server we want to update
  823. CServer *pTreeServer = (CServer*)node->GetTreeObject();
  824. // Make sure the tree node is correct
  825. if(pTreeServer != pServer)
  826. {
  827. UnlockTreeControl();
  828. return 0;
  829. }
  830. }
  831. else
  832. {
  833. UnlockTreeControl();
  834. return 0;
  835. }
  836. UINT NewState;
  837. // Remember the previous state
  838. UINT PreviousState = GetTreeCtrl().GetItemState(hServer, 0x0F00);
  839. // Change the icon/overlay for the server
  840. // If the server isn't sane, put a not sign over the icon
  841. if(!pServer->IsServerSane()) NewState = STATE_NOT;
  842. // If we aren't done getting all the information about this server,
  843. // put a question mark over the icon
  844. else if(pServer->IsState(SS_GETTING_INFO)) NewState = STATE_QUESTION;
  845. // If it is fine, we want to remove any overlays from the icon
  846. else NewState = STATE_NORMAL;
  847. // Set the tree item to the new state
  848. GetTreeCtrl().SetItemState(hServer, NewState, 0x0F00);
  849. // If this Server was not opened and now is GOOD,
  850. // add it's children to the tree
  851. if(PreviousState != STATE_NORMAL && pServer->IsState(SS_GOOD)) {
  852. int ServerIcon = DetermineServerIcon(pServer);
  853. GetTreeCtrl().SetItemImage(hServer, ServerIcon, ServerIcon);
  854. AddServerChildren(hServer, pServer , nt );
  855. // If this server is the server the user is sitting at and is
  856. // the currently selected tree item, expand it
  857. if(hServer == GetTreeCtrl().GetSelectedItem() && pServer->IsCurrentServer()) {
  858. GetTreeCtrl().Expand(hServer, TVE_EXPAND);
  859. }
  860. }
  861. else if(pServer->GetPreviousState() == SS_DISCONNECTING && pServer->IsState(SS_NOT_CONNECTED)) {
  862. int ServerIcon = DetermineServerIcon(pServer);
  863. GetTreeCtrl().SetItemImage(hServer, ServerIcon, ServerIcon);
  864. }
  865. // If we changed the state of this server and it is the currently
  866. // selected node in the tree, we need to send a message to change
  867. // the view
  868. if(NewState != PreviousState && hServer == GetTreeCtrl().GetSelectedItem()) {
  869. ForceSelChange();
  870. }
  871. UnlockTreeControl();
  872. return 0;
  873. } // end CAdminTreeView::OnAdminUpdateServer
  874. LRESULT CAdminTreeView::OnAdminAddWinStation(WPARAM wParam, LPARAM lParam)
  875. {
  876. ASSERT(lParam);
  877. ODS( L"**CAdminTreeView::OnAdminAddWinStation\n" );
  878. CWinStation *pWinStation = (CWinStation*)lParam;
  879. // Get the HTREEITEM of the Server this WinStation is attached to
  880. // TODO:
  881. // update the server item in the favorite list
  882. HTREEITEM hServer = pWinStation->GetServer()->GetTreeItem();
  883. if( hServer != NULL )
  884. {
  885. AddWinStation( pWinStation , hServer , ( BOOL )wParam , NODE_NONE );
  886. }
  887. hServer = pWinStation->GetServer( )->GetTreeItemFromFav( );
  888. if( hServer != NULL )
  889. {
  890. AddWinStation( pWinStation , hServer , ( BOOL )wParam , NODE_FAV_LIST );
  891. }
  892. hServer = pWinStation->GetServer( )->GetTreeItemFromThisComputer( );
  893. if( hServer != NULL )
  894. {
  895. AddWinStation( pWinStation , hServer , ( BOOL )wParam , NODE_THIS_COMP );
  896. }
  897. return 0;
  898. }
  899. ////////////////////////////////
  900. // F'N: CAdminTreeView::OnAdminAddWinStation
  901. //
  902. // Message handler to add a WinStation to the tree
  903. // lParam = pointer to CWinStation to add
  904. // wParam is TRUE if this is replacing a WinStation that was currently selected
  905. //
  906. LRESULT CAdminTreeView::AddWinStation( CWinStation * pWinStation , HTREEITEM hServer , BOOL bSel , NODETYPE nt )
  907. {
  908. ODS( L"**CAdminTreeView::AddWinStation\n" );
  909. HTREEITEM hWinStation;
  910. LockTreeControl();
  911. // Figure out which icon to use
  912. int WhichIcon = DetermineWinStationIcon(pWinStation);
  913. // Figure out what text to display
  914. TCHAR NameToDisplay[DISPLAY_NAME_SIZE];
  915. DetermineWinStationText(pWinStation, NameToDisplay);
  916. CTreeNode *pNode = new CTreeNode(NODE_WINSTATION, pWinStation);
  917. if(pNode) {
  918. pNode->SetSortOrder(pWinStation->GetSortOrder());
  919. // We have to insert this WinStation in sorted order
  920. // Get the first WinStation item attached to this server
  921. HTREEITEM hChild = GetTreeCtrl().GetNextItem(hServer, TVGN_CHILD);
  922. HTREEITEM hLastChild = TVI_FIRST;
  923. BOOL bAdded = FALSE;
  924. while(hChild)
  925. {
  926. CTreeNode *ChildNode = (CTreeNode*)GetTreeCtrl().GetItemData(hChild);
  927. if(ChildNode)
  928. {
  929. // Does it belong before this tree node?
  930. CWinStation *pTreeWinStation = (CWinStation*)ChildNode->GetTreeObject();
  931. if((pTreeWinStation->GetSortOrder() > pWinStation->GetSortOrder())
  932. || ((pTreeWinStation->GetSortOrder() == pWinStation->GetSortOrder()) &&
  933. (pTreeWinStation->GetSdClass() > pWinStation->GetSdClass())))
  934. {
  935. hWinStation = AddItemToTree(hServer, NameToDisplay, hLastChild, WhichIcon, (LPARAM)pNode);
  936. if(!hWinStation)
  937. {
  938. delete pNode;
  939. }
  940. // The WinStation wants to know his tree item handle
  941. if( nt == NODE_FAV_LIST )
  942. {
  943. pWinStation->SetTreeItemForFav( hWinStation );
  944. }
  945. else if( nt == NODE_THIS_COMP )
  946. {
  947. pWinStation->SetTreeItemForThisComputer( hWinStation );
  948. }
  949. else
  950. {
  951. pWinStation->SetTreeItem(hWinStation);
  952. }
  953. bAdded = TRUE;
  954. break;
  955. }
  956. }
  957. hLastChild = hChild;
  958. hChild = GetTreeCtrl().GetNextItem(hChild, TVGN_NEXT);
  959. }
  960. // If we didn't add it yet, add it at the end
  961. if(!bAdded)
  962. {
  963. hWinStation = AddItemToTree(hServer, NameToDisplay, hLastChild, WhichIcon, (LPARAM)pNode);
  964. if( hWinStation == NULL )
  965. {
  966. delete pNode;
  967. }
  968. // The WinStation wants to know his tree item handle
  969. if( nt == NODE_FAV_LIST )
  970. {
  971. pWinStation->SetTreeItemForFav( hWinStation );
  972. }
  973. else if( nt == NODE_THIS_COMP )
  974. {
  975. pWinStation->SetTreeItemForThisComputer( hWinStation );
  976. }
  977. else
  978. {
  979. pWinStation->SetTreeItem(hWinStation);
  980. }
  981. }
  982. // If this is replacing a WinStation in the tree that was the currently selected
  983. // tree item, make this new item in the tree the currently selected item
  984. if( bSel ) {
  985. GetTreeCtrl().SelectItem(hWinStation);
  986. }
  987. }
  988. UnlockTreeControl();
  989. return 0;
  990. } // end CAdminTreeView::OnAdminAddWinStation
  991. ////////////////////////////////
  992. // F'N: CAdminTreeView::OnAdminUpdateWinStation
  993. //
  994. // Message handler to update a WinStation in the tree
  995. // lParam = pointer to CWinStation to update
  996. //
  997. LRESULT CAdminTreeView::OnAdminUpdateWinStation(WPARAM wParam, LPARAM lParam)
  998. {
  999. ODS( L"CAdminTreeView::OnAdminUpdateWinStation\n" );
  1000. ASSERT(lParam);
  1001. CWinStation *pWinStation = (CWinStation*)lParam;
  1002. HTREEITEM hWinStation = pWinStation->GetTreeItem();
  1003. if( hWinStation != NULL )
  1004. {
  1005. UpdateWinStation( hWinStation , pWinStation );
  1006. }
  1007. hWinStation = pWinStation->GetTreeItemFromFav( );
  1008. if( hWinStation != NULL )
  1009. {
  1010. UpdateWinStation( hWinStation , pWinStation );
  1011. }
  1012. hWinStation = pWinStation->GetTreeItemFromThisComputer( );
  1013. if( hWinStation != NULL )
  1014. {
  1015. UpdateWinStation( hWinStation , pWinStation );
  1016. }
  1017. return 0;
  1018. }
  1019. LRESULT CAdminTreeView::UpdateWinStation( HTREEITEM hWinStation , CWinStation *pWinStation )
  1020. {
  1021. ODS( L"CAdminTreeView::UpdateWinStation\n" );
  1022. LockTreeControl();
  1023. // Get the data attached to this tree node
  1024. CTreeNode *node = (CTreeNode*)GetTreeCtrl().GetItemData(hWinStation);
  1025. if(node) {
  1026. // Is this the WinStation we want to update
  1027. CWinStation *pTreeWinStation = (CWinStation*)node->GetTreeObject();
  1028. // Make sure the tree node is correct
  1029. if(pTreeWinStation != pWinStation) {
  1030. UnlockTreeControl();
  1031. return 0;
  1032. }
  1033. } else {
  1034. UnlockTreeControl();
  1035. return 0;
  1036. }
  1037. // If the sort order of this WinStation has changed,
  1038. // we have to remove it from the tree and add it back in
  1039. if(node->GetSortOrder() != pWinStation->GetSortOrder())
  1040. {
  1041. OnAdminRemoveWinStation( 0 , ( LPARAM )pWinStation );
  1042. /*GetTreeCtrl().DeleteItem(hWinStation);
  1043. pWinStation->SetTreeItem(NULL);
  1044. */
  1045. OnAdminAddWinStation((GetTreeCtrl().GetSelectedItem() == hWinStation), ( LPARAM )pWinStation );
  1046. UnlockTreeControl();
  1047. return 0;
  1048. }
  1049. int WhichIcon = DetermineWinStationIcon(pWinStation);
  1050. GetTreeCtrl().SetItemImage(hWinStation, WhichIcon, WhichIcon);
  1051. TCHAR NameToDisplay[DISPLAY_NAME_SIZE];
  1052. DetermineWinStationText(pWinStation, NameToDisplay);
  1053. GetTreeCtrl().SetItemText(hWinStation, NameToDisplay);
  1054. UnlockTreeControl();
  1055. return 0;
  1056. } // end CAdminTreeView::OnAdminUpdateWinStation
  1057. ////////////////////////////////
  1058. // F'N: CAdminTreeView::OnAdminRemoveWinStation
  1059. //
  1060. // Message handler to remove a WinStation from the tree
  1061. // lParam = pointer to CWinStation to remove
  1062. LRESULT CAdminTreeView::OnAdminRemoveWinStation(WPARAM wParam, LPARAM lParam)
  1063. {
  1064. ODS( L"CAdminTreeView::OnAdminRemoveWinStation\n" );
  1065. ASSERT(lParam);
  1066. //TODO:
  1067. // remove winstaion from favorite list
  1068. CWinStation *pWinStation = (CWinStation*)lParam;
  1069. HTREEITEM hWinStation;
  1070. hWinStation = pWinStation->GetTreeItem();
  1071. if( hWinStation != NULL )
  1072. {
  1073. RemoveWinstation( hWinStation , pWinStation );
  1074. pWinStation->SetTreeItem( NULL );
  1075. }
  1076. hWinStation = pWinStation->GetTreeItemFromFav( );
  1077. if( hWinStation != NULL )
  1078. {
  1079. RemoveWinstation( hWinStation , pWinStation );
  1080. pWinStation->SetTreeItemForFav( NULL );
  1081. }
  1082. hWinStation = pWinStation->GetTreeItemFromThisComputer( );
  1083. if( hWinStation != NULL )
  1084. {
  1085. RemoveWinstation( hWinStation , pWinStation );
  1086. pWinStation->SetTreeItemForThisComputer( NULL );
  1087. }
  1088. return 0;
  1089. }
  1090. LRESULT CAdminTreeView::RemoveWinstation( HTREEITEM hWinStation , CWinStation *pWinStation )
  1091. {
  1092. BOOL CurrentInTree = FALSE;
  1093. LockTreeControl();
  1094. // Get the data attached to this tree node
  1095. CTreeNode *node = ( CTreeNode * )GetTreeCtrl().GetItemData(hWinStation);
  1096. if( node != NULL )
  1097. {
  1098. // Is this the WinStation we want to update
  1099. CWinStation *pTreeWinStation = (CWinStation*)node->GetTreeObject();
  1100. // Make sure the tree node is correct
  1101. if(pTreeWinStation != pWinStation)
  1102. {
  1103. UnlockTreeControl();
  1104. return 0;
  1105. }
  1106. }
  1107. else
  1108. {
  1109. UnlockTreeControl();
  1110. return 0;
  1111. }
  1112. // Delete the data attached to the tree item
  1113. delete node;
  1114. // Let the WinStation know he is no longer in the tree
  1115. // Is this WinStation currently selected in the tree?
  1116. CurrentInTree = ( GetTreeCtrl().GetSelectedItem() == hWinStation );
  1117. // Remove the WinStation from the tree
  1118. GetTreeCtrl().DeleteItem( hWinStation );
  1119. // If this WinStation is the currently selected node in the tree,
  1120. // make it not so
  1121. // This may not be necessary!
  1122. if( CurrentInTree )
  1123. {
  1124. ((CWinAdminDoc*)GetDocument())->SetCurrentView(VIEW_CHANGING);
  1125. }
  1126. UnlockTreeControl();
  1127. return 0;
  1128. } // end CAdminTreeView::OnAdminRemoveWinStation
  1129. ////////////////////////////////
  1130. // F'N: CAdminTreeView::OnAdminUpdateDomain
  1131. //
  1132. // Message handler to update a Domain in the tree
  1133. // Pointer to CDomain to update is in lParam
  1134. //
  1135. LRESULT CAdminTreeView::OnAdminUpdateDomain(WPARAM wParam, LPARAM lParam)
  1136. {
  1137. ASSERT(lParam);
  1138. CDomain *pDomain = (CDomain*)lParam;
  1139. HTREEITEM hDomain = pDomain->GetTreeItem();
  1140. if(!hDomain) return 0;
  1141. LockTreeControl();
  1142. // Get the data attached to this tree node
  1143. CTreeNode *node = (CTreeNode*)GetTreeCtrl().GetItemData(hDomain);
  1144. if(node) {
  1145. // Is this the domain we want to update
  1146. CDomain *pTreeDomain = (CDomain*)node->GetTreeObject();
  1147. // Make sure the tree node is correct
  1148. if(pTreeDomain != pDomain) {
  1149. UnlockTreeControl();
  1150. return 0;
  1151. }
  1152. } else {
  1153. UnlockTreeControl();
  1154. return 0;
  1155. }
  1156. UINT NewState;
  1157. // Remember the previous state
  1158. UINT PreviousState = GetTreeCtrl().GetItemState(hDomain, 0x0F00);
  1159. // Change the icon/overlay for the domain
  1160. if(pDomain->GetState() == DS_INITIAL_ENUMERATION) NewState = STATE_QUESTION;
  1161. // If it is fine, we want to remove any overlays from the icon
  1162. else NewState = STATE_NORMAL;
  1163. // Set the tree item to the new state
  1164. GetTreeCtrl().SetItemState(hDomain, NewState, 0x0F00);
  1165. // If the new state is STATE_NORMAL, change the icon
  1166. if(NewState == STATE_NORMAL) {
  1167. int DomainIcon = DetermineDomainIcon(pDomain);
  1168. GetTreeCtrl().SetItemImage(hDomain, DomainIcon, DomainIcon);
  1169. }
  1170. // If we changed the state of this domain and it is the currently
  1171. // selected node in the tree, we need to send a message to change
  1172. // the view
  1173. if(NewState != PreviousState && hDomain == GetTreeCtrl().GetSelectedItem()) {
  1174. ForceSelChange();
  1175. }
  1176. if(pDomain->GetState() == DS_ENUMERATING) GetTreeCtrl().Expand(hDomain, TVE_EXPAND);
  1177. UnlockTreeControl();
  1178. return 0;
  1179. } // end CAdminTreeView::OnAdminUpdateDomain
  1180. ////////////////////////////////
  1181. // F'N: CAdminTreeView::OnAdminAddDomain
  1182. //
  1183. // Message handler to update a Domain in the tree
  1184. // Pointer to CDomain to update is in lParam
  1185. //
  1186. LRESULT CAdminTreeView::OnAdminAddDomain(WPARAM wParam, LPARAM lParam)
  1187. {
  1188. ASSERT(lParam);
  1189. if(lParam)
  1190. {
  1191. CDomain *pDomain = (CDomain*)lParam;
  1192. return (LRESULT)AddDomainToTree(pDomain);
  1193. }
  1194. return 0;
  1195. } // end CAdminTreeView::OnAdminAddDomain
  1196. ////////////////////////////////
  1197. // F'N: CAdminTreeView::OnContextMenu
  1198. //
  1199. // Message handler called when user wants a context menu
  1200. // This happens when the user clicks the right mouse button,
  1201. // presses Shift-F10, or presses the menu key on a Windows keyboard
  1202. //
  1203. void CAdminTreeView::OnContextMenu(CWnd* pWnd, CPoint ptScreen)
  1204. {
  1205. LockTreeControl();
  1206. // Get a pointer to our document
  1207. CWinAdminDoc *doc = (CWinAdminDoc*)GetDocument();
  1208. CTreeCtrl &tree = GetTreeCtrl();
  1209. // TODO: Add your message handler code here
  1210. HTREEITEM hItem;
  1211. CPoint ptClient = ptScreen;
  1212. ScreenToClient(&ptClient);
  1213. // If we got here from the keyboard,
  1214. if(ptScreen.x == -1 && ptScreen.y == -1) {
  1215. hItem = tree.GetSelectedItem();
  1216. RECT rect;
  1217. tree.GetItemRect(hItem, &rect, TRUE);
  1218. ptScreen.x = rect.left + (rect.right - rect.left)/2;
  1219. ptScreen.y = rect.top + (rect.bottom - rect.top)/2;
  1220. tree.ClientToScreen(&ptScreen);
  1221. }
  1222. else {
  1223. // we shouldn't get here from the mouse
  1224. // but sometimes we do, so handle it gracefully
  1225. UnlockTreeControl();
  1226. return;
  1227. }
  1228. // Pop-up the menu for WinStations
  1229. CTreeNode *pNode = (CTreeNode*)tree.GetItemData(hItem);
  1230. ((CWinAdminDoc*)GetDocument())->SetTreeTemp(pNode->GetTreeObject(), (pNode->GetNodeType()));
  1231. if(pNode) {
  1232. CMenu menu;
  1233. UINT nIDResource = 0;
  1234. switch(pNode->GetNodeType()) {
  1235. case NODE_ALL_SERVERS:
  1236. nIDResource = IDR_ALLSERVERS_POPUP;
  1237. break;
  1238. case NODE_DOMAIN:
  1239. nIDResource = IDR_DOMAIN_POPUP;
  1240. break;
  1241. case NODE_SERVER:
  1242. nIDResource = IDR_SERVER_POPUP;
  1243. break;
  1244. case NODE_WINSTATION:
  1245. nIDResource = IDR_WINSTATION_TREE_POPUP;
  1246. break;
  1247. }
  1248. if(nIDResource)
  1249. {
  1250. if(menu.LoadMenu(nIDResource))
  1251. {
  1252. CMenu *pMenu = menu.GetSubMenu(0);
  1253. pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
  1254. }
  1255. }
  1256. } // end if(pNode)
  1257. UnlockTreeControl();
  1258. } // end CAdminTreeView::OnContextMenu
  1259. ////////////////////////////////
  1260. // F'N: CAdminTreeView::OnRClick
  1261. //
  1262. // The Tree Common Control sends a WM_NOTIFY of NM_RCLICK when
  1263. // the user presses the right mouse button in the tree
  1264. //
  1265. void CAdminTreeView::OnRClick(NMHDR* pNMHDR, LRESULT* pResult)
  1266. {
  1267. CPoint ptScreen(::GetMessagePos());
  1268. LockTreeControl();
  1269. // Get a pointer to our document
  1270. CWinAdminDoc *doc = (CWinAdminDoc*)GetDocument();
  1271. CTreeCtrl &tree = GetTreeCtrl();
  1272. // TODO: Add your message handler code here
  1273. UINT flags;
  1274. HTREEITEM hItem;
  1275. CPoint ptClient = ptScreen;
  1276. ScreenToClient(&ptClient);
  1277. hItem = tree.HitTest(ptClient, &flags);
  1278. if((NULL == hItem) || !(TVHT_ONITEM & flags)) {
  1279. UnlockTreeControl();
  1280. return;
  1281. }
  1282. // Pop-up the menu
  1283. CTreeNode *pNode = (CTreeNode*)tree.GetItemData(hItem);
  1284. ((CWinAdminDoc*)GetDocument())->SetTreeTemp(pNode->GetTreeObject(), (pNode->GetNodeType()));
  1285. if(pNode) {
  1286. CMenu menu;
  1287. UINT nIDResource = 0;
  1288. tree.SelectItem( hItem );
  1289. switch(pNode->GetNodeType()) {
  1290. case NODE_ALL_SERVERS:
  1291. nIDResource = IDR_ALLSERVERS_POPUP;
  1292. break;
  1293. case NODE_DOMAIN:
  1294. nIDResource = IDR_DOMAIN_POPUP;
  1295. break;
  1296. case NODE_SERVER:
  1297. nIDResource = IDR_SERVER_POPUP;
  1298. break;
  1299. case NODE_WINSTATION:
  1300. nIDResource = IDR_WINSTATION_TREE_POPUP;
  1301. break;
  1302. }
  1303. if(menu.LoadMenu( nIDResource ) )
  1304. {
  1305. CMenu *pMenu = menu.GetSubMenu(0);
  1306. if( pMenu != NULL )
  1307. {
  1308. pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
  1309. }
  1310. }
  1311. } // end if(pNode)
  1312. UnlockTreeControl();
  1313. } // end CAdminTreeView::OnRClick
  1314. //A false result means the server is disconnected
  1315. BOOL CAdminTreeView::ConnectToServer(CTreeCtrl* tree, HTREEITEM* hItem)
  1316. {
  1317. CTreeNode *pNode = (CTreeNode*)tree->GetItemData(*hItem);
  1318. if(pNode != NULL && *hItem == tree->GetSelectedItem() )
  1319. {
  1320. if( pNode->GetNodeType() == NODE_SERVER)
  1321. {
  1322. // Is this server in the "just disconnected" state
  1323. CServer *pServer = (CServer*)pNode->GetTreeObject();
  1324. // If both previous state and state are SS_NOT_CONNECTED,
  1325. // we know the user just disconnected from this server
  1326. if(pServer != NULL)
  1327. {
  1328. if(pServer->IsState(SS_NOT_CONNECTED) ||
  1329. pServer->IsState(SS_BAD))
  1330. return false;
  1331. }
  1332. else
  1333. return false;
  1334. }
  1335. else if( pNode->GetNodeType( ) == NODE_DOMAIN )
  1336. {
  1337. CDomain *pDomain = ( CDomain * )pNode->GetTreeObject( );
  1338. if( pDomain != NULL && pDomain->GetThreadPointer() == NULL )
  1339. pDomain->StartEnumerating();
  1340. }
  1341. }
  1342. return true;
  1343. }
  1344. ////////////////////////////////
  1345. // F'N: CAdminTreeView::OnLButtonDown
  1346. //
  1347. void CAdminTreeView::OnLButtonDblClk(UINT nFlags, CPoint ptClient)
  1348. {
  1349. LockTreeControl();
  1350. CTreeCtrl &tree = GetTreeCtrl();
  1351. UINT flags;
  1352. // Figure out what they clicked on
  1353. HTREEITEM hItem = tree.HitTest(ptClient, &flags);
  1354. if((NULL != hItem) && (TVHT_ONITEM & flags))
  1355. {
  1356. if (!ConnectToServer(&tree, &hItem))
  1357. {
  1358. LRESULT Result = 0xc0;
  1359. OnSelChange(NULL, &Result);
  1360. }
  1361. }
  1362. UnlockTreeControl();
  1363. CTreeView::OnLButtonDblClk(nFlags, ptClient);
  1364. }
  1365. LRESULT CAdminTreeView::OnAdminConnectToServer( WPARAM wp , LPARAM lp )
  1366. {
  1367. OnEnterKey();
  1368. return 0;
  1369. }
  1370. LRESULT CAdminTreeView::OnAdminForceSelChange( WPARAM wp , LPARAM lp )
  1371. {
  1372. ForceSelChange();
  1373. return 0;
  1374. }
  1375. void CAdminTreeView::OnEnterKey( )
  1376. {
  1377. LockTreeControl();
  1378. CTreeCtrl &tree = GetTreeCtrl();
  1379. // Figure out what's selected
  1380. HTREEITEM hItem = tree.GetSelectedItem( );
  1381. if (!ConnectToServer(&tree, &hItem))
  1382. {
  1383. LRESULT Result = 0xc0;
  1384. OnSelChange(NULL, &Result);
  1385. }
  1386. UnlockTreeControl();
  1387. }
  1388. void CAdminTreeView::OnSetFocus( CWnd *pOld )
  1389. {
  1390. CWnd::OnSetFocus( pOld );
  1391. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  1392. pDoc->RegisterLastFocus( TREE_VIEW );
  1393. }
  1394. //=---------------------------------------------------------------------------------------
  1395. // wp is the node type to expand on
  1396. // this computer
  1397. // favorite item
  1398. // domain item
  1399. LRESULT CAdminTreeView::OnAdminGotoServer( WPARAM wp , LPARAM lp )
  1400. {
  1401. // todo use wp correctly
  1402. CServer *pServer = ( CServer * )lp;
  1403. if( pServer == NULL )
  1404. {
  1405. ODS( L"CAdminTreeView::OnAdminGotoServer invalid server arg\n" );
  1406. return 0 ;
  1407. }
  1408. LockTreeControl( );
  1409. CTreeCtrl &tree = GetTreeCtrl( );
  1410. HTREEITEM hTreeItem = pServer->GetTreeItem( );
  1411. if( hTreeItem != NULL )
  1412. {
  1413. ODS( L"CAdminTreeView!OnAdminGotoServer - Server treeitem was found\n" );
  1414. tree.SelectItem(hTreeItem);
  1415. tree.Expand(hTreeItem, TVE_EXPAND);
  1416. }
  1417. UnlockTreeControl( );
  1418. return 0;
  1419. }
  1420. //=---------------------------------------------------------------------------------------
  1421. // wp and lp not used
  1422. //
  1423. LRESULT CAdminTreeView::OnAdminDelFavServer( WPARAM wp , LPARAM lp )
  1424. {
  1425. // get the current treenode
  1426. // determine if its a fav folder or if its parent a fav folder
  1427. // if so get the server and kill it
  1428. LockTreeControl( );
  1429. CTreeCtrl &tree = GetTreeCtrl( );
  1430. HTREEITEM hTreeItem = tree.GetSelectedItem();
  1431. do
  1432. {
  1433. if( hTreeItem == NULL )
  1434. {
  1435. break;
  1436. }
  1437. HTREEITEM hTreeRoot = tree.GetRootItem( );
  1438. if( hTreeRoot == NULL )
  1439. {
  1440. break;
  1441. }
  1442. // get fav folder
  1443. HTREEITEM hTreeFavRoot = tree.GetNextItem( hTreeRoot , TVGN_NEXT );
  1444. if( hTreeFavRoot == NULL )
  1445. {
  1446. break;
  1447. }
  1448. if( hTreeFavRoot == hTreeItem )
  1449. {
  1450. // not a cool thing here ignore
  1451. break;
  1452. }
  1453. hTreeRoot = tree.GetNextItem( hTreeItem , TVGN_PARENT );
  1454. if( hTreeFavRoot == hTreeRoot )
  1455. {
  1456. // yes we're talking about a fav node that the user wants to delete
  1457. CTreeNode *pNode = ( CTreeNode* )tree.GetItemData( hTreeItem );
  1458. if( pNode != NULL && pNode->GetNodeType() == NODE_SERVER )
  1459. {
  1460. CServer *pServer = ( CServer* )pNode->GetTreeObject();
  1461. // sanity check
  1462. if( pServer != NULL && pServer->GetTreeItemFromFav() == hTreeItem )
  1463. {
  1464. OnAdminRemoveServerFromFavs( 0 , ( LPARAM )pServer );
  1465. }
  1466. }
  1467. }
  1468. }while( 0 );
  1469. UnlockTreeControl( );
  1470. return 0;
  1471. }
  1472. //=-------------------------------------------------------------
  1473. LRESULT CAdminTreeView::OnGetTVStates( WPARAM , LPARAM )
  1474. {
  1475. ODS( L"CAdminTreeView::OnGetTVStates\n" );
  1476. DWORD dwStates = 0;
  1477. // find out the tri-states
  1478. HTREEITEM hRoot;
  1479. LockTreeControl( );
  1480. CTreeCtrl &tree = GetTreeCtrl( );
  1481. hRoot = tree.GetRootItem( ); // this computer
  1482. if( hRoot != NULL )
  1483. {
  1484. if( tree.GetItemState( hRoot , TVIS_EXPANDED ) & TVIS_EXPANDED )
  1485. {
  1486. dwStates = TV_THISCOMP;
  1487. }
  1488. hRoot = tree.GetNextItem( hRoot , TVGN_NEXT ); // favorites
  1489. if( hRoot != NULL && tree.GetItemState( hRoot , TVIS_EXPANDED ) & TVIS_EXPANDED )
  1490. {
  1491. dwStates |= TV_FAVS;
  1492. }
  1493. hRoot = tree.GetNextItem( hRoot , TVGN_NEXT ); // all servers
  1494. if( hRoot != NULL && tree.GetItemState( hRoot , TVIS_EXPANDED ) & TVIS_EXPANDED )
  1495. {
  1496. dwStates |= TV_ALLSERVERS;
  1497. }
  1498. }
  1499. UnlockTreeControl( );
  1500. return ( LRESULT )dwStates;
  1501. }
  1502. //=-------------------------------------------------------------
  1503. LRESULT CAdminTreeView::OnUpdateTVState( WPARAM , LPARAM )
  1504. {
  1505. LRESULT lResult = 0xc0;
  1506. HTREEITEM hThisComputerRootItem = GetTreeCtrl().GetRootItem( );
  1507. HTREEITEM hFavRoot = GetTreeCtrl().GetNextItem( hThisComputerRootItem , TVGN_NEXT );
  1508. HTREEITEM hRoot = GetTreeCtrl().GetNextItem( hFavRoot , TVGN_NEXT );
  1509. // We want to default to having the current server being the
  1510. // currently selected item in the tree and be expanded
  1511. if( hThisComputerRootItem != NULL && ( g_dwTreeViewExpandedStates & TV_THISCOMP ) )
  1512. {
  1513. HTREEITEM hThisComputer = GetTreeCtrl().GetNextItem( hThisComputerRootItem , TVGN_CHILD );
  1514. if( hThisComputer != NULL )
  1515. {
  1516. GetTreeCtrl().SelectItem(hThisComputer);
  1517. GetTreeCtrl().Expand(hThisComputer, TVE_EXPAND);
  1518. // GetTreeCtrl().Expand(hDomain, TVE_EXPAND);
  1519. //lResult = 0xc0;
  1520. OnSelChange( NULL , &lResult );
  1521. }
  1522. }
  1523. if( hFavRoot != NULL && ( g_dwTreeViewExpandedStates & TV_FAVS ) )
  1524. {
  1525. GetTreeCtrl().SelectItem( hFavRoot );
  1526. GetTreeCtrl().Expand( hFavRoot , TVE_EXPAND );
  1527. OnSelChange( NULL , &lResult );
  1528. }
  1529. if( hRoot != NULL && ( g_dwTreeViewExpandedStates & TV_ALLSERVERS ) )
  1530. {
  1531. GetTreeCtrl().SelectItem( hRoot );
  1532. GetTreeCtrl().Expand( hRoot , TVE_EXPAND );
  1533. OnSelChange( NULL , &lResult );
  1534. }
  1535. return 0;
  1536. }
  1537. //=-------------------------------------------------------------
  1538. void CAdminTreeView::OnBeginDrag( NMHDR *pNMHDR , LRESULT *pResult )
  1539. {
  1540. ODS( L"CAdminTreeView::OnBeginDrag\n" );
  1541. RECT rc;
  1542. NMTREEVIEW *pTV = ( NMTREEVIEW * )pNMHDR;
  1543. if( pTV != NULL )
  1544. {
  1545. if( m_pimgDragList != NULL )
  1546. {
  1547. // this should never happen
  1548. ODS( L"There is a possible leak CAdminTreeView!OnBeginDrag\n" );
  1549. delete m_pimgDragList;
  1550. m_pimgDragList = NULL;
  1551. }
  1552. if( pTV->itemNew.hItem != NULL )
  1553. {
  1554. m_pimgDragList = GetTreeCtrl().CreateDragImage( pTV->itemNew.hItem );
  1555. }
  1556. if( m_pimgDragList != NULL )
  1557. {
  1558. GetTreeCtrl().GetItemRect( pTV->itemNew.hItem , &rc , FALSE );
  1559. CPoint cp( pTV->ptDrag.x - rc.left , pTV->ptDrag.y - rc.top );
  1560. /*
  1561. HCURSOR hCursor = ::LoadCursor( NULL, IDC_CROSS );
  1562. ICONINFO iconinfo;
  1563. ::GetIconInfo( ( HICON )hCursor , &iconinfo );
  1564. */
  1565. m_pimgDragList->BeginDrag( 0 , CPoint( 0 , 0 ) );
  1566. /*
  1567. cp.x -= iconinfo.xHotspot;
  1568. cp.y -= iconinfo.yHotspot;
  1569. m_pimgDragList->SetDragCursorImage( 0 , cp );
  1570. */
  1571. m_pimgDragList->DragEnter( &GetTreeCtrl( ) , cp );
  1572. SetCapture();
  1573. // this is for us to check when we're not in the client area
  1574. m_nTimer = SetTimer( 1 , 50 , NULL );
  1575. //ShowCursor( FALSE );
  1576. m_hDragItem = pTV->itemNew.hItem;
  1577. }
  1578. }
  1579. *pResult = 0;
  1580. }
  1581. //=-------------------------------------------------------------
  1582. void CAdminTreeView::OnTimer( UINT nIDEvent )
  1583. {
  1584. UINT uflags;
  1585. POINT pt;
  1586. CTreeCtrl &cTree = GetTreeCtrl( );
  1587. GetCursorPos(&pt);
  1588. cTree.ScreenToClient( &pt );
  1589. if( m_nTimer == 0 )
  1590. {
  1591. return;
  1592. }
  1593. HTREEITEM hItem;
  1594. HTREEITEM hTreeItem = cTree.HitTest( CPoint( pt.x , pt.y ) , &uflags );
  1595. if( uflags & TVHT_ABOVE )
  1596. {
  1597. ODS( L"scrolling up...\n" );
  1598. hItem = cTree.GetFirstVisibleItem( );
  1599. hItem = cTree.GetNextItem( hItem , TVGN_PREVIOUSVISIBLE );
  1600. if( hItem != NULL )
  1601. {
  1602. cTree.Invalidate( );
  1603. cTree.EnsureVisible( hItem );
  1604. }
  1605. }
  1606. else if( uflags & TVHT_BELOW )
  1607. {
  1608. ODS( L"scrolling down...\n" );
  1609. hItem = cTree.GetFirstVisibleItem( );
  1610. hItem = cTree.GetNextItem( hItem , TVGN_NEXT );
  1611. if( hItem != NULL )
  1612. {
  1613. cTree.EnsureVisible( hItem );
  1614. }
  1615. }
  1616. }
  1617. //=-------------------------------------------------------------
  1618. void CAdminTreeView::OnLButtonUp( UINT uFlags , CPoint cp )
  1619. {
  1620. ODS( L"CAdminTreeView::OnLButtonUp\n" );
  1621. if( m_hDragItem != NULL && m_pimgDragList != NULL )
  1622. {
  1623. m_pimgDragList->DragLeave( &GetTreeCtrl( ) );
  1624. m_pimgDragList->EndDrag( );
  1625. m_pimgDragList->DeleteImageList( );
  1626. delete m_pimgDragList;
  1627. m_pimgDragList = NULL;
  1628. KillTimer( m_nTimer );
  1629. m_nTimer = 0;
  1630. ReleaseCapture( );
  1631. Invalidate( );
  1632. // ShowCursor( TRUE );
  1633. }
  1634. }
  1635. //=-------------------------------------------------------------
  1636. void CAdminTreeView::OnMouseMove( UINT uFlags , CPoint cp )
  1637. {
  1638. if( m_pimgDragList != NULL )
  1639. {
  1640. UINT uflags;
  1641. HTREEITEM hTreeItem = GetTreeCtrl( ).HitTest( cp , &uflags );
  1642. if( hTreeItem != GetTreeCtrl( ).GetDropHilightItem( ) )
  1643. {
  1644. ODS( L"CAdminTreeView::OnMouseMove NOT!!\n");
  1645. m_pimgDragList->DragLeave( &GetTreeCtrl( ) );
  1646. GetTreeCtrl( ).SelectDropTarget( NULL );
  1647. GetTreeCtrl( ).SelectDropTarget( hTreeItem );
  1648. m_pimgDragList->DragEnter( &GetTreeCtrl( ) , cp );
  1649. }
  1650. else
  1651. {
  1652. m_pimgDragList->DragMove( cp );
  1653. }
  1654. }
  1655. }
  1656. //=-------------------------------------------------------------
  1657. LRESULT CAdminTreeView::OnEmptyFavorites( WPARAM wp, LPARAM )
  1658. {
  1659. ODS( L"CAdminTreeView!OnEmptyFavorites\n" );
  1660. // check to see if there are any items in the view
  1661. LockTreeControl( );
  1662. CTreeCtrl &tree = GetTreeCtrl( );
  1663. int nRet;
  1664. HTREEITEM hTreeRoot = tree.GetRootItem( );
  1665. do
  1666. {
  1667. if( hTreeRoot == NULL )
  1668. {
  1669. break;
  1670. }
  1671. // get fav folder
  1672. HTREEITEM hTreeFavRoot = tree.GetNextItem( hTreeRoot , TVGN_NEXT );
  1673. if( hTreeFavRoot == NULL )
  1674. {
  1675. break;
  1676. }
  1677. HTREEITEM hItem = tree.GetNextItem( hTreeFavRoot , TVGN_CHILD );
  1678. if( hItem == NULL )
  1679. {
  1680. break;
  1681. }
  1682. // warn the user about losing the entire favorite list
  1683. CString cstrMsg;
  1684. CString cstrTitle;
  1685. cstrMsg.LoadString( IDS_EMPTYFOLDER );
  1686. cstrTitle.LoadString( AFX_IDS_APP_TITLE );
  1687. #ifdef _STRESS_BUILD
  1688. if( ( BOOL )wp != TRUE )
  1689. {
  1690. #endif
  1691. nRet = MessageBox( cstrMsg ,
  1692. cstrTitle ,
  1693. MB_YESNO | MB_ICONINFORMATION );
  1694. #ifdef _STRESS_BUILD
  1695. }
  1696. else
  1697. {
  1698. nRet = IDYES;
  1699. }
  1700. #endif
  1701. if( nRet == IDYES )
  1702. {
  1703. // loop through every item and remove the item
  1704. HTREEITEM hNextItem = hItem;
  1705. while( hItem != NULL )
  1706. {
  1707. CTreeNode *pNode = (CTreeNode*)tree.GetItemData(hItem);
  1708. hNextItem = tree.GetNextItem( hItem , TVGN_NEXT );
  1709. if( pNode != NULL )
  1710. {
  1711. // Is it the same item as is selected
  1712. if( pNode->GetNodeType() == NODE_SERVER )
  1713. {
  1714. CServer *pServer = (CServer*)pNode->GetTreeObject();
  1715. // skip this server if its being disconnected
  1716. if( !pServer->IsState( SS_DISCONNECTING ) )
  1717. {
  1718. SendMessage( WM_ADMIN_REMOVESERVERFROMFAV , 0 , ( LPARAM )pServer );
  1719. }
  1720. }
  1721. }
  1722. hItem = hNextItem;
  1723. }
  1724. }
  1725. }while( 0 );
  1726. UnlockTreeControl( );
  1727. return 0;
  1728. }
  1729. //=----------------------------------------------------------------
  1730. LRESULT CAdminTreeView::OnIsFavListEmpty( WPARAM wp , LPARAM lp )
  1731. {
  1732. LockTreeControl( );
  1733. CTreeCtrl &tree = GetTreeCtrl( );
  1734. HTREEITEM hTreeRoot = tree.GetRootItem( );
  1735. BOOL bEmpty = TRUE;
  1736. do
  1737. {
  1738. if( hTreeRoot == NULL )
  1739. {
  1740. break;
  1741. }
  1742. // get fav folder
  1743. HTREEITEM hTreeFavRoot = tree.GetNextItem( hTreeRoot , TVGN_NEXT );
  1744. if( hTreeFavRoot == NULL )
  1745. {
  1746. break;
  1747. }
  1748. HTREEITEM hItem = tree.GetNextItem( hTreeFavRoot , TVGN_CHILD );
  1749. if( hItem == NULL )
  1750. {
  1751. break;
  1752. }
  1753. bEmpty = FALSE;
  1754. } while( 0 );
  1755. UnlockTreeControl( );
  1756. return ( LRESULT )bEmpty;
  1757. }