Leaked source code of windows server 2003
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.

1451 lines
51 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 CONTROLINFO OAIDL_CONTROLINFO
  7. #define LPCONTROLINFO LPOAIDL_CONTROLINFO
  8. #include <shlobj.h>
  9. #include <shlobjp.h> // NMVIEWFOLDER structure
  10. #undef CONTROLINFO
  11. #undef LPCONTROLINFO
  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. // Monthcal control
  236. case MCN_SELCHANGE: return sizeof(NMSELCHANGE);
  237. case MCN_GETDAYSTATE: return sizeof(NMDAYSTATE);
  238. case MCN_SELECT: return sizeof(NMSELECT);
  239. // Date/time picker control
  240. case DTN_DATETIMECHANGE: return sizeof(NMDATETIMECHANGE);
  241. case DTN_USERSTRINGA: return sizeof(NMDATETIMESTRINGA);
  242. case DTN_USERSTRINGW: return sizeof(NMDATETIMESTRINGW);
  243. case DTN_WMKEYDOWNA: return sizeof(NMDATETIMEWMKEYDOWNA);
  244. case DTN_WMKEYDOWNW: return sizeof(NMDATETIMEWMKEYDOWNW);
  245. case DTN_FORMATA: return sizeof(NMDATETIMEFORMATA);
  246. case DTN_FORMATW: return sizeof(NMDATETIMEFORMATW);
  247. case DTN_FORMATQUERYA: return sizeof(NMDATETIMEFORMATQUERYA);
  248. case DTN_FORMATQUERYW: return sizeof(NMDATETIMEFORMATQUERYW);
  249. case DTN_DROPDOWN: return sizeof(NMHDR);
  250. case DTN_CLOSEUP: return sizeof(NMHDR);
  251. // Comboex notifications
  252. case CBEN_GETDISPINFOA: return sizeof(NMCOMBOBOXEXA);
  253. case CBEN_GETDISPINFOW: return sizeof(NMCOMBOBOXEXW);
  254. case CBEN_INSERTITEM: return sizeof(NMCOMBOBOXEX); // Random character set
  255. case CBEN_DELETEITEM: return sizeof(NMCOMBOBOXEX); // No strings
  256. case CBEN_ITEMCHANGED: return sizeof(NMCOMBOBOXEX); // Not used
  257. case CBEN_BEGINEDIT: return sizeof(NMHDR);
  258. case CBEN_ENDEDITA: return sizeof(NMCBEENDEDITA);
  259. case CBEN_ENDEDITW: return sizeof(NMCBEENDEDITW);
  260. case CBEN_DRAGBEGINA: return sizeof(NMCBEDRAGBEGINA);
  261. case CBEN_DRAGBEGINW: return sizeof(NMCBEDRAGBEGINW);
  262. // Rebar notifications
  263. case RBN_HEIGHTCHANGE: return sizeof(NMHDR);
  264. case RBN_GETOBJECT: return sizeof(NMOBJECTNOTIFY);
  265. case RBN_LAYOUTCHANGED: return sizeof(NMHDR);
  266. case RBN_AUTOSIZE: return sizeof(NMRBAUTOSIZE);
  267. case RBN_BEGINDRAG: return sizeof(NMREBAR);
  268. case RBN_DELETINGBAND: return sizeof(NMREBAR);
  269. case RBN_DELETEDBAND: return sizeof(NMREBAR);
  270. case RBN_CHILDSIZE: return sizeof(NMREBARCHILDSIZE);
  271. // IP address control notification
  272. case IPN_FIELDCHANGED: return sizeof(NMIPADDRESS);
  273. // Status bar notifications
  274. case SBN_SIMPLEMODECHANGE: return sizeof(NMHDR);
  275. // Pager control notifications
  276. case PGN_SCROLL: return sizeof(NMPGSCROLL);
  277. case PGN_CALCSIZE: return sizeof(NMPGCALCSIZE);
  278. default:
  279. break;
  280. }
  281. //
  282. // Categories of notifications we explicitly know nothing about.
  283. //
  284. if (code >= WMN_LAST && code <= WMN_FIRST) { // Internet Mail and News
  285. return 0;
  286. }
  287. if ((int)code >= 0) { // Application-specific notifications
  288. return 0;
  289. }
  290. //
  291. // IF THIS ASSERT FIRES, YOU MUST FIX IT OR YOU WILL BREAK WOW!
  292. //
  293. AssertMsg(0, TEXT("Notification code %d must be added to WOWGetNotifySize"));
  294. return 0;
  295. }
  296. #endif // NEED_WOWGETNOTIFYSIZE_HELPER
  297. LRESULT WINAPI SendNotifyEx(HWND hwndTo, HWND hwndFrom, int code, NMHDR FAR* pnmhdr, BOOL bUnicode)
  298. {
  299. CONTROLINFO ci;
  300. if (!hwndTo) {
  301. if (IsWindow(hwndFrom))
  302. hwndTo = GetParent(hwndFrom);
  303. if (!hwndTo)
  304. return 0;
  305. }
  306. ci.hwndParent = hwndTo;
  307. ci.hwnd = hwndFrom;
  308. ci.bUnicode = BOOLIFY(bUnicode);
  309. ci.uiCodePage = CP_ACP;
  310. return CCSendNotify(&ci, code, pnmhdr);
  311. }
  312. void StringBufferAtoW(UINT uiCodePage, LPVOID pvOrgPtr, DWORD dwOrgSize, CHAR **ppszText)
  313. {
  314. if (pvOrgPtr == *ppszText)
  315. {
  316. // the pointer has not been changed by the callback...
  317. // must convert from A to W in-place
  318. if (dwOrgSize)
  319. {
  320. LPWSTR pszW = ProduceWFromA(uiCodePage, *ppszText);
  321. if (pszW)
  322. {
  323. // this becomes a W buffer
  324. StringCchCopyW((WCHAR *)(*ppszText), dwOrgSize, pszW);
  325. FreeProducedString(pszW);
  326. }
  327. }
  328. }
  329. else
  330. {
  331. // the pointer has been changed out from underneath us, copy
  332. // unicode back into the original buffer.
  333. ConvertAToWN(uiCodePage, pvOrgPtr, dwOrgSize, *ppszText, -1);
  334. *ppszText = pvOrgPtr;
  335. }
  336. }
  337. typedef struct tagTHUNKSTATE {
  338. LPVOID ts_pvThunk1;
  339. LPVOID ts_pvThunk2;
  340. DWORD ts_dwThunkSize;
  341. } THUNKSTATE;
  342. //
  343. // InOutWtoA/InOutAtoW is for thunking INOUT string parameters.
  344. //
  345. // INOUT parameters always create a hassle.
  346. //
  347. // We need to save both the original ANSI and the
  348. // original UNICODE strings, so that if the app doesn't
  349. // change the ANSI string, we leave the original UNICODE
  350. // string alone. That way, UNICODE item names don't get
  351. // obliterated by the thunk.
  352. //
  353. // The original buffer is saved in pvThunk1.
  354. // We allocate two ANSI buffers.
  355. // pvThunk2 contains the original ANSIfied string.
  356. // pvThunk2+cchTextMax is the buffer we pass to the app.
  357. // On the way back, we compare pvThunk2 with pvThunk2+cchTextMax.
  358. // If they are different, then we unthunk the string; otherwise,
  359. // we leave the original UNICODE buffer alone.
  360. BOOL InOutWtoA(CONTROLINFO *pci, THUNKSTATE *pts, LPWSTR *ppsz, DWORD cchTextMax)
  361. {
  362. pts->ts_pvThunk1 = *ppsz; // Save original buffer
  363. pts->ts_dwThunkSize = cchTextMax;
  364. if (!IsFlagPtr(pts->ts_pvThunk1))
  365. {
  366. pts->ts_pvThunk2 = LocalAlloc(LPTR, cchTextMax * 2 * sizeof(char));
  367. if (!ConvertWToAN(pci->uiCodePage, (LPSTR)pts->ts_pvThunk2, pts->ts_dwThunkSize, (LPWSTR)pts->ts_pvThunk1, -1))
  368. {
  369. LocalFree(pts->ts_pvThunk2);
  370. return 0;
  371. }
  372. *ppsz = (LPWSTR)((LPSTR)pts->ts_pvThunk2 + cchTextMax);
  373. StringCchCopyA((LPSTR)*ppsz, pts->ts_dwThunkSize, pts->ts_pvThunk2);
  374. }
  375. return TRUE;
  376. }
  377. void InOutAtoW(CONTROLINFO *pci, THUNKSTATE *pts, LPSTR *ppsz)
  378. {
  379. if (!IsFlagPtr(pts->ts_pvThunk1))
  380. {
  381. if (!IsFlagPtr(*ppsz) &&
  382. lstrcmpA(pts->ts_pvThunk2, (LPSTR)*ppsz) != 0)
  383. StringBufferAtoW(pci->uiCodePage, pts->ts_pvThunk1, pts->ts_dwThunkSize, ppsz);
  384. LocalFree(pts->ts_pvThunk2);
  385. }
  386. *ppsz = pts->ts_pvThunk1;
  387. }
  388. LRESULT WINAPI CCSendNotify(CONTROLINFO * pci, int code, LPNMHDR pnmhdr)
  389. {
  390. NMHDR nmhdr;
  391. LONG_PTR id;
  392. THUNKSTATE ts = { 0 };
  393. #define pvThunk1 ts.ts_pvThunk1
  394. #define pvThunk2 ts.ts_pvThunk2
  395. #define dwThunkSize ts.ts_dwThunkSize
  396. LRESULT lRet;
  397. BOOL bSet = FALSE;
  398. HWND hwndParent = pci->hwndParent;
  399. DWORD dwParentPid;
  400. // -1 means Requery on each notify
  401. if ( hwndParent == (HWND)-1 )
  402. {
  403. hwndParent = GetParent(pci->hwnd);
  404. }
  405. // unlikely but it can technically happen -- avoid the rips
  406. if ( hwndParent == NULL )
  407. return 0;
  408. //
  409. // If pci->hwnd is -1, then a WM_NOTIFY is being forwared
  410. // from one control to a parent. EG: Tooltips sent
  411. // a WM_NOTIFY to toolbar, and toolbar is forwarding it
  412. // to the real parent window.
  413. //
  414. if (pci->hwnd != (HWND) -1) {
  415. //
  416. // If this is a child then get its ID. We need to go out of our way to
  417. // avoid calling GetDlgCtrlID on toplevel windows since it will return
  418. // a pseudo-random number (those of you who know what this number is
  419. // keep quiet). Anyway it's kinda hard to figure this out in Windows
  420. // because of the following:
  421. //
  422. // - a window can SetWindowLong(GWL_STYLE, WS_CHILD) but this only
  423. // does about half the work - hence checking the style is out.
  424. // - GetParent will return your OWNER if you are toplevel.
  425. // - there is no GetWindow(...GW_HWNDPARENT) to save us.
  426. //
  427. // Hence we are stuck with calling GetParent and then checking to see
  428. // if it lied and gave us the owner instead. Yuck.
  429. //
  430. id = 0;
  431. if (pci->hwnd) {
  432. HWND hwndParent = GetParent(pci->hwnd);
  433. if (hwndParent && (hwndParent != GetWindow(pci->hwnd, GW_OWNER))) {
  434. id = GetDlgCtrlID(pci->hwnd);
  435. }
  436. }
  437. if (!pnmhdr)
  438. pnmhdr = &nmhdr;
  439. pnmhdr->hwndFrom = pci->hwnd;
  440. pnmhdr->idFrom = id;
  441. pnmhdr->code = code;
  442. } else {
  443. id = pnmhdr->idFrom;
  444. code = pnmhdr->code;
  445. }
  446. // OLE in its massively componentized world sometimes creates
  447. // a control whose parent belongs to another process. (For example,
  448. // when there is a local server embedding.) WM_NOTIFY
  449. // messages can't cross process boundaries, so stop the message
  450. // from going there lest we fault the recipient.
  451. if (!GetWindowThreadProcessId(hwndParent, &dwParentPid) ||
  452. dwParentPid != GetCurrentProcessId())
  453. {
  454. TraceMsg(TF_WARNING, "nf: Not sending WM_NOTIFY %08x across processes", code);
  455. return 0;
  456. }
  457. #ifdef NEED_WOWGETNOTIFYSIZE_HELPER
  458. ASSERT(code >= 0 || WOWGetNotifySize(code));
  459. #endif // NEED_WOWGETNOTIFYSIZE_HELPER
  460. /*
  461. * All the thunking for Notify Messages happens here
  462. */
  463. if (!pci->bUnicode) {
  464. BOOL fThunked = TRUE;
  465. switch( code ) {
  466. case LVN_ODFINDITEMW:
  467. pnmhdr->code = LVN_ODFINDITEMA;
  468. goto ThunkLV_FINDINFO;
  469. case LVN_INCREMENTALSEARCHW:
  470. pnmhdr->code = LVN_INCREMENTALSEARCHA;
  471. goto ThunkLV_FINDINFO;
  472. ThunkLV_FINDINFO:
  473. {
  474. LV_FINDINFO *plvfi;
  475. // Hack Alert! This code assumes that all fields of LV_FINDINFOA and
  476. // LV_FINDINFOW are exactly the same except for the string pointers.
  477. COMPILETIME_ASSERT(sizeof(LV_FINDINFOA) == sizeof(LV_FINDINFOW));
  478. // Since WCHARs are bigger than char, we will just use the
  479. // wchar buffer to hold the chars, and not worry about the extra
  480. // room at the end.
  481. COMPILETIME_ASSERT(sizeof(WCHAR) >= sizeof(char));
  482. plvfi = &((PNM_FINDITEM)pnmhdr)->lvfi;
  483. if (plvfi->flags & (LVFI_STRING | LVFI_PARTIAL | LVFI_SUBSTRING))
  484. {
  485. pvThunk1 = (PVOID)plvfi->psz;
  486. dwThunkSize = lstrlen(pvThunk1) + 1;
  487. plvfi->psz = (LPWSTR)ProduceAFromW(pci->uiCodePage, plvfi->psz);
  488. }
  489. }
  490. break;
  491. case LVN_GETDISPINFOW: {
  492. LV_ITEMW *pitem;
  493. pnmhdr->code = LVN_GETDISPINFOA;
  494. // Hack Alert! This code assumes that all fields of LV_DISPINFOA and
  495. // LV_DISPINFOW are exactly the same except for the string pointers.
  496. COMPILETIME_ASSERT(sizeof(LV_DISPINFOA) == sizeof(LV_DISPINFOW));
  497. // Since WCHARs are bigger than char, we will just use the
  498. // wchar buffer to hold the chars, and not worry about the extra
  499. // room at the end.
  500. COMPILETIME_ASSERT(sizeof(WCHAR) >= sizeof(char));
  501. //
  502. // Some sleazebag code (shell32.dll) just changes the pszText
  503. // pointer to point to the name, so capture the original pointer
  504. // so we can detect this and not smash their data.
  505. //
  506. pitem = &(((LV_DISPINFOW *)pnmhdr)->item);
  507. if (!IsFlagPtr(pitem) && (pitem->mask & LVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  508. pvThunk1 = pitem->pszText;
  509. dwThunkSize = pitem->cchTextMax;
  510. }
  511. break;
  512. }
  513. // LVN_ENDLABELEDIT uses an INOUT parameter, never explicitly
  514. // documented as such, but it just happened to be that way,
  515. // and I don't want to take the chance that somebody was relying
  516. // on it.
  517. case LVN_ENDLABELEDITW:
  518. pnmhdr->code = LVN_ENDLABELEDITA;
  519. goto ThunkLV_DISPINFO;
  520. case LVN_BEGINLABELEDITW:
  521. pnmhdr->code = LVN_BEGINLABELEDITA;
  522. goto ThunkLV_DISPINFO;
  523. case LVN_SETDISPINFOW:
  524. pnmhdr->code = LVN_SETDISPINFOA;
  525. goto ThunkLV_DISPINFO;
  526. case LVN_GETEMPTYTEXTW:
  527. pnmhdr->code = LVN_GETEMPTYTEXTA;
  528. goto ThunkLV_DISPINFO;
  529. ThunkLV_DISPINFO: {
  530. LV_ITEMW *pitem;
  531. COMPILETIME_ASSERT(sizeof(LV_ITEMA) == sizeof(LV_ITEMW));
  532. pitem = &(((LV_DISPINFOW *)pnmhdr)->item);
  533. if (pitem->mask & LVIF_TEXT) {
  534. if (!InOutWtoA(pci, &ts, &pitem->pszText, pitem->cchTextMax))
  535. return 0;
  536. }
  537. break;
  538. }
  539. case LVN_GETINFOTIPW: {
  540. NMLVGETINFOTIPW *pgit = (NMLVGETINFOTIPW *)pnmhdr;
  541. COMPILETIME_ASSERT(sizeof(NMLVGETINFOTIPA) == sizeof(NMLVGETINFOTIPW));
  542. pnmhdr->code = LVN_GETINFOTIPA;
  543. if (!InOutWtoA(pci, &ts, &pgit->pszText, pgit->cchTextMax))
  544. return 0;
  545. }
  546. break;
  547. case TVN_GETINFOTIPW:
  548. {
  549. NMTVGETINFOTIPW *pgit = (NMTVGETINFOTIPW *)pnmhdr;
  550. pnmhdr->code = TVN_GETINFOTIPA;
  551. pvThunk1 = pgit->pszText;
  552. dwThunkSize = pgit->cchTextMax;
  553. }
  554. break;
  555. case TBN_GETINFOTIPW:
  556. {
  557. NMTBGETINFOTIPW *pgit = (NMTBGETINFOTIPW *)pnmhdr;
  558. pnmhdr->code = TBN_GETINFOTIPA;
  559. pvThunk1 = pgit->pszText;
  560. dwThunkSize = pgit->cchTextMax;
  561. }
  562. break;
  563. case TVN_SELCHANGINGW:
  564. pnmhdr->code = TVN_SELCHANGINGA;
  565. bSet = TRUE;
  566. // fall through
  567. case TVN_SELCHANGEDW:
  568. if (!bSet) {
  569. pnmhdr->code = TVN_SELCHANGEDA;
  570. bSet = TRUE;
  571. }
  572. /*
  573. * These msgs have a NM_TREEVIEW with both TV_ITEMs filled in
  574. *
  575. * FALL THROUGH TO TVN_DELETEITEM to thunk itemOld then go on for
  576. * the other structure.
  577. */
  578. // fall through
  579. case TVN_DELETEITEMW: {
  580. /*
  581. * This message has a NM_TREEVIEW in lParam with itemOld filled in
  582. */
  583. LPTV_ITEMW pitem;
  584. if (!bSet) {
  585. pnmhdr->code = TVN_DELETEITEMA;
  586. bSet = TRUE;
  587. }
  588. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemOld);
  589. // thunk itemOld
  590. if ( (pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  591. pvThunk2 = pitem->pszText;
  592. pitem->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk2);
  593. }
  594. // if this is deleteitem then we are done
  595. if (pnmhdr->code == TVN_DELETEITEMA)
  596. break;
  597. /* FALL THROUGH TO TVN_ITEMEXPANDING to thunk itemNew */
  598. }
  599. // fall through
  600. case TVN_ITEMEXPANDINGW:
  601. if (!bSet) {
  602. pnmhdr->code = TVN_ITEMEXPANDINGA;
  603. bSet = TRUE;
  604. }
  605. // fall through
  606. case TVN_ITEMEXPANDEDW:
  607. if (!bSet) {
  608. pnmhdr->code = TVN_ITEMEXPANDEDA;
  609. bSet = TRUE;
  610. }
  611. // fall through
  612. case TVN_BEGINDRAGW:
  613. if (!bSet) {
  614. pnmhdr->code = TVN_BEGINDRAGA;
  615. bSet = TRUE;
  616. }
  617. // fall through
  618. case TVN_BEGINRDRAGW: {
  619. /* these msgs have a NM_TREEVIEW with itemNew TV_ITEM filled in */
  620. LPTV_ITEMW pitem;
  621. if (!bSet) {
  622. pnmhdr->code = TVN_BEGINRDRAGA;
  623. }
  624. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemNew);
  625. if ( (pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  626. pvThunk1 = pitem->pszText;
  627. pitem->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk1);
  628. }
  629. break;
  630. }
  631. case TVN_SETDISPINFOW:
  632. pnmhdr->code = TVN_SETDISPINFOA;
  633. goto ThunkTV_DISPINFO;
  634. case TVN_BEGINLABELEDITW:
  635. pnmhdr->code = TVN_BEGINLABELEDITA;
  636. goto ThunkTV_DISPINFO;
  637. // TVN_ENDLABELEDIT uses an INOUT parameter, never explicitly
  638. // documented as such, but it just happened to be that way,
  639. // and I don't want to take the chance that somebody was relying
  640. // on it.
  641. case TVN_ENDLABELEDITW:
  642. pnmhdr->code = TVN_ENDLABELEDITA;
  643. goto ThunkTV_DISPINFO;
  644. ThunkTV_DISPINFO: {
  645. /*
  646. * All these messages have a TV_DISPINFO in lParam.
  647. */
  648. LPTV_ITEMW pitem;
  649. pitem = &(((TV_DISPINFOW *)pnmhdr)->item);
  650. if (pitem->mask & TVIF_TEXT) {
  651. if (!InOutWtoA(pci, &ts, &pitem->pszText, pitem->cchTextMax))
  652. return 0;
  653. }
  654. break;
  655. }
  656. case TVN_GETDISPINFOW: {
  657. /*
  658. * All these messages have a TV_DISPINFO in lParam.
  659. */
  660. LPTV_ITEMW pitem;
  661. pnmhdr->code = TVN_GETDISPINFOA;
  662. pitem = &(((TV_DISPINFOW *)pnmhdr)->item);
  663. if ((pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText) && pitem->cchTextMax) {
  664. pvThunk1 = pitem->pszText;
  665. dwThunkSize = pitem->cchTextMax;
  666. pvThunk2 = LocalAlloc(LPTR, pitem->cchTextMax * sizeof(char));
  667. pitem->pszText = pvThunk2;
  668. pitem->pszText[0] = TEXT('\0');
  669. }
  670. break;
  671. }
  672. case HDN_ITEMCHANGINGW:
  673. pnmhdr->code = HDN_ITEMCHANGINGA;
  674. bSet = TRUE;
  675. // fall through
  676. case HDN_ITEMCHANGEDW:
  677. if (!bSet) {
  678. pnmhdr->code = HDN_ITEMCHANGEDA;
  679. bSet = TRUE;
  680. }
  681. // fall through
  682. case HDN_ITEMCLICKW:
  683. if (!bSet) {
  684. pnmhdr->code = HDN_ITEMCLICKA;
  685. bSet = TRUE;
  686. }
  687. // fall through
  688. case HDN_ITEMDBLCLICKW:
  689. if (!bSet) {
  690. pnmhdr->code = HDN_ITEMDBLCLICKA;
  691. bSet = TRUE;
  692. }
  693. // fall through
  694. case HDN_DIVIDERDBLCLICKW:
  695. if (!bSet) {
  696. pnmhdr->code = HDN_DIVIDERDBLCLICKA;
  697. bSet = TRUE;
  698. }
  699. // fall through
  700. case HDN_BEGINTRACKW:
  701. if (!bSet) {
  702. pnmhdr->code = HDN_BEGINTRACKA;
  703. bSet = TRUE;
  704. }
  705. // fall through
  706. case HDN_ENDTRACKW:
  707. if (!bSet) {
  708. pnmhdr->code = HDN_ENDTRACKA;
  709. bSet = TRUE;
  710. }
  711. // fall through
  712. case HDN_TRACKW: {
  713. HD_ITEMW *pitem;
  714. if (!bSet) {
  715. pnmhdr->code = HDN_TRACKA;
  716. }
  717. pitem = ((HD_NOTIFY *)pnmhdr)->pitem;
  718. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_TEXT) && !IsFlagPtr(pitem->pszText)) {
  719. pvThunk1 = pitem->pszText;
  720. dwThunkSize = pitem->cchTextMax;
  721. pitem->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk1);
  722. }
  723. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_FILTER) && pitem->pvFilter )
  724. {
  725. if ( !(pitem->type & HDFT_HASNOVALUE) &&
  726. ((pitem->type & HDFT_ISMASK)==HDFT_ISSTRING) )
  727. {
  728. LPHD_TEXTFILTER ptextFilter = (LPHD_TEXTFILTER)pitem->pvFilter;
  729. pvThunk2 = ptextFilter->pszText;
  730. dwThunkSize = ptextFilter->cchTextMax;
  731. ptextFilter->pszText = (LPWSTR)ProduceAFromW(pci->uiCodePage, pvThunk2);
  732. }
  733. }
  734. break;
  735. }
  736. case CBEN_ENDEDITW:
  737. {
  738. LPNMCBEENDEDITW peew = (LPNMCBEENDEDITW) pnmhdr;
  739. LPNMCBEENDEDITA peea = LocalAlloc(LPTR, sizeof(NMCBEENDEDITA));
  740. if (!peea)
  741. return 0;
  742. peea->hdr = peew->hdr;
  743. peea->hdr.code = CBEN_ENDEDITA;
  744. peea->fChanged = peew->fChanged;
  745. peea->iNewSelection = peew->iNewSelection;
  746. peea->iWhy = peew->iWhy;
  747. ConvertWToAN(pci->uiCodePage, peea->szText, ARRAYSIZE(peea->szText),
  748. peew->szText, -1);
  749. pvThunk1 = pnmhdr;
  750. pnmhdr = &peea->hdr;
  751. ASSERT((LPVOID)pnmhdr == (LPVOID)peea);
  752. break;
  753. }
  754. case CBEN_DRAGBEGINW:
  755. {
  756. LPNMCBEDRAGBEGINW pdbw = (LPNMCBEDRAGBEGINW) pnmhdr;
  757. LPNMCBEDRAGBEGINA pdba = LocalAlloc(LPTR, sizeof(NMCBEDRAGBEGINA));
  758. if (!pdba)
  759. return 0;
  760. pdba->hdr = pdbw->hdr;
  761. pdba->hdr.code = CBEN_DRAGBEGINA;
  762. pdba->iItemid = pdbw->iItemid;
  763. ConvertWToAN(pci->uiCodePage, pdba->szText, ARRAYSIZE(pdba->szText),
  764. pdbw->szText, -1);
  765. pvThunk1 = pnmhdr;
  766. pnmhdr = &pdba->hdr;
  767. ASSERT((LPVOID)pnmhdr == (LPVOID)pdba);
  768. break;
  769. }
  770. case CBEN_GETDISPINFOW: {
  771. PNMCOMBOBOXEXW pnmcbe = (PNMCOMBOBOXEXW)pnmhdr;
  772. pnmhdr->code = CBEN_GETDISPINFOA;
  773. if (pnmcbe->ceItem.mask & CBEIF_TEXT
  774. && !IsFlagPtr(pnmcbe->ceItem.pszText) && pnmcbe->ceItem.cchTextMax) {
  775. pvThunk1 = pnmcbe->ceItem.pszText;
  776. dwThunkSize = pnmcbe->ceItem.cchTextMax;
  777. pvThunk2 = LocalAlloc(LPTR, pnmcbe->ceItem.cchTextMax * sizeof(char));
  778. pnmcbe->ceItem.pszText = pvThunk2;
  779. pnmcbe->ceItem.pszText[0] = TEXT('\0');
  780. }
  781. break;
  782. }
  783. case HDN_GETDISPINFOW: {
  784. LPNMHDDISPINFOW pHDDispInfoW;
  785. pnmhdr->code = HDN_GETDISPINFOA;
  786. pHDDispInfoW = (LPNMHDDISPINFOW) pnmhdr;
  787. pvThunk1 = pHDDispInfoW->pszText;
  788. dwThunkSize = pHDDispInfoW->cchTextMax;
  789. pHDDispInfoW->pszText = LocalAlloc (LPTR, pHDDispInfoW->cchTextMax * sizeof(char));
  790. if (!pHDDispInfoW->pszText) {
  791. pHDDispInfoW->pszText = (LPWSTR) pvThunk1;
  792. break;
  793. }
  794. WideCharToMultiByte(pci->uiCodePage, 0, (LPWSTR)pvThunk1, -1,
  795. (LPSTR)pHDDispInfoW->pszText, pHDDispInfoW->cchTextMax,
  796. NULL, NULL);
  797. break;
  798. }
  799. case TBN_GETBUTTONINFOW:
  800. {
  801. LPTBNOTIFYW pTBNW;
  802. pnmhdr->code = TBN_GETBUTTONINFOA;
  803. pTBNW = (LPTBNOTIFYW)pnmhdr;
  804. pvThunk1 = pTBNW->pszText;
  805. dwThunkSize = pTBNW->cchText;
  806. pvThunk2 = LocalAlloc (LPTR, pTBNW->cchText * sizeof(char));
  807. if (!pvThunk2) {
  808. break;
  809. }
  810. pTBNW->pszText = pvThunk2;
  811. WideCharToMultiByte(pci->uiCodePage, 0, (LPWSTR)pvThunk1, -1,
  812. (LPSTR)pTBNW->pszText, pTBNW->cchText,
  813. NULL, NULL);
  814. }
  815. break;
  816. case TTN_NEEDTEXTW:
  817. {
  818. LPTOOLTIPTEXTA lpTTTA;
  819. LPTOOLTIPTEXTW lpTTTW = (LPTOOLTIPTEXTW) pnmhdr;
  820. lpTTTA = LocalAlloc(LPTR, sizeof(TOOLTIPTEXTA));
  821. if (!lpTTTA)
  822. return 0;
  823. lpTTTA->hdr = lpTTTW->hdr;
  824. lpTTTA->hdr.code = TTN_NEEDTEXTA;
  825. lpTTTA->lpszText = lpTTTA->szText;
  826. lpTTTA->hinst = lpTTTW->hinst;
  827. lpTTTA->uFlags = lpTTTW->uFlags;
  828. lpTTTA->lParam = lpTTTW->lParam;
  829. WideCharToMultiByte(pci->uiCodePage, 0, lpTTTW->szText, -1, lpTTTA->szText, ARRAYSIZE(lpTTTA->szText), NULL, NULL);
  830. pvThunk1 = pnmhdr;
  831. pnmhdr = (NMHDR FAR *)lpTTTA;
  832. }
  833. break;
  834. case DTN_USERSTRINGW:
  835. {
  836. LPNMDATETIMESTRINGW lpDateTimeString = (LPNMDATETIMESTRINGW) pnmhdr;
  837. pnmhdr->code = DTN_USERSTRINGA;
  838. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeString->pszUserString);
  839. lpDateTimeString->pszUserString = (LPWSTR) pvThunk1;
  840. }
  841. break;
  842. case DTN_WMKEYDOWNW:
  843. {
  844. LPNMDATETIMEWMKEYDOWNW lpDateTimeWMKeyDown =
  845. (LPNMDATETIMEWMKEYDOWNW) pnmhdr;
  846. pnmhdr->code = DTN_WMKEYDOWNA;
  847. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeWMKeyDown->pszFormat);
  848. lpDateTimeWMKeyDown->pszFormat = (LPWSTR) pvThunk1;
  849. }
  850. break;
  851. case DTN_FORMATQUERYW:
  852. {
  853. LPNMDATETIMEFORMATQUERYW lpDateTimeFormatQuery =
  854. (LPNMDATETIMEFORMATQUERYW) pnmhdr;
  855. pnmhdr->code = DTN_FORMATQUERYA;
  856. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeFormatQuery->pszFormat);
  857. lpDateTimeFormatQuery->pszFormat = (LPWSTR) pvThunk1;
  858. }
  859. break;
  860. case DTN_FORMATW:
  861. {
  862. LPNMDATETIMEFORMATW lpDateTimeFormat =
  863. (LPNMDATETIMEFORMATW) pnmhdr;
  864. pnmhdr->code = DTN_FORMATA;
  865. pvThunk1 = ProduceAFromW(pci->uiCodePage, lpDateTimeFormat->pszFormat);
  866. lpDateTimeFormat->pszFormat = (LPWSTR) pvThunk1;
  867. }
  868. break;
  869. default:
  870. fThunked = FALSE;
  871. break;
  872. }
  873. #ifdef NEED_WOWGETNOTIFYSIZE_HELPER
  874. ASSERT(code >= 0 || WOWGetNotifySize(code));
  875. #endif // NEED_WOWGETNOTIFYSIZE_HELPER
  876. lRet = SendMessage(hwndParent, WM_NOTIFY, (WPARAM)id, (LPARAM)pnmhdr);
  877. /*
  878. * All the thunking for Notify Messages happens here
  879. */
  880. if (fThunked)
  881. {
  882. switch(pnmhdr->code) {
  883. case LVN_ODFINDITEMA:
  884. case LVN_INCREMENTALSEARCHA:
  885. {
  886. LV_FINDINFO *plvfi = &((PNM_FINDITEM)pnmhdr)->lvfi;
  887. if (pvThunk1)
  888. {
  889. FreeProducedString((LPWSTR)plvfi->psz);
  890. plvfi->psz = pvThunk1;
  891. }
  892. }
  893. break;
  894. case LVN_GETDISPINFOA:
  895. {
  896. LV_ITEMA *pitem = &(((LV_DISPINFOA *)pnmhdr)->item);
  897. // BUGBUG what if pointer is to large buffer?
  898. if (!IsFlagPtr(pitem) && (pitem->mask & LVIF_TEXT) && !IsFlagPtr(pitem->pszText))
  899. {
  900. StringBufferAtoW(pci->uiCodePage, pvThunk1, dwThunkSize, &pitem->pszText);
  901. }
  902. }
  903. break;
  904. case LVN_ENDLABELEDITA:
  905. case LVN_BEGINLABELEDITA:
  906. case LVN_SETDISPINFOA:
  907. case LVN_GETEMPTYTEXTA:
  908. {
  909. LV_ITEMA *pitem = &(((LV_DISPINFOA *)pnmhdr)->item);
  910. InOutAtoW(pci, &ts, &pitem->pszText);
  911. }
  912. break;
  913. case LVN_GETINFOTIPA:
  914. {
  915. NMLVGETINFOTIPA *pgit = (NMLVGETINFOTIPA *)pnmhdr;
  916. InOutAtoW(pci, &ts, &pgit->pszText);
  917. }
  918. break;
  919. case TVN_GETINFOTIPA:
  920. {
  921. NMTVGETINFOTIPA *pgit = (NMTVGETINFOTIPA *)pnmhdr;
  922. StringBufferAtoW(pci->uiCodePage, pvThunk1, dwThunkSize, &pgit->pszText);
  923. }
  924. break;
  925. case TBN_GETINFOTIPA:
  926. {
  927. NMTBGETINFOTIPA *pgit = (NMTBGETINFOTIPA *)pnmhdr;
  928. StringBufferAtoW(pci->uiCodePage, pvThunk1, dwThunkSize, &pgit->pszText);
  929. }
  930. break;
  931. case TVN_SELCHANGINGA:
  932. case TVN_SELCHANGEDA:
  933. case TVN_DELETEITEMA: {
  934. LPTV_ITEMW pitem;
  935. if ( !IsFlagPtr(pvThunk2) ) {
  936. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemOld);
  937. FreeProducedString(pitem->pszText);
  938. pitem->pszText = pvThunk2;
  939. }
  940. // if this is delitem, then we are done
  941. if (code == TVN_DELETEITEM)
  942. break;
  943. /* FALL THROUGH TO TVN_ITEMEXPANDING to unthunk itemNew */
  944. }
  945. // fall through
  946. case TVN_ITEMEXPANDINGA:
  947. case TVN_ITEMEXPANDEDA:
  948. case TVN_BEGINDRAGA:
  949. case TVN_BEGINRDRAGA: {
  950. /* these msgs have a NM_TREEVIEW with itemNew TV_ITEM filled in */
  951. LPTV_ITEMW pitem;
  952. if (!IsFlagPtr(pvThunk1)) {
  953. pitem = &(((LPNM_TREEVIEWW)pnmhdr)->itemNew);
  954. FreeProducedString(pitem->pszText);
  955. pitem->pszText = pvThunk1;
  956. }
  957. break;
  958. }
  959. case TVN_SETDISPINFOA:
  960. case TVN_BEGINLABELEDITA:
  961. case TVN_ENDLABELEDITA:
  962. {
  963. LPTV_ITEMA pitem;
  964. pitem = &(((TV_DISPINFOA *)pnmhdr)->item);
  965. InOutAtoW(pci, &ts, &pitem->pszText);
  966. }
  967. break;
  968. case TVN_GETDISPINFOA: {
  969. /*
  970. * This message has a TV_DISPINFO in lParam that wass filled in
  971. * during the callback and needs to be unthunked.
  972. */
  973. LPTV_ITEMW pitem;
  974. pitem = &(((TV_DISPINFOW *)pnmhdr)->item);
  975. if (!IsFlagPtr(pvThunk1) && (pitem->mask & TVIF_TEXT) && !IsFlagPtr(pitem->pszText)) {
  976. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)pitem->pszText, -1);
  977. pitem->pszText = pvThunk1;
  978. LocalFree(pvThunk2);
  979. }
  980. break;
  981. }
  982. case HDN_ITEMCHANGINGA:
  983. case HDN_ITEMCHANGEDA:
  984. case HDN_ITEMCLICKA:
  985. case HDN_ITEMDBLCLICKA:
  986. case HDN_DIVIDERDBLCLICKA:
  987. case HDN_BEGINTRACKA:
  988. case HDN_ENDTRACKA:
  989. case HDN_TRACKA: {
  990. HD_ITEMW *pitem;
  991. pitem = ((HD_NOTIFY *)pnmhdr)->pitem;
  992. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_TEXT) && !IsFlagPtr(pvThunk1)) {
  993. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pitem->pszText), -1);
  994. FreeProducedString(pitem->pszText);
  995. pitem->pszText = pvThunk1;
  996. }
  997. if ( !IsFlagPtr(pitem) && (pitem->mask & HDI_FILTER) && pitem->pvFilter && pvThunk2 )
  998. {
  999. if ( !(pitem->type & HDFT_HASNOVALUE) &&
  1000. ((pitem->type & HDFT_ISMASK)==HDFT_ISSTRING) )
  1001. {
  1002. LPHD_TEXTFILTER ptextFilter = (LPHD_TEXTFILTER)pitem->pvFilter;
  1003. ConvertAToWN(pci->uiCodePage, pvThunk2, dwThunkSize, (LPSTR)(ptextFilter->pszText), -1);
  1004. FreeProducedString(ptextFilter->pszText);
  1005. ptextFilter->pszText = pvThunk2;
  1006. }
  1007. }
  1008. break;
  1009. }
  1010. case CBEN_ENDEDITA:
  1011. {
  1012. LPNMCBEENDEDITW peew = (LPNMCBEENDEDITW) pvThunk1;
  1013. LPNMCBEENDEDITA peea = (LPNMCBEENDEDITA) pnmhdr;
  1014. // Don't unthunk the string since that destroys unicode round-trip
  1015. // and the client shouldn't be modifying it anyway.
  1016. // ConvertAToWN(pci->uiCodePage, peew->szText, ARRAYSIZE(peew->szText),
  1017. // peea->szText, -1);
  1018. LocalFree(peea);
  1019. }
  1020. break;
  1021. case CBEN_DRAGBEGINA:
  1022. {
  1023. LPNMCBEDRAGBEGINW pdbw = (LPNMCBEDRAGBEGINW) pvThunk1;
  1024. LPNMCBEDRAGBEGINA pdba = (LPNMCBEDRAGBEGINA) pnmhdr;
  1025. // Don't unthunk the string since that destroys unicode round-trip
  1026. // and the client shouldn't be modifying it anyway.
  1027. // ConvertAToWN(pci->uiCodePage, pdbw->szText, ARRAYSIZE(pdbw->szText),
  1028. // pdba->szText, -1);
  1029. LocalFree(pdba);
  1030. }
  1031. break;
  1032. case CBEN_GETDISPINFOA:
  1033. {
  1034. PNMCOMBOBOXEXW pnmcbeW;
  1035. pnmcbeW = (PNMCOMBOBOXEXW)pnmhdr;
  1036. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pnmcbeW->ceItem.pszText), -1);
  1037. if (pvThunk2)
  1038. LocalFree(pvThunk2);
  1039. pnmcbeW->ceItem.pszText = pvThunk1;
  1040. }
  1041. break;
  1042. case HDN_GETDISPINFOA:
  1043. {
  1044. LPNMHDDISPINFOW pHDDispInfoW;
  1045. pHDDispInfoW = (LPNMHDDISPINFOW)pnmhdr;
  1046. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pHDDispInfoW->pszText), -1);
  1047. LocalFree(pHDDispInfoW->pszText);
  1048. pHDDispInfoW->pszText = pvThunk1;
  1049. }
  1050. break;
  1051. case TBN_GETBUTTONINFOA:
  1052. {
  1053. LPTBNOTIFYW pTBNW;
  1054. pTBNW = (LPTBNOTIFYW)pnmhdr;
  1055. ConvertAToWN(pci->uiCodePage, pvThunk1, dwThunkSize, (LPSTR)(pTBNW->pszText), -1);
  1056. pTBNW->pszText = pvThunk1;
  1057. LocalFree(pvThunk2);
  1058. }
  1059. break;
  1060. case TTN_NEEDTEXTA:
  1061. {
  1062. LPTOOLTIPTEXTA lpTTTA = (LPTOOLTIPTEXTA) pnmhdr;
  1063. LPTOOLTIPTEXTW lpTTTW = (LPTOOLTIPTEXTW) pvThunk1;
  1064. ThunkToolTipTextAtoW (lpTTTA, lpTTTW, pci->uiCodePage);
  1065. LocalFree(lpTTTA);
  1066. }
  1067. break;
  1068. case DTN_USERSTRINGA:
  1069. case DTN_WMKEYDOWNA:
  1070. case DTN_FORMATQUERYA:
  1071. {
  1072. FreeProducedString (pvThunk1);
  1073. break;
  1074. }
  1075. case DTN_FORMATA:
  1076. {
  1077. LPNMDATETIMEFORMATA lpDateTimeFormat = (LPNMDATETIMEFORMATA) pnmhdr;
  1078. FreeProducedString (pvThunk1);
  1079. //
  1080. // pszDisplay and szDisplay are special cases.
  1081. //
  1082. if (lpDateTimeFormat->pszDisplay && *lpDateTimeFormat->pszDisplay)
  1083. {
  1084. //
  1085. // if pszDisplay still points at szDisplay then thunk
  1086. // in place. Otherwise allocate memory and copy the
  1087. // display string. This buffer will be freeded in monthcal.c
  1088. //
  1089. if (lpDateTimeFormat->pszDisplay == lpDateTimeFormat->szDisplay)
  1090. {
  1091. CHAR szDisplay[64];
  1092. StringCchCopyA(szDisplay, ARRAYSIZE(szDisplay), lpDateTimeFormat->szDisplay);
  1093. ConvertAToWN (pci->uiCodePage, (LPWSTR)lpDateTimeFormat->szDisplay, ARRAYSIZE(lpDateTimeFormat->szDisplay),
  1094. szDisplay, -1);
  1095. }
  1096. else
  1097. {
  1098. lpDateTimeFormat->pszDisplay =
  1099. (LPSTR) ProduceWFromA (pci->uiCodePage, lpDateTimeFormat->pszDisplay);
  1100. }
  1101. }
  1102. break;
  1103. }
  1104. default:
  1105. /* No thunking needed */
  1106. break;
  1107. }
  1108. }
  1109. return lRet;
  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 FAR* pnmhdr)
  1117. {
  1118. CONTROLINFO 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 NEAR PASCAL CICustomDrawNotify(LPCONTROLINFO 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(LPCONTROLINFO lpci, DWORD dwStage, LPNMCUSTOMDRAW lpnmcd)
  1157. {
  1158. DWORD dwRet = CDRF_DODEFAULT;
  1159. if (lpci->iVersion >= 5 && !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(CONTROLINFO * 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. }