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.

795 lines
14 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. lgrpdlg.cpp
  5. Abstract:
  6. License group dialog implementation.
  7. Author:
  8. Don Ryan (donryan) 03-Mar-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. Jeff Parham (jeffparh) 30-Jan-1996
  13. o Added new element to LV_COLUMN_ENTRY to differentiate the string
  14. used for the column header from the string used in the menus
  15. (so that the menu option can contain hot keys).
  16. --*/
  17. #include "stdafx.h"
  18. #include "llsmgr.h"
  19. #include "lgrpdlg.h"
  20. #include "nmapdlg.h"
  21. #include "mappsht.h"
  22. #define LVID_MAPPING 0
  23. #define LVID_LICENSES 1
  24. #define LVID_DESCRIPTION 2
  25. #define LVCX_MAPPING 35
  26. #define LVCX_LICENSES 20
  27. #define LVCX_DESCRIPTION -1
  28. static LV_COLUMN_INFO g_mappingColumnInfo = {
  29. 0, 0, 3,
  30. {{LVID_MAPPING, IDS_GROUP_NAME, 0, LVCX_MAPPING },
  31. {LVID_LICENSES, IDS_LICENSES, 0, LVCX_LICENSES },
  32. {LVID_DESCRIPTION, IDS_DESCRIPTION, 0, LVCX_DESCRIPTION}},
  33. };
  34. #ifdef _DEBUG
  35. #undef THIS_FILE
  36. static char BASED_CODE THIS_FILE[] = __FILE__;
  37. #endif
  38. BEGIN_MESSAGE_MAP(CLicenseGroupsDialog, CDialog)
  39. //{{AFX_MSG_MAP(CLicenseGroupsDialog)
  40. ON_BN_CLICKED(IDC_LICENSE_GROUPS_DELETE, OnDelete)
  41. ON_BN_CLICKED(IDC_LICENSE_GROUPS_EDIT, OnEdit)
  42. ON_BN_CLICKED(IDC_LICENSE_GROUPS_ADD, OnAdd)
  43. ON_NOTIFY(NM_DBLCLK, IDC_LICENSE_GROUPS_MAPPINGS, OnDblClkMappings)
  44. ON_NOTIFY(NM_RETURN, IDC_LICENSE_GROUPS_MAPPINGS, OnReturnMappings)
  45. ON_NOTIFY(NM_SETFOCUS, IDC_LICENSE_GROUPS_MAPPINGS, OnSetFocusMappings)
  46. ON_NOTIFY(NM_KILLFOCUS, IDC_LICENSE_GROUPS_MAPPINGS, OnKillFocusMappings)
  47. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LICENSE_GROUPS_MAPPINGS, OnColumnClickMappings)
  48. ON_NOTIFY(LVN_GETDISPINFO, IDC_LICENSE_GROUPS_MAPPINGS, OnGetDispInfoMappings)
  49. ON_COMMAND( ID_EDIT_DELETE , OnDelete )
  50. ON_WM_DESTROY()
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. CLicenseGroupsDialog::CLicenseGroupsDialog(CWnd* pParent /*=NULL*/)
  54. : CDialog(CLicenseGroupsDialog::IDD, pParent)
  55. /*++
  56. Routine Description:
  57. Constructor for license groups dialog.
  58. Arguments:
  59. pParent - parent window handle.
  60. Return Values:
  61. None.
  62. --*/
  63. {
  64. //{{AFX_DATA_INIT(CLicenseGroupsDialog)
  65. //}}AFX_DATA_INIT
  66. m_bAreCtrlsInitialized = FALSE;
  67. m_fUpdateHint = UPDATE_INFO_NONE;
  68. m_hAccel = ::LoadAccelerators( AfxGetInstanceHandle( ) ,
  69. MAKEINTRESOURCE( IDR_MAINFRAME ) );
  70. }
  71. void CLicenseGroupsDialog::DoDataExchange(CDataExchange* pDX)
  72. /*++
  73. Routine Description:
  74. Called by framework to exchange dialog data.
  75. Arguments:
  76. pDX - data exchange object.
  77. Return Values:
  78. None.
  79. --*/
  80. {
  81. CDialog::DoDataExchange(pDX);
  82. //{{AFX_DATA_MAP(CLicenseGroupsDialog)
  83. DDX_Control(pDX, IDC_LICENSE_GROUPS_ADD, m_addBtn);
  84. DDX_Control(pDX, IDC_LICENSE_GROUPS_DELETE, m_delBtn);
  85. DDX_Control(pDX, IDC_LICENSE_GROUPS_EDIT, m_edtBtn);
  86. DDX_Control(pDX, IDC_LICENSE_GROUPS_MAPPINGS, m_mappingList);
  87. //}}AFX_DATA_MAP
  88. }
  89. void CLicenseGroupsDialog::InitCtrls()
  90. /*++
  91. Routine Description:
  92. Initializes dialog controls.
  93. Arguments:
  94. None.
  95. Return Values:
  96. None.
  97. --*/
  98. {
  99. m_mappingList.SetFocus();
  100. m_delBtn.EnableWindow(FALSE);
  101. m_edtBtn.EnableWindow(FALSE);
  102. m_bAreCtrlsInitialized = TRUE;
  103. ::LvInitColumns(&m_mappingList, &g_mappingColumnInfo);
  104. }
  105. void CLicenseGroupsDialog::AbortDialogIfNecessary()
  106. /*++
  107. Routine Description:
  108. Displays status and aborts if connection lost.
  109. Arguments:
  110. None.
  111. Return Values:
  112. None.
  113. --*/
  114. {
  115. theApp.DisplayLastStatus();
  116. if (IsConnectionDropped(LlsGetLastStatus()))
  117. {
  118. AbortDialog(); // bail...
  119. }
  120. }
  121. void CLicenseGroupsDialog::AbortDialog()
  122. /*++
  123. Routine Description:
  124. Aborts dialog.
  125. Arguments:
  126. None.
  127. Return Values:
  128. None.
  129. --*/
  130. {
  131. m_fUpdateHint = UPDATE_INFO_ABORT;
  132. EndDialog(IDABORT);
  133. }
  134. BOOL CLicenseGroupsDialog::OnInitDialog()
  135. /*++
  136. Routine Description:
  137. Message handler for WM_INITDIALOG.
  138. Arguments:
  139. None.
  140. Return Values:
  141. Returns false if focus set manually.
  142. --*/
  143. {
  144. CDialog::OnInitDialog();
  145. SendMessage(WM_COMMAND, ID_INIT_CTRLS);
  146. return TRUE;
  147. }
  148. void CLicenseGroupsDialog::OnDestroy()
  149. /*++
  150. Routine Description:
  151. Message handler for WM_DESTROY.
  152. Arguments:
  153. None.
  154. Return Values:
  155. None.
  156. --*/
  157. {
  158. ::LvReleaseObArray(&m_mappingList); // release now...
  159. CDialog::OnDestroy();
  160. }
  161. BOOL CLicenseGroupsDialog::RefreshCtrls()
  162. /*++
  163. Routine Description:
  164. Refreshs dialog controls.
  165. Arguments:
  166. None.
  167. Return Values:
  168. Returns true if controls refreshed.
  169. --*/
  170. {
  171. CController* pController = (CController*)MKOBJ(LlsGetApp()->GetActiveController());
  172. VARIANT va;
  173. VariantInit(&va);
  174. BOOL bIsRefreshed = FALSE;
  175. BeginWaitCursor(); // hourglass...
  176. if (pController)
  177. {
  178. VALIDATE_OBJECT(pController, CController);
  179. CMappings* pMappings = (CMappings*)MKOBJ(pController->GetMappings(va));
  180. if (pMappings)
  181. {
  182. VALIDATE_OBJECT(pMappings, CMappings);
  183. bIsRefreshed = ::LvRefreshObArray(
  184. &m_mappingList,
  185. &g_mappingColumnInfo,
  186. pMappings->m_pObArray
  187. );
  188. pMappings->InternalRelease(); // add ref'd individually...
  189. }
  190. pController->InternalRelease(); // release now...
  191. }
  192. if (!bIsRefreshed)
  193. {
  194. ::LvReleaseObArray(&m_mappingList); // reset list now...
  195. }
  196. EndWaitCursor(); // hourglass...
  197. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  198. return bIsRefreshed;
  199. }
  200. BOOL CLicenseGroupsDialog::PreTranslateMessage( MSG *pMsg )
  201. {
  202. if( m_hAccel != NULL )
  203. {
  204. if( ::TranslateAccelerator( m_hWnd , m_hAccel , pMsg ) )
  205. {
  206. return TRUE;
  207. }
  208. }
  209. return CDialog::PreTranslateMessage( pMsg );
  210. }
  211. void CLicenseGroupsDialog::OnDelete()
  212. /*++
  213. Routine Description:
  214. Deletes specified mapping.
  215. Arguments:
  216. None.
  217. Return Values:
  218. None.
  219. --*/
  220. {
  221. CMapping* pMapping;
  222. pMapping = (CMapping*)::LvGetSelObj(&m_mappingList);
  223. if (NULL != pMapping)
  224. {
  225. VALIDATE_OBJECT(pMapping, CMapping);
  226. CString strConfirm;
  227. AfxFormatString1(
  228. strConfirm,
  229. IDP_CONFIRM_DELETE_GROUP,
  230. pMapping->m_strName
  231. );
  232. if (AfxMessageBox(strConfirm, MB_YESNO) != IDYES)
  233. return; // bail...
  234. NTSTATUS NtStatus;
  235. BeginWaitCursor(); // hourglass...
  236. NtStatus = ::LlsGroupDelete(
  237. LlsGetActiveHandle(),
  238. MKSTR(pMapping->m_strName)
  239. );
  240. EndWaitCursor(); // hourglass...
  241. if (NtStatus == STATUS_OBJECT_NAME_NOT_FOUND)
  242. NtStatus = STATUS_SUCCESS;
  243. LlsSetLastStatus(NtStatus); // called api...
  244. if (NT_SUCCESS(NtStatus))
  245. {
  246. m_fUpdateHint |= UPDATE_GROUP_DELETED;
  247. if (!RefreshCtrls())
  248. {
  249. AbortDialogIfNecessary(); // display error...
  250. }
  251. }
  252. else
  253. {
  254. AbortDialogIfNecessary(); // display error...
  255. }
  256. }
  257. }
  258. void CLicenseGroupsDialog::OnEdit()
  259. /*++
  260. Routine Description:
  261. View properties of mapping.
  262. Arguments:
  263. None.
  264. Return Values:
  265. None.
  266. --*/
  267. {
  268. CMapping* pMapping;
  269. pMapping = (CMapping*)::LvGetSelObj(&m_mappingList);
  270. if (NULL != pMapping)
  271. {
  272. VALIDATE_OBJECT(pMapping, CMapping);
  273. CString strTitle;
  274. AfxFormatString1(strTitle, IDS_PROPERTIES_OF, pMapping->m_strName);
  275. CMappingPropertySheet mappingProperties(strTitle);
  276. mappingProperties.InitPages(pMapping);
  277. mappingProperties.DoModal();
  278. m_fUpdateHint |= mappingProperties.m_fUpdateHint;
  279. if (IsUpdateAborted(mappingProperties.m_fUpdateHint))
  280. {
  281. AbortDialog(); // don't display error...
  282. }
  283. else if (IsGroupInfoUpdated(mappingProperties.m_fUpdateHint) && !RefreshCtrls())
  284. {
  285. AbortDialogIfNecessary(); // display error...
  286. }
  287. }
  288. }
  289. void CLicenseGroupsDialog::OnAdd()
  290. /*++
  291. Routine Description:
  292. Add a new mapping.
  293. Arguments:
  294. None.
  295. Return Values:
  296. None.
  297. --*/
  298. {
  299. CNewMappingDialog newmDlg;
  300. newmDlg.DoModal();
  301. if (IsUpdateAborted(newmDlg.m_fUpdateHint))
  302. {
  303. AbortDialog(); // don't display error...
  304. }
  305. else if (IsGroupInfoUpdated(newmDlg.m_fUpdateHint) && !RefreshCtrls())
  306. {
  307. AbortDialogIfNecessary(); // display error...
  308. }
  309. }
  310. void CLicenseGroupsDialog::OnDblClkMappings(NMHDR* pNMHDR, LRESULT* pResult)
  311. /*++
  312. Routine Description:
  313. Notification handler for NM_DLBCLK.
  314. Arguments:
  315. pNMHDR - notification header.
  316. pResult - return code.
  317. Return Values:
  318. None.
  319. --*/
  320. {
  321. UNREFERENCED_PARAMETER(pNMHDR);
  322. OnEdit();
  323. ASSERT(NULL != pResult);
  324. *pResult = 0;
  325. }
  326. void CLicenseGroupsDialog::OnReturnMappings(NMHDR* pNMHDR, LRESULT* pResult)
  327. /*++
  328. Routine Description:
  329. Notification handler for NM_RETURN.
  330. Arguments:
  331. pNMHDR - notification header.
  332. pResult - return code.
  333. Return Values:
  334. None.
  335. --*/
  336. {
  337. UNREFERENCED_PARAMETER(pNMHDR);
  338. OnEdit();
  339. ASSERT(NULL != pResult);
  340. *pResult = 0;
  341. }
  342. void CLicenseGroupsDialog::OnSetFocusMappings(NMHDR* pNMHDR, LRESULT* pResult)
  343. /*++
  344. Routine Description:
  345. Notification handler for NM_SETFOCUS.
  346. Arguments:
  347. pNMHDR - notification header.
  348. pResult - return code.
  349. Return Values:
  350. None.
  351. --*/
  352. {
  353. UNREFERENCED_PARAMETER(pNMHDR);
  354. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  355. ASSERT(NULL != pResult);
  356. *pResult = 0;
  357. }
  358. void CLicenseGroupsDialog::OnKillFocusMappings(NMHDR* pNMHDR, LRESULT* pResult)
  359. /*++
  360. Routine Description:
  361. Notification handler for NM_KILLFOCUS.
  362. Arguments:
  363. pNMHDR - notification header.
  364. pResult - return code.
  365. Return Values:
  366. None.
  367. --*/
  368. {
  369. UNREFERENCED_PARAMETER(pNMHDR);
  370. ::LvSelObjIfNecessary(&m_mappingList); // ensure selection...
  371. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  372. ASSERT(NULL != pResult);
  373. *pResult = 0;
  374. }
  375. BOOL CLicenseGroupsDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  376. /*++
  377. Routine Description:
  378. Message handler for WM_COMMAND.
  379. Arguments:
  380. wParam - message specific.
  381. lParam - message specific.
  382. Return Values:
  383. Returns true if message processed.
  384. --*/
  385. {
  386. if (wParam == ID_INIT_CTRLS)
  387. {
  388. if (!m_bAreCtrlsInitialized)
  389. {
  390. InitCtrls();
  391. if (!RefreshCtrls())
  392. {
  393. AbortDialogIfNecessary(); // display error...
  394. }
  395. }
  396. ::SafeEnableWindow(
  397. &m_delBtn,
  398. &m_addBtn,
  399. CDialog::GetFocus(),
  400. m_mappingList.GetItemCount()
  401. );
  402. ::SafeEnableWindow(
  403. &m_edtBtn,
  404. &m_addBtn,
  405. CDialog::GetFocus(),
  406. m_mappingList.GetItemCount()
  407. );
  408. return TRUE; // processed...
  409. }
  410. return CDialog::OnCommand(wParam, lParam);
  411. }
  412. void CLicenseGroupsDialog::OnColumnClickMappings(NMHDR* pNMHDR, LRESULT* pResult)
  413. /*++
  414. Routine Description:
  415. Notification handler for LVN_COLUMNCLICK.
  416. Arguments:
  417. pNMHDR - notification header.
  418. pResult - return code.
  419. Return Values:
  420. None.
  421. --*/
  422. {
  423. g_mappingColumnInfo.bSortOrder = GetKeyState(VK_CONTROL) < 0;
  424. ASSERT(NULL != pNMHDR);
  425. g_mappingColumnInfo.nSortedItem = ((NM_LISTVIEW*)pNMHDR)->iSubItem;
  426. m_mappingList.SortItems(CompareMappings, 0); // use column info
  427. ASSERT(NULL != pResult);
  428. *pResult = 0;
  429. }
  430. void CLicenseGroupsDialog::OnGetDispInfoMappings(NMHDR* pNMHDR, LRESULT* pResult)
  431. /*++
  432. Routine Description:
  433. Notification handler for LVN_GETDISPINFO.
  434. Arguments:
  435. pNMHDR - notification header.
  436. pResult - return code.
  437. Return Values:
  438. None.
  439. --*/
  440. {
  441. ASSERT(NULL != pNMHDR);
  442. LV_ITEM* plvItem = &((LV_DISPINFO*)pNMHDR)->item;
  443. ASSERT(plvItem);
  444. CMapping* pMapping = (CMapping*)plvItem->lParam;
  445. VALIDATE_OBJECT(pMapping, CMapping);
  446. switch (plvItem->iSubItem)
  447. {
  448. case LVID_MAPPING:
  449. plvItem->iImage = BMPI_LICENSE_GROUP;
  450. lstrcpyn(plvItem->pszText, pMapping->m_strName, plvItem->cchTextMax);
  451. break;
  452. case LVID_LICENSES:
  453. {
  454. CString strLabel;
  455. strLabel.Format(_T("%ld"), pMapping->m_lInUse);
  456. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  457. }
  458. break;
  459. case LVID_DESCRIPTION:
  460. lstrcpyn(plvItem->pszText, pMapping->m_strDescription, plvItem->cchTextMax);
  461. break;
  462. }
  463. ASSERT(NULL != pResult);
  464. *pResult = 0;
  465. }
  466. int CALLBACK CompareMappings(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  467. /*++
  468. Routine Description:
  469. Notification handler for LVM_SORTITEMS.
  470. Arguments:
  471. lParam1 - object to sort.
  472. lParam2 - object to sort.
  473. lParamSort - sort criteria.
  474. Return Values:
  475. Same as lstrcmp.
  476. --*/
  477. {
  478. UNREFERENCED_PARAMETER(lParamSort);
  479. #define pMapping1 ((CMapping*)lParam1)
  480. #define pMapping2 ((CMapping*)lParam2)
  481. VALIDATE_OBJECT(pMapping1, CMapping);
  482. VALIDATE_OBJECT(pMapping2, CMapping);
  483. int iResult;
  484. switch (g_mappingColumnInfo.nSortedItem)
  485. {
  486. case LVID_MAPPING:
  487. iResult = pMapping1->m_strName.CompareNoCase(pMapping2->m_strName);
  488. break;
  489. case LVID_LICENSES:
  490. iResult = pMapping1->m_lInUse - pMapping2->m_lInUse;
  491. break;
  492. case LVID_DESCRIPTION:
  493. iResult = pMapping1->m_strDescription.CompareNoCase(pMapping2->m_strDescription);
  494. break;
  495. default:
  496. iResult = 0;
  497. break;
  498. }
  499. return g_mappingColumnInfo.bSortOrder ? -iResult : iResult;
  500. }