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.

353 lines
11 KiB

  1. #include "shellprv.h"
  2. #include "ids.h"
  3. #include "ftadv.h"
  4. #include "ftcmmn.h"
  5. #include "ftaction.h"
  6. #include "ftassoc.h"
  7. const static DWORD cs_rgdwHelpIDsArray[] =
  8. { // Context Help IDs
  9. IDC_FT_CMD_ACTION, IDH_FCAB_FT_CMD_ACTION,
  10. IDC_FT_CMD_EXETEXT, IDH_FCAB_FT_CMD_EXE,
  11. IDC_FT_CMD_EXE, IDH_FCAB_FT_CMD_EXE,
  12. IDC_FT_CMD_BROWSE, IDH_FCAB_FT_CMD_BROWSE,
  13. IDC_FT_CMD_DDEGROUP, IDH_FCAB_FT_CMD_USEDDE,
  14. IDC_FT_CMD_USEDDE, IDH_FCAB_FT_CMD_USEDDE,
  15. IDC_FT_CMD_DDEMSG, IDH_FCAB_FT_CMD_DDEMSG,
  16. IDC_FT_CMD_DDEAPP, IDH_FCAB_FT_CMD_DDEAPP,
  17. IDC_FT_CMD_DDEAPPNOT, IDH_FCAB_FT_CMD_DDEAPPNOT,
  18. IDC_FT_CMD_DDETOPIC, IDH_FCAB_FT_CMD_DDETOPIC,
  19. 0, 0
  20. };
  21. CFTActionDlg::CFTActionDlg(PROGIDACTION* pProgIDAction, LPTSTR pszProgIDDescr,
  22. BOOL fEdit) :
  23. CFTDlg((ULONG_PTR)cs_rgdwHelpIDsArray),
  24. _pProgIDAction(pProgIDAction), _pszProgIDDescr(pszProgIDDescr),
  25. _fEdit(fEdit)
  26. {
  27. }
  28. CFTActionDlg::~CFTActionDlg()
  29. {
  30. }
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // Logic specific to our problem
  33. LRESULT CFTActionDlg::OnInitDialog(WPARAM wParam, LPARAM lParam)
  34. {
  35. DECLAREWAITCURSOR;
  36. SetWaitCursor();
  37. if (_fEdit || _fShowAgain)
  38. {
  39. TCHAR szTitle[50 + MAX_PROGIDDESCR + 5];
  40. TCHAR szTitleTemplate[50];
  41. _fShowAgain = FALSE;
  42. if (LoadString(g_hinst, IDS_FT_EDITTITLE, szTitleTemplate, ARRAYSIZE(szTitleTemplate)))
  43. {
  44. wnsprintf(szTitle, ARRAYSIZE(szTitle), szTitleTemplate, _pszProgIDDescr);
  45. SetWindowText(_hwnd, szTitle);
  46. }
  47. SetDlgItemText(_hwnd, IDC_FT_CMD_ACTION, _pProgIDAction->szAction);
  48. SetDlgItemText(_hwnd, IDC_FT_CMD_EXE, _pProgIDAction->szCmdLine);
  49. SetDlgItemText(_hwnd, IDC_FT_CMD_DDEMSG, _pProgIDAction->szDDEMsg);
  50. SetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPP, _pProgIDAction->szDDEApplication);
  51. SetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPPNOT, _pProgIDAction->szDDEAppNotRunning);
  52. SetDlgItemText(_hwnd, IDC_FT_CMD_DDETOPIC, _pProgIDAction->szDDETopic);
  53. CheckDlgButton(_hwnd, IDC_FT_CMD_USEDDE, _pProgIDAction->fUseDDE);
  54. _ResizeDlgForDDE(_pProgIDAction->fUseDDE);
  55. }
  56. else
  57. {
  58. CheckDlgButton(_hwnd, IDC_FT_CMD_USEDDE, FALSE);
  59. _ResizeDlgForDDE(FALSE);
  60. }
  61. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_ACTION), MAX_ACTION - 1);
  62. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_EXE), MAX_ACTIONCMDLINE - 1);
  63. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDEMSG), MAX_ACTIONDDEMSG - 1);
  64. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPP), MAX_ACTIONAPPL - 1);
  65. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPPNOT), MAX_ACTIONDDEAPPNOTRUN - 1);
  66. Edit_LimitText(GetDlgItem(_hwnd, IDC_FT_CMD_DDETOPIC), MAX_ACTIONTOPIC - 1);
  67. ResetWaitCursor();
  68. // Return TRUE so that system set focus
  69. return TRUE;
  70. }
  71. BOOL CFTActionDlg::_Validate()
  72. {
  73. BOOL bRet = TRUE;
  74. // Check the Action
  75. TCHAR szAction[MAX_ACTION];
  76. if (!GetDlgItemText(_hwnd, IDC_FT_CMD_ACTION, szAction, ARRAYSIZE(szAction)) ||
  77. !*szAction)
  78. {
  79. ShellMessageBox(g_hinst, _hwnd, MAKEINTRESOURCE(IDS_FT_MB_NOACTION),
  80. MAKEINTRESOURCE(IDS_FT), MB_OK | MB_ICONSTOP);
  81. PostMessage(_hwnd, WM_CTRL_SETFOCUS, (WPARAM)0,
  82. (LPARAM)GetDlgItem(_hwnd, IDC_FT_CMD_ACTION));
  83. bRet = FALSE;
  84. }
  85. if (bRet)
  86. {
  87. TCHAR szPath[MAX_PATH];
  88. LPTSTR pszFileName = NULL;
  89. // Check for valid exe
  90. GetDlgItemText(_hwnd, IDC_FT_CMD_EXE, szPath, ARRAYSIZE(szPath));
  91. PathRemoveArgs(szPath);
  92. PathUnquoteSpaces(szPath);
  93. pszFileName = PathFindFileName(szPath);
  94. if(!(*szPath) ||
  95. !(PathIsExe(szPath)) ||
  96. ((!(PathFileExists(szPath))) && (!(PathFindOnPath(pszFileName, NULL)))))
  97. {
  98. // Tell user that this exe is invalid
  99. ShellMessageBox(g_hinst, _hwnd, MAKEINTRESOURCE(IDS_FT_MB_EXETEXT),
  100. MAKEINTRESOURCE(IDS_FT), MB_OK | MB_ICONSTOP);
  101. PostMessage(_hwnd, WM_CTRL_SETFOCUS, (WPARAM)0,
  102. (LPARAM)GetDlgItem(_hwnd, IDC_FT_CMD_EXE));
  103. bRet = FALSE;
  104. }
  105. }
  106. return bRet;
  107. }
  108. void CFTActionDlg::SetShowAgain()
  109. {
  110. _fShowAgain = TRUE;
  111. }
  112. BOOL _IsThereAnyPercentArgument(LPTSTR pszCommand)
  113. {
  114. BOOL fRet = FALSE;
  115. LPTSTR pszArgs = PathGetArgs(pszCommand);
  116. if (pszArgs && *pszArgs)
  117. {
  118. if (StrStr(pszArgs, TEXT("%")))
  119. {
  120. fRet = TRUE;
  121. }
  122. }
  123. return fRet;
  124. }
  125. LRESULT CFTActionDlg::OnOK(WORD wNotif)
  126. {
  127. if (_Validate())
  128. {
  129. GetDlgItemText(_hwnd, IDC_FT_CMD_ACTION, _pProgIDAction->szAction, MAX_ACTION);
  130. // Is this a new action?
  131. if (!_fEdit)
  132. {
  133. // Yes, initialize the old action field
  134. StrCpyN(_pProgIDAction->szOldAction, _pProgIDAction->szAction,
  135. ARRAYSIZE(_pProgIDAction->szOldAction));
  136. // Build the ActionReg
  137. lstrcpy(_pProgIDAction->szActionReg, _pProgIDAction->szAction);
  138. // Replace spaces with underscores
  139. LPTSTR psz = _pProgIDAction->szActionReg;
  140. while (*psz)
  141. {
  142. if (TEXT(' ') == *psz)
  143. {
  144. *psz = TEXT('_');
  145. }
  146. psz = CharNext(psz);
  147. }
  148. lstrcpy(_pProgIDAction->szOldActionReg, _pProgIDAction->szActionReg);
  149. }
  150. GetDlgItemText(_hwnd, IDC_FT_CMD_EXE, _pProgIDAction->szCmdLine, MAX_ACTIONCMDLINE);
  151. GetDlgItemText(_hwnd, IDC_FT_CMD_DDEMSG, _pProgIDAction->szDDEMsg, MAX_ACTIONDDEMSG);
  152. GetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPP, _pProgIDAction->szDDEApplication, MAX_ACTIONAPPL);
  153. GetDlgItemText(_hwnd, IDC_FT_CMD_DDEAPPNOT, _pProgIDAction->szDDEAppNotRunning, MAX_ACTIONDDEAPPNOTRUN);
  154. GetDlgItemText(_hwnd, IDC_FT_CMD_DDETOPIC, _pProgIDAction->szDDETopic, MAX_ACTIONTOPIC);
  155. _pProgIDAction->fUseDDE = IsDlgButtonChecked(_hwnd, IDC_FT_CMD_USEDDE);
  156. // Append %1 to action field, if required
  157. if (!_IsThereAnyPercentArgument(_pProgIDAction->szCmdLine))
  158. {
  159. TCHAR* pszPercentToAppend;
  160. if (StrChr(_pProgIDAction->szCmdLine,TEXT('\\')))
  161. {
  162. if (App_IsLFNAware(_pProgIDAction->szCmdLine))
  163. pszPercentToAppend = TEXT(" \"%1\"");
  164. else
  165. pszPercentToAppend = TEXT(" %1");
  166. }
  167. else
  168. {
  169. TCHAR szFullPathFileName[MAX_PATH];
  170. //
  171. StrCpyN(szFullPathFileName, _pProgIDAction->szCmdLine,
  172. ARRAYSIZE(szFullPathFileName));
  173. //PathFindOnPath: first param is the filename, if it is on the path
  174. // then it returns fully qualified, if not return false.
  175. //Second param is optional directory to look in first
  176. if (PathFindOnPath(szFullPathFileName, NULL))
  177. {
  178. if (App_IsLFNAware(szFullPathFileName))
  179. pszPercentToAppend = TEXT(" \"%1\"");
  180. else
  181. pszPercentToAppend = TEXT(" %1");
  182. }
  183. else
  184. {//just in case, default to good old behavior. Should not come here because
  185. // ActionExeIsValid was done earlier
  186. pszPercentToAppend = TEXT(" %1");
  187. }
  188. }
  189. //append...
  190. StrCatN(_pProgIDAction->szCmdLine, pszPercentToAppend,
  191. ARRAYSIZE(_pProgIDAction->szCmdLine));
  192. }
  193. EndDialog(_hwnd, IDOK);
  194. }
  195. return FALSE;
  196. }
  197. LRESULT CFTActionDlg::OnCancel(WORD wNotif)
  198. {
  199. EndDialog(_hwnd, IDCANCEL);
  200. return FALSE;
  201. }
  202. LRESULT CFTActionDlg::OnUseDDE(WORD wNotif)
  203. {
  204. _ResizeDlgForDDE(IsDlgButtonChecked(_hwnd, IDC_FT_CMD_USEDDE));
  205. return FALSE;
  206. }
  207. LRESULT CFTActionDlg::OnBrowse(WORD wNotif)
  208. {
  209. TCHAR szPath[MAX_PATH];
  210. TCHAR szTitle[40];
  211. TCHAR szEXE[MAX_PATH];
  212. TCHAR szFilters[MAX_PATH];
  213. LPTSTR psz;
  214. szPath[0] = 0;
  215. EVAL(LoadString(g_hinst, IDS_CAP_OPENAS, szTitle, ARRAYSIZE(szTitle)));
  216. EVAL(LoadString(g_hinst, IDS_FT_EXE, szEXE, ARRAYSIZE(szEXE)));
  217. // And we need to convert #'s to \0's...
  218. EVAL(LoadString(g_hinst, IDS_PROGRAMSFILTER, szFilters, ARRAYSIZE(szFilters)));
  219. psz = szFilters;
  220. while (*psz)
  221. {
  222. if (*psz == TEXT('#'))
  223. {
  224. LPTSTR pszT = psz;
  225. psz = CharNext(psz);
  226. *pszT = TEXT('\0');
  227. }
  228. else
  229. psz = CharNext(psz);
  230. }
  231. if (GetFileNameFromBrowse(_hwnd, szPath, ARRAYSIZE(szPath), NULL, szEXE, szFilters, szTitle))
  232. {
  233. PathQuoteSpaces(szPath);
  234. SetDlgItemText(_hwnd, IDC_FT_CMD_EXE, szPath);
  235. }
  236. return FALSE;
  237. }
  238. void CFTActionDlg::_ResizeDlgForDDE(BOOL fShow)
  239. {
  240. RECT rcDialog;
  241. RECT rcControl;
  242. GetWindowRect(_hwnd, &rcDialog);
  243. if(fShow)
  244. GetWindowRect(GetDlgItem(_hwnd, IDC_FT_CMD_DDEGROUP), &rcControl);
  245. else
  246. GetWindowRect(GetDlgItem(_hwnd, IDC_FT_CMD_USEDDE), &rcControl);
  247. // Hide/Show the windows to take care of the Tabbing. If we don't hide them then
  248. // we tab through the "visible" window outside of the dialog.
  249. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEMSG), fShow);
  250. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPP), fShow);
  251. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEAPPNOT), fShow);
  252. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDETOPIC), fShow);
  253. ShowWindow(GetDlgItem(_hwnd, IDC_FT_CMD_DDEGROUP), fShow);
  254. SetWindowPos(GetDlgItem(_hwnd, IDC_FT_CMD_USEDDE), HWND_TOPMOST,
  255. 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
  256. MoveWindow(_hwnd, rcDialog.left, rcDialog.top, rcDialog.right - rcDialog.left,
  257. (rcControl.bottom - rcDialog.top) + 10, TRUE);
  258. SetFocus(GetDlgItem(_hwnd, IDC_FT_CMD_USEDDE));
  259. }
  260. LRESULT CFTActionDlg::OnDestroy(WPARAM wParam, LPARAM lParam)
  261. {
  262. CFTDlg::OnDestroy(wParam, lParam);
  263. return FALSE;
  264. }
  265. ///////////////////////////////////////////////////////////////////////////////
  266. // Windows boiler plate code
  267. LRESULT CFTActionDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  268. {
  269. LRESULT lRes = FALSE;
  270. switch(GET_WM_COMMAND_ID(wParam, lParam))
  271. {
  272. case IDC_FT_CMD_USEDDE:
  273. // Resize Dialog to see/hide DDE controls
  274. lRes = OnUseDDE(GET_WM_COMMAND_CMD(wParam, lParam));
  275. break;
  276. case IDC_FT_CMD_BROWSE:
  277. lRes = OnBrowse(GET_WM_COMMAND_CMD(wParam, lParam));
  278. break;
  279. default:
  280. lRes = CFTDlg::OnCommand(wParam, lParam);
  281. break;
  282. }
  283. return lRes;
  284. }