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.

416 lines
9.9 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. // Q148388 How to Change Default Control Focus on CPropertyPageEx
  57. //
  58. LRESULT CReplicaSetPropPage::OnSetPageFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  59. {
  60. ::SetFocus(GetDlgItem(IDC_REPLICA_SET_COMMENT));
  61. return 0;
  62. }
  63. BOOL CReplicaSetPropPage::OnSetActive()
  64. {
  65. PostMessage(WM_SETPAGEFOCUS, 0, 0L);
  66. return TRUE;
  67. }
  68. /*++
  69. This function is called when a user clicks the ? in the top right of a property sheet
  70. and then clciks a control, or when they hit F1 in a control.
  71. --*/
  72. LRESULT CReplicaSetPropPage::OnCtxHelp(
  73. IN UINT i_uMsg,
  74. IN WPARAM i_wParam,
  75. IN LPARAM i_lParam,
  76. IN OUT BOOL& io_bHandled
  77. )
  78. {
  79. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  80. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  81. return FALSE;
  82. ::WinHelp((HWND)(lphi->hItemHandle),
  83. DFS_CTX_HELP_FILE,
  84. HELP_WM_HELP,
  85. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_JP_PROP);
  86. return TRUE;
  87. }
  88. /*++
  89. This function handles "What's This" help when a user right clicks the control
  90. --*/
  91. LRESULT CReplicaSetPropPage::OnCtxMenuHelp(
  92. IN UINT i_uMsg,
  93. IN WPARAM i_wParam,
  94. IN LPARAM i_lParam,
  95. IN OUT BOOL& io_bHandled
  96. )
  97. {
  98. ::WinHelp((HWND)i_wParam,
  99. DFS_CTX_HELP_FILE,
  100. HELP_CONTEXTMENU,
  101. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_JP_PROP);
  102. return TRUE;
  103. }
  104. void
  105. CReplicaSetPropPage::_ReSet()
  106. {
  107. if ((IDfsRoot *)m_piDfsRoot)
  108. m_piDfsRoot.Release();
  109. if ((IDfsJunctionPoint *)m_piDfsJPObject)
  110. m_piDfsJPObject.Release();
  111. m_bstrJPEntryPath.Empty();
  112. m_bstrJPComment.Empty();
  113. m_lReferralTime = 0;
  114. m_bDfsRoot = FALSE;
  115. m_bHideTimeout = FALSE;
  116. }
  117. HRESULT
  118. CReplicaSetPropPage::Initialize(
  119. IN IDfsRoot* i_piDfsRoot,
  120. IN IDfsJunctionPoint* i_piDfsJPObject
  121. )
  122. {
  123. if (i_piDfsRoot && i_piDfsJPObject ||
  124. !i_piDfsRoot && !i_piDfsJPObject)
  125. return E_INVALIDARG;
  126. _ReSet();
  127. HRESULT hr = S_OK;
  128. do {
  129. if (i_piDfsRoot)
  130. {
  131. m_piDfsRoot = i_piDfsRoot;
  132. m_bDfsRoot = TRUE;
  133. hr = m_piDfsRoot->get_RootEntryPath(&m_bstrJPEntryPath);
  134. BREAK_IF_FAILED(hr);
  135. hr = m_piDfsRoot->get_Comment(&m_bstrJPComment);
  136. BREAK_IF_FAILED(hr);
  137. hr = m_piDfsRoot->get_Timeout(&m_lReferralTime);
  138. if (HRESULT_FROM_WIN32(RPC_X_BAD_STUB_DATA) == hr)
  139. {
  140. // NT4 doesn't support Timeout, NetDfsGetInfo with level 4 will return 1783 when managing a NT4 root
  141. hr = S_OK;
  142. m_bHideTimeout = TRUE;
  143. m_lReferralTime = 0;
  144. }
  145. BREAK_IF_FAILED(hr);
  146. }
  147. if (i_piDfsJPObject)
  148. {
  149. m_piDfsJPObject = i_piDfsJPObject;
  150. m_bDfsRoot = FALSE;
  151. hr = m_piDfsJPObject->get_EntryPath(&m_bstrJPEntryPath);
  152. BREAK_IF_FAILED(hr);
  153. hr = m_piDfsJPObject->get_Comment(&m_bstrJPComment);
  154. BREAK_IF_FAILED(hr);
  155. hr = m_piDfsJPObject->get_Timeout(&m_lReferralTime);
  156. if (HRESULT_FROM_WIN32(RPC_X_BAD_STUB_DATA) == hr)
  157. {
  158. // NT4 doesn't support Timeout, NetDfsGetInfo with level 4 will return 1783 when managing a NT4 root
  159. hr = S_OK;
  160. m_bHideTimeout = TRUE;
  161. m_lReferralTime = 0;
  162. }
  163. BREAK_IF_FAILED(hr);
  164. }
  165. } while (0);
  166. if (FAILED(hr))
  167. _ReSet();
  168. return hr;
  169. }
  170. HRESULT
  171. CReplicaSetPropPage::_Save(
  172. IN BSTR i_bstrJPComment,
  173. IN long i_lTimeout)
  174. {
  175. if (m_bDfsRoot)
  176. {
  177. RETURN_INVALIDARG_IF_NULL((IDfsRoot *)m_piDfsRoot);
  178. } else
  179. {
  180. RETURN_INVALIDARG_IF_NULL((IDfsJunctionPoint *)m_piDfsJPObject);
  181. }
  182. HRESULT hr = S_OK;
  183. if (FALSE == PROPSTRNOCHNG((BSTR)m_bstrJPComment, i_bstrJPComment))
  184. {
  185. if (m_bDfsRoot)
  186. hr = m_piDfsRoot->put_Comment(i_bstrJPComment);
  187. else
  188. hr = m_piDfsJPObject->put_Comment(i_bstrJPComment);
  189. if (SUCCEEDED(hr))
  190. m_bstrJPComment = i_bstrJPComment;
  191. }
  192. if (SUCCEEDED(hr) &&
  193. m_lReferralTime != i_lTimeout)
  194. {
  195. if (m_bDfsRoot)
  196. hr = m_piDfsRoot->put_Timeout(i_lTimeout);
  197. else
  198. hr = m_piDfsJPObject->put_Timeout(i_lTimeout);
  199. if (SUCCEEDED(hr))
  200. m_lReferralTime = i_lTimeout;
  201. }
  202. return hr;
  203. }
  204. LRESULT
  205. CReplicaSetPropPage::OnApply()
  206. /*++
  207. Routine Description:
  208. Called on when OK or Apply are pressed by the user.
  209. We get the information from the dialog box and notify
  210. the snapin
  211. MMCPropertyChangeNotify is used to pass on this
  212. information to the snapin.
  213. */
  214. {
  215. CWaitCursor wait;
  216. HRESULT hr = S_OK;
  217. DWORD dwTextLength = 0;
  218. int idControl = 0;
  219. int idString = 0;
  220. BOOL bValidInput = FALSE;
  221. ULONG ulTimeout = 0;
  222. CComBSTR bstrJPComment;
  223. do {
  224. idControl = IDC_REFFERAL_TIME;
  225. CComBSTR bstrTime;
  226. hr = GetInputText(GetDlgItem(IDC_REFFERAL_TIME), &bstrTime, &dwTextLength);
  227. BREAK_IF_FAILED(hr);
  228. if (0 == dwTextLength || !ValidateTimeout(bstrTime, &ulTimeout))
  229. {
  230. idString = IDS_MSG_TIMEOUT_INVALIDRANGE;
  231. break;
  232. }
  233. idControl = IDC_REPLICA_SET_COMMENT;
  234. hr = GetInputText(GetDlgItem(IDC_REPLICA_SET_COMMENT), &bstrJPComment, &dwTextLength);
  235. BREAK_IF_FAILED(hr);
  236. if (0 == dwTextLength)
  237. bstrJPComment = _T("");
  238. bValidInput = TRUE;
  239. } while (0);
  240. if (FAILED(hr))
  241. {
  242. SetActivePropertyPage(GetParent(), m_hWnd);
  243. DisplayMessageBoxForHR(hr);
  244. ::SetFocus(GetDlgItem(idControl));
  245. return FALSE;
  246. } else if (bValidInput)
  247. {
  248. hr = _Save(bstrJPComment, ulTimeout);
  249. if (FAILED(hr))
  250. {
  251. SetActivePropertyPage(GetParent(), m_hWnd);
  252. DisplayMessageBoxForHR(hr);
  253. return FALSE;
  254. }
  255. ::SendMessage(GetParent(), PSM_UNCHANGED, (WPARAM)m_hWnd, 0);
  256. if (m_lNotifyHandle && m_lNotifyParam)
  257. MMCPropertyChangeNotify(m_lNotifyHandle, m_lNotifyParam);
  258. return TRUE;
  259. } else
  260. {
  261. SetActivePropertyPage(GetParent(), m_hWnd);
  262. if (idString)
  263. DisplayMessageBoxWithOK(idString);
  264. ::SetFocus(GetDlgItem(idControl));
  265. return FALSE;
  266. }
  267. }
  268. LRESULT
  269. CReplicaSetPropPage::OnComment(
  270. IN WORD i_wNotifyCode,
  271. IN WORD i_wID,
  272. IN HWND i_hWndCtl,
  273. IN OUT BOOL& io_bHandled
  274. )
  275. {
  276. if (EN_CHANGE == i_wNotifyCode)
  277. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  278. return TRUE;
  279. }
  280. LRESULT
  281. CReplicaSetPropPage::OnReferralTime(
  282. IN WORD i_wNotifyCode,
  283. IN WORD i_wID,
  284. IN HWND i_hWndCtl,
  285. IN OUT BOOL& io_bHandled
  286. )
  287. /*++
  288. Routine Description:
  289. Called on an event on the Referral edit box
  290. Arguments:
  291. i_wNotifyCode - What type of event is this
  292. */
  293. {
  294. if (EN_CHANGE == i_wNotifyCode)
  295. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  296. return TRUE;
  297. }
  298. LRESULT
  299. CReplicaSetPropPage::OnParentClosing(
  300. IN UINT i_uMsg,
  301. IN WPARAM i_wParam,
  302. LPARAM i_lParam,
  303. IN OUT BOOL& io_bHandled
  304. )
  305. /*++
  306. Routine Description:
  307. Used by the node to tell the propery page to close.
  308. Arguments:
  309. Not used.
  310. --*/
  311. {
  312. ::SendMessage(GetParent(), PSM_PRESSBUTTON, PSBTN_CANCEL, 0);
  313. return TRUE;
  314. }
  315. HRESULT
  316. CReplicaSetPropPage::SetNotifyData(
  317. IN LONG_PTR i_lNotifyHandle,
  318. IN LPARAM i_lParam
  319. )
  320. /*++
  321. Routine Description:
  322. Set the value of notify handle to be used to notify changes
  323. and the lparam to be used for notifications.
  324. Arguments:
  325. i_lNotifyHandle - The notify handle.
  326. i_lParam - The lparam to be used with notifications
  327. --*/
  328. {
  329. m_lNotifyHandle = i_lNotifyHandle;
  330. m_lNotifyParam = i_lParam;
  331. return S_OK;
  332. }