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.

2014 lines
51 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*++
  3. Module Name:
  4. RtList.cpp
  5. Abstract:
  6. This Module contains the implementation of CRightList class
  7. (The View class used for the Right 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 "LSServer.h"
  16. #include "RtList.h"
  17. #include "Mainfrm.h"
  18. #include "LSmgrdoc.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. extern int GetStatusPosition( CLicense *pLic );
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CRightList
  27. IMPLEMENT_DYNCREATE(CRightList, CListView)
  28. CRightList::CRightList()
  29. {
  30. }
  31. CRightList::~CRightList()
  32. {
  33. m_ImageListLarge.DeleteImageList();
  34. m_ImageListSmall.DeleteImageList();
  35. }
  36. BEGIN_MESSAGE_MAP(CRightList, CListView)
  37. //{{AFX_MSG_MAP(CRightList)
  38. ON_MESSAGE(WM_SEL_CHANGE, OnSelChange)
  39. ON_COMMAND(ID_LARGE_ICONS, OnLargeIcons)
  40. ON_COMMAND(ID_SMALL_ICONS, OnSmallIcons)
  41. ON_COMMAND(ID_LIST, OnList)
  42. ON_COMMAND(ID_DETAILS, OnDetails)
  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_KEYPACK, OnAddKeyPack)
  47. ON_COMMAND(ID_ADD_LICENSES, OnAddNewKeyPack)
  48. ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
  49. ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
  50. ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
  51. ON_NOTIFY_REFLECT(NM_CLICK , OnLeftClick )
  52. // server menuitems
  53. // all server menus
  54. ON_WM_CONTEXTMENU()
  55. // ON_COMMAND( ID_LPK_CONNECT , OnServerConnect )
  56. ON_COMMAND( ID_LPK_REFRESHALL , OnRefreshAllServers )
  57. // server menuitems
  58. // ON_COMMAND( ID_LPK_CONNECT , OnServerConnect )
  59. ON_COMMAND( ID_LPK_REFRESH , OnRefreshServer )
  60. ON_COMMAND( ID_LPK_REFRESHALL , OnRefreshAllServers )
  61. ON_COMMAND( ID_LPK_DOWNLOADLICENSES , OnDownloadKeepPack )
  62. ON_COMMAND( ID_SVR_ACTIVATESERVER , OnRegisterServer )
  63. ON_COMMAND( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , OnRepeatLastDownload )
  64. ON_COMMAND( ID_LPK_ADVANCED_REACTIVATESERVER , OnReactivateServer )
  65. ON_COMMAND( ID_LPK_ADVANCED_DEACTIVATESERVER , OnDeactivateServer )
  66. ON_COMMAND( ID_LPK_PROPERTIES , OnServerProperties )
  67. ON_COMMAND( ID_LPK_HELP , OnGeneralHelp )
  68. // license pak items
  69. // ON_COMMAND( ID_LICPAK_CONNECT , OnServerConnect )
  70. ON_COMMAND( ID_LICPAK_REFRESH , OnRefreshServer )
  71. // ON_COMMAND( ID_LICPAK_REFRESHALL , OnRefreshAllServers )
  72. ON_COMMAND( ID_LICPAK_DOWNLOADLICENSES , OnDownloadKeepPack )
  73. ON_COMMAND( ID_LICPAK_REPEATDOWNLOAD , OnRepeatLastDownload )
  74. ON_COMMAND( ID_LICPAK_HELP , OnGeneralHelp )
  75. // license pak items
  76. // license items
  77. /* removed from spec
  78. ON_COMMAND( ID_LIC_CONNECT , OnServerConnect )
  79. ON_COMMAND( ID_LIC_REFRESH , OnRefreshServer )
  80. ON_COMMAND( ID_LIC_DOWNLOADLICENSES , OnDownloadKeepPack )
  81. ON_COMMAND( ID_LIC_HELP , OnGeneralHelp )
  82. */
  83. //}}AFX_MSG_MAP
  84. END_MESSAGE_MAP()
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CRightList drawing
  87. void CRightList::OnDraw(CDC* pDC)
  88. {
  89. CDocument* pDoc = GetDocument();
  90. // TODO: add draw code here
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CRightList diagnostics
  94. #ifdef _DEBUG
  95. void CRightList::AssertValid() const
  96. {
  97. CListView::AssertValid();
  98. }
  99. void CRightList::Dump(CDumpContext& dc) const
  100. {
  101. CListView::Dump(dc);
  102. }
  103. #endif //_DEBUG
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CRightList message handlers
  106. LRESULT CRightList::OnSelChange(WPARAM wParam, LPARAM lParam)
  107. {
  108. LRESULT lResult = 0;
  109. BOOL bChangeColumns = FALSE;
  110. CLicMgrDoc * pDoc = (CLicMgrDoc *)GetDocument();
  111. ASSERT(pDoc);
  112. if(NULL == pDoc)
  113. return lResult;
  114. CLicServer * pLicServer = NULL;
  115. CKeyPack * pKeyPack = NULL;
  116. CListCtrl& ListCtrl = GetListCtrl();
  117. ListCtrl.DeleteAllItems();
  118. NODETYPE CurNodeType = ((CLicMgrDoc *)GetDocument())->GetNodeType();
  119. if(CurNodeType != (NODETYPE)wParam)
  120. {
  121. bChangeColumns = TRUE;
  122. pDoc->SetNodeType((NODETYPE)wParam);
  123. }
  124. switch(wParam)
  125. {
  126. case NODE_ALL_SERVERS:
  127. if(bChangeColumns)
  128. SetServerColumns();
  129. AddServerstoList();
  130. SetActiveServer( NULL );
  131. break;
  132. case NODE_SERVER:
  133. pLicServer = (CLicServer *)lParam;
  134. ASSERT(pLicServer);
  135. if(NULL == pLicServer)
  136. break;
  137. if(bChangeColumns)
  138. SetKeyPackColumns();
  139. /* if(FALSE == pLicServer->IsExpanded())
  140. {
  141. SetCursor(LoadCursor(NULL,IDC_WAIT));
  142. HRESULT hResult = pDoc->EnumerateKeyPacks(pLicServer,LSKEYPACK_SEARCH_LANGID, TRUE);
  143. if(hResult != S_OK)
  144. {
  145. ((CMainFrame *)AfxGetMainWnd())->EnumFailed(hResult,pLicServer);
  146. break;
  147. }
  148. }*/
  149. SetActiveServer( pLicServer );
  150. AddKeyPackstoList((CLicServer *)lParam);
  151. SetCursor(LoadCursor(NULL,IDC_ARROW));
  152. break;
  153. case NODE_KEYPACK:
  154. pKeyPack = (CKeyPack *)lParam;
  155. ASSERT(pKeyPack);
  156. if(NULL == pKeyPack)
  157. break;
  158. if(bChangeColumns)
  159. SetLicenseColumns();
  160. /*if(FALSE == pKeyPack->IsExpanded())
  161. {
  162. SetCursor(LoadCursor(NULL,IDC_WAIT));
  163. HRESULT hResult = pDoc->EnumerateLicenses(pKeyPack,LSLICENSE_SEARCH_KEYPACKID, TRUE);
  164. if(hResult != S_OK)
  165. {
  166. ((CMainFrame *)AfxGetMainWnd())->EnumFailed(hResult,pKeyPack->GetServer());
  167. break;
  168. }
  169. }*/
  170. SetActiveServer( pKeyPack->GetServer( ) );
  171. ((CMainFrame *)AfxGetMainWnd())->AddLicensestoList(
  172. (CKeyPack *)lParam,
  173. &ListCtrl,
  174. FALSE
  175. );
  176. SetCursor(LoadCursor(NULL,IDC_ARROW));
  177. break;
  178. }
  179. return lResult;
  180. }
  181. HRESULT CRightList::AddServerstoList()
  182. {
  183. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  184. ASSERT(pDoc);
  185. if(NULL == pDoc)
  186. {
  187. return E_FAIL;
  188. }
  189. //Get the List Control
  190. CListCtrl& ListCtrl = GetListCtrl();
  191. CString TempString;
  192. CString StatusString;
  193. LicServerList * licserverlist = NULL;
  194. int nIndex = 0;
  195. CAllServers *pAllServer = pDoc->GetAllServers();
  196. if(NULL == pAllServer)
  197. {
  198. goto cleanup;
  199. }
  200. licserverlist = pAllServer->GetLicServerList();
  201. LV_ITEM lvI;
  202. lvI.mask = LVIF_TEXT |LVIF_IMAGE |LVIF_STATE | LVIF_PARAM;
  203. lvI.state = 0;
  204. lvI.stateMask =0;
  205. // lvI.iImage = 0;
  206. POSITION pos;
  207. pos = licserverlist->GetHeadPosition();
  208. while(pos)
  209. {
  210. //Display the Server Name
  211. DWORD dwServerStatus;
  212. lvI.iItem = nIndex;
  213. lvI.iSubItem = 0;
  214. CLicServer * pLicServer = licserverlist->GetNext(pos);
  215. lvI.lParam = (LPARAM)pLicServer;
  216. TempString = pLicServer->GetName();
  217. lvI.pszText = TempString.GetBuffer(TempString.GetLength());
  218. lvI.cchTextMax =lstrlen(lvI.pszText + 1);
  219. dwServerStatus = pLicServer->GetServerRegistrationStatus();
  220. if(pLicServer->GetServerType() == SERVER_TS5_ENFORCED)
  221. {
  222. if( dwServerStatus == LSERVERSTATUS_REGISTER_INTERNET
  223. ||
  224. dwServerStatus == LSERVERSTATUS_REGISTER_OTHER )
  225. {
  226. StatusString.LoadString(IDS_SERVER_REGISTERED);
  227. lvI.iImage = 3;
  228. }
  229. else if( dwServerStatus == LSERVERSTATUS_WAITFORPIN )
  230. {
  231. StatusString.LoadString(IDS_SERVER_WAITFORPIN);
  232. lvI.iImage = 4;
  233. }
  234. else if( dwServerStatus == LSERVERSTATUS_UNREGISTER )
  235. {
  236. lvI.iImage = 5;
  237. StatusString.LoadString(IDS_SERVER_UNREGISTER);
  238. }
  239. else
  240. {
  241. lvI.iImage = 6;
  242. StatusString.LoadString( IDS_UNKNOWN );
  243. }
  244. }
  245. else
  246. {
  247. StatusString.LoadString(IDS_SERVER_NOTREQUIRE);
  248. lvI.iImage = 0;
  249. }
  250. //
  251. // Display registration status
  252. //
  253. nIndex = ListCtrl.InsertItem(&lvI);
  254. // ListCtrl.SetItemText(nIndex,1,(LPCTSTR)pLicServer->GetScope());
  255. ListCtrl.SetItemText(nIndex, 1, (LPCTSTR)StatusString);
  256. nIndex ++;
  257. }
  258. ListCtrl.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  259. cleanup:
  260. return S_OK;
  261. }
  262. //----------------------------------------------------------------------
  263. HRESULT
  264. CRightList::AddKeyPackstoList(
  265. CLicServer * pServer,
  266. BOOL bRefresh
  267. )
  268. /*++
  269. Abstract:
  270. Parameter:
  271. bRefresh : TRUE if refresh licenses, FALSE otherwise.
  272. --*/
  273. {
  274. ASSERT(pServer);
  275. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  276. ASSERT(pDoc);
  277. if(NULL == pDoc || NULL == pServer)
  278. {
  279. return E_FAIL;
  280. }
  281. CListCtrl& ListCtrl = GetListCtrl();
  282. ULONG nIndex = 0;
  283. POSITION pos;
  284. int nSubItemIndex = 1;
  285. CString TempString;
  286. DWORD dwLicenses = 0;
  287. if(bRefresh == TRUE)
  288. {
  289. if(pServer->RefreshCachedKeyPack() != S_OK)
  290. {
  291. return E_FAIL;
  292. }
  293. }
  294. KeyPackList * keypacklist = pServer->GetKeyPackList();
  295. ULONG nNumKeyPacks = (ULONG)keypacklist->GetCount();
  296. if(0 == nNumKeyPacks)
  297. {
  298. goto cleanup;
  299. }
  300. pos = keypacklist->GetHeadPosition();
  301. for(nIndex = 0; nIndex < nNumKeyPacks; nIndex++)
  302. {
  303. CKeyPack * pKeyPack = keypacklist->GetNext(pos);
  304. if(NULL == pKeyPack)
  305. {
  306. continue;
  307. }
  308. AddKeyPack(ListCtrl, nIndex, pKeyPack);
  309. }
  310. ListCtrl.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  311. cleanup:
  312. return S_OK;
  313. }
  314. HRESULT CRightList::SetServerColumns()
  315. {
  316. CListCtrl& ListCtrl = GetListCtrl();
  317. for(int index = 0; index < MAX_COLUMNS; index++)
  318. {
  319. ListCtrl.DeleteColumn(0);
  320. }
  321. LV_COLUMN lvC;
  322. CString ColumnText;
  323. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
  324. lvC.fmt = LVCFMT_LEFT;
  325. lvC.cx = 125;
  326. for(index = 0; index < NUM_SERVER_COLUMNS; index ++)
  327. {
  328. lvC.iSubItem = index;
  329. ColumnText.LoadString(IDS_SERVER_COLUMN1 + index);
  330. lvC.pszText = ColumnText.GetBuffer(ColumnText.GetLength());
  331. GetListCtrl().InsertColumn(index, &lvC);
  332. }
  333. return S_OK;
  334. }
  335. HRESULT CRightList::SetKeyPackColumns()
  336. {
  337. CListCtrl& ListCtrl = GetListCtrl();
  338. for(int index = 0; index < MAX_COLUMNS; index++)
  339. {
  340. ListCtrl.DeleteColumn(0);
  341. }
  342. LV_COLUMN lvC;
  343. CString ColumnText;
  344. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
  345. lvC.fmt = LVCFMT_LEFT;
  346. lvC.cx = KEYPACK_DISPNAME_WIDTH;
  347. for(index = 0; index < NUM_KEYPACK_COLUMNS; index ++)
  348. {
  349. lvC.iSubItem = index;
  350. ColumnText.LoadString(IDS_KEYPACK_COLUMN1 + index);
  351. lvC.pszText = ColumnText.GetBuffer(ColumnText.GetLength());
  352. ListCtrl.InsertColumn(index, &lvC);
  353. lvC.cx = KEYPACK_OTHERS_WIDTH;
  354. }
  355. return S_OK;
  356. }
  357. HRESULT CRightList::SetLicenseColumns()
  358. {
  359. CListCtrl& ListCtrl = GetListCtrl();
  360. for(int index = 0; index < MAX_COLUMNS; index++)
  361. {
  362. ListCtrl.DeleteColumn(0);
  363. }
  364. LV_COLUMN lvC;
  365. CString ColumnText;
  366. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
  367. lvC.fmt = LVCFMT_LEFT;
  368. lvC.cx = 125;
  369. for(index = 0; index < NUM_LICENSE_COLUMNS; index ++)
  370. {
  371. lvC.iSubItem = index;
  372. ColumnText.LoadString(IDS_LICENSE_COLUMN1 + index);
  373. lvC.pszText = ColumnText.GetBuffer(ColumnText.GetLength());
  374. ListCtrl.InsertColumn(index, &lvC);
  375. }
  376. return S_OK;
  377. }
  378. void CRightList::OnInitialUpdate()
  379. {
  380. CListView::OnInitialUpdate();
  381. CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
  382. ASSERT(pMainFrame);
  383. if(NULL == pMainFrame)
  384. return;
  385. //Create and set the image lists
  386. m_ImageListSmall.Create( SM_BITMAP_WIDTH,SM_BITMAP_HEIGHT,TRUE, 7, 7);
  387. m_ImageListLarge.Create( LG_BITMAP_WIDTH,LG_BITMAP_HEIGHT,TRUE, 7, 7);
  388. HICON hIcon = NULL;
  389. DWORD rgdwIDs[] = { IDI_SERVER , IDI_KEYPACK , IDI_LICENSE , IDI_SERVERREG , IDI_SERVERM , IDI_SERVERX , IDI_SERVERQ , (DWORD)-1 };
  390. int index = 0;
  391. while( rgdwIDs[ index ] != ( DWORD )-1 )
  392. {
  393. hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE( rgdwIDs[ index ] ) );
  394. if (NULL == hIcon)
  395. {
  396. ASSERT(!"LoadIcon Failed");
  397. continue;
  398. }
  399. m_ImageListSmall.Add(hIcon);
  400. m_ImageListLarge.Add(hIcon);
  401. /*
  402. if ((m_ImageListSmall.Add(hIcon) == -1) || (m_ImageListLarge.Add(hIcon) == -1))
  403. {
  404. continue;
  405. }
  406. }
  407. */
  408. ++index;
  409. }
  410. GetListCtrl().SetImageList(&m_ImageListSmall,LVSIL_SMALL);
  411. GetListCtrl().SetImageList(&m_ImageListLarge,LVSIL_NORMAL);
  412. //Set the style
  413. GetListCtrl().ModifyStyle(0,LVS_REPORT | LVS_AUTOARRANGE | LVS_SINGLESEL | LVS_SORTASCENDING,0);
  414. GetListCtrl().SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE , LVS_EX_FULLROWSELECT , LVS_EX_FULLROWSELECT );
  415. //Select details view by default
  416. CMenu *pMenu = pMainFrame->GetMenu();
  417. if(pMenu)
  418. pMenu->CheckMenuRadioItem(ID_DETAILS,ID_LIST, ID_DETAILS,MF_BYCOMMAND);
  419. pMainFrame->PressButton(ID_DETAILS,TRUE);
  420. //Display the server
  421. pMainFrame->ConnectAndDisplay();
  422. }
  423. void CRightList::OnLargeIcons()
  424. {
  425. // TODO: Add your command handler code here
  426. CListCtrl &ListCtrl = GetListCtrl();
  427. ListCtrl.ModifyStyle(LVS_LIST|LVS_REPORT | LVS_SMALLICON,LVS_ICON,0);
  428. CMenu *pMenu = AfxGetMainWnd()->GetMenu();
  429. if(pMenu)
  430. pMenu->CheckMenuRadioItem(ID_LARGE_ICONS,ID_LIST,ID_LARGE_ICONS,MF_BYCOMMAND);
  431. CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
  432. ASSERT(pMainFrame);
  433. if(NULL == pMainFrame)
  434. return;
  435. pMainFrame->PressButton(ID_LARGE_ICONS,TRUE);
  436. pMainFrame->PressButton(ID_SMALL_ICONS,FALSE);
  437. pMainFrame->PressButton(ID_LIST,FALSE);
  438. pMainFrame->PressButton(ID_DETAILS,FALSE);
  439. return;
  440. }
  441. void CRightList::OnSmallIcons()
  442. {
  443. // TODO: Add your command handler code here
  444. CListCtrl &ListCtrl = GetListCtrl();
  445. ListCtrl.ModifyStyle(LVS_LIST|LVS_ICON | LVS_REPORT,LVS_SMALLICON,0);
  446. CMenu *pMenu = AfxGetMainWnd()->GetMenu();
  447. if(pMenu)
  448. pMenu->CheckMenuRadioItem(ID_LARGE_ICONS,ID_LIST,ID_SMALL_ICONS,MF_BYCOMMAND);
  449. CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
  450. ASSERT(pMainFrame);
  451. if(NULL == pMainFrame)
  452. return;
  453. pMainFrame->PressButton(ID_LARGE_ICONS,FALSE);
  454. pMainFrame->PressButton(ID_SMALL_ICONS,TRUE);
  455. pMainFrame->PressButton(ID_LIST,FALSE);
  456. pMainFrame->PressButton(ID_DETAILS,FALSE);
  457. return;
  458. }
  459. void CRightList::OnList()
  460. {
  461. // TODO: Add your command handler code here
  462. CListCtrl &ListCtrl = GetListCtrl();
  463. ListCtrl.ModifyStyle(LVS_REPORT|LVS_ICON | LVS_SMALLICON,LVS_LIST,0);
  464. CMenu *pMenu = AfxGetMainWnd()->GetMenu();
  465. if(pMenu)
  466. pMenu->CheckMenuRadioItem(ID_LARGE_ICONS,ID_LIST,ID_LIST,MF_BYCOMMAND);
  467. CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
  468. ASSERT(pMainFrame);
  469. if(NULL == pMainFrame)
  470. return;
  471. pMainFrame->PressButton(ID_LARGE_ICONS,FALSE);
  472. pMainFrame->PressButton(ID_SMALL_ICONS,FALSE);
  473. pMainFrame->PressButton(ID_LIST,TRUE);
  474. pMainFrame->PressButton(ID_DETAILS,FALSE);
  475. return;
  476. }
  477. void CRightList::OnDetails()
  478. {
  479. // TODO: Add your command handler code here
  480. CListCtrl &ListCtrl = GetListCtrl();
  481. ListCtrl.ModifyStyle(LVS_LIST|LVS_ICON | LVS_SMALLICON,LVS_REPORT,0);
  482. CMenu *pMenu = AfxGetMainWnd()->GetMenu();
  483. if(pMenu)
  484. pMenu->CheckMenuRadioItem(ID_LARGE_ICONS,ID_LIST,ID_DETAILS,MF_BYCOMMAND);
  485. CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
  486. ASSERT(pMainFrame);
  487. if(NULL == pMainFrame)
  488. return;
  489. pMainFrame->PressButton(ID_LARGE_ICONS,FALSE);
  490. pMainFrame->PressButton(ID_SMALL_ICONS,FALSE);
  491. pMainFrame->PressButton(ID_LIST,FALSE);
  492. pMainFrame->PressButton(ID_DETAILS,TRUE);
  493. return;
  494. }
  495. LRESULT CRightList::OnAddServer(WPARAM wParam, LPARAM lParam)
  496. {
  497. LRESULT lResult = 0;
  498. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  499. ASSERT(pDoc);
  500. if(NULL == pDoc)
  501. {
  502. return lResult;
  503. }
  504. if(NODE_ALL_SERVERS != pDoc->GetNodeType())
  505. {
  506. return lResult;
  507. }
  508. CListCtrl& ListCtrl = GetListCtrl();
  509. CLicServer *pServer = (CLicServer*)lParam;
  510. ASSERT(pServer);
  511. if(NULL == pServer)
  512. {
  513. return lResult;
  514. }
  515. LV_ITEM lvI;
  516. lvI.iImage = 0;
  517. if( pServer->GetServerType() == SERVER_TS5_ENFORCED )
  518. {
  519. DWORD dwStatus = pServer->GetServerRegistrationStatus( );
  520. if( dwStatus == LSERVERSTATUS_REGISTER_INTERNET || dwStatus == LSERVERSTATUS_REGISTER_OTHER )
  521. {
  522. lvI.iImage = 3;
  523. }
  524. else if( dwStatus == LSERVERSTATUS_WAITFORPIN )
  525. {
  526. lvI.iImage = 4;
  527. }
  528. else if( dwStatus == LSERVERSTATUS_UNREGISTER )
  529. {
  530. lvI.iImage = 5;
  531. }
  532. else
  533. {
  534. lvI.iImage = 6;
  535. }
  536. }
  537. CString Name;
  538. int nIndex = GetListCtrl().GetItemCount();
  539. // Insert Server Name;
  540. lvI.mask = LVIF_TEXT |LVIF_IMAGE |LVIF_STATE | LVIF_PARAM;
  541. lvI.state = 0;
  542. lvI.stateMask =0;
  543. lvI.iSubItem = 0;
  544. //lvI.iImage = 0;
  545. lvI.iItem = nIndex;
  546. lvI.lParam = (LPARAM)pServer;
  547. Name = pServer->GetName();
  548. lvI.pszText = Name.GetBuffer(Name.GetLength());
  549. lvI.cchTextMax =lstrlen(lvI.pszText + 1);
  550. nIndex = ListCtrl.InsertItem(&lvI);
  551. //Insert Server Scope
  552. //ListCtrl.SetItemText(nIndex,1,pServer->GetScope());
  553. CString TempString;
  554. if(pServer->GetServerType() == SERVER_TS5_ENFORCED)
  555. {
  556. if(pServer->GetServerRegistrationStatus() == LSERVERSTATUS_REGISTER_INTERNET
  557. ||
  558. pServer->GetServerRegistrationStatus() == LSERVERSTATUS_REGISTER_OTHER )
  559. {
  560. VERIFY(TempString.LoadString(IDS_SERVER_REGISTERED) == TRUE);
  561. }
  562. else if( pServer->GetServerRegistrationStatus() == LSERVERSTATUS_WAITFORPIN )
  563. {
  564. VERIFY(TempString.LoadString(IDS_SERVER_WAITFORPIN) == TRUE);
  565. }
  566. else if( pServer->GetServerRegistrationStatus() == LSERVERSTATUS_UNREGISTER )
  567. {
  568. VERIFY(TempString.LoadString(IDS_SERVER_UNREGISTER) == TRUE);
  569. }
  570. else
  571. {
  572. VERIFY(TempString.LoadString(IDS_UNKNOWN ) == TRUE);
  573. }
  574. }
  575. else
  576. {
  577. VERIFY(TempString.LoadString(IDS_SERVER_NOTREQUIRE) == TRUE);
  578. }
  579. ListCtrl.SetItemText(nIndex, 1, (LPCTSTR)TempString);
  580. if(nIndex == 0)
  581. {
  582. ListCtrl.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  583. }
  584. return lResult;
  585. } // OnAddServer
  586. LRESULT CRightList::OnAddKeyPack(WPARAM wParam, LPARAM lParam)
  587. {
  588. LRESULT lResult = 0;
  589. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  590. ASSERT(pDoc);
  591. if(NULL == pDoc)
  592. return lResult;
  593. if(NODE_SERVER != pDoc->GetNodeType())
  594. return lResult;
  595. CListCtrl& ListCtrl = GetListCtrl();
  596. int nIndex = ListCtrl.GetItemCount();
  597. CKeyPack *pKeyPack = (CKeyPack*)lParam;
  598. ASSERT(pKeyPack);
  599. if(NULL == pKeyPack)
  600. return lResult;
  601. AddKeyPack(ListCtrl,nIndex,pKeyPack);
  602. if(nIndex == 0)
  603. ListCtrl.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  604. return lResult;
  605. } // OnAddKeyPack
  606. void CRightList::OnAddNewKeyPack()
  607. {
  608. // TODO: Add your command handler code here
  609. HRESULT hResult = ERROR_SUCCESS;
  610. CListCtrl& listctrl = GetListCtrl();
  611. CLicMgrDoc * pDoc = (CLicMgrDoc *)GetDocument();
  612. ASSERT(pDoc);
  613. if(NULL == pDoc)
  614. return;
  615. //Get the selected item
  616. int nSelected = listctrl.GetNextItem(-1, LVNI_SELECTED);
  617. if(-1 == nSelected)
  618. {
  619. if(NODE_SERVER == pDoc->GetNodeType())
  620. hResult = ((CMainFrame *)AfxGetMainWnd())->AddKeyPackDialog(NULL);
  621. return;
  622. }
  623. //Get the Data associated with the item.
  624. #ifdef _WIN64
  625. DWORD_PTR dCurrSel;
  626. #else
  627. DWORD dCurrSel;
  628. #endif
  629. dCurrSel = listctrl.GetItemData(nSelected);
  630. if(LB_ERR == dCurrSel)
  631. return;
  632. pDoc =(CLicMgrDoc *)GetDocument();
  633. ASSERT(pDoc);
  634. if(NULL == pDoc)
  635. return;
  636. if(NODE_ALL_SERVERS == pDoc->GetNodeType())
  637. hResult = ((CMainFrame *)AfxGetMainWnd())->AddKeyPackDialog((PLICSERVER)dCurrSel);
  638. else
  639. {
  640. if(NODE_SERVER == pDoc->GetNodeType())
  641. {
  642. CKeyPack * pKeyPack = (CKeyPack *)dCurrSel;
  643. if(NULL == pKeyPack)
  644. return;
  645. hResult = ((CMainFrame *)AfxGetMainWnd())->AddKeyPackDialog(pKeyPack->GetServer());
  646. }
  647. }
  648. return;
  649. }
  650. void CRightList::AddKeyPack(CListCtrl& ListCtrl,int nIndex, CKeyPack * pKeyPack)
  651. {
  652. if(NULL == pKeyPack)
  653. {
  654. return;
  655. }
  656. LSKeyPack sKeyPack;
  657. int nSubItemIndex = 1;
  658. DWORD dwLicenses = 0;
  659. CLicMgrDoc * pDoc = (CLicMgrDoc *)GetDocument();
  660. ASSERT(pDoc);
  661. if(NULL == pDoc)
  662. {
  663. return;
  664. }
  665. CString TempString;
  666. DWORD dwIssuedLicenses = 0;
  667. LV_ITEM lvI;
  668. lvI.mask = LVIF_TEXT |LVIF_IMAGE |LVIF_STATE | LVIF_PARAM;
  669. lvI.state = 0;
  670. lvI.stateMask =0;
  671. lvI.iItem = 0;
  672. lvI.iSubItem = 0;
  673. lvI.iImage = 1;
  674. lvI.iItem = nIndex;
  675. lvI.lParam = (LPARAM)pKeyPack;
  676. TempString = pKeyPack->GetDisplayName();
  677. lvI.pszText = TempString.GetBuffer(TempString.GetLength());
  678. lvI.cchTextMax =lstrlen(lvI.pszText + 1);
  679. nIndex = ListCtrl.InsertItem(&lvI);
  680. sKeyPack = pKeyPack->GetKeyPackStruct();
  681. //Set the KeyPack Type.
  682. if(NUM_KEYPACK_TYPE <= sKeyPack.ucKeyPackType)
  683. {
  684. TempString.LoadString(IDS_LSKEYPACKTYPE_UNKNOWN );
  685. }
  686. else
  687. {
  688. if(LSKEYPACKTYPE_FREE == sKeyPack.ucKeyPackType)
  689. {
  690. TempString.LoadString(IDS_LSKEYPACKTYPE_FREE );
  691. }
  692. else
  693. {
  694. TempString.LoadString(IDS_LSKEYPACKTYPE_UNKNOWN+ sKeyPack.ucKeyPackType);
  695. }
  696. }
  697. ListCtrl.SetItemText(nIndex,nSubItemIndex,(LPCTSTR)TempString);
  698. nSubItemIndex++;
  699. //Set the Activation date, Now called Registered on
  700. #ifdef SPANISH
  701. if(LSKEYPACKTYPE_TEMPORARY != sKeyPack.ucKeyPackType)
  702. {
  703. TempString = pDoc->TimeToString(&sKeyPack.dwActivateDate);
  704. if(TempString.IsEmpty())
  705. {
  706. TempString.LoadString(IDS_UNKNOWN);
  707. }
  708. }
  709. else
  710. {
  711. TempString.LoadString(IDS_DASH);
  712. }
  713. ListCtrl.SetItemText(nIndex,nSubItemIndex,(LPCTSTR)TempString);
  714. nSubItemIndex++;
  715. #endif
  716. //Set Total licenses.
  717. //
  718. // HueiWang 7/7/98 - per marketing request
  719. //
  720. if(LSKEYPACKTYPE_TEMPORARY == sKeyPack.ucKeyPackType)
  721. {
  722. TempString.LoadString(IDS_DASH);
  723. }
  724. else
  725. {
  726. if(LSKEYPACKTYPE_FREE == sKeyPack.ucKeyPackType)
  727. {
  728. TempString.LoadString(IDS_UNLIMITED);
  729. }
  730. else
  731. {
  732. TempString.Format(_T("%d"),sKeyPack.dwTotalLicenseInKeyPack);
  733. }
  734. }
  735. ListCtrl.SetItemText(nIndex,nSubItemIndex,(LPCTSTR)TempString);
  736. nSubItemIndex++;
  737. //Set Available licenses.
  738. if(LSKEYPACKTYPE_TEMPORARY == sKeyPack.ucKeyPackType)
  739. {
  740. TempString.LoadString(IDS_DASH);
  741. }
  742. else
  743. {
  744. if( LSKEYPACKSTATUS_RETURNED == sKeyPack.ucKeyPackStatus ||
  745. LSKEYPACKSTATUS_REVOKED == sKeyPack.ucKeyPackStatus )
  746. {
  747. TempString.Format(_T("%d"), 0);
  748. }
  749. else if(LSKEYPACKTYPE_FREE == sKeyPack.ucKeyPackType)
  750. {
  751. TempString.LoadString(IDS_UNLIMITED);
  752. }
  753. else
  754. {
  755. TempString.Format(_T("%d"),sKeyPack.dwNumberOfLicenses);
  756. }
  757. }
  758. ListCtrl.SetItemText(nIndex,nSubItemIndex,(LPCTSTR)TempString);
  759. nSubItemIndex++;
  760. //Set Issued licenses.
  761. if(LSKEYPACKTYPE_TEMPORARY == sKeyPack.ucKeyPackType ||
  762. LSKEYPACKTYPE_FREE == sKeyPack.ucKeyPackType )
  763. {
  764. dwLicenses = sKeyPack.dwNumberOfLicenses;
  765. }
  766. else
  767. {
  768. dwLicenses = sKeyPack.dwTotalLicenseInKeyPack - sKeyPack.dwNumberOfLicenses;
  769. }
  770. TempString.Format(_T("%d"),dwLicenses);
  771. ListCtrl.SetItemText(nIndex,nSubItemIndex,(LPCTSTR)TempString);
  772. nSubItemIndex++;
  773. TempString.Empty( );
  774. switch( sKeyPack.ucKeyPackStatus )
  775. {
  776. case LSKEYPACKSTATUS_UNKNOWN:
  777. TempString.LoadString( IDS_KEYPACKSTATUS_UNKNOWN );
  778. break;
  779. case LSKEYPACKSTATUS_TEMPORARY:
  780. TempString.LoadString( IDS_KEYPACKSTATUS_TEMPORARY );
  781. break;
  782. case LSKEYPACKSTATUS_ACTIVE:
  783. case LSKEYPACKSTATUS_PENDING:
  784. //case LSKEYPACKSTATUS_RESTORE:
  785. TempString.LoadString( IDS_KEYPACKSTATUS_ACTIVE );
  786. break;
  787. case LSKEYPACKSTATUS_RETURNED:
  788. TempString.LoadString( IDS_KEYPACKSTATUS_RETURNED );
  789. break;
  790. case LSKEYPACKSTATUS_REVOKED:
  791. TempString.LoadString( IDS_KEYPACKSTATUS_REVOKED );
  792. break;
  793. }
  794. if( TempString.IsEmpty() )
  795. {
  796. TempString.LoadString(IDS_UNKNOWN);
  797. }
  798. ListCtrl.SetItemText(nIndex,nSubItemIndex,(LPCTSTR)TempString);
  799. return;
  800. }
  801. LRESULT CRightList::OnDeleteServer(WPARAM wParam, LPARAM lParam)
  802. {
  803. LRESULT lResult = 0;
  804. DBGMSG( L"CRightList_OnDeleteServer\n" , 0 );
  805. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  806. ASSERT(pDoc);
  807. if(NULL == pDoc)
  808. return lResult;
  809. CLicServer *pServer = (CLicServer*)lParam;
  810. ASSERT(pServer);
  811. if(NULL == pServer)
  812. return lResult;
  813. CListCtrl& ListCtrl = GetListCtrl();
  814. if(0 == ListCtrl.GetItemCount())
  815. return lResult;
  816. int nIndex = 0;
  817. CKeyPack * pKeyPack = NULL;
  818. LV_ITEM Item;
  819. ZeroMemory((LPVOID)&Item,sizeof(Item));
  820. switch(pDoc->GetNodeType())
  821. {
  822. case NODE_ALL_SERVERS:
  823. DBGMSG( L"\tNODE_ALL_SERVERS\n",0 );
  824. LV_FINDINFO FindInfo;
  825. FindInfo.flags = LVFI_PARAM;
  826. FindInfo.psz = NULL;
  827. FindInfo.lParam = (LPARAM)pServer;
  828. nIndex = ListCtrl.FindItem(&FindInfo);
  829. if(-1 == nIndex)
  830. return lResult;
  831. ListCtrl.DeleteItem(nIndex);
  832. break;
  833. case NODE_SERVER:
  834. DBGMSG( L"\tNODE_SERVER\n",0 );
  835. Item.iItem = 0;
  836. Item.mask = LVIF_PARAM;
  837. nIndex = ListCtrl.GetItem(&Item);
  838. if(-1 == nIndex)
  839. break;
  840. pKeyPack = (CKeyPack *)Item.lParam;
  841. if(NULL == pKeyPack)
  842. break;
  843. if(pServer == pKeyPack->GetServer())
  844. ListCtrl.DeleteAllItems();
  845. break;
  846. case NODE_KEYPACK:
  847. DBGMSG( L"\tNODE_KEYPACK\n",0 );
  848. Item.iItem = 0;
  849. Item.mask = LVIF_PARAM;
  850. nIndex = ListCtrl.GetItem(&Item);
  851. if(-1 == nIndex)
  852. break;
  853. CLicense * pLicense = (CLicense *)Item.lParam;
  854. if(NULL == pLicense)
  855. break;
  856. pKeyPack = pLicense->GetKeyPack();
  857. if(NULL == pKeyPack)
  858. break;
  859. if(pServer == pKeyPack->GetServer())
  860. ListCtrl.DeleteAllItems();
  861. break;
  862. }
  863. return lResult;
  864. } // OnDeleteServer
  865. LRESULT CRightList::OnUpdateServer(WPARAM wParam, LPARAM lParam)
  866. {
  867. LRESULT lResult = 0;
  868. int item;
  869. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  870. ASSERT(pDoc);
  871. if(NULL == pDoc)
  872. {
  873. return lResult;
  874. }
  875. CLicServer *pServer = (CLicServer*)lParam;
  876. ASSERT(pServer);
  877. if(NULL == pServer)
  878. {
  879. return lResult;
  880. }
  881. CListCtrl& ListCtrl = GetListCtrl();
  882. if(0 == ListCtrl.GetItemCount())
  883. {
  884. return lResult;
  885. }
  886. int nIndex = 0;
  887. CKeyPack * pKeyPack = NULL;
  888. LV_ITEM Item;
  889. ZeroMemory((LPVOID)&Item,sizeof(Item));
  890. Item.mask = LVIF_IMAGE;
  891. switch(pDoc->GetNodeType())
  892. {
  893. case NODE_ALL_SERVERS:
  894. // HUEIHUEI : Find the server and update its status
  895. if(ListCtrl.GetSelectedCount() > 1)
  896. {
  897. break;
  898. }
  899. for( item = 0; item < ListCtrl.GetItemCount( ); ++item )
  900. {
  901. if( ListCtrl.GetItemState( item , LVNI_SELECTED ) != LVNI_SELECTED )
  902. {
  903. continue;
  904. }
  905. // update status of registration
  906. CString TempString;
  907. if(pServer->GetServerType() == SERVER_TS5_ENFORCED)
  908. {
  909. if(pServer->GetServerRegistrationStatus() == LSERVERSTATUS_REGISTER_INTERNET
  910. ||
  911. pServer->GetServerRegistrationStatus() == LSERVERSTATUS_REGISTER_OTHER )
  912. {
  913. TempString.LoadString(IDS_SERVER_REGISTERED);
  914. Item.iImage = 3;
  915. }
  916. else if( pServer->GetServerRegistrationStatus() == LSERVERSTATUS_WAITFORPIN )
  917. {
  918. TempString.LoadString( IDS_SERVER_WAITFORPIN );
  919. Item.iImage = 4;
  920. }
  921. else if( pServer->GetServerRegistrationStatus() == LSERVERSTATUS_UNREGISTER )
  922. {
  923. TempString.LoadString(IDS_SERVER_UNREGISTER);
  924. Item.iImage = 5;
  925. }
  926. else
  927. {
  928. TempString.LoadString(IDS_UNKNOWN);
  929. Item.iImage = 6;
  930. }
  931. }
  932. else
  933. {
  934. TempString.LoadString(IDS_SERVER_NOTREQUIRE);
  935. }
  936. Item.iItem = item;
  937. ListCtrl.SetItem( &Item );
  938. ListCtrl.SetItemText(item, 1, (LPCTSTR)TempString);
  939. }
  940. break;
  941. case NODE_SERVER:
  942. Item.iItem = 0;
  943. Item.mask = LVIF_PARAM;
  944. nIndex = ListCtrl.GetItem(&Item);
  945. if(-1 == nIndex)
  946. {
  947. break;
  948. }
  949. pKeyPack = (CKeyPack *)Item.lParam;
  950. if(NULL == pKeyPack)
  951. {
  952. break;
  953. }
  954. if(pServer == pKeyPack->GetServer())
  955. {
  956. ListCtrl.DeleteAllItems();
  957. AddKeyPackstoList(pServer, TRUE);
  958. }
  959. break;
  960. case NODE_KEYPACK:
  961. Item.iItem = 0;
  962. Item.mask = LVIF_PARAM;
  963. nIndex = ListCtrl.GetItem(&Item);
  964. if(-1 == nIndex)
  965. {
  966. break;
  967. }
  968. CLicense * pLicense = (CLicense *)Item.lParam;
  969. if(NULL == pLicense)
  970. {
  971. break;
  972. }
  973. pKeyPack = pLicense->GetKeyPack();
  974. if(NULL == pKeyPack)
  975. {
  976. break;
  977. }
  978. if(pServer == pKeyPack->GetServer())
  979. {
  980. ListCtrl.DeleteAllItems();
  981. ((CMainFrame *)AfxGetMainWnd())->AddLicensestoList(pKeyPack, &ListCtrl, TRUE);
  982. }
  983. break;
  984. }
  985. return lResult;
  986. } // OnUpdateServer
  987. //-----------------------------------------------------------------------------------------------------
  988. void CRightList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
  989. {
  990. // TODO: Add your control notification handler code here
  991. // TODO: Add your control notification handler code here
  992. CListCtrl& listctrl = GetListCtrl();
  993. //Get the selected item
  994. int nSelected = listctrl.GetNextItem(-1, LVNI_SELECTED);
  995. if(-1 == nSelected)
  996. return;
  997. //Get the Data associated with the item.
  998. #ifdef _WIN64
  999. DWORD_PTR dCurrSel;
  1000. #else
  1001. DWORD dCurrSel;
  1002. #endif
  1003. dCurrSel = listctrl.GetItemData(nSelected);
  1004. if(LB_ERR == dCurrSel)
  1005. return;
  1006. switch(((CLicMgrDoc *)GetDocument())->GetNodeType())
  1007. {
  1008. case NODE_ALL_SERVERS:
  1009. ((CMainFrame *)AfxGetMainWnd())->SetTreeViewSel(dCurrSel,NODE_SERVER);
  1010. break;
  1011. case NODE_SERVER:
  1012. ((CMainFrame *)AfxGetMainWnd())->SetTreeViewSel(dCurrSel,NODE_KEYPACK);
  1013. break;
  1014. }
  1015. *pResult = 0;
  1016. }
  1017. //-----------------------------------------------------------------------------------------------------
  1018. void CRightList::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult)
  1019. {
  1020. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  1021. // TODO: Add your control notification handler code here
  1022. CMainFrame * pMainFrame = ((CMainFrame *)AfxGetMainWnd());
  1023. if(pLVKeyDow->wVKey == VK_RETURN)
  1024. {
  1025. OnDblclk(pNMHDR,pResult);
  1026. pMainFrame->SelectView(LISTVIEW);
  1027. }
  1028. if(pLVKeyDow->wVKey == VK_TAB)
  1029. {
  1030. pMainFrame->SelectView(TREEVIEW);
  1031. }
  1032. *pResult = 0;
  1033. }
  1034. /*
  1035. * Column Sorting.
  1036. */
  1037. BOOL fColSortDir[MAX_COLUMNS * NODE_NONE];
  1038. int CALLBACK CompareAllServers(LPARAM, LPARAM, LPARAM);
  1039. int CALLBACK CompareServer(LPARAM, LPARAM, LPARAM);
  1040. int CALLBACK CompareKeyPack(LPARAM, LPARAM, LPARAM);
  1041. VOID
  1042. CRightList::OnColumnClick(
  1043. NMHDR* pNMHDR,
  1044. LRESULT* pResult
  1045. )
  1046. {
  1047. NM_LISTVIEW* pnmlv = (NM_LISTVIEW*)pNMHDR;
  1048. NODETYPE curType = ((CLicMgrDoc*)GetDocument())->GetNodeType();
  1049. switch(curType) {
  1050. case NODE_ALL_SERVERS:
  1051. GetListCtrl().SortItems(CompareAllServers, pnmlv->iSubItem);
  1052. break;
  1053. case NODE_SERVER:
  1054. GetListCtrl().SortItems(CompareServer, pnmlv->iSubItem);
  1055. break;
  1056. case NODE_KEYPACK:
  1057. GetListCtrl().SortItems(CompareKeyPack, pnmlv->iSubItem);
  1058. break;
  1059. }
  1060. fColSortDir[curType * MAX_COLUMNS + pnmlv->iSubItem] =
  1061. !fColSortDir[curType * MAX_COLUMNS + pnmlv->iSubItem];
  1062. }
  1063. /*
  1064. * Compare Functions.
  1065. */
  1066. int CALLBACK
  1067. CompareAllServers(
  1068. LPARAM lParam1,
  1069. LPARAM lParam2,
  1070. LPARAM lParamSort
  1071. )
  1072. {
  1073. CLicServer* pItem1 = (CLicServer*)lParam1;
  1074. CLicServer* pItem2 = (CLicServer*)lParam2;
  1075. int retVal = 0;
  1076. int iCol = (NODE_ALL_SERVERS * MAX_COLUMNS) + (int)lParamSort;
  1077. int dir;
  1078. switch(lParamSort) {
  1079. case 0:
  1080. case 1:
  1081. retVal = pItem1->GetName().CompareNoCase(pItem2->GetName());
  1082. break;
  1083. default:
  1084. return(0);
  1085. }
  1086. dir = fColSortDir[iCol] ? 1 : -1;
  1087. return(dir * retVal);
  1088. }
  1089. int CALLBACK
  1090. CompareServer(
  1091. LPARAM lParam1,
  1092. LPARAM lParam2,
  1093. LPARAM lParamSort
  1094. )
  1095. {
  1096. CKeyPack* pItem1 = (CKeyPack*)lParam1;
  1097. CKeyPack* pItem2 = (CKeyPack*)lParam2;
  1098. CString szTemp1;
  1099. CString szTemp2;
  1100. int retVal = 0;
  1101. int iCol = (NODE_SERVER * MAX_COLUMNS) + (int)lParamSort;
  1102. int dir;
  1103. int tmp1, tmp2;
  1104. switch(lParamSort) {
  1105. case 0:
  1106. retVal = _tcsicmp(pItem1->GetDisplayName(), pItem2->GetDisplayName());
  1107. break;
  1108. case 1:
  1109. tmp1 = pItem1->GetKeyPackStruct().ucKeyPackType;
  1110. tmp2 = pItem2->GetKeyPackStruct().ucKeyPackType;
  1111. if (tmp1 >= NUM_KEYPACK_TYPE) {
  1112. szTemp1.LoadString(IDS_LSKEYPACKTYPE_UNKNOWN);
  1113. } else if(tmp1 == LSKEYPACKTYPE_FREE) {
  1114. szTemp1.LoadString(IDS_LSKEYPACKTYPE_FREE);
  1115. } else {
  1116. szTemp1.LoadString(IDS_LSKEYPACKTYPE_UNKNOWN + tmp1);
  1117. }
  1118. if (tmp2 >= NUM_KEYPACK_TYPE) {
  1119. szTemp2.LoadString(IDS_LSKEYPACKTYPE_UNKNOWN);
  1120. } else if(tmp2 == LSKEYPACKTYPE_FREE) {
  1121. szTemp2.LoadString(IDS_LSKEYPACKTYPE_FREE);
  1122. } else {
  1123. szTemp2.LoadString(IDS_LSKEYPACKTYPE_UNKNOWN + tmp2);
  1124. }
  1125. retVal = _tcsicmp(szTemp1, szTemp2);
  1126. break;
  1127. case 2:
  1128. tmp1 = pItem1->GetKeyPackStruct().ucKeyPackType;
  1129. tmp2 = pItem2->GetKeyPackStruct().ucKeyPackType;
  1130. if (tmp1 == LSKEYPACKTYPE_FREE) {
  1131. retVal = 1;
  1132. } else if (tmp1 == LSKEYPACKTYPE_TEMPORARY) {
  1133. retVal = -1;
  1134. } else {
  1135. if (tmp2 == LSKEYPACKTYPE_FREE) {
  1136. retVal = -1;
  1137. } else if (tmp2 == LSKEYPACKTYPE_TEMPORARY) {
  1138. retVal = 1;
  1139. } else {
  1140. retVal = pItem1->GetKeyPackStruct().dwTotalLicenseInKeyPack -
  1141. pItem2->GetKeyPackStruct().dwTotalLicenseInKeyPack;
  1142. }
  1143. }
  1144. break;
  1145. case 3:
  1146. tmp1 = pItem1->GetKeyPackStruct().ucKeyPackType;
  1147. tmp2 = pItem2->GetKeyPackStruct().ucKeyPackType;
  1148. if (tmp1 == LSKEYPACKTYPE_FREE) {
  1149. retVal = 1;
  1150. } else if (tmp1 == LSKEYPACKTYPE_TEMPORARY) {
  1151. retVal = -1;
  1152. } else {
  1153. if (tmp2 == LSKEYPACKTYPE_FREE) {
  1154. retVal = -1;
  1155. } else if (tmp2 == LSKEYPACKTYPE_TEMPORARY) {
  1156. retVal = 1;
  1157. } else {
  1158. retVal = pItem1->GetKeyPackStruct().dwNumberOfLicenses -
  1159. pItem2->GetKeyPackStruct().dwNumberOfLicenses;
  1160. }
  1161. }
  1162. break;
  1163. case 4:
  1164. DWORD sort1, sort2;
  1165. tmp1 = pItem1->GetKeyPackStruct().ucKeyPackType;
  1166. tmp2 = pItem2->GetKeyPackStruct().ucKeyPackType;
  1167. if ((tmp1 == LSKEYPACKTYPE_TEMPORARY) || (tmp1 == LSKEYPACKTYPE_FREE)) {
  1168. sort1 = pItem1->GetKeyPackStruct().dwNumberOfLicenses;
  1169. } else {
  1170. sort1 = pItem1->GetKeyPackStruct().dwTotalLicenseInKeyPack -
  1171. pItem1->GetKeyPackStruct().dwNumberOfLicenses;
  1172. }
  1173. if ((tmp2 == LSKEYPACKTYPE_TEMPORARY) || (tmp2 == LSKEYPACKTYPE_FREE)) {
  1174. sort2 = pItem2->GetKeyPackStruct().dwNumberOfLicenses;
  1175. } else {
  1176. sort2 = pItem2->GetKeyPackStruct().dwTotalLicenseInKeyPack -
  1177. pItem2->GetKeyPackStruct().dwNumberOfLicenses;
  1178. }
  1179. retVal = sort1 - sort2;
  1180. break;
  1181. default:
  1182. return(0);
  1183. }
  1184. dir = fColSortDir[iCol] ? 1 : -1;
  1185. return(dir * retVal);
  1186. }
  1187. int CALLBACK
  1188. CompareKeyPack(
  1189. LPARAM lParam1,
  1190. LPARAM lParam2,
  1191. LPARAM lParamSort
  1192. )
  1193. {
  1194. CLicense* pItem1 = (CLicense*)lParam1;
  1195. CLicense* pItem2 = (CLicense*)lParam2;
  1196. int retVal = 0;
  1197. int iCol = (NODE_KEYPACK * MAX_COLUMNS) + (int)lParamSort;
  1198. int dir;
  1199. switch(lParamSort) {
  1200. case 0:
  1201. retVal = _tcsicmp(pItem1->GetLicenseStruct().szMachineName,
  1202. pItem2->GetLicenseStruct().szMachineName);
  1203. break;
  1204. case 1:
  1205. retVal = pItem1->GetLicenseStruct().ftIssueDate -
  1206. pItem2->GetLicenseStruct().ftIssueDate;
  1207. break;
  1208. case 2:
  1209. retVal = pItem1->GetLicenseStruct().ftExpireDate -
  1210. pItem2->GetLicenseStruct().ftExpireDate;
  1211. break;
  1212. default:
  1213. return(0);
  1214. }
  1215. dir = fColSortDir[iCol] ? 1 : -1;
  1216. return(dir * retVal);
  1217. }
  1218. afx_msg void CRightList::OnLeftClick( NMHDR* pNMHDR, LRESULT* pResult )
  1219. {
  1220. CPoint pt;
  1221. DWORD_PTR itemData;
  1222. GetCursorPos( &pt );
  1223. ScreenToClient( &pt );
  1224. UINT flag;
  1225. CListCtrl& listctrl = GetListCtrl();
  1226. int iItem = listctrl.HitTest( pt , &flag );
  1227. itemData = listctrl.GetItemData( iItem );
  1228. if( itemData == LB_ERR )
  1229. {
  1230. int iItem = listctrl.GetNextItem(-1, LVNI_SELECTED | LVNI_FOCUSED );
  1231. if( iItem != LB_ERR )
  1232. {
  1233. itemData = listctrl.GetItemData( iItem );
  1234. }
  1235. else
  1236. {
  1237. DBGMSG( L"\tno item selected\n", 0 );
  1238. return;
  1239. }
  1240. }
  1241. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  1242. if(NULL == pDoc)
  1243. {
  1244. return;
  1245. }
  1246. NODETYPE nt = pDoc->GetNodeType();
  1247. switch( nt )
  1248. {
  1249. case NODE_ALL_SERVERS:
  1250. {
  1251. CLicServer *pServer = reinterpret_cast< CLicServer* >( itemData );
  1252. SetActiveServer( pServer );
  1253. if( NULL == pServer )
  1254. {
  1255. DBGMSG( L"\tno item selected\n", 0 );
  1256. break;
  1257. }
  1258. DBGMSG( L"\tServer item selected\n", 0 );
  1259. }
  1260. break;
  1261. case NODE_SERVER:
  1262. {
  1263. CKeyPack *pKeyPack = reinterpret_cast< CKeyPack * >( itemData );
  1264. if(NULL == pKeyPack)
  1265. {
  1266. DBGMSG( L"\tno item selected\n", 0 );
  1267. SetActiveServer( NULL );
  1268. break;
  1269. }
  1270. SetActiveServer( pKeyPack->GetServer( ) );
  1271. DBGMSG( L"\tLicense pak item selected\n", 0 );
  1272. }
  1273. break;
  1274. case NODE_KEYPACK:
  1275. {
  1276. CLicense * pLicense = reinterpret_cast< CLicense * >( itemData );
  1277. if( pLicense != NULL )
  1278. {
  1279. CKeyPack *pKeyPack = pLicense->GetKeyPack( );
  1280. if( pKeyPack != NULL )
  1281. {
  1282. SetActiveServer( pKeyPack->GetServer( ) );
  1283. break;
  1284. }
  1285. }
  1286. SetActiveServer( NULL );
  1287. }
  1288. break;
  1289. }
  1290. }
  1291. //------------------------------------------------------------------------
  1292. afx_msg void CRightList::OnContextMenu( CWnd* pWnd, CPoint pt )
  1293. {
  1294. CMenu menu;
  1295. CMenu *pContextMenu = NULL;
  1296. DWORD_PTR itemData;
  1297. DBGMSG( L"LICMGR @ CRightList::OnContextMenu\n" , 0 );
  1298. DBGMSG( L"\tpoint x = %d " , pt.x );
  1299. DBGMSG( L"y = %d\n" , pt.y );
  1300. UINT flag;
  1301. int nItem = -1;
  1302. CListCtrl& listctrl = GetListCtrl();
  1303. // maybe keyboard selected this item
  1304. if(pt.x == -1 && pt.y == -1)
  1305. {
  1306. if( listctrl.GetSelectedCount( ) > 0 )
  1307. {
  1308. RECT rect;
  1309. nItem = listctrl.GetNextItem( nItem , LVNI_SELECTED );
  1310. if( nItem != ( int )LB_ERR )
  1311. {
  1312. listctrl.GetItemRect( nItem , &rect , LVIR_BOUNDS );
  1313. pt.x = rect.left + (rect.right - rect.left)/2;
  1314. pt.y = rect.top + (rect.bottom - rect.top)/2;
  1315. }
  1316. }
  1317. }
  1318. else
  1319. {
  1320. // otherwise we're invoked by the mouse
  1321. ScreenToClient( &pt );
  1322. nItem = listctrl.HitTest( pt , &flag );
  1323. }
  1324. itemData = listctrl.GetItemData( nItem );
  1325. CLicMgrDoc * pDoc =(CLicMgrDoc *)GetDocument();
  1326. if(NULL == pDoc)
  1327. {
  1328. return;
  1329. }
  1330. ClientToScreen( &pt );
  1331. NODETYPE nt = pDoc->GetNodeType();
  1332. switch( nt )
  1333. {
  1334. case NODE_ALL_SERVERS:
  1335. {
  1336. CLicServer *pServer = reinterpret_cast< CLicServer* >( itemData );
  1337. SetActiveServer( pServer );
  1338. if( NULL == pServer )
  1339. {
  1340. DBGMSG( L"\tno item selected\n", 0 );
  1341. break;
  1342. }
  1343. DBGMSG( L"\tServer item selected\n", 0 );
  1344. menu.LoadMenu( IDR_MENU_LPK );
  1345. pContextMenu = menu.GetSubMenu( 0 );
  1346. nt = NODE_SERVER;
  1347. }
  1348. break;
  1349. case NODE_SERVER:
  1350. {
  1351. nt = NODE_KEYPACK;
  1352. CKeyPack *pKeyPack = reinterpret_cast< CKeyPack * >( itemData );
  1353. if(NULL == pKeyPack)
  1354. {
  1355. DBGMSG( L"\tno item selected\n", 0 );
  1356. // SetActiveServer( NULL );
  1357. break;
  1358. }
  1359. SetActiveServer( pKeyPack->GetServer( ) );
  1360. DBGMSG( L"\tLicense pak item selected\n", 0 );
  1361. menu.LoadMenu( IDR_MENU_LPK );
  1362. pContextMenu = menu.GetSubMenu( 1 );
  1363. }
  1364. break;
  1365. case NODE_KEYPACK:
  1366. {
  1367. CLicense * pLicense = reinterpret_cast< CLicense * >( itemData );
  1368. if( pLicense == NULL )
  1369. {
  1370. DBGMSG( L"\tno item selected\n", 0 );
  1371. // SetActiveServer( NULL );
  1372. break;
  1373. }
  1374. CKeyPack *pKeyPack = pLicense->GetKeyPack( );
  1375. if( pKeyPack != NULL )
  1376. {
  1377. SetActiveServer( pKeyPack->GetServer( ) );
  1378. }
  1379. else
  1380. {
  1381. // impossible! a license with out a home
  1382. ASSERT( 0 );
  1383. }
  1384. /*
  1385. nt = NODE_NONE; // its safe
  1386. CLicense * pLicense = reinterpret_cast< CLicense * >( itemData );
  1387. if( pLicense == NULL )
  1388. {
  1389. DBGMSG( L"\tno item selected\n", 0 );
  1390. break;
  1391. }
  1392. DBGMSG( L"\tLicense item selected\n", 0 );
  1393. menu.LoadMenu( IDR_MENU_LPK );
  1394. pContextMenu = menu.GetSubMenu( 2 );
  1395. */
  1396. }
  1397. break;
  1398. }
  1399. UI_initmenu( pContextMenu , nt );
  1400. if( pContextMenu != NULL )
  1401. {
  1402. pContextMenu->TrackPopupMenu( TPM_LEFTALIGN , pt.x , pt.y , this );
  1403. }
  1404. }
  1405. //----------------------------------------------------------------------------
  1406. void CRightList::UI_initmenu( CMenu *pMenu , NODETYPE nt )
  1407. {
  1408. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  1409. if( pMainFrame != NULL )
  1410. {
  1411. pMainFrame->UI_initmenu( pMenu , nt );
  1412. }
  1413. }
  1414. //----------------------------------------------------------------------------
  1415. DWORD CRightList::WizardActionOnServer( WIZACTION wa , PBOOL pbRefresh )
  1416. {
  1417. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  1418. if( pMainFrame != NULL )
  1419. {
  1420. return pMainFrame->WizardActionOnServer( wa , pbRefresh , LISTVIEW );
  1421. }
  1422. return ERROR_INVALID_PARAMETER;
  1423. }
  1424. //-----------------------------------------------------------------------------------------
  1425. void CRightList::OnServerConnect( )
  1426. {
  1427. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  1428. if( pMainFrame != NULL )
  1429. {
  1430. pMainFrame->ConnectServer( );
  1431. }
  1432. }
  1433. //-----------------------------------------------------------------------------------------
  1434. void CRightList::OnRefreshAllServers( )
  1435. {
  1436. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  1437. if( pMainFrame != NULL )
  1438. {
  1439. pMainFrame->OnRefresh( );
  1440. }
  1441. }
  1442. //-----------------------------------------------------------------------------------------
  1443. void CRightList::OnRefreshServer( )
  1444. {
  1445. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  1446. CLicServer *pServer = NULL;
  1447. if( pMainFrame != NULL )
  1448. {
  1449. CListCtrl& listctrl = GetListCtrl();
  1450. CLicMgrDoc * pDoc = (CLicMgrDoc *)GetDocument();
  1451. ASSERT(pDoc);
  1452. if(NULL == pDoc)
  1453. {
  1454. return;
  1455. }
  1456. int nSelected = listctrl.GetNextItem(-1, LVNI_SELECTED);
  1457. if( -1 != nSelected)
  1458. {
  1459. DWORD_PTR dCurrSel = listctrl.GetItemData( nSelected );
  1460. if( NODE_ALL_SERVERS == pDoc->GetNodeType() )
  1461. {
  1462. pServer = reinterpret_cast< CLicServer * >( dCurrSel );
  1463. }
  1464. else if( pDoc->GetNodeType() == NODE_SERVER )
  1465. {
  1466. CKeyPack *pKeyPack = reinterpret_cast< CKeyPack *>( dCurrSel );
  1467. if( pKeyPack != NULL )
  1468. {
  1469. pServer = pKeyPack->GetServer( );
  1470. }
  1471. }
  1472. else if( pDoc->GetNodeType( ) == NODE_KEYPACK )
  1473. {
  1474. CLicense * pLicense = reinterpret_cast< CLicense * >( dCurrSel );
  1475. pServer = ( pLicense->GetKeyPack() )->GetServer( );
  1476. }
  1477. }
  1478. if( pServer != NULL )
  1479. {
  1480. pMainFrame->RefreshServer( pServer );
  1481. }
  1482. }
  1483. }
  1484. //-----------------------------------------------------------------------------------------
  1485. void CRightList::OnDownloadKeepPack()
  1486. {
  1487. BOOL bRefresh;
  1488. DWORD dwStatus = WizardActionOnServer( WIZACTION_DOWNLOADLKP , &bRefresh );
  1489. DBGMSG( L"LICMGR : CRightList::OnDownloadKeepPack StartWizard returned 0x%x\n" , dwStatus );
  1490. }
  1491. //-----------------------------------------------------------------------------------------
  1492. void CRightList::OnRegisterServer()
  1493. {
  1494. BOOL bRefresh;
  1495. DWORD dwStatus = WizardActionOnServer( WIZACTION_REGISTERLS , &bRefresh );
  1496. DBGMSG( L"LICMGR : CRightList::OnRegisterServer StartWizard returned 0x%x\n" , dwStatus );
  1497. }
  1498. //-----------------------------------------------------------------------------------------
  1499. void CRightList::OnRepeatLastDownload()
  1500. {
  1501. BOOL bRefresh;
  1502. DWORD dwStatus = WizardActionOnServer( WIZACTION_DOWNLOADLASTLKP , &bRefresh );
  1503. DBGMSG( L"LICMGR : CRightList::OnRepeatLastDownload StartWizard returned 0x%x\n" , dwStatus );
  1504. }
  1505. //-----------------------------------------------------------------------------------------
  1506. void CRightList::OnReactivateServer( )
  1507. {
  1508. BOOL bRefresh;
  1509. DWORD dwStatus = WizardActionOnServer( WIZACTION_REREGISTERLS , &bRefresh );
  1510. DBGMSG( L"LICMGR : CRightList::OnReactivateServer StartWizard returned 0x%x\n" , dwStatus );
  1511. }
  1512. //-----------------------------------------------------------------------------------------
  1513. void CRightList::OnDeactivateServer( )
  1514. {
  1515. BOOL bRefresh;
  1516. DWORD dwStatus = WizardActionOnServer( WIZACTION_UNREGISTERLS , &bRefresh );
  1517. DBGMSG( L"LICMGR : CRightList::OnDeactivateServer StartWizard returned 0x%x\n" , dwStatus );
  1518. }
  1519. //-----------------------------------------------------------------------------------------
  1520. void CRightList::OnServerProperties( )
  1521. {
  1522. BOOL bRefresh;
  1523. DWORD dwStatus = WizardActionOnServer( WIZACTION_SHOWPROPERTIES , &bRefresh );
  1524. DBGMSG( L"LICMGR : CRightList::OnServerProperties StartWizard returned 0x%x\n" , dwStatus );
  1525. }
  1526. //-----------------------------------------------------------------------------------------
  1527. void CRightList::OnGeneralHelp( )
  1528. {
  1529. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  1530. if( pMainFrame != NULL )
  1531. {
  1532. pMainFrame->OnHelp( );
  1533. }
  1534. }
  1535. //-----------------------------------------------------------------------------------------
  1536. void CRightList::SetActiveServer( CLicServer *pServer )
  1537. {
  1538. CMainFrame *pMainFrame = static_cast< CMainFrame * >( AfxGetMainWnd() );
  1539. if( pServer != NULL )
  1540. {
  1541. DBGMSG( L"LICMGR : CRightList::SetActiveServer %s\n" , pServer->GetName( ) );
  1542. }
  1543. if( pMainFrame != NULL )
  1544. {
  1545. pMainFrame->SetActiveServer( pServer );
  1546. }
  1547. }