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.

918 lines
20 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. prdppgl.cpp
  5. Abstract:
  6. Product property page (licences) implementation.
  7. Author:
  8. Don Ryan (donryan) 02-Feb-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. Jeff Parham (jeffparh) 30-Jan-1996
  13. o Ported to CCF API to add/remove licenses.
  14. o Added new element to LV_COLUMN_ENTRY to differentiate the string
  15. used for the column header from the string used in the menus
  16. (so that the menu option can contain hot keys).
  17. --*/
  18. #include "stdafx.h"
  19. #include "llsmgr.h"
  20. #include "prdppgl.h"
  21. #include "mainfrm.h"
  22. #define LVID_DATE 1
  23. #define LVID_QUANTITY 2
  24. #define LVID_ADMIN 3
  25. #define LVID_COMMENT 4
  26. #define LVCX_DATE 20
  27. #define LVCX_QUANTITY 20
  28. #define LVCX_ADMIN 30
  29. #define LVCX_COMMENT -1
  30. static LV_COLUMN_INFO g_licenseColumnInfo = {
  31. 0, 0, 5,
  32. {{LVID_SEPARATOR, 0, 0, 0 },
  33. {LVID_DATE, IDS_DATE, 0, LVCX_DATE },
  34. {LVID_QUANTITY, IDS_QUANTITY, 0, LVCX_QUANTITY},
  35. {LVID_ADMIN, IDS_ADMINISTRATOR, 0, LVCX_ADMIN },
  36. {LVID_COMMENT, IDS_COMMENT, 0, LVCX_COMMENT }},
  37. };
  38. #ifdef _DEBUG
  39. #undef THIS_FILE
  40. static char BASED_CODE THIS_FILE[] = __FILE__;
  41. #endif
  42. IMPLEMENT_DYNCREATE(CProductPropertyPageLicenses, CPropertyPage)
  43. BEGIN_MESSAGE_MAP(CProductPropertyPageLicenses, CPropertyPage)
  44. //{{AFX_MSG_MAP(CProductPropertyPageLicenses)
  45. ON_BN_CLICKED(IDC_PP_PRODUCT_LICENSES_NEW, OnNew)
  46. ON_NOTIFY(LVN_COLUMNCLICK, IDC_PP_PRODUCT_LICENSES_LICENSES, OnColumnClickLicenses)
  47. ON_NOTIFY(LVN_GETDISPINFO, IDC_PP_PRODUCT_LICENSES_LICENSES, OnGetDispInfoLicenses)
  48. ON_BN_CLICKED(IDC_PP_PRODUCT_LICENSES_DELETE, OnDelete)
  49. ON_WM_DESTROY()
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. CProductPropertyPageLicenses::CProductPropertyPageLicenses()
  53. : CPropertyPage(CProductPropertyPageLicenses::IDD)
  54. /*++
  55. Routine Description:
  56. Constructor for product property page (licenses).
  57. Arguments:
  58. None.
  59. Return Values:
  60. None.
  61. --*/
  62. {
  63. //{{AFX_DATA_INIT(CProductPropertyPageLicenses)
  64. m_nLicensesTotal = 0;
  65. //}}AFX_DATA_INIT
  66. m_pProduct = NULL;
  67. m_pUpdateHint = NULL;
  68. m_bAreCtrlsInitialized = FALSE;
  69. }
  70. CProductPropertyPageLicenses::~CProductPropertyPageLicenses()
  71. /*++
  72. Routine Description:
  73. Destructor for product property page (licenses).
  74. Arguments:
  75. None.
  76. Return Values:
  77. None.
  78. --*/
  79. {
  80. //
  81. // Nothing to do here...
  82. //
  83. }
  84. void CProductPropertyPageLicenses::DoDataExchange(CDataExchange* pDX)
  85. /*++
  86. Routine Description:
  87. Called by framework to exchange dialog data.
  88. Arguments:
  89. pDX - data exchange object.
  90. Return Values:
  91. None.
  92. --*/
  93. {
  94. CPropertyPage::DoDataExchange(pDX);
  95. //{{AFX_DATA_MAP(CProductPropertyPageLicenses)
  96. DDX_Control(pDX, IDC_PP_PRODUCT_LICENSES_NEW, m_newBtn);
  97. DDX_Control(pDX, IDC_PP_PRODUCT_LICENSES_DELETE, m_delBtn);
  98. DDX_Control(pDX, IDC_PP_PRODUCT_LICENSES_LICENSES, m_licenseList);
  99. DDX_Text(pDX, IDC_PP_PRODUCT_LICENSES_TOTAL, m_nLicensesTotal);
  100. //}}AFX_DATA_MAP
  101. }
  102. void CProductPropertyPageLicenses::InitCtrls()
  103. /*++
  104. Routine Description:
  105. Initializes property page controls.
  106. Arguments:
  107. None.
  108. Return Values:
  109. None.
  110. --*/
  111. {
  112. m_newBtn.SetFocus();
  113. m_delBtn.EnableWindow(FALSE);
  114. m_bAreCtrlsInitialized = TRUE;
  115. ::LvInitColumns(&m_licenseList, &g_licenseColumnInfo);
  116. }
  117. void CProductPropertyPageLicenses::InitPage(CProduct* pProduct, DWORD* pUpdateHint)
  118. /*++
  119. Routine Description:
  120. Initializes property page.
  121. Arguments:
  122. pProduct - product object.
  123. pUpdateHint - update hint.
  124. Return Values:
  125. None.
  126. --*/
  127. {
  128. ASSERT(pUpdateHint);
  129. VALIDATE_OBJECT(pProduct, CProduct);
  130. m_pProduct = pProduct;
  131. m_pUpdateHint = pUpdateHint;
  132. }
  133. void CProductPropertyPageLicenses::AbortPageIfNecessary()
  134. /*++
  135. Routine Description:
  136. Displays status and aborts if connection lost.
  137. Arguments:
  138. None.
  139. Return Values:
  140. None.
  141. --*/
  142. {
  143. theApp.DisplayLastStatus();
  144. if (IsConnectionDropped(LlsGetLastStatus()))
  145. {
  146. AbortPage(); // bail...
  147. }
  148. }
  149. void CProductPropertyPageLicenses::AbortPage()
  150. /*++
  151. Routine Description:
  152. Aborts property page.
  153. Arguments:
  154. None.
  155. Return Values:
  156. None.
  157. --*/
  158. {
  159. *m_pUpdateHint = UPDATE_INFO_ABORT;
  160. GetParent()->PostMessage(WM_COMMAND, IDCANCEL);
  161. }
  162. BOOL CProductPropertyPageLicenses::OnInitDialog()
  163. /*++
  164. Routine Description:
  165. Message handler for WM_INITDIALOG.
  166. Arguments:
  167. None.
  168. Return Values:
  169. Returns false if focus set to control manually.
  170. --*/
  171. {
  172. CPropertyPage::OnInitDialog();
  173. SendMessage(WM_COMMAND, ID_INIT_CTRLS);
  174. return TRUE;
  175. }
  176. void CProductPropertyPageLicenses::OnNew()
  177. /*++
  178. Routine Description:
  179. Creates a new license for product.
  180. Arguments:
  181. None.
  182. Return Values:
  183. None.
  184. --*/
  185. {
  186. CController* pController = (CController*)MKOBJ(LlsGetApp()->GetActiveController());
  187. VALIDATE_OBJECT(pController, CController);
  188. BSTR pszUniServerName = pController->GetName();
  189. BSTR pszUniProductName = m_pProduct->GetName();
  190. if ( ( NULL == pszUniServerName ) || ( NULL == pszUniProductName ) )
  191. {
  192. theApp.DisplayStatus( STATUS_NO_MEMORY );
  193. }
  194. else
  195. {
  196. /*
  197. LPSTR pszAscServerName = (LPSTR) LocalAlloc( LMEM_FIXED, 1 + lstrlen( pszUniServerName ) );
  198. LPSTR pszAscProductName = (LPSTR) LocalAlloc( LMEM_FIXED, 1 + lstrlen( pszUniProductName ) );
  199. */
  200. LPSTR pszAscServerName = NULL;
  201. LPSTR pszAscProductName = NULL;
  202. int cbSize = 0;
  203. cbSize = WideCharToMultiByte( CP_OEMCP ,
  204. 0 ,
  205. pszUniServerName ,
  206. -1,
  207. pszAscServerName ,
  208. 0 ,
  209. NULL ,
  210. NULL );
  211. if( cbSize != 0 )
  212. {
  213. pszAscServerName = ( LPSTR )LocalAlloc( LMEM_FIXED , cbSize + 1 );
  214. }
  215. if( pszAscServerName == NULL )
  216. {
  217. theApp.DisplayStatus( STATUS_NO_MEMORY );
  218. return;
  219. }
  220. WideCharToMultiByte( CP_OEMCP ,
  221. 0 ,
  222. pszUniServerName ,
  223. -1,
  224. pszAscServerName ,
  225. cbSize ,
  226. NULL ,
  227. NULL );
  228. cbSize = 0;
  229. cbSize = WideCharToMultiByte( CP_OEMCP ,
  230. 0 ,
  231. pszUniProductName ,
  232. -1,
  233. pszAscProductName ,
  234. 0 ,
  235. NULL ,
  236. NULL );
  237. if( cbSize != 0 )
  238. {
  239. pszAscProductName = ( LPSTR )LocalAlloc( LMEM_FIXED , 1 + cbSize );
  240. }
  241. if( NULL == pszAscProductName )
  242. {
  243. theApp.DisplayStatus( STATUS_NO_MEMORY );
  244. return;
  245. }
  246. else
  247. {
  248. /*
  249. wsprintfA( pszAscServerName, "%ls", pszUniServerName );
  250. wsprintfA( pszAscProductName, "%ls", pszUniProductName );
  251. */
  252. WideCharToMultiByte( CP_OEMCP ,
  253. 0 ,
  254. pszUniProductName ,
  255. -1,
  256. pszAscProductName ,
  257. cbSize ,
  258. NULL ,
  259. NULL );
  260. DWORD dwError = CCFCertificateEnterUI( m_hWnd, pszAscServerName, pszAscProductName, "Microsoft", CCF_ENTER_FLAG_PER_SEAT_ONLY | CCF_ENTER_FLAG_SERVER_IS_ES, NULL );
  261. DWORD fUpdateHint;
  262. if ( ERROR_SUCCESS == dwError )
  263. {
  264. fUpdateHint = UPDATE_LICENSE_ADDED;
  265. }
  266. else
  267. {
  268. fUpdateHint = UPDATE_INFO_NONE;
  269. }
  270. *m_pUpdateHint |= fUpdateHint;
  271. if (IsLicenseInfoUpdated(fUpdateHint) && !RefreshCtrls())
  272. {
  273. AbortPageIfNecessary(); // display error...
  274. }
  275. }
  276. if ( NULL != pszAscServerName )
  277. {
  278. LocalFree( pszAscServerName );
  279. }
  280. if ( NULL != pszAscProductName )
  281. {
  282. LocalFree( pszAscProductName );
  283. }
  284. }
  285. if ( NULL != pszUniServerName )
  286. {
  287. SysFreeString( pszUniServerName );
  288. }
  289. if ( NULL != pszUniProductName )
  290. {
  291. SysFreeString( pszUniProductName );
  292. }
  293. }
  294. void CProductPropertyPageLicenses::OnDelete()
  295. /*++
  296. Routine Description:
  297. Removes licenses from product.
  298. Arguments:
  299. None.
  300. Return Values:
  301. None.
  302. --*/
  303. {
  304. CController* pController = (CController*)MKOBJ(LlsGetApp()->GetActiveController());
  305. VALIDATE_OBJECT(pController, CController);
  306. BSTR pszUniServerName = pController->GetName();
  307. LPSTR pszAscServerName = NULL;
  308. LPSTR pszAscProductName = NULL;
  309. int cbSize;
  310. if ( NULL == pszUniServerName )
  311. {
  312. theApp.DisplayStatus( STATUS_NO_MEMORY );
  313. }
  314. else
  315. {
  316. // LPSTR pszAscServerName = (LPSTR) LocalAlloc( LMEM_FIXED, 1 + lstrlen( pszUniServerName ) );
  317. cbSize = WideCharToMultiByte( CP_OEMCP ,
  318. 0 ,
  319. pszUniServerName ,
  320. -1,
  321. pszAscServerName ,
  322. 0 ,
  323. NULL ,
  324. NULL );
  325. if( cbSize != 0 )
  326. {
  327. pszAscServerName = ( LPSTR )LocalAlloc( LMEM_FIXED , cbSize + 1 );
  328. }
  329. if ( NULL == pszAscServerName )
  330. {
  331. theApp.DisplayStatus( STATUS_NO_MEMORY );
  332. }
  333. else
  334. {
  335. // wsprintfA( pszAscServerName, "%ls", pszUniServerName );
  336. WideCharToMultiByte( CP_OEMCP ,
  337. 0 ,
  338. pszUniServerName ,
  339. -1,
  340. pszAscServerName ,
  341. cbSize ,
  342. NULL ,
  343. NULL );
  344. // LPSTR pszAscProductName = NULL;
  345. BSTR pszUniProductName = m_pProduct->GetName();
  346. if ( NULL != pszUniProductName )
  347. {
  348. // pszAscProductName = (LPSTR) LocalAlloc( LMEM_FIXED, 1 + lstrlen( pszUniProductName ) );
  349. cbSize = 0;
  350. cbSize = WideCharToMultiByte( CP_OEMCP ,
  351. 0 ,
  352. pszUniProductName ,
  353. -1,
  354. pszAscProductName ,
  355. 0 ,
  356. NULL ,
  357. NULL );
  358. if( cbSize != 0 )
  359. {
  360. pszAscProductName = ( LPSTR )LocalAlloc( LMEM_FIXED , 1 + cbSize );
  361. }
  362. if ( NULL != pszAscProductName )
  363. {
  364. // wsprintfA( pszAscProductName, "%ls", pszUniProductName );
  365. WideCharToMultiByte( CP_OEMCP ,
  366. 0 ,
  367. pszUniProductName ,
  368. -1,
  369. pszAscProductName ,
  370. cbSize ,
  371. NULL ,
  372. NULL );
  373. }
  374. SysFreeString( pszUniProductName );
  375. }
  376. CCFCertificateRemoveUI( m_hWnd, pszAscServerName, pszAscProductName, pszAscProductName ? "Microsoft" : NULL, NULL, NULL );
  377. *m_pUpdateHint |= UPDATE_LICENSE_DELETED;
  378. if ( !RefreshCtrls() )
  379. {
  380. AbortPageIfNecessary(); // display error...
  381. }
  382. LocalFree( pszAscServerName );
  383. if ( NULL != pszAscProductName )
  384. {
  385. LocalFree( pszAscProductName );
  386. }
  387. }
  388. SysFreeString( pszUniServerName );
  389. }
  390. }
  391. BOOL CProductPropertyPageLicenses::RefreshCtrls()
  392. /*++
  393. Routine Description:
  394. Refreshs property page controls.
  395. Arguments:
  396. None.
  397. Return Values:
  398. Returns true if controls refreshed.
  399. --*/
  400. {
  401. VALIDATE_OBJECT(m_pProduct, CProduct);
  402. BOOL bIsRefreshed = FALSE;
  403. VARIANT va;
  404. VariantInit(&va);
  405. m_nLicensesTotal = 0; // reset now...
  406. BeginWaitCursor(); // hourglass...
  407. CLicenses* pLicenses = (CLicenses*)MKOBJ(m_pProduct->GetLicenses(va));
  408. if (pLicenses)
  409. {
  410. VALIDATE_OBJECT(pLicenses, CLicenses);
  411. bIsRefreshed = ::LvRefreshObArray(
  412. &m_licenseList,
  413. &g_licenseColumnInfo,
  414. pLicenses->m_pObArray
  415. );
  416. if (bIsRefreshed)
  417. {
  418. CObArray* pObArray;
  419. CLicense* pLicense;
  420. pObArray = pLicenses->m_pObArray;
  421. INT_PTR nLicenses = pObArray->GetSize();
  422. while (nLicenses--)
  423. {
  424. pLicense = (CLicense*)pObArray->GetAt(nLicenses);
  425. VALIDATE_OBJECT(pLicense, CLicense);
  426. m_nLicensesTotal += pLicense->GetQuantity();
  427. }
  428. }
  429. pLicenses->InternalRelease(); // add ref'd individually...
  430. }
  431. if (!bIsRefreshed)
  432. {
  433. ::LvReleaseObArray(&m_licenseList); // reset list now...
  434. }
  435. EndWaitCursor(); // hourglass...
  436. UpdateData(FALSE); // update total...
  437. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  438. return bIsRefreshed;
  439. }
  440. void CProductPropertyPageLicenses::OnDestroy()
  441. /*++
  442. Routine Description:
  443. Message handler for WM_DESTROY.
  444. Arguments:
  445. None.
  446. Return Values:
  447. None.
  448. --*/
  449. {
  450. ::LvReleaseObArray(&m_licenseList); // release now...
  451. CPropertyPage::OnDestroy();
  452. }
  453. BOOL CProductPropertyPageLicenses::OnSetActive()
  454. /*++
  455. Routine Description:
  456. Activates property page.
  457. Arguments:
  458. None.
  459. Return Values:
  460. Returns true if focus accepted.
  461. --*/
  462. {
  463. BOOL bIsActivated;
  464. bIsActivated = CPropertyPage::OnSetActive();
  465. if (FALSE != bIsActivated)
  466. {
  467. if (IsLicenseInfoUpdated(*m_pUpdateHint) && !RefreshCtrls())
  468. {
  469. AbortPageIfNecessary(); // display error...
  470. }
  471. }
  472. return bIsActivated;
  473. }
  474. BOOL CProductPropertyPageLicenses::OnCommand(WPARAM wParam, LPARAM lParam)
  475. /*++
  476. Routine Description:
  477. Message handler for WM_COMMAND.
  478. Arguments:
  479. wParam - message specific.
  480. lParam - message specific.
  481. Return Values:
  482. Returns true if message processed.
  483. --*/
  484. {
  485. if (wParam == ID_INIT_CTRLS)
  486. {
  487. if (!m_bAreCtrlsInitialized)
  488. {
  489. InitCtrls();
  490. if (!RefreshCtrls())
  491. {
  492. AbortPageIfNecessary(); // display error...
  493. }
  494. }
  495. ::SafeEnableWindow(
  496. &m_delBtn,
  497. &m_licenseList,
  498. CDialog::GetFocus(),
  499. (BOOL)(m_nLicensesTotal > 0)
  500. );
  501. return TRUE; // processed...
  502. }
  503. return CDialog::OnCommand(wParam, lParam);
  504. }
  505. void CProductPropertyPageLicenses::OnColumnClickLicenses(NMHDR* pNMHDR, LRESULT* pResult)
  506. /*++
  507. Routine Description:
  508. Notification handler for LVN_COLUMNCLICK.
  509. Arguments:
  510. pNMHDR - notification header.
  511. pResult - return code.
  512. Return Values:
  513. None.
  514. --*/
  515. {
  516. g_licenseColumnInfo.bSortOrder = GetKeyState(VK_CONTROL) < 0;
  517. ASSERT(NULL != pNMHDR);
  518. g_licenseColumnInfo.nSortedItem = ((NM_LISTVIEW*)pNMHDR)->iSubItem;
  519. m_licenseList.SortItems(CompareProductLicenses, 0); // use column info
  520. ASSERT(NULL != pResult);
  521. *pResult = 0;
  522. }
  523. void CProductPropertyPageLicenses::OnGetDispInfoLicenses(NMHDR* pNMHDR, LRESULT* pResult)
  524. /*++
  525. Routine Description:
  526. Notification handler for LVN_GETDISPINFO.
  527. Arguments:
  528. pNMHDR - notification header.
  529. pResult - return code.
  530. Return Values:
  531. None.
  532. --*/
  533. {
  534. ASSERT(NULL != pNMHDR);
  535. LV_ITEM* plvItem = &((LV_DISPINFO*)pNMHDR)->item;
  536. ASSERT(plvItem);
  537. CLicense* pLicense = (CLicense*)plvItem->lParam;
  538. VALIDATE_OBJECT(pLicense, CLicense);
  539. switch (plvItem->iSubItem)
  540. {
  541. case LVID_SEPARATOR:
  542. {
  543. plvItem->iImage = 0;
  544. CString strLabel = _T("");
  545. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  546. }
  547. break;
  548. case LVID_DATE:
  549. {
  550. BSTR bstrDate = pLicense->GetDateString();
  551. if( bstrDate != NULL)
  552. {
  553. lstrcpyn(plvItem->pszText, bstrDate, plvItem->cchTextMax);
  554. SysFreeString(bstrDate);
  555. }
  556. else
  557. {
  558. plvItem->pszText[0] = L'\0';
  559. }
  560. }
  561. break;
  562. case LVID_QUANTITY:
  563. {
  564. CString strLabel;
  565. strLabel.Format(_T("%ld"), pLicense->m_lQuantity);
  566. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  567. }
  568. break;
  569. case LVID_ADMIN:
  570. lstrcpyn(plvItem->pszText, pLicense->m_strUser, plvItem->cchTextMax);
  571. break;
  572. case LVID_COMMENT:
  573. lstrcpyn(plvItem->pszText, pLicense->m_strDescription, plvItem->cchTextMax);
  574. break;
  575. }
  576. ASSERT(NULL != pNMHDR);
  577. *pResult = 0;
  578. }
  579. int CALLBACK CompareProductLicenses(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  580. /*++
  581. Routine Description:
  582. Notification handler for LVM_SORTITEMS.
  583. Arguments:
  584. lParam1 - object to sort.
  585. lParam2 - object to sort.
  586. lParamSort - sort criteria.
  587. Return Values:
  588. Same as lstrcmp.
  589. --*/
  590. {
  591. UNREFERENCED_PARAMETER(lParamSort);
  592. #define pLicense1 ((CLicense*)lParam1)
  593. #define pLicense2 ((CLicense*)lParam2)
  594. VALIDATE_OBJECT(pLicense1, CLicense);
  595. VALIDATE_OBJECT(pLicense2, CLicense);
  596. int iResult;
  597. switch (g_licenseColumnInfo.nSortedItem)
  598. {
  599. case LVID_DATE:
  600. iResult = pLicense1->m_lDate - pLicense2->m_lDate;
  601. break;
  602. case LVID_QUANTITY:
  603. iResult = pLicense1->GetQuantity() - pLicense2->GetQuantity();
  604. break;
  605. case LVID_ADMIN:
  606. iResult =pLicense1->m_strUser.CompareNoCase(pLicense2->m_strUser);
  607. break;
  608. case LVID_COMMENT:
  609. iResult = pLicense1->m_strDescription.CompareNoCase(pLicense2->m_strDescription);
  610. break;
  611. default:
  612. iResult = 0;
  613. break;
  614. }
  615. return g_licenseColumnInfo.bSortOrder ? -iResult : iResult;
  616. }