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.

775 lines
13 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. if (pMapping = (CMapping*)::LvGetSelObj(&m_mappingList))
  223. {
  224. VALIDATE_OBJECT(pMapping, CMapping);
  225. CString strConfirm;
  226. AfxFormatString1(
  227. strConfirm,
  228. IDP_CONFIRM_DELETE_GROUP,
  229. pMapping->m_strName
  230. );
  231. if (AfxMessageBox(strConfirm, MB_YESNO) != IDYES)
  232. return; // bail...
  233. NTSTATUS NtStatus;
  234. BeginWaitCursor(); // hourglass...
  235. NtStatus = ::LlsGroupDelete(
  236. LlsGetActiveHandle(),
  237. MKSTR(pMapping->m_strName)
  238. );
  239. EndWaitCursor(); // hourglass...
  240. if (NtStatus == STATUS_OBJECT_NAME_NOT_FOUND)
  241. NtStatus = STATUS_SUCCESS;
  242. LlsSetLastStatus(NtStatus); // called api...
  243. if (NT_SUCCESS(NtStatus))
  244. {
  245. m_fUpdateHint |= UPDATE_GROUP_DELETED;
  246. if (!RefreshCtrls())
  247. {
  248. AbortDialogIfNecessary(); // display error...
  249. }
  250. }
  251. else
  252. {
  253. AbortDialogIfNecessary(); // display error...
  254. }
  255. }
  256. }
  257. void CLicenseGroupsDialog::OnEdit()
  258. /*++
  259. Routine Description:
  260. View properties of mapping.
  261. Arguments:
  262. None.
  263. Return Values:
  264. None.
  265. --*/
  266. {
  267. CMapping* pMapping;
  268. if (pMapping = (CMapping*)::LvGetSelObj(&m_mappingList))
  269. {
  270. VALIDATE_OBJECT(pMapping, CMapping);
  271. CString strTitle;
  272. AfxFormatString1(strTitle, IDS_PROPERTIES_OF, pMapping->m_strName);
  273. CMappingPropertySheet mappingProperties(strTitle);
  274. mappingProperties.InitPages(pMapping);
  275. mappingProperties.DoModal();
  276. m_fUpdateHint |= mappingProperties.m_fUpdateHint;
  277. if (IsUpdateAborted(mappingProperties.m_fUpdateHint))
  278. {
  279. AbortDialog(); // don't display error...
  280. }
  281. else if (IsGroupInfoUpdated(mappingProperties.m_fUpdateHint) && !RefreshCtrls())
  282. {
  283. AbortDialogIfNecessary(); // display error...
  284. }
  285. }
  286. }
  287. void CLicenseGroupsDialog::OnAdd()
  288. /*++
  289. Routine Description:
  290. Add a new mapping.
  291. Arguments:
  292. None.
  293. Return Values:
  294. None.
  295. --*/
  296. {
  297. CNewMappingDialog newmDlg;
  298. newmDlg.DoModal();
  299. if (IsUpdateAborted(newmDlg.m_fUpdateHint))
  300. {
  301. AbortDialog(); // don't display error...
  302. }
  303. else if (IsGroupInfoUpdated(newmDlg.m_fUpdateHint) && !RefreshCtrls())
  304. {
  305. AbortDialogIfNecessary(); // display error...
  306. }
  307. }
  308. void CLicenseGroupsDialog::OnDblClkMappings(NMHDR* pNMHDR, LRESULT* pResult)
  309. /*++
  310. Routine Description:
  311. Notification handler for NM_DLBCLK.
  312. Arguments:
  313. pNMHDR - notification header.
  314. pResult - return code.
  315. Return Values:
  316. None.
  317. --*/
  318. {
  319. OnEdit();
  320. *pResult = 0;
  321. }
  322. void CLicenseGroupsDialog::OnReturnMappings(NMHDR* pNMHDR, LRESULT* pResult)
  323. /*++
  324. Routine Description:
  325. Notification handler for NM_RETURN.
  326. Arguments:
  327. pNMHDR - notification header.
  328. pResult - return code.
  329. Return Values:
  330. None.
  331. --*/
  332. {
  333. OnEdit();
  334. *pResult = 0;
  335. }
  336. void CLicenseGroupsDialog::OnSetFocusMappings(NMHDR* pNMHDR, LRESULT* pResult)
  337. /*++
  338. Routine Description:
  339. Notification handler for NM_SETFOCUS.
  340. Arguments:
  341. pNMHDR - notification header.
  342. pResult - return code.
  343. Return Values:
  344. None.
  345. --*/
  346. {
  347. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  348. *pResult = 0;
  349. }
  350. void CLicenseGroupsDialog::OnKillFocusMappings(NMHDR* pNMHDR, LRESULT* pResult)
  351. /*++
  352. Routine Description:
  353. Notification handler for NM_KILLFOCUS.
  354. Arguments:
  355. pNMHDR - notification header.
  356. pResult - return code.
  357. Return Values:
  358. None.
  359. --*/
  360. {
  361. ::LvSelObjIfNecessary(&m_mappingList); // ensure selection...
  362. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  363. *pResult = 0;
  364. }
  365. BOOL CLicenseGroupsDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  366. /*++
  367. Routine Description:
  368. Message handler for WM_COMMAND.
  369. Arguments:
  370. wParam - message specific.
  371. lParam - message specific.
  372. Return Values:
  373. Returns true if message processed.
  374. --*/
  375. {
  376. if (wParam == ID_INIT_CTRLS)
  377. {
  378. if (!m_bAreCtrlsInitialized)
  379. {
  380. InitCtrls();
  381. if (!RefreshCtrls())
  382. {
  383. AbortDialogIfNecessary(); // display error...
  384. }
  385. }
  386. ::SafeEnableWindow(
  387. &m_delBtn,
  388. &m_addBtn,
  389. CDialog::GetFocus(),
  390. m_mappingList.GetItemCount()
  391. );
  392. ::SafeEnableWindow(
  393. &m_edtBtn,
  394. &m_addBtn,
  395. CDialog::GetFocus(),
  396. m_mappingList.GetItemCount()
  397. );
  398. return TRUE; // processed...
  399. }
  400. return CDialog::OnCommand(wParam, lParam);
  401. }
  402. void CLicenseGroupsDialog::OnColumnClickMappings(NMHDR* pNMHDR, LRESULT* pResult)
  403. /*++
  404. Routine Description:
  405. Notification handler for LVN_COLUMNCLICK.
  406. Arguments:
  407. pNMHDR - notification header.
  408. pResult - return code.
  409. Return Values:
  410. None.
  411. --*/
  412. {
  413. g_mappingColumnInfo.bSortOrder = GetKeyState(VK_CONTROL) < 0;
  414. g_mappingColumnInfo.nSortedItem = ((NM_LISTVIEW*)pNMHDR)->iSubItem;
  415. m_mappingList.SortItems(CompareMappings, 0); // use column info
  416. *pResult = 0;
  417. }
  418. void CLicenseGroupsDialog::OnGetDispInfoMappings(NMHDR* pNMHDR, LRESULT* pResult)
  419. /*++
  420. Routine Description:
  421. Notification handler for LVN_GETDISPINFO.
  422. Arguments:
  423. pNMHDR - notification header.
  424. pResult - return code.
  425. Return Values:
  426. None.
  427. --*/
  428. {
  429. LV_ITEM* plvItem = &((LV_DISPINFO*)pNMHDR)->item;
  430. ASSERT(plvItem);
  431. CMapping* pMapping = (CMapping*)plvItem->lParam;
  432. VALIDATE_OBJECT(pMapping, CMapping);
  433. switch (plvItem->iSubItem)
  434. {
  435. case LVID_MAPPING:
  436. plvItem->iImage = BMPI_LICENSE_GROUP;
  437. lstrcpyn(plvItem->pszText, pMapping->m_strName, plvItem->cchTextMax);
  438. break;
  439. case LVID_LICENSES:
  440. {
  441. CString strLabel;
  442. strLabel.Format(_T("%ld"), pMapping->m_lInUse);
  443. lstrcpyn(plvItem->pszText, strLabel, plvItem->cchTextMax);
  444. }
  445. break;
  446. case LVID_DESCRIPTION:
  447. lstrcpyn(plvItem->pszText, pMapping->m_strDescription, plvItem->cchTextMax);
  448. break;
  449. }
  450. *pResult = 0;
  451. }
  452. int CALLBACK CompareMappings(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  453. /*++
  454. Routine Description:
  455. Notification handler for LVM_SORTITEMS.
  456. Arguments:
  457. lParam1 - object to sort.
  458. lParam2 - object to sort.
  459. lParamSort - sort criteria.
  460. Return Values:
  461. Same as lstrcmp.
  462. --*/
  463. {
  464. #define pMapping1 ((CMapping*)lParam1)
  465. #define pMapping2 ((CMapping*)lParam2)
  466. VALIDATE_OBJECT(pMapping1, CMapping);
  467. VALIDATE_OBJECT(pMapping2, CMapping);
  468. int iResult;
  469. switch (g_mappingColumnInfo.nSortedItem)
  470. {
  471. case LVID_MAPPING:
  472. iResult = pMapping1->m_strName.CompareNoCase(pMapping2->m_strName);
  473. break;
  474. case LVID_LICENSES:
  475. iResult = pMapping1->m_lInUse - pMapping2->m_lInUse;
  476. break;
  477. case LVID_DESCRIPTION:
  478. iResult = pMapping1->m_strDescription.CompareNoCase(pMapping2->m_strDescription);
  479. break;
  480. default:
  481. iResult = 0;
  482. break;
  483. }
  484. return g_mappingColumnInfo.bSortOrder ? -iResult : iResult;
  485. }