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.

1246 lines
40 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * WUCLIP.C
  8. * WOW32 16-bit User API support
  9. *
  10. * History:
  11. * WOW Clipboard functionality designed and developed by ChandanC
  12. *
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. struct _CBFORMATS ClipboardFormats;
  17. DLLENTRYPOINTS OleStringConversion[WOW_OLESTRINGCONVERSION_COUNT] =
  18. {"ConvertObjDescriptor", NULL};
  19. UINT CFOLEObjectDescriptor;
  20. UINT CFOLELinkSrcDescriptor;
  21. MODNAME(wuclip.c);
  22. /*++
  23. BOOL ChangeClipboardChain(<hwnd>, <hwndNext>)
  24. HWND <hwnd>;
  25. HWND <hwndNext>;
  26. The %ChangeClipboardChain% function removes the window specified by the
  27. <hwnd> parameter from the chain of clipboard viewers and makes the window
  28. specified by the <hwndNext> parameter the descendant of the <hwnd>
  29. parameter's ancestor in the chain.
  30. <hwnd>
  31. Identifies the window that is to be removed from the chain. The handle
  32. must previously have been passed to the SetClipboardViewer function.
  33. <hwndNext>
  34. Identifies the window that follows <hwnd> in the clipboard-viewer
  35. chain (this is the handle returned by the %SetClipboardViewer% function,
  36. unless the sequence was changed in response to a WM_CHANGECBCHAIN
  37. message).
  38. The return value specifies the status of the <hwnd> window. It is TRUE if
  39. the window is found and removed. Otherwise, it is FALSE.
  40. --*/
  41. ULONG FASTCALL WU32ChangeClipboardChain(PVDMFRAME pFrame)
  42. {
  43. ULONG ul;
  44. register PCHANGECLIPBOARDCHAIN16 parg16;
  45. GETARGPTR(pFrame, sizeof(CHANGECLIPBOARDCHAIN16), parg16);
  46. ul = GETBOOL16(ChangeClipboardChain(
  47. HWND32(parg16->f1),
  48. HWND32(parg16->f2)
  49. ));
  50. FREEARGPTR(parg16);
  51. RETURN(ul);
  52. }
  53. /*++
  54. BOOL CloseClipboard(VOID)
  55. The %CloseClipboard% function closes the clipboard. The %CloseClipboard%
  56. function should be called when a window has finished examining or changing
  57. the clipboard. It lets other applications access the clipboard.
  58. This function has no parameters.
  59. The return value specifies whether the clipboard is closed. It is TRUE if
  60. the clipboard is closed. Otherwise, it is FALSE.
  61. --*/
  62. ULONG FASTCALL WU32CloseClipboard(PVDMFRAME pFrame)
  63. {
  64. ULONG ul;
  65. UNREFERENCED_PARAMETER(pFrame);
  66. ul = GETBOOL16(CloseClipboard());
  67. RETURN(ul);
  68. }
  69. /*++
  70. No REF header file
  71. --*/
  72. ULONG FASTCALL WU32CountClipboardFormats(PVDMFRAME pFrame)
  73. {
  74. ULONG ul;
  75. UNREFERENCED_PARAMETER(pFrame);
  76. ul = GETINT16(CountClipboardFormats());
  77. RETURN(ul);
  78. }
  79. /*++
  80. BOOL EmptyClipboard(VOID)
  81. The %EmptyClipboard% function empties the clipboard and frees handles to
  82. data in the clipboard. It then assigns ownership of the clipboard to the
  83. window that currently has the clipboard open.
  84. This function has no parameters.
  85. The return value specifies the status of the clipboard. It is TRUE if the
  86. clipboard is emptied. It is FALSE if an error occurs.
  87. The clipboard must be open when the %EmptyClipboard% function is called.
  88. --*/
  89. ULONG FASTCALL WU32EmptyClipboard(PVDMFRAME pFrame)
  90. {
  91. ULONG ul;
  92. UNREFERENCED_PARAMETER(pFrame);
  93. ul = GETBOOL16(EmptyClipboard());
  94. W32EmptyClipboard ();
  95. RETURN(ul);
  96. }
  97. /*++
  98. WORD EnumClipboardFormats(<wFormat>)
  99. WORD <wFormat>;
  100. The %EnumClipboardFormats% function enumerates the formats found in a list
  101. of available formats that belong to the clipboard. On each call to this
  102. function, the <wFormat> parameter specifies a known available format, and
  103. the function returns the format that appears next in the list. The first
  104. format in the list can be retrieved by setting <wFormat> to zero.
  105. <wFormat>
  106. Specifies a known format.
  107. The return value specifies the next known clipboard data format. It is zero
  108. if <wFormat> specifies the last format in the list of available formats. It
  109. is zero if the clipboard is not open.
  110. Before it enumerates the formats by using the %EnumClipboardFormats%
  111. function, an application must open the clipboard by using the
  112. %OpenClipboard% function.
  113. The order that an application uses for putting alternative formats for the
  114. same data into the clipboard is the same order that the enumerator uses when
  115. returning them to the pasting application. The pasting application should
  116. use the first format enumerated that it can handle. This gives the donor a
  117. chance to recommend formats that involve the least loss of data.
  118. --*/
  119. ULONG FASTCALL WU32EnumClipboardFormats(PVDMFRAME pFrame)
  120. {
  121. ULONG ul;
  122. register PENUMCLIPBOARDFORMATS16 parg16;
  123. GETARGPTR(pFrame, sizeof(ENUMCLIPBOARDFORMATS16), parg16);
  124. ul = GETWORD16(EnumClipboardFormats(
  125. WORD32(parg16->f1)
  126. ));
  127. FREEARGPTR(parg16);
  128. RETURN(ul);
  129. }
  130. /*++
  131. HANDLE GetClipboardData(<wFormat>)
  132. WORD <wFormat>;
  133. The %GetClipboardData% function retrieves data from the clipboard in the
  134. format given by the <wFormat> parameter. The clipboard must have been opened
  135. previously.
  136. <wFormat>
  137. Specifies a data format. For a description of the data formats, see the
  138. SetClipboardData function, later in this chapter.
  139. The return value identifies the memory block that contains the data from the
  140. clipboard. The handle type depends on the type of data specified by the
  141. <wFormat> parameter. It is NULL if there is an error.
  142. The available formats can be enumerated in advance by using the
  143. %EnumClipboardFormats% function.
  144. The data handle returned by %GetClipboardData% is controlled by the
  145. clipboard, not by the application. The application should copy the data
  146. immediately, instead of relying on the data handle for long-term use. The
  147. application should not free the data handle or leave it locked.
  148. Windows supports two formats for text, CF_TEXT and CF_OEMTEXT. CF_TEXT is
  149. the default Windows text clipboard format, while Windows uses the CF_OEMTEXT
  150. format for text in non-Windows applications. If you call %GetClipboardData%
  151. to retrieve data in one text format and the other text format is the only
  152. available text format, Windows automatically converts the text to the
  153. requested format before supplying it to your application.
  154. If the clipboard contains data in the CF_PALETTE (logical color palette)
  155. format, the application should assume that any other data in the clipboard
  156. is realized against that logical palette.
  157. --*/
  158. ULONG FASTCALL WU32GetClipboardData(PVDMFRAME pFrame)
  159. {
  160. ULONG ul = 0;
  161. HANDLE hMem32, hMeta32 = 0;
  162. HMEM16 hMem16=0, hMeta16 = 0;
  163. VPVOID vp;
  164. LPBYTE lpMem32;
  165. LPBYTE lpMem16;
  166. int cb;
  167. register PGETCLIPBOARDDATA16 parg16;
  168. GETARGPTR(pFrame, sizeof(GETCLIPBOARDDATA16), parg16);
  169. LOGDEBUG(6, ("WOW::WUICBGetClipboardData(): CF_FORMAT is %04x\n", parg16->f1));
  170. switch (parg16->f1) {
  171. // This is intentional to let it thru to the "case statements".
  172. // ChandanC 5/11/92.
  173. default:
  174. if ((parg16->f1 == CFOLEObjectDescriptor) || (parg16->f1 == CFOLELinkSrcDescriptor)) {
  175. hMem32 = GetClipboardData(WORD32(parg16->f1));
  176. if (hMem32) {
  177. hMem16 = (HMEM16) W32ConvertObjDescriptor(hMem32, CFOLE_UNICODE_TO_ANSI);
  178. }
  179. WU32ICBStoreHandle(parg16->f1, hMem16);
  180. break;
  181. }
  182. case CF_DIB:
  183. case CF_TEXT:
  184. case CF_DSPTEXT:
  185. case CF_SYLK:
  186. case CF_DIF:
  187. case CF_TIFF:
  188. case CF_OEMTEXT:
  189. case CF_PENDATA:
  190. case CF_RIFF:
  191. case CF_WAVE:
  192. case CF_OWNERDISPLAY:
  193. hMem16 = WU32ICBGetHandle(parg16->f1);
  194. if (!hMem16) {
  195. hMem32 = GetClipboardData(WORD32(parg16->f1));
  196. if (hMem16 = WU32ICBGetHandle(parg16->f1)) {
  197. //
  198. // We couldn't find the hMem16 using WU32ICBGetHandle
  199. // before we called Win32 GetClipboardData, but we can
  200. // now, so that means it was cut/copied from a task in
  201. // this WOW using delayed rendering, so that the actual
  202. // non-NULL hMem16 wasn't SetClipboardData until we
  203. // just called GetClipboardData. Since we now have
  204. // a valid cached copy of the data in 16-bit land,
  205. // we can just return that.
  206. //
  207. break;
  208. }
  209. lpMem32 = GlobalLock(hMem32);
  210. if (hMem32 && lpMem32) {
  211. cb = GlobalSize(hMem32);
  212. vp = GlobalAllocLock16(GMEM_MOVEABLE | GMEM_DDESHARE, cb, &hMem16);
  213. // 16-bit memory may have moved - refresh flat pointers
  214. FREEARGPTR(parg16);
  215. FREEVDMPTR(pFrame);
  216. GETFRAMEPTR(((PTD)CURRENTPTD())->vpStack, pFrame);
  217. GETARGPTR(pFrame, sizeof(GETCLIPBOARDDATA16), parg16);
  218. if (vp) {
  219. GETMISCPTR(vp, lpMem16);
  220. RtlCopyMemory(lpMem16, lpMem32, cb);
  221. GlobalUnlock16(hMem16);
  222. FLUSHVDMPTR(vp, cb, lpMem16);
  223. FREEMISCPTR(lpMem16);
  224. }
  225. GlobalUnlock(hMem32);
  226. }
  227. WU32ICBStoreHandle(parg16->f1, hMem16);
  228. }
  229. break;
  230. case CF_HDROP:
  231. // This is the case when app is retrieving cf_hdrop from the
  232. // clipboard, thus we will convert the dropfiles structure
  233. // from 32 to 16-bit one
  234. hMem16 = WU32ICBGetHandle(parg16->f1);
  235. if (!hMem16) {
  236. hMem32 = GetClipboardData(WORD32(parg16->f1));
  237. if (hMem32) {
  238. hMem16 = CopyDropFilesFrom32(hMem32);
  239. }
  240. WU32ICBStoreHandle(parg16->f1, hMem16);
  241. }
  242. break;
  243. case CF_DSPBITMAP:
  244. case CF_BITMAP:
  245. hMem16 = GETHBITMAP16(GetClipboardData(WORD32(parg16->f1)));
  246. break;
  247. case CF_PALETTE:
  248. hMem16 = GETHPALETTE16(GetClipboardData(WORD32(parg16->f1)));
  249. break;
  250. case CF_DSPMETAFILEPICT:
  251. case CF_METAFILEPICT:
  252. hMem16 = WU32ICBGetHandle(parg16->f1);
  253. if (!(hMem16)) {
  254. hMem32 = GetClipboardData(WORD32(parg16->f1));
  255. if (hMem16 = WU32ICBGetHandle(parg16->f1)) {
  256. //
  257. // We couldn't find the hMem16 using WU32ICBGetHandle
  258. // before we called Win32 GetClipboardData, but we can
  259. // now, so that means it was cut/copied from a task in
  260. // this WOW using delayed rendering, so that the actual
  261. // non-NULL hMem16 wasn't SetClipboardData until we
  262. // just called GetClipboardData. Since we now have
  263. // a valid cached copy of the data in 16-bit land,
  264. // we can just return that.
  265. //
  266. break;
  267. }
  268. lpMem32 = GlobalLock(hMem32);
  269. if (hMem32 && lpMem32) {
  270. vp = GlobalAllocLock16(GMEM_MOVEABLE | GMEM_DDESHARE, sizeof(METAFILEPICT16), &hMem16);
  271. // 16-bit memory may have moved - refresh flat pointers
  272. FREEARGPTR(parg16);
  273. FREEVDMPTR(pFrame);
  274. GETFRAMEPTR(((PTD)CURRENTPTD())->vpStack, pFrame);
  275. GETARGPTR(pFrame, sizeof(GETCLIPBOARDDATA16), parg16);
  276. if (vp) {
  277. GETMISCPTR(vp, lpMem16);
  278. FixMetafile32To16 ((LPMETAFILEPICT) lpMem32, (LPMETAFILEPICT16) lpMem16);
  279. FREEMISCPTR(lpMem16);
  280. hMeta32 = ((LPMETAFILEPICT) lpMem32)->hMF;
  281. if (hMeta32) {
  282. hMeta16 = WinMetaFileFromHMF(hMeta32, FALSE);
  283. // 16-bit memory may have moved
  284. FREEARGPTR(parg16);
  285. FREEVDMPTR(pFrame);
  286. GETFRAMEPTR(((PTD)CURRENTPTD())->vpStack, pFrame);
  287. GETARGPTR(pFrame,sizeof(GETCLIPBOARDDATA16),parg16);
  288. }
  289. GETMISCPTR(vp, lpMem16);
  290. STOREWORD(((LPMETAFILEPICT16) lpMem16)->hMF, hMeta16);
  291. GlobalUnlock16(hMem16);
  292. FLUSHVDMPTR(vp, sizeof(METAFILEPICT16), lpMem16);
  293. FREEMISCPTR(lpMem16);
  294. }
  295. GlobalUnlock(hMem32);
  296. }
  297. WU32ICBStoreHandle(parg16->f1, hMem16);
  298. }
  299. break;
  300. }
  301. ul = (ULONG) hMem16;
  302. FREEARGPTR(parg16);
  303. RETURN(ul);
  304. }
  305. /*++
  306. int GetClipboardFormatName(<wFormat>, <lpFormatName>, <nMaxCount>)
  307. WORD <wFormat>;
  308. LPSTR <lpFormatName>;
  309. int <nMaxCount>;
  310. The %GetClipboardFormatName% function retrieves from the clipboard the name
  311. of the registered format specified by the <wFormat> parameter. The name is
  312. copied to the buffer pointed to by the <lpFormatName> parameter.
  313. <wFormat>
  314. Specifies the type of format to be retrieved. It must not specify any of
  315. the predefined clipboard formats.
  316. <lpFormatName>
  317. Points to the buffer that is to receive the format name.
  318. <nMaxCount>
  319. Specifies the maximum length (in bytes) of the string to be copied
  320. to the buffer. If the actual name is longer, it is truncated.
  321. The return value specifies the actual length of the string copied to the
  322. buffer. It is zero if the requested format does not exist or is a predefined
  323. format.
  324. --*/
  325. ULONG FASTCALL WU32GetClipboardFormatName(PVDMFRAME pFrame)
  326. {
  327. ULONG ul;
  328. PSZ psz2 = NULL;
  329. register PGETCLIPBOARDFORMATNAME16 parg16;
  330. GETARGPTR(pFrame, sizeof(GETCLIPBOARDFORMATNAME16), parg16);
  331. ALLOCVDMPTR(parg16->f2, parg16->f3, psz2);
  332. ul = GETINT16(GetClipboardFormatName(
  333. WORD32(parg16->f1),
  334. psz2,
  335. INT32(parg16->f3)
  336. ));
  337. FLUSHVDMPTR(parg16->f2, strlen(psz2)+1, psz2);
  338. FREEVDMPTR(psz2);
  339. FREEARGPTR(parg16);
  340. RETURN(ul);
  341. }
  342. /*++
  343. HWND GetClipboardOwner(VOID)
  344. The %GetClipboardOwner% function retrieves the window handle of the current
  345. owner of the clipboard.
  346. This function has no parameters.
  347. The return value identifies the window that owns the clipboard. It is NULL
  348. if the clipboard is not owned.
  349. The clipboard can still contain data even if the clipboard is not currently
  350. owned.
  351. --*/
  352. ULONG FASTCALL WU32GetClipboardOwner(PVDMFRAME pFrame)
  353. {
  354. ULONG ul;
  355. UNREFERENCED_PARAMETER(pFrame);
  356. ul = GETHWND16(GetClipboardOwner());
  357. RETURN(ul);
  358. }
  359. /*++
  360. HWND GetClipboardViewer(VOID)
  361. The %GetClipboardViewer% function retrieves the window handle of the first
  362. window in the clipboard-viewer chain.
  363. This function has no parameters.
  364. The return value identifies the window currently responsible for displaying
  365. the clipboard. It is NULL if there is no viewer.
  366. --*/
  367. ULONG FASTCALL WU32GetClipboardViewer(PVDMFRAME pFrame)
  368. {
  369. ULONG ul;
  370. UNREFERENCED_PARAMETER(pFrame);
  371. ul = GETHWND16(GetClipboardViewer());
  372. RETURN(ul);
  373. }
  374. /*++
  375. int GetPriorityClipboardFormat(<lpPriorityList>, <cEntries>)
  376. LPWORD <lpPriorityList>;
  377. int <cEntries>;
  378. The %GetPriorityClipboardFormat% function returns the first clipboard format
  379. in a list for which data exist in the clipboard.
  380. <lpPriorityList>
  381. Points to an integer array that contains a list of clipboard formats in
  382. priority order. For a description of the data formats, see the
  383. SetClipboardData function later in this chapter.
  384. <cEntries>
  385. Specifies the number of entries in <lpPriorityList>. This value
  386. must not be greater than the actual number of entries in the list.
  387. The return value is the highest priority clipboard format in the list for
  388. which data exist. If no data exist in the clipboard, this function returns
  389. NULL. If data exist in the clipboard which did not match any format in the
  390. list, the return value is -1.
  391. --*/
  392. ULONG FASTCALL WU32GetPriorityClipboardFormat(PVDMFRAME pFrame)
  393. {
  394. ULONG ul;
  395. UINT *pu1;
  396. register PGETPRIORITYCLIPBOARDFORMAT16 parg16;
  397. INT BufferT[256]; // comfortably large array
  398. GETARGPTR(pFrame, sizeof(GETPRIORITYCLIPBOARDFORMAT16), parg16);
  399. pu1 = STACKORHEAPALLOC(parg16->f2 * sizeof(INT), sizeof(BufferT), BufferT);
  400. getuintarray16(parg16->f1, parg16->f2, pu1);
  401. if (pu1) {
  402. ul = GETINT16(GetPriorityClipboardFormat(
  403. pu1,
  404. INT32(parg16->f2)
  405. ));
  406. } else {
  407. ul = (ULONG)-1;
  408. }
  409. STACKORHEAPFREE(pu1, BufferT);
  410. FREEARGPTR(parg16);
  411. RETURN(ul);
  412. }
  413. /*++
  414. BOOL IsClipboardFormatAvailable(<wFormat>)
  415. WORD <wFormat>;
  416. The %IsClipboardFormatAvailable% function specifies whether data of a
  417. certain type exist in the clipboard.
  418. <wFormat>
  419. Specifies a registered clipboard format. For information on clipboard
  420. formats, see the description of the SetClipboardData function, later in
  421. this chapter.
  422. The return value specifies the outcome of the function. It is TRUE if data
  423. having the specified format are present. Otherwise, it is FALSE.
  424. This function is typically called during processing of the WM_INITMENU or
  425. WM_INITMENUPOPUP message to determine whether the clipboard contains data
  426. that the application can paste. If such data are present, the application
  427. typically enables the Paste command (in its Edit menu).
  428. --*/
  429. ULONG FASTCALL WU32IsClipboardFormatAvailable(PVDMFRAME pFrame)
  430. {
  431. ULONG ul;
  432. register PISCLIPBOARDFORMATAVAILABLE16 parg16;
  433. GETARGPTR(pFrame, sizeof(ISCLIPBOARDFORMATAVAILABLE16), parg16);
  434. // Hack-a-roo! PhotoShop 2.5 has a bug in its code for handling large DIB's
  435. // on the clipboard and will fault if it encounters one. On WFW, it usually
  436. // won't encounter one because most apps (in this case alt-Prtscrn button)
  437. // copy BITMAPS, not DIBS, to the clipboard. On NT, anytime an app writes
  438. // a BITMAP to the clipboard it gets converted to a DIB & vice versa-making
  439. // more clipboard data formats available to inquiring apps. Unfortunately,
  440. // Photoshop checks for DIBS before BITMAPS and finds one on Win
  441. // Versions >= 4.0. a-craigj
  442. // if this is a DIB check && the app is PhotoShop...
  443. if((WORD32(parg16->f1) == CF_DIB) &&
  444. (CURRENTPTD()->dwWOWCompatFlagsEx & WOWCFEX_NODIBSHERE)) {
  445. // ...see if there is a bitmap format available too
  446. if(IsClipboardFormatAvailable(CF_BITMAP)) {
  447. // if so return FALSE which will cause Photoshop to ask for a
  448. // BITMAP format next
  449. ul = FALSE;
  450. }
  451. // otherwise we'll check for a DIB anyway & hope it's a small one
  452. else {
  453. ul = GETBOOL16(IsClipboardFormatAvailable(CF_DIB));
  454. }
  455. }
  456. // no hack path
  457. else {
  458. ul = GETBOOL16(IsClipboardFormatAvailable(WORD32(parg16->f1)));
  459. }
  460. FREEARGPTR(parg16);
  461. RETURN(ul);
  462. }
  463. /*++
  464. BOOL OpenClipboard(<hwnd>)
  465. HWND <hwnd>;
  466. The %OpenClipboard% function opens the clipboard. Other applications will
  467. not be able to modify the clipboard until the %CloseClipboard% function is
  468. called.
  469. <hwnd>
  470. Identifies the window to be associated with the open clipboard.
  471. The return value is TRUE if the clipboard is opened, or FALSE if another
  472. application or window has the clipboard opened.
  473. The window specified by the <hwnd> parameter will not become the owner of
  474. the clipboard until the %EmptyCLipboard% function is called.
  475. --*/
  476. ULONG FASTCALL WU32OpenClipboard(PVDMFRAME pFrame)
  477. {
  478. ULONG ul;
  479. register POPENCLIPBOARD16 parg16;
  480. GETARGPTR(pFrame, sizeof(OPENCLIPBOARD16), parg16);
  481. ul = GETBOOL16(OpenClipboard(
  482. HWND32(parg16->f1)
  483. ));
  484. FREEARGPTR(parg16);
  485. RETURN(ul);
  486. }
  487. /*++
  488. WORD RegisterClipboardFormat(<lpFormatName>)
  489. LPSTR <lpFormatName>;
  490. The %RegisterClipboardFormat% function registers a new clipboard format
  491. whose name is pointed to by the <lpFormatName> parameter. The registered
  492. format can be used in subsequent clipboard functions as a valid format in
  493. which to render data, and it will appear in the clipboard's list of
  494. formats.
  495. <lpFormatName>
  496. Points to a character string that names the new format. The string must
  497. be a null-terminated string.
  498. The return value specifies the newly registered format. If the identical
  499. format name has been registered before, even by a different application, the
  500. format's reference count is increased and the same value is returned as when
  501. the format was originally registered. The return value is zero if the format
  502. cannot be registered.
  503. The format value returned by the %RegisterClipboardFormat% function is
  504. within the range of 0xC000 to 0xFFFF.
  505. --*/
  506. ULONG FASTCALL WU32RegisterClipboardFormat(PVDMFRAME pFrame)
  507. {
  508. ULONG ul;
  509. PSZ psz1;
  510. register PREGISTERCLIPBOARDFORMAT16 parg16;
  511. GETARGPTR(pFrame, sizeof(REGISTERCLIPBOARDFORMAT16), parg16);
  512. GETPSZPTR(parg16->f1, psz1);
  513. ul = GETWORD16(RegisterClipboardFormat(
  514. psz1
  515. ));
  516. FREEPSZPTR(psz1);
  517. FREEARGPTR(parg16);
  518. RETURN(ul);
  519. }
  520. /*++
  521. HANDLE SetClipboardData(<wFormat>, <hData>)
  522. WORD <wFormat>;
  523. HANDLE <hData>;
  524. The %SetClipboardData% function sets the data in the clipboard. The
  525. application must have called the %OpenClipboard% function before calling
  526. the %SetClipboardData% function.
  527. <wFormat>
  528. Specifies the format of the data. It can be any one of the
  529. system-defined formats, or a format registered by the
  530. %RegisterClipboardFormat% function. For a list of system-defined
  531. formats,
  532. <hData>
  533. Identifies the data to be placed into the clipboard. For all formats
  534. except CF_BITMAP and CF_PALETTE, this parameter must be a handle to
  535. memory allocated by the %GlobalAlloc% function. For CF_BITMAP format,
  536. the <hData> parameter is a handle to a bitmap (see %LoadBitmap%). For
  537. CF_PALETTE format, the <hData> parameter is a handle to a palette (see
  538. %CreatePalette%).
  539. If this parameter is NULL, the owner of the clipboard will be sent a
  540. WM_RENDERFORMAT message when it needs to supply the data.
  541. The return value is a handle to the data if the function is succesful, or
  542. NULL if an error occurred.
  543. If the <hData> parameter contains a handle to memory allocated by the
  544. %GlobalAlloc% function, the application must not use this handle once it
  545. has called the %SetClipboardData% function.
  546. The following list contains the system-defined clipboard formats:
  547. CF_BITMAP
  548. The data is a bitmap.
  549. CF_DIB
  550. The data is a memory block containing a %BITMAPINFO% structure followed
  551. by the bitmap data.
  552. CF_DIF
  553. The data is in Software Arts' Data Interchange Format.
  554. CF_DSPBITMAP
  555. The data is a bitmap representation of a private format. This data is
  556. displayed in bitmap format in lieu of the privately formatted data.
  557. CF_DSPMETAFILEPICT
  558. The data is a metafile representation of a private data format. This
  559. data is displayed in metafile-picture format in lieu of the privately
  560. formatted data.
  561. CF_DSPTEXT
  562. The data is a textual representation of a private data format. This data
  563. is displayed in text format in lieu of the privately formatted data.
  564. CF_METAFILEPICT
  565. The data is a metafile (see description of the %METAFILEPICT%
  566. structure).
  567. CF_OEMTEXT
  568. The data is an array of text characters in the OEM character set. Each
  569. line ends with a carriage return/linefeed (CR-LF) combination. A null
  570. character signals the end of the data.
  571. CF_OWNERDISPLAY
  572. The data is in a private format that the clipboard owner must display.
  573. CF_PALETTE
  574. The data is a color palette.
  575. CF_SYLK
  576. The data is in Microsoft Symbolic Link (SYLK) format.
  577. CF_TEXT
  578. The data is an array of text characters. Each line ends with a carriage
  579. return/linefeed (CR-LF) combination. A null character signals the end of
  580. the data.
  581. CF_TIFF
  582. The data is in Tag Image File Format.
  583. Private data formats in the range of CF_PRIVATEFIRST to CF_PRIVATELAST are
  584. not automatically freed when the data is deleted from the clipboard. Data
  585. handles associated with these formats should be freed upon receiving a
  586. WM_DESTROYCLIPBOARD message.
  587. Private data formats in the range of CF_GDIOBJFIRST to CF_GDIOBJLAST will
  588. be automatically deleted with a call to %DeleteObject% when the data is
  589. deleted from the clipboard.
  590. If the Windows clipboard application is running, it will not update its
  591. window to show the data placed in the clipboard by the %SetClipboardData%
  592. until after the %CloseClipboard% function is called.
  593. 31-Oct-1990 [ralphw] Miscelanious material, needs to be moved to other
  594. function descriptions/overviews.
  595. Whenever an application places data in the clipboard that depends on or
  596. assumes a color palette, it should also place the palette in the
  597. clipboard as well.
  598. If the clipboard contains data in the CF_PALETTE (logical color palette)
  599. format, the application should assume that any other data in the
  600. clipboard is realized against that logical palette.
  601. The clipboard-viewer application (CLIPBRD.EXE) always uses as its
  602. current palette any object in CF_PALETTE format that is in the clipboard
  603. when it displays the other formats in the clipboard.
  604. Windows supports two formats for text, CF_TEXT and CF_OEMTEXT. CF_TEXT
  605. is the default Windows text clipboard format, while Windows uses the
  606. CF_OEMTEXT format for text in non-Windows applications. If you call
  607. %GetClipboardData% to retrieve data in one text format and the other
  608. text format is the only available text format, Windows automatically
  609. converts the text to the requested format before supplying it to your
  610. application.
  611. An application registers other standard formats, such as Rich Text
  612. Format (RTF), by name using the %RegisterClipboardFormat% function
  613. rather than by a symbolic constant. For information on these external
  614. formats, see the README.TXT file.
  615. --*/
  616. ULONG FASTCALL WU32SetClipboardData(PVDMFRAME pFrame)
  617. {
  618. ULONG ul = 0;
  619. HANDLE hMem32 = NULL, hMF32 = NULL;
  620. HAND16 hMem16, hMeta16 = 0;
  621. LPBYTE lpMem16, lpMem32;
  622. INT cb;
  623. VPVOID vp;
  624. register PSETCLIPBOARDDATA16 parg16;
  625. GETARGPTR(pFrame, sizeof(SETCLIPBOARDDATA16), parg16);
  626. LOGDEBUG(6, ("WOW::WUICBSetClipboardData(): CF_FORMAT is %04x\n", parg16->f1));
  627. switch (parg16->f1) {
  628. default:
  629. if ((parg16->f1 == CFOLEObjectDescriptor) || (parg16->f1 == CFOLELinkSrcDescriptor)) {
  630. if (parg16->f2) {
  631. hMem32 = W32ConvertObjDescriptor((HANDLE) parg16->f2, CFOLE_ANSI_TO_UNICODE);
  632. }
  633. ul = (ULONG) SetClipboardData(WORD32(parg16->f1), hMem32);
  634. WU32ICBStoreHandle(parg16->f1, parg16->f2);
  635. break;
  636. }
  637. // It is intentional to let it thru to the "case statements".
  638. // ChandanC 5/11/92.
  639. case CF_DIB:
  640. case CF_TEXT:
  641. case CF_DSPTEXT:
  642. case CF_SYLK:
  643. case CF_DIF:
  644. case CF_TIFF:
  645. case CF_OEMTEXT:
  646. case CF_PENDATA:
  647. case CF_RIFF:
  648. case CF_WAVE:
  649. case CF_OWNERDISPLAY:
  650. hMem16 = parg16->f2;
  651. if (hMem16) {
  652. vp = GlobalLock16(hMem16, &cb);
  653. if (vp) {
  654. GETMISCPTR(vp, lpMem16);
  655. hMem32 = Copyh16Toh32 (cb, lpMem16);
  656. GlobalUnlock16(hMem16);
  657. FREEMISCPTR(lpMem16);
  658. }
  659. }
  660. ul = (ULONG) SetClipboardData(WORD32(parg16->f1), hMem32);
  661. WU32ICBStoreHandle(parg16->f1, hMem16);
  662. break;
  663. case CF_HDROP:
  664. // support cf_hdrop format by converting the dropfiles structure
  665. hMem16 = parg16->f2;
  666. if (hMem16) {
  667. hMem32 = CopyDropFilesFrom16(hMem16);
  668. }
  669. ul = (ULONG)SetClipboardData(WORD32(parg16->f1), hMem32);
  670. WU32ICBStoreHandle(parg16->f1, hMem16);
  671. break;
  672. case CF_DSPBITMAP:
  673. case CF_BITMAP:
  674. ul = (ULONG) SetClipboardData(WORD32(parg16->f1),
  675. HBITMAP32(parg16->f2));
  676. break;
  677. case CF_PALETTE:
  678. ul = (ULONG) SetClipboardData(WORD32(parg16->f1),
  679. HPALETTE32(parg16->f2));
  680. break;
  681. case CF_DSPMETAFILEPICT:
  682. case CF_METAFILEPICT:
  683. hMem16 = parg16->f2;
  684. if (hMem16) {
  685. vp = GlobalLock16(hMem16, &cb);
  686. if (vp) {
  687. GETMISCPTR(vp, lpMem16);
  688. hMem32 = WOWGLOBALALLOC(GMEM_DDESHARE,sizeof(METAFILEPICT));
  689. WOW32ASSERT(hMem32);
  690. lpMem32 = GlobalLock(hMem32);
  691. if (hMem32 && lpMem32) {
  692. ((LPMETAFILEPICT) lpMem32)->mm = FETCHSHORT(((LPMETAFILEPICT16) lpMem16)->mm);
  693. ((LPMETAFILEPICT) lpMem32)->xExt = (LONG) FETCHSHORT(((LPMETAFILEPICT16) lpMem16)->xExt);
  694. ((LPMETAFILEPICT) lpMem32)->yExt = (LONG) FETCHSHORT(((LPMETAFILEPICT16) lpMem16)->yExt);
  695. hMeta16 = FETCHWORD(((LPMETAFILEPICT16) lpMem16)->hMF);
  696. if (hMeta16) {
  697. hMF32 = (HMETAFILE) HMFFromWinMetaFile(hMeta16, FALSE);
  698. }
  699. ((LPMETAFILEPICT) lpMem32)->hMF = hMF32;
  700. GlobalUnlock(hMem32);
  701. }
  702. GlobalUnlock16(hMem16);
  703. FREEMISCPTR(lpMem16);
  704. }
  705. }
  706. ul = (ULONG) SetClipboardData(WORD32(parg16->f1), hMem32);
  707. WU32ICBStoreHandle(parg16->f1, hMem16);
  708. break;
  709. }
  710. if (parg16->f2) {
  711. ul = parg16->f2;
  712. }
  713. FREEARGPTR(parg16);
  714. RETURN(ul);
  715. }
  716. /*++
  717. HWND SetClipboardViewer(<hwnd>)
  718. HWND <hwnd>;
  719. The %SetClipboardViewer% function adds the window specified by the <hwnd>
  720. parameter to the chain of windows that are notified (via the
  721. WM_DRAWCLIPBOARD message) whenever the contents of the clipboard are
  722. changed.
  723. <hwnd>
  724. Identifies the window to receive clipboard-viewer chain messages.
  725. The return value identifies the next window in the clipboard-viewer chain.
  726. This handle should be saved in static memory and used in responding to
  727. clipboard-viewer chain messages.
  728. Windows that are part of the clipboard-viewer chain must respond to
  729. WM_CHANGECBCHAIN, WM_DRAWCLIPBOARD, and WM_DESTROY messages.
  730. If an application wishes to remove itself from the clipboard-viewer chain,
  731. it must call the %ChangeClipboardChain% function.
  732. --*/
  733. ULONG FASTCALL WU32SetClipboardViewer(PVDMFRAME pFrame)
  734. {
  735. ULONG ul;
  736. register PSETCLIPBOARDVIEWER16 parg16;
  737. GETARGPTR(pFrame, sizeof(SETCLIPBOARDVIEWER16), parg16);
  738. ul = GETHWND16(SetClipboardViewer(HWND32(parg16->f1)));
  739. FREEARGPTR(parg16);
  740. RETURN(ul);
  741. }
  742. VOID WU32ICBStoreHandle(WORD wFormat, HMEM16 hMem16)
  743. {
  744. HAND16 h16, hMeta16;
  745. PCBNODE Temp, Temp1;
  746. LPBYTE lpMem16;
  747. VPVOID vp;
  748. int cb;
  749. if ((wFormat == CF_METAFILEPICT) || (wFormat == CF_DSPMETAFILEPICT)) {
  750. if (wFormat == CF_METAFILEPICT) {
  751. h16 = ClipboardFormats.Pre1[wFormat];
  752. }
  753. else {
  754. h16 = ClipboardFormats.Pre2[3];
  755. }
  756. if (h16) {
  757. vp = GlobalLock16(h16, &cb);
  758. if (vp) {
  759. GETMISCPTR(vp, lpMem16);
  760. hMeta16 = FETCHWORD(((LPMETAFILEPICT16) lpMem16)->hMF);
  761. GlobalUnlockFree16(GlobalLock16(hMeta16, NULL));
  762. }
  763. GlobalUnlockFree16(vp);
  764. if (wFormat == CF_METAFILEPICT) {
  765. ClipboardFormats.Pre1[wFormat] = 0;
  766. }
  767. else {
  768. ClipboardFormats.Pre2[3] = 0;
  769. }
  770. }
  771. }
  772. if ((wFormat >= CF_TEXT ) && (wFormat <= CF_WAVE)) {
  773. if (ClipboardFormats.Pre1[wFormat]) {
  774. GlobalUnlockFree16(GlobalLock16(ClipboardFormats.Pre1[wFormat], NULL));
  775. }
  776. ClipboardFormats.Pre1[wFormat] = hMem16;
  777. }
  778. else if ((wFormat >= CF_OWNERDISPLAY) && (wFormat <= CF_DSPMETAFILEPICT)) {
  779. wFormat = (wFormat & (WORD) 3);
  780. if (ClipboardFormats.Pre2[wFormat]) {
  781. GlobalUnlockFree16(GlobalLock16(ClipboardFormats.Pre2[wFormat], NULL));
  782. }
  783. ClipboardFormats.Pre2[wFormat] = hMem16;
  784. }
  785. else if (wFormat == CF_HDROP) {
  786. if (ClipboardFormats.hmem16Drop) {
  787. GlobalUnlockFree16(GlobalLock16(ClipboardFormats.hmem16Drop, NULL));
  788. }
  789. ClipboardFormats.hmem16Drop = hMem16;
  790. }
  791. else {
  792. Temp = ClipboardFormats.NewFormats;
  793. if (Temp) {
  794. while ((Temp->Next) && (Temp->Id != wFormat)) {
  795. Temp = Temp->Next;
  796. }
  797. if (Temp->Id == wFormat) {
  798. // free a previous handle if it exists
  799. if (Temp->hMem16) {
  800. GlobalUnlockFree16(GlobalLock16(Temp->hMem16, NULL));
  801. }
  802. Temp->hMem16 = hMem16;
  803. }
  804. else {
  805. Temp1 = (PCBNODE) malloc_w (sizeof(CBNODE));
  806. if (Temp1) {
  807. Temp->Next = Temp1;
  808. Temp1->Id = wFormat;
  809. Temp1->hMem16 = hMem16;
  810. Temp1->Next = NULL;
  811. LOGDEBUG(6,("WOW::WU32ICBStoreHandle: Adding a new node for private clipboard data format %04lx\n", wFormat));
  812. }
  813. }
  814. }
  815. else {
  816. Temp = (PCBNODE) malloc_w (sizeof(CBNODE));
  817. if (Temp) {
  818. ClipboardFormats.NewFormats = Temp;
  819. Temp->Id = wFormat;
  820. Temp->hMem16 = hMem16;
  821. Temp->Next = NULL;
  822. LOGDEBUG(6,("WOW::WU32ICBStoreHandle: Adding the FIRST node for private clipboard data format %04lx\n", wFormat));
  823. }
  824. }
  825. }
  826. }
  827. HMEM16 WU32ICBGetHandle(WORD wFormat)
  828. {
  829. HMEM16 hMem16 = 0;
  830. PCBNODE Temp;
  831. if ((wFormat >= CF_TEXT) && (wFormat <= CF_WAVE)) {
  832. hMem16 = ClipboardFormats.Pre1[wFormat];
  833. }
  834. else if ((wFormat >= CF_OWNERDISPLAY) && (wFormat <= CF_DSPMETAFILEPICT)) {
  835. wFormat = (wFormat & (WORD) 3);
  836. hMem16 = ClipboardFormats.Pre2[wFormat];
  837. }
  838. else if (wFormat == CF_HDROP) {
  839. hMem16 = ClipboardFormats.hmem16Drop;
  840. }
  841. else {
  842. Temp = ClipboardFormats.NewFormats;
  843. if (Temp) {
  844. while ((Temp->Next) && (Temp->Id != wFormat)) {
  845. Temp = Temp->Next;
  846. }
  847. if (Temp->Id == wFormat) {
  848. hMem16 = Temp->hMem16;
  849. }
  850. else {
  851. LOGDEBUG(6,("WOW::WU32ICBGetHandle: Cann't find private clipboard data format %04lx\n", wFormat));
  852. hMem16 = (WORD) NULL;
  853. }
  854. }
  855. }
  856. return (hMem16);
  857. }
  858. VOID W32EmptyClipboard ()
  859. {
  860. PCBNODE Temp, Temp1;
  861. int wFormat, cb;
  862. HAND16 hMem16, hMeta16;
  863. LPBYTE lpMem16;
  864. VPVOID vp;
  865. // Empty CF_METAFILEPICT
  866. hMem16 = ClipboardFormats.Pre1[CF_METAFILEPICT];
  867. if (hMem16) {
  868. vp = GlobalLock16(hMem16, &cb);
  869. if (vp) {
  870. GETMISCPTR(vp, lpMem16);
  871. hMeta16 = FETCHWORD(((LPMETAFILEPICT16) lpMem16)->hMF);
  872. GlobalUnlockFree16(GlobalLock16(hMeta16, NULL));
  873. }
  874. GlobalUnlockFree16(vp);
  875. ClipboardFormats.Pre1[CF_METAFILEPICT] = 0;
  876. }
  877. // Empty CF_DSPMETAFILEPICT
  878. hMem16 = ClipboardFormats.Pre2[3];
  879. if (hMem16) {
  880. vp = GlobalLock16(hMem16, &cb);
  881. if (vp) {
  882. GETMISCPTR(vp, lpMem16);
  883. hMeta16 = FETCHWORD(((LPMETAFILEPICT16) lpMem16)->hMF);
  884. GlobalUnlockFree16(GlobalLock16(hMeta16, NULL));
  885. }
  886. GlobalUnlockFree16(vp);
  887. ClipboardFormats.Pre2[3] = 0;
  888. }
  889. // Empty rest of the formats
  890. for (wFormat=0; wFormat <= CF_WAVE ; wFormat++) {
  891. if (ClipboardFormats.Pre1[wFormat]) {
  892. GlobalUnlockFree16(GlobalLock16(ClipboardFormats.Pre1[wFormat], NULL));
  893. ClipboardFormats.Pre1[wFormat] = 0;
  894. }
  895. }
  896. for (wFormat=0; wFormat < 4 ; wFormat++) {
  897. if (ClipboardFormats.Pre2[wFormat]) {
  898. GlobalUnlockFree16(GlobalLock16(ClipboardFormats.Pre2[wFormat], NULL));
  899. ClipboardFormats.Pre2[wFormat] = 0;
  900. }
  901. }
  902. if (ClipboardFormats.hmem16Drop) {
  903. GlobalUnlockFree16(GlobalLock16(ClipboardFormats.hmem16Drop, NULL));
  904. }
  905. ClipboardFormats.hmem16Drop = 0;
  906. // These are the private registered data formats. This list is purged when
  907. // 32 bit USER purges its clipboard cache.
  908. Temp = ClipboardFormats.NewFormats;
  909. ClipboardFormats.NewFormats = NULL;
  910. while (Temp) {
  911. Temp1 = Temp->Next;
  912. if (Temp->hMem16) {
  913. GlobalUnlockFree16(GlobalLock16(Temp->hMem16, NULL));
  914. }
  915. free_w(Temp);
  916. Temp = Temp1;
  917. }
  918. }
  919. VOID InitCBFormats ()
  920. {
  921. int wFormat;
  922. for (wFormat = 0 ; wFormat <= CF_WAVE ; wFormat++) {
  923. ClipboardFormats.Pre1[wFormat] = 0;
  924. }
  925. for (wFormat=0; wFormat < 4; wFormat++) {
  926. ClipboardFormats.Pre2[wFormat] = 0;
  927. }
  928. ClipboardFormats.hmem16Drop = 0;
  929. // These are the private registered data formats.
  930. ClipboardFormats.NewFormats = NULL;
  931. CFOLEObjectDescriptor = RegisterClipboardFormat ("Object Descriptor");
  932. CFOLELinkSrcDescriptor = RegisterClipboardFormat ("Link Source Descriptor");
  933. #ifndef DBCS
  934. #ifdef DEBUG
  935. //
  936. // This would assert in LoadLibraryAndGetProcAddresses if the function
  937. // or DLL name has changed.
  938. //
  939. if (!(OleStringConversion[WOW_OLE_STRINGCONVERSION].lpfn)) {
  940. LoadLibraryAndGetProcAddresses(L"OLETHK32.DLL", OleStringConversion, WOW_OLESTRINGCONVERSION_COUNT);
  941. }
  942. #endif
  943. #endif // !DBCS
  944. }
  945. HGLOBAL W32ConvertObjDescriptor(HANDLE hMem, UINT flag)
  946. {
  947. HANDLE hMemOut;
  948. if (!(OleStringConversion[WOW_OLE_STRINGCONVERSION].lpfn)) {
  949. if (!LoadLibraryAndGetProcAddresses(L"OLETHK32.DLL", OleStringConversion, WOW_OLESTRINGCONVERSION_COUNT)) {
  950. return (0);
  951. }
  952. }
  953. hMemOut = (HANDLE) (*OleStringConversion[WOW_OLE_STRINGCONVERSION].lpfn) (hMem, flag);
  954. return (hMemOut);
  955. }