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.

539 lines
9.5 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. sdomdlg.cpp
  5. Abstract:
  6. Select domain dialog implementation.
  7. Author:
  8. Don Ryan (donryan) 20-Jan-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #include "sdomdlg.h"
  16. #include <lmerr.h>
  17. #include <lmcons.h>
  18. #include <lmapibuf.h>
  19. extern "C" {
  20. #include <icanon.h>
  21. }
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26. BEGIN_MESSAGE_MAP(CSelectDomainDialog, CDialog)
  27. //{{AFX_MSG_MAP(CSelectDomainDialog)
  28. ON_NOTIFY(TVN_ITEMEXPANDING, IDC_SELECT_DOMAIN_DOMAINS, OnItemExpandingDomains)
  29. ON_NOTIFY(TVN_SELCHANGED, IDC_SELECT_DOMAIN_DOMAINS, OnSelChangedDomain)
  30. ON_NOTIFY(NM_DBLCLK, IDC_SELECT_DOMAIN_DOMAINS, OnDblclkDomain)
  31. ON_NOTIFY(NM_RETURN, IDC_SELECT_DOMAIN_DOMAINS, OnReturnDomains)
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. CSelectDomainDialog::CSelectDomainDialog(CWnd* pParent /*=NULL*/)
  35. : CDialog(CSelectDomainDialog::IDD, pParent)
  36. /*++
  37. Routine Description:
  38. Constructor for select domain dialog
  39. Arguments:
  40. pParent - parent window handle.
  41. Return Values:
  42. None.
  43. --*/
  44. {
  45. //{{AFX_DATA_INIT(CSelectDomainDialog)
  46. m_strDomain = _T("");
  47. //}}AFX_DATA_INIT
  48. m_bIsFocusDomain = FALSE;
  49. m_bAreCtrlsInitialized = FALSE;
  50. m_fUpdateHint = UPDATE_INFO_NONE;
  51. }
  52. void CSelectDomainDialog::DoDataExchange(CDataExchange* pDX)
  53. /*++
  54. Routine Description:
  55. Called by framework to exchange dialog data.
  56. Arguments:
  57. pDX - data exchange object.
  58. Return Values:
  59. None.
  60. --*/
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CSelectDomainDialog)
  64. DDX_Control(pDX, IDC_SELECT_DOMAIN_DOMAIN, m_domEdit);
  65. DDX_Control(pDX, IDC_SELECT_DOMAIN_DOMAINS, m_serverTree);
  66. DDX_Text(pDX, IDC_SELECT_DOMAIN_DOMAIN, m_strDomain);
  67. //}}AFX_DATA_MAP
  68. }
  69. void CSelectDomainDialog::InitCtrls()
  70. /*++
  71. Routine Description:
  72. Initializes dialog controls.
  73. Arguments:
  74. None.
  75. Return Values:
  76. None.
  77. --*/
  78. {
  79. TV_ITEM tvItem = {0};
  80. HTREEITEM htItem;
  81. TV_INSERTSTRUCT tvInsert;
  82. CString strLabel;
  83. tvItem.mask = TVIF_TEXT|
  84. TVIF_PARAM|
  85. TVIF_CHILDREN|
  86. TVIF_SELECTEDIMAGE|
  87. TVIF_IMAGE;
  88. tvItem.cChildren = TRUE;
  89. tvItem.iImage = BMPI_ENTERPRISE;
  90. tvItem.iSelectedImage = BMPI_ENTERPRISE;
  91. strLabel.LoadString(IDS_ENTERPRISE);
  92. tvItem.pszText = MKSTR(strLabel);
  93. tvItem.lParam = (LPARAM)(LPVOID)LlsGetApp();
  94. tvInsert.item = tvItem;
  95. tvInsert.hInsertAfter = (HTREEITEM)TVI_ROOT;
  96. tvInsert.hParent = (HTREEITEM)NULL;
  97. VERIFY(htItem = m_serverTree.InsertItem(&tvInsert));
  98. m_serverTree.SetImageList(&theApp.m_smallImages, TVSIL_NORMAL);
  99. m_bAreCtrlsInitialized = TRUE; // validate now...
  100. VERIFY(m_serverTree.Select(htItem, TVGN_CARET)); // redraw now...
  101. if (!IsConnectionDropped(LlsGetLastStatus()))
  102. {
  103. m_serverTree.Expand(htItem, TVE_EXPAND);
  104. }
  105. else if (LlsGetApp()->IsFocusDomain())
  106. {
  107. CDomain* pDomain = (CDomain*)MKOBJ(LlsGetApp()->GetActiveDomain());
  108. VALIDATE_OBJECT(pDomain, CDomain);
  109. m_strDomain = pDomain->m_strName;
  110. UpdateData(FALSE); // upload...
  111. m_domEdit.SetSel(0,-1);
  112. m_domEdit.SetFocus();
  113. pDomain->InternalRelease(); // release now...
  114. m_bIsFocusDomain = TRUE;
  115. }
  116. }
  117. BOOL CSelectDomainDialog::OnInitDialog()
  118. /*++
  119. Routine Description:
  120. Message handler for WM_INITDIALOG.
  121. Arguments:
  122. None.
  123. Return Values:
  124. Returns false if focus set manually.
  125. --*/
  126. {
  127. CDialog::OnInitDialog();
  128. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  129. return TRUE;
  130. }
  131. BOOL CSelectDomainDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  132. /*++
  133. Routine Description:
  134. Message handler for WM_COMMAND.
  135. Arguments:
  136. wParam - message specific.
  137. lParam - message specific.
  138. Return Values:
  139. Returns true if message processed.
  140. --*/
  141. {
  142. if (wParam == ID_INIT_CTRLS)
  143. {
  144. if (!m_bAreCtrlsInitialized)
  145. {
  146. InitCtrls();
  147. }
  148. return TRUE; // processed...
  149. }
  150. return CDialog::OnCommand(wParam, lParam);
  151. }
  152. void CSelectDomainDialog::OnDblclkDomain(NMHDR* pNMHDR, LRESULT* pResult)
  153. /*++
  154. Routine Description:
  155. Notification handler for WM_LBUTTONDBLCLK.
  156. Arguments:
  157. pNMHDR - notification message header.
  158. pResult - return status.
  159. Return Values:
  160. None.
  161. --*/
  162. {
  163. if (!m_strDomain.IsEmpty())
  164. {
  165. OnOK();
  166. }
  167. else
  168. {
  169. if (theApp.OpenDocumentFile(NULL)) // open enterprise
  170. {
  171. m_fUpdateHint = UPDATE_DOMAIN_SELECTED;
  172. EndDialog(IDOK);
  173. }
  174. }
  175. *pResult = 0;
  176. }
  177. void CSelectDomainDialog::OnItemExpandingDomains(NMHDR* pNMHDR, LRESULT* pResult)
  178. /*++
  179. Routine Description:
  180. Notification handler for TVN_ITEMEXPANDING.
  181. Arguments:
  182. pNMHDR - notification message header.
  183. pResult - return status.
  184. Return Values:
  185. None.
  186. --*/
  187. {
  188. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  189. TV_ITEM tvItem = pNMTreeView->itemNew;
  190. if (!(tvItem.state & TVIS_EXPANDEDONCE))
  191. {
  192. BeginWaitCursor(); // hourglass...
  193. CApplication* pApplication = (CApplication*)tvItem.lParam;
  194. VALIDATE_OBJECT(pApplication, CApplication);
  195. CDomains* pDomains;
  196. if (pDomains = pApplication->m_pDomains)
  197. {
  198. pDomains->InternalAddRef();
  199. }
  200. else
  201. {
  202. VARIANT va;
  203. VariantInit(&va);
  204. pDomains = (CDomains*)MKOBJ(pApplication->GetDomains(va));
  205. }
  206. if (pDomains)
  207. {
  208. InsertDomains(tvItem.hItem, pDomains);
  209. pDomains->InternalRelease();
  210. }
  211. else
  212. {
  213. theApp.DisplayLastStatus();
  214. }
  215. EndWaitCursor(); // hourglass...
  216. }
  217. *pResult = 0;
  218. }
  219. void CSelectDomainDialog::OnOK()
  220. /*++
  221. Routine Description:
  222. Message handler for IDOK.
  223. Arguments:
  224. None.
  225. Return Values:
  226. None.
  227. --*/
  228. {
  229. if (!UpdateData(TRUE))
  230. return;
  231. LPCTSTR pszDomain = m_strDomain;
  232. while (_istspace(*pszDomain)) //
  233. pszDomain = _tcsinc(pszDomain); // CString::TrimLeft does not work for UNICODE...
  234. m_strDomain = pszDomain; //
  235. m_strDomain.TrimRight();
  236. if (!m_strDomain.IsEmpty())
  237. {
  238. DWORD NetStatus;
  239. pszDomain = m_strDomain;
  240. if ((pszDomain[0] == _T('\\')) &&
  241. (pszDomain[1] == _T('\\')))
  242. {
  243. NetStatus = NetpNameValidate(
  244. NULL,
  245. (LPTSTR)(pszDomain + 2),
  246. NAMETYPE_COMPUTER,
  247. 0
  248. );
  249. }
  250. else
  251. {
  252. NetStatus = NetpNameValidate(
  253. NULL,
  254. (LPTSTR)pszDomain,
  255. NAMETYPE_DOMAIN,
  256. 0
  257. );
  258. }
  259. if (NetStatus == ERROR_SUCCESS)
  260. {
  261. if (theApp.OpenDocumentFile(m_strDomain))
  262. {
  263. m_fUpdateHint = UPDATE_DOMAIN_SELECTED;
  264. EndDialog(IDOK);
  265. }
  266. }
  267. else
  268. {
  269. AfxMessageBox(IDP_ERROR_INVALID_DOMAIN);
  270. }
  271. }
  272. else
  273. {
  274. AfxMessageBox(IDP_ERROR_INVALID_DOMAIN);
  275. }
  276. }
  277. void CSelectDomainDialog::OnSelChangedDomain(NMHDR* pNMHDR, LRESULT* pResult)
  278. /*++
  279. Routine Description:
  280. Notification handler for TVN_SELCHANGED.
  281. Arguments:
  282. pNMHDR - notification message header.
  283. pResult - return status.
  284. Return Values:
  285. None.
  286. --*/
  287. {
  288. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  289. TV_ITEM tvItem = pNMTreeView->itemNew;
  290. if (tvItem.hItem != m_serverTree.GetRootItem())
  291. {
  292. CDomain* pDomain = (CDomain*)tvItem.lParam;
  293. VALIDATE_OBJECT(pDomain, CDomain);
  294. m_strDomain = pDomain->m_strName;
  295. UpdateData(FALSE); // upload...
  296. m_bIsFocusDomain = TRUE;
  297. }
  298. else if (tvItem.hItem == m_serverTree.GetRootItem())
  299. {
  300. m_strDomain = _T("");
  301. UpdateData(FALSE);
  302. m_bIsFocusDomain = FALSE;
  303. }
  304. *pResult = 0;
  305. }
  306. void CSelectDomainDialog::OnReturnDomains(NMHDR* pNMHDR, LRESULT* pResult)
  307. /*++
  308. Routine Description:
  309. Notification handler for NM_RETURN.
  310. Arguments:
  311. pNMHDR - notification message header.
  312. pResult - return status.
  313. Return Values:
  314. None.
  315. --*/
  316. {
  317. OnDblclkDomain(pNMHDR, pResult);
  318. }
  319. void CSelectDomainDialog::InsertDomains(HTREEITEM hParent, CDomains* pDomains)
  320. /*++
  321. Routine Description:
  322. Inserts domain list.
  323. Arguments:
  324. hParent - parent item.
  325. pDomains - domain collection.
  326. Return Values:
  327. None.
  328. --*/
  329. {
  330. VALIDATE_OBJECT(pDomains, CDomains);
  331. TV_ITEM tvItem = {0};
  332. TV_INSERTSTRUCT tvInsert;
  333. long nDomains = pDomains->GetCount();
  334. tvItem.mask = TVIF_TEXT|
  335. TVIF_PARAM|
  336. TVIF_IMAGE|
  337. TVIF_SELECTEDIMAGE;
  338. tvItem.iImage = BMPI_DOMAIN;
  339. tvItem.iSelectedImage = BMPI_DOMAIN;
  340. tvInsert.hInsertAfter = (HTREEITEM)TVI_LAST;
  341. tvInsert.hParent = (HTREEITEM)hParent;
  342. VARIANT va;
  343. VariantInit(&va);
  344. for (va.vt = VT_I4, va.lVal = 0; va.lVal < nDomains; va.lVal++)
  345. {
  346. CDomain* pDomain = (CDomain*)MKOBJ(pDomains->GetItem(va));
  347. VALIDATE_OBJECT(pDomain, CDomain);
  348. tvItem.pszText = MKSTR(pDomain->m_strName);
  349. tvItem.lParam = (LPARAM)(LPVOID)pDomain;
  350. tvInsert.item = tvItem;
  351. m_serverTree.InsertItem(&tvInsert);
  352. pDomain->InternalRelease();
  353. }
  354. }