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.

687 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. nmapdlg.cpp
  5. Abstract:
  6. New mapping dialog 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 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 "nmapdlg.h"
  20. #include "ausrdlg.h"
  21. #include "mainfrm.h"
  22. static LV_COLUMN_INFO g_userColumnInfo = {0, 0, 1, {0, 0, 0, -1}};
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char BASED_CODE THIS_FILE[] = __FILE__;
  26. #endif
  27. BEGIN_MESSAGE_MAP(CNewMappingDialog, CDialog)
  28. //{{AFX_MSG_MAP(CNewMappingDialog)
  29. ON_BN_CLICKED(IDC_NEW_MAPPING_ADD, OnAdd)
  30. ON_BN_CLICKED(IDC_NEW_MAPPING_DELETE, OnDelete)
  31. ON_NOTIFY(NM_SETFOCUS, IDC_NEW_MAPPING_USERS, OnSetFocusUsers)
  32. ON_NOTIFY(NM_KILLFOCUS, IDC_NEW_MAPPING_USERS, OnKillFocusUsers)
  33. ON_NOTIFY(UDN_DELTAPOS, IDC_NEW_MAPPING_SPIN, OnDeltaPosSpin)
  34. ON_EN_UPDATE(IDC_NEW_MAPPING_LICENSES, OnUpdateQuantity)
  35. ON_WM_DESTROY()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. CNewMappingDialog::CNewMappingDialog(CWnd* pParent /*=NULL*/)
  39. : CDialog(CNewMappingDialog::IDD, pParent)
  40. /*++
  41. Routine Description:
  42. Constructor for dialog.
  43. Arguments:
  44. None.
  45. Return Values:
  46. None.
  47. --*/
  48. {
  49. //{{AFX_DATA_INIT(CNewMappingDialog)
  50. m_strDescription = _T("");
  51. m_strName = _T("");
  52. m_nLicenses = 0;
  53. m_nLicensesMin = 0;
  54. //}}AFX_DATA_INIT
  55. m_bAreCtrlsInitialized = FALSE;
  56. m_fUpdateHint = UPDATE_INFO_NONE;
  57. }
  58. void CNewMappingDialog::DoDataExchange(CDataExchange* pDX)
  59. /*++
  60. Routine Description:
  61. Called by framework to exchange dialog data.
  62. Arguments:
  63. pDX - data exchange object.
  64. Return Values:
  65. None.
  66. --*/
  67. {
  68. CDialog::DoDataExchange(pDX);
  69. //{{AFX_DATA_MAP(CNewMappingDialog)
  70. DDX_Control(pDX, IDC_NEW_MAPPING_DESCRIPTION, m_desEdit);
  71. DDX_Control(pDX, IDC_NEW_MAPPING_ADD, m_addBtn);
  72. DDX_Control(pDX, IDC_NEW_MAPPING_DELETE, m_delBtn);
  73. DDX_Control(pDX, IDC_NEW_MAPPING_SPIN, m_spinCtrl);
  74. DDX_Control(pDX, IDC_NEW_MAPPING_USERS, m_userList);
  75. DDX_Control(pDX, IDC_NEW_MAPPING_NAME, m_userEdit);
  76. DDX_Control(pDX, IDC_NEW_MAPPING_LICENSES, m_licEdit);
  77. DDX_Text(pDX, IDC_NEW_MAPPING_DESCRIPTION, m_strDescription);
  78. DDX_Text(pDX, IDC_NEW_MAPPING_NAME, m_strName);
  79. DDX_Text(pDX, IDC_NEW_MAPPING_LICENSES, m_nLicenses);
  80. DDV_MinMaxLong(pDX, m_nLicenses, m_nLicensesMin, 999999);
  81. //}}AFX_DATA_MAP
  82. }
  83. void CNewMappingDialog::InitCtrls()
  84. /*++
  85. Routine Description:
  86. Initializes dialog controls.
  87. Arguments:
  88. None.
  89. Return Values:
  90. None.
  91. --*/
  92. {
  93. m_userEdit.SetFocus();
  94. m_delBtn.EnableWindow(FALSE);
  95. m_spinCtrl.SetRange(0, UD_MAXVAL);
  96. m_licEdit.LimitText(6);
  97. m_desEdit.LimitText(256);
  98. m_userEdit.LimitText(256);
  99. m_bAreCtrlsInitialized = TRUE;
  100. ::LvInitColumns(&m_userList, &g_userColumnInfo);
  101. }
  102. void CNewMappingDialog::AbortDialogIfNecessary()
  103. /*++
  104. Routine Description:
  105. Displays status and aborts if connection lost.
  106. Arguments:
  107. None.
  108. Return Values:
  109. None.
  110. --*/
  111. {
  112. theApp.DisplayLastStatus();
  113. if (IsConnectionDropped(LlsGetLastStatus()))
  114. {
  115. AbortDialog(); // bail...
  116. }
  117. }
  118. void CNewMappingDialog::AbortDialog()
  119. /*++
  120. Routine Description:
  121. Aborts dialog.
  122. Arguments:
  123. None.
  124. Return Values:
  125. None.
  126. --*/
  127. {
  128. m_fUpdateHint = UPDATE_INFO_ABORT;
  129. EndDialog(IDABORT);
  130. }
  131. BOOL CNewMappingDialog::OnInitDialog()
  132. /*++
  133. Routine Description:
  134. Message handler for WM_INITDIALOG.
  135. Arguments:
  136. None.
  137. Return Values:
  138. Returns false if focus set to control manually.
  139. --*/
  140. {
  141. CDialog::OnInitDialog();
  142. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  143. return TRUE;
  144. }
  145. void CNewMappingDialog::OnDestroy()
  146. /*++
  147. Routine Description:
  148. Message handler for WM_DESTROY.
  149. Arguments:
  150. None.
  151. Return Values:
  152. None.
  153. --*/
  154. {
  155. ::LvReleaseObArray(&m_userList); // release now...
  156. CDialog::OnDestroy();
  157. }
  158. BOOL CNewMappingDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  159. /*++
  160. Routine Description:
  161. Message handler for WM_COMMAND.
  162. Arguments:
  163. wParam - message specific.
  164. lParam - message specific.
  165. Return Values:
  166. Returns true if message processed.
  167. --*/
  168. {
  169. if (wParam == ID_INIT_CTRLS)
  170. {
  171. if (!m_bAreCtrlsInitialized)
  172. {
  173. InitCtrls();
  174. }
  175. ::SafeEnableWindow(
  176. &m_delBtn,
  177. &m_addBtn,
  178. CDialog::GetFocus(),
  179. m_userList.GetItemCount()
  180. );
  181. ::LvResizeColumns(&m_userList, &g_userColumnInfo);
  182. return TRUE; // processed...
  183. }
  184. return CDialog::OnCommand(wParam, lParam);
  185. }
  186. void CNewMappingDialog::OnAdd()
  187. /*++
  188. Routine Description:
  189. Adds new users to mapping.
  190. Arguments:
  191. None.
  192. Return Values:
  193. None.
  194. --*/
  195. {
  196. CObList newUserList;
  197. CAddUsersDialog addDlg;
  198. addDlg.InitDialog(&newUserList);
  199. if (addDlg.DoModal() == IDOK)
  200. {
  201. int nUsers = m_userList.GetItemCount();
  202. while (!newUserList.IsEmpty())
  203. {
  204. CUser* pUser = (CUser*)newUserList.RemoveHead();
  205. VALIDATE_OBJECT(pUser, CUser);
  206. LV_FINDINFO lvFindInfo;
  207. lvFindInfo.flags = LVFI_STRING;
  208. lvFindInfo.psz = MKSTR(pUser->m_strName);
  209. if (m_userList.FindItem(&lvFindInfo, -1) == -1)
  210. {
  211. LV_ITEM lvItem;
  212. lvItem.mask = LVIF_TEXT|
  213. LVIF_PARAM|
  214. LVIF_IMAGE;
  215. lvItem.iItem = nUsers++; // append...
  216. lvItem.iSubItem = 0;
  217. lvItem.lParam = (LPARAM)(LPVOID)pUser;
  218. lvItem.iImage = BMPI_USER;
  219. lvItem.pszText = MKSTR(pUser->m_strName);
  220. m_userList.InsertItem(&lvItem);
  221. }
  222. else
  223. {
  224. pUser->InternalRelease(); // allocated in add user dialog...
  225. }
  226. }
  227. VERIFY(m_userList.SortItems(CompareUsersInMapping, 0)); // use column info...
  228. ::LvSelObjIfNecessary(&m_userList, TRUE); // ensure selection...
  229. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  230. }
  231. }
  232. void CNewMappingDialog::OnDelete()
  233. /*++
  234. Routine Description:
  235. Deletes users from list.
  236. Arguments:
  237. None.
  238. Return Values:
  239. None.
  240. --*/
  241. {
  242. ::LvReleaseSelObjs(&m_userList);
  243. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  244. }
  245. void CNewMappingDialog::OnOK()
  246. /*++
  247. Routine Description:
  248. Message handler for IDOK.
  249. Arguments:
  250. None.
  251. Return Values:
  252. None.
  253. --*/
  254. {
  255. if (!IsQuantityValid())
  256. return;
  257. if (!m_strName.IsEmpty() && m_userList.GetItemCount())
  258. {
  259. CUser* pUser;
  260. NTSTATUS NtStatus;
  261. LLS_GROUP_INFO_1 MappingInfo1;
  262. BeginWaitCursor(); // hourglass...
  263. MappingInfo1.Name = MKSTR(m_strName);
  264. MappingInfo1.Comment = MKSTR(m_strDescription);
  265. MappingInfo1.Licenses = m_nLicenses;
  266. NtStatus = ::LlsGroupAdd(
  267. LlsGetActiveHandle(),
  268. 1,
  269. (LPBYTE)&MappingInfo1
  270. );
  271. int iItem = -1;
  272. LlsSetLastStatus(NtStatus); // called api...
  273. if (NT_SUCCESS(NtStatus))
  274. {
  275. m_fUpdateHint |= UPDATE_GROUP_ADDED;
  276. while (NT_SUCCESS(NtStatus) &&
  277. (NULL != (pUser = (CUser*)::LvGetNextObj(&m_userList, &iItem, LVNI_ALL))))
  278. {
  279. VALIDATE_OBJECT(pUser, CUser);
  280. //
  281. // Add users one-by-one (blah!)
  282. //
  283. NtStatus = ::LlsGroupUserAdd(
  284. LlsGetActiveHandle(),
  285. MKSTR(m_strName),
  286. MKSTR(pUser->m_strName)
  287. );
  288. LlsSetLastStatus(NtStatus); // called api...
  289. }
  290. }
  291. if (NT_SUCCESS(NtStatus))
  292. {
  293. EndDialog(IDOK);
  294. }
  295. else
  296. {
  297. AbortDialogIfNecessary(); // display error...
  298. }
  299. EndWaitCursor(); // hourglass...
  300. }
  301. else
  302. {
  303. AfxMessageBox(IDP_ERROR_INVALID_MAPPING);
  304. }
  305. }
  306. void CNewMappingDialog::OnSetFocusUsers(NMHDR* pNMHDR, LRESULT* pResult)
  307. /*++
  308. Routine Description:
  309. Notification handler for NM_SETFOCUS.
  310. Arguments:
  311. pNMHDR - notification header.
  312. pResult - return code.
  313. Return Values:
  314. None.
  315. --*/
  316. {
  317. UNREFERENCED_PARAMETER(pNMHDR);
  318. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  319. ASSERT(NULL != pResult);
  320. *pResult = 0;
  321. }
  322. void CNewMappingDialog::OnKillFocusUsers(NMHDR* pNMHDR, LRESULT* pResult)
  323. /*++
  324. Routine Description:
  325. Notification handler for NM_KILLFOCUS.
  326. Arguments:
  327. pNMHDR - notification header.
  328. pResult - return code.
  329. Return Values:
  330. None.
  331. --*/
  332. {
  333. UNREFERENCED_PARAMETER(pNMHDR);
  334. ::LvSelObjIfNecessary(&m_userList); // ensure selection...
  335. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  336. ASSERT(NULL != pResult);
  337. *pResult = 0;
  338. }
  339. void CNewMappingDialog::OnDeltaPosSpin(NMHDR* pNMHDR, LRESULT* pResult)
  340. /*++
  341. Routine Description:
  342. Notification handler for UDN_DELTAPOS.
  343. Arguments:
  344. pNMHDR - notification header.
  345. pResult - return code.
  346. Return Values:
  347. None.
  348. --*/
  349. {
  350. UpdateData(TRUE); // get data
  351. ASSERT(NULL != pNMHDR);
  352. m_nLicenses += ((NM_UPDOWN*)pNMHDR)->iDelta;
  353. if (m_nLicenses < 0)
  354. {
  355. m_nLicenses = 0;
  356. ::MessageBeep(MB_OK);
  357. }
  358. else if (m_nLicenses > 999999)
  359. {
  360. m_nLicenses = 999999;
  361. ::MessageBeep(MB_OK);
  362. }
  363. UpdateData(FALSE); // set data
  364. ASSERT(NULL != pResult);
  365. *pResult = 1; // handle ourselves...
  366. }
  367. void CNewMappingDialog::OnUpdateQuantity()
  368. /*++
  369. Routine Description:
  370. Message handler for EN_UPDATE.
  371. Arguments:
  372. None.
  373. Return Values:
  374. None.
  375. --*/
  376. {
  377. long nLicensesOld = m_nLicenses;
  378. if (!IsQuantityValid())
  379. {
  380. m_nLicenses = nLicensesOld;
  381. UpdateData(FALSE);
  382. m_licEdit.SetFocus();
  383. m_licEdit.SetSel(0,-1);
  384. ::MessageBeep(MB_OK);
  385. }
  386. }
  387. BOOL CNewMappingDialog::IsQuantityValid()
  388. /*++
  389. Routine Description:
  390. Wrapper around UpdateData(TRUE).
  391. Arguments:
  392. None.
  393. Return Values:
  394. VT_BOOL.
  395. --*/
  396. {
  397. BOOL bIsValid;
  398. m_nLicensesMin = 1; // raise minimum...
  399. bIsValid = UpdateData(TRUE);
  400. m_nLicensesMin = 0; // reset minimum...
  401. return bIsValid;
  402. }
  403. int CALLBACK CompareUsersInMapping(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  404. /*++
  405. Routine Description:
  406. Notification handler for LVM_SORTITEMS.
  407. Arguments:
  408. lParam1 - object to sort.
  409. lParam2 - object to sort.
  410. lParamSort - sort criteria.
  411. Return Values:
  412. Same as lstrcmp.
  413. --*/
  414. {
  415. UNREFERENCED_PARAMETER(lParamSort);
  416. #define pUser1 ((CUser*)lParam1)
  417. #define pUser2 ((CUser*)lParam2)
  418. VALIDATE_OBJECT(pUser1, CUser);
  419. VALIDATE_OBJECT(pUser2, CUser);
  420. ASSERT(g_userColumnInfo.nSortedItem == 0);
  421. ASSERT(g_userColumnInfo.bSortOrder == FALSE);
  422. return pUser1->m_strName.CompareNoCase(pUser2->m_strName);
  423. }