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.

542 lines
13 KiB

  1. /*++
  2. Copyright (c) 2000-2001, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. callback.c
  5. Abstract:
  6. This file contains functions that wrap various enumeratation
  7. procedures and callback functions
  8. Functions found in this file:
  9. EnumCalendarInfoProc
  10. EnumCalendarInfoProcEx
  11. EnumDateFormatsProc
  12. EnumDateFormatsProcEx
  13. EnumFontFamExProc
  14. EnumFontFamProc
  15. EnumICMProfilesProcCallback
  16. EnumLocalesProc
  17. EnumTimeFormatsProc
  18. PropEnumProc
  19. PropEnumProcEx
  20. GrayStringProc
  21. Revision History:
  22. 7 Nov 2000 v-michka Created.
  23. --*/
  24. #include "precomp.h"
  25. /*-------------------------------
  26. EnumCalendarInfoProc
  27. -------------------------------*/
  28. BOOL CALLBACK EnumCalendarInfoProc(LPSTR lpCalendarInfoString)
  29. {
  30. BOOL RetVal = FALSE;
  31. LPGODOTTLSINFO lpgti;
  32. CALINFO_ENUMPROCW lpfn;
  33. size_t cb = lstrlenA(lpCalendarInfoString);
  34. LPWSTR lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  35. if(!lpsz)
  36. {
  37. SetLastError(ERROR_OUTOFMEMORY);
  38. return(FALSE);
  39. }
  40. lpgti = GetThreadInfoSafe(TRUE);
  41. // No TLS info means no way to know what proc to call
  42. if(lpgti)
  43. {
  44. lpfn = lpgti->pfnCalendarInfo;
  45. MultiByteToWideChar(g_acp, 0, lpCalendarInfoString, -1, lpsz, cb);
  46. // Chain to the original callback function
  47. RetVal = (* lpfn)(lpsz);
  48. }
  49. // Cleanup and get out
  50. GodotHeapFree(lpsz);
  51. return(RetVal);
  52. }
  53. /*-------------------------------
  54. EnumCalendarInfoProcEx
  55. -------------------------------*/
  56. BOOL CALLBACK EnumCalendarInfoProcEx (LPSTR lpCalendarInfoString, CALID Calendar)
  57. {
  58. BOOL RetVal = FALSE;
  59. LPGODOTTLSINFO lpgti;
  60. CALINFO_ENUMPROCEXW lpfn;
  61. size_t cb = lstrlenA(lpCalendarInfoString);
  62. LPWSTR lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  63. if(!lpsz)
  64. {
  65. SetLastError(ERROR_OUTOFMEMORY);
  66. return(FALSE);
  67. }
  68. lpgti = GetThreadInfoSafe(TRUE);
  69. // No TLS info means no way to know what proc to call
  70. if(lpgti)
  71. {
  72. lpfn = lpgti->pfnCalendarInfoEx;
  73. MultiByteToWideChar(g_acp, 0, lpCalendarInfoString, -1, lpsz, cb);
  74. // Chain to the original callback function
  75. RetVal = (* lpfn)(lpsz, Calendar);
  76. }
  77. // Cleanup and get out
  78. GodotHeapFree(lpsz);
  79. return(RetVal);
  80. }
  81. /*-------------------------------
  82. EnumDateFormatsProc
  83. -------------------------------*/
  84. BOOL CALLBACK EnumDateFormatsProc(LPSTR lpDateFormatString)
  85. {
  86. BOOL RetVal = FALSE;
  87. LPGODOTTLSINFO lpgti;
  88. DATEFMT_ENUMPROCW lpfn;
  89. size_t cb = lstrlenA(lpDateFormatString);
  90. LPWSTR lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  91. if(!lpsz)
  92. {
  93. SetLastError(ERROR_OUTOFMEMORY);
  94. return(FALSE);
  95. }
  96. lpgti = GetThreadInfoSafe(TRUE);
  97. // No TLS info means no way to know what proc to call
  98. if(lpgti)
  99. {
  100. lpfn = lpgti->pfnDateFormats;
  101. MultiByteToWideChar(g_acp, 0, lpDateFormatString, -1, lpsz, cb);
  102. // Chain to the original callback function
  103. RetVal = (* lpfn)(lpsz);
  104. }
  105. // Cleanup and get out
  106. GodotHeapFree(lpsz);
  107. return(RetVal);
  108. }
  109. /*-------------------------------
  110. EnumDateFormatsProcEx
  111. -------------------------------*/
  112. BOOL CALLBACK EnumDateFormatsProcEx(LPSTR lpDateFormatString, CALID CalendarID)
  113. {
  114. BOOL RetVal = FALSE;
  115. LPGODOTTLSINFO lpgti;
  116. DATEFMT_ENUMPROCEXW lpfn;
  117. size_t cb = lstrlenA(lpDateFormatString);
  118. LPWSTR lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  119. if(!lpsz)
  120. {
  121. SetLastError(ERROR_OUTOFMEMORY);
  122. return(FALSE);
  123. }
  124. lpgti = GetThreadInfoSafe(TRUE);
  125. // No TLS info means no way to know what proc to call
  126. if(lpgti)
  127. {
  128. lpfn = lpgti->pfnDateFormatsEx;
  129. MultiByteToWideChar(g_acp, 0, lpDateFormatString, -1, lpsz, cb);
  130. // Chain to the original callback function
  131. RetVal = (* lpfn)(lpsz, CalendarID);
  132. }
  133. // Cleanup and get out
  134. GodotHeapFree(lpsz);
  135. return(RetVal);
  136. }
  137. /*-------------------------------
  138. EnumLocalesProc
  139. -------------------------------*/
  140. BOOL CALLBACK EnumLocalesProc(LPSTR lpLocaleString)
  141. {
  142. BOOL RetVal = FALSE;
  143. LPGODOTTLSINFO lpgti;
  144. LOCALE_ENUMPROCW lpfn;
  145. size_t cb = lstrlenA(lpLocaleString);
  146. LPWSTR lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  147. if(!lpsz)
  148. {
  149. SetLastError(ERROR_OUTOFMEMORY);
  150. return(FALSE);
  151. }
  152. lpgti = GetThreadInfoSafe(TRUE);
  153. // No TLS info means no way to know what proc to call
  154. if(lpgti)
  155. {
  156. lpfn = lpgti->pfnLocales;
  157. MultiByteToWideChar(g_acp, 0, lpLocaleString, -1, lpsz, cb);
  158. RetVal = (* lpfn)(lpsz);
  159. }
  160. // Cleanup and get out
  161. GodotHeapFree(lpsz);
  162. return(RetVal);
  163. }
  164. /*-------------------------------
  165. EnumTimeFormatsProc
  166. -------------------------------*/
  167. BOOL CALLBACK EnumTimeFormatsProc(LPSTR lpTimeFormatString)
  168. {
  169. BOOL RetVal = FALSE;
  170. LPGODOTTLSINFO lpgti;
  171. TIMEFMT_ENUMPROCW lpfn;
  172. size_t cb = lstrlenA(lpTimeFormatString);
  173. LPWSTR lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  174. if(!lpsz)
  175. {
  176. SetLastError(ERROR_OUTOFMEMORY);
  177. return(FALSE);
  178. }
  179. lpgti = GetThreadInfoSafe(TRUE);
  180. // No TLS info means no way to know what proc to call
  181. if(lpgti)
  182. {
  183. lpfn = lpgti->pfnTimeFormats;
  184. MultiByteToWideChar(g_acp, 0, lpTimeFormatString, -1, lpsz, cb);
  185. // Chain to the original callback function
  186. RetVal = (* lpfn)(lpsz);
  187. }
  188. // Cleanup and get out
  189. GodotHeapFree(lpsz);
  190. return(RetVal);
  191. }
  192. /*-------------------------------
  193. PropEnumProcA
  194. -------------------------------*/
  195. BOOL CALLBACK PropEnumProcA(HWND hwnd, LPCSTR lpszString, HANDLE hData)
  196. {
  197. BOOL RetVal = FALSE;
  198. LPGODOTTLSINFO lpgti;
  199. PROPENUMPROCA lpfn;
  200. if(IsInternalWindowProperty((LPWSTR)lpszString, FALSE))
  201. return(TRUE);
  202. // No TLS info means no way to know what proc to call
  203. if(lpgti = GetThreadInfoSafe(TRUE))
  204. {
  205. lpfn = lpgti->pfnPropA;
  206. RetVal = (* lpfn)(hwnd, lpszString, hData);
  207. }
  208. return(RetVal);
  209. }
  210. /*-------------------------------
  211. PropEnumProc
  212. -------------------------------*/
  213. BOOL CALLBACK PropEnumProc(HWND hwnd, LPCSTR lpszString, HANDLE hData)
  214. {
  215. BOOL RetVal = FALSE;
  216. LPGODOTTLSINFO lpgti;
  217. PROPENUMPROCW lpfn;
  218. size_t cb;
  219. LPWSTR lpsz;
  220. if(IsInternalWindowProperty((LPWSTR)lpszString, FALSE))
  221. return(TRUE);
  222. cb = lstrlenA(lpszString);
  223. lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  224. if(!lpsz)
  225. {
  226. SetLastError(ERROR_OUTOFMEMORY);
  227. return(FALSE);
  228. }
  229. // No TLS info means no way to know what proc to call
  230. if(lpgti = GetThreadInfoSafe(TRUE))
  231. {
  232. lpfn = lpgti->pfnProp;
  233. MultiByteToWideChar(g_acp, 0, lpszString, -1, lpsz, cb);
  234. RetVal = (* lpfn)(hwnd, lpsz, hData);
  235. }
  236. // Cleanup and get out
  237. GodotHeapFree(lpsz);
  238. return(RetVal);
  239. }
  240. /*-------------------------------
  241. PropEnumProcEx
  242. -------------------------------*/
  243. BOOL CALLBACK PropEnumProcExA(HWND hwnd, LPSTR lpszString, HANDLE hData, ULONG_PTR dwData)
  244. {
  245. // begin locals
  246. BOOL RetVal = FALSE;
  247. LPGODOTTLSINFO lpgti;
  248. PROPENUMPROCEXA lpfn;
  249. if(IsInternalWindowProperty((LPWSTR)lpszString, FALSE))
  250. return(TRUE);
  251. // No TLS info means no way to know what proc to call
  252. if(lpgti = GetThreadInfoSafe(TRUE))
  253. {
  254. lpfn = lpgti->pfnPropExA;
  255. // Chain to the original callback function
  256. RetVal = (*lpfn)(hwnd, lpszString, hData, dwData);
  257. }
  258. return(RetVal);
  259. }
  260. /*-------------------------------
  261. PropEnumProcEx
  262. -------------------------------*/
  263. BOOL CALLBACK PropEnumProcEx(HWND hwnd, LPSTR lpszString, HANDLE hData, ULONG_PTR dwData)
  264. {
  265. // begin locals
  266. BOOL RetVal = FALSE;
  267. LPGODOTTLSINFO lpgti;
  268. PROPENUMPROCEXW lpfn;
  269. size_t cb;
  270. LPWSTR lpsz;
  271. if(IsInternalWindowProperty((LPWSTR)lpszString, FALSE))
  272. return(TRUE);
  273. cb = lstrlenA(lpszString);
  274. lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  275. if(!lpsz)
  276. {
  277. SetLastError(ERROR_OUTOFMEMORY);
  278. return(FALSE);
  279. }
  280. lpgti = GetThreadInfoSafe(TRUE);
  281. // No TLS info means no way to know what proc to call
  282. if(lpgti)
  283. {
  284. lpfn = lpgti->pfnPropEx;
  285. MultiByteToWideChar(g_acp, 0, lpszString, -1, lpsz, (cb * sizeof(WCHAR)));
  286. // Chain to the original callback function
  287. RetVal = (*lpfn)(hwnd, lpsz, hData, dwData);
  288. }
  289. // Cleanup and get out
  290. GodotHeapFree(lpsz);
  291. return(RetVal);
  292. }
  293. /*-------------------------------
  294. EnumFontFamExProc
  295. -------------------------------*/
  296. int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXA *lpelfe, NEWTEXTMETRICEXA *lpntme, DWORD FontType, LPARAM lParam)
  297. {
  298. // begin locals
  299. int RetVal = 0;
  300. LPGODOTTLSINFO lpgti;
  301. FONTENUMPROCW lpfnFEP;
  302. LOGFONTW lfW;
  303. lpgti = GetThreadInfoSafe(TRUE);
  304. // No TLS info means no way to know what proc to call
  305. if(lpgti)
  306. {
  307. lpfnFEP = lpgti->pfnFontFamiliesEx;
  308. LogFontWfromA(&lfW, (LOGFONTA *)lpelfe);
  309. if (FontType & TRUETYPE_FONTTYPE)
  310. {
  311. NEWTEXTMETRICEXW ntmeW;
  312. NewTextMetricExWfromA(&ntmeW, lpntme);
  313. // Chain to the original callback function
  314. RetVal = (*lpfnFEP)(&lfW, (LPTEXTMETRICW)&ntmeW, FontType, lParam);
  315. }
  316. else
  317. {
  318. TEXTMETRICW tmW;
  319. TextMetricWfromA(&tmW, (LPTEXTMETRICA)lpntme);
  320. // Chain to the original callback function
  321. RetVal = (*lpfnFEP)(&lfW, &tmW, FontType, lParam);
  322. }
  323. }
  324. // Cleanup and get out
  325. return(RetVal);
  326. }
  327. /*-------------------------------
  328. EnumFontFamProc
  329. -------------------------------*/
  330. int CALLBACK EnumFontFamProc(ENUMLOGFONTA *lpelf, LPNEWTEXTMETRICA lpntm, DWORD FontType, LPARAM lParam)
  331. {
  332. // begin locals
  333. int RetVal = 0;
  334. LPGODOTTLSINFO lpgti;
  335. FONTENUMPROCW lpfnFEP;
  336. LOGFONTW lfW;
  337. lpgti = GetThreadInfoSafe(TRUE);
  338. // No TLS info means no way to know what proc to call
  339. if(lpgti)
  340. {
  341. lpfnFEP = lpgti->pfnFontFamilies;
  342. LogFontWfromA(&lfW, (LOGFONTA *)lpelf);
  343. if (FontType & TRUETYPE_FONTTYPE)
  344. {
  345. NEWTEXTMETRICW ntmW;
  346. NewTextMetricWfromA(&ntmW, lpntm);
  347. // Chain to the original callback function
  348. RetVal = (*lpfnFEP)(&lfW, (LPTEXTMETRICW)&ntmW, FontType, lParam);
  349. }
  350. else
  351. {
  352. TEXTMETRICW tmW;
  353. TextMetricWfromA(&tmW, (LPTEXTMETRICA)lpntm);
  354. // Chain to the original callback function
  355. RetVal = (*lpfnFEP)(&lfW, &tmW, FontType, lParam);
  356. }
  357. }
  358. return(RetVal);
  359. }
  360. /*-------------------------------
  361. EnumFontsProc
  362. -------------------------------*/
  363. int CALLBACK EnumFontsProc(CONST LOGFONTA *lplf, CONST TEXTMETRICA *lptm, DWORD dwType, LPARAM lpData)
  364. {
  365. // begin locals
  366. int RetVal = 0;
  367. LPGODOTTLSINFO lpgti;
  368. FONTENUMPROCW lpfnFEP;
  369. TEXTMETRICW tmW;
  370. LOGFONTW lfW;
  371. lpgti = GetThreadInfoSafe(TRUE);
  372. // No TLS info means no way to know what proc to call
  373. if(lpgti)
  374. {
  375. lpfnFEP = lpgti->pfnFonts;
  376. LogFontWfromA(&lfW, (LOGFONTA *)lplf);
  377. TextMetricWfromA(&tmW, (TEXTMETRICA *)lptm);
  378. // Chain to the original callback function
  379. RetVal = (*lpfnFEP)(&lfW, &tmW, dwType, lpData);
  380. }
  381. return(RetVal);
  382. }
  383. /*-------------------------------
  384. EnumICMProfilesProcCallback
  385. -------------------------------*/
  386. int CALLBACK EnumICMProfilesProcCallback(LPSTR lpszFilename, LPARAM lParam)
  387. {
  388. // begin locals
  389. BOOL RetVal = FALSE;
  390. LPGODOTTLSINFO lpgti;
  391. ICMENUMPROCW lpfnIEP;
  392. size_t cb = lstrlenA(lpszFilename);
  393. LPWSTR lpsz = GodotHeapAlloc(cb * sizeof(WCHAR));
  394. if(!lpsz)
  395. {
  396. SetLastError(ERROR_OUTOFMEMORY);
  397. return (FALSE);
  398. }
  399. lpgti = GetThreadInfoSafe(TRUE);
  400. // No TLS info means no way to know what proc to call
  401. if(lpgti)
  402. {
  403. lpfnIEP = lpgti->pfnICMProfiles;
  404. MultiByteToWideChar(g_acp, 0, lpszFilename, -1, lpsz, (cb * sizeof(WCHAR)));
  405. // Chain to the original callback function
  406. RetVal = (*lpfnIEP)(lpsz, lParam);
  407. }
  408. // Cleanup and get out
  409. GodotHeapFree(lpsz);
  410. return(RetVal);
  411. }
  412. /*-------------------------------
  413. GrayStringProc
  414. -------------------------------*/
  415. BOOL CALLBACK GrayStringProc(HDC hdc, LPARAM lpData, int cchData)
  416. {
  417. LPGODOTTLSINFO lpgti;
  418. BOOL RetVal = FALSE;
  419. GRAYSTRINGPROC lpfn;
  420. LPWSTR lpsz = GodotHeapAlloc(cchData * sizeof(WCHAR));
  421. if(!lpsz)
  422. {
  423. SetLastError(ERROR_OUTOFMEMORY);
  424. return (FALSE);
  425. }
  426. // No TLS info means no way to know what proc to call
  427. if(lpgti = GetThreadInfoSafe(TRUE))
  428. {
  429. lpfn = lpgti->pfnGrayString;
  430. MultiByteToWideChar(lpgti->cpgGrayString, 0, (LPSTR)lpData, -1, lpsz, (cchData * sizeof(WCHAR)));
  431. // Chain to the original callback function
  432. RetVal = (*lpfn)(hdc, (LPARAM)lpsz, gwcslen(lpsz));
  433. }
  434. // Cleanup and get out
  435. GodotHeapFree(lpsz);
  436. return(RetVal);
  437. }