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.

510 lines
15 KiB

  1. //
  2. // proplocalres.cpp: local resources property sheet dialog proc
  3. //
  4. // Tab B
  5. //
  6. // Copyright Microsoft Corporation 2000
  7. // nadima
  8. #include "stdafx.h"
  9. #define TRC_GROUP TRC_GROUP_UI
  10. #define TRC_FILE "proplocalres"
  11. #include <atrcapi.h>
  12. #include "sh.h"
  13. #include "commctrl.h"
  14. #include "proplocalres.h"
  15. #ifdef OS_WINCE
  16. #include <ceconfig.h>
  17. #endif
  18. //
  19. // Controls that need to be disabled/enabled
  20. // during connection (for progress animation)
  21. //
  22. CTL_ENABLE connectingDisableCtlsPLocalRes[] = {
  23. {IDC_COMBO_SOUND_OPTIONS, FALSE},
  24. {IDC_COMBO_SEND_KEYS, FALSE},
  25. {IDC_CHECK_REDIRECT_DRIVES, FALSE},
  26. {IDC_CHECK_REDIRECT_PRINTERS, FALSE},
  27. {IDC_CHECK_REDIRECT_COM, FALSE},
  28. {IDC_CHECK_REDIRECT_SMARTCARD, FALSE}
  29. };
  30. const UINT numConnectingDisableCtlsPLocalRes =
  31. sizeof(connectingDisableCtlsPLocalRes)/
  32. sizeof(connectingDisableCtlsPLocalRes[0]);
  33. CPropLocalRes* CPropLocalRes::_pPropLocalResInstance = NULL;
  34. CPropLocalRes::CPropLocalRes(HINSTANCE hInstance, CTscSettings* pTscSet, CSH* pSh)
  35. {
  36. DC_BEGIN_FN("CPropLocalRes");
  37. _hInstance = hInstance;
  38. CPropLocalRes::_pPropLocalResInstance = this;
  39. _pTscSet = pTscSet;
  40. _pSh = pSh;
  41. TRC_ASSERT(_pTscSet,(TB,_T("_pTscSet is null")));
  42. TRC_ASSERT(_pSh,(TB,_T("_pSh is null")));
  43. if(!LoadLocalResourcesPgStrings())
  44. {
  45. TRC_ERR((TB, _T("Failed LoadLocalResourcesPgStrings()")));
  46. }
  47. //
  48. // Disable keyb hook on win9x.
  49. //
  50. _fRunningOnWin9x = FALSE;
  51. #ifdef OS_WINCE
  52. OSVERSIONINFO osVersionInfo;
  53. osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  54. #else
  55. OSVERSIONINFOA osVersionInfo;
  56. osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
  57. #endif
  58. //call A version to avoid wrapping
  59. #ifdef OS_WINCE
  60. if(GetVersionEx(&osVersionInfo))
  61. #else
  62. if(GetVersionExA(&osVersionInfo))
  63. #endif
  64. {
  65. _fRunningOnWin9x = (osVersionInfo.dwPlatformId ==
  66. VER_PLATFORM_WIN32_WINDOWS);
  67. }
  68. else
  69. {
  70. _fRunningOnWin9x = FALSE;
  71. TRC_ERR((TB,_T("GetVersionEx failed: %d\n"), GetLastError()));
  72. }
  73. DC_END_FN();
  74. }
  75. CPropLocalRes::~CPropLocalRes()
  76. {
  77. CPropLocalRes::_pPropLocalResInstance = NULL;
  78. }
  79. INT_PTR CALLBACK CPropLocalRes::StaticPropPgLocalResDialogProc(HWND hwndDlg,
  80. UINT uMsg,
  81. WPARAM wParam,
  82. LPARAM lParam)
  83. {
  84. //
  85. // Delegate to appropriate instance (only works for single instance dialogs)
  86. //
  87. DC_BEGIN_FN("StaticDialogBoxProc");
  88. DCINT retVal = 0;
  89. TRC_ASSERT(_pPropLocalResInstance, (TB, _T("localres dialog has NULL static instance ptr\n")));
  90. retVal = _pPropLocalResInstance->PropPgLocalResDialogProc( hwndDlg,
  91. uMsg,
  92. wParam,
  93. lParam);
  94. DC_END_FN();
  95. return retVal;
  96. }
  97. INT_PTR CALLBACK CPropLocalRes::PropPgLocalResDialogProc (HWND hwndDlg,
  98. UINT uMsg,
  99. WPARAM wParam,
  100. LPARAM lParam)
  101. {
  102. DC_BEGIN_FN("PropPgLocalResDialogProc");
  103. switch(uMsg)
  104. {
  105. case WM_INITDIALOG:
  106. {
  107. #ifndef OS_WINCE
  108. int i;
  109. #endif
  110. //
  111. // Position the dialog within the tab
  112. //
  113. SetWindowPos( hwndDlg, HWND_TOP,
  114. _rcTabDispayArea.left, _rcTabDispayArea.top,
  115. _rcTabDispayArea.right - _rcTabDispayArea.left,
  116. _rcTabDispayArea.bottom - _rcTabDispayArea.top,
  117. 0);
  118. InitSendKeysToServerCombo(hwndDlg);
  119. InitPlaySoundCombo(hwndDlg);
  120. BOOL fDriveRedir = _pTscSet->GetDriveRedirection();
  121. CheckDlgButton(hwndDlg, IDC_CHECK_REDIRECT_DRIVES,
  122. (fDriveRedir ? BST_CHECKED : BST_UNCHECKED));
  123. BOOL fPrinterRedir = _pTscSet->GetPrinterRedirection();
  124. CheckDlgButton(hwndDlg, IDC_CHECK_REDIRECT_PRINTERS,
  125. (fPrinterRedir ? BST_CHECKED : BST_UNCHECKED));
  126. BOOL fCOMRedir = _pTscSet->GetCOMPortRedirection();
  127. CheckDlgButton(hwndDlg, IDC_CHECK_REDIRECT_COM,
  128. (fCOMRedir ? BST_CHECKED : BST_UNCHECKED));
  129. BOOL fScardRedir = _pTscSet->GetSCardRedirection();
  130. CheckDlgButton(hwndDlg, IDC_CHECK_REDIRECT_SMARTCARD,
  131. (fScardRedir ? BST_CHECKED : BST_UNCHECKED));
  132. #ifdef OS_WINCE
  133. if ((GetFileAttributes(PRINTER_APPLET_NAME) == -1) ||
  134. (g_CEConfig == CE_CONFIG_WBT))
  135. {
  136. ShowWindow(GetDlgItem(hwndDlg,IDC_SETUP_PRINTER),SW_HIDE);
  137. }
  138. #endif
  139. if(!CUT::IsSCardReaderInstalled())
  140. {
  141. //
  142. // Hide the SCard checkbox
  143. //
  144. ShowWindow(GetDlgItem(hwndDlg,IDC_CHECK_REDIRECT_SMARTCARD),
  145. SW_HIDE);
  146. }
  147. _pSh->SH_ThemeDialogWindow(hwndDlg, ETDT_ENABLETAB);
  148. return TRUE;
  149. }
  150. break; //WM_INITDIALOG
  151. case WM_TSC_ENABLECONTROLS:
  152. {
  153. //
  154. // wParam is TRUE to enable controls,
  155. // FALSE to disable them
  156. //
  157. CSH::EnableControls( hwndDlg,
  158. connectingDisableCtlsPLocalRes,
  159. numConnectingDisableCtlsPLocalRes,
  160. wParam ? TRUE : FALSE);
  161. }
  162. break;
  163. #ifdef OS_WINCE
  164. case WM_COMMAND:
  165. {
  166. switch(DC_GET_WM_COMMAND_ID(wParam))
  167. {
  168. case IDC_SETUP_PRINTER:
  169. SHELLEXECUTEINFO sei;
  170. memset(&sei,0,sizeof(SHELLEXECUTEINFO));
  171. sei.cbSize = sizeof(sei);
  172. sei.hwnd = hwndDlg;
  173. sei.lpFile = L"ctlpnl.EXE";
  174. sei.lpParameters = _T("wbtprncpl.dll,0");
  175. sei.lpDirectory = NULL;
  176. sei.nShow = SW_SHOWNORMAL;
  177. ShellExecuteEx(&sei);
  178. break;
  179. default:
  180. {
  181. if ( (HIWORD(wParam) == BN_CLICKED) && (IDC_CHECK_REDIRECT_PRINTERS == (int)LOWORD(wParam)))
  182. {
  183. LRESULT lResult = SendMessage(GetDlgItem(hwndDlg,IDC_CHECK_REDIRECT_PRINTERS),
  184. BM_GETCHECK,
  185. 0,
  186. 0);
  187. if ((lResult == BST_CHECKED) && (GetFileAttributes(PRINTER_APPLET_NAME) != -1))
  188. {
  189. EnableWindow(GetDlgItem(hwndDlg,IDC_SETUP_PRINTER),TRUE);
  190. }
  191. else if (lResult == BST_UNCHECKED)
  192. {
  193. EnableWindow(GetDlgItem(hwndDlg,IDC_SETUP_PRINTER),FALSE);
  194. }
  195. }
  196. }
  197. }
  198. }
  199. break;
  200. #endif
  201. case WM_SAVEPROPSHEET: //Intentional fallthru
  202. case WM_DESTROY:
  203. {
  204. //
  205. // Save page settings
  206. //
  207. //keyboard hook
  208. int keyboardHookMode = (int)SendMessage(
  209. GetDlgItem(hwndDlg, IDC_COMBO_SEND_KEYS),
  210. CB_GETCURSEL, 0, 0);
  211. _pTscSet->SetKeyboardHookMode(keyboardHookMode);
  212. //sound redirection
  213. int soundRedirIdx = (int)SendMessage(
  214. GetDlgItem(hwndDlg, IDC_COMBO_SOUND_OPTIONS),
  215. CB_GETCURSEL, 0, 0);
  216. int soundMode = MapComboIdxSoundRedirMode(soundRedirIdx);
  217. _pTscSet->SetSoundRedirectionMode( soundMode);
  218. //drive redirection
  219. BOOL fDriveRedir = IsDlgButtonChecked(hwndDlg,
  220. IDC_CHECK_REDIRECT_DRIVES);
  221. _pTscSet->SetDriveRedirection(fDriveRedir);
  222. //printer redirection
  223. BOOL fPrinterRedir = IsDlgButtonChecked(hwndDlg,
  224. IDC_CHECK_REDIRECT_PRINTERS);
  225. _pTscSet->SetPrinterRedirection(fPrinterRedir);
  226. //com port
  227. BOOL fCOMPortRedir = IsDlgButtonChecked(hwndDlg,
  228. IDC_CHECK_REDIRECT_COM);
  229. _pTscSet->SetCOMPortRedirection(fCOMPortRedir);
  230. //scard
  231. BOOL fSCardRedir = IsDlgButtonChecked(hwndDlg,
  232. IDC_CHECK_REDIRECT_SMARTCARD);
  233. _pTscSet->SetSCardRedirection(fSCardRedir);
  234. }
  235. break; //WM_DESTROY
  236. }
  237. DC_END_FN();
  238. return 0;
  239. }
  240. //
  241. // Load resources for the local resources dialog
  242. //
  243. BOOL CPropLocalRes::LoadLocalResourcesPgStrings()
  244. {
  245. DC_BEGIN_FN("LoadLocalResourcesPgStrings");
  246. //
  247. // Load sendkeys strings
  248. //
  249. #ifndef OS_WINCE
  250. if(!LoadString(_hInstance,
  251. UI_IDS_SENDKEYS_FSCREEN,
  252. _szSendKeysInFScreen,
  253. sizeof(_szSendKeysInFScreen)/sizeof(TCHAR)))
  254. {
  255. TRC_ERR((TB, _T("Failed to load UI_IDS_FULLSCREEN")));
  256. return FALSE;
  257. }
  258. #endif
  259. if(!LoadString(_hInstance,
  260. UI_IDS_SENDKEYS_ALWAYS,
  261. _szSendKeysAlways,
  262. sizeof(_szSendKeysAlways)/sizeof(TCHAR)))
  263. {
  264. TRC_ERR((TB, _T("Failed to load UI_IDS_FULLSCREEN")));
  265. return FALSE;
  266. }
  267. if(!LoadString(_hInstance,
  268. UI_IDS_SENDKEYS_NEVER,
  269. _szSendKeysNever,
  270. sizeof(_szSendKeysNever)/sizeof(TCHAR)))
  271. {
  272. TRC_ERR((TB, _T("Failed to load UI_IDS_FULLSCREEN")));
  273. return FALSE;
  274. }
  275. //
  276. // Load playsound strings
  277. //
  278. #ifdef OS_WINCE
  279. HINSTANCE hLibInst = NULL;
  280. if ((hLibInst = LoadLibrary(_T("WaveApi.dll"))) != NULL)
  281. {
  282. #endif
  283. if(!LoadString(_hInstance,
  284. UI_IDS_PLAYSOUND_LOCAL,
  285. _szPlaySoundLocal,
  286. sizeof(_szPlaySoundLocal)/sizeof(TCHAR)))
  287. {
  288. TRC_ERR((TB, _T("Failed to load UI_IDS_PLAYSOUND_LOCAL")));
  289. return FALSE;
  290. }
  291. #ifdef OS_WINCE
  292. FreeLibrary(hLibInst);
  293. }
  294. #endif
  295. if(!LoadString(_hInstance,
  296. UI_IDS_PLAYSOUND_REMOTE,
  297. _szPlaySoundRemote,
  298. sizeof(_szPlaySoundRemote)/sizeof(TCHAR)))
  299. {
  300. TRC_ERR((TB, _T("Failed to load UI_IDS_PLAYSOUND_REMOTE")));
  301. return FALSE;
  302. }
  303. if(!LoadString(_hInstance,
  304. UI_IDS_PLAYSOUND_NOSOUND,
  305. _szPlaySoundNowhere,
  306. sizeof(_szPlaySoundNowhere)/sizeof(TCHAR)))
  307. {
  308. TRC_ERR((TB, _T("Failed to load UI_IDS_PLAYSOUND_NOSOUND")));
  309. return FALSE;
  310. }
  311. DC_END_FN();
  312. return TRUE;
  313. }
  314. void CPropLocalRes::InitSendKeysToServerCombo(HWND hwndPropPage)
  315. {
  316. //
  317. // This call can be used to re-intialize a combo
  318. // so delete any items first
  319. //
  320. #ifndef OS_WINCE
  321. INT ret = 1;
  322. while(ret && ret != CB_ERR)
  323. {
  324. ret = SendDlgItemMessage(hwndPropPage,
  325. IDC_COMBO_SEND_KEYS,
  326. CBEM_DELETEITEM,
  327. 0,0);
  328. }
  329. #else
  330. SendDlgItemMessage(hwndPropPage, IDC_COMBO_SEND_KEYS, CB_RESETCONTENT, 0, 0);
  331. #endif
  332. //Order of the string has to match the keyboard
  333. //hook mode options.
  334. SendDlgItemMessage(hwndPropPage,
  335. IDC_COMBO_SEND_KEYS,
  336. CB_ADDSTRING,
  337. 0,
  338. (LPARAM)(PDCTCHAR)_szSendKeysNever);
  339. SendDlgItemMessage(hwndPropPage,
  340. IDC_COMBO_SEND_KEYS,
  341. CB_ADDSTRING,
  342. 0,
  343. (LPARAM)(PDCTCHAR)_szSendKeysAlways);
  344. #ifndef OS_WINCE
  345. SendDlgItemMessage(hwndPropPage,
  346. IDC_COMBO_SEND_KEYS,
  347. CB_ADDSTRING,
  348. 0,
  349. (LPARAM)(PDCTCHAR)_szSendKeysInFScreen);
  350. #endif
  351. if(!_fRunningOnWin9x)
  352. {
  353. SendDlgItemMessage(hwndPropPage, IDC_COMBO_SEND_KEYS,
  354. CB_SETCURSEL,
  355. (WPARAM)_pTscSet->GetKeyboardHookMode(),0);
  356. }
  357. else
  358. {
  359. //Feature disabled on 9x, force selection to first option
  360. //and disable UI so it can't be changed.
  361. SendDlgItemMessage(hwndPropPage, IDC_COMBO_SEND_KEYS,
  362. CB_SETCURSEL,
  363. (WPARAM)0,0);
  364. EnableWindow(GetDlgItem(hwndPropPage,IDC_COMBO_SEND_KEYS), FALSE);
  365. }
  366. }
  367. void CPropLocalRes::InitPlaySoundCombo(HWND hwndPropPage)
  368. {
  369. //
  370. // This call can be used to re-intialize a combo
  371. // so delete any items first
  372. //
  373. #ifndef OS_WINCE
  374. INT ret = 1;
  375. while(ret && ret != CB_ERR)
  376. {
  377. ret = SendDlgItemMessage(hwndPropPage,
  378. IDC_COMBO_SOUND_OPTIONS,
  379. CBEM_DELETEITEM,
  380. 0,0);
  381. }
  382. #else
  383. SendDlgItemMessage(hwndPropPage, IDC_COMBO_SOUND_OPTIONS, CB_RESETCONTENT, 0, 0);
  384. #endif
  385. //Order of the string has to match the sound
  386. //mode options.
  387. #ifdef OS_WINCE
  388. HINSTANCE hLibInst = NULL;
  389. if ((hLibInst = LoadLibrary(_T("WaveApi.dll"))) != NULL)
  390. {
  391. #endif
  392. SendDlgItemMessage(hwndPropPage,
  393. IDC_COMBO_SOUND_OPTIONS,
  394. CB_ADDSTRING,
  395. 0,
  396. (LPARAM)(PDCTCHAR)_szPlaySoundLocal);
  397. #ifdef OS_WINCE
  398. FreeLibrary(hLibInst);
  399. }
  400. #endif
  401. SendDlgItemMessage(hwndPropPage,
  402. IDC_COMBO_SOUND_OPTIONS,
  403. CB_ADDSTRING,
  404. 0,
  405. (LPARAM)(PDCTCHAR)_szPlaySoundNowhere);
  406. SendDlgItemMessage(hwndPropPage,
  407. IDC_COMBO_SOUND_OPTIONS,
  408. CB_ADDSTRING,
  409. 0,
  410. (LPARAM)(PDCTCHAR)_szPlaySoundRemote);
  411. int soundIdx = MapComboIdxSoundRedirMode(_pTscSet->GetSoundRedirectionMode());
  412. SendDlgItemMessage(hwndPropPage, IDC_COMBO_SOUND_OPTIONS,
  413. CB_SETCURSEL,(WPARAM)(WPARAM)
  414. soundIdx,0);
  415. }
  416. //
  417. // Maps from the sound combo index to the
  418. // appropriate sound mode value
  419. // what happened here is that the two bottom strings
  420. // in the combo were flipped (the function is bidirectional)
  421. //
  422. int CPropLocalRes::MapComboIdxSoundRedirMode(int idx)
  423. {
  424. int ret=0;
  425. switch (idx)
  426. {
  427. case 0:
  428. return 0;
  429. case 1:
  430. return 2;
  431. case 2:
  432. return 1;
  433. default:
  434. return 0;
  435. }
  436. }