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.

896 lines
16 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. ausrdlg.cpp
  5. Abstract:
  6. Add user dialog implementation.
  7. Author:
  8. Don Ryan (donryan) 14-Feb-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 "ausrdlg.h"
  20. static LV_COLUMN_INFO g_userColumnInfo = {0, 0, 1, {0, 0, 0, -1}};
  21. static LV_COLUMN_INFO g_addedColumnInfo = {0, 0, 1, {0, 0, 0, -1}};
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26. BEGIN_MESSAGE_MAP(CAddUsersDialog, CDialog)
  27. //{{AFX_MSG_MAP(CAddUsersDialog)
  28. ON_CBN_DROPDOWN(IDC_ADD_USERS_DOMAINS, OnDropdownDomains)
  29. ON_BN_CLICKED(IDC_ADD_USERS_ADD, OnAdd)
  30. ON_BN_CLICKED(IDC_ADD_USERS_DELETE, OnDelete)
  31. ON_NOTIFY(NM_DBLCLK, IDC_ADD_USERS_ADD_USERS, OnDblclkAddUsers)
  32. ON_NOTIFY(NM_DBLCLK, IDC_ADD_USERS_USERS, OnDblclkUsers)
  33. ON_CBN_SELCHANGE(IDC_ADD_USERS_DOMAINS, OnSelchangeDomains)
  34. ON_NOTIFY(LVN_GETDISPINFO, IDC_ADD_USERS_USERS, OnGetdispinfoUsers)
  35. ON_NOTIFY(NM_KILLFOCUS, IDC_ADD_USERS_USERS, OnKillfocusUsers)
  36. ON_NOTIFY(NM_SETFOCUS, IDC_ADD_USERS_USERS, OnSetfocusUsers)
  37. ON_NOTIFY(NM_KILLFOCUS, IDC_ADD_USERS_ADD_USERS, OnKillfocusAddUsers)
  38. ON_NOTIFY(NM_SETFOCUS, IDC_ADD_USERS_ADD_USERS, OnSetfocusAddUsers)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. CAddUsersDialog::CAddUsersDialog(CWnd* pParent /*=NULL*/)
  42. : CDialog(CAddUsersDialog::IDD, pParent)
  43. /*++
  44. Routine Description:
  45. Constructor for add user dialog.
  46. Arguments:
  47. pParent - parent window handle.
  48. Return Values:
  49. None.
  50. --*/
  51. {
  52. //{{AFX_DATA_INIT(CAddUsersDialog)
  53. m_iDomain = -1;
  54. m_iIndex = 0;
  55. //}}AFX_DATA_INIT
  56. m_pObList = NULL;
  57. m_bIsDomainListExpanded = FALSE;
  58. m_bIsFocusUserList = FALSE;
  59. m_bIsFocusAddedList = FALSE;
  60. }
  61. void CAddUsersDialog::DoDataExchange(CDataExchange* pDX)
  62. /*++
  63. Routine Description:
  64. Called by framework to exchange dialog data.
  65. Arguments:
  66. pDX - data exchange object.
  67. Return Values:
  68. None.
  69. --*/
  70. {
  71. CDialog::DoDataExchange(pDX);
  72. //{{AFX_DATA_MAP(CAddUsersDialog)
  73. DDX_Control(pDX, IDC_ADD_USERS_ADD, m_addBtn);
  74. DDX_Control(pDX, IDC_ADD_USERS_DELETE, m_delBtn);
  75. DDX_Control(pDX, IDC_ADD_USERS_DOMAINS, m_domainList);
  76. DDX_Control(pDX, IDC_ADD_USERS_ADD_USERS, m_addedList);
  77. DDX_Control(pDX, IDC_ADD_USERS_USERS, m_userList);
  78. DDX_CBIndex(pDX, IDC_ADD_USERS_DOMAINS, m_iDomain);
  79. //}}AFX_DATA_MAP
  80. }
  81. void CAddUsersDialog::InitDialog(CObList* pObList)
  82. /*++
  83. Routine Description:
  84. Initializes return list.
  85. Arguments:
  86. pObList - pointer to return list.
  87. Return Values:
  88. None.
  89. --*/
  90. {
  91. ASSERT_VALID(pObList);
  92. m_pObList = pObList;
  93. }
  94. void CAddUsersDialog::InitDomainList()
  95. /*++
  96. Routine Description:
  97. Initializes list of domains.
  98. Arguments:
  99. None.
  100. Return Values:
  101. VT_BOOL.
  102. --*/
  103. {
  104. int iDomain;
  105. CString strLabel;
  106. strLabel.LoadString(IDS_DEFAULT_DOMAIN);
  107. if ((iDomain = m_domainList.AddString(strLabel)) != CB_ERR)
  108. {
  109. m_domainList.SetCurSel(iDomain);
  110. m_domainList.SetItemDataPtr(iDomain, (LPVOID)-1L);
  111. }
  112. else
  113. {
  114. theApp.DisplayStatus( STATUS_NO_MEMORY );
  115. }
  116. }
  117. void CAddUsersDialog::InitUserList()
  118. /*++
  119. Routine Description:
  120. Initializes list of users.
  121. Arguments:
  122. None.
  123. Return Values:
  124. None.
  125. --*/
  126. {
  127. ::LvInitColumns(&m_userList, &g_userColumnInfo);
  128. ::LvInitColumns(&m_addedList, &g_addedColumnInfo);
  129. }
  130. BOOL CAddUsersDialog::InsertDomains(CDomains* pDomains)
  131. /*++
  132. Routine Description:
  133. Inserts domains into domain list.
  134. Arguments:
  135. pDomains - domain collection.
  136. Return Values:
  137. None.
  138. --*/
  139. {
  140. NTSTATUS NtStatus = STATUS_SUCCESS;
  141. ASSERT_VALID(pDomains);
  142. if (pDomains)
  143. {
  144. VARIANT va;
  145. VariantInit(&va);
  146. CDomain* pDomain;
  147. int iDomain;
  148. int nDomains = pDomains->GetCount();
  149. for (va.vt = VT_I4, va.lVal = 0; (va.lVal < nDomains) && NT_SUCCESS(NtStatus); va.lVal++)
  150. {
  151. pDomain = (CDomain*)MKOBJ(pDomains->GetItem(va));
  152. ASSERT(pDomain && pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  153. if (pDomain)
  154. {
  155. if ((iDomain = m_domainList.AddString(pDomain->m_strName)) != CB_ERR)
  156. {
  157. m_domainList.SetItemDataPtr(iDomain, pDomain);
  158. }
  159. else
  160. {
  161. NtStatus = STATUS_NO_MEMORY;
  162. }
  163. pDomain->InternalRelease();
  164. }
  165. else
  166. {
  167. NtStatus = STATUS_NO_MEMORY;
  168. }
  169. }
  170. }
  171. else
  172. {
  173. NtStatus = STATUS_INVALID_PARAMETER;
  174. }
  175. if (NT_SUCCESS(NtStatus))
  176. {
  177. m_bIsDomainListExpanded = TRUE;
  178. }
  179. else
  180. {
  181. m_domainList.ResetContent();
  182. LlsSetLastStatus(NtStatus);
  183. }
  184. return m_bIsDomainListExpanded;
  185. }
  186. void CAddUsersDialog::OnAdd()
  187. /*++
  188. Routine Description:
  189. Message handler for IDC_ADD_USER_ADD.
  190. Arguments:
  191. None.
  192. Return Values:
  193. None.
  194. --*/
  195. {
  196. CUser* pUser;
  197. int iItem = -1;
  198. while (pUser = (CUser*)::LvGetNextObj(&m_userList, &iItem))
  199. {
  200. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  201. LV_FINDINFO lvFindInfo;
  202. lvFindInfo.flags = LVFI_STRING;
  203. lvFindInfo.psz = MKSTR(pUser->m_strName);
  204. if (m_addedList.FindItem(&lvFindInfo, -1) == -1)
  205. {
  206. //
  207. // Make a copy of the user (w/no parent)
  208. //
  209. CUser* pNewUser = new CUser(NULL, pUser->m_strName);
  210. if (pNewUser)
  211. {
  212. LV_ITEM lvItem;
  213. lvItem.mask = LVIF_TEXT|
  214. LVIF_PARAM|
  215. LVIF_IMAGE;
  216. lvItem.iSubItem = 0;
  217. lvItem.lParam = (LPARAM)(LPVOID)pNewUser;
  218. lvItem.iImage = BMPI_USER;
  219. lvItem.pszText = MKSTR(pNewUser->m_strName);
  220. lvItem.iItem = m_iIndex;
  221. m_addedList.InsertItem(&lvItem);
  222. m_iIndex++;
  223. }
  224. else
  225. {
  226. theApp.DisplayStatus( STATUS_NO_MEMORY );
  227. break;
  228. }
  229. }
  230. }
  231. m_userList.SetFocus();
  232. }
  233. void CAddUsersDialog::OnDblclkAddUsers(NMHDR* pNMHDR, LRESULT* pResult)
  234. /*++
  235. Routine Description:
  236. Notification handler for NM_DLBCLK.
  237. Arguments:
  238. pNMHDR - notification header.
  239. pResult - return code.
  240. Return Values:
  241. None.
  242. --*/
  243. {
  244. OnDelete();
  245. *pResult = 0;
  246. }
  247. void CAddUsersDialog::OnDblclkUsers(NMHDR* pNMHDR, LRESULT* pResult)
  248. /*++
  249. Routine Description:
  250. Notification handler for NM_DLBCLK.
  251. Arguments:
  252. pNMHDR - notification header.
  253. pResult - return code.
  254. Return Values:
  255. None.
  256. --*/
  257. {
  258. OnAdd();
  259. *pResult = 0;
  260. }
  261. void CAddUsersDialog::OnDelete()
  262. /*++
  263. Routine Description:
  264. Message handler for IDC_ADD_USER_DELETE.
  265. Arguments:
  266. None.
  267. Return Values:
  268. None.
  269. --*/
  270. {
  271. CUser* pUser;
  272. int iItem = -1;
  273. int iLastItem = 0;
  274. while (pUser = (CUser*)::LvGetNextObj(&m_addedList, &iItem))
  275. {
  276. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  277. pUser->InternalRelease(); // allocated above....
  278. m_addedList.DeleteItem(iItem);
  279. iLastItem = iItem;
  280. iItem = -1;
  281. m_iIndex--;
  282. }
  283. m_addedList.SetItemState(iLastItem, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  284. m_addedList.SetFocus();
  285. }
  286. void CAddUsersDialog::OnDropdownDomains()
  287. /*++
  288. Routine Description:
  289. Notification handler for CBN_DROPDOWN.
  290. Arguments:
  291. None.
  292. Return Values:
  293. None.
  294. --*/
  295. {
  296. if (m_bIsDomainListExpanded)
  297. return;
  298. NTSTATUS NtStatus = STATUS_SUCCESS;
  299. CDomains* pDomains;
  300. CDomain* pDomain;
  301. int iDomain;
  302. VARIANT va;
  303. VariantInit(&va);
  304. if (LlsGetApp()->IsFocusDomain())
  305. {
  306. pDomain = (CDomain*)MKOBJ(LlsGetApp()->GetActiveDomain());
  307. ASSERT(pDomain && pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  308. if (pDomain)
  309. {
  310. //
  311. // Expand to include trusted domains
  312. //
  313. pDomains = (CDomains*)MKOBJ(pDomain->GetTrustedDomains(va));
  314. if (pDomains && InsertDomains(pDomains))
  315. {
  316. //
  317. // Now add active domain itself...
  318. //
  319. if ((iDomain = m_domainList.AddString(pDomain->m_strName)) != CB_ERR)
  320. {
  321. m_domainList.SetItemDataPtr(iDomain, pDomain);
  322. }
  323. else
  324. {
  325. NtStatus = STATUS_NO_MEMORY;
  326. }
  327. }
  328. else
  329. {
  330. NtStatus = LlsGetLastStatus();
  331. }
  332. if (pDomains)
  333. pDomains->InternalRelease();
  334. pDomain->InternalRelease();
  335. }
  336. else
  337. {
  338. NtStatus = LlsGetLastStatus();
  339. }
  340. }
  341. else
  342. {
  343. pDomain = (CDomain*)MKOBJ(LlsGetApp()->GetLocalDomain());
  344. ASSERT(pDomain && pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  345. if (pDomain)
  346. {
  347. //
  348. // Expand to include all domains
  349. //
  350. pDomains = (CDomains*)MKOBJ(LlsGetApp()->GetDomains(va));
  351. if (pDomains && InsertDomains(pDomains))
  352. {
  353. //
  354. // CODEWORK... scroll to local domain???
  355. //
  356. }
  357. else
  358. {
  359. NtStatus = LlsGetLastStatus();
  360. }
  361. if (pDomains)
  362. pDomains->InternalRelease();
  363. pDomain->InternalRelease();
  364. }
  365. else
  366. {
  367. NtStatus = LlsGetLastStatus();
  368. }
  369. }
  370. if (!NT_SUCCESS(NtStatus))
  371. {
  372. theApp.DisplayStatus(NtStatus);
  373. m_domainList.ResetContent();
  374. }
  375. }
  376. BOOL CAddUsersDialog::OnInitDialog()
  377. /*++
  378. Routine Description:
  379. Message handler for WM_INITDIALOG.
  380. Arguments:
  381. None.
  382. Return Values:
  383. None.
  384. --*/
  385. {
  386. BeginWaitCursor();
  387. CDialog::OnInitDialog();
  388. InitUserList(); // always construct headers...
  389. InitDomainList();
  390. m_addBtn.EnableWindow(FALSE);
  391. m_delBtn.EnableWindow(FALSE);
  392. if (!RefreshUserList())
  393. theApp.DisplayLastStatus();
  394. m_domainList.SetFocus();
  395. EndWaitCursor();
  396. return FALSE; // set focus to domain list
  397. }
  398. void CAddUsersDialog::OnSelchangeDomains()
  399. /*++
  400. Routine Description:
  401. Message handler for CBN_SELCHANGED.
  402. Arguments:
  403. None.
  404. Return Values:
  405. None.
  406. --*/
  407. {
  408. RefreshUserList();
  409. }
  410. BOOL CAddUsersDialog::RefreshUserList()
  411. /*++
  412. Routine Description:
  413. Refreshs list of users (with currently selected item).
  414. Arguments:
  415. None.
  416. Return Values:
  417. VT_BOOL.
  418. --*/
  419. {
  420. NTSTATUS NtStatus = STATUS_SUCCESS;
  421. m_userList.DeleteAllItems();
  422. int iDomain;
  423. if ((iDomain = m_domainList.GetCurSel()) != CB_ERR)
  424. {
  425. CDomain* pDomain = (CDomain*)m_domainList.GetItemDataPtr(iDomain);
  426. CUsers* pUsers = (CUsers*)NULL;
  427. VARIANT va;
  428. VariantInit(&va);
  429. if (pDomain == (CDomain*)-1L)
  430. {
  431. //
  432. // Enumerate users in license cache...
  433. //
  434. CController* pController = (CController*)MKOBJ(LlsGetApp()->GetActiveController());
  435. if ( pController )
  436. {
  437. pController->InternalRelease(); // held open by CApplication
  438. pUsers = pController->m_pUsers;
  439. pUsers->InternalAddRef(); // released below...
  440. }
  441. }
  442. else
  443. {
  444. //
  445. // Enumerate users in particular domain...
  446. //
  447. ASSERT(pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  448. pUsers = (CUsers*)MKOBJ(pDomain->GetUsers(va));
  449. ASSERT(pUsers && pUsers->IsKindOf(RUNTIME_CLASS(CUsers)));
  450. }
  451. if (pUsers)
  452. {
  453. CUser* pUser;
  454. int nUsers = pUsers->GetCount();
  455. LV_ITEM lvItem;
  456. lvItem.mask = LVIF_TEXT|
  457. LVIF_PARAM|
  458. LVIF_IMAGE;
  459. lvItem.iSubItem = 0;
  460. lvItem.pszText = LPSTR_TEXTCALLBACK;
  461. lvItem.cchTextMax = LPSTR_TEXTCALLBACK_MAX;
  462. lvItem.iImage = BMPI_USER;
  463. for (va.vt = VT_I4, va.lVal = 0; (va.lVal < nUsers) && NT_SUCCESS(NtStatus); va.lVal++)
  464. {
  465. pUser = (CUser*)MKOBJ(pUsers->GetItem(va));
  466. ASSERT(pUser && pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  467. if (pUser)
  468. {
  469. lvItem.iItem = va.lVal;
  470. lvItem.lParam = (LPARAM)(LPVOID)pUser;
  471. if (m_userList.InsertItem(&lvItem) == -1)
  472. {
  473. NtStatus = STATUS_NO_MEMORY;
  474. }
  475. pUser->InternalRelease();
  476. }
  477. else
  478. {
  479. NtStatus = STATUS_NO_MEMORY;
  480. }
  481. }
  482. pUsers->InternalRelease();
  483. }
  484. else
  485. {
  486. NtStatus = LlsGetLastStatus();
  487. }
  488. VariantClear(&va);
  489. }
  490. else
  491. {
  492. NtStatus = STATUS_NO_MEMORY;
  493. }
  494. if (!NT_SUCCESS(NtStatus))
  495. {
  496. m_userList.DeleteAllItems();
  497. LlsSetLastStatus(NtStatus);
  498. }
  499. ::LvResizeColumns(&m_userList, &g_userColumnInfo);
  500. return NT_SUCCESS(NtStatus);
  501. }
  502. void CAddUsersDialog::OnOK()
  503. /*++
  504. Routine Description:
  505. Message handler for IDOK.
  506. Arguments:
  507. None.
  508. Return Values:
  509. None.
  510. --*/
  511. {
  512. if (m_pObList)
  513. {
  514. CUser* pUser;
  515. int iItem = -1;
  516. m_pObList->RemoveAll();
  517. while (pUser = (CUser*)::LvGetNextObj(&m_addedList, &iItem, LVNI_ALL))
  518. {
  519. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  520. m_pObList->AddTail(pUser);
  521. }
  522. }
  523. CDialog::OnOK();
  524. }
  525. void CAddUsersDialog::OnCancel()
  526. /*++
  527. Routine Description:
  528. Message handler for IDCANCEL.
  529. Arguments:
  530. None.
  531. Return Values:
  532. None.
  533. --*/
  534. {
  535. CUser* pUser;
  536. int iItem = -1;
  537. while (pUser = (CUser*)::LvGetNextObj(&m_addedList, &iItem, LVNI_ALL))
  538. {
  539. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  540. pUser->InternalRelease();
  541. }
  542. CDialog::OnCancel();
  543. }
  544. void CAddUsersDialog::InitDialogCtrls()
  545. {
  546. int iItem = -1;
  547. if (m_bIsFocusUserList && m_userList.GetItemCount())
  548. {
  549. m_addBtn.EnableWindow(TRUE);
  550. m_delBtn.EnableWindow(FALSE);
  551. }
  552. else if (m_bIsFocusAddedList && m_addedList.GetItemCount())
  553. {
  554. m_addBtn.EnableWindow(FALSE);
  555. m_delBtn.EnableWindow(TRUE);
  556. }
  557. else
  558. {
  559. m_addBtn.EnableWindow(FALSE);
  560. m_delBtn.EnableWindow(FALSE);
  561. }
  562. ::LvResizeColumns(&m_userList, &g_userColumnInfo);
  563. ::LvResizeColumns(&m_addedList, &g_addedColumnInfo);
  564. }
  565. void CAddUsersDialog::OnGetdispinfoUsers(NMHDR* pNMHDR, LRESULT* pResult)
  566. {
  567. LV_ITEM lvItem = ((LV_DISPINFO*)pNMHDR)->item;
  568. if (lvItem.iSubItem == 0)
  569. {
  570. CUser* pUser = (CUser*)lvItem.lParam;
  571. ASSERT(pUser && pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  572. lstrcpyn(lvItem.pszText, pUser->m_strName, lvItem.cchTextMax);
  573. }
  574. *pResult = 0;
  575. }
  576. void CAddUsersDialog::OnKillfocusUsers(NMHDR* pNMHDR, LRESULT* pResult)
  577. {
  578. *pResult = 0;
  579. }
  580. void CAddUsersDialog::OnSetfocusUsers(NMHDR* pNMHDR, LRESULT* pResult)
  581. {
  582. m_bIsFocusUserList = TRUE;
  583. m_bIsFocusAddedList = FALSE;
  584. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  585. *pResult = 0;
  586. }
  587. void CAddUsersDialog::OnKillfocusAddUsers(NMHDR* pNMHDR, LRESULT* pResult)
  588. {
  589. *pResult = 0;
  590. }
  591. void CAddUsersDialog::OnSetfocusAddUsers(NMHDR* pNMHDR, LRESULT* pResult)
  592. {
  593. m_bIsFocusUserList = FALSE;
  594. m_bIsFocusAddedList = TRUE;
  595. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  596. *pResult = 0;
  597. }
  598. BOOL CAddUsersDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  599. {
  600. if (wParam == ID_INIT_CTRLS)
  601. {
  602. InitDialogCtrls();
  603. return TRUE; // processed...
  604. }
  605. return CDialog::OnCommand(wParam, lParam);
  606. }