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.

911 lines
18 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. LPTSTR pszUniServerName = pController->GetName();
  189. LPTSTR 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. LPTSTR 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. LPTSTR 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. if (bIsActivated = CPropertyPage::OnSetActive())
  465. {
  466. if (IsLicenseInfoUpdated(*m_pUpdateHint) && !RefreshCtrls())
  467. {
  468. AbortPageIfNecessary(); // display error...
  469. }
  470. }
  471. return bIsActivated;
  472. }
  473. BOOL CProductPropertyPageLicenses::OnCommand(WPARAM wParam, LPARAM lParam)
  474. /*++
  475. Routine Description:
  476. Message handler for WM_COMMAND.
  477. Arguments:
  478. wParam - message specific.
  479. lParam - message specific.
  480. Return Values:
  481. Returns true if message processed.
  482. --*/
  483. {
  484. if (wParam == ID_INIT_CTRLS)
  485. {
  486. if (!m_bAreCtrlsInitialized)
  487. {
  488. InitCtrls();
  489. if (!RefreshCtrls())
  490. {
  491. AbortPageIfNecessary(); // display error...
  492. }
  493. }
  494. ::SafeEnableWindow(
  495. &m_delBtn,
  496. &m_licenseList,
  497. CDialog::GetFocus(),
  498. (BOOL)(m_nLicensesTotal > 0)
  499. );
  500. return TRUE; // processed...
  501. }
  502. return CDialog::OnCommand(wParam, lParam);
  503. }
  504. void CProductPropertyPageLicenses::OnColumnClickLicenses(NMHDR* pNMHDR, LRESULT* pResult)
  505. /*++
  506. Routine Description:
  507. Notification handler for LVN_COLUMNCLICK.
  508. Arguments:
  509. pNMHDR - notification header.
  510. pResult - return code.
  511. Return Values:
  512. None.
  513. --*/
  514. {
  515. g_licenseColumnInfo.bSortOrder = GetKeyState(VK_CONTROL) < 0;
  516. g_licenseColumnInfo.nSortedItem = ((NM_LISTVIEW*)pNMHDR)->iSubItem;
  517. m_licenseList.SortItems(CompareProductLicenses, 0); // use column info
  518. *pResult = 0;
  519. }
  520. void CProductPropertyPageLicenses::OnGetDispInfoLicenses(NMHDR* pNMHDR, LRESULT* pResult)
  521. /*++
  522. Routine Description:
  523. Notification handler for LVN_GETDISPINFO.
  524. Arguments:
  525. pNMHDR - notification header.
  526. pResult - return code.
  527. Return Values:
  528. None.
  529. --*/
  530. {
  531. LV_ITEM* plvItem = &((LV_DISPINFO*)pNMHDR)->item;
  532. ASSERT(plvItem);
  533. CLicense* pLicense = (CLicense*)plvItem->lParam;
  534. VALIDATE_OBJECT(pLicense, CLicense);
  535. switch (plvItem->iSubItem)
  536. {
  537. case LVID_SEPARATOR:
  538. {
  539. plvItem->iImage = 0;
  540. CString strLabel = _T("");
  541. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  542. }
  543. break;
  544. case LVID_DATE:
  545. {
  546. BSTR bstrDate = pLicense->GetDateString();
  547. if( bstrDate != NULL)
  548. {
  549. lstrcpyn(plvItem->pszText, bstrDate, plvItem->cchTextMax);
  550. SysFreeString(bstrDate);
  551. }
  552. else
  553. {
  554. lstrcpy(plvItem->pszText, L"");
  555. }
  556. }
  557. break;
  558. case LVID_QUANTITY:
  559. {
  560. CString strLabel;
  561. strLabel.Format(_T("%ld"), pLicense->m_lQuantity);
  562. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  563. }
  564. break;
  565. case LVID_ADMIN:
  566. lstrcpyn(plvItem->pszText, pLicense->m_strUser, plvItem->cchTextMax);
  567. break;
  568. case LVID_COMMENT:
  569. lstrcpyn(plvItem->pszText, pLicense->m_strDescription, plvItem->cchTextMax);
  570. break;
  571. }
  572. *pResult = 0;
  573. }
  574. int CALLBACK CompareProductLicenses(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  575. /*++
  576. Routine Description:
  577. Notification handler for LVM_SORTITEMS.
  578. Arguments:
  579. lParam1 - object to sort.
  580. lParam2 - object to sort.
  581. lParamSort - sort criteria.
  582. Return Values:
  583. Same as lstrcmp.
  584. --*/
  585. {
  586. #define pLicense1 ((CLicense*)lParam1)
  587. #define pLicense2 ((CLicense*)lParam2)
  588. VALIDATE_OBJECT(pLicense1, CLicense);
  589. VALIDATE_OBJECT(pLicense2, CLicense);
  590. int iResult;
  591. switch (g_licenseColumnInfo.nSortedItem)
  592. {
  593. case LVID_DATE:
  594. iResult = pLicense1->m_lDate - pLicense2->m_lDate;
  595. break;
  596. case LVID_QUANTITY:
  597. iResult = pLicense1->GetQuantity() - pLicense2->GetQuantity();
  598. break;
  599. case LVID_ADMIN:
  600. iResult =pLicense1->m_strUser.CompareNoCase(pLicense2->m_strUser);
  601. break;
  602. case LVID_COMMENT:
  603. iResult = pLicense1->m_strDescription.CompareNoCase(pLicense2->m_strDescription);
  604. break;
  605. default:
  606. iResult = 0;
  607. break;
  608. }
  609. return g_licenseColumnInfo.bSortOrder ? -iResult : iResult;
  610. }