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.

283 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: CacheSet.h
  7. //
  8. // Contents: CCacheSettingsDlg implementation. Allows the setting of file sharing
  9. // caching options.
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. #include "CacheSet.h"
  14. #include "filesvc.h"
  15. #include <htmlhelp.h>
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CCacheSettingsDlg dialog
  23. CCacheSettingsDlg::CCacheSettingsDlg(
  24. CWnd* pParent,
  25. DWORD& dwFlags)
  26. : CDialog(CCacheSettingsDlg::IDD, pParent),
  27. m_dwFlags (dwFlags)
  28. {
  29. //{{AFX_DATA_INIT(CCacheSettingsDlg)
  30. m_bAllowCaching = FALSE;
  31. m_hintStr = _T("");
  32. //}}AFX_DATA_INIT
  33. m_bAllowCaching = !GetCachedFlag (m_dwFlags, CSC_CACHE_NONE);
  34. }
  35. void CCacheSettingsDlg::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CDialog::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CCacheSettingsDlg)
  39. DDX_Control(pDX, IDC_CACHE_OPTIONS, m_cacheOptionsCombo);
  40. DDX_Check(pDX, IDC_ALLOW_CACHING, m_bAllowCaching);
  41. DDX_Text(pDX, IDC_HINT, m_hintStr);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CCacheSettingsDlg, CDialog)
  45. //{{AFX_MSG_MAP(CCacheSettingsDlg)
  46. ON_CBN_SELCHANGE(IDC_CACHE_OPTIONS, OnSelchangeCacheOptions)
  47. ON_BN_CLICKED(IDC_ALLOW_CACHING, OnAllowCaching)
  48. ON_MESSAGE(WM_HELP, OnHelp)
  49. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CCacheSettingsDlg message handlers
  54. void CCacheSettingsDlg::OnSelchangeCacheOptions()
  55. {
  56. int nIndex = m_cacheOptionsCombo.GetCurSel ();
  57. ASSERT (CB_ERR != nIndex);
  58. if ( CB_ERR != nIndex )
  59. {
  60. DWORD dwData = (DWORD)m_cacheOptionsCombo.GetItemData (nIndex);
  61. switch (dwData)
  62. {
  63. case IDS_MANUAL_WORKGROUP_SHARE:
  64. VERIFY (m_hintStr.LoadString (IDS_MANUAL_WORKGROUP_SHARE_HINT));
  65. break;
  66. case IDS_AUTOMATIC_WORKGROUP_SHARE:
  67. VERIFY (m_hintStr.LoadString (IDS_AUTOMATIC_WORKGROUP_SHARE_HINT));
  68. break;
  69. case IDS_AUTOMATIC_APPLICATION_SHARE:
  70. VERIFY (m_hintStr.LoadString (IDS_AUTOMATIC_APPLICATION_SHARE_HINT));
  71. break;
  72. default:
  73. ASSERT (0);
  74. break;
  75. }
  76. UpdateData (FALSE);
  77. }
  78. }
  79. void CCacheSettingsDlg::OnAllowCaching()
  80. {
  81. UpdateData (TRUE);
  82. if ( m_bAllowCaching )
  83. {
  84. GetDlgItem(IDC_CACHE_SETTINGS_LABEL)->EnableWindow(TRUE);
  85. m_cacheOptionsCombo.EnableWindow (TRUE);
  86. CString text;
  87. VERIFY (text.LoadString (IDS_MANUAL_WORKGROUP_SHARE));
  88. int nIndex = m_cacheOptionsCombo.SelectString (-1, text);
  89. ASSERT (CB_ERR != nIndex);
  90. if ( CB_ERR != nIndex )
  91. {
  92. VERIFY (m_hintStr.LoadString (IDS_MANUAL_WORKGROUP_SHARE_HINT));
  93. UpdateData (FALSE);
  94. }
  95. }
  96. else
  97. {
  98. GetDlgItem(IDC_CACHE_SETTINGS_LABEL)->EnableWindow(FALSE);
  99. m_cacheOptionsCombo.SetCurSel (-1);
  100. m_cacheOptionsCombo.EnableWindow (FALSE);
  101. m_hintStr = L"";
  102. UpdateData (FALSE);
  103. }
  104. }
  105. BOOL CCacheSettingsDlg::OnInitDialog()
  106. {
  107. CDialog::OnInitDialog();
  108. CString text;
  109. // Add the various caching options to the combo box.
  110. // Save the string ID in the item data for easy recognition of the
  111. // contents of the selected item.
  112. // If the given cache value is set, select the item and put its hint in the
  113. // hint field.
  114. VERIFY (text.LoadString (IDS_MANUAL_WORKGROUP_SHARE));
  115. int nIndex = m_cacheOptionsCombo.AddString (text);
  116. ASSERT (CB_ERR != nIndex && CB_ERRSPACE != nIndex);
  117. if (CB_ERR == nIndex || CB_ERRSPACE == nIndex)
  118. return TRUE;
  119. VERIFY (CB_ERR != m_cacheOptionsCombo.SetItemData (nIndex, IDS_MANUAL_WORKGROUP_SHARE));
  120. if ( GetCachedFlag (m_dwFlags, CSC_CACHE_MANUAL_REINT) )
  121. {
  122. VERIFY (CB_ERR != m_cacheOptionsCombo.SetCurSel (nIndex));
  123. VERIFY (m_hintStr.LoadString (IDS_MANUAL_WORKGROUP_SHARE_HINT));
  124. UpdateData (FALSE);
  125. }
  126. VERIFY (text.LoadString (IDS_AUTOMATIC_WORKGROUP_SHARE));
  127. nIndex = m_cacheOptionsCombo.AddString (text);
  128. ASSERT (CB_ERR != nIndex && CB_ERRSPACE != nIndex);
  129. if (CB_ERR == nIndex || CB_ERRSPACE == nIndex)
  130. return TRUE;
  131. VERIFY (CB_ERR != m_cacheOptionsCombo.SetItemData (nIndex, IDS_AUTOMATIC_WORKGROUP_SHARE));
  132. if ( GetCachedFlag (m_dwFlags, CSC_CACHE_AUTO_REINT) )
  133. {
  134. VERIFY (CB_ERR != m_cacheOptionsCombo.SetCurSel (nIndex));
  135. VERIFY (m_hintStr.LoadString (IDS_AUTOMATIC_WORKGROUP_SHARE_HINT));
  136. UpdateData (FALSE);
  137. }
  138. VERIFY (text.LoadString (IDS_AUTOMATIC_APPLICATION_SHARE));
  139. nIndex = m_cacheOptionsCombo.AddString (text);
  140. ASSERT (CB_ERR != nIndex && CB_ERRSPACE != nIndex);
  141. if (CB_ERR == nIndex || CB_ERRSPACE == nIndex)
  142. return TRUE;
  143. VERIFY (CB_ERR != m_cacheOptionsCombo.SetItemData (nIndex, IDS_AUTOMATIC_APPLICATION_SHARE));
  144. if ( GetCachedFlag (m_dwFlags, CSC_CACHE_VDO) )
  145. {
  146. VERIFY (CB_ERR != m_cacheOptionsCombo.SetCurSel (nIndex));
  147. VERIFY (m_hintStr.LoadString (IDS_AUTOMATIC_APPLICATION_SHARE_HINT));
  148. UpdateData (FALSE);
  149. }
  150. // Disable able the caching options combo box if caching is not allowed
  151. if ( !m_bAllowCaching )
  152. {
  153. m_cacheOptionsCombo.EnableWindow (FALSE);
  154. m_hintStr = L"";
  155. UpdateData (FALSE);
  156. }
  157. return TRUE; // return TRUE unless you set the focus to a control
  158. // EXCEPTION: OCX Property Pages should return FALSE
  159. }
  160. void CCacheSettingsDlg::OnOK()
  161. {
  162. DWORD dwNewFlag = 0;
  163. if ( !m_bAllowCaching )
  164. dwNewFlag = CSC_CACHE_NONE;
  165. else
  166. {
  167. int nIndex = m_cacheOptionsCombo.GetCurSel ();
  168. ASSERT (CB_ERR != nIndex);
  169. if ( CB_ERR != nIndex )
  170. {
  171. DWORD dwData = (DWORD)m_cacheOptionsCombo.GetItemData (nIndex);
  172. switch (dwData)
  173. {
  174. case IDS_MANUAL_WORKGROUP_SHARE:
  175. dwNewFlag = CSC_CACHE_MANUAL_REINT;
  176. break;
  177. case IDS_AUTOMATIC_WORKGROUP_SHARE:
  178. dwNewFlag = CSC_CACHE_AUTO_REINT;
  179. break;
  180. case IDS_AUTOMATIC_APPLICATION_SHARE:
  181. dwNewFlag = CSC_CACHE_VDO;
  182. break;
  183. default:
  184. ASSERT (0);
  185. break;
  186. }
  187. }
  188. }
  189. SetCachedFlag (&m_dwFlags, dwNewFlag);
  190. CDialog::OnOK();
  191. }
  192. BOOL CCacheSettingsDlg::GetCachedFlag( DWORD dwFlags, DWORD dwFlagToCheck )
  193. {
  194. return (dwFlags & CSC_MASK) == dwFlagToCheck;
  195. }
  196. VOID CCacheSettingsDlg::SetCachedFlag( DWORD* pdwFlags, DWORD dwNewFlag )
  197. {
  198. *pdwFlags &= ~CSC_MASK;
  199. *pdwFlags |= dwNewFlag;
  200. }
  201. /////////////////////////////////////////////////////////////////////
  202. // Help
  203. BOOL CCacheSettingsDlg::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  204. {
  205. return DoHelp(lParam, HELP_DIALOG_TOPIC(IDD_SMB_CACHE_SETTINGS));
  206. }
  207. BOOL CCacheSettingsDlg::OnContextHelp(WPARAM wParam, LPARAM /*lParam*/)
  208. {
  209. return DoContextHelp(wParam, HELP_DIALOG_TOPIC(IDD_SMB_CACHE_SETTINGS));
  210. }
  211. ///////////////////////////////////////////////////////////////////////////////
  212. // CacheSettingsDlg ()
  213. //
  214. // Invoke a dialog to set/modify cache settings for a share
  215. //
  216. // RETURNS
  217. // Return S_OK if the user clicked on the OK button.
  218. // Return S_FALSE if the user clicked on the Cancel button.
  219. // Return E_OUTOFMEMORY if there is not enough memory.
  220. // Return E_UNEXPECTED if an expected error occured (eg: bad parameter)
  221. //
  222. ///////////////////////////////////////////////////////////////////////////////
  223. HRESULT
  224. CacheSettingsDlg(
  225. HWND hwndParent, // IN: Parent's window handle
  226. DWORD& dwFlags) // IN & OUT: share flags
  227. {
  228. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  229. ASSERT(::IsWindow(hwndParent));
  230. HRESULT hResult = S_OK;
  231. CWnd parentWnd;
  232. parentWnd.Attach (hwndParent);
  233. CCacheSettingsDlg dlg (&parentWnd, dwFlags);
  234. CThemeContextActivator activator;
  235. if (IDOK != dlg.DoModal())
  236. hResult = S_FALSE;
  237. parentWnd.Detach ();
  238. return hResult;
  239. } // CacheSettingsDlg()