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.

401 lines
9.1 KiB

  1. /*++
  2. Module Name:
  3. JPProp.cpp
  4. Abstract:
  5. This module contains the implementation for CReplicaSetPropPage
  6. This is used to implement the property page for Junction Point(aka Replica Set)
  7. --*/
  8. #include "stdafx.h"
  9. #include "resource.h"
  10. #include "utils.h"
  11. #include "JpProp.h"
  12. #include "dfshelp.h"
  13. CReplicaSetPropPage::CReplicaSetPropPage() :
  14. m_lReferralTime(300),
  15. m_lNotifyHandle(0),
  16. m_lNotifyParam(0),
  17. m_bDfsRoot(FALSE),
  18. m_bHideTimeout(FALSE),
  19. CQWizardPageImpl<CReplicaSetPropPage>(false)
  20. {
  21. }
  22. CReplicaSetPropPage::~CReplicaSetPropPage()
  23. {
  24. if (m_lNotifyHandle)
  25. MMCFreeNotifyHandle(m_lNotifyHandle);
  26. }
  27. extern WNDPROC g_fnOldEditCtrlProc;
  28. LRESULT
  29. CReplicaSetPropPage::OnInitDialog(
  30. IN UINT i_uMsg,
  31. IN WPARAM i_wParam,
  32. LPARAM i_lParam,
  33. IN OUT BOOL& io_bHandled
  34. )
  35. {
  36. ::SendMessage(GetDlgItem(IDC_REFFERAL_TIME), EM_LIMITTEXT, 10, 0);
  37. ::SendMessage(GetDlgItem(IDC_REPLICA_SET_COMMENT), EM_LIMITTEXT, MAXCOMMENTSZ, 0);
  38. TCHAR szTime[16];
  39. _stprintf(szTime, _T("%u"), m_lReferralTime);
  40. SetDlgItemText(IDC_REFFERAL_TIME, szTime);
  41. g_fnOldEditCtrlProc = reinterpret_cast<WNDPROC>(
  42. ::SetWindowLongPtr(
  43. GetDlgItem(IDC_REFFERAL_TIME),
  44. GWLP_WNDPROC,
  45. reinterpret_cast<LONG_PTR>(NoPasteEditCtrlProc)));
  46. SetDlgItemText(IDC_REPLICA_SET_NAME, m_bstrJPEntryPath);
  47. SetDlgItemText(IDC_REPLICA_SET_COMMENT, m_bstrJPComment);
  48. if (m_bHideTimeout)
  49. {
  50. MyShowWindow(GetDlgItem(IDC_REFFERAL_TIME_LABEL), FALSE);
  51. MyShowWindow(GetDlgItem(IDC_REFFERAL_TIME), FALSE);
  52. }
  53. return TRUE; // To let the dialg set the control
  54. }
  55. /*++
  56. This function is called when a user clicks the ? in the top right of a property sheet
  57. and then clciks a control, or when they hit F1 in a control.
  58. --*/
  59. LRESULT CReplicaSetPropPage::OnCtxHelp(
  60. IN UINT i_uMsg,
  61. IN WPARAM i_wParam,
  62. IN LPARAM i_lParam,
  63. IN OUT BOOL& io_bHandled
  64. )
  65. {
  66. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  67. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  68. return FALSE;
  69. ::WinHelp((HWND)(lphi->hItemHandle),
  70. DFS_CTX_HELP_FILE,
  71. HELP_WM_HELP,
  72. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_JP_PROP);
  73. return TRUE;
  74. }
  75. /*++
  76. This function handles "What's This" help when a user right clicks the control
  77. --*/
  78. LRESULT CReplicaSetPropPage::OnCtxMenuHelp(
  79. IN UINT i_uMsg,
  80. IN WPARAM i_wParam,
  81. IN LPARAM i_lParam,
  82. IN OUT BOOL& io_bHandled
  83. )
  84. {
  85. ::WinHelp((HWND)i_wParam,
  86. DFS_CTX_HELP_FILE,
  87. HELP_CONTEXTMENU,
  88. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_JP_PROP);
  89. return TRUE;
  90. }
  91. void
  92. CReplicaSetPropPage::_ReSet()
  93. {
  94. if ((IDfsRoot *)m_piDfsRoot)
  95. m_piDfsRoot.Release();
  96. if ((IDfsJunctionPoint *)m_piDfsJPObject)
  97. m_piDfsJPObject.Release();
  98. m_bstrJPEntryPath.Empty();
  99. m_bstrJPComment.Empty();
  100. m_lReferralTime = 0;
  101. m_bDfsRoot = FALSE;
  102. m_bHideTimeout = FALSE;
  103. }
  104. HRESULT
  105. CReplicaSetPropPage::Initialize(
  106. IN IDfsRoot* i_piDfsRoot,
  107. IN IDfsJunctionPoint* i_piDfsJPObject
  108. )
  109. {
  110. if (i_piDfsRoot && i_piDfsJPObject ||
  111. !i_piDfsRoot && !i_piDfsJPObject)
  112. return E_INVALIDARG;
  113. _ReSet();
  114. HRESULT hr = S_OK;
  115. do {
  116. if (i_piDfsRoot)
  117. {
  118. m_piDfsRoot = i_piDfsRoot;
  119. m_bDfsRoot = TRUE;
  120. hr = m_piDfsRoot->get_RootEntryPath(&m_bstrJPEntryPath);
  121. BREAK_IF_FAILED(hr);
  122. hr = m_piDfsRoot->get_Comment(&m_bstrJPComment);
  123. BREAK_IF_FAILED(hr);
  124. hr = m_piDfsRoot->get_Timeout(&m_lReferralTime);
  125. if (HRESULT_FROM_WIN32(RPC_X_BAD_STUB_DATA) == hr)
  126. {
  127. // NT4 doesn't support Timeout, NetDfsGetInfo with level 4 will return 1783 when managing a NT4 root
  128. hr = S_OK;
  129. m_bHideTimeout = TRUE;
  130. m_lReferralTime = 0;
  131. }
  132. BREAK_IF_FAILED(hr);
  133. }
  134. if (i_piDfsJPObject)
  135. {
  136. m_piDfsJPObject = i_piDfsJPObject;
  137. m_bDfsRoot = FALSE;
  138. hr = m_piDfsJPObject->get_EntryPath(&m_bstrJPEntryPath);
  139. BREAK_IF_FAILED(hr);
  140. hr = m_piDfsJPObject->get_Comment(&m_bstrJPComment);
  141. BREAK_IF_FAILED(hr);
  142. hr = m_piDfsJPObject->get_Timeout(&m_lReferralTime);
  143. if (HRESULT_FROM_WIN32(RPC_X_BAD_STUB_DATA) == hr)
  144. {
  145. // NT4 doesn't support Timeout, NetDfsGetInfo with level 4 will return 1783 when managing a NT4 root
  146. hr = S_OK;
  147. m_bHideTimeout = TRUE;
  148. m_lReferralTime = 0;
  149. }
  150. BREAK_IF_FAILED(hr);
  151. }
  152. } while (0);
  153. if (FAILED(hr))
  154. _ReSet();
  155. return hr;
  156. }
  157. HRESULT
  158. CReplicaSetPropPage::_Save(
  159. IN BSTR i_bstrJPComment,
  160. IN long i_lTimeout)
  161. {
  162. if (m_bDfsRoot)
  163. {
  164. RETURN_INVALIDARG_IF_NULL((IDfsRoot *)m_piDfsRoot);
  165. } else
  166. {
  167. RETURN_INVALIDARG_IF_NULL((IDfsJunctionPoint *)m_piDfsJPObject);
  168. }
  169. HRESULT hr = S_OK;
  170. if (FALSE == PROPSTRNOCHNG((BSTR)m_bstrJPComment, i_bstrJPComment))
  171. {
  172. if (m_bDfsRoot)
  173. hr = m_piDfsRoot->put_Comment(i_bstrJPComment);
  174. else
  175. hr = m_piDfsJPObject->put_Comment(i_bstrJPComment);
  176. if (SUCCEEDED(hr))
  177. m_bstrJPComment = i_bstrJPComment;
  178. }
  179. if (SUCCEEDED(hr) &&
  180. m_lReferralTime != i_lTimeout)
  181. {
  182. if (m_bDfsRoot)
  183. hr = m_piDfsRoot->put_Timeout(i_lTimeout);
  184. else
  185. hr = m_piDfsJPObject->put_Timeout(i_lTimeout);
  186. if (SUCCEEDED(hr))
  187. m_lReferralTime = i_lTimeout;
  188. }
  189. return hr;
  190. }
  191. LRESULT
  192. CReplicaSetPropPage::OnApply()
  193. /*++
  194. Routine Description:
  195. Called on when OK or Apply are pressed by the user.
  196. We get the information from the dialog box and notify
  197. the snapin
  198. MMCPropertyChangeNotify is used to pass on this
  199. information to the snapin.
  200. */
  201. {
  202. CWaitCursor wait;
  203. HRESULT hr = S_OK;
  204. DWORD dwTextLength = 0;
  205. int idControl = 0;
  206. int idString = 0;
  207. BOOL bValidInput = FALSE;
  208. ULONG ulTimeout = 0;
  209. CComBSTR bstrJPComment;
  210. do {
  211. idControl = IDC_REFFERAL_TIME;
  212. CComBSTR bstrTime;
  213. hr = GetInputText(GetDlgItem(IDC_REFFERAL_TIME), &bstrTime, &dwTextLength);
  214. BREAK_IF_FAILED(hr);
  215. if (0 == dwTextLength || !ValidateTimeout(bstrTime, &ulTimeout))
  216. {
  217. idString = IDS_MSG_TIMEOUT_INVALIDRANGE;
  218. break;
  219. }
  220. idControl = IDC_REPLICA_SET_COMMENT;
  221. hr = GetInputText(GetDlgItem(IDC_REPLICA_SET_COMMENT), &bstrJPComment, &dwTextLength);
  222. BREAK_IF_FAILED(hr);
  223. if (0 == dwTextLength)
  224. bstrJPComment = _T("");
  225. bValidInput = TRUE;
  226. } while (0);
  227. if (FAILED(hr))
  228. {
  229. SetActivePropertyPage(GetParent(), m_hWnd);
  230. DisplayMessageBoxForHR(hr);
  231. ::SetFocus(GetDlgItem(idControl));
  232. return FALSE;
  233. } else if (bValidInput)
  234. {
  235. hr = _Save(bstrJPComment, ulTimeout);
  236. if (FAILED(hr))
  237. {
  238. SetActivePropertyPage(GetParent(), m_hWnd);
  239. DisplayMessageBoxForHR(hr);
  240. return FALSE;
  241. }
  242. ::SendMessage(GetParent(), PSM_UNCHANGED, (WPARAM)m_hWnd, 0);
  243. if (m_lNotifyHandle && m_lNotifyParam)
  244. MMCPropertyChangeNotify(m_lNotifyHandle, m_lNotifyParam);
  245. return TRUE;
  246. } else
  247. {
  248. SetActivePropertyPage(GetParent(), m_hWnd);
  249. if (idString)
  250. DisplayMessageBoxWithOK(idString);
  251. ::SetFocus(GetDlgItem(idControl));
  252. return FALSE;
  253. }
  254. }
  255. LRESULT
  256. CReplicaSetPropPage::OnComment(
  257. IN WORD i_wNotifyCode,
  258. IN WORD i_wID,
  259. IN HWND i_hWndCtl,
  260. IN OUT BOOL& io_bHandled
  261. )
  262. {
  263. if (EN_CHANGE == i_wNotifyCode)
  264. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  265. return TRUE;
  266. }
  267. LRESULT
  268. CReplicaSetPropPage::OnReferralTime(
  269. IN WORD i_wNotifyCode,
  270. IN WORD i_wID,
  271. IN HWND i_hWndCtl,
  272. IN OUT BOOL& io_bHandled
  273. )
  274. /*++
  275. Routine Description:
  276. Called on an event on the Referral edit box
  277. Arguments:
  278. i_wNotifyCode - What type of event is this
  279. */
  280. {
  281. if (EN_CHANGE == i_wNotifyCode)
  282. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  283. return TRUE;
  284. }
  285. LRESULT
  286. CReplicaSetPropPage::OnParentClosing(
  287. IN UINT i_uMsg,
  288. IN WPARAM i_wParam,
  289. LPARAM i_lParam,
  290. IN OUT BOOL& io_bHandled
  291. )
  292. /*++
  293. Routine Description:
  294. Used by the node to tell the propery page to close.
  295. Arguments:
  296. Not used.
  297. --*/
  298. {
  299. ::SendMessage(GetParent(), PSM_PRESSBUTTON, PSBTN_CANCEL, 0);
  300. return TRUE;
  301. }
  302. HRESULT
  303. CReplicaSetPropPage::SetNotifyData(
  304. IN LONG_PTR i_lNotifyHandle,
  305. IN LPARAM i_lParam
  306. )
  307. /*++
  308. Routine Description:
  309. Set the value of notify handle to be used to notify changes
  310. and the lparam to be used for notifications.
  311. Arguments:
  312. i_lNotifyHandle - The notify handle.
  313. i_lParam - The lparam to be used with notifications
  314. --*/
  315. {
  316. m_lNotifyHandle = i_lNotifyHandle;
  317. m_lNotifyParam = i_lParam;
  318. return S_OK;
  319. }