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.

317 lines
7.4 KiB

  1. /*++
  2. Module Name:
  3. LinkFilt.cpp
  4. Abstract:
  5. This module contains the implementation for CFilterDfsLinks.
  6. This class displays the Dfs link filter Dialog.
  7. */
  8. #include "stdafx.h"
  9. #include "LinkFilt.h"
  10. #include "utils.h"
  11. #include "dfshelp.h"
  12. #include "netutils.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAddToDfs
  15. CFilterDfsLinks::CFilterDfsLinks() :
  16. m_ulMaxLimit(0),
  17. m_lLinkFilterType(FILTERDFSLINKS_TYPE_NO_FILTER)
  18. {
  19. }
  20. CFilterDfsLinks::~CFilterDfsLinks()
  21. {
  22. }
  23. HRESULT CFilterDfsLinks::put_EnumFilterType
  24. (
  25. FILTERDFSLINKS_TYPE i_lLinkFilterType
  26. )
  27. {
  28. m_lLinkFilterType = i_lLinkFilterType;
  29. return S_OK;
  30. }
  31. HRESULT CFilterDfsLinks::get_EnumFilterType
  32. (
  33. FILTERDFSLINKS_TYPE *o_plLinkFilterType
  34. )
  35. {
  36. if (!o_plLinkFilterType)
  37. return E_INVALIDARG;
  38. *o_plLinkFilterType = m_lLinkFilterType;
  39. return S_OK;
  40. }
  41. HRESULT CFilterDfsLinks::put_EnumFilter
  42. (
  43. BSTR i_bstrEnumFilter
  44. )
  45. {
  46. m_bstrEnumFilter = i_bstrEnumFilter ? i_bstrEnumFilter : _T("");
  47. if (!m_bstrEnumFilter)
  48. return E_OUTOFMEMORY;
  49. return S_OK;
  50. }
  51. HRESULT CFilterDfsLinks::get_EnumFilter
  52. (
  53. BSTR *o_pbstrEnumFilter
  54. )
  55. {
  56. if (!o_pbstrEnumFilter)
  57. return E_INVALIDARG;
  58. *o_pbstrEnumFilter = SysAllocString(m_bstrEnumFilter);
  59. if (!*o_pbstrEnumFilter)
  60. return E_OUTOFMEMORY;
  61. return S_OK;
  62. }
  63. HRESULT CFilterDfsLinks::put_MaxLimit
  64. (
  65. ULONG i_ulMaxLimit
  66. )
  67. {
  68. m_ulMaxLimit = i_ulMaxLimit;
  69. return S_OK;
  70. }
  71. HRESULT CFilterDfsLinks::get_MaxLimit
  72. (
  73. ULONG *o_pulMaxLimit
  74. )
  75. {
  76. if (!o_pulMaxLimit)
  77. return E_INVALIDARG;
  78. *o_pulMaxLimit = m_ulMaxLimit;
  79. return S_OK;
  80. }
  81. extern WNDPROC g_fnOldEditCtrlProc;
  82. LRESULT CFilterDfsLinks::OnInitDialog
  83. (
  84. UINT uMsg,
  85. WPARAM wParam,
  86. LPARAM lParam,
  87. BOOL& bHandled
  88. )
  89. {
  90. CComBSTR bstrBeginWith, bstrContain;
  91. HRESULT hr = LoadStringFromResource(IDS_FILTERDFSLINKS_BEGINWITH, &bstrBeginWith);
  92. if (FAILED(hr))
  93. return FALSE;
  94. hr = LoadStringFromResource(IDS_FILTERDFSLINKS_CONTAIN, &bstrContain);
  95. if (FAILED(hr))
  96. return FALSE;
  97. SetDlgItemText(IDC_FILTERDFSLINKS_FILTER, m_bstrEnumFilter);
  98. TCHAR szMaxLimit[16];
  99. _stprintf(szMaxLimit, _T("%u"), m_ulMaxLimit);
  100. SetDlgItemText(IDC_FILTERDFSLINKS_MAXLIMIT, szMaxLimit);
  101. SendDlgItemMessage(IDC_FILTERDFSLINKS_MAXLIMIT, EM_LIMITTEXT, 5, 0);
  102. CheckRadioButton(
  103. IDC_FILTERDFSLINKS_RADIO_NO,
  104. IDC_FILTERDFSLINKS_RADIO_YES,
  105. (m_lLinkFilterType == FILTERDFSLINKS_TYPE_NO_FILTER ?
  106. IDC_FILTERDFSLINKS_RADIO_NO :
  107. IDC_FILTERDFSLINKS_RADIO_YES));
  108. SendDlgItemMessage(IDC_FILTERDFSLINKS_FILTER_TYPE, CB_INSERTSTRING, 0, (LPARAM)(BSTR)bstrBeginWith);
  109. SendDlgItemMessage(IDC_FILTERDFSLINKS_FILTER_TYPE, CB_INSERTSTRING, 1, (LPARAM)(BSTR)bstrContain);
  110. if (m_lLinkFilterType == FILTERDFSLINKS_TYPE_CONTAIN)
  111. SendDlgItemMessage(IDC_FILTERDFSLINKS_FILTER_TYPE, CB_SETCURSEL, 1, 0);
  112. else
  113. SendDlgItemMessage(IDC_FILTERDFSLINKS_FILTER_TYPE, CB_SETCURSEL, 0, 0);
  114. if (m_lLinkFilterType == FILTERDFSLINKS_TYPE_NO_FILTER)
  115. {
  116. // disable combo and edit box
  117. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER_TYPE), FALSE);
  118. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER), FALSE);
  119. }
  120. g_fnOldEditCtrlProc = reinterpret_cast<WNDPROC>(
  121. ::SetWindowLongPtr(
  122. GetDlgItem(IDC_FILTERDFSLINKS_MAXLIMIT),
  123. GWLP_WNDPROC,
  124. reinterpret_cast<LONG_PTR>(NoPasteEditCtrlProc)));
  125. return TRUE; // Let the system set the focus
  126. }
  127. LRESULT CFilterDfsLinks::OnRadioNo
  128. (
  129. WORD wNotifyCode,
  130. WORD wID,
  131. HWND hWndCtl,
  132. BOOL& bHandled
  133. )
  134. {
  135. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER_TYPE), FALSE);
  136. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER_LABEL), FALSE);
  137. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER), FALSE);
  138. return TRUE;
  139. }
  140. LRESULT CFilterDfsLinks::OnRadioYes
  141. (
  142. WORD wNotifyCode,
  143. WORD wID,
  144. HWND hWndCtl,
  145. BOOL& bHandled
  146. )
  147. {
  148. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER_TYPE), TRUE);
  149. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER_LABEL), TRUE);
  150. ::EnableWindow(GetDlgItem(IDC_FILTERDFSLINKS_FILTER), TRUE);
  151. return TRUE;
  152. }
  153. /*++
  154. This function is called when a user clicks the ? in the top right of a property sheet
  155. and then clciks a control, or when they hit F1 in a control.
  156. --*/
  157. LRESULT CFilterDfsLinks::OnCtxHelp(
  158. IN UINT i_uMsg,
  159. IN WPARAM i_wParam,
  160. IN LPARAM i_lParam,
  161. IN OUT BOOL& io_bHandled
  162. )
  163. {
  164. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  165. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  166. return FALSE;
  167. ::WinHelp((HWND)(lphi->hItemHandle),
  168. DFS_CTX_HELP_FILE,
  169. HELP_WM_HELP,
  170. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_FILTERDFSLINKS);
  171. return TRUE;
  172. }
  173. /*++
  174. This function handles "What's This" help when a user right clicks the control
  175. --*/
  176. LRESULT CFilterDfsLinks::OnCtxMenuHelp(
  177. IN UINT i_uMsg,
  178. IN WPARAM i_wParam,
  179. IN LPARAM i_lParam,
  180. IN OUT BOOL& io_bHandled
  181. )
  182. {
  183. ::WinHelp((HWND)i_wParam,
  184. DFS_CTX_HELP_FILE,
  185. HELP_CONTEXTMENU,
  186. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_FILTERDFSLINKS);
  187. return TRUE;
  188. }
  189. LRESULT CFilterDfsLinks::OnOK
  190. (
  191. WORD wNotifyCode,
  192. WORD wID,
  193. HWND hWndCtl,
  194. BOOL& bHandled
  195. )
  196. {
  197. BOOL bValidInput = FALSE;
  198. int idControl = 0;
  199. int idString = 0;
  200. HRESULT hr = S_OK;
  201. do {
  202. DWORD dwTextLength = 0;
  203. // Validate IDC_FILTERDFSLINKS_MAXLIMIT
  204. idControl = IDC_FILTERDFSLINKS_MAXLIMIT;
  205. CComBSTR bstrTemp;
  206. hr = GetInputText(GetDlgItem(idControl), &bstrTemp, &dwTextLength);
  207. if (FAILED(hr))
  208. break;
  209. if (0 == dwTextLength)
  210. {
  211. idString = IDS_MSG_EMPTY_LINKFILTMAX;
  212. break;
  213. }
  214. m_ulMaxLimit = (ULONG)_wtoi64(bstrTemp);
  215. if (IsDlgButtonChecked(IDC_FILTERDFSLINKS_RADIO_NO))
  216. {
  217. m_lLinkFilterType = FILTERDFSLINKS_TYPE_NO_FILTER;
  218. m_bstrEnumFilter = _T("");
  219. } else
  220. {
  221. // Validate IDC_FILTERDFSLINKS_FILTER_TYPE
  222. m_lLinkFilterType = (0 == SendDlgItemMessage(IDC_FILTERDFSLINKS_FILTER_TYPE, CB_GETCURSEL, 0, 0))
  223. ? FILTERDFSLINKS_TYPE_BEGINWITH : FILTERDFSLINKS_TYPE_CONTAIN;
  224. // Validate IDC_FILTERDFSLINKS_FILTER
  225. idControl = IDC_FILTERDFSLINKS_FILTER;
  226. m_bstrEnumFilter.Empty();
  227. hr = GetInputText(GetDlgItem(idControl), &m_bstrEnumFilter, &dwTextLength);
  228. if (FAILED(hr))
  229. break;
  230. if (0 == dwTextLength)
  231. m_bstrEnumFilter = _T("");
  232. }
  233. bValidInput = TRUE;
  234. } while (0);
  235. if (FAILED(hr))
  236. {
  237. DisplayMessageBoxForHR(hr);
  238. ::SetFocus(GetDlgItem(idControl));
  239. return FALSE;
  240. } else if (bValidInput)
  241. {
  242. EndDialog(S_OK);
  243. return TRUE;
  244. } else
  245. {
  246. if (idString)
  247. DisplayMessageBoxWithOK(idString);
  248. ::SetFocus(GetDlgItem(idControl));
  249. return FALSE;
  250. }
  251. }
  252. LRESULT CFilterDfsLinks::OnCancel
  253. (
  254. WORD wNotifyCode,
  255. WORD wID,
  256. HWND hWndCtl,
  257. BOOL& bHandled
  258. )
  259. {
  260. EndDialog(S_FALSE);
  261. return TRUE;
  262. }