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.

811 lines
14 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. prdppgs.cpp
  5. Abstract:
  6. Product property page (servers) 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 Added refresh when service info is updated.
  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 "prdppgs.h"
  21. #include "srvpsht.h"
  22. #define LVID_SERVER 0
  23. #define LVID_PURCHASED 1
  24. #define LVID_REACHED 2
  25. #define LVCX_SERVER 40
  26. #define LVCX_PURCHASED 30
  27. #define LVCX_REACHED -1
  28. static LV_COLUMN_INFO g_serverColumnInfo = {
  29. 0, 0, 3,
  30. {{LVID_SERVER, IDS_SERVER_NAME, 0, LVCX_SERVER },
  31. {LVID_PURCHASED, IDS_PURCHASED, 0, LVCX_PURCHASED},
  32. {LVID_REACHED, IDS_REACHED, 0, LVCX_REACHED }},
  33. };
  34. #ifdef _DEBUG
  35. #undef THIS_FILE
  36. static char BASED_CODE THIS_FILE[] = __FILE__;
  37. #endif
  38. IMPLEMENT_DYNCREATE(CProductPropertyPageServers, CPropertyPage)
  39. BEGIN_MESSAGE_MAP(CProductPropertyPageServers, CPropertyPage)
  40. //{{AFX_MSG_MAP(CProductPropertyPageServers)
  41. ON_BN_CLICKED(IDC_PP_PRODUCT_SERVERS_EDIT, OnEdit)
  42. ON_NOTIFY(NM_DBLCLK, IDC_PP_PRODUCT_SERVERS_SERVERS, OnDblClkServers)
  43. ON_NOTIFY(NM_RETURN, IDC_PP_PRODUCT_SERVERS_SERVERS, OnReturnServers)
  44. ON_NOTIFY(NM_SETFOCUS, IDC_PP_PRODUCT_SERVERS_SERVERS, OnSetFocusServers)
  45. ON_NOTIFY(NM_KILLFOCUS, IDC_PP_PRODUCT_SERVERS_SERVERS, OnKillFocusServers)
  46. ON_NOTIFY(LVN_COLUMNCLICK, IDC_PP_PRODUCT_SERVERS_SERVERS, OnColumnClickServers)
  47. ON_NOTIFY(LVN_GETDISPINFO, IDC_PP_PRODUCT_SERVERS_SERVERS, OnGetDispInfoServers)
  48. ON_WM_DESTROY()
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. CProductPropertyPageServers::CProductPropertyPageServers()
  52. : CPropertyPage(CProductPropertyPageServers::IDD)
  53. /*++
  54. Routine Description:
  55. Constructor for product property page (servers).
  56. Arguments:
  57. None.
  58. Return Values:
  59. None.
  60. --*/
  61. {
  62. //{{AFX_DATA_INIT(CProductPropertyPageServers)
  63. //}}AFX_DATA_INIT
  64. m_pProduct = NULL;
  65. m_pUpdateHint = NULL;
  66. m_bAreCtrlsInitialized = FALSE;
  67. }
  68. CProductPropertyPageServers::~CProductPropertyPageServers()
  69. /*++
  70. Routine Description:
  71. Destructor for product property page (servers).
  72. Arguments:
  73. None.
  74. Return Values:
  75. None.
  76. --*/
  77. {
  78. //
  79. // Nothing to do here...
  80. //
  81. }
  82. void CProductPropertyPageServers::DoDataExchange(CDataExchange* pDX)
  83. /*++
  84. Routine Description:
  85. Called by framework to exchange dialog data.
  86. Arguments:
  87. pDX - data exchange object.
  88. Return Values:
  89. None.
  90. --*/
  91. {
  92. CPropertyPage::DoDataExchange(pDX);
  93. //{{AFX_DATA_MAP(CProductPropertyPageServers)
  94. DDX_Control(pDX, IDC_PP_PRODUCT_SERVERS_EDIT, m_editBtn);
  95. DDX_Control(pDX, IDC_PP_PRODUCT_SERVERS_SERVERS, m_serverList);
  96. //}}AFX_DATA_MAP
  97. }
  98. void CProductPropertyPageServers::InitCtrls()
  99. /*++
  100. Routine Description:
  101. Initializes property page controls.
  102. Arguments:
  103. None.
  104. Return Values:
  105. None.
  106. --*/
  107. {
  108. m_serverList.SetFocus();
  109. m_editBtn.EnableWindow(FALSE);
  110. m_bAreCtrlsInitialized = TRUE;
  111. ::LvInitColumns(&m_serverList, &g_serverColumnInfo);
  112. }
  113. void CProductPropertyPageServers::InitPage(CProduct* pProduct, DWORD* pUpdateHint)
  114. /*++
  115. Routine Description:
  116. Initializes property page.
  117. Arguments:
  118. pProduct - product object.
  119. pUpdateHint - update hint.
  120. Return Values:
  121. None.
  122. --*/
  123. {
  124. ASSERT(pUpdateHint);
  125. VALIDATE_OBJECT(pProduct, CProduct);
  126. m_pProduct = pProduct;
  127. m_pUpdateHint = pUpdateHint;
  128. }
  129. void CProductPropertyPageServers::AbortPageIfNecessary()
  130. /*++
  131. Routine Description:
  132. Displays status and aborts if connection lost.
  133. Arguments:
  134. None.
  135. Return Values:
  136. None.
  137. --*/
  138. {
  139. theApp.DisplayLastStatus();
  140. if (IsConnectionDropped(LlsGetLastStatus()))
  141. {
  142. AbortPage(); // bail...
  143. }
  144. }
  145. void CProductPropertyPageServers::AbortPage()
  146. /*++
  147. Routine Description:
  148. Aborts property page.
  149. Arguments:
  150. None.
  151. Return Values:
  152. None.
  153. --*/
  154. {
  155. *m_pUpdateHint = UPDATE_INFO_ABORT;
  156. GetParent()->PostMessage(WM_COMMAND, IDCANCEL);
  157. }
  158. void CProductPropertyPageServers::OnEdit()
  159. /*++
  160. Routine Description:
  161. View properties of server.
  162. Arguments:
  163. None.
  164. Return Values:
  165. None.
  166. --*/
  167. {
  168. ViewServerProperties();
  169. }
  170. BOOL CProductPropertyPageServers::OnInitDialog()
  171. /*++
  172. Routine Description:
  173. Message handler for WM_INITDIALOG.
  174. Arguments:
  175. None.
  176. Return Values:
  177. Returns false if focus set to control manually.
  178. --*/
  179. {
  180. CPropertyPage::OnInitDialog();
  181. SendMessage(WM_COMMAND, ID_INIT_CTRLS);
  182. return TRUE;
  183. }
  184. void CProductPropertyPageServers::OnDestroy()
  185. /*++
  186. Routine Description:
  187. Message handler for WM_DESTROY.
  188. Arguments:
  189. None.
  190. Return Values:
  191. None.
  192. --*/
  193. {
  194. ::LvReleaseObArray(&m_serverList); // release now...
  195. CPropertyPage::OnDestroy();
  196. }
  197. BOOL CProductPropertyPageServers::OnSetActive()
  198. /*++
  199. Routine Description:
  200. Activates property page.
  201. Arguments:
  202. None.
  203. Return Values:
  204. Returns true if focus accepted.
  205. --*/
  206. {
  207. BOOL bIsActivated;
  208. bIsActivated = CPropertyPage::OnSetActive();
  209. if (FALSE != bIsActivated)
  210. {
  211. if ( ( IsServerInfoUpdated( *m_pUpdateHint )
  212. || IsServiceInfoUpdated( *m_pUpdateHint ) )
  213. && !RefreshCtrls() )
  214. {
  215. AbortPageIfNecessary(); // display error...
  216. }
  217. }
  218. return bIsActivated;
  219. }
  220. BOOL CProductPropertyPageServers::RefreshCtrls()
  221. /*++
  222. Routine Description:
  223. Refreshs property page controls.
  224. Arguments:
  225. None.
  226. Return Values:
  227. Returns true if controls refreshed.
  228. --*/
  229. {
  230. VALIDATE_OBJECT(m_pProduct, CProduct);
  231. BOOL bIsRefreshed = FALSE;
  232. VARIANT va;
  233. VariantInit(&va);
  234. BeginWaitCursor(); // hourglass...
  235. CServerStatistics* pStatistics = (CServerStatistics*)MKOBJ(m_pProduct->GetServerStatistics(va));
  236. if (pStatistics)
  237. {
  238. VALIDATE_OBJECT(pStatistics, CServerStatistics);
  239. bIsRefreshed = ::LvRefreshObArray(
  240. &m_serverList,
  241. &g_serverColumnInfo,
  242. pStatistics->m_pObArray
  243. );
  244. pStatistics->InternalRelease(); // add ref'd individually...
  245. }
  246. if (!bIsRefreshed)
  247. {
  248. ::LvReleaseObArray(&m_serverList); // reset list now...
  249. }
  250. EndWaitCursor(); // hourglass...
  251. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  252. return bIsRefreshed;
  253. }
  254. void CProductPropertyPageServers::ViewServerProperties()
  255. /*++
  256. Routine Description:
  257. View properties of server.
  258. Arguments:
  259. None.
  260. Return Values:
  261. None.
  262. --*/
  263. {
  264. CServerStatistic* pStatistic;
  265. pStatistic = (CServerStatistic*)::LvGetSelObj(&m_serverList);
  266. if (NULL != pStatistic)
  267. {
  268. VALIDATE_OBJECT(pStatistic, CServerStatistic);
  269. CServer* pServer = new CServer(NULL, pStatistic->m_strEntry);
  270. if (pServer)
  271. {
  272. CString strTitle;
  273. AfxFormatString1(strTitle, IDS_PROPERTIES_OF, pServer->m_strName);
  274. CServerPropertySheet serverProperties(strTitle);
  275. serverProperties.InitPages(pServer);
  276. serverProperties.DoModal();
  277. *m_pUpdateHint |= serverProperties.m_fUpdateHint;
  278. if (IsUpdateAborted(serverProperties.m_fUpdateHint))
  279. {
  280. AbortPage(); // don't display error...
  281. }
  282. else if ( ( IsServerInfoUpdated( serverProperties.m_fUpdateHint )
  283. || IsServiceInfoUpdated( serverProperties.m_fUpdateHint ) )
  284. && !RefreshCtrls() )
  285. {
  286. AbortPageIfNecessary(); // display error...
  287. }
  288. }
  289. else
  290. {
  291. AbortPageIfNecessary(); // display error...
  292. }
  293. if (pServer)
  294. pServer->InternalRelease(); // delete object...
  295. }
  296. }
  297. BOOL CProductPropertyPageServers::OnCommand(WPARAM wParam, LPARAM lParam)
  298. /*++
  299. Routine Description:
  300. Message handler for WM_COMMAND.
  301. Arguments:
  302. wParam - message specific.
  303. lParam - message specific.
  304. Return Values:
  305. Returns true if message processed.
  306. --*/
  307. {
  308. if (wParam == ID_INIT_CTRLS)
  309. {
  310. if (!m_bAreCtrlsInitialized)
  311. {
  312. InitCtrls();
  313. if (!RefreshCtrls())
  314. {
  315. AbortPageIfNecessary(); // display error...
  316. }
  317. }
  318. ::SafeEnableWindow(
  319. &m_editBtn,
  320. &m_serverList,
  321. CDialog::GetFocus(),
  322. m_serverList.GetItemCount()
  323. );
  324. return TRUE; // processed...
  325. }
  326. return CDialog::OnCommand(wParam, lParam);
  327. }
  328. void CProductPropertyPageServers::OnDblClkServers(NMHDR* pNMHDR, LRESULT* pResult)
  329. /*++
  330. Routine Description:
  331. Notification handler for NM_DBLCLK.
  332. Arguments:
  333. pNMHDR - notification header.
  334. pResult - return code.
  335. Return Values:
  336. None.
  337. --*/
  338. {
  339. UNREFERENCED_PARAMETER(pNMHDR);
  340. ViewServerProperties();
  341. ASSERT(NULL != pResult);
  342. *pResult = 0;
  343. }
  344. void CProductPropertyPageServers::OnReturnServers(NMHDR* pNMHDR, LRESULT* pResult)
  345. /*++
  346. Routine Description:
  347. Notification handler for NM_RETURN.
  348. Arguments:
  349. pNMHDR - notification header.
  350. pResult - return code.
  351. Return Values:
  352. None.
  353. --*/
  354. {
  355. UNREFERENCED_PARAMETER(pNMHDR);
  356. ViewServerProperties();
  357. ASSERT(NULL != pResult);
  358. *pResult = 0;
  359. }
  360. void CProductPropertyPageServers::OnSetFocusServers(NMHDR* pNMHDR, LRESULT* pResult)
  361. /*++
  362. Routine Description:
  363. Notification handler for NM_SETFOCUS.
  364. Arguments:
  365. pNMHDR - notification header.
  366. pResult - return code.
  367. Return Values:
  368. None.
  369. --*/
  370. {
  371. UNREFERENCED_PARAMETER(pNMHDR);
  372. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  373. ASSERT(NULL != pResult);
  374. *pResult = 0;
  375. }
  376. void CProductPropertyPageServers::OnKillFocusServers(NMHDR* pNMHDR, LRESULT* pResult)
  377. /*++
  378. Routine Description:
  379. Notification handler for NM_KILLFOCUS.
  380. Arguments:
  381. pNMHDR - notification header.
  382. pResult - return code.
  383. Return Values:
  384. None.
  385. --*/
  386. {
  387. UNREFERENCED_PARAMETER(pNMHDR);
  388. ::LvSelObjIfNecessary(&m_serverList); // ensure selection...
  389. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  390. ASSERT(NULL != pResult);
  391. *pResult = 0;
  392. }
  393. void CProductPropertyPageServers::OnColumnClickServers(NMHDR* pNMHDR, LRESULT* pResult)
  394. /*++
  395. Routine Description:
  396. Notification handler for LVN_COLUMNCLICK.
  397. Arguments:
  398. pNMHDR - notification header.
  399. pResult - return code.
  400. Return Values:
  401. None.
  402. --*/
  403. {
  404. g_serverColumnInfo.bSortOrder = GetKeyState(VK_CONTROL) < 0;
  405. ASSERT(NULL != pNMHDR);
  406. g_serverColumnInfo.nSortedItem = ((NM_LISTVIEW*)pNMHDR)->iSubItem;
  407. m_serverList.SortItems(CompareProductServers, 0); // use column info
  408. ASSERT(NULL != pResult);
  409. *pResult = 0;
  410. }
  411. void CProductPropertyPageServers::OnGetDispInfoServers(NMHDR* pNMHDR, LRESULT* pResult)
  412. /*++
  413. Routine Description:
  414. Notification handler for LVN_GETDISPINFO.
  415. Arguments:
  416. pNMHDR - notification header.
  417. pResult - return code.
  418. Return Values:
  419. None.
  420. --*/
  421. {
  422. ASSERT(NULL != pNMHDR);
  423. LV_ITEM* plvItem = &((LV_DISPINFO*)pNMHDR)->item;
  424. ASSERT(plvItem);
  425. CServerStatistic* pStatistic = (CServerStatistic*)plvItem->lParam;
  426. VALIDATE_OBJECT(pStatistic, CServerStatistic);
  427. switch (plvItem->iSubItem)
  428. {
  429. case LVID_SERVER:
  430. {
  431. if (pStatistic->m_bIsPerServer)
  432. {
  433. if ((pStatistic->GetMaxUses() <= pStatistic->GetHighMark()) && pStatistic->GetMaxUses())
  434. {
  435. plvItem->iImage = BMPI_WARNING_AT_LIMIT;
  436. }
  437. else
  438. {
  439. plvItem->iImage = BMPI_PRODUCT_PER_SERVER;
  440. }
  441. }
  442. else
  443. {
  444. plvItem->iImage = BMPI_PRODUCT_PER_SEAT;
  445. }
  446. lstrcpyn(plvItem->pszText, pStatistic->m_strEntry, plvItem->cchTextMax);
  447. }
  448. break;
  449. case LVID_PURCHASED:
  450. {
  451. CString strLabel;
  452. if (pStatistic->m_bIsPerServer)
  453. {
  454. strLabel.Format(_T("%ld"), pStatistic->GetMaxUses());
  455. }
  456. else
  457. {
  458. strLabel.LoadString(IDS_NOT_APPLICABLE);
  459. }
  460. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  461. }
  462. break;
  463. case LVID_REACHED:
  464. {
  465. CString strLabel;
  466. strLabel.Format(_T("%ld"), pStatistic->GetHighMark());
  467. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  468. }
  469. break;
  470. }
  471. ASSERT(NULL != pResult);
  472. *pResult = 0;
  473. }
  474. int CALLBACK CompareProductServers(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  475. /*++
  476. Routine Description:
  477. Notification handler for LVM_SORTITEMS.
  478. Arguments:
  479. lParam1 - object to sort.
  480. lParam2 - object to sort.
  481. lParamSort - sort criteria.
  482. Return Values:
  483. Same as lstrcmp.
  484. --*/
  485. {
  486. UNREFERENCED_PARAMETER(lParamSort);
  487. #define pStatistic1 ((CServerStatistic*)lParam1)
  488. #define pStatistic2 ((CServerStatistic*)lParam2)
  489. VALIDATE_OBJECT(pStatistic1, CServerStatistic);
  490. VALIDATE_OBJECT(pStatistic2, CServerStatistic);
  491. int iResult;
  492. switch (g_serverColumnInfo.nSortedItem)
  493. {
  494. case LVID_SERVER:
  495. iResult = pStatistic1->m_strEntry.CompareNoCase(pStatistic2->m_strEntry);
  496. break;
  497. case LVID_PURCHASED:
  498. iResult = pStatistic1->GetMaxUses() - pStatistic2->GetMaxUses();
  499. break;
  500. case LVID_REACHED:
  501. iResult = pStatistic1->GetHighMark() - pStatistic2->GetHighMark();
  502. break;
  503. default:
  504. iResult = 0;
  505. break;
  506. }
  507. return g_serverColumnInfo.bSortOrder ? -iResult : iResult;
  508. }