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.

399 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: imagetransferpage.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // ImageTransferPage.cpp : implementation file
  11. //
  12. #include "precomp.hxx"
  13. #include "imagetransferpage.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. //context ids for context help
  20. const DWORD g_ImageTransferHelp [] = {
  21. IDC_IMAGEXFER_ENABLE_IRCOMM, IDH_IMAGEXFER_ENABLE_IRCOMM,
  22. IDC_IMAGEXFER_DESTGROUP, IDH_DISABLEHELP,
  23. IDC_IMAGEXFER_DESTDESC, IDH_IMAGEXFER_DESTDESC,
  24. IDC_IMAGEXFER_DEST, IDH_IMAGEXFER_DEST,
  25. IDC_IMAGEXFER_BROWSE, IDH_IMAGEXFER_BROWSE,
  26. IDC_IMAGEXFER_EXPLOREONCOMPLETION, IDH_IMAGEXFER_EXPLOREONCOMPLETION,
  27. 0, 0
  28. };
  29. //
  30. // Registry entries that control IrTranP image transfer behavior.
  31. // Everything is under HKEY_CURRENT_USER\\Control Panel\\Infrared\IrTranP
  32. // subkey. Whenever there are changes, they are recorded in the registry
  33. // and the service(IrMon) would pick up the changes by RegNotifyChangeKeyValue
  34. // API.
  35. //
  36. //
  37. //
  38. TCHAR const REG_PATH_IRTRANP_CPL[] = TEXT("Control Panel\\Infrared\\IrTranP");
  39. //
  40. // Entry that controls if IrTranPV1 service should be disabled.
  41. // The type is REG_DWORD. Default is enabled(either the entry
  42. // does not exist or the value is zero).
  43. //
  44. TCHAR const REG_STR_DISABLE_IRTRANPV1[] = TEXT("DisableIrTranPv1");
  45. //
  46. // Entry that controls if IrCOMM should be disabled.
  47. // The type is REG_DWORD. Default is enabled(either the entry
  48. // does not exist or the value is zero).
  49. //
  50. TCHAR const REG_STR_DISABLE_IRCOMM[] = TEXT("DisableIrCOMM");
  51. // Entry that specifies the image file destionation subfolder.
  52. // The type is REG_SZ. The default is Shell special folder CSIDL_MYPICTURES
  53. // (if the entry does not exist).
  54. //
  55. TCHAR const REG_STR_DESTLOCATION[] = TEXT("RecvdFilesLocation");
  56. //
  57. // Entry that controls if IrMon should explore the picture subfolder
  58. // when image transfer(s) are done. The type is REG_DWORD.
  59. // Default is enabled(the entry does not exist of its value is
  60. // non-zero.
  61. //
  62. TCHAR const REG_STR_EXPLORE_ON_COMPLETION[] = TEXT("ExploreOnCompletion");
  63. /////////////////////////////////////////////////////////////////////////////
  64. // ImageTransferPage property page
  65. void ImageTransferPage::OnCommand(UINT ctrlId, HWND hwndCtrl, UINT cNotify)
  66. {
  67. switch (ctrlId) {
  68. case IDC_IMAGEXFER_EXPLOREONCOMPLETION:
  69. OnEnableExploring();
  70. break;
  71. case IDC_IMAGEXFER_BROWSE:
  72. OnBrowse();
  73. break;
  74. case IDC_IMAGEXFER_ENABLE_IRCOMM:
  75. OnEnableIrCOMM();
  76. break;
  77. }
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. // ImageTransferPage message handlers
  81. void ImageTransferPage::OnBrowse()
  82. {
  83. BROWSEINFO browseInfo;
  84. TCHAR pszSelectedFolder[MAX_PATH];
  85. TCHAR pszTitle[MAX_PATH];
  86. LPITEMIDLIST lpItemIDList;
  87. LPMALLOC pMalloc;
  88. // load the title string
  89. ::LoadString(hInstance, IDS_IMAGEFOLDER_PROMPT, pszTitle,
  90. sizeof(pszTitle) / sizeof(TCHAR));
  91. browseInfo.hwndOwner = hDlg;
  92. browseInfo.pidlRoot = NULL; //this will get the desktop folder
  93. browseInfo.pszDisplayName = pszSelectedFolder;
  94. browseInfo.lpszTitle = pszTitle;
  95. browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS |
  96. BIF_VALIDATE | BIF_EDITBOX;
  97. browseInfo.lpfn = BrowseCallback;
  98. // this will the the initial selection which is from
  99. // either the registry or the default or the last value
  100. // selected.
  101. browseInfo.lParam = (LPARAM)m_TempDestLocation;
  102. if (NULL != (lpItemIDList = SHBrowseForFolder (&browseInfo)))
  103. {
  104. HRESULT hr;
  105. //the user chose the OK button in the browse dialog box
  106. SHGetPathFromIDList(lpItemIDList, pszSelectedFolder);
  107. StringCbCopy(m_TempDestLocation,sizeof(m_TempDestLocation), pszSelectedFolder);
  108. m_ctrlDestLocation.SetWindowText(m_TempDestLocation);
  109. if (lstrcmpi(m_TempDestLocation, m_FinalDestLocation))
  110. m_ChangeMask |= CHANGE_IMAGE_LOCATION;
  111. else
  112. m_ChangeMask &= ~(CHANGE_IMAGE_LOCATION);
  113. SetModified(m_ChangeMask);
  114. hr=SHGetMalloc(&pMalloc);
  115. if (SUCCEEDED(hr)) {
  116. pMalloc->Free (lpItemIDList); //free the item id list as we do not need it any more
  117. pMalloc->Release();
  118. }
  119. }
  120. }
  121. void ImageTransferPage::OnEnableExploring()
  122. {
  123. int Enabled = m_ctrlEnableExploring.GetCheck();
  124. // Only accepted value is 0 or 1.
  125. assert(Enabled >= 0 && Enabled <= 1);
  126. // if new state is different than our old one
  127. // enable/disable Apply Now accordingly
  128. if (Enabled != m_ExploringEnabled)
  129. m_ChangeMask |= CHANGE_EXPLORE_ON_COMPLETION;
  130. else
  131. m_ChangeMask &= ~(CHANGE_EXPLORE_ON_COMPLETION);
  132. SetModified(m_ChangeMask);
  133. }
  134. void ImageTransferPage::OnEnableIrCOMM()
  135. {
  136. int Enabled = m_ctrlEnableIrCOMM.GetCheck();
  137. // Only accepted value is 0 or 1.
  138. assert(Enabled >= 0 && Enabled <= 1);
  139. // enable/disable Apply Now accordingly.
  140. if (Enabled != m_IrCOMMEnabled)
  141. m_ChangeMask |= CHANGE_DISABLE_IRCOMM;
  142. else
  143. m_ChangeMask &= ~(CHANGE_DISABLE_IRCOMM);
  144. SetModified(m_ChangeMask);
  145. }
  146. void ImageTransferPage::LoadRegistrySettings()
  147. {
  148. HKEY hKeyIrTranP;
  149. DWORD dwType, dwValue, dwSize;
  150. LONG Error;
  151. //
  152. // the ctor should have initialized
  153. // m_ExploringEnabled,
  154. // m_IrCOMMEnabled and
  155. // m_FinalDestLocation
  156. //
  157. // It is okay if we can not open the registry key.
  158. // We simply use the defaults.
  159. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REG_PATH_IRTRANP_CPL, 0,
  160. KEY_READ, &hKeyIrTranP))
  161. {
  162. // read the value "ExploreOnCompletion" and "RecvdFilesLocation"
  163. dwSize = sizeof(dwValue);
  164. Error = RegQueryValueEx(hKeyIrTranP,
  165. REG_STR_EXPLORE_ON_COMPLETION,
  166. 0,
  167. &dwType,
  168. (LPBYTE)&dwValue,
  169. &dwSize
  170. );
  171. if (ERROR_SUCCESS == Error && REG_DWORD == dwType)
  172. {
  173. m_ExploringEnabled = (dwValue) ? 1 : 0;
  174. }
  175. dwSize = sizeof(m_FinalDestLocation);
  176. Error = RegQueryValueEx(hKeyIrTranP,
  177. REG_STR_DESTLOCATION,
  178. 0,
  179. &dwType,
  180. (LPBYTE)m_FinalDestLocation,
  181. &dwSize);
  182. if (ERROR_SUCCESS != Error || REG_SZ != dwType) {
  183. // If the destionation location is not specified,
  184. // use the default(My Picture subfolder).
  185. // Create it if necessary.
  186. SHGetSpecialFolderPath(hDlg, m_FinalDestLocation, CSIDL_MYPICTURES, TRUE);
  187. } else {
  188. // make sure the folder does exist
  189. dwType = GetFileAttributes(m_FinalDestLocation);
  190. if (0xFFFFFFFF == dwType || !(dwType & FILE_ATTRIBUTE_DIRECTORY))
  191. {
  192. // the destination does not exist or it is not a
  193. // directory, delete it
  194. Error = RegDeleteValue(hKeyIrTranP, REG_STR_DESTLOCATION);
  195. if (ERROR_SUCCESS == Error) {
  196. // If the destionation location is not specified,
  197. // use the default(My Picture subfolder).
  198. // Create it if necessary.
  199. SHGetSpecialFolderPath(hDlg, m_FinalDestLocation, CSIDL_MYPICTURES, TRUE);
  200. }
  201. }
  202. }
  203. //
  204. // m_TempDestLocation will be used as the intial
  205. // folder of choice for SHBrowseForFolder call.
  206. //
  207. StringCbCopy(m_TempDestLocation,sizeof(m_TempDestLocation), m_FinalDestLocation);
  208. dwSize = sizeof(dwValue);
  209. Error = RegQueryValueEx(hKeyIrTranP,
  210. REG_STR_DISABLE_IRCOMM,
  211. 0,
  212. &dwType,
  213. (LPBYTE)&dwValue,
  214. &dwSize
  215. );
  216. if (ERROR_SUCCESS == Error && REG_DWORD == dwType)
  217. {
  218. // when the value is non-zero, IrCOMM is disabled.
  219. // Do not assume it is either 1 or 0!
  220. m_IrCOMMEnabled = (dwValue) ? 0 : 1;
  221. } else {
  222. // default
  223. m_IrCOMMEnabled = 0;
  224. }
  225. RegCloseKey(hKeyIrTranP);
  226. }
  227. }
  228. void ImageTransferPage::SaveRegistrySettings()
  229. {
  230. LONG Error;
  231. HKEY hKeyIrTranP;
  232. if (m_ChangeMask)
  233. {
  234. Error = RegCreateKeyEx(HKEY_CURRENT_USER,
  235. REG_PATH_IRTRANP_CPL,
  236. 0, // reserved
  237. NULL, // class
  238. REG_OPTION_NON_VOLATILE, // options
  239. KEY_ALL_ACCESS,// REGSAM
  240. NULL, // Security
  241. &hKeyIrTranP, //
  242. NULL // disposition
  243. );
  244. if (ERROR_SUCCESS == Error)
  245. {
  246. if (m_ChangeMask & CHANGE_EXPLORE_ON_COMPLETION)
  247. {
  248. Error = RegSetValueEx(hKeyIrTranP,
  249. REG_STR_EXPLORE_ON_COMPLETION,
  250. 0,
  251. REG_DWORD,
  252. (LPBYTE)&m_ExploringEnabled,
  253. sizeof(m_ExploringEnabled)
  254. );
  255. if (ERROR_SUCCESS != Error)
  256. {
  257. IdMessageBox(hDlg, IDS_ERROR_REGVALUE_WRITE);
  258. }
  259. }
  260. if (m_ChangeMask & CHANGE_IMAGE_LOCATION)
  261. {
  262. Error = RegSetValueEx(hKeyIrTranP,
  263. REG_STR_DESTLOCATION,
  264. 0,
  265. REG_SZ,
  266. (LPBYTE)m_FinalDestLocation,
  267. lstrlen(m_FinalDestLocation) * sizeof(TCHAR)
  268. );
  269. if (ERROR_SUCCESS != Error)
  270. IdMessageBox(hDlg, IDS_ERROR_REGVALUE_WRITE);
  271. }
  272. if (m_ChangeMask & CHANGE_DISABLE_IRCOMM)
  273. {
  274. int IrCOMMDisabled = m_IrCOMMEnabled ^ 1;
  275. Error = RegSetValueEx(hKeyIrTranP,
  276. REG_STR_DISABLE_IRCOMM,
  277. 0,
  278. REG_DWORD,
  279. (LPBYTE)&IrCOMMDisabled,
  280. sizeof(IrCOMMDisabled)
  281. );
  282. if (ERROR_SUCCESS != Error)
  283. IdMessageBox(hDlg, IDS_ERROR_REGVALUE_WRITE);
  284. }
  285. RegCloseKey(hKeyIrTranP);
  286. }
  287. else
  288. {
  289. IdMessageBox(hDlg, IDS_ERROR_REGKEY_CREATE);
  290. }
  291. }
  292. }
  293. INT_PTR ImageTransferPage::OnInitDialog(HWND hDialog)
  294. {
  295. PropertyPage::OnInitDialog(hDialog);
  296. m_ctrlEnableExploring.SetParent(hDialog);
  297. m_ctrlDestLocation.SetParent(hDialog);
  298. m_ctrlEnableIrCOMM.SetParent(hDialog);
  299. //
  300. // Load initial settings from the system registry
  301. //
  302. LoadRegistrySettings();
  303. m_ctrlEnableExploring.SetCheck(m_ExploringEnabled);
  304. m_ctrlEnableIrCOMM.SetCheck(m_IrCOMMEnabled);
  305. m_ctrlDestLocation.SetWindowText(m_FinalDestLocation);
  306. return TRUE; // return TRUE unless you set the focus to a control
  307. // EXCEPTION: OCX Property Pages should return FALSE
  308. }
  309. void ImageTransferPage::OnApply(LPPSHNOTIFY lppsn)
  310. {
  311. if (m_ChangeMask)
  312. {
  313. if (m_ChangeMask & CHANGE_IMAGE_LOCATION)
  314. StringCbCopy(m_FinalDestLocation,sizeof(m_FinalDestLocation), m_TempDestLocation);
  315. if (m_ChangeMask & CHANGE_EXPLORE_ON_COMPLETION)
  316. m_ExploringEnabled = m_ctrlEnableExploring.GetCheck();
  317. if (m_ChangeMask & CHANGE_DISABLE_IRCOMM)
  318. m_IrCOMMEnabled = m_ctrlEnableIrCOMM.GetCheck();
  319. SaveRegistrySettings();
  320. m_ChangeMask = 0;
  321. }
  322. PropertyPage::OnApply(lppsn);
  323. }
  324. BOOL ImageTransferPage::OnHelp (LPHELPINFO pHelpInfo)
  325. {
  326. TCHAR szHelpFile[MAX_PATH];
  327. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  328. ::WinHelp((HWND)(pHelpInfo->hItemHandle),
  329. (LPCTSTR) szHelpFile,
  330. HELP_WM_HELP,
  331. (ULONG_PTR)(LPTSTR)g_ImageTransferHelp);
  332. return FALSE;
  333. }
  334. BOOL ImageTransferPage::OnContextMenu (WPARAM wParam, LPARAM lParam)
  335. {
  336. TCHAR szHelpFile[MAX_PATH];
  337. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  338. ::WinHelp((HWND) wParam,
  339. (LPCTSTR) szHelpFile,
  340. HELP_CONTEXTMENU,
  341. (ULONG_PTR)(LPVOID)g_ImageTransferHelp);
  342. return FALSE;
  343. }