Source code of Windows XP (NT5)
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.

1213 lines
33 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*++
  3. Module Name:
  4. LtView.cpp
  5. Abstract:
  6. This Module contains the implementation of CLicMgrLeftView class
  7. (The View class used for the Left pane of the splitter)
  8. Author:
  9. Arathi Kundapur (v-akunda) 11-Feb-1998
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "LicMgr.h"
  14. #include "defines.h"
  15. #include "LSMgrDoc.h"
  16. #include "LtView.h"
  17. #include "TreeNode.h"
  18. #include "LSServer.h"
  19. #include "mainfrm.h"
  20. #include "addkp.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CLicMgrLeftView
  28. IMPLEMENT_DYNCREATE(CLicMgrLeftView, CTreeView)
  29. BEGIN_MESSAGE_MAP(CLicMgrLeftView, CTreeView)
  30. //{{AFX_MSG_MAP(CLicMgrLeftView)
  31. ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  32. ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
  33. ON_NOTIFY_REFLECT(TVN_KEYDOWN, OnKeydown)
  34. ON_NOTIFY_REFLECT(NM_RCLICK , OnRightClick )
  35. ON_NOTIFY_REFLECT(NM_CLICK , OnLeftClick )
  36. ON_COMMAND(ID_ADD_LICENSES, OnAddNewKeyPack)
  37. ON_WM_DESTROY()
  38. //}}AFX_MSG_MAP
  39. // Standard printing commands
  40. ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
  41. ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
  42. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
  43. ON_MESSAGE(WM_ADD_SERVER, OnAddServer)
  44. ON_MESSAGE(WM_DELETE_SERVER, OnDeleteServer)
  45. ON_MESSAGE(WM_UPDATE_SERVER, OnUpdateServer)
  46. ON_MESSAGE(WM_ADD_ALL_SERVERS, OnAddAllServers)
  47. ON_MESSAGE(WM_ADD_KEYPACK, OnAddKeyPack)
  48. // all server menus
  49. ON_WM_CONTEXTMENU( )
  50. ON_COMMAND( ID_ALLSVR_CONNECT , OnServerConnect )
  51. ON_COMMAND( ID_ALLSVR_REFRESHALL , OnRefreshAllServers )
  52. ON_COMMAND( ID_ALLSVR_HELP , OnGeneralHelp )
  53. // server menuitems
  54. // ON_COMMAND( ID_LPK_CONNECT , OnServerConnect )
  55. ON_COMMAND( ID_LPK_REFRESH , OnRefreshServer )
  56. ON_COMMAND( ID_LPK_REFRESHALL , OnRefreshAllServers )
  57. ON_COMMAND( ID_LPK_DOWNLOADLICENSES , OnDownloadKeepPack )
  58. ON_COMMAND( ID_SVR_ACTIVATESERVER , OnRegisterServer )
  59. ON_COMMAND( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , OnRepeatLastDownload )
  60. ON_COMMAND( ID_LPK_ADVANCED_REACTIVATESERVER , OnReactivateServer )
  61. ON_COMMAND( ID_LPK_ADVANCED_DEACTIVATESERVER , OnDeactivateServer )
  62. ON_COMMAND( ID_LPK_PROPERTIES , OnServerProperties )
  63. ON_COMMAND( ID_LPK_HELP , OnGeneralHelp )
  64. // license pak items
  65. // ON_COMMAND( ID_LICPAK_CONNECT , OnServerConnect )
  66. ON_COMMAND( ID_LICPAK_REFRESH , OnRefreshServer )
  67. // ON_COMMAND( ID_LICPAK_REFRESHALL , OnRefreshAllServers )
  68. ON_COMMAND( ID_LICPAK_DOWNLOADLICENSES , OnDownloadKeepPack )
  69. ON_COMMAND( ID_LICPAK_REPEATDOWNLOAD , OnRepeatLastDownload )
  70. ON_COMMAND( ID_LICPAK_HELP , OnGeneralHelp )
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CLicMgrLeftView construction/destruction
  74. CLicMgrLeftView::CLicMgrLeftView()
  75. {
  76. // TODO: add construction code here
  77. m_ht = ( HTREEITEM )NULL;
  78. }
  79. CLicMgrLeftView::~CLicMgrLeftView()
  80. {
  81. }
  82. BOOL CLicMgrLeftView::PreCreateWindow(CREATESTRUCT& cs)
  83. {
  84. // TODO: Modify the Window class or styles here by modifying
  85. // the CREATESTRUCT cs
  86. return CTreeView::PreCreateWindow(cs);
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CLicMgrLeftView drawing
  90. void CLicMgrLeftView::OnDraw(CDC* pDC)
  91. {
  92. CLicMgrDoc* pDoc = GetDocument();
  93. ASSERT_VALID(pDoc);
  94. // TODO: add draw code for native data here
  95. }
  96. void CLicMgrLeftView::OnInitialUpdate()
  97. {
  98. CTreeView::OnInitialUpdate();
  99. GetTreeCtrl().ModifyStyle(0,TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS);
  100. BuildImageList();
  101. // TODO: You may populate your TreeView with items by directly accessing
  102. // its tree control through a call to GetTreeCtrl().
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CLicMgrLeftView printing
  106. BOOL CLicMgrLeftView::OnPreparePrinting(CPrintInfo* pInfo)
  107. {
  108. // default preparation
  109. return DoPreparePrinting(pInfo);
  110. }
  111. void CLicMgrLeftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  112. {
  113. // TODO: add extra initialization before printing
  114. }
  115. void CLicMgrLeftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  116. {
  117. // TODO: add cleanup after printing
  118. }
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CLicMgrLeftView diagnostics
  121. #ifdef _DEBUG
  122. void CLicMgrLeftView::AssertValid() const
  123. {
  124. CTreeView::AssertValid();
  125. }
  126. void CLicMgrLeftView::Dump(CDumpContext& dc) const
  127. {
  128. CTreeView::Dump(dc);
  129. }
  130. CLicMgrDoc* CLicMgrLeftView::GetDocument() // non-debug version is inline
  131. {
  132. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLicMgrDoc)));
  133. return (CLicMgrDoc*)m_pDocument;
  134. }
  135. #endif //_DEBUG
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CLicMgrLeftView message handlers
  138. HTREEITEM CLicMgrLeftView::AddItemToTree(HTREEITEM hParent, CString Text, HTREEITEM hInsAfter, int iImage, LPARAM lParam)
  139. {
  140. HTREEITEM hItem = NULL;
  141. TV_ITEM tvItem = {0};
  142. TV_INSERTSTRUCT tvInsert;
  143. ASSERT(lParam);
  144. if(NULL == lParam)
  145. return hItem;
  146. tvItem.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  147. tvItem.pszText = Text.GetBuffer(Text.GetLength());
  148. tvItem.cchTextMax = Text.GetLength();
  149. tvItem.iImage = iImage;
  150. tvItem.iSelectedImage = iImage;
  151. tvItem.lParam = lParam;
  152. tvInsert.item = tvItem;
  153. tvInsert.hInsertAfter = hInsAfter;
  154. tvInsert.hParent = hParent;
  155. hItem = GetTreeCtrl().InsertItem(&tvInsert);
  156. // GetTreeCtrl().Expand(GetTreeCtrl().GetRootItem(), TVE_EXPAND);
  157. return hItem;
  158. }
  159. LRESULT CLicMgrLeftView::OnAddServer(WPARAM wParam, LPARAM lParam)
  160. {
  161. LRESULT lResult = 0;
  162. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  163. ASSERT(pDoc);
  164. if(NULL == pDoc)
  165. return lResult;
  166. CLicServer *pServer = (CLicServer*)lParam;
  167. ASSERT(pServer);
  168. if(NULL == pServer)
  169. return lResult;
  170. HTREEITEM hServer = NULL;
  171. HTREEITEM hItem = NULL;
  172. CTreeNode* pNode = NULL;
  173. HTREEITEM hRoot = GetTreeCtrl().GetRootItem();
  174. if(!hRoot)
  175. goto cleanup;
  176. // First make sure the server isn't already in the tree
  177. // Get the first server under the domain
  178. hItem = GetTreeCtrl().GetNextItem(hRoot, TVGN_CHILD);
  179. while(hItem) {
  180. // Get the data attached to the tree item
  181. CTreeNode *node = (CTreeNode*)GetTreeCtrl().GetItemData(hItem);
  182. if(node) {
  183. // Is this the server we want to add
  184. CLicServer *pServer = (CLicServer*)node->GetTreeObject();
  185. if(pServer == (CLicServer*)lParam) return 0;
  186. }
  187. hItem = GetTreeCtrl().GetNextItem(hItem, TVGN_NEXT);
  188. }
  189. // Add the server to the tree
  190. // Create a CTreeNode object with info about this tree node
  191. pNode = new CTreeNode(NODE_SERVER, pServer);
  192. if(pNode)
  193. {
  194. int iImage = 0;
  195. if( pServer->GetServerType() == SERVER_TS5_ENFORCED )
  196. {
  197. DWORD dwStatus = pServer->GetServerRegistrationStatus();
  198. if( dwStatus == LSERVERSTATUS_REGISTER_INTERNET || dwStatus == LSERVERSTATUS_REGISTER_OTHER )
  199. {
  200. iImage = 3;
  201. }
  202. else if( dwStatus == LSERVERSTATUS_WAITFORPIN )
  203. {
  204. iImage = 4;
  205. }
  206. else if( dwStatus == LSERVERSTATUS_UNREGISTER )
  207. {
  208. iImage = 5;
  209. }
  210. else
  211. {
  212. iImage = 6;
  213. }
  214. }
  215. hServer = AddItemToTree(hRoot, pServer->GetDisplayName(), TVI_SORT, iImage , (LPARAM)pNode);
  216. if(!hServer) delete pNode;
  217. // The server wants to know his tree item handle
  218. pServer->SetTreeItem(hServer);
  219. }
  220. cleanup:
  221. return lResult;
  222. } // OnAddServer
  223. LRESULT CLicMgrLeftView::OnAddKeyPack(WPARAM wParam, LPARAM lParam)
  224. {
  225. LRESULT lResult = 0;
  226. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  227. ASSERT(pDoc);
  228. if(NULL == pDoc)
  229. return lResult;
  230. CLicServer *pServer = (CLicServer*)wParam;
  231. ASSERT(pServer);
  232. if(NULL == pServer)
  233. return lResult;
  234. CKeyPack *pKeyPack = (CKeyPack*)lParam;
  235. ASSERT(pKeyPack);
  236. if(NULL == pKeyPack)
  237. return lResult;
  238. HTREEITEM hKeyPackItem = NULL;
  239. TV_ITEM Item;
  240. memset((void *)&Item,0,sizeof(Item));
  241. Item.mask = TVIF_HANDLE;
  242. HTREEITEM hServer = pServer->GetTreeItem();
  243. if(NULL == hServer)
  244. return lResult;
  245. Item.hItem = hServer;
  246. if(FALSE == GetTreeCtrl().GetItem(&Item))
  247. return lResult;
  248. if(Item.state & TVIS_EXPANDED)
  249. {
  250. CTreeNode *pNode = new CTreeNode(NODE_KEYPACK, pKeyPack);
  251. if(pNode)
  252. {
  253. hKeyPackItem = AddItemToTree(hServer, (LPCTSTR)pKeyPack->GetDisplayName(), hServer, 2, (LPARAM)pNode);
  254. if(!hKeyPackItem)
  255. delete pNode;
  256. }
  257. pKeyPack->SetTreeItem(hKeyPackItem);
  258. }
  259. return lResult;
  260. } // OnAddKeyPack
  261. LRESULT CLicMgrLeftView::OnAddAllServers(WPARAM wParam, LPARAM lParam)
  262. {
  263. LRESULT lResult = 0;
  264. HTREEITEM hItem = NULL;
  265. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  266. ASSERT(pDoc);
  267. if(NULL == pDoc)
  268. return lResult;
  269. CTreeNode* pNode = NULL;
  270. CAllServers *pAllServer = (CAllServers*)lParam;
  271. if(!pAllServer)
  272. goto cleanup ;
  273. hItem = pAllServer->GetTreeItem();
  274. if(NULL != hItem)
  275. goto cleanup;
  276. // Create a CTreeNode object with info about this tree node
  277. pNode = new CTreeNode(NODE_ALL_SERVERS, pAllServer);
  278. if(pNode)
  279. {
  280. HTREEITEM hAllServers = AddItemToTree(NULL, pAllServer->GetName(), TVI_SORT,0 , (LPARAM)pNode);
  281. if(!hAllServers) delete pNode;
  282. // The server wants to know his tree item handle
  283. pAllServer->SetTreeItem(hAllServers);
  284. //Set the Selection to this item
  285. GetTreeCtrl().SelectItem(hAllServers);
  286. }
  287. GetTreeCtrl().Expand(GetTreeCtrl().GetRootItem(), TVE_EXPAND);
  288. cleanup:
  289. return lResult ;
  290. } // OnAddAllServers
  291. void CLicMgrLeftView::AddServerKeyPacks(CLicServer *pServer)
  292. {
  293. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  294. ASSERT(pDoc);
  295. if(NULL == pDoc)
  296. return;
  297. POSITION pos;
  298. KeyPackList *pKeyPackList = NULL;
  299. HTREEITEM hLastNode = NULL;
  300. ASSERT(pServer);
  301. if(NULL == pServer)
  302. return;
  303. HTREEITEM hServer = pServer->GetTreeItem();
  304. if(NULL == hServer)
  305. goto cleanup; //Server Not in the Tree.
  306. hLastNode= hServer;
  307. // Get a pointer to the server's list of installed KeyPacks
  308. pKeyPackList = pServer->GetKeyPackList();
  309. // Iterate through the KeyPack list
  310. pos = pKeyPackList->GetHeadPosition();
  311. while(pos)
  312. {
  313. CKeyPack *pKeyPack = (CKeyPack *)pKeyPackList->GetNext(pos);
  314. CTreeNode *pNode = new CTreeNode(NODE_KEYPACK, pKeyPack);
  315. if(pNode)
  316. {
  317. hLastNode = AddItemToTree(hServer, (LPCTSTR)pKeyPack->GetDisplayName(), hLastNode, 2, (LPARAM)pNode);
  318. if(!hLastNode)
  319. delete pNode;
  320. }
  321. pKeyPack->SetTreeItem(hLastNode);
  322. }
  323. cleanup:
  324. return;
  325. } // end AddKeyPacks
  326. void CLicMgrLeftView::BuildImageList()
  327. {
  328. m_ImageList.Create(16, 16, TRUE, 18, 0);
  329. AddIconToImageList(IDI_ALL_SERVERS);
  330. AddIconToImageList(IDI_SERVER);
  331. AddIconToImageList(IDI_KEYPACK);
  332. AddIconToImageList(IDI_SERVERREG );
  333. AddIconToImageList(IDI_SERVERM );
  334. AddIconToImageList(IDI_SERVERX );
  335. AddIconToImageList(IDI_SERVERQ );
  336. GetTreeCtrl().SetImageList(&m_ImageList, TVSIL_NORMAL);
  337. } // end BuildImageList
  338. int CLicMgrLeftView::AddIconToImageList(int iconID)
  339. {
  340. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  341. return m_ImageList.Add(hIcon);
  342. }
  343. void CLicMgrLeftView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
  344. {
  345. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  346. // TODO: Add your control notification handler code here
  347. //Check if the node selected is All-Servers,Server or the KeyPack.
  348. //Accordingly change the right pane view.
  349. CTreeCtrl& TreeCtrl = GetTreeCtrl();
  350. HTREEITEM hCurr = TreeCtrl.GetSelectedItem();
  351. if(NULL == hCurr)
  352. {
  353. return;
  354. }
  355. CTreeNode *pNode = (CTreeNode *)GetTreeCtrl().GetItemData(hCurr);
  356. if(NULL == pNode)
  357. {
  358. return;
  359. }
  360. CLicServer *pLicServer = NULL;
  361. CKeyPack * pKeyPack = NULL;
  362. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  363. ASSERT(pDoc);
  364. if(NULL == pDoc)
  365. return;
  366. switch(pNode->GetNodeType())
  367. {
  368. case NODE_ALL_SERVERS:
  369. AfxGetMainWnd()->SendMessage(WM_SEL_CHANGE,NODE_ALL_SERVERS,NULL);
  370. break;
  371. case NODE_SERVER:
  372. pLicServer = (CLicServer *)pNode->GetTreeObject();
  373. if(NULL == pLicServer)
  374. break;
  375. if(FALSE == pLicServer->IsExpanded())
  376. {
  377. SetCursor(LoadCursor(NULL,IDC_WAIT));
  378. HRESULT hResult = pDoc->EnumerateKeyPacks(pLicServer,LSKEYPACK_SEARCH_LANGID, TRUE);
  379. if(hResult != S_OK)
  380. {
  381. ((CMainFrame *)AfxGetMainWnd())->EnumFailed(hResult,pLicServer);
  382. if(pLicServer && pLicServer->GetTreeItem())
  383. {
  384. TreeCtrl.SelectItem(TreeCtrl.GetParentItem(pLicServer->GetTreeItem()));
  385. }
  386. break;
  387. }
  388. AddServerKeyPacks(pLicServer);
  389. }
  390. else
  391. {
  392. if(!pLicServer->GetKeyPackList()->IsEmpty())
  393. {
  394. if(!TreeCtrl.ItemHasChildren(hCurr))
  395. AddServerKeyPacks(pLicServer);
  396. }
  397. }
  398. AfxGetMainWnd()->SendMessage(WM_SEL_CHANGE,NODE_SERVER,(LPARAM)pLicServer);
  399. break;
  400. case NODE_KEYPACK:
  401. pKeyPack = (CKeyPack *)pNode->GetTreeObject();
  402. ASSERT(pKeyPack);
  403. if(NULL == pKeyPack)
  404. break;
  405. if(FALSE == pKeyPack->IsExpanded())
  406. {
  407. SetCursor(LoadCursor(NULL,IDC_WAIT));
  408. HRESULT hResult = pDoc->EnumerateLicenses(pKeyPack,LSLICENSE_SEARCH_KEYPACKID, TRUE);
  409. if(hResult != S_OK)
  410. {
  411. ((CMainFrame *)AfxGetMainWnd())->EnumFailed(hResult,pKeyPack->GetServer());
  412. if(pKeyPack && pKeyPack->GetTreeItem())
  413. {
  414. TreeCtrl.SelectItem(TreeCtrl.GetParentItem(pKeyPack->GetTreeItem()));
  415. }
  416. break;
  417. }
  418. }
  419. AfxGetMainWnd()->SendMessage(WM_SEL_CHANGE,NODE_KEYPACK,(LPARAM)pNode->GetTreeObject());
  420. break;
  421. }
  422. *pResult = 0;
  423. }
  424. void CLicMgrLeftView::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult)
  425. {
  426. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  427. // TODO: Add your control notification handler code here
  428. *pResult = 0;
  429. }
  430. void CLicMgrLeftView::OnAddNewKeyPack()
  431. {
  432. // TODO: Add your command handler code here
  433. HTREEITEM hTreeItem = GetTreeCtrl().GetSelectedItem();
  434. // CAddKeyPack KeyPack;
  435. if(NULL == hTreeItem)
  436. return;
  437. CTreeNode *pNode = (CTreeNode *)GetTreeCtrl().GetItemData(hTreeItem);
  438. if(NULL == pNode)
  439. return;
  440. if(NODE_SERVER == pNode->GetNodeType())
  441. ((CMainFrame *)AfxGetMainWnd())->AddKeyPackDialog((PLICSERVER)pNode->GetTreeObject());
  442. else
  443. {
  444. if(NODE_KEYPACK == pNode->GetNodeType())
  445. {
  446. CKeyPack * pKeyPack = (CKeyPack *)pNode->GetTreeObject();
  447. if(NULL == pKeyPack)
  448. return;
  449. ((CMainFrame *)AfxGetMainWnd())->AddKeyPackDialog(pKeyPack->GetServer());
  450. }
  451. }
  452. return;
  453. }
  454. void CLicMgrLeftView::OnDestroy()
  455. {
  456. //Get the Root Item
  457. HTREEITEM hRoot = GetTreeCtrl().GetRootItem();
  458. if(!hRoot)
  459. return;
  460. HTREEITEM hServerItem = GetTreeCtrl().GetNextItem(hRoot,TVGN_CHILD);
  461. while(hServerItem)
  462. {
  463. // Get the data attached to the tree item
  464. CTreeNode *pServerNode = (CTreeNode*)GetTreeCtrl().GetItemData(hServerItem);
  465. if(pServerNode)
  466. {
  467. // Is this the server we want to add
  468. HTREEITEM hKeyPackItem = GetTreeCtrl().GetNextItem(hServerItem,TVGN_CHILD);
  469. while(hKeyPackItem)
  470. {
  471. CTreeNode *pKeyPackNode = (CTreeNode*)GetTreeCtrl().GetItemData(hKeyPackItem);
  472. if(pKeyPackNode)
  473. delete pKeyPackNode;
  474. hKeyPackItem = GetTreeCtrl().GetNextItem(hKeyPackItem,TVGN_NEXT);
  475. }
  476. delete pServerNode;
  477. }
  478. hServerItem = GetTreeCtrl().GetNextItem(hServerItem, TVGN_NEXT);
  479. }
  480. CTreeNode * pRootNode = (CTreeNode*)GetTreeCtrl().GetItemData(hRoot);
  481. if(pRootNode)
  482. delete pRootNode;
  483. return;
  484. }
  485. LRESULT CLicMgrLeftView::OnDeleteServer(WPARAM wParam, LPARAM lParam)
  486. {
  487. LRESULT lResult = 0;
  488. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  489. ASSERT(pDoc);
  490. if(NULL == pDoc)
  491. return lResult;
  492. CLicServer *pServer = (CLicServer*)lParam;
  493. ASSERT(pServer);
  494. if(NULL == pServer)
  495. return lResult;
  496. HTREEITEM hServer = pServer->GetTreeItem();
  497. DBGMSG( L"CLicMgrLeftView_OnDeleteServer GetTreeItem ret 0x%x\n" , hServer );
  498. if(hServer == NULL)
  499. return lResult;
  500. CTreeNode *pNode = (CTreeNode*)GetTreeCtrl().GetItemData(hServer);
  501. DBGMSG( L"CLicMgrLeftView_OnDeleteServer GetItemData ret 0x%x\n" , pNode );
  502. if(pNode)
  503. delete pNode;
  504. GetTreeCtrl().DeleteItem(hServer);
  505. return lResult;
  506. } // OnDeleteServer
  507. LRESULT CLicMgrLeftView::OnUpdateServer(WPARAM wParam, LPARAM lParam)
  508. {
  509. LRESULT lResult = 0;
  510. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  511. ASSERT(pDoc);
  512. if(NULL == pDoc)
  513. return lResult;
  514. BOOL bIsExpanded = FALSE;
  515. BOOL bIsSelected = FALSE;
  516. BOOL bIsChild = FALSE;
  517. HTREEITEM hSelectedItem = NULL;
  518. CKeyPack * pSelectedPack = NULL;
  519. CLicServer *pServer = (CLicServer*)lParam;
  520. ASSERT(pServer);
  521. if(NULL == pServer)
  522. return lResult;
  523. HTREEITEM hServer = pServer->GetTreeItem();
  524. if(hServer == NULL)
  525. return lResult;
  526. // check to see if we need to remove any keypacks
  527. // Get a pointer to the server's list of installed KeyPacks
  528. // Get the data attached to the tree item
  529. CTreeNode *pServerNode = (CTreeNode*)GetTreeCtrl().GetItemData(hServer);
  530. if( pServerNode != NULL )
  531. {
  532. HTREEITEM hKeyPackItem = GetTreeCtrl().GetNextItem(hServer,TVGN_CHILD);
  533. while( hKeyPackItem != NULL )
  534. {
  535. CTreeNode *pKeyPackNode = (CTreeNode*)GetTreeCtrl().GetItemData(hKeyPackItem);
  536. if( pKeyPackNode != NULL )
  537. {
  538. DBGMSG( L"CLicMgrLeftView!OnUpdateServer removing a licpak\n" , 0 );
  539. delete pKeyPackNode;
  540. }
  541. hKeyPackItem = GetTreeCtrl().GetNextItem(hKeyPackItem,TVGN_NEXT);
  542. }
  543. delete pServerNode;
  544. }
  545. TV_ITEM Item;
  546. memset((void *)&Item,0,sizeof(Item));
  547. Item.mask = TVIF_HANDLE | TVIF_STATE;
  548. Item.hItem = hServer;
  549. if(FALSE == GetTreeCtrl().GetItem(&Item))
  550. return lResult;
  551. if(Item.state & TVIS_EXPANDED)
  552. bIsExpanded = TRUE;
  553. if(Item.state & TVIS_SELECTED)
  554. bIsSelected = TRUE;
  555. else
  556. hSelectedItem = GetTreeCtrl().GetSelectedItem();
  557. if(hSelectedItem)
  558. {
  559. if(hServer == GetTreeCtrl().GetParentItem(hSelectedItem))
  560. {
  561. CString ProdDesc = GetTreeCtrl().GetItemText(hSelectedItem);
  562. KeyPackList * pkeyPackList = pServer->GetKeyPackList();
  563. POSITION pos = pkeyPackList->GetHeadPosition();
  564. while(pos)
  565. {
  566. CKeyPack * pKeyPack = (CKeyPack *)pkeyPackList->GetNext(pos);
  567. if(NULL == pKeyPack)
  568. {
  569. continue;
  570. }
  571. LSKeyPack sKeyPack = pKeyPack->GetKeyPackStruct();
  572. if(0 == ProdDesc.CompareNoCase(sKeyPack.szProductDesc))
  573. {
  574. pSelectedPack = pKeyPack;
  575. break;
  576. }
  577. }
  578. bIsChild = TRUE;
  579. }
  580. }
  581. GetTreeCtrl().DeleteItem(hServer);
  582. SendMessage(WM_ADD_SERVER,0,(LPARAM)pServer);
  583. AddServerKeyPacks(pServer);
  584. hServer = pServer->GetTreeItem();
  585. if(bIsExpanded)
  586. GetTreeCtrl().Expand(hServer, TVE_EXPAND);
  587. if(bIsSelected)
  588. GetTreeCtrl().SelectItem(hServer);
  589. else
  590. {
  591. //Not good, find an alternative for this....
  592. if(bIsChild)
  593. {
  594. if(pSelectedPack)
  595. GetTreeCtrl().SelectItem(pSelectedPack->GetTreeItem());
  596. else
  597. {
  598. hSelectedItem = GetTreeCtrl().GetChildItem(hServer);
  599. if(hSelectedItem)
  600. GetTreeCtrl().SelectItem(hSelectedItem);
  601. }
  602. }
  603. }
  604. return lResult;
  605. } // OnUpdateServer
  606. void CLicMgrLeftView::SetSelection(LPARAM lParam,NODETYPE NodeType)
  607. {
  608. if(NULL == lParam)
  609. return;
  610. HTREEITEM hItem = NULL;
  611. if(NODE_ALL_SERVERS == NodeType)
  612. hItem = ((CAllServers *)lParam)->GetTreeItem();
  613. else if(NODE_SERVER == NodeType)
  614. hItem = ((CLicServer *)lParam)->GetTreeItem();
  615. else if(NODE_KEYPACK == NodeType)
  616. hItem = ((CKeyPack *)lParam)->GetTreeItem();
  617. if(hItem)
  618. GetTreeCtrl().SelectItem(hItem);
  619. return;
  620. }
  621. void CLicMgrLeftView::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
  622. {
  623. LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
  624. // TODO: Add your control notification handler code here
  625. if(pLVKeyDown->wVKey == VK_TAB)
  626. {
  627. CMainFrame * pMainFrame = ((CMainFrame *)AfxGetMainWnd());
  628. pMainFrame->SelectView(LISTVIEW);
  629. }
  630. *pResult = 0;
  631. }
  632. //-----------------------------------------------------------------------------------------
  633. afx_msg void CLicMgrLeftView::OnLeftClick(NMHDR* pNMHDR, LRESULT* pResult)
  634. {
  635. CPoint pt;
  636. GetCursorPos( &pt );
  637. ScreenToClient( &pt );
  638. DBGMSG( L"LICMGR@CLicMgrLeftView::OnLeftClick\n" , 0 );
  639. HTREEITEM hTreeItem = GetTreeCtrl( ).GetSelectedItem( ); //GetTreeCtrl().HitTest( pt , &flag );
  640. if( hTreeItem != NULL )
  641. {
  642. CTreeNode *pNode = (CTreeNode *)GetTreeCtrl().GetItemData(hTreeItem);
  643. if(NULL == pNode)
  644. {
  645. return;
  646. }
  647. ClientToScreen( &pt );
  648. NODETYPE nt = pNode->GetNodeType();
  649. if(NODE_SERVER == nt )
  650. {
  651. DBGMSG( L"\tServer Node selected\n", 0 );
  652. SetActiveServer( static_cast< CLicServer * >( pNode->GetTreeObject() ) );
  653. }
  654. else if( nt == NODE_KEYPACK )
  655. {
  656. CKeyPack *pKeyPack = static_cast< CKeyPack *>( pNode->GetTreeObject() );
  657. if( pKeyPack != NULL )
  658. {
  659. SetActiveServer( pKeyPack->GetServer( ) );
  660. }
  661. }
  662. else
  663. {
  664. #ifdef DBG
  665. if( NODE_ALL_SERVERS == nt )
  666. {
  667. DBGMSG( L"\tAll servers selected\n" , 0 );
  668. }
  669. #endif
  670. SetActiveServer( NULL );
  671. }
  672. }
  673. else
  674. {
  675. DBGMSG( L"\tTreeview item returned NULL\n" , 0 );
  676. SetActiveServer( NULL );
  677. }
  678. }
  679. //-----------------------------------------------------------------------------------------
  680. afx_msg void CLicMgrLeftView::OnContextMenu( CWnd* pWnd, CPoint pt )
  681. {
  682. CMenu menu;
  683. CMenu *pContextmenu = NULL;
  684. DBGMSG( L"LICMGR@CLicMgrLeftView::OnContextMenu\n" , 0 );
  685. DBGMSG( L"\tpoint x = %d " , pt.x );
  686. DBGMSG( L"y = %d\n" , pt.y );
  687. UINT flag;
  688. HTREEITEM hTreeItem;
  689. CTreeCtrl& treectrl = GetTreeCtrl();
  690. // maybe keyboard selected this item
  691. if(pt.x == -1 && pt.y == -1)
  692. {
  693. hTreeItem = treectrl.GetSelectedItem( );
  694. if( hTreeItem != NULL )
  695. {
  696. RECT rect;
  697. treectrl.GetItemRect( hTreeItem , &rect , FALSE );
  698. pt.x = rect.left + (rect.right - rect.left)/2;
  699. pt.y = rect.top + (rect.bottom - rect.top)/2;
  700. }
  701. }
  702. else
  703. {
  704. // otherwise we're invoked by the mouse
  705. ScreenToClient( &pt );
  706. hTreeItem = treectrl.HitTest( pt , &flag );
  707. }
  708. if( hTreeItem != NULL )
  709. {
  710. CTreeNode *pNode = (CTreeNode *)GetTreeCtrl().GetItemData(hTreeItem);
  711. if(NULL == pNode)
  712. {
  713. return;
  714. }
  715. SetRightClickedItem( hTreeItem );
  716. ClientToScreen( &pt );
  717. // GetTreeCtrl().SelectItem( hTreeItem );
  718. NODETYPE nt = pNode->GetNodeType();
  719. if(NODE_SERVER == nt )
  720. {
  721. DBGMSG( L"\tServer Node selected\n", 0 );
  722. menu.LoadMenu( IDR_MENU_LPK );
  723. pContextmenu = menu.GetSubMenu( 0 );
  724. }
  725. else if( NODE_KEYPACK == nt )
  726. {
  727. DBGMSG( L"\tLicense pack selected\n" , 0 );
  728. menu.LoadMenu( IDR_MENU_LPK );
  729. pContextmenu = menu.GetSubMenu( 1 );
  730. }
  731. else if( NODE_ALL_SERVERS == nt )
  732. {
  733. DBGMSG( L"\tAll servers selected\n" , 0 );
  734. menu.LoadMenu( IDR_MENU_LPK );
  735. pContextmenu = menu.GetSubMenu( 3 );
  736. }
  737. else
  738. {
  739. DBGMSG( L"\tIn left pane no item selected\n" , 0 );
  740. return;
  741. }
  742. UI_initmenu( pContextmenu , nt );
  743. if( pContextmenu != NULL )
  744. {
  745. pContextmenu->TrackPopupMenu( TPM_LEFTALIGN , pt.x , pt.y , this );
  746. }
  747. }
  748. else
  749. {
  750. hTreeItem = GetTreeCtrl( ).GetSelectedItem( );
  751. SetRightClickedItem( hTreeItem );
  752. }
  753. }
  754. //-----------------------------------------------------------------------------------------
  755. afx_msg void CLicMgrLeftView::OnRightClick(NMHDR* pNMHDR, LRESULT* pResult)
  756. {
  757. CPoint pt;
  758. CMenu menu;
  759. CMenu *pContextmenu = NULL;
  760. GetCursorPos( &pt );
  761. OnContextMenu( NULL , pt );
  762. return;
  763. }
  764. //-----------------------------------------------------------------------------------------
  765. void CLicMgrLeftView::UI_initmenu( CMenu *pMenu , NODETYPE nt )
  766. {
  767. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  768. if( pMainFrame != NULL )
  769. {
  770. pMainFrame->UI_initmenu( pMenu , nt );
  771. }
  772. }
  773. //-----------------------------------------------------------------------------------------
  774. void CLicMgrLeftView::OnServerConnect( )
  775. {
  776. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  777. if( pMainFrame != NULL )
  778. {
  779. pMainFrame->ConnectServer( );
  780. }
  781. }
  782. //-----------------------------------------------------------------------------------------
  783. void CLicMgrLeftView::OnRefreshAllServers( )
  784. {
  785. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  786. if( pMainFrame != NULL )
  787. {
  788. pMainFrame->OnRefresh( );
  789. }
  790. }
  791. //-----------------------------------------------------------------------------------------
  792. void CLicMgrLeftView::OnRefreshServer( )
  793. {
  794. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  795. CLicServer *pServer = NULL;
  796. if( pMainFrame != NULL )
  797. {
  798. CTreeNode *pNode = (CTreeNode *)GetTreeCtrl().GetItemData( GetRightClickedItem() );
  799. if( pNode == NULL )
  800. {
  801. return;
  802. }
  803. if( pNode->GetNodeType() == NODE_SERVER )
  804. {
  805. pServer = static_cast< CLicServer * >( pNode->GetTreeObject() );
  806. }
  807. else if( pNode->GetNodeType() == NODE_KEYPACK )
  808. {
  809. CKeyPack *pKeyPack = static_cast< CKeyPack *>( pNode->GetTreeObject() );
  810. if( pKeyPack != NULL )
  811. {
  812. pServer = pKeyPack->GetServer( );
  813. }
  814. }
  815. if( pServer != NULL )
  816. {
  817. pMainFrame->RefreshServer( pServer );
  818. }
  819. }
  820. }
  821. //-----------------------------------------------------------------------------------------
  822. void CLicMgrLeftView::OnDownloadKeepPack()
  823. {
  824. BOOL bRefresh = FALSE;
  825. DWORD dwStatus = WizardActionOnServer( WIZACTION_DOWNLOADLKP , &bRefresh );
  826. if( bRefresh )
  827. {
  828. // need to review this
  829. OnRefreshServer( );
  830. }
  831. DBGMSG( L"LICMGR : CLicMgrLeftView::OnDownloadKeepPack StartWizard returned 0x%x\n" , dwStatus );
  832. }
  833. //-----------------------------------------------------------------------------------------
  834. void CLicMgrLeftView::OnRegisterServer()
  835. {
  836. BOOL bRefresh;
  837. DWORD dwStatus = WizardActionOnServer( WIZACTION_REGISTERLS , &bRefresh );
  838. DBGMSG( L"LICMGR : CLicMgrLeftView::OnRegisterServer StartWizard returned 0x%x\n" , dwStatus );
  839. }
  840. //-----------------------------------------------------------------------------------------
  841. void CLicMgrLeftView::OnRepeatLastDownload()
  842. {
  843. BOOL bRefresh;
  844. DWORD dwStatus = WizardActionOnServer( WIZACTION_DOWNLOADLASTLKP , &bRefresh );
  845. DBGMSG( L"LICMGR : CLicMgrLeftView::OnRepeatLastDownload StartWizard returned 0x%x\n" , dwStatus );
  846. }
  847. //-----------------------------------------------------------------------------------------
  848. void CLicMgrLeftView::OnReactivateServer( )
  849. {
  850. BOOL bRefresh;
  851. DWORD dwStatus = WizardActionOnServer( WIZACTION_REREGISTERLS , &bRefresh );
  852. DBGMSG( L"LICMGR : CLicMgrLeftView::OnReactivateServer StartWizard returned 0x%x\n" , dwStatus );
  853. }
  854. //-----------------------------------------------------------------------------------------
  855. void CLicMgrLeftView::OnDeactivateServer( )
  856. {
  857. BOOL bRefresh;
  858. DWORD dwStatus = WizardActionOnServer( WIZACTION_UNREGISTERLS , &bRefresh );
  859. DBGMSG( L"LICMGR : CLicMgrLeftView::OnDeactivateServer StartWizard returned 0x%x\n" , dwStatus );
  860. }
  861. //-----------------------------------------------------------------------------------------
  862. void CLicMgrLeftView::OnServerProperties( )
  863. {
  864. BOOL bRefresh;
  865. DWORD dwStatus = WizardActionOnServer( WIZACTION_SHOWPROPERTIES , &bRefresh );
  866. DBGMSG( L"LICMGR : CLicMgrLeftView::OnServerProperties StartWizard returned 0x%x\n" , dwStatus );
  867. }
  868. //-----------------------------------------------------------------------------------------
  869. void CLicMgrLeftView::OnGeneralHelp( )
  870. {
  871. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  872. if( pMainFrame != NULL )
  873. {
  874. pMainFrame->OnHelp( );
  875. }
  876. }
  877. //-----------------------------------------------------------------------------------------
  878. DWORD CLicMgrLeftView::WizardActionOnServer( WIZACTION wa , PBOOL pbRefresh )
  879. {
  880. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  881. if( pMainFrame != NULL )
  882. {
  883. return pMainFrame->WizardActionOnServer( wa , pbRefresh , TREEVIEW );
  884. }
  885. return ERROR_INVALID_PARAMETER;
  886. }
  887. //-----------------------------------------------------------------------------------------
  888. void CLicMgrLeftView::SetActiveServer( CLicServer *pServer )
  889. {
  890. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  891. #ifdef DBG
  892. if( pServer != NULL )
  893. {
  894. DBGMSG( L"CLicMgrLeftView::SetActiveServer %s\n" , pServer->GetName( ) );
  895. }
  896. #endif
  897. if( pMainFrame != NULL )
  898. {
  899. pMainFrame->SetActiveServer( pServer );
  900. }
  901. }
  902. //-----------------------------------------------------------------------------------------
  903. void CLicMgrLeftView::SetRightClickedItem( HTREEITEM ht )
  904. {
  905. m_ht = ht;
  906. CTreeNode *pNode = (CTreeNode *)GetTreeCtrl().GetItemData(ht);
  907. if(NULL == pNode)
  908. {
  909. SetActiveServer( NULL );
  910. return;
  911. }
  912. NODETYPE nt = pNode->GetNodeType();
  913. if(NODE_SERVER == nt )
  914. {
  915. SetActiveServer( static_cast< CLicServer * >( pNode->GetTreeObject() ) );
  916. }
  917. else if( nt == NODE_KEYPACK )
  918. {
  919. CKeyPack *pKeyPack = static_cast< CKeyPack *>( pNode->GetTreeObject() );
  920. if( pKeyPack != NULL )
  921. {
  922. SetActiveServer( pKeyPack->GetServer( ) );
  923. }
  924. }
  925. else
  926. {
  927. SetActiveServer( NULL );
  928. }
  929. }