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.

258 lines
6.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: simprop2.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // SimProp2.cpp
  11. #include "stdafx.h"
  12. #include "common.h"
  13. #include "helpids.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. ///////////////////////////////////////
  20. const TColumnHeaderItem rgzColumnHeader[] =
  21. {
  22. { IDS_SIM_KERBEROS_PRINCIPAL_NAME, 85 },
  23. { 0, 0 },
  24. };
  25. /////////////////////////////////////////////////////////////////////////////
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CSimKerberosPropPage property page
  28. // IMPLEMENT_DYNCREATE(CSimKerberosPropPage, CSimPropPage)
  29. CSimKerberosPropPage::CSimKerberosPropPage() : CSimPropPage(CSimKerberosPropPage::IDD)
  30. {
  31. //{{AFX_DATA_INIT(CSimKerberosPropPage)
  32. // NOTE: the ClassWizard will add member initialization here
  33. //}}AFX_DATA_INIT
  34. m_prgzColumnHeader = rgzColumnHeader;
  35. }
  36. CSimKerberosPropPage::~CSimKerberosPropPage()
  37. {
  38. }
  39. void CSimKerberosPropPage::DoDataExchange(CDataExchange* pDX)
  40. {
  41. ASSERT(m_pData != NULL);
  42. CSimPropPage::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CSimKerberosPropPage)
  44. // NOTE: the ClassWizard will add DDX and DDV calls here
  45. //}}AFX_DATA_MAP
  46. if (!pDX->m_bSaveAndValidate)
  47. {
  48. // Fill in the listview
  49. ListView_DeleteAllItems(m_hwndListview);
  50. for (CSimEntry * pSimEntry = m_pData->m_pSimEntryList;
  51. pSimEntry != NULL;
  52. pSimEntry = pSimEntry->m_pNext)
  53. {
  54. if (pSimEntry->m_eDialogTarget != eKerberos)
  55. continue;
  56. LPCTSTR pszT = pSimEntry->PchGetString();
  57. pszT += cchKerberos;
  58. ListView_AddString(m_hwndListview, pszT, (LPARAM)pSimEntry);
  59. } // for
  60. ListView_SelectItem(m_hwndListview, 0);
  61. } // if
  62. } // CSimKerberosPropPage::DoDataExchange()
  63. BEGIN_MESSAGE_MAP(CSimKerberosPropPage, CSimPropPage)
  64. //{{AFX_MSG_MAP(CSimKerberosPropPage)
  65. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  66. ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. void CSimKerberosPropPage::OnButtonAdd()
  70. {
  71. CSimAddKerberosDlg dlg;
  72. if (dlg.DoModal() != IDOK)
  73. return;
  74. CString str = dlg.m_strName;
  75. str.TrimLeft();
  76. str.TrimRight();
  77. int iItem = ListView_FindString(m_hwndListview, str);
  78. if (iItem >= 0)
  79. {
  80. ListView_SelectItem(m_hwndListview, iItem);
  81. ReportErrorEx (GetSafeHwnd(),IDS_SIM_ERR_KERBEROS_NAME_ALREADY_EXISTS,S_OK,
  82. MB_OK | MB_ICONINFORMATION, NULL, 0);
  83. return;
  84. }
  85. CString strTemp = szKerberos;
  86. strTemp += str;
  87. CSimEntry * pSimEntry = m_pData->PAddSimEntry(strTemp);
  88. UpdateData(FALSE);
  89. ListView_SelectLParam(m_hwndListview, (LPARAM)pSimEntry);
  90. SetDirty();
  91. } // OnButtonAdd()
  92. void CSimKerberosPropPage::OnButtonEdit()
  93. {
  94. int iItem;
  95. CSimEntry * pSimEntry = (CSimEntry *)ListView_GetItemLParam(m_hwndListview, -1, OUT &iItem);
  96. if (pSimEntry == NULL || iItem < 0)
  97. {
  98. // No item selected
  99. return;
  100. }
  101. CString str;
  102. ListView_GetItemString(m_hwndListview, iItem, 0, OUT str);
  103. // ASSERT(!str.IsEmpty());
  104. CSimAddKerberosDlg dlg;
  105. dlg.m_strName = str;
  106. if (dlg.DoModal() != IDOK)
  107. return;
  108. dlg.m_strName.TrimLeft();
  109. dlg.m_strName.TrimRight();
  110. if (str == dlg.m_strName)
  111. {
  112. // Strings are identical
  113. return;
  114. }
  115. int iItemT = ListView_FindString(m_hwndListview, dlg.m_strName);
  116. if (iItemT >= 0)
  117. {
  118. ListView_SelectItem(m_hwndListview, iItemT);
  119. ReportErrorEx (GetSafeHwnd(),IDS_SIM_ERR_KERBEROS_NAME_ALREADY_EXISTS,S_OK,
  120. MB_OK | MB_ICONINFORMATION, NULL, 0);
  121. return;
  122. }
  123. CString strTemp = szKerberos;
  124. strTemp += dlg.m_strName;
  125. pSimEntry->SetString(strTemp);
  126. UpdateData(FALSE);
  127. ListView_SelectLParam(m_hwndListview, (LPARAM)pSimEntry);
  128. SetDirty();
  129. } // OnButtonEdit()
  130. void CSimKerberosPropPage::DoContextHelp (HWND hWndControl)
  131. {
  132. TRACE0 ("Entering CSimKerberosPropPage::DoContextHelp\n");
  133. static const DWORD help_map[] =
  134. {
  135. IDC_EDIT_USER_ACCOUNT, IDH_EDIT_USER_ACCOUNT,
  136. IDC_LISTVIEW, IDH_LISTVIEW_KERBEROS,
  137. IDC_BUTTON_ADD, IDH_BUTTON_ADD,
  138. IDC_BUTTON_EDIT, IDH_BUTTON_EDIT,
  139. IDC_BUTTON_REMOVE, IDH_BUTTON_REMOVE,
  140. 0, 0
  141. };
  142. // Display context help for a control
  143. if ( !::WinHelp (
  144. hWndControl,
  145. DSADMIN_CONTEXT_HELP_FILE,
  146. HELP_WM_HELP,
  147. (DWORD_PTR) help_map) )
  148. {
  149. TRACE1 ("WinHelp () failed: 0x%x\n", GetLastError ());
  150. }
  151. TRACE0 ("Leaving CSimKerberosPropPage::DoContextHelp\n");
  152. }
  153. /////////////////////////////////////////////////////////////////////////////
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CSimAddKerberosDlg dialog
  156. CSimAddKerberosDlg::CSimAddKerberosDlg(CWnd* pParent /*=NULL*/)
  157. : CDialog(CSimAddKerberosDlg::IDD, pParent)
  158. {
  159. //{{AFX_DATA_INIT(CSimAddKerberosDlg)
  160. //}}AFX_DATA_INIT
  161. }
  162. void CSimAddKerberosDlg::DoDataExchange(CDataExchange* pDX)
  163. {
  164. CDialog::DoDataExchange(pDX);
  165. //{{AFX_DATA_MAP(CSimAddKerberosDlg)
  166. DDX_Text(pDX, IDC_EDIT_KERBEROS_NAME, m_strName);
  167. //}}AFX_DATA_MAP
  168. }
  169. BEGIN_MESSAGE_MAP(CSimAddKerberosDlg, CDialog)
  170. //{{AFX_MSG_MAP(CSimAddKerberosDlg)
  171. ON_EN_CHANGE(IDC_EDIT_KERBEROS_NAME, OnChangeEditKerberosName)
  172. //}}AFX_MSG_MAP
  173. ON_MESSAGE(WM_HELP, OnHelp)
  174. END_MESSAGE_MAP()
  175. BOOL CSimAddKerberosDlg::OnInitDialog()
  176. {
  177. CDialog::OnInitDialog();
  178. if ( m_strName.IsEmpty() )
  179. {
  180. GetDlgItem (IDOK)->EnableWindow (FALSE);
  181. }
  182. else
  183. {
  184. // Change the caption
  185. CString str;
  186. VERIFY( str.LoadString(IDS_SIM_EDIT_KERBEROS_NAME) );
  187. SetWindowText(str);
  188. }
  189. return TRUE;
  190. }
  191. void CSimAddKerberosDlg::OnChangeEditKerberosName()
  192. {
  193. UpdateData (TRUE);
  194. m_strName.TrimLeft ();
  195. m_strName.TrimRight ();
  196. GetDlgItem (IDOK)->EnableWindow (!m_strName.IsEmpty ());
  197. }
  198. void CSimAddKerberosDlg::DoContextHelp (HWND hWndControl)
  199. {
  200. TRACE0 ("Entering CSimAddKerberosDlg::DoContextHelp\n");
  201. static const DWORD help_map[] =
  202. {
  203. IDC_EDIT_KERBEROS_NAME, IDH_EDIT_KERBEROS_NAME,
  204. 0, 0
  205. };
  206. // Display context help for a control
  207. if ( !::WinHelp (
  208. hWndControl,
  209. DSADMIN_CONTEXT_HELP_FILE,
  210. HELP_WM_HELP,
  211. (DWORD_PTR) help_map) )
  212. {
  213. TRACE1 ("WinHelp () failed: 0x%x\n", GetLastError ());
  214. }
  215. TRACE0 ("Leaving CSimAddKerberosDlg::DoContextHelp\n");
  216. }
  217. BOOL CSimAddKerberosDlg::OnHelp(WPARAM, LPARAM lParam)
  218. {
  219. TRACE0 ("Entering CSimAddKerberosDlg::OnHelp\n");
  220. const LPHELPINFO pHelpInfo = (LPHELPINFO)lParam;
  221. if (pHelpInfo && pHelpInfo->iContextType == HELPINFO_WINDOW)
  222. {
  223. DoContextHelp ((HWND) pHelpInfo->hItemHandle);
  224. }
  225. TRACE0 ("Leaving CSimAddKerberosDlg::OnHelp\n");
  226. return TRUE;
  227. }