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.

560 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. nlicdlg.cpp
  5. Abstract:
  6. New license dialog implementation.
  7. Author:
  8. Don Ryan (donryan) 02-Feb-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #include "nlicdlg.h"
  16. #include "mainfrm.h"
  17. #include "pseatdlg.h"
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22. BEGIN_MESSAGE_MAP(CNewLicenseDialog, CDialog)
  23. //{{AFX_MSG_MAP(CNewLicenseDialog)
  24. ON_NOTIFY(UDN_DELTAPOS, IDC_NEW_LICENSE_SPIN, OnDeltaPosSpin)
  25. ON_EN_UPDATE(IDC_NEW_LICENSE_QUANTITY, OnUpdateQuantity)
  26. //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28. CNewLicenseDialog::CNewLicenseDialog(CWnd* pParent /*=NULL*/)
  29. : CDialog(CNewLicenseDialog::IDD, pParent)
  30. /*++
  31. Routine Description:
  32. Constructor for dialog.
  33. Arguments:
  34. pParent - owner window.
  35. Return Values:
  36. None.
  37. --*/
  38. {
  39. //{{AFX_DATA_INIT(CNewLicenseDialog)
  40. m_strComment = _T("");
  41. m_nLicenses = 0;
  42. m_nLicensesMin = 0;
  43. m_strProduct = _T("");
  44. //}}AFX_DATA_INIT
  45. m_pProduct = NULL;
  46. m_bIsOnlyProduct = FALSE;
  47. m_bAreCtrlsInitialized = FALSE;
  48. m_fUpdateHint = UPDATE_INFO_NONE;
  49. }
  50. void CNewLicenseDialog::DoDataExchange(CDataExchange* pDX)
  51. /*++
  52. Routine Description:
  53. Called by framework to exchange dialog data.
  54. Arguments:
  55. pDX - data exchange object.
  56. Return Values:
  57. None.
  58. --*/
  59. {
  60. CDialog::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CNewLicenseDialog)
  62. DDX_Control(pDX, IDC_NEW_LICENSE_COMMENT, m_comEdit);
  63. DDX_Control(pDX, IDC_NEW_LICENSE_QUANTITY, m_licEdit);
  64. DDX_Control(pDX, IDC_NEW_LICENSE_SPIN, m_spinCtrl);
  65. DDX_Control(pDX, IDC_NEW_LICENSE_PRODUCT, m_productList);
  66. DDX_Text(pDX, IDC_NEW_LICENSE_COMMENT, m_strComment);
  67. DDX_Text(pDX, IDC_NEW_LICENSE_QUANTITY, m_nLicenses);
  68. DDV_MinMaxLong(pDX, m_nLicenses, m_nLicensesMin, 999999);
  69. DDX_CBString(pDX, IDC_NEW_LICENSE_PRODUCT, m_strProduct);
  70. //}}AFX_DATA_MAP
  71. }
  72. void CNewLicenseDialog::InitCtrls()
  73. /*++
  74. Routine Description:
  75. Initializes dialog controls.
  76. Arguments:
  77. None.
  78. Return Values:
  79. None.
  80. --*/
  81. {
  82. m_licEdit.SetFocus();
  83. m_licEdit.SetSel(0,-1);
  84. m_licEdit.LimitText(6);
  85. m_comEdit.LimitText(256);
  86. m_spinCtrl.SetRange(0, UD_MAXVAL);
  87. m_bAreCtrlsInitialized = TRUE;
  88. }
  89. void CNewLicenseDialog::InitDialog(CProduct* pProduct, BOOL bIsOnlyProduct)
  90. /*++
  91. Routine Description:
  92. Initializes dialog.
  93. Arguments:
  94. pProduct - product object.
  95. bIsSingleProduct - true if only this product listed.
  96. Return Values:
  97. None.
  98. --*/
  99. {
  100. m_pProduct = pProduct;
  101. m_bIsOnlyProduct = bIsOnlyProduct;
  102. #ifdef SUPPORT_UNLISTED_PRODUCTS
  103. m_iUnlisted = CB_ERR;
  104. #endif
  105. }
  106. void CNewLicenseDialog::AbortDialogIfNecessary()
  107. /*++
  108. Routine Description:
  109. Displays status and aborts if connection lost.
  110. Arguments:
  111. None.
  112. Return Values:
  113. None.
  114. --*/
  115. {
  116. theApp.DisplayLastStatus();
  117. if (IsConnectionDropped(LlsGetLastStatus()))
  118. {
  119. AbortDialog(); // bail...
  120. }
  121. }
  122. void CNewLicenseDialog::AbortDialog()
  123. /*++
  124. Routine Description:
  125. Aborts dialog.
  126. Arguments:
  127. None.
  128. Return Values:
  129. None.
  130. --*/
  131. {
  132. m_fUpdateHint = UPDATE_INFO_ABORT;
  133. EndDialog(IDABORT);
  134. }
  135. BOOL CNewLicenseDialog::OnInitDialog()
  136. /*++
  137. Routine Description:
  138. Message handler for WM_INITDIALOG.
  139. Arguments:
  140. None.
  141. Return Values:
  142. Returns false if focus set manually.
  143. --*/
  144. {
  145. CDialog::OnInitDialog();
  146. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  147. return TRUE;
  148. }
  149. void CNewLicenseDialog::OnOK()
  150. /*++
  151. Routine Description:
  152. Creates a new license for product.
  153. Arguments:
  154. None.
  155. Return Values:
  156. None.
  157. --*/
  158. {
  159. if (!IsQuantityValid())
  160. return;
  161. if (m_strProduct.IsEmpty())
  162. return;
  163. #ifdef SUPPORT_UNLISTED_PRODUCTS
  164. if (m_productList.GetCurSel() == m_iUnlisted)
  165. {
  166. //
  167. // CODEWORK...
  168. //
  169. return;
  170. }
  171. #endif
  172. CPerSeatLicensingDialog psLicDlg;
  173. psLicDlg.m_strProduct = m_strProduct;
  174. if (psLicDlg.DoModal() != IDOK)
  175. return;
  176. BeginWaitCursor(); // hourglass...
  177. NTSTATUS NtStatus;
  178. LLS_LICENSE_INFO_0 LicenseInfo0;
  179. TCHAR szUserBuffer[256];
  180. DWORD dwUserBuffer = sizeof(szUserBuffer);
  181. if (::GetUserName(szUserBuffer, &dwUserBuffer))
  182. {
  183. LicenseInfo0.Product = MKSTR(m_strProduct);
  184. LicenseInfo0.Quantity = m_nLicenses;
  185. LicenseInfo0.Date = 0; // ignored...
  186. LicenseInfo0.Admin = szUserBuffer;
  187. LicenseInfo0.Comment = MKSTR(m_strComment);
  188. NtStatus = ::LlsLicenseAdd(
  189. LlsGetActiveHandle(),
  190. 0,
  191. (LPBYTE)&LicenseInfo0
  192. );
  193. LlsSetLastStatus(NtStatus); // called api...
  194. if (NT_SUCCESS(NtStatus))
  195. {
  196. m_fUpdateHint = UPDATE_LICENSE_ADDED;
  197. EndDialog(IDOK);
  198. }
  199. else
  200. {
  201. AbortDialogIfNecessary(); // display error...
  202. }
  203. }
  204. else
  205. {
  206. LlsSetLastStatus(::GetLastError());
  207. AbortDialogIfNecessary(); // display error...
  208. }
  209. EndWaitCursor(); // hourglass...
  210. }
  211. BOOL CNewLicenseDialog::RefreshCtrls()
  212. /*++
  213. Routine Description:
  214. Refreshs list of products available.
  215. Arguments:
  216. None.
  217. Return Values:
  218. Returns true if controls refreshed.
  219. --*/
  220. {
  221. int iProductInCB = CB_ERR;
  222. BeginWaitCursor(); // hourglass...
  223. if (m_bIsOnlyProduct)
  224. {
  225. VALIDATE_OBJECT(m_pProduct, CProduct);
  226. iProductInCB = m_productList.AddString(m_pProduct->m_strName);
  227. }
  228. else
  229. {
  230. CController* pController = (CController*)MKOBJ(LlsGetApp()->GetActiveController());
  231. pController->InternalRelease(); // held open by application...
  232. VALIDATE_OBJECT(pController, CController);
  233. VALIDATE_OBJECT(pController->m_pProducts, CProducts);
  234. CObArray* pObArray = pController->m_pProducts->m_pObArray;
  235. VALIDATE_OBJECT(pObArray, CObArray);
  236. int iProduct = 0;
  237. int nProducts = pObArray->GetSize();
  238. CProduct* pProduct;
  239. while (nProducts--)
  240. {
  241. pProduct = (CProduct*)pObArray->GetAt(iProduct++);
  242. VALIDATE_OBJECT(pProduct, CProduct);
  243. if (m_productList.AddString(pProduct->m_strName) == CB_ERR)
  244. {
  245. LlsSetLastStatus(STATUS_NO_MEMORY);
  246. return FALSE; // bail...
  247. }
  248. }
  249. if (m_pProduct)
  250. {
  251. VALIDATE_OBJECT(m_pProduct, CProduct);
  252. iProductInCB = m_productList.FindStringExact(-1, m_pProduct->m_strName);
  253. ASSERT(iProductInCB != CB_ERR);
  254. }
  255. #ifdef SUPPORT_UNLISTED_PRODUCTS
  256. CString strUnlisted;
  257. strUnlisted.LoadString(IDS_UNLISTED_PRODUCT);
  258. m_iUnlisted = m_productList.AddString(strUnlisted);
  259. #endif
  260. }
  261. m_productList.SetCurSel((iProductInCB == CB_ERR) ? 0 : iProductInCB);
  262. EndWaitCursor(); // hourglass...
  263. return TRUE;
  264. }
  265. BOOL CNewLicenseDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  266. /*++
  267. Routine Description:
  268. Message handler for WM_COMMAND.
  269. Arguments:
  270. wParam - message specific.
  271. lParam - message specific.
  272. Return Values:
  273. Returns true if message processed.
  274. --*/
  275. {
  276. if (wParam == ID_INIT_CTRLS)
  277. {
  278. if (!m_bAreCtrlsInitialized)
  279. {
  280. InitCtrls();
  281. if (!RefreshCtrls())
  282. {
  283. AbortDialogIfNecessary(); // display error...
  284. }
  285. }
  286. return TRUE; // processed...
  287. }
  288. return CDialog::OnCommand(wParam, lParam);
  289. }
  290. void CNewLicenseDialog::OnDeltaPosSpin(NMHDR* pNMHDR, LRESULT* pResult)
  291. /*++
  292. Routine Description:
  293. Notification handler for UDN_DELTAPOS.
  294. Arguments:
  295. pNMHDR - notification header.
  296. pResult - return code.
  297. Return Values:
  298. None.
  299. --*/
  300. {
  301. UpdateData(TRUE); // get data
  302. m_nLicenses += ((NM_UPDOWN*)pNMHDR)->iDelta;
  303. if (m_nLicenses < 0)
  304. {
  305. m_nLicenses = 0;
  306. ::MessageBeep(MB_OK);
  307. }
  308. else if (m_nLicenses > 999999)
  309. {
  310. m_nLicenses = 999999;
  311. ::MessageBeep(MB_OK);
  312. }
  313. UpdateData(FALSE); // set data
  314. *pResult = 1; // handle ourselves...
  315. }
  316. void CNewLicenseDialog::OnUpdateQuantity()
  317. /*++
  318. Routine Description:
  319. Message handler for EN_UPDATE.
  320. Arguments:
  321. None.
  322. Return Values:
  323. None.
  324. --*/
  325. {
  326. long nLicensesOld = m_nLicenses;
  327. if (!IsQuantityValid())
  328. {
  329. m_nLicenses = nLicensesOld;
  330. UpdateData(FALSE);
  331. m_licEdit.SetFocus();
  332. m_licEdit.SetSel(0,-1);
  333. ::MessageBeep(MB_OK);
  334. }
  335. }
  336. BOOL CNewLicenseDialog::IsQuantityValid()
  337. /*++
  338. Routine Description:
  339. Wrapper around UpdateData(TRUE).
  340. Arguments:
  341. None.
  342. Return Values:
  343. VT_BOOL.
  344. --*/
  345. {
  346. BOOL bIsValid;
  347. m_nLicensesMin = 1; // raise minimum...
  348. bIsValid = UpdateData(TRUE);
  349. m_nLicensesMin = 0; // reset minimum...
  350. return bIsValid;
  351. }