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.

390 lines
12 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. //the user chose the OK button in the browse dialog box
  105. SHGetPathFromIDList(lpItemIDList, pszSelectedFolder);
  106. lstrcpy(m_TempDestLocation, pszSelectedFolder);
  107. m_ctrlDestLocation.SetWindowText(m_TempDestLocation);
  108. if (lstrcmpi(m_TempDestLocation, m_FinalDestLocation))
  109. m_ChangeMask |= CHANGE_IMAGE_LOCATION;
  110. else
  111. m_ChangeMask &= ~(CHANGE_IMAGE_LOCATION);
  112. SetModified(m_ChangeMask);
  113. SHGetMalloc(&pMalloc);
  114. pMalloc->Free (lpItemIDList); //free the item id list as we do not need it any more
  115. pMalloc->Release();
  116. }
  117. }
  118. void ImageTransferPage::OnEnableExploring()
  119. {
  120. int Enabled = m_ctrlEnableExploring.GetCheck();
  121. // Only accepted value is 0 or 1.
  122. assert(Enabled >= 0 && Enabled <= 1);
  123. // if new state is different than our old one
  124. // enable/disable Apply Now accordingly
  125. if (Enabled != m_ExploringEnabled)
  126. m_ChangeMask |= CHANGE_EXPLORE_ON_COMPLETION;
  127. else
  128. m_ChangeMask &= ~(CHANGE_EXPLORE_ON_COMPLETION);
  129. SetModified(m_ChangeMask);
  130. }
  131. void ImageTransferPage::OnEnableIrCOMM()
  132. {
  133. int Enabled = m_ctrlEnableIrCOMM.GetCheck();
  134. // Only accepted value is 0 or 1.
  135. assert(Enabled >= 0 && Enabled <= 1);
  136. // enable/disable Apply Now accordingly.
  137. if (Enabled != m_IrCOMMEnabled)
  138. m_ChangeMask |= CHANGE_DISABLE_IRCOMM;
  139. else
  140. m_ChangeMask &= ~(CHANGE_DISABLE_IRCOMM);
  141. SetModified(m_ChangeMask);
  142. }
  143. void ImageTransferPage::LoadRegistrySettings()
  144. {
  145. HKEY hKeyIrTranP;
  146. DWORD dwType, dwValue, dwSize;
  147. LONG Error;
  148. //
  149. // the ctor should have initialized
  150. // m_ExploringEnabled,
  151. // m_IrCOMMEnabled and
  152. // m_FinalDestLocation
  153. //
  154. // It is okay if we can not open the registry key.
  155. // We simply use the defaults.
  156. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REG_PATH_IRTRANP_CPL, 0,
  157. KEY_READ, &hKeyIrTranP))
  158. {
  159. // read the value "ExploreOnCompletion" and "RecvdFilesLocation"
  160. dwSize = sizeof(m_ExploringEnabled);
  161. Error = RegQueryValueEx(hKeyIrTranP,
  162. REG_STR_EXPLORE_ON_COMPLETION,
  163. 0,
  164. &dwType,
  165. (LPBYTE)&dwValue,
  166. &dwSize
  167. );
  168. if (ERROR_SUCCESS == Error && REG_DWORD == dwType)
  169. {
  170. m_ExploringEnabled = (dwValue) ? 1 : 0;
  171. }
  172. dwSize = sizeof(m_FinalDestLocation);
  173. Error = RegQueryValueEx(hKeyIrTranP,
  174. REG_STR_DESTLOCATION,
  175. 0,
  176. &dwType,
  177. (LPBYTE)m_FinalDestLocation,
  178. &dwSize);
  179. if (ERROR_SUCCESS != Error || REG_SZ != dwType) {
  180. // If the destionation location is not specified,
  181. // use the default(My Picture subfolder).
  182. // Create it if necessary.
  183. SHGetSpecialFolderPath(hDlg, m_FinalDestLocation, CSIDL_MYPICTURES, TRUE);
  184. } else {
  185. // make sure the folder does exist
  186. dwType = GetFileAttributes(m_FinalDestLocation);
  187. if (0xFFFFFFFF == dwType || !(dwType & FILE_ATTRIBUTE_DIRECTORY))
  188. {
  189. // the destination does not exist or it is not a
  190. // directory, delete it
  191. Error = RegDeleteValue(hKeyIrTranP, REG_STR_DESTLOCATION);
  192. if (ERROR_SUCCESS == Error) {
  193. // If the destionation location is not specified,
  194. // use the default(My Picture subfolder).
  195. // Create it if necessary.
  196. SHGetSpecialFolderPath(hDlg, m_FinalDestLocation, CSIDL_MYPICTURES, TRUE);
  197. }
  198. }
  199. }
  200. //
  201. // m_TempDestLocation will be used as the intial
  202. // folder of choice for SHBrowseForFolder call.
  203. //
  204. lstrcpy(m_TempDestLocation, m_FinalDestLocation);
  205. dwSize = sizeof(dwValue);
  206. Error = RegQueryValueEx(hKeyIrTranP,
  207. REG_STR_DISABLE_IRCOMM,
  208. 0,
  209. &dwType,
  210. (LPBYTE)&dwValue,
  211. &dwSize
  212. );
  213. if (ERROR_SUCCESS == Error && REG_DWORD == dwType)
  214. {
  215. // when the value is non-zero, IrCOMM is disabled.
  216. // Do not assume it is either 1 or 0!
  217. m_IrCOMMEnabled = (dwValue) ? 0 : 1;
  218. } else {
  219. // default
  220. m_IrCOMMEnabled = 0;
  221. }
  222. RegCloseKey(hKeyIrTranP);
  223. }
  224. }
  225. void ImageTransferPage::SaveRegistrySettings()
  226. {
  227. LONG Error;
  228. HKEY hKeyIrTranP;
  229. if (m_ChangeMask)
  230. {
  231. Error = RegCreateKeyEx(HKEY_CURRENT_USER,
  232. REG_PATH_IRTRANP_CPL,
  233. 0, // reserved
  234. NULL, // class
  235. REG_OPTION_NON_VOLATILE, // options
  236. KEY_ALL_ACCESS,// REGSAM
  237. NULL, // Security
  238. &hKeyIrTranP, //
  239. NULL // disposition
  240. );
  241. if (ERROR_SUCCESS == Error)
  242. {
  243. if (m_ChangeMask & CHANGE_EXPLORE_ON_COMPLETION)
  244. {
  245. Error = RegSetValueEx(hKeyIrTranP,
  246. REG_STR_EXPLORE_ON_COMPLETION,
  247. 0,
  248. REG_DWORD,
  249. (LPBYTE)&m_ExploringEnabled,
  250. sizeof(m_ExploringEnabled)
  251. );
  252. if (ERROR_SUCCESS != Error)
  253. {
  254. IdMessageBox(hDlg, IDS_ERROR_REGVALUE_WRITE);
  255. }
  256. }
  257. if (m_ChangeMask & CHANGE_IMAGE_LOCATION)
  258. {
  259. Error = RegSetValueEx(hKeyIrTranP,
  260. REG_STR_DESTLOCATION,
  261. 0,
  262. REG_SZ,
  263. (LPBYTE)m_FinalDestLocation,
  264. lstrlen(m_FinalDestLocation) * sizeof(TCHAR)
  265. );
  266. if (ERROR_SUCCESS != Error)
  267. IdMessageBox(hDlg, IDS_ERROR_REGVALUE_WRITE);
  268. }
  269. if (m_ChangeMask & CHANGE_DISABLE_IRCOMM)
  270. {
  271. int IrCOMMDisabled = m_IrCOMMEnabled ^ 1;
  272. Error = RegSetValueEx(hKeyIrTranP,
  273. REG_STR_DISABLE_IRCOMM,
  274. 0,
  275. REG_DWORD,
  276. (LPBYTE)&IrCOMMDisabled,
  277. sizeof(IrCOMMDisabled)
  278. );
  279. if (ERROR_SUCCESS != Error)
  280. IdMessageBox(hDlg, IDS_ERROR_REGVALUE_WRITE);
  281. }
  282. RegCloseKey(hKeyIrTranP);
  283. }
  284. else
  285. {
  286. IdMessageBox(hDlg, IDS_ERROR_REGKEY_CREATE);
  287. }
  288. }
  289. }
  290. INT_PTR ImageTransferPage::OnInitDialog(HWND hDialog)
  291. {
  292. PropertyPage::OnInitDialog(hDialog);
  293. m_ctrlEnableExploring.SetParent(hDialog);
  294. m_ctrlDestLocation.SetParent(hDialog);
  295. m_ctrlEnableIrCOMM.SetParent(hDialog);
  296. //
  297. // Load initial settings from the system registry
  298. //
  299. LoadRegistrySettings();
  300. m_ctrlEnableExploring.SetCheck(m_ExploringEnabled);
  301. m_ctrlEnableIrCOMM.SetCheck(m_IrCOMMEnabled);
  302. m_ctrlDestLocation.SetWindowText(m_FinalDestLocation);
  303. return TRUE; // return TRUE unless you set the focus to a control
  304. // EXCEPTION: OCX Property Pages should return FALSE
  305. }
  306. void ImageTransferPage::OnApply(LPPSHNOTIFY lppsn)
  307. {
  308. if (m_ChangeMask)
  309. {
  310. if (m_ChangeMask & CHANGE_IMAGE_LOCATION)
  311. lstrcpy(m_FinalDestLocation, m_TempDestLocation);
  312. if (m_ChangeMask & CHANGE_EXPLORE_ON_COMPLETION)
  313. m_ExploringEnabled = m_ctrlEnableExploring.GetCheck();
  314. if (m_ChangeMask & CHANGE_DISABLE_IRCOMM)
  315. m_IrCOMMEnabled = m_ctrlEnableIrCOMM.GetCheck();
  316. SaveRegistrySettings();
  317. m_ChangeMask = 0;
  318. }
  319. PropertyPage::OnApply(lppsn);
  320. }
  321. BOOL ImageTransferPage::OnHelp (LPHELPINFO pHelpInfo)
  322. {
  323. TCHAR szHelpFile[MAX_PATH];
  324. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  325. ::WinHelp((HWND)(pHelpInfo->hItemHandle),
  326. (LPCTSTR) szHelpFile,
  327. HELP_WM_HELP,
  328. (ULONG_PTR)(LPTSTR)g_ImageTransferHelp);
  329. return FALSE;
  330. }
  331. BOOL ImageTransferPage::OnContextMenu (WPARAM wParam, LPARAM lParam)
  332. {
  333. TCHAR szHelpFile[MAX_PATH];
  334. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  335. ::WinHelp((HWND) wParam,
  336. (LPCTSTR) szHelpFile,
  337. HELP_CONTEXTMENU,
  338. (ULONG_PTR)(LPVOID)g_ImageTransferHelp);
  339. return FALSE;
  340. }