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.

462 lines
12 KiB

  1. #ifdef unix
  2. #include <tchar.h>
  3. #include "inetcplp.h"
  4. #include <shsemip.h>
  5. #include <mluisupp.h>
  6. #include <mainwin.h> // _MAX_FNAME
  7. #include <unistd.h>
  8. #define UNIX_EDITOR_ENV TEXT("EDITOR")
  9. #define UNIX_EDITOR_REG TEXT("command")
  10. //
  11. // Private Functions and Structures
  12. //
  13. BOOL ProgramsDlgInit( HWND hDlg);
  14. typedef struct {
  15. HWND hDlg; // dialog windows handle
  16. HWND hwndMail; // Mail dropdown
  17. HWND hwndNews; // News dropdown
  18. HWND hwndCalendar; // Calendar dropdown
  19. HWND hwndContact; // Contact dropdown
  20. HWND hwndCall; // Internet call dropdown
  21. BOOL bAssociationCheck; // Is IE the default browser?
  22. int iMail;
  23. int iNews;
  24. int iCalendar;
  25. int iContact;
  26. int iCall;
  27. BOOL fChanged;
  28. } PROGRAMSPAGE, *LPPROGRAMSPAGE;
  29. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  30. #ifdef WALLET
  31. typedef int (*PFN_DISPLAYWALLETPAYDIALOG_PROC)(HWND, HINSTANCE, LPTSTR, int);
  32. typedef int (*PFN_DISPLAYWALLETADDRDIALOG_PROC)(HWND, HINSTANCE, LPTSTR, int);
  33. #endif
  34. void FindEditClient(LPTSTR szProtocol, HWND hwndDlg, int nIDDlgItem, LPTSTR szPath)
  35. {
  36. TCHAR szCurrent[MAX_PATH];
  37. TCHAR szMsg[MAX_PATH];
  38. HKEY hkey;
  39. DWORD dw;
  40. HWND hwnd;
  41. // get the name of the new client
  42. if (hwnd = GetDlgItem(hwndDlg, nIDDlgItem))
  43. {
  44. Edit_GetText(hwnd, szCurrent, MAX_PATH);
  45. if (RegCreateKeyEx(HKEY_CURRENT_USER, szPath,
  46. 0, NULL, 0, KEY_READ|KEY_WRITE, NULL, &hkey, &dw) == ERROR_SUCCESS)
  47. {
  48. DWORD cb;
  49. cb = (lstrlen(szCurrent)+1)*sizeof(TCHAR);
  50. RegSetValueEx(hkey, REGSTR_PATH_CURRENT, NULL, REG_SZ, (LPBYTE)szCurrent, cb);
  51. // close the keys
  52. RegCloseKey(hkey);
  53. } // if RegCreateKeyEx()
  54. }
  55. } // FindEditClient()
  56. BOOL FoundProgram(HWND hwndDlg, int nIDDlgItem)
  57. {
  58. TCHAR szCurrent[MAX_PATH];
  59. CHAR szCurrentA[MAX_PATH];
  60. TCHAR szMsg[MAX_PATH];
  61. HWND hwnd;
  62. DWORD dwCurChar;
  63. BOOL bPath = FALSE;
  64. // get the name of the new client
  65. if (hwnd = GetDlgItem(hwndDlg, nIDDlgItem))
  66. {
  67. if (!IsWindowEnabled(hwnd))
  68. return TRUE;
  69. Edit_GetText(hwnd, szCurrent, MAX_PATH);
  70. for (dwCurChar = 0; dwCurChar < lstrlen(szCurrent); dwCurChar++)
  71. {
  72. if (szCurrent[dwCurChar] == TEXT('/'))
  73. {
  74. bPath = TRUE;
  75. break;
  76. }
  77. }
  78. if (!bPath) // if it's file name with no path we assume it's in the user's PATH
  79. return TRUE;
  80. #ifdef UNICODE
  81. WideCharToMultiByte(CP_ACP, 0, szCurrent, -1, szCurrentA, MAX_PATH, NULL, NULL);
  82. if (access(szCurrentA, X_OK) == 0)
  83. #else
  84. if (access(szCurrent, X_OK) == 0)
  85. #endif
  86. return TRUE;
  87. }
  88. return FALSE;
  89. } // FoundProgram()
  90. HRESULT ViewScript(TCHAR *lpszPath)
  91. {
  92. HRESULT hr = S_OK;
  93. TCHAR tszPath[MAX_PATH];
  94. TCHAR tszCommand[INTERNET_MAX_URL_LENGTH];
  95. TCHAR tszExpandedCommand[INTERNET_MAX_URL_LENGTH];
  96. UINT nCommandSize;
  97. int i;
  98. HKEY hkey;
  99. DWORD dw;
  100. TCHAR *pchPos;
  101. BOOL bMailed;
  102. STARTUPINFO stInfo;
  103. _tcscpy(tszPath, lpszPath);
  104. hr = RegCreateKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_VSOURCECLIENTS, 0, NULL, 0, KEY_READ, NULL, &hkey, &dw);
  105. if (hr != ERROR_SUCCESS)
  106. goto Cleanup;
  107. dw = INTERNET_MAX_URL_LENGTH;
  108. hr = RegQueryValueEx(hkey, REGSTR_PATH_CURRENT, NULL, NULL, (LPBYTE)tszCommand, &dw);
  109. if (hr != ERROR_SUCCESS)
  110. {
  111. RegCloseKey(hkey);
  112. goto Cleanup;
  113. }
  114. dw = ExpandEnvironmentStrings(tszCommand, tszExpandedCommand, INTERNET_MAX_URL_LENGTH);
  115. if (!dw)
  116. {
  117. _tcscpy(tszExpandedCommand, tszCommand);
  118. }
  119. _tcscat(tszCommand, tszExpandedCommand);
  120. for (i = _tcslen(tszCommand); i > 0; i--)
  121. if (tszCommand[i] == TEXT('/'))
  122. {
  123. tszCommand[i] = TEXT('\0');
  124. break;
  125. }
  126. _tcscat(tszCommand, TEXT(" "));
  127. _tcscat(tszCommand, tszPath);
  128. memset(&stInfo, 0, sizeof(stInfo));
  129. stInfo.cb = sizeof(stInfo);
  130. stInfo.wShowWindow= SW_SHOWNORMAL;
  131. bMailed = CreateProcess(tszExpandedCommand, tszCommand, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &stInfo, NULL);
  132. Cleanup:
  133. return hr;
  134. }
  135. BOOL EditScript(HKEY hkeyProtocol)
  136. {
  137. HKEY hKey;
  138. TCHAR tszCurrent[MAX_PATH];
  139. TCHAR tszScript[MAX_PATH];
  140. DWORD dw;
  141. dw = MAX_PATH;
  142. if (RegQueryValueEx(hkeyProtocol, REGSTR_PATH_CURRENT, NULL, NULL, (LPBYTE)tszCurrent, &dw)
  143. != ERROR_SUCCESS)
  144. {
  145. return FALSE;
  146. }
  147. ExpandEnvironmentStrings(tszCurrent, tszScript, INTERNET_MAX_URL_LENGTH);
  148. return ViewScript(tszScript);
  149. }
  150. BOOL FindScript(HWND hwndLabel, HKEY hkeyProtocol)
  151. {
  152. TCHAR tszCurrent[2*MAX_PATH + 1 ];
  153. TCHAR tszScript[2*MAX_PATH + 1];
  154. TCHAR tszFilter[5];
  155. DWORD dw;
  156. OPENFILENAME ofn;
  157. dw = MAX_PATH;
  158. if (RegQueryValueEx(hkeyProtocol, REGSTR_PATH_CURRENT, NULL, NULL, (LPBYTE)tszCurrent, &dw)
  159. != ERROR_SUCCESS)
  160. {
  161. return FALSE;
  162. }
  163. tszCurrent[MAX_PATH] = TEXT('\0');
  164. ExpandEnvironmentStrings(tszCurrent, tszScript, INTERNET_MAX_URL_LENGTH);
  165. _tcscpy(tszCurrent, tszScript);
  166. BOOL bDirFound = FALSE;
  167. int i;
  168. for (i = _tcslen(tszCurrent) - 1; i>=0; i--)
  169. if (tszCurrent[i] == TEXT('/') )
  170. {
  171. tszCurrent[i] = TEXT('\0');
  172. bDirFound = TRUE;
  173. break;
  174. }
  175. if( !bDirFound )
  176. tszCurrent[0] = TEXT('\0');
  177. else
  178. _tcscpy( tszScript, tszCurrent+i+1 );
  179. tszScript[ _MAX_FNAME - 1 ] = TEXT('\0');
  180. memset((void*)&tszFilter, 0, 5 * sizeof(TCHAR));
  181. tszFilter[0] = TEXT('*');
  182. tszFilter[2] = TEXT('*');
  183. memset((void*)&ofn, 0, sizeof(ofn));
  184. ofn.lpstrFilter = tszFilter;
  185. ofn.lStructSize = sizeof(ofn);
  186. ofn.hwndOwner = hwndLabel;
  187. ofn.lpstrFile = tszScript;
  188. ofn.nMaxFile = MAX_PATH;
  189. ofn.lpstrInitialDir = tszCurrent;
  190. ofn.Flags = OFN_HIDEREADONLY;
  191. if (GetOpenFileName(&ofn))
  192. {
  193. SendMessage(hwndLabel, EM_SETSEL, 0, -1);
  194. SendMessage(hwndLabel, EM_REPLACESEL, 0, (LPARAM)tszScript);
  195. }
  196. return TRUE;
  197. }
  198. #endif
  199. // Function used to determine if the given file exists in the directory
  200. // that the current process is running from
  201. BOOL LocalFileCheck(LPCTSTR aszFileName)
  202. {
  203. // Determinate the base path of the current process binary
  204. TCHAR szPath[MAX_PATH];
  205. GetModuleFileName(NULL, szPath, sizeof(szPath)/sizeof(szPath[0]));
  206. // Find the final element separator if there is one
  207. #ifdef UNICODE
  208. LPTSTR szPathName = _tcsrchr(szPath, FILENAME_SEPARATOR_W);
  209. #else
  210. LPTSTR szPathName = _tcsrchr(szPath, FILENAME_SEPARATOR);
  211. #endif
  212. DWORD dwPathLength;
  213. if (szPathName)
  214. {
  215. szPathName[1] = TEXT('\0');
  216. dwPathLength = szPathName-szPath+1;
  217. }
  218. else
  219. {
  220. dwPathLength = _tcslen(szPath)+1;
  221. #ifdef UNICODE
  222. _tcsncat(szPath, FILENAME_SEPARATOR_STR_W, sizeof(szPath)/
  223. #else
  224. _tcsncat(szPath, FILENAME_SEPARATOR_STR, sizeof(szPath)/
  225. #endif
  226. sizeof(szPath[0])-dwPathLength);
  227. }
  228. // Append the target file name to the base path (make sure
  229. // the new string can't overflow the buffer)
  230. _tcsncat(szPath, aszFileName, sizeof(szPath)/sizeof(szPath[0])-
  231. dwPathLength-1);
  232. // Look for the given file without trying to open it
  233. WIN32_FIND_DATA findData;
  234. HANDLE hFind = FindFirstFile(szPath, &findData);
  235. if (hFind == INVALID_HANDLE_VALUE)
  236. {
  237. return TRUE;
  238. }
  239. else
  240. {
  241. FindClose(hFind);
  242. return(FALSE);
  243. }
  244. }
  245. UINT RegPopulateEditText(HWND hwndCB, HKEY hkeyProtocol)
  246. {
  247. TCHAR szCurrent [MAX_PATH];
  248. TCHAR szExpanded [MAX_PATH];
  249. FILETIME ftLastWriteTime;
  250. DWORD cb;
  251. cb = sizeof(szCurrent);
  252. if (RegQueryValueEx(hkeyProtocol, REGSTR_PATH_CURRENT, NULL, NULL, (LPBYTE)szCurrent, &cb)
  253. != ERROR_SUCCESS)
  254. {
  255. szCurrent[0]=TEXT('\0');
  256. }
  257. ExpandEnvironmentStrings(szCurrent, szExpanded, MAX_PATH);
  258. SendMessage(hwndCB, EM_REPLACESEL, (WPARAM) 0, (LPARAM) szExpanded);
  259. return 0;
  260. } // RegPopulateEditText()
  261. static const CHAR szCacheLockStatus[] = "unixGetWininetCacheLockStatus";
  262. static const TCHAR szCacheLockStatusDll[] = TEXT("WININET.DLL");
  263. typedef void (WINAPI *LPCACHELOCKSTATUS)(BOOL *pBoolReadOnly, TCHAR **ppszLockingHost);
  264. BOOL IsCacheReadOnly()
  265. {
  266. HINSTANCE hCacheLockStatusDll = NULL;
  267. LPCACHELOCKSTATUS fnCacheLockStatus;
  268. BOOL bReadOnlyCacheLockStatus;
  269. hCacheLockStatusDll = LoadLibrary(szCacheLockStatusDll);
  270. if (hCacheLockStatusDll)
  271. {
  272. fnCacheLockStatus = (LPCACHELOCKSTATUS)GetProcAddress(hCacheLockStatusDll, szCacheLockStatus);
  273. FreeLibrary(hCacheLockStatusDll);
  274. }
  275. if (fnCacheLockStatus)
  276. fnCacheLockStatus(&bReadOnlyCacheLockStatus, NULL);
  277. return bReadOnlyCacheLockStatus;
  278. }
  279. BOOL CALLBACK FontUpdDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  280. {
  281. HWND hProg = GetDlgItem(hDlg, IDC_FONTUPD_PROG);
  282. UINT nTimer = 1;
  283. switch (uMsg)
  284. {
  285. case WM_INITDIALOG:
  286. HCURSOR hOldCursor = NULL;
  287. HCURSOR hNewCursor = NULL;
  288. hNewCursor = LoadCursor(NULL, IDC_WAIT);
  289. if (hNewCursor)
  290. hOldCursor = SetCursor(hNewCursor);
  291. SendMessage(hProg, PBM_SETRANGE, 0, MAKELPARAM(0, FONT_UPDATE_TICK));
  292. SendMessage(hProg, PBM_SETSTEP, 1, 0);
  293. SetTimer(hDlg, nTimer, 600, NULL);
  294. break;
  295. case WM_TIMER:
  296. KillTimer(hDlg, nTimer);
  297. MwFontCacheUpdate(TRUE, FontUpdateFeedBack, FONT_UPDATE_TICK, (void*)hDlg);
  298. break;
  299. case WM_CLOSE:
  300. EndDialog(hDlg, 0);
  301. case PBM_SETRANGE:
  302. SendMessage(hProg, PBM_SETRANGE, wParam, lParam);
  303. break;
  304. case PBM_SETSTEP:
  305. SendMessage(hProg, PBM_SETSTEP, wParam, lParam);
  306. break;
  307. case PBM_STEPIT:
  308. SendMessage(hProg, PBM_STEPIT, wParam, lParam);
  309. break;
  310. default:
  311. return FALSE;
  312. }
  313. return TRUE;
  314. }
  315. void FontUpdateFeedBack(int nTick, void *pvParam)
  316. {
  317. HWND hDlg = (HWND)pvParam;
  318. MSG msg;
  319. int iMsg = 0;
  320. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) && iMsg++ < 20)
  321. {
  322. TranslateMessage(&msg);
  323. DispatchMessage(&msg);
  324. }
  325. if (hDlg)
  326. SendMessage(hDlg, PBM_STEPIT, 0, 0);
  327. if (nTick == FONT_UPDATE_TICK - 1)
  328. SendMessage(hDlg, WM_CLOSE, 0, 0);
  329. }
  330. VOID DrawXFontButton(HWND hDlg, LPDRAWITEMSTRUCT lpdis)
  331. {
  332. SIZE thin = { GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER) };
  333. RECT rc = lpdis->rcItem;
  334. HDC hdc = lpdis->hDC;
  335. BOOL bFocus = ((lpdis->itemState & ODS_FOCUS) && !(lpdis->itemState & ODS_DISABLED));
  336. if (!thin.cx) thin.cx = 1;
  337. if (!thin.cy) thin.cy = 1;
  338. FillRect(hdc, &rc, GetSysColorBrush(COLOR_3DFACE));
  339. //Draw Icon
  340. HICON hXFIcon;
  341. if (hXFIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_FONT)))
  342. {
  343. DrawIcon(hdc, (rc.right + rc.left) / 2 - 8, (rc.top + rc.bottom / 2) / 2 - 8, hXFIcon);
  344. }
  345. // Draw any caption
  346. TCHAR szCaption[80];
  347. int cyText = (rc.bottom + rc.top)/2;
  348. if (GetWindowText(lpdis->hwndItem, szCaption, ARRAYSIZE(szCaption)))
  349. {
  350. COLORREF crText;
  351. RECT rcText = rc;
  352. rcText.top = cyText;
  353. int nOldMode = SetBkMode(hdc, TRANSPARENT);
  354. if (lpdis->itemState & ODS_DISABLED)
  355. {
  356. // Draw disabled text using the embossed look
  357. crText = SetTextColor(hdc, GetSysColor(COLOR_BTNHIGHLIGHT));
  358. RECT rcOffset = rcText;
  359. OffsetRect(&rcOffset, 1, 1);
  360. DrawText(hdc, szCaption, -1, &rcOffset, DT_VCENTER|DT_SINGLELINE);
  361. SetTextColor(hdc, GetSysColor(COLOR_BTNSHADOW));
  362. }
  363. else
  364. {
  365. crText = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
  366. }
  367. DrawText(hdc, szCaption, -1, &rcText, DT_VCENTER|DT_CENTER|DT_SINGLELINE);
  368. SetTextColor(hdc, crText);
  369. SetBkMode(hdc, nOldMode);
  370. }
  371. // Draw the button portion
  372. if (lpdis->itemState & ODS_SELECTED)
  373. {
  374. DrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
  375. OffsetRect(&rc, 1, 1);
  376. }
  377. else
  378. {
  379. DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_ADJUST);
  380. }
  381. if (bFocus)
  382. {
  383. InflateRect(&rc, -thin.cx, -thin.cy);
  384. DrawFocusRect(hdc, &rc);
  385. InflateRect(&rc, thin.cx, thin.cy);
  386. }
  387. }