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.

1479 lines
50 KiB

  1. #include "ctlspriv.h"
  2. #ifdef NEED_WOWGETNOTIFYSIZE_HELPER
  3. #include <shsemip.h> // SEN_* notifications
  4. #include <commdlg.h> // CDN_* notifications
  5. // Miscellaneous hackery needed in order to include shlobjp.h
  6. #define CCONTROLINFO OAIDL_CONTROLINFO
  7. #define LPCCONTROLINFO LPOAIDL_CONTROLINFO
  8. #include <shlobj.h>
  9. #include <shlobjp.h> // NMVIEWFOLDER structure
  10. #undef CCONTROLINFO
  11. #undef LPCCONTROLINFO
  12. //
  13. // Helper function for WOW on NT.
  14. //
  15. // WOW needs to know the size of the notify structure associated with a
  16. // notification. If a 32-bit window has been subclassed by a 16-bit app,
  17. // WOW needs to copy the notify structure into 16-bit space, and then when
  18. // the 16-bit guy does a CallWindowProc(), they have to copy it back into
  19. // 32-bit space. Without the size information, you fault on the
  20. // 32-bit side because the notify structure is incomplete.
  21. //
  22. // Some notifications have multiple structures associated with them, in
  23. // which case you should return the largest possible valid structure.
  24. //
  25. STDAPI_(UINT) WOWGetNotifySize(UINT code)
  26. {
  27. switch (code) {
  28. // Generic comctl32 notifications
  29. case NM_OUTOFMEMORY: return sizeof(NMHDR); // not used
  30. case NM_CLICK: return max(max(
  31. sizeof(NMHDR), // tab, treeview
  32. sizeof(NMCLICK)), // toolbar, statusbar
  33. sizeof(NMITEMACTIVATE)); // listview
  34. case NM_DBLCLK: return max(max(
  35. sizeof(NMHDR), // tab, treeview
  36. sizeof(NMCLICK)), // toolbar, statusbar
  37. sizeof(NMITEMACTIVATE)); // listview
  38. case NM_RETURN: return sizeof(NMHDR);
  39. case NM_RCLICK: return max(max(
  40. sizeof(NMHDR), // header, listview report mode, treeview
  41. sizeof(NMCLICK)), // toolbar, statusbar
  42. sizeof(NMITEMACTIVATE)); // listview icon mode
  43. case NM_RDBLCLK: return max(max(
  44. sizeof(NMHDR), // treeview
  45. sizeof(NMCLICK)), // toolbar, statusbar
  46. sizeof(NMITEMACTIVATE)); // listview
  47. case NM_SETFOCUS: return sizeof(NMHDR);
  48. case NM_KILLFOCUS: return sizeof(NMHDR);
  49. case NM_STARTWAIT: return sizeof(NMHDR); // not used
  50. case NM_ENDWAIT: return sizeof(NMHDR); // not used
  51. case NM_BTNCLK: return sizeof(NMHDR); // not used
  52. case NM_CUSTOMDRAW: return sizeof(NMCUSTOMDRAW);
  53. case NM_HOVER: return sizeof(NMHDR);
  54. case NM_NCHITTEST: return sizeof(NMMOUSE);
  55. case NM_KEYDOWN: return sizeof(NMKEY);
  56. case NM_RELEASEDCAPTURE: return sizeof(NMHDR);
  57. case NM_SETCURSOR: return sizeof(NMMOUSE);
  58. case NM_CHAR: return sizeof(NMCHAR);
  59. case NM_TOOLTIPSCREATED: return sizeof(NMTOOLTIPSCREATED);
  60. case NM_LDOWN: return sizeof(NMCLICK);
  61. case NM_RDOWN: return sizeof(NMCLICK); // not used
  62. // Listview notifications
  63. case LVN_ITEMCHANGING: return sizeof(NMLISTVIEW);
  64. case LVN_ITEMCHANGED: return sizeof(NMLISTVIEW);
  65. case LVN_INSERTITEM: return sizeof(NMLISTVIEW);
  66. case LVN_DELETEITEM: return sizeof(NMLISTVIEW);
  67. case LVN_DELETEALLITEMS: return sizeof(NMLISTVIEW);
  68. case LVN_BEGINLABELEDITA: return sizeof(NMLVDISPINFOA);
  69. case LVN_BEGINLABELEDITW: return sizeof(NMLVDISPINFOW);
  70. case LVN_ENDLABELEDITA: return sizeof(NMLVDISPINFOA);
  71. case LVN_ENDLABELEDITW: return sizeof(NMLVDISPINFOW);
  72. case LVN_COLUMNCLICK: return sizeof(NMLISTVIEW);
  73. case LVN_BEGINDRAG: return sizeof(NMITEMACTIVATE);
  74. case LVN_BEGINRDRAG: return sizeof(NMITEMACTIVATE); // not used
  75. case LVN_ENDDRAG: return sizeof(NMITEMACTIVATE); // not used
  76. case LVN_ENDRDRAG: return sizeof(NMITEMACTIVATE); // not used
  77. case LVN_ODCACHEHINT: return sizeof(NMLVCACHEHINT);
  78. case LVN_ODFINDITEMA: return sizeof(NMLVFINDITEMA);
  79. case LVN_ODFINDITEMW: return sizeof(NMLVFINDITEMW);
  80. case LVN_ITEMACTIVATE: return sizeof(NMITEMACTIVATE);
  81. case LVN_ODSTATECHANGED: return sizeof(NMLVODSTATECHANGE);
  82. // case LVN_PEN: // Pen Windows slackers
  83. case LVN_HOTTRACK: return sizeof(NMLISTVIEW);
  84. case LVN_GETDISPINFOA: return sizeof(NMLVDISPINFOA);
  85. case LVN_GETDISPINFOW: return sizeof(NMLVDISPINFOW);
  86. case LVN_SETDISPINFOA: return sizeof(NMLVDISPINFOA);
  87. case LVN_SETDISPINFOW: return sizeof(NMLVDISPINFOW);
  88. case LVN_KEYDOWN: return sizeof(NMLVKEYDOWN);
  89. case LVN_MARQUEEBEGIN: return sizeof(NMITEMACTIVATE);
  90. case LVN_GETINFOTIPA: return sizeof(NMLVGETINFOTIPA);
  91. case LVN_GETINFOTIPW: return sizeof(NMLVGETINFOTIPW);
  92. case LVN_GETEMPTYTEXTA: return sizeof(NMLVDISPINFOA);
  93. case LVN_GETEMPTYTEXTW: return sizeof(NMLVDISPINFOW);
  94. case LVN_INCREMENTALSEARCHA:return sizeof(NMLVFINDITEMA);
  95. case LVN_INCREMENTALSEARCHW:return sizeof(NMLVFINDITEMW);
  96. // Property sheet notifications
  97. case PSN_SETACTIVE: return sizeof(PSHNOTIFY);
  98. case PSN_KILLACTIVE: return sizeof(PSHNOTIFY);
  99. case PSN_APPLY: return sizeof(PSHNOTIFY);
  100. case PSN_RESET: return sizeof(PSHNOTIFY);
  101. case PSN_HASHELP: return sizeof(PSHNOTIFY); // not used
  102. case PSN_HELP: return sizeof(PSHNOTIFY);
  103. case PSN_WIZBACK: return sizeof(PSHNOTIFY);
  104. case PSN_WIZNEXT: return sizeof(PSHNOTIFY);
  105. case PSN_WIZFINISH: return sizeof(PSHNOTIFY);
  106. case PSN_QUERYCANCEL: return sizeof(PSHNOTIFY);
  107. case PSN_GETOBJECT: return sizeof(NMOBJECTNOTIFY);
  108. case PSN_LASTCHANCEAPPLY: return sizeof(PSHNOTIFY);
  109. case PSN_TRANSLATEACCELERATOR:
  110. return sizeof(PSHNOTIFY);
  111. case PSN_QUERYINITIALFOCUS: return sizeof(PSHNOTIFY);
  112. // Header notifications
  113. case HDN_ITEMCHANGINGA: return sizeof(NMHEADERA);
  114. case HDN_ITEMCHANGINGW: return sizeof(NMHEADERW);
  115. case HDN_ITEMCHANGEDA: return sizeof(NMHEADERA);
  116. case HDN_ITEMCHANGEDW: return sizeof(NMHEADERW);
  117. case HDN_ITEMCLICKA: return sizeof(NMHEADERA);
  118. case HDN_ITEMCLICKW: return sizeof(NMHEADERW);
  119. case HDN_ITEMDBLCLICKA: return sizeof(NMHEADERA);
  120. case HDN_ITEMDBLCLICKW: return sizeof(NMHEADERW);
  121. case HDN_DIVIDERDBLCLICKA: return sizeof(NMHEADERA);
  122. case HDN_DIVIDERDBLCLICKW: return sizeof(NMHEADERW);
  123. case HDN_BEGINTRACKA: return sizeof(NMHEADERA);
  124. case HDN_BEGINTRACKW: return sizeof(NMHEADERW);
  125. case HDN_ENDTRACKA: return sizeof(NMHEADERA);
  126. case HDN_ENDTRACKW: return sizeof(NMHEADERW);
  127. case HDN_TRACKA: return sizeof(NMHEADERA);
  128. case HDN_TRACKW: return sizeof(NMHEADERW);
  129. case HDN_GETDISPINFOA: return sizeof(NMHDDISPINFOA);
  130. case HDN_GETDISPINFOW: return sizeof(NMHDDISPINFOW);
  131. case HDN_BEGINDRAG: return sizeof(NMHEADER); // No strings
  132. case HDN_ENDDRAG: return sizeof(NMHEADER); // No strings
  133. case HDN_FILTERCHANGE: return sizeof(NMHEADER); // No strings
  134. case HDN_FILTERBTNCLICK: return sizeof(NMHDFILTERBTNCLICK);
  135. // Treeview notifications
  136. case TVN_SELCHANGINGA: return sizeof(NMTREEVIEWA);
  137. case TVN_SELCHANGINGW: return sizeof(NMTREEVIEWW);
  138. case TVN_SELCHANGEDA: return sizeof(NMTREEVIEWA);
  139. case TVN_SELCHANGEDW: return sizeof(NMTREEVIEWW);
  140. case TVN_GETDISPINFOA: return sizeof(NMTVDISPINFOA);
  141. case TVN_GETDISPINFOW: return sizeof(NMTVDISPINFOW);
  142. case TVN_SETDISPINFOA: return sizeof(NMTVDISPINFOA);
  143. case TVN_SETDISPINFOW: return sizeof(NMTVDISPINFOW);
  144. case TVN_ITEMEXPANDINGA: return sizeof(NMTREEVIEWA);
  145. case TVN_ITEMEXPANDINGW: return sizeof(NMTREEVIEWW);
  146. case TVN_ITEMEXPANDEDA: return sizeof(NMTREEVIEWA);
  147. case TVN_ITEMEXPANDEDW: return sizeof(NMTREEVIEWW);
  148. case TVN_BEGINDRAGA: return sizeof(NMTREEVIEWA);
  149. case TVN_BEGINDRAGW: return sizeof(NMTREEVIEWW);
  150. case TVN_BEGINRDRAGA: return sizeof(NMTREEVIEWA);
  151. case TVN_BEGINRDRAGW: return sizeof(NMTREEVIEWW);
  152. case TVN_DELETEITEMA: return sizeof(NMTREEVIEWA);
  153. case TVN_DELETEITEMW: return sizeof(NMTREEVIEWW);
  154. case TVN_BEGINLABELEDITA: return sizeof(NMTVDISPINFOA);
  155. case TVN_BEGINLABELEDITW: return sizeof(NMTVDISPINFOW);
  156. case TVN_ENDLABELEDITA: return sizeof(NMTVDISPINFOA);
  157. case TVN_ENDLABELEDITW: return sizeof(NMTVDISPINFOW);
  158. case TVN_KEYDOWN: return sizeof(NMTVKEYDOWN);
  159. case TVN_GETINFOTIPA: return sizeof(NMTVGETINFOTIPA);
  160. case TVN_GETINFOTIPW: return sizeof(NMTVGETINFOTIPW);
  161. case TVN_SINGLEEXPAND: return sizeof(NMTREEVIEW); // No strings
  162. // Rundll32 notifications
  163. case RDN_TASKINFO: return sizeof(RUNDLL_NOTIFY);
  164. // Tooltip notifications
  165. case TTN_GETDISPINFOA: return sizeof(NMTTDISPINFOA);
  166. case TTN_GETDISPINFOW: return sizeof(NMTTDISPINFOW);
  167. case TTN_SHOW: return sizeof(NMTTSHOWINFO);
  168. case TTN_POP: return sizeof(NMHDR);
  169. // Tab control notifications
  170. // WE ARE SUCH HORRIBLE SLACKERS!
  171. //
  172. // Even though commctrl.h says that the shell reserved range is from
  173. // -580 to -589, shsemip.h defines SEN_FIRST as -550, which conflicts
  174. // with TCN_KEYDOWN, so now TCN_KEYDOWN and SEN_DDEEXECUTE have the
  175. // same value.
  176. case TCN_KEYDOWN: return max(sizeof(NMTCKEYDOWN),
  177. sizeof(NMVIEWFOLDERW));
  178. case TCN_SELCHANGE: return sizeof(NMHDR);
  179. case TCN_SELCHANGING: return sizeof(NMHDR);
  180. case TCN_GETOBJECT: return sizeof(NMOBJECTNOTIFY);
  181. case TCN_FOCUSCHANGE: return sizeof(NMHDR);
  182. // Comdlg32 notifications
  183. case CDN_INITDONE: return max(sizeof(OFNOTIFYA),
  184. sizeof(OFNOTIFYW));
  185. case CDN_SELCHANGE: return max(sizeof(OFNOTIFYA),
  186. sizeof(OFNOTIFYW));
  187. case CDN_FOLDERCHANGE: return max(sizeof(OFNOTIFYA),
  188. sizeof(OFNOTIFYW));
  189. case CDN_SHAREVIOLATION: return max(sizeof(OFNOTIFYA),
  190. sizeof(OFNOTIFYW));
  191. case CDN_HELP: return max(sizeof(OFNOTIFYA),
  192. sizeof(OFNOTIFYW));
  193. case CDN_FILEOK: return max(sizeof(OFNOTIFYA),
  194. sizeof(OFNOTIFYW));
  195. case CDN_TYPECHANGE: return max(sizeof(OFNOTIFYA),
  196. sizeof(OFNOTIFYW));
  197. case CDN_INCLUDEITEM: return max(sizeof(OFNOTIFYEXA),
  198. sizeof(OFNOTIFYEXW));
  199. // Toolbar notifications
  200. case TBN_GETBUTTONINFOA: return sizeof(NMTOOLBARA);
  201. case TBN_GETBUTTONINFOW: return sizeof(NMTOOLBARW);
  202. case TBN_BEGINDRAG: return sizeof(NMTOOLBAR); // No strings
  203. case TBN_ENDDRAG: return sizeof(NMTOOLBAR); // No strings
  204. case TBN_BEGINADJUST: return sizeof(NMHDR);
  205. case TBN_ENDADJUST: return sizeof(NMHDR);
  206. case TBN_RESET: return sizeof(NMTBCUSTOMIZEDLG);
  207. case TBN_QUERYINSERT: return sizeof(NMTOOLBAR); // No strings
  208. case TBN_QUERYDELETE: return sizeof(NMTOOLBAR); // No strings
  209. case TBN_TOOLBARCHANGE: return sizeof(NMHDR);
  210. case TBN_CUSTHELP: return sizeof(NMHDR);
  211. case TBN_DROPDOWN: return sizeof(NMTOOLBAR); // No strings
  212. case TBN_CLOSEUP: return sizeof(NMHDR); // not used
  213. case TBN_GETOBJECT: return sizeof(NMOBJECTNOTIFY);
  214. case TBN_HOTITEMCHANGE: return sizeof(NMTBHOTITEM);
  215. case TBN_DRAGOUT: return sizeof(NMTOOLBAR); // No strings
  216. case TBN_DELETINGBUTTON: return sizeof(NMTOOLBAR); // No strings
  217. case TBN_GETDISPINFOA: return sizeof(NMTBDISPINFOA);
  218. case TBN_GETDISPINFOW: return sizeof(NMTBDISPINFOW);
  219. case TBN_GETINFOTIPA: return sizeof(NMTBGETINFOTIPA);
  220. case TBN_GETINFOTIPW: return sizeof(NMTBGETINFOTIPW);
  221. case TBN_RESTORE: return sizeof(NMTBRESTORE);
  222. // WE ARE SUCH HORRIBLE SLACKERS!
  223. //
  224. // The TBN_FIRST/TBN_LAST range reserves 20 notifications for toolbar,
  225. // and we overflowed that limit, so now UDN_DELTAPOS and
  226. // TBN_SAVE have the same value.
  227. case TBN_SAVE: return max(sizeof(NMTBSAVE),
  228. sizeof(NMUPDOWN));
  229. case TBN_INITCUSTOMIZE: return sizeof(NMTBCUSTOMIZEDLG);
  230. case TBN_WRAPHOTITEM: return sizeof(NMTBWRAPHOTITEM);
  231. case TBN_DUPACCELERATOR: return sizeof(NMTBDUPACCELERATOR);
  232. case TBN_WRAPACCELERATOR: return sizeof(NMTBWRAPACCELERATOR);
  233. case TBN_DRAGOVER: return sizeof(NMTBHOTITEM);
  234. case TBN_MAPACCELERATOR: return sizeof(NMCHAR);
  235. // Up-down control
  236. #if 0 // see comment at TBN_SAVE
  237. case UDN_DELTAPOS: return sizeof(NMUPDOWN);
  238. #endif
  239. // Monthcal control
  240. case MCN_SELCHANGE: return sizeof(NMSELCHANGE);
  241. case MCN_GETDAYSTATE: return sizeof(NMDAYSTATE);
  242. case MCN_SELECT: return sizeof(NMSELECT);
  243. // Date/time picker control
  244. case DTN_DATETIMECHANGE: return sizeof(NMDATETIMECHANGE);
  245. case DTN_USERSTRINGA: return sizeof(NMDATETIMESTRINGA);
  246. case DTN_USERSTRINGW: return sizeof(NMDATETIMESTRINGW);
  247. case DTN_WMKEYDOWNA: return sizeof(NMDATETIMEWMKEYDOWNA);
  248. case DTN_WMKEYDOWNW: return sizeof(NMDATETIMEWMKEYDOWNW);
  249. case DTN_FORMATA: return sizeof(NMDATETIMEFORMATA);
  250. case DTN_FORMATW: return sizeof(NMDATETIMEFORMATW);
  251. case DTN_FORMATQUERYA: return sizeof(NMDATETIMEFORMATQUERYA);
  252. case DTN_FORMATQUERYW: return sizeof(NMDATETIMEFORMATQUERYW);
  253. case DTN_DROPDOWN: return sizeof(NMHDR);
  254. case DTN_CLOSEUP: return sizeof(NMHDR);
  255. // Comboex notifications
  256. case CBEN_GETDISPINFOA: return sizeof(NMCOMBOBOXEXA);
  257. case CBEN_GETDISPINFOW: return sizeof(NMCOMBOBOXEXW);
  258. case CBEN_INSERTITEM: return sizeof(NMCOMBOBOXEX); // Random character set
  259. case CBEN_DELETEITEM: return sizeof(NMCOMBOBOXEX); // No strings
  260. case CBEN_ITEMCHANGED: return sizeof(NMCOMBOBOXEX); // Not used
  261. case CBEN_BEGINEDIT: return sizeof(NMHDR);
  262. case CBEN_ENDEDITA: return sizeof(NMCBEENDEDITA);
  263. case CBEN_ENDEDITW: return sizeof(NMCBEENDEDITW);
  264. case CBEN_DRAGBEGINA: return sizeof(NMCBEDRAGBEGINA);
  265. case CBEN_DRAGBEGINW: return sizeof(NMCBEDRAGBEGINW);
  266. // Rebar notifications
  267. case RBN_HEIGHTCHANGE: return sizeof(NMHDR);
  268. case RBN_GETOBJECT: return sizeof(NMOBJECTNOTIFY);
  269. case RBN_LAYOUTCHANGED: return sizeof(NMHDR);
  270. case RBN_AUTOSIZE: return sizeof(NMRBAUTOSIZE);
  271. case RBN_BEGINDRAG: return sizeof(NMREBAR);
  272. case RBN_DELETINGBAND: return sizeof(NMREBAR);
  273. case RBN_DELETEDBAND: return sizeof(NMREBAR);
  274. case RBN_CHILDSIZE: return sizeof(NMREBARCHILDSIZE);
  275. // IP address control notification
  276. case IPN_FIELDCHANGED: return sizeof(NMIPADDRESS);
  277. // Status bar notifications
  278. case SBN_SIMPLEMODECHANGE: return sizeof(NMHDR);
  279. // Pager control notifications
  280. case PGN_SCROLL: return sizeof(NMPGSCROLL);
  281. case PGN_CALCSIZE: return sizeof(NMPGCALCSIZE);
  282. default:
  283. break;
  284. }
  285. //
  286. // Categories of notifications we explicitly know nothing about.
  287. //
  288. if (code >= WMN_LAST && code <= WMN_FIRST) { // Internet Mail and News
  289. return 0;
  290. }
  291. if ((int)code >= 0) { // Application-specific notifications
  292. return 0;
  293. }
  294. //
  295. // IF THIS ASSERT FIRES, YOU MUST FIX IT OR YOU WILL BREAK WOW!
  296. //
  297. AssertMsg(0, TEXT("Notification code %d must be added to WOWGetNotifySize"));
  298. return 0;
  299. }
  300. #endif // NEED_WOWGETNOTIFYSIZE_HELPER
  301. LRESULT WINAPI SendNotifyEx(HWND hwndTo, HWND hwndFrom, int code, NMHDR* pnmhdr, BOOL bUnicode)
  302. {
  303. CCONTROLINFO ci;
  304. if (!hwndTo) {
  305. if (IsWindow(hwndFrom))
  306. hwndTo = GetParent(hwndFrom);
  307. if (!hwndTo)
  308. return 0;
  309. }
  310. ci.hwndParent = hwndTo;
  311. ci.hwnd = hwndFrom;
  312. ci.bUnicode = BOOLIFY(bUnicode);
  313. ci.uiCodePage = CP_ACP;
  314. return CCSendNotify(&ci, code, pnmhdr);
  315. }
  316. void StringBufferAtoW(UINT uiCodePage, LPVOID pvOrgPtr, DWORD dwOrgSize, CHAR **ppszText)
  317. {
  318. if (pvOrgPtr == *ppszText)
  319. {
  320. // the pointer has not been changed by the callback...
  321. // must convert from A to W in-place
  322. if (dwOrgSize)
  323. {
  324. LPWSTR pszW = ProduceWFromA(uiCodePage, *ppszText);
  325. if (pszW)
  326. {
  327. lstrcpynW((WCHAR *)(*ppszText), pszW, dwOrgSize); // this becomes a W buffer
  328. FreeProducedString(pszW);
  329. }
  330. }
  331. }
  332. else
  333. {
  334. // the pointer has been changed out from underneath us, copy
  335. // unicode back into the original buffer.
  336. ConvertAToWN(uiCodePage, pvOrgPtr, dwOrgSize, *ppszText, -1);
  337. *ppszText = pvOrgPtr;
  338. }
  339. }
  340. typedef struct tagTHUNKSTATE {
  341. LPVOID ts_pvThunk1;
  342. LPVOID ts_pvThunk2;
  343. DWORD ts_dwThunkSize;
  344. } THUNKSTATE;
  345. //
  346. // InOutWtoA/InOutAtoW is for thunking INOUT string parameters.
  347. //
  348. // INOUT parameters always create a hassle.
  349. //
  350. // We need to save both the original ANSI and the
  351. // original UNICODE strings, so that if the app doesn't
  352. // change the ANSI string, we leave the original UNICODE
  353. // string alone. That way, UNICODE item names don't get
  354. // obliterated by the thunk.
  355. //
  356. // The original buffer is saved in pvThunk1.
  357. // We allocate two ANSI buffers.
  358. // pvThunk2 contains the original ANSIfied string.
  359. // pvThunk2+cchTextMax is the buffer we pass to the app.
  360. // On the way back, we compare pvThunk2 with pvThunk2+cchTextMax.
  361. // If they are different, then we unthunk the string; otherwise,
  362. // we leave the original UNICODE buffer alone.
  363. BOOL InOutWtoA(CCONTROLINFO *pci, THUNKSTATE *pts, LPWSTR *ppsz, DWORD cchTextMax)
  364. {
  365. pts->ts_pvThunk1 = *ppsz; // Save original buffer
  366. pts->ts_dwThunkSize = cchTextMax;
  367. if (!IsFlagPtr(pts->ts_pvThunk1))
  368. {
  369. pts->ts_pvThunk2 = LocalAlloc(LPTR, cchTextMax * 2 * sizeof(char));
  370. if (!ConvertWToAN(pci->uiCodePage, (LPSTR)pts->ts_pvThunk2, pts->ts_dwThunkSize, (LPWSTR)pts->ts_pvThunk1, -1))
  371. {
  372. LocalFree(pts->ts_pvThunk2);
  373. return 0;
  374. }
  375. *ppsz = (LPWSTR)((LPSTR)pts->ts_pvThunk2 + cchTextMax);
  376. lstrcpyA((LPSTR)*ppsz, pts->ts_pvThunk2);
  377. }
  378. return TRUE;
  379. }
  380. void InOutAtoW(CCONTROLINFO *pci, THUNKSTATE *pts, LPSTR *ppsz)
  381. {
  382. if (!IsFlagPtr(pts->ts_pvThunk1))
  383. {
  384. if (!IsFlagPtr(*ppsz) &&
  385. lstrcmpA(pts->ts_pvThunk2, (LPSTR)*ppsz) != 0)
  386. StringBufferAtoW(pci->uiCodePage, pts->ts_pvThunk1, pts->ts_dwThunkSize, ppsz);
  387. LocalFree(pts->ts_pvThunk2);
  388. }
  389. *ppsz = pts->ts_pvThunk1;
  390. }
  391. LRESULT WINAPI CCSendNotify(CCONTROLINFO * pci, int code, LPNMHDR pnmhdr)
  392. {
  393. NMHDR nmhdr;
  394. LONG_PTR id;
  395. THUNKSTATE ts = { 0 };
  396. #define pvThunk1 ts.ts_pvThunk1
  397. #define pvThunk2 ts.ts_pvThunk2
  398. #define dwThunkSize ts.ts_dwThunkSize
  399. LRESULT lRet;
  400. BOOL bSet = FALSE;
  401. HWND hwndParent = pci->hwndParent;
  402. DWORD dwParentPid;
  403. // -1 means Requery on each notify
  404. if ( hwndParent == (HWND)-1 )
  405. {
  406. hwndParent = GetParent(pci->hwnd);
  407. }
  408. // unlikely but it can technically happen -- avoid the rips
  409. if ( hwndParent == NULL )
  410. return 0;
  411. //
  412. // If pci->hwnd is -1, then a WM_NOTIFY is being forwared
  413. // from one control to a parent. EG: Tooltips sent
  414. // a WM_NOTIFY to toolbar, and toolbar is forwarding it
  415. // to the real parent window.
  416. //
  417. if (pci->hwnd != (HWND) -1) {
  418. //
  419. // If this is a child then get its ID. We need to go out of our way to
  420. // avoid calling GetDlgCtrlID on toplevel windows since it will return
  421. // a pseudo-random number (those of you who know what this number is
  422. // keep quiet). Anyway it's kinda hard to figure this out in Windows
  423. // because of the following:
  424. //
  425. // - a window can SetWindowLong(GWL_STYLE, WS_CHILD) but this only
  426. // does about half the work - hence checking the style is out.
  427. // - GetParent will return your OWNER if you are toplevel.
  428. // - there is no GetWindow(...GW_HWNDPARENT) to save us.
  429. //
  430. // Hence we are stuck with calling GetParent and then checking to see
  431. // if it lied and gave us the owner instead. Yuck.
  432. //
  433. id = 0;
  434. if (pci->hwnd) {
  435. HWND hwndParent = GetParent(pci->hwnd);
  436. if (hwndParent && (hwndParent != GetWindow(pci->hwnd, GW_OWNER))) {
  437. id = GetDlgCtrlID(pci->hwnd);
  438. }
  439. }
  440. if (!pnmhdr)
  441. pnmhdr = &nmhdr;
  442. pnmhdr->hwndFrom = pci->hwnd;
  443. pnmhdr->idFrom = id;
  444. pnmhdr->code = code;
  445. } else {
  446. id = pnmhdr->idFrom;
  447. code = pnmhdr->code;
  448. }
  449. // OLE in its massively componentized world sometimes creates
  450. // a control whose parent belongs to another process. (For example,
  451. // when there is a local server embedding.) WM_NOTIFY
  452. // messages can't cross process boundaries, so stop the message
  453. // from going there lest we fault the recipient.
  454. if (!GetWindowThreadProcessId(hwndParent, &dwParentPid) ||
  455. dwParentPid != GetCurrentProcessId())
  456. {
  457. TraceMsg(TF_WARNING, "nf: Not sending WM_NOTIFY %08x across processes", code);
  458. return 0;
  459. }
  460. #ifdef NEED_WOWGETNOTIFYSIZE_HELPER
  461. ASSERT(code >= 0 || WOWGetNotifySize(code));
  462. #endif // NEED_WOWGETNOTIFYSIZE_HELPER
  463. /*
  464. * All the thunking for Notify Messages happens here
  465. */
  466. if (!pci->bUnicode) {
  467. BOOL fThunked = TRUE;
  468. switch( code ) {
  469. case LVN_ODFINDITEMW:
  470. pnmhdr->code = LVN_ODFINDITEMA;
  471. goto ThunkLV_FINDINFO;
  472. case LVN_INCREMENTALSEARCHW:
  473. pnmhdr->code = LVN_INCREMENTALSEARCHA;
  474. goto ThunkLV_FINDINFO;
  475. ThunkLV_FINDINFO:
  476. {
  477. LV_FINDINFO *plvfi;
  478. // Hack Alert! This code assumes that all fields of LV_FINDINFOA and
  479. // LV_FINDINFOW are exactly the same except for the string pointers.
  480. COMPILETIME_ASSERT(sizeof(LV_FINDINFOA) == sizeof(LV_FINDINFOW));
  481. // Since WCHARs are bigger than char, we will just use the
  482. // wchar buffer to hold the chars, and not worry about the extra
  483. // room at the end.
  484. COMPILETIME_ASSERT(sizeof(WCHAR) >= sizeof(char));
  485. plvfi = &((PNM_FINDITEM)pnmhdr)->lvfi;
  486. if (plvfi->flags & (LVFI_STRING | LVFI_PARTIAL | LVFI_SUBSTRING))
  487. {
  488. pvThunk1 = (PVOID)plvfi->psz;
  489. dwThunkSize = lstrlen(pvThunk1) + 1;
  490. plvfi->psz = (LPWSTR)ProduceAFromW(pci->uiCodePage, plvfi->psz);
  491. }
  492. }
  493. break;
  494. case LVN_GETDISPINFOW: {
  495. LV_ITEMW *pitem;
  496. pnmhdr->code = LVN_GETDISPINFOA;
  497. // Hack Alert! This code assumes that all fields of LV_DISPINFOA and
  498. // LV_DISPINFOW are exactly the same except for the string pointers.
  499. COMPILETIME_ASSERT(sizeof(LV_DISPINFOA) == sizeof(LV_DISPINFOW));
  500. // Since WCHARs are bigger than char, we will just use the
  501. // wchar buffer to hold the chars, and not worry about the extra
  502. // room at the end.
  503. COMPILETIME_ASSERT(sizeof(WCHAR) >= sizeof(char));
  504. //
  505. // Some sleazebag code (shell32.dll) just changes the pszText
  506. // pointer to point to the name, so capture the original pointer
  507. // so we can detect this and not smash their data.
  508. //
  509. pitem = &(((LV_DISPINFOW *)pnmhdr)->item);
  510. if (!IsFlagPtr(pitem) && (pitem->mask & LVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  511. pvThunk1 = pitem->pszText;
  512. dwThunkSize = pitem->cchTextMax;
  513. }
  514. break;
  515. }
  516. // LVN_ENDLABELEDIT uses an INOUT parameter, never explicitly
  517. // documented as such, but it just happened to be that way,
  518. // and I don't want to take the chance that somebody was relying
  519. // on it.
  520. case LVN_ENDLABELEDITW:
  521. pnmhdr->code = LVN_ENDLABELEDITA;
  522. goto ThunkLV_DISPINFO;
  523. case LVN_BEGINLABELEDITW:
  524. pnmhdr->code = LVN_BEGINLABELEDITA;
  525. goto ThunkLV_DISPINFO;
  526. case LVN_SETDISPINFOW:
  527. pnmhdr->code = LVN_SETDISPINFOA;
  528. goto ThunkLV_DISPINFO;
  529. case LVN_GETEMPTYTEXTW:
  530. pnmhdr->code = LVN_GETEMPTYTEXTA;
  531. goto ThunkLV_DISPINFO;
  532. ThunkLV_DISPINFO: {
  533. LV_ITEMW *pitem;
  534. COMPILETIME_ASSERT(sizeof(LV_ITEMA) == sizeof(LV_ITEMW));
  535. pitem = &(((LV_DISPINFOW *)pnmhdr)->item);
  536. if (pitem->mask & LVIF_TEXT) {
  537. if (!InOutWtoA(pci, &ts, &pitem->pszText, pitem->cchTextMax))
  538. return 0;
  539. }
  540. break;
  541. }
  542. case LVN_GETINFOTIPW: {
  543. NMLVGETINFOTIPW *pgit = (NMLVGETINFOTIPW *)pnmhdr;
  544. COMPILETIME_ASSERT(sizeof(NMLVGETINFOTIPA) == sizeof(NMLVGETINFOTIPW));
  545. pnmhdr->code = LVN_GETINFOTIPA;
  546. if (!InOutWtoA(pci, &ts, &pgit->pszText, pgit->cchTextMax))
  547. return 0;
  548. }
  549. break;
  550. case TVN_GETINFOTIPW:
  551. {
  552. NMTVGETINFOTIPW *pgit = (NMTVGETINFOTIPW *)pnmhdr;
  553. pnmhdr->code = TVN_GETINFOTIPA;
  554. pvThunk1 = pgit->pszText;
  555. dwThunkSize = pgit->cchTextMax;
  556. }
  557. break;
  558. case TBN_GETINFOTIPW:
  559. {
  560. NMTBGETINFOTIPW *pgit = (NMTBGETINFOTIPW *)pnmhdr;
  561. pnmhdr->code = TBN_GETINFOTIPA;
  562. pvThunk1 = pgit->pszText;
  563. dwThunkSize = pgit->cchTextMax;
  564. }
  565. break;
  566. case TVN_SELCHANGINGW:
  567. pnmhdr->code = TVN_SELCHANGINGA;
  568. bSet = TRUE;
  569. // fall through
  570. case TVN_SELCHANGEDW:
  571. if (!bSet) {
  572. pnmhdr->code = TVN_SELCHANGEDA;
  573. bSet = TRUE;
  574. }
  575. /*
  576. * These msgs have a NM_TREEVIEW with both TV_ITEMs filled in
  577. *
  578. * FALL THROUGH TO TVN_DELETEITEM to thunk itemOld then go on for
  579. * the other structure.
  580. */
  581. // fall through
  582. case TVN_DELETEITEMW: {
  583. /*
  584. * This message has a NM_TREEVIEW in lParam with itemOld filled in
  585. */
  586. LPTV_ITEMW pitem;
  587. if (!bSet) {
  588. pnmhdr->code = TVN_DELETEITEMA;
  589. bSet = TRUE;
  590. }
  591. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemOld);
  592. // thunk itemOld
  593. if ( (pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  594. pvThunk2 = pitem->pszText;
  595. pitem->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk2);
  596. }
  597. // if this is deleteitem then we are done
  598. if (pnmhdr->code == TVN_DELETEITEMA)
  599. break;
  600. /* FALL THROUGH TO TVN_ITEMEXPANDING to thunk itemNew */
  601. }
  602. // fall through
  603. case TVN_ITEMEXPANDINGW:
  604. if (!bSet) {
  605. pnmhdr->code = TVN_ITEMEXPANDINGA;
  606. bSet = TRUE;
  607. }
  608. // fall through
  609. case TVN_ITEMEXPANDEDW:
  610. if (!bSet) {
  611. pnmhdr->code = TVN_ITEMEXPANDEDA;
  612. bSet = TRUE;
  613. }
  614. // fall through
  615. case TVN_BEGINDRAGW:
  616. if (!bSet) {
  617. pnmhdr->code = TVN_BEGINDRAGA;
  618. bSet = TRUE;
  619. }
  620. // fall through
  621. case TVN_BEGINRDRAGW: {
  622. /* these msgs have a NM_TREEVIEW with itemNew TV_ITEM filled in */
  623. LPTV_ITEMW pitem;
  624. if (!bSet) {
  625. pnmhdr->code = TVN_BEGINRDRAGA;
  626. }
  627. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemNew);
  628. if ( (pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  629. pvThunk1 = pitem->pszText;
  630. pitem->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk1);
  631. }
  632. break;
  633. }
  634. case TVN_SETDISPINFOW:
  635. pnmhdr->code = TVN_SETDISPINFOA;
  636. goto ThunkTV_DISPINFO;
  637. case TVN_BEGINLABELEDITW:
  638. pnmhdr->code = TVN_BEGINLABELEDITA;
  639. goto ThunkTV_DISPINFO;
  640. // TVN_ENDLABELEDIT uses an INOUT parameter, never explicitly
  641. // documented as such, but it just happened to be that way,
  642. // and I don't want to take the chance that somebody was relying
  643. // on it.
  644. case TVN_ENDLABELEDITW:
  645. pnmhdr->code = TVN_ENDLABELEDITA;
  646. goto ThunkTV_DISPINFO;
  647. ThunkTV_DISPINFO:
  648. {
  649. /*
  650. * All these messages have a TV_DISPINFO in lParam.
  651. */
  652. LPTV_ITEMW pitem;
  653. pitem = &(((TV_DISPINFOW *)pnmhdr)->item);
  654. if (pitem->mask & TVIF_TEXT)
  655. {
  656. if (!InOutWtoA(pci, &ts, &pitem->pszText, pitem->cchTextMax))
  657. return 0;
  658. }
  659. break;
  660. }
  661. case TVN_GETDISPINFOW:
  662. {
  663. // All these messages have a TV_DISPINFO in lParam.
  664. LPTV_ITEMW pitem;
  665. pnmhdr->code = TVN_GETDISPINFOA;
  666. pitem = &(((TV_DISPINFOW *)pnmhdr)->item);
  667. if ((pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText) && pitem->cchTextMax) {
  668. pvThunk1 = pitem->pszText;
  669. dwThunkSize = pitem->cchTextMax;
  670. pvThunk2 = LocalAlloc(LPTR, pitem->cchTextMax * sizeof(char));
  671. pitem->pszText = pvThunk2;
  672. pitem->pszText[0] = TEXT('\0');
  673. }
  674. break;
  675. }
  676. case HDN_ITEMCHANGINGW:
  677. pnmhdr->code = HDN_ITEMCHANGINGA;
  678. bSet = TRUE;
  679. // fall through
  680. case HDN_ITEMCHANGEDW:
  681. if (!bSet) {
  682. pnmhdr->code = HDN_ITEMCHANGEDA;
  683. bSet = TRUE;
  684. }
  685. // fall through
  686. case HDN_ITEMCLICKW:
  687. if (!bSet) {
  688. pnmhdr->code = HDN_ITEMCLICKA;
  689. bSet = TRUE;
  690. }
  691. // fall through
  692. case HDN_ITEMDBLCLICKW:
  693. if (!bSet) {
  694. pnmhdr->code = HDN_ITEMDBLCLICKA;
  695. bSet = TRUE;
  696. }
  697. // fall through
  698. case HDN_DIVIDERDBLCLICKW:
  699. if (!bSet) {
  700. pnmhdr->code = HDN_DIVIDERDBLCLICKA;
  701. bSet = TRUE;
  702. }
  703. // fall through
  704. case HDN_BEGINTRACKW:
  705. if (!bSet) {
  706. pnmhdr->code = HDN_BEGINTRACKA;
  707. bSet = TRUE;
  708. }
  709. // fall through
  710. case HDN_ENDTRACKW:
  711. if (!bSet) {
  712. pnmhdr->code = HDN_ENDTRACKA;
  713. bSet = TRUE;
  714. }
  715. // fall through
  716. case HDN_TRACKW: {
  717. HD_ITEMW *pitem;
  718. if (!bSet) {
  719. pnmhdr->code = HDN_TRACKA;
  720. }
  721. pitem = ((HD_NOTIFY *)pnmhdr)->pitem;
  722. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_TEXT) && !IsFlagPtr(pitem->pszText)) {
  723. pvThunk1 = pitem->pszText;
  724. dwThunkSize = pitem->cchTextMax;
  725. pitem->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk1);
  726. }
  727. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_FILTER) && pitem->pvFilter )
  728. {
  729. if ( !(pitem->type & HDFT_HASNOVALUE) &&
  730. ((pitem->type & HDFT_ISMASK)==HDFT_ISSTRING) )
  731. {
  732. LPHD_TEXTFILTER ptextFilter = (LPHD_TEXTFILTER)pitem->pvFilter;
  733. pvThunk2 = ptextFilter->pszText;
  734. dwThunkSize = ptextFilter->cchTextMax;
  735. ptextFilter->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk2);
  736. }
  737. }
  738. break;
  739. }
  740. case CBEN_ENDEDITW:
  741. {
  742. LPNMCBEENDEDITW peew = (LPNMCBEENDEDITW) pnmhdr;
  743. LPNMCBEENDEDITA peea = LocalAlloc(LPTR, sizeof(NMCBEENDEDITA));
  744. if (!peea)
  745. return 0;
  746. peea->hdr = peew->hdr;
  747. peea->hdr.code = CBEN_ENDEDITA;
  748. peea->fChanged = peew->fChanged;
  749. peea->iNewSelection = peew->iNewSelection;
  750. peea->iWhy = peew->iWhy;
  751. ConvertWToAN(pci->uiCodePage, peea->szText, ARRAYSIZE(peea->szText),
  752. peew->szText, -1);
  753. pvThunk1 = pnmhdr;
  754. pnmhdr = &peea->hdr;
  755. ASSERT((LPVOID)pnmhdr == (LPVOID)peea);
  756. break;
  757. }
  758. case CBEN_DRAGBEGINW:
  759. {
  760. LPNMCBEDRAGBEGINW pdbw = (LPNMCBEDRAGBEGINW) pnmhdr;
  761. LPNMCBEDRAGBEGINA pdba = LocalAlloc(LPTR, sizeof(NMCBEDRAGBEGINA));
  762. if (!pdba)
  763. return 0;
  764. pdba->hdr = pdbw->hdr;
  765. pdba->hdr.code = CBEN_DRAGBEGINA;
  766. pdba->iItemid = pdbw->iItemid;
  767. ConvertWToAN(pci->uiCodePage, pdba->szText, ARRAYSIZE(pdba->szText),
  768. pdbw->szText, -1);
  769. pvThunk1 = pnmhdr;
  770. pnmhdr = &pdba->hdr;
  771. ASSERT((LPVOID)pnmhdr == (LPVOID)pdba);
  772. break;
  773. }
  774. case CBEN_GETDISPINFOW: {
  775. PNMCOMBOBOXEXW pnmcbe = (PNMCOMBOBOXEXW)pnmhdr;
  776. pnmhdr->code = CBEN_GETDISPINFOA;
  777. if (pnmcbe->ceItem.mask & CBEIF_TEXT
  778. && !IsFlagPtr(pnmcbe->ceItem.pszText) && pnmcbe->ceItem.cchTextMax) {
  779. pvThunk1 = pnmcbe->ceItem.pszText;
  780. dwThunkSize = pnmcbe->ceItem.cchTextMax;
  781. pvThunk2 = LocalAlloc(LPTR, pnmcbe->ceItem.cchTextMax * sizeof(char));
  782. pnmcbe->ceItem.pszText = pvThunk2;
  783. pnmcbe->ceItem.pszText[0] = TEXT('\0');
  784. }
  785. break;
  786. }
  787. case HDN_GETDISPINFOW: {
  788. LPNMHDDISPINFOW pHDDispInfoW;
  789. pnmhdr->code = HDN_GETDISPINFOA;
  790. pHDDispInfoW = (LPNMHDDISPINFOW) pnmhdr;
  791. pvThunk1 = pHDDispInfoW->pszText;
  792. dwThunkSize = pHDDispInfoW->cchTextMax;
  793. pHDDispInfoW->pszText = LocalAlloc (LPTR, pHDDispInfoW->cchTextMax * sizeof(char));
  794. if (!pHDDispInfoW->pszText) {
  795. pHDDispInfoW->pszText = (LPWSTR) pvThunk1;
  796. break;
  797. }
  798. WideCharToMultiByte(pci->uiCodePage, 0, (LPWSTR)pvThunk1, -1,
  799. (LPSTR)pHDDispInfoW->pszText, pHDDispInfoW->cchTextMax,
  800. NULL, NULL);
  801. break;
  802. }
  803. case TBN_GETBUTTONINFOW:
  804. {
  805. LPTBNOTIFYW pTBNW;
  806. pnmhdr->code = TBN_GETBUTTONINFOA;
  807. pTBNW = (LPTBNOTIFYW)pnmhdr;
  808. pvThunk1 = pTBNW->pszText;
  809. dwThunkSize = pTBNW->cchText;
  810. pvThunk2 = LocalAlloc (LPTR, pTBNW->cchText * sizeof(char));
  811. if (!pvThunk2) {
  812. break;
  813. }
  814. pTBNW->pszText = pvThunk2;
  815. WideCharToMultiByte(pci->uiCodePage, 0, (LPWSTR)pvThunk1, -1,
  816. (LPSTR)pTBNW->pszText, pTBNW->cchText,
  817. NULL, NULL);
  818. }
  819. break;
  820. case TTN_NEEDTEXTW:
  821. {
  822. LPTOOLTIPTEXTA lpTTTA;
  823. LPTOOLTIPTEXTW lpTTTW = (LPTOOLTIPTEXTW) pnmhdr;
  824. lpTTTA = LocalAlloc(LPTR, sizeof(TOOLTIPTEXTA));
  825. if (!lpTTTA)
  826. return 0;
  827. lpTTTA->hdr = lpTTTW->hdr;
  828. lpTTTA->hdr.code = TTN_NEEDTEXTA;
  829. lpTTTA->lpszText = lpTTTA->szText;
  830. lpTTTA->hinst = lpTTTW->hinst;
  831. lpTTTA->uFlags = lpTTTW->uFlags;
  832. lpTTTA->lParam = lpTTTW->lParam;
  833. WideCharToMultiByte(pci->uiCodePage, 0, lpTTTW->szText, -1, lpTTTA->szText, ARRAYSIZE(lpTTTA->szText), NULL, NULL);
  834. pvThunk1 = pnmhdr;
  835. pnmhdr = (NMHDR *)lpTTTA;
  836. }
  837. break;
  838. case DTN_USERSTRINGW:
  839. {
  840. LPNMDATETIMESTRINGW lpDateTimeString = (LPNMDATETIMESTRINGW) pnmhdr;
  841. pnmhdr->code = DTN_USERSTRINGA;
  842. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeString->pszUserString);
  843. lpDateTimeString->pszUserString = (LPWSTR) pvThunk1;
  844. }
  845. break;
  846. case DTN_WMKEYDOWNW:
  847. {
  848. LPNMDATETIMEWMKEYDOWNW lpDateTimeWMKeyDown =
  849. (LPNMDATETIMEWMKEYDOWNW) pnmhdr;
  850. pnmhdr->code = DTN_WMKEYDOWNA;
  851. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeWMKeyDown->pszFormat);
  852. lpDateTimeWMKeyDown->pszFormat = (LPWSTR) pvThunk1;
  853. }
  854. break;
  855. case DTN_FORMATQUERYW:
  856. {
  857. LPNMDATETIMEFORMATQUERYW lpDateTimeFormatQuery =
  858. (LPNMDATETIMEFORMATQUERYW) pnmhdr;
  859. pnmhdr->code = DTN_FORMATQUERYA;
  860. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeFormatQuery->pszFormat);
  861. lpDateTimeFormatQuery->pszFormat = (LPWSTR) pvThunk1;
  862. }
  863. break;
  864. case DTN_FORMATW:
  865. {
  866. LPNMDATETIMEFORMATW lpDateTimeFormat =
  867. (LPNMDATETIMEFORMATW) pnmhdr;
  868. pnmhdr->code = DTN_FORMATA;
  869. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeFormat->pszFormat);
  870. lpDateTimeFormat->pszFormat = (LPWSTR) pvThunk1;
  871. }
  872. break;
  873. default:
  874. fThunked = FALSE;
  875. break;
  876. }
  877. #ifdef NEED_WOWGETNOTIFYSIZE_HELPER
  878. ASSERT(code >= 0 || WOWGetNotifySize(code));
  879. #endif // NEED_WOWGETNOTIFYSIZE_HELPER
  880. lRet = SendMessage(hwndParent, WM_NOTIFY, (WPARAM)id, (LPARAM)pnmhdr);
  881. /*
  882. * All the thunking for Notify Messages happens here
  883. */
  884. if (fThunked)
  885. {
  886. switch(pnmhdr->code) {
  887. case LVN_ODFINDITEMA:
  888. case LVN_INCREMENTALSEARCHA:
  889. {
  890. LV_FINDINFO *plvfi = &((PNM_FINDITEM)pnmhdr)->lvfi;
  891. if (pvThunk1)
  892. {
  893. FreeProducedString((LPWSTR)plvfi->psz);
  894. plvfi->psz = pvThunk1;
  895. }
  896. }
  897. break;
  898. case LVN_GETDISPINFOA:
  899. {
  900. LV_ITEMA *pitem = &(((LV_DISPINFOA *)pnmhdr)->item);
  901. if (!IsFlagPtr(pitem) && (pitem->mask & LVIF_TEXT) && !IsFlagPtr(pitem->pszText))
  902. {
  903. StringBufferAtoW(pci->uiCodePage, pvThunk1, dwThunkSize, &pitem->pszText);
  904. }
  905. }
  906. break;
  907. case LVN_ENDLABELEDITA:
  908. case LVN_BEGINLABELEDITA:
  909. case LVN_SETDISPINFOA:
  910. case LVN_GETEMPTYTEXTA:
  911. {
  912. LV_ITEMA *pitem = &(((LV_DISPINFOA *)pnmhdr)->item);
  913. InOutAtoW(pci, &ts, &pitem->pszText);
  914. }
  915. break;
  916. case LVN_GETINFOTIPA:
  917. {
  918. NMLVGETINFOTIPA *pgit = (NMLVGETINFOTIPA *)pnmhdr;
  919. InOutAtoW(pci, &ts, &pgit->pszText);
  920. }
  921. break;
  922. case TVN_GETINFOTIPA:
  923. {
  924. NMTVGETINFOTIPA *pgit = (NMTVGETINFOTIPA *)pnmhdr;
  925. StringBufferAtoW(pci->uiCodePage, pvThunk1, dwThunkSize, &pgit->pszText);
  926. }
  927. break;
  928. case TBN_GETINFOTIPA:
  929. {
  930. NMTBGETINFOTIPA *pgit = (NMTBGETINFOTIPA *)pnmhdr;
  931. StringBufferAtoW(pci->uiCodePage, pvThunk1, dwThunkSize, &pgit->pszText);
  932. }
  933. break;
  934. case TVN_SELCHANGINGA:
  935. case TVN_SELCHANGEDA:
  936. case TVN_DELETEITEMA: {
  937. LPTV_ITEMW pitem;
  938. if ( !IsFlagPtr(pvThunk2) ) {
  939. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemOld);
  940. FreeProducedString(pitem->pszText);
  941. pitem->pszText = pvThunk2;
  942. }
  943. // if this is delitem, then we are done
  944. if (code == TVN_DELETEITEM)
  945. break;
  946. /* FALL THROUGH TO TVN_ITEMEXPANDING to unthunk itemNew */
  947. }
  948. // fall through
  949. case TVN_ITEMEXPANDINGA:
  950. case TVN_ITEMEXPANDEDA:
  951. case TVN_BEGINDRAGA:
  952. case TVN_BEGINRDRAGA: {
  953. /* these msgs have a NM_TREEVIEW with itemNew TV_ITEM filled in */
  954. LPTV_ITEMW pitem;
  955. if (!IsFlagPtr(pvThunk1)) {
  956. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemNew);
  957. FreeProducedString(pitem->pszText);
  958. pitem->pszText = pvThunk1;
  959. }
  960. break;
  961. }
  962. case TVN_SETDISPINFOA:
  963. case TVN_BEGINLABELEDITA:
  964. case TVN_ENDLABELEDITA:
  965. {
  966. LPTV_ITEMA pitem;
  967. pitem = &(((TV_DISPINFOA *)pnmhdr)->item);
  968. InOutAtoW(pci, &ts, &pitem->pszText);
  969. }
  970. break;
  971. case TVN_GETDISPINFOA: {
  972. /*
  973. * This message has a TV_DISPINFO in lParam that wass filled in
  974. * during the callback and needs to be unthunked.
  975. */
  976. LPTV_ITEMW pitem;
  977. pitem = &(((TV_DISPINFOW *)pnmhdr)->item);
  978. if (!IsFlagPtr(pvThunk1) && (pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  979. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)pitem->pszText, -1);
  980. pitem->pszText = pvThunk1;
  981. LocalFree(pvThunk2);
  982. }
  983. break;
  984. }
  985. case HDN_ITEMCHANGINGA:
  986. case HDN_ITEMCHANGEDA:
  987. case HDN_ITEMCLICKA:
  988. case HDN_ITEMDBLCLICKA:
  989. case HDN_DIVIDERDBLCLICKA:
  990. case HDN_BEGINTRACKA:
  991. case HDN_ENDTRACKA:
  992. case HDN_TRACKA: {
  993. HD_ITEMW *pitem;
  994. pitem = ((HD_NOTIFY *)pnmhdr)->pitem;
  995. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_TEXT) && !IsFlagPtr(pvThunk1)) {
  996. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pitem->pszText), -1);
  997. FreeProducedString(pitem->pszText);
  998. pitem->pszText = pvThunk1;
  999. }
  1000. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_FILTER) && pitem->pvFilter && pvThunk2 )
  1001. {
  1002. if ( !(pitem->type & HDFT_HASNOVALUE) &&
  1003. ((pitem->type & HDFT_ISMASK)==HDFT_ISSTRING) )
  1004. {
  1005. LPHD_TEXTFILTER ptextFilter = (LPHD_TEXTFILTER)pitem->pvFilter;
  1006. ConvertAToWN(pci->uiCodePage, pvThunk2, dwThunkSize, (LPSTR)(ptextFilter->pszText), -1);
  1007. FreeProducedString(ptextFilter->pszText);
  1008. ptextFilter->pszText = pvThunk2;
  1009. }
  1010. }
  1011. break;
  1012. }
  1013. case CBEN_ENDEDITA:
  1014. {
  1015. LPNMCBEENDEDITW peew = (LPNMCBEENDEDITW) pvThunk1;
  1016. LPNMCBEENDEDITA peea = (LPNMCBEENDEDITA) pnmhdr;
  1017. // Don't unthunk the string since that destroys unicode round-trip
  1018. // and the client shouldn't be modifying it anyway.
  1019. // ConvertAToWN(pci->uiCodePage, peew->szText, ARRAYSIZE(peew->szText),
  1020. // peea->szText, -1);
  1021. LocalFree(peea);
  1022. }
  1023. break;
  1024. case CBEN_DRAGBEGINA:
  1025. {
  1026. LPNMCBEDRAGBEGINW pdbw = (LPNMCBEDRAGBEGINW) pvThunk1;
  1027. LPNMCBEDRAGBEGINA pdba = (LPNMCBEDRAGBEGINA) pnmhdr;
  1028. // Don't unthunk the string since that destroys unicode round-trip
  1029. // and the client shouldn't be modifying it anyway.
  1030. // ConvertAToWN(pci->uiCodePage, pdbw->szText, ARRAYSIZE(pdbw->szText),
  1031. // pdba->szText, -1);
  1032. LocalFree(pdba);
  1033. }
  1034. break;
  1035. case CBEN_GETDISPINFOA:
  1036. {
  1037. PNMCOMBOBOXEXW pnmcbeW;
  1038. pnmcbeW = (PNMCOMBOBOXEXW)pnmhdr;
  1039. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pnmcbeW->ceItem.pszText), -1);
  1040. if (pvThunk2)
  1041. LocalFree(pvThunk2);
  1042. pnmcbeW->ceItem.pszText = pvThunk1;
  1043. }
  1044. break;
  1045. case HDN_GETDISPINFOA:
  1046. {
  1047. LPNMHDDISPINFOW pHDDispInfoW;
  1048. pHDDispInfoW = (LPNMHDDISPINFOW)pnmhdr;
  1049. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pHDDispInfoW->pszText), -1);
  1050. LocalFree(pHDDispInfoW->pszText);
  1051. pHDDispInfoW->pszText = pvThunk1;
  1052. }
  1053. break;
  1054. case TBN_GETBUTTONINFOA:
  1055. {
  1056. LPTBNOTIFYW pTBNW;
  1057. pTBNW = (LPTBNOTIFYW)pnmhdr;
  1058. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pTBNW->pszText), -1);
  1059. pTBNW->pszText = pvThunk1;
  1060. LocalFree(pvThunk2);
  1061. }
  1062. break;
  1063. case TTN_NEEDTEXTA:
  1064. {
  1065. LPTOOLTIPTEXTA lpTTTA = (LPTOOLTIPTEXTA) pnmhdr;
  1066. LPTOOLTIPTEXTW lpTTTW = (LPTOOLTIPTEXTW) pvThunk1;
  1067. ThunkToolTipTextAtoW (lpTTTA, lpTTTW, pci->uiCodePage);
  1068. LocalFree(lpTTTA);
  1069. }
  1070. break;
  1071. case DTN_USERSTRINGA:
  1072. case DTN_WMKEYDOWNA:
  1073. case DTN_FORMATQUERYA:
  1074. {
  1075. FreeProducedString (pvThunk1);
  1076. }
  1077. break;
  1078. case DTN_FORMATA:
  1079. {
  1080. LPNMDATETIMEFORMATA lpDateTimeFormat = (LPNMDATETIMEFORMATA) pnmhdr;
  1081. FreeProducedString (pvThunk1);
  1082. //
  1083. // pszDisplay and szDisplay are special cases.
  1084. //
  1085. if (lpDateTimeFormat->pszDisplay && *lpDateTimeFormat->pszDisplay) {
  1086. //
  1087. // if pszDisplay still points at szDisplay then thunk
  1088. // in place. Otherwise allocate memory and copy the
  1089. // display string. This buffer will be freeded in monthcal.c
  1090. //
  1091. if (lpDateTimeFormat->pszDisplay == lpDateTimeFormat->szDisplay) {
  1092. CHAR szDisplay[64];
  1093. lstrcpynA (szDisplay, lpDateTimeFormat->szDisplay, 64);
  1094. ConvertAToWN (pci->uiCodePage, (LPWSTR)lpDateTimeFormat->szDisplay, 64,
  1095. szDisplay, -1);
  1096. } else {
  1097. lpDateTimeFormat->pszDisplay =
  1098. (LPSTR) ProduceWFromA (pci->uiCodePage, lpDateTimeFormat->pszDisplay);
  1099. }
  1100. }
  1101. }
  1102. break;
  1103. default:
  1104. /* No thunking needed */
  1105. break;
  1106. }
  1107. }
  1108. return lRet;
  1109. }
  1110. else
  1111. return(SendMessage(hwndParent, WM_NOTIFY, (WPARAM)id, (LPARAM)pnmhdr));
  1112. #undef pvThunk1
  1113. #undef pvThunk2
  1114. #undef dwThunkSize
  1115. }
  1116. LRESULT WINAPI SendNotify(HWND hwndTo, HWND hwndFrom, int code, NMHDR* pnmhdr)
  1117. {
  1118. CCONTROLINFO ci;
  1119. ci.hwndParent = hwndTo;
  1120. ci.hwnd = hwndFrom;
  1121. ci.bUnicode = FALSE;
  1122. ci.uiCodePage = CP_ACP;
  1123. //
  1124. // SendNotify is obsolete. New code should call CCSendNotify
  1125. // instead. However, if something does call SendNotify,
  1126. // it will call SendNotifyEx with FALSE as the Unicode parameter,
  1127. // because it probably is ANSI code.
  1128. //
  1129. return CCSendNotify(&ci, code, pnmhdr);
  1130. }
  1131. DWORD CICustomDrawNotify(LPCCONTROLINFO lpci, DWORD dwStage, LPNMCUSTOMDRAW lpnmcd)
  1132. {
  1133. DWORD dwRet = CDRF_DODEFAULT;
  1134. // bail if...
  1135. // this is an item notification, but an item notification wasn't asked for
  1136. if ((dwStage & CDDS_ITEM) && !(lpci->dwCustom & CDRF_NOTIFYITEMDRAW)) {
  1137. return dwRet;
  1138. }
  1139. lpnmcd->dwDrawStage = dwStage;
  1140. dwRet = (DWORD) CCSendNotify(lpci, NM_CUSTOMDRAW, &lpnmcd->hdr);
  1141. // validate the flags
  1142. if (dwRet & ~CDRF_VALIDFLAGS)
  1143. return CDRF_DODEFAULT;
  1144. return dwRet;
  1145. }
  1146. //
  1147. // Too many apps encounter strange behavior when we send out
  1148. // NM_CUSTOMDRAW messages at times unrelated to painting.
  1149. // E.g., NetMeeting and MFC recurse back into ListView_RecomputeLabelSize.
  1150. // CryptUI will fault if it's asked to NM_CUSTOMDRAW before it gets
  1151. // WM_INITDIALOG. So all this fake customdraw stuff is v5 only.
  1152. //
  1153. // And since it is very popular to call back into the control during
  1154. // the handling of NM_CUSTOMDRAW, we protect against recursing ourselves
  1155. // to death by blowing off nested fake customdraw messages.
  1156. DWORD CIFakeCustomDrawNotify(LPCCONTROLINFO lpci, DWORD dwStage, LPNMCUSTOMDRAW lpnmcd)
  1157. {
  1158. DWORD dwRet = CDRF_DODEFAULT;
  1159. if (!lpci->bInFakeCustomDraw)
  1160. {
  1161. lpci->bInFakeCustomDraw = TRUE;
  1162. dwRet = CICustomDrawNotify(lpci, dwStage, lpnmcd);
  1163. ASSERT(lpci->bInFakeCustomDraw);
  1164. lpci->bInFakeCustomDraw = FALSE;
  1165. }
  1166. return dwRet;
  1167. }
  1168. /*----------------------------------------------------------
  1169. Purpose: Release the capture and tell the parent we've done so.
  1170. Returns: Whether the control is still alive.
  1171. */
  1172. BOOL CCReleaseCapture(CCONTROLINFO * pci)
  1173. {
  1174. HWND hwndCtl = pci->hwnd;
  1175. NMHDR nmhdr = {0};
  1176. ReleaseCapture();
  1177. // Tell the parent we've released the capture
  1178. CCSendNotify(pci, NM_RELEASEDCAPTURE, &nmhdr);
  1179. return IsWindow(hwndCtl);
  1180. }
  1181. /*----------------------------------------------------------
  1182. Purpose: Set the capture. If the hwndSet is NULL, it means
  1183. the capture is being released, so tell the parent
  1184. we've done so.
  1185. Use this function if there's a possibility that the
  1186. hwnd may be NULL.
  1187. */
  1188. void CCSetCapture(CCONTROLINFO * pci, HWND hwndSet)
  1189. {
  1190. SetCapture(hwndSet);
  1191. if (NULL == hwndSet)
  1192. {
  1193. NMHDR nmhdr = {0};
  1194. // Tell the parent we've released the capture
  1195. CCSendNotify(pci, NM_RELEASEDCAPTURE, &nmhdr);
  1196. }
  1197. }