Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1 | /* |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 2 | * WIN32 clipboard implementation |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1994 Martin Ayotte |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 5 | * 1996 Alex Korobka |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 6 | * 1999 Noel Borthwick |
| 7 | * |
| 8 | * NOTES: |
| 9 | * This file contains the implementation for the WIN32 Clipboard API |
| 10 | * and Wine's internal clipboard cache. |
| 11 | * The actual contents of the clipboard are held in the clipboard cache. |
| 12 | * The internal implementation talks to a "clipboard driver" to fill or |
| 13 | * expose the cache to the native device. (Currently only the X11 and |
| 14 | * TTY clipboard driver are available) |
| 15 | * |
| 16 | * TODO: |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 17 | * |
| 18 | */ |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 19 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <unistd.h> |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 25 | #include <string.h> |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 26 | #include "windef.h" |
| 27 | #include "wingdi.h" |
Marcus Meissner | 61afa33 | 1999-02-22 10:16:00 +0000 | [diff] [blame] | 28 | #include "winuser.h" |
Marcus Meissner | 219cfd8 | 1999-02-24 13:05:13 +0000 | [diff] [blame] | 29 | #include "wine/winuser16.h" |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 30 | #include "wine/winbase16.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 31 | #include "heap.h" |
Marcus Meissner | 61afa33 | 1999-02-22 10:16:00 +0000 | [diff] [blame] | 32 | #include "message.h" |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 33 | #include "task.h" |
| 34 | #include "queue.h" |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 35 | #include "user.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 36 | #include "clipboard.h" |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 37 | #include "debugtools.h" |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 38 | |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 39 | DEFAULT_DEBUG_CHANNEL(clipboard); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 40 | |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 41 | #define CF_REGFORMATBASE 0xC000 |
| 42 | |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 43 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 44 | * Clipboard context global variables |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 45 | */ |
| 46 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 47 | static HANDLE hClipLock = 0; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 48 | static BOOL bCBHasChanged = FALSE; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 49 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 50 | HWND hWndClipWindow = 0; /* window that last opened clipboard */ |
| 51 | HWND hWndClipOwner = 0; /* current clipboard owner */ |
| 52 | HANDLE16 hTaskClipOwner = 0; /* clipboard owner's task */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 53 | static HWND hWndViewer = 0; /* start of viewers chain */ |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 54 | |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 55 | static WORD LastRegFormat = CF_REGFORMATBASE; |
| 56 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 57 | /* Clipboard cache initial data. |
| 58 | * WARNING: This data ordering is dependendent on the WINE_CLIPFORMAT structure |
| 59 | * declared in clipboard.h |
| 60 | */ |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 61 | WINE_CLIPFORMAT ClipFormats[17] = { |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 62 | { CF_TEXT, 1, 0, "Text", 0, 0, 0, 0, NULL, &ClipFormats[1]}, |
| 63 | { CF_BITMAP, 1, 0, "Bitmap", 0, 0, 0, 0, &ClipFormats[0], &ClipFormats[2]}, |
| 64 | { CF_METAFILEPICT, 1, 0, "MetaFile Picture", 0, 0, 0, 0, &ClipFormats[1], &ClipFormats[3]}, |
| 65 | { CF_SYLK, 1, 0, "Sylk", 0, 0, 0, 0, &ClipFormats[2], &ClipFormats[4]}, |
| 66 | { CF_DIF, 1, 0, "DIF", 0, 0, 0, 0, &ClipFormats[3], &ClipFormats[5]}, |
| 67 | { CF_TIFF, 1, 0, "TIFF", 0, 0, 0, 0, &ClipFormats[4], &ClipFormats[6]}, |
| 68 | { CF_OEMTEXT, 1, 0, "OEM Text", 0, 0, 0, 0, &ClipFormats[5], &ClipFormats[7]}, |
| 69 | { CF_DIB, 1, 0, "DIB", 0, 0, 0, 0, &ClipFormats[6], &ClipFormats[8]}, |
| 70 | { CF_PALETTE, 1, 0, "Palette", 0, 0, 0, 0, &ClipFormats[7], &ClipFormats[9]}, |
| 71 | { CF_PENDATA, 1, 0, "PenData", 0, 0, 0, 0, &ClipFormats[8], &ClipFormats[10]}, |
| 72 | { CF_RIFF, 1, 0, "RIFF", 0, 0, 0, 0, &ClipFormats[9], &ClipFormats[11]}, |
| 73 | { CF_WAVE, 1, 0, "Wave", 0, 0, 0, 0, &ClipFormats[10], &ClipFormats[12]}, |
| 74 | { CF_OWNERDISPLAY, 1, 0, "Owner Display", 0, 0, 0, 0, &ClipFormats[11], &ClipFormats[13]}, |
| 75 | { CF_DSPTEXT, 1, 0, "DSPText", 0, 0, 0, 0, &ClipFormats[12], &ClipFormats[14]}, |
| 76 | { CF_DSPMETAFILEPICT, 1, 0, "DSPMetaFile Picture", 0, 0, 0, 0, &ClipFormats[13], &ClipFormats[15]}, |
| 77 | { CF_DSPBITMAP, 1, 0, "DSPBitmap", 0, 0, 0, 0, &ClipFormats[14], &ClipFormats[16]}, |
| 78 | { CF_HDROP, 1, 0, "HDROP", 0, 0, 0, 0, &ClipFormats[15], NULL} |
| 79 | }; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 80 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 81 | |
| 82 | /************************************************************************** |
| 83 | * Internal Clipboard implementation methods |
| 84 | **************************************************************************/ |
| 85 | |
| 86 | |
| 87 | /************************************************************************** |
| 88 | * CLIPBOARD_LookupFormat |
| 89 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 90 | static LPWINE_CLIPFORMAT __lookup_format( LPWINE_CLIPFORMAT lpFormat, WORD wID ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 91 | { |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 92 | while(TRUE) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 93 | { |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 94 | if (lpFormat == NULL || |
| 95 | lpFormat->wFormatID == wID) break; |
| 96 | lpFormat = lpFormat->NextFormat; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 97 | } |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 98 | return lpFormat; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 101 | LPWINE_CLIPFORMAT CLIPBOARD_LookupFormat( WORD wID ) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 102 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 103 | return __lookup_format( ClipFormats, wID ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 106 | /************************************************************************** |
| 107 | * CLIPBOARD_IsLocked |
| 108 | * Check if the clipboard cache is available to the caller |
| 109 | */ |
| 110 | BOOL CLIPBOARD_IsLocked() |
| 111 | { |
| 112 | BOOL bIsLocked = TRUE; |
| 113 | HANDLE16 hTaskCur = GetCurrentTask(); |
| 114 | |
| 115 | /* |
| 116 | * The clipboard is available: |
| 117 | * 1. if the caller's task has opened the clipboard, |
| 118 | * or |
| 119 | * 2. if the caller is the clipboard owners task, AND is responding to a |
| 120 | * WM_RENDERFORMAT message. |
| 121 | */ |
| 122 | if ( hClipLock == hTaskCur ) |
| 123 | bIsLocked = FALSE; |
| 124 | |
| 125 | else if ( hTaskCur == hTaskClipOwner ) |
| 126 | { |
| 127 | /* Check if we're currently executing inside a window procedure |
| 128 | * called in response to a WM_RENDERFORMAT message. A WM_RENDERFORMAT |
| 129 | * handler is not permitted to open the clipboard since it has been opened |
| 130 | * by another client. However the handler must have access to the |
| 131 | * clipboard in order to update data in response to this message. |
| 132 | */ |
| 133 | MESSAGEQUEUE *queue = QUEUE_Lock( GetFastQueue16() ); |
| 134 | |
| 135 | if ( queue |
| 136 | && queue->smWaiting |
| 137 | && queue->smWaiting->msg == WM_RENDERFORMAT |
| 138 | && queue->smWaiting->hSrcQueue |
| 139 | ) |
| 140 | bIsLocked = FALSE; |
| 141 | |
| 142 | QUEUE_Unlock( queue ); |
| 143 | } |
| 144 | |
| 145 | return bIsLocked; |
| 146 | } |
| 147 | |
| 148 | /************************************************************************** |
| 149 | * CLIPBOARD_ReleaseOwner |
| 150 | * Gives up ownership of the clipboard |
| 151 | */ |
| 152 | void CLIPBOARD_ReleaseOwner() |
| 153 | { |
| 154 | hWndClipOwner = 0; |
| 155 | hTaskClipOwner = 0; |
| 156 | } |
| 157 | |
| 158 | /************************************************************************** |
| 159 | * CLIPBOARD_GlobalFreeProc |
| 160 | * |
| 161 | * This is a callback mechanism to allow HGLOBAL data to be released in |
| 162 | * the context of the process which allocated it. We post a WM_TIMER message |
| 163 | * to the owner window(in CLIPBOARD_DeleteRecord) and destroy the data(in idEvent) |
| 164 | * in this WndProc, which is invoked when the apps message loop calls DispatchMessage. |
| 165 | * This technique is discussed in Matt Pietrek's "Under the Hood". |
| 166 | * An article describing the same may be found in MSDN by searching for WM_TIMER. |
| 167 | * Note that this mechanism will probably stop working when WINE supports |
| 168 | * address space separation. When "queue events" are implemented in Wine we |
| 169 | * should switch to using that mechanism, since it is more robust and does not |
| 170 | * require a procedure address to be passed. See the SetWinEventHook API for |
| 171 | * more info on this. |
| 172 | */ |
| 173 | VOID CALLBACK CLIPBOARD_GlobalFreeProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ) |
| 174 | { |
| 175 | /* idEvent is the HGLOBAL to be deleted */ |
| 176 | GlobalFree( (HGLOBAL)idEvent ); |
| 177 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 178 | |
| 179 | /************************************************************************** |
| 180 | * CLIPBOARD_DeleteRecord |
| 181 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 182 | void CLIPBOARD_DeleteRecord(LPWINE_CLIPFORMAT lpFormat, BOOL bChange) |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 183 | { |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 184 | if( (lpFormat->wFormatID >= CF_GDIOBJFIRST && |
Ulrich Czekalla | 6623b85 | 1999-10-23 14:10:04 +0000 | [diff] [blame] | 185 | lpFormat->wFormatID <= CF_GDIOBJLAST) || lpFormat->wFormatID == CF_BITMAP |
| 186 | || lpFormat->wFormatID == CF_PALETTE) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 187 | { |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 188 | if (lpFormat->hData32) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 189 | DeleteObject(lpFormat->hData32); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 190 | if (lpFormat->hData16) |
Alexandre Julliard | b0efe28 | 2000-08-04 04:18:04 +0000 | [diff] [blame] | 191 | DeleteObject(lpFormat->hData16); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 192 | } |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 193 | else if( lpFormat->wFormatID == CF_METAFILEPICT ) |
| 194 | { |
| 195 | if (lpFormat->hData32) |
| 196 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 197 | DeleteMetaFile( ((METAFILEPICT *)GlobalLock( lpFormat->hData32 ))->hMF ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 198 | PostMessageA(hWndClipOwner, WM_TIMER, |
| 199 | (WPARAM)lpFormat->hData32, (LPARAM)CLIPBOARD_GlobalFreeProc); |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 200 | if (lpFormat->hDataSrc32) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 201 | { |
| 202 | /* Release lpFormat->hData32 in the context of the process which created it. |
| 203 | * See CLIPBOARD_GlobalFreeProc for more details about this technique. |
| 204 | * GlobalFree(lpFormat->hDataSrc32); |
| 205 | */ |
| 206 | PostMessageA(hWndClipOwner, WM_TIMER, |
| 207 | (WPARAM)lpFormat->hDataSrc32, (LPARAM)CLIPBOARD_GlobalFreeProc); |
| 208 | } |
| 209 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 210 | if (lpFormat->hData16) |
| 211 | /* HMETAFILE16 and HMETAFILE32 are apparently the same thing, |
| 212 | and a shallow copy is enough to share a METAFILEPICT |
| 213 | structure between 16bit and 32bit clipboards. The MetaFile |
| 214 | should of course only be deleted once. */ |
| 215 | GlobalFree16(lpFormat->hData16); |
| 216 | } |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 217 | if (lpFormat->hData16) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 218 | { |
| 219 | DeleteMetaFile16( ((METAFILEPICT16 *)GlobalLock16( lpFormat->hData16 ))->hMF ); |
| 220 | GlobalFree16(lpFormat->hData16); |
| 221 | } |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | if (lpFormat->hData32) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 226 | { |
| 227 | /* Release lpFormat->hData32 in the context of the process which created it. |
| 228 | * See CLIPBOARD_GlobalFreeProc for more details about this technique. |
| 229 | * GlobalFree( lpFormat->hData32 ); |
| 230 | */ |
| 231 | PostMessageA(hWndClipOwner, WM_TIMER, |
| 232 | (WPARAM)lpFormat->hData32, (LPARAM)CLIPBOARD_GlobalFreeProc); |
| 233 | } |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 234 | if (lpFormat->hDataSrc32) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 235 | { |
| 236 | /* Release lpFormat->hData32 in the context of the process which created it. |
| 237 | * See CLIPBOARD_GlobalFreeProc for more details about this technique. |
| 238 | * GlobalFree(lpFormat->hDataSrc32); |
| 239 | */ |
| 240 | PostMessageA(hWndClipOwner, WM_TIMER, |
| 241 | (WPARAM)lpFormat->hDataSrc32, (LPARAM)CLIPBOARD_GlobalFreeProc); |
| 242 | } |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 243 | if (lpFormat->hData16) |
| 244 | GlobalFree16(lpFormat->hData16); |
| 245 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 246 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 247 | lpFormat->wDataPresent = 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 248 | lpFormat->hData16 = 0; |
| 249 | lpFormat->hData32 = 0; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 250 | lpFormat->hDataSrc32 = 0; |
| 251 | lpFormat->drvData = 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 252 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 253 | if( bChange ) bCBHasChanged = TRUE; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 257 | * CLIPBOARD_EmptyCache |
| 258 | */ |
| 259 | void CLIPBOARD_EmptyCache( BOOL bChange ) |
| 260 | { |
| 261 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
| 262 | |
| 263 | while(lpFormat) |
| 264 | { |
| 265 | if ( lpFormat->wDataPresent || lpFormat->hData16 || lpFormat->hData32 ) |
| 266 | CLIPBOARD_DeleteRecord( lpFormat, bChange ); |
| 267 | |
| 268 | lpFormat = lpFormat->NextFormat; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /************************************************************************** |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 273 | * CLIPBOARD_IsPresent |
| 274 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 275 | BOOL CLIPBOARD_IsPresent(WORD wFormat) |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 276 | { |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 277 | /* special case */ |
| 278 | |
| 279 | if( wFormat == CF_TEXT || wFormat == CF_OEMTEXT ) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 280 | return ClipFormats[CF_TEXT-1].wDataPresent || |
| 281 | ClipFormats[CF_OEMTEXT-1].wDataPresent; |
| 282 | else |
| 283 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 284 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 285 | if( lpFormat ) return (lpFormat->wDataPresent); |
| 286 | } |
| 287 | return FALSE; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 291 | * CLIPBOARD_IsCacheRendered |
| 292 | * Checks if any data needs to be rendered to the clipboard cache |
| 293 | * RETURNS: |
| 294 | * TRUE - All clipboard data is available in the cache |
| 295 | * FALSE - Some data is marked for delayed render and needs rendering |
| 296 | */ |
| 297 | BOOL CLIPBOARD_IsCacheRendered() |
| 298 | { |
| 299 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
| 300 | |
| 301 | /* check if all formats were rendered */ |
| 302 | while(lpFormat) |
| 303 | { |
| 304 | if( lpFormat->wDataPresent && !lpFormat->hData16 && !lpFormat->hData32 ) |
| 305 | return FALSE; |
| 306 | |
| 307 | lpFormat = lpFormat->NextFormat; |
| 308 | } |
| 309 | |
| 310 | return TRUE; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | /************************************************************************** |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 315 | * CLIPBOARD_IsMemoryObject |
| 316 | * Tests if the clipboard format specifies a memory object |
| 317 | */ |
| 318 | BOOL CLIPBOARD_IsMemoryObject( WORD wFormat ) |
| 319 | { |
| 320 | switch(wFormat) |
| 321 | { |
| 322 | case CF_BITMAP: |
| 323 | case CF_METAFILEPICT: |
| 324 | case CF_DSPTEXT: |
| 325 | case CF_ENHMETAFILE: |
| 326 | case CF_HDROP: |
| 327 | case CF_PALETTE: |
| 328 | case CF_PENDATA: |
| 329 | return FALSE; |
| 330 | default: |
| 331 | return TRUE; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /*********************************************************************** |
| 336 | * CLIPBOARD_GlobalDupMem( HGLOBAL ) |
| 337 | * Helper method to duplicate an HGLOBAL chunk of memory into shared memory |
| 338 | */ |
| 339 | HGLOBAL CLIPBOARD_GlobalDupMem( HGLOBAL hGlobalSrc ) |
| 340 | { |
| 341 | HGLOBAL hGlobalDest; |
| 342 | PVOID pGlobalSrc, pGlobalDest; |
| 343 | DWORD cBytes; |
| 344 | |
| 345 | if ( !hGlobalSrc ) |
| 346 | return 0; |
| 347 | |
| 348 | cBytes = GlobalSize(hGlobalSrc); |
| 349 | if ( 0 == cBytes ) |
| 350 | return 0; |
| 351 | |
| 352 | /* Turn on the DDESHARE and _MOVEABLE flags explicitly */ |
| 353 | hGlobalDest = GlobalAlloc( GlobalFlags(hGlobalSrc) | GMEM_DDESHARE | GMEM_MOVEABLE, |
| 354 | cBytes ); |
| 355 | if ( !hGlobalDest ) |
| 356 | return 0; |
| 357 | |
| 358 | pGlobalSrc = GlobalLock(hGlobalSrc); |
| 359 | pGlobalDest = GlobalLock(hGlobalDest); |
| 360 | if ( !pGlobalSrc || !pGlobalDest ) |
| 361 | return 0; |
| 362 | |
| 363 | memcpy(pGlobalDest, pGlobalSrc, cBytes); |
| 364 | |
| 365 | GlobalUnlock(hGlobalSrc); |
| 366 | GlobalUnlock(hGlobalDest); |
| 367 | |
| 368 | return hGlobalDest; |
| 369 | } |
| 370 | |
| 371 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 372 | * CLIPBOARD_GetFormatName |
| 373 | * Gets the format name associated with an ID |
| 374 | */ |
| 375 | char * CLIPBOARD_GetFormatName(UINT wFormat) |
| 376 | { |
| 377 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
| 378 | return (lpFormat) ? lpFormat->Name : NULL; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | /************************************************************************** |
| 383 | * CLIPBOARD_RenderFormat |
| 384 | */ |
| 385 | static BOOL CLIPBOARD_RenderFormat(LPWINE_CLIPFORMAT lpFormat) |
| 386 | { |
| 387 | /* |
| 388 | * If WINE is not the selection owner, and the format is available |
| 389 | * we must ask the the driver to render the data to the clipboard cache. |
| 390 | */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 391 | if ( !USER_Driver.pIsSelectionOwner() |
| 392 | && USER_Driver.pIsClipboardFormatAvailable( lpFormat->wFormatID ) ) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 393 | { |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 394 | if ( !USER_Driver.pGetClipboardData( lpFormat->wFormatID ) ) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 395 | return FALSE; |
| 396 | } |
| 397 | /* |
| 398 | * If Wine owns the clipboard, and the data is marked for delayed render, |
| 399 | * render it now. |
| 400 | */ |
| 401 | else if( lpFormat->wDataPresent && !lpFormat->hData16 && !lpFormat->hData32 ) |
| 402 | { |
| 403 | if( IsWindow(hWndClipOwner) ) |
| 404 | { |
| 405 | /* Send a WM_RENDERFORMAT message to notify the owner to render the |
| 406 | * data requested into the clipboard. |
| 407 | */ |
| 408 | TRACE("Sending WM_RENDERFORMAT message\n"); |
| 409 | SendMessage16(hWndClipOwner,WM_RENDERFORMAT, |
| 410 | (WPARAM16)lpFormat->wFormatID,0L); |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | WARN("\thWndClipOwner (%04x) is lost!\n", |
| 415 | hWndClipOwner); |
| 416 | CLIPBOARD_ReleaseOwner(); |
| 417 | lpFormat->wDataPresent = 0; |
| 418 | return FALSE; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | return (lpFormat->hData16 || lpFormat->hData32) ? TRUE : FALSE; |
| 423 | } |
| 424 | |
| 425 | |
| 426 | /************************************************************************** |
| 427 | * CLIPBOARD_RenderText |
| 428 | * |
| 429 | * Renders text to the clipboard buffer converting between UNIX and DOS formats. |
| 430 | * |
| 431 | * RETURNS: pointer to the WINE_CLIPFORMAT if successful, NULL otherwise |
| 432 | * |
| 433 | * FIXME: Should be a pair of driver functions that convert between OEM text and Windows. |
| 434 | * |
| 435 | */ |
| 436 | static LPWINE_CLIPFORMAT CLIPBOARD_RenderText( UINT wFormat ) |
| 437 | { |
| 438 | LPWINE_CLIPFORMAT lpSource = ClipFormats; |
| 439 | LPWINE_CLIPFORMAT lpTarget; |
| 440 | |
| 441 | /* Asked for CF_TEXT and not available - always attempt to convert from CF_OEM_TEXT */ |
| 442 | if( wFormat == CF_TEXT && !ClipFormats[CF_TEXT-1].wDataPresent ) |
| 443 | { |
| 444 | /* Convert OEMTEXT -> TEXT */ |
| 445 | lpSource = &ClipFormats[CF_OEMTEXT-1]; |
| 446 | lpTarget = &ClipFormats[CF_TEXT-1]; |
| 447 | |
| 448 | TRACE("\tOEMTEXT -> TEXT\n"); |
| 449 | } |
| 450 | /* Asked for CF_OEM_TEXT, and CF_TEXT available */ |
| 451 | else if( wFormat == CF_OEMTEXT && !ClipFormats[CF_OEMTEXT-1].wDataPresent |
| 452 | && ClipFormats[CF_TEXT-1].wDataPresent ) |
| 453 | { |
| 454 | /* Convert TEXT -> OEMTEXT */ |
| 455 | lpSource = &ClipFormats[CF_TEXT-1]; |
| 456 | lpTarget = &ClipFormats[CF_OEMTEXT-1]; |
| 457 | |
| 458 | TRACE("\tTEXT -> OEMTEXT\n"); |
| 459 | } |
| 460 | /* Text format requested is available - no conversion necessary */ |
| 461 | else |
| 462 | { |
| 463 | lpSource = __lookup_format( ClipFormats, wFormat ); |
| 464 | lpTarget = lpSource; |
| 465 | } |
| 466 | |
| 467 | /* First render the source text format */ |
| 468 | if ( !lpSource || !CLIPBOARD_RenderFormat(lpSource) ) return NULL; |
| 469 | |
| 470 | /* Convert to the desired target text format, if necessary */ |
| 471 | if( lpTarget != lpSource && !lpTarget->hData16 && !lpTarget->hData32 ) |
| 472 | { |
| 473 | UINT16 size; |
| 474 | LPCSTR lpstrS; |
| 475 | LPSTR lpstrT; |
| 476 | |
| 477 | if (lpSource->hData32) |
| 478 | { |
| 479 | size = GlobalSize( lpSource->hData32 ); |
| 480 | lpstrS = (LPSTR)GlobalLock(lpSource->hData32); |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | size = GlobalSize16( lpSource->hData16 ); |
| 485 | lpstrS = (LPSTR)GlobalLock16(lpSource->hData16); |
| 486 | } |
| 487 | |
| 488 | if( !lpstrS ) return NULL; |
| 489 | TRACE("\tconverting from '%s' to '%s', %i chars\n", |
| 490 | lpSource->Name, lpTarget->Name, size); |
| 491 | |
Francis Beaudet | 56ab55d | 1999-10-24 20:22:24 +0000 | [diff] [blame] | 492 | lpTarget->hData32 = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, size); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 493 | lpstrT = (LPSTR)GlobalLock(lpTarget->hData32); |
| 494 | |
| 495 | if( lpstrT ) |
| 496 | { |
| 497 | if( lpSource->wFormatID == CF_TEXT ) |
| 498 | CharToOemBuffA(lpstrS, lpstrT, size); |
| 499 | else |
| 500 | OemToCharBuffA(lpstrS, lpstrT, size); |
| 501 | TRACE("\tgot %s\n", lpstrT); |
| 502 | GlobalUnlock(lpTarget->hData32); |
| 503 | } |
| 504 | else |
| 505 | lpTarget->hData32 = 0; |
| 506 | |
| 507 | /* Unlock source */ |
| 508 | if (lpSource->hData32) |
| 509 | GlobalUnlock(lpSource->hData32); |
| 510 | else |
| 511 | GlobalUnlock16(lpSource->hData16); |
| 512 | } |
| 513 | |
| 514 | return (lpTarget->hData16 || lpTarget->hData32) ? lpTarget : NULL; |
| 515 | } |
| 516 | |
| 517 | /************************************************************************** |
| 518 | * WIN32 Clipboard implementation |
| 519 | **************************************************************************/ |
| 520 | |
| 521 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 522 | * OpenClipboard16 (USER.137) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 523 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 524 | BOOL16 WINAPI OpenClipboard16( HWND16 hWnd ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 525 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 526 | return OpenClipboard( hWnd ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | |
| 530 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 531 | * OpenClipboard (USER32.407) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 532 | * |
| 533 | * Note: Netscape uses NULL hWnd to open the clipboard. |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 534 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 535 | BOOL WINAPI OpenClipboard( HWND hWnd ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 536 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 537 | BOOL bRet; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 538 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 539 | TRACE("(%04x)...\n", hWnd); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 540 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 541 | if (!hClipLock) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 542 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 543 | hClipLock = GetCurrentTask(); |
| 544 | |
| 545 | /* Save current user of the clipboard */ |
| 546 | hWndClipWindow = hWnd; |
| 547 | bCBHasChanged = FALSE; |
| 548 | bRet = TRUE; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 549 | } |
| 550 | else bRet = FALSE; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 551 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 552 | TRACE(" returning %i\n", bRet); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 553 | return bRet; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | |
| 557 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 558 | * CloseClipboard16 (USER.138) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 559 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 560 | BOOL16 WINAPI CloseClipboard16(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 561 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 562 | return CloseClipboard(); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | |
| 566 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 567 | * CloseClipboard (USER32.54) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 568 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 569 | BOOL WINAPI CloseClipboard(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 570 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 571 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 572 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 573 | if (hClipLock == GetCurrentTask()) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 574 | { |
| 575 | hWndClipWindow = 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 576 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 577 | if (bCBHasChanged && hWndViewer) |
| 578 | SendMessage16(hWndViewer, WM_DRAWCLIPBOARD, 0, 0L); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 579 | hClipLock = 0; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 580 | } |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 581 | return TRUE; |
| 582 | } |
| 583 | |
| 584 | |
| 585 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 586 | * EmptyClipboard16 (USER.139) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 587 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 588 | BOOL16 WINAPI EmptyClipboard16(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 589 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 590 | return EmptyClipboard(); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | |
| 594 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 595 | * EmptyClipboard (USER32.169) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 596 | * Empties and acquires ownership of the clipboard |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 597 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 598 | BOOL WINAPI EmptyClipboard(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 599 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 600 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 601 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 602 | if (hClipLock != GetCurrentTask()) |
| 603 | { |
| 604 | WARN("Clipboard not opened by calling task!"); |
| 605 | return FALSE; |
| 606 | } |
| 607 | |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 608 | /* destroy private objects */ |
| 609 | |
| 610 | if (hWndClipOwner) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 611 | SendMessage16(hWndClipOwner, WM_DESTROYCLIPBOARD, 0, 0L); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 612 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 613 | /* empty the cache */ |
| 614 | CLIPBOARD_EmptyCache(TRUE); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 615 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 616 | /* Assign ownership of the clipboard to the current client */ |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 617 | hWndClipOwner = hWndClipWindow; |
| 618 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 619 | /* Save the current task */ |
| 620 | hTaskClipOwner = GetCurrentTask(); |
| 621 | |
| 622 | /* Tell the driver to acquire the selection */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 623 | USER_Driver.pAcquireClipboard(); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 624 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 625 | return TRUE; |
| 626 | } |
| 627 | |
| 628 | |
| 629 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 630 | * GetClipboardOwner16 (USER.140) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 631 | * FIXME: Can't return the owner if the clipbard is owned by an external app |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 632 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 633 | HWND16 WINAPI GetClipboardOwner16(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 634 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 635 | TRACE("()\n"); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 636 | return hWndClipOwner; |
| 637 | } |
| 638 | |
| 639 | |
| 640 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 641 | * GetClipboardOwner (USER32.225) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 642 | * FIXME: Can't return the owner if the clipbard is owned by an external app |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 643 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 644 | HWND WINAPI GetClipboardOwner(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 645 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 646 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 647 | return hWndClipOwner; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | |
| 651 | /************************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 652 | * SetClipboardData16 (USER.141) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 653 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 654 | HANDLE16 WINAPI SetClipboardData16( UINT16 wFormat, HANDLE16 hData ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 655 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 656 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 657 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 658 | TRACE("(%04X, %04x) !\n", wFormat, hData); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 659 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 660 | /* NOTE: If the hData is zero and current owner doesn't match |
| 661 | * the window that opened the clipboard then this application |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 662 | * is screwed because WM_RENDERFORMAT will go to the owner. |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 663 | * (to become the owner it must call EmptyClipboard() before |
| 664 | * adding new data). |
| 665 | */ |
| 666 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 667 | if( CLIPBOARD_IsLocked() || !lpFormat || |
| 668 | (!hData && (!hWndClipOwner || (hWndClipOwner != hWndClipWindow))) ) |
| 669 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 670 | WARN("Invalid hData or clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 671 | return 0; |
| 672 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 673 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 674 | /* Pass on the request to the driver */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 675 | USER_Driver.pSetClipboardData(wFormat); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 676 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 677 | if ( lpFormat->wDataPresent || lpFormat->hData16 || lpFormat->hData32 ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 678 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 679 | CLIPBOARD_DeleteRecord(lpFormat, TRUE); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 680 | |
| 681 | /* delete existing CF_TEXT/CF_OEMTEXT aliases */ |
| 682 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 683 | if( wFormat == CF_TEXT |
| 684 | && ( ClipFormats[CF_OEMTEXT-1].hData16 |
| 685 | || ClipFormats[CF_OEMTEXT-1].hData32 ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 686 | && !ClipFormats[CF_OEMTEXT-1].wDataPresent ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 687 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1], TRUE); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 688 | if( wFormat == CF_OEMTEXT |
| 689 | && ( ClipFormats[CF_OEMTEXT-1].hData16 |
| 690 | || ClipFormats[CF_OEMTEXT-1].hData32 ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 691 | && !ClipFormats[CF_TEXT-1].wDataPresent ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 692 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 693 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 694 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 695 | bCBHasChanged = TRUE; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 696 | lpFormat->wDataPresent = 1; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 697 | lpFormat->hData16 = hData; /* 0 is legal, see WM_RENDERFORMAT */ |
| 698 | lpFormat->hData32 = 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 699 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 700 | return lpFormat->hData16; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 703 | |
| 704 | /************************************************************************** |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 705 | * SetClipboardData (USER32.470) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 706 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 707 | HANDLE WINAPI SetClipboardData( UINT wFormat, HANDLE hData ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 708 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 709 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 710 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 711 | TRACE("(%08X, %08x) !\n", wFormat, hData); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 712 | |
| 713 | /* NOTE: If the hData is zero and current owner doesn't match |
| 714 | * the window that opened the clipboard then this application |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 715 | * is screwed because WM_RENDERFORMAT will go to the owner. |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 716 | * (to become the owner it must call EmptyClipboard() before |
| 717 | * adding new data). |
| 718 | */ |
| 719 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 720 | if( CLIPBOARD_IsLocked() || !lpFormat || |
| 721 | (!hData && (!hWndClipOwner || (hWndClipOwner != hWndClipWindow))) ) |
| 722 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 723 | WARN("Invalid hData or clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 724 | return 0; |
| 725 | } |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 726 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 727 | /* Tell the driver to acquire the selection */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 728 | USER_Driver.pAcquireClipboard(); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 729 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 730 | if ( lpFormat->wDataPresent && |
| 731 | (lpFormat->hData16 || lpFormat->hData32) ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 732 | { |
| 733 | CLIPBOARD_DeleteRecord(lpFormat, TRUE); |
| 734 | |
| 735 | /* delete existing CF_TEXT/CF_OEMTEXT aliases */ |
| 736 | |
| 737 | if( wFormat == CF_TEXT |
| 738 | && ( ClipFormats[CF_OEMTEXT-1].hData16 |
| 739 | || ClipFormats[CF_OEMTEXT-1].hData32 ) |
| 740 | && !ClipFormats[CF_OEMTEXT-1].wDataPresent ) |
| 741 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1], TRUE); |
| 742 | if( wFormat == CF_OEMTEXT |
| 743 | && ( ClipFormats[CF_OEMTEXT-1].hData16 |
| 744 | || ClipFormats[CF_OEMTEXT-1].hData32 ) |
| 745 | && !ClipFormats[CF_TEXT-1].wDataPresent ) |
| 746 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE); |
| 747 | } |
| 748 | |
| 749 | bCBHasChanged = TRUE; |
| 750 | lpFormat->wDataPresent = 1; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 751 | lpFormat->hDataSrc32 = hData; /* Save the source handle */ |
| 752 | |
| 753 | /* |
| 754 | * Make a shared duplicate if the memory is not shared |
| 755 | * TODO: What should be done for non-memory objects |
| 756 | */ |
| 757 | if ( CLIPBOARD_IsMemoryObject(wFormat) && hData && !(GlobalFlags(hData) & GMEM_DDESHARE) ) |
| 758 | lpFormat->hData32 = CLIPBOARD_GlobalDupMem( hData ); |
| 759 | else |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 760 | lpFormat->hData32 = hData; /* 0 is legal, see WM_RENDERFORMAT */ |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 761 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 762 | lpFormat->hData16 = 0; |
| 763 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 764 | return lpFormat->hData32; /* Should we return lpFormat->hDataSrc32 */ |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 768 | /************************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 769 | * GetClipboardData16 (USER.142) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 770 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 771 | HANDLE16 WINAPI GetClipboardData16( UINT16 wFormat ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 772 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 773 | LPWINE_CLIPFORMAT lpRender = ClipFormats; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 774 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 775 | TRACE("(%04X)\n", wFormat); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 776 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 777 | if (CLIPBOARD_IsLocked()) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 778 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 779 | WARN("Clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 780 | return 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 781 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 782 | |
| 783 | if( wFormat == CF_TEXT || wFormat == CF_OEMTEXT ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 784 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 785 | lpRender = CLIPBOARD_RenderText(wFormat); |
| 786 | if ( !lpRender ) return 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 787 | } |
| 788 | else |
| 789 | { |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 790 | lpRender = __lookup_format( ClipFormats, wFormat ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 791 | if( !lpRender || !CLIPBOARD_RenderFormat(lpRender) ) return 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 794 | /* Convert between 32 -> 16 bit data, if necessary */ |
Francis Beaudet | 56ab55d | 1999-10-24 20:22:24 +0000 | [diff] [blame] | 795 | if( lpRender->hData32 && !lpRender->hData16 |
| 796 | && CLIPBOARD_IsMemoryObject(wFormat) ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 797 | { |
| 798 | int size; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 799 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 800 | size = sizeof( METAFILEPICT16 ); |
| 801 | else |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 802 | size = GlobalSize(lpRender->hData32); |
| 803 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 804 | lpRender->hData16 = GlobalAlloc16(GMEM_ZEROINIT, size); |
| 805 | if( !lpRender->hData16 ) |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 806 | ERR("(%04X) -- not enough memory in 16b heap\n", wFormat); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 807 | else |
| 808 | { |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 809 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
| 810 | { |
| 811 | FIXME("\timplement function CopyMetaFilePict32to16\n"); |
| 812 | FIXME("\tin the appropriate file.\n"); |
| 813 | #ifdef SOMEONE_IMPLEMENTED_ME |
| 814 | CopyMetaFilePict32to16( GlobalLock16(lpRender->hData16), |
| 815 | GlobalLock(lpRender->hData32) ); |
| 816 | #endif |
| 817 | } |
| 818 | else |
| 819 | { |
| 820 | memcpy( GlobalLock16(lpRender->hData16), |
| 821 | GlobalLock(lpRender->hData32), |
| 822 | size ); |
| 823 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 824 | GlobalUnlock16(lpRender->hData16); |
| 825 | GlobalUnlock(lpRender->hData32); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 829 | TRACE("\treturning %04x (type %i)\n", |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 830 | lpRender->hData16, lpRender->wFormatID); |
| 831 | return lpRender->hData16; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | |
| 835 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 836 | * GetClipboardData (USER32.222) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 837 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 838 | HANDLE WINAPI GetClipboardData( UINT wFormat ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 839 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 840 | LPWINE_CLIPFORMAT lpRender = ClipFormats; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 841 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 842 | TRACE("(%08X)\n", wFormat); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 843 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 844 | if (CLIPBOARD_IsLocked()) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 845 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 846 | WARN("Clipboard not opened by calling task!"); |
| 847 | return 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 848 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 849 | |
| 850 | if( wFormat == CF_TEXT || wFormat == CF_OEMTEXT ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 851 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 852 | lpRender = CLIPBOARD_RenderText(wFormat); |
| 853 | if ( !lpRender ) return 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 854 | } |
| 855 | else |
| 856 | { |
| 857 | lpRender = __lookup_format( ClipFormats, wFormat ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 858 | if( !lpRender || !CLIPBOARD_RenderFormat(lpRender) ) return 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 861 | /* Convert between 16 -> 32 bit data, if necessary */ |
Francis Beaudet | 56ab55d | 1999-10-24 20:22:24 +0000 | [diff] [blame] | 862 | if( lpRender->hData16 && !lpRender->hData32 |
| 863 | && CLIPBOARD_IsMemoryObject(wFormat) ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 864 | { |
| 865 | int size; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 866 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 867 | size = sizeof( METAFILEPICT ); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 868 | else |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 869 | size = GlobalSize16(lpRender->hData16); |
| 870 | lpRender->hData32 = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 871 | size); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 872 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 873 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 874 | FIXME("\timplement function CopyMetaFilePict16to32\n"); |
| 875 | FIXME("\tin the appropriate file.\n"); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 876 | #ifdef SOMEONE_IMPLEMENTED_ME |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 877 | CopyMetaFilePict16to32( GlobalLock16(lpRender->hData32), |
| 878 | GlobalLock(lpRender->hData16) ); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 879 | #endif |
| 880 | } |
| 881 | else |
| 882 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 883 | memcpy( GlobalLock(lpRender->hData32), |
| 884 | GlobalLock16(lpRender->hData16), |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 885 | size ); |
| 886 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 887 | GlobalUnlock(lpRender->hData32); |
| 888 | GlobalUnlock16(lpRender->hData16); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 891 | TRACE("\treturning %04x (type %i)\n", |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 892 | lpRender->hData32, lpRender->wFormatID); |
| 893 | return lpRender->hData32; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 896 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 897 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 898 | * CountClipboardFormats16 (USER.143) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 899 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 900 | INT16 WINAPI CountClipboardFormats16(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 901 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 902 | return CountClipboardFormats(); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | |
| 906 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 907 | * CountClipboardFormats (USER32.63) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 908 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 909 | INT WINAPI CountClipboardFormats(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 910 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 911 | INT FormatCount = 0; |
| 912 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 913 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 914 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 915 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 916 | while(TRUE) |
| 917 | { |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 918 | if (lpFormat == NULL) break; |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 919 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 920 | if( lpFormat->wFormatID != CF_TEXT ) /* Don't count CF_TEXT */ |
| 921 | { |
| 922 | /* |
| 923 | * The format is available if either: |
| 924 | * 1. The data is already in the cache. |
| 925 | * 2. The selection is not owned by us(WINE) and the data is |
| 926 | * available to the clipboard driver. |
| 927 | */ |
| 928 | if ( lpFormat->wDataPresent || |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 929 | ( !USER_Driver.pIsSelectionOwner() |
| 930 | && USER_Driver.pIsClipboardFormatAvailable( lpFormat->wFormatID ) ) ) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 931 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 932 | TRACE("\tdata found for format 0x%04x(%s)\n", |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 933 | lpFormat->wFormatID, CLIPBOARD_GetFormatName(lpFormat->wFormatID)); |
| 934 | FormatCount++; |
| 935 | } |
| 936 | } |
| 937 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 938 | lpFormat = lpFormat->NextFormat; |
| 939 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 940 | |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 941 | /* these two are equivalent, adjust the total */ |
| 942 | |
| 943 | FormatCount += abs(ClipFormats[CF_TEXT-1].wDataPresent - |
| 944 | ClipFormats[CF_OEMTEXT-1].wDataPresent); |
| 945 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 946 | TRACE("\ttotal %d\n", FormatCount); |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 947 | return FormatCount; |
| 948 | } |
| 949 | |
| 950 | |
| 951 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 952 | * EnumClipboardFormats16 (USER.144) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 953 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 954 | UINT16 WINAPI EnumClipboardFormats16( UINT16 wFormat ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 955 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 956 | return EnumClipboardFormats( wFormat ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | |
| 960 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 961 | * EnumClipboardFormats (USER32.179) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 962 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 963 | UINT WINAPI EnumClipboardFormats( UINT wFormat ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 964 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 965 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
| 966 | BOOL bFormatPresent; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 967 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 968 | TRACE("(%04X)\n", wFormat); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 969 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 970 | if (CLIPBOARD_IsLocked()) |
| 971 | { |
| 972 | WARN("Clipboard not opened by calling task!"); |
| 973 | return 0; |
| 974 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 975 | |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 976 | if (wFormat == 0) /* start from the beginning */ |
| 977 | lpFormat = ClipFormats; |
| 978 | else |
Jesper Skov | 5c3e457 | 1998-11-01 19:27:22 +0000 | [diff] [blame] | 979 | { |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 980 | /* walk up to the specified format record */ |
| 981 | |
| 982 | if( !(lpFormat = __lookup_format( lpFormat, wFormat )) ) |
| 983 | return 0; |
| 984 | lpFormat = lpFormat->NextFormat; /* right */ |
Jesper Skov | 5c3e457 | 1998-11-01 19:27:22 +0000 | [diff] [blame] | 985 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 986 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 987 | while(TRUE) |
| 988 | { |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 989 | if (lpFormat == NULL) return 0; |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 990 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 991 | /* Synthesize CF_TEXT from CF_OEMTEXT and vice versa */ |
| 992 | bFormatPresent = (lpFormat->wDataPresent || |
| 993 | (lpFormat->wFormatID == CF_OEMTEXT && ClipFormats[CF_TEXT-1].wDataPresent) || |
| 994 | (lpFormat->wFormatID == CF_TEXT && ClipFormats[CF_OEMTEXT-1].wDataPresent) ); |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 995 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 996 | /* Query the driver if not yet in the cache */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 997 | if (!bFormatPresent && !USER_Driver.pIsSelectionOwner()) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 998 | { |
| 999 | bFormatPresent = |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 1000 | USER_Driver.pIsClipboardFormatAvailable( (lpFormat->wFormatID == CF_TEXT) ? |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1001 | CF_OEMTEXT : lpFormat->wFormatID ); |
| 1002 | } |
| 1003 | |
| 1004 | if (bFormatPresent) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1005 | break; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1006 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1007 | lpFormat = lpFormat->NextFormat; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1008 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1009 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1010 | return lpFormat->wFormatID; |
| 1011 | } |
| 1012 | |
| 1013 | |
| 1014 | /************************************************************************** |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1015 | * RegisterClipboardFormat16 (USER.145) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1016 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1017 | UINT16 WINAPI RegisterClipboardFormat16( LPCSTR FormatName ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1018 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1019 | LPWINE_CLIPFORMAT lpNewFormat; |
| 1020 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1021 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1022 | if (FormatName == NULL) return 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1023 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1024 | TRACE("('%s') !\n", FormatName); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1025 | |
| 1026 | /* walk format chain to see if it's already registered */ |
| 1027 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1028 | while(TRUE) |
| 1029 | { |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1030 | if ( !strcmp(lpFormat->Name,FormatName) ) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1031 | { |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1032 | lpFormat->wRefCount++; |
| 1033 | return lpFormat->wFormatID; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1034 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1035 | |
| 1036 | if ( lpFormat->NextFormat == NULL ) break; |
| 1037 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1038 | lpFormat = lpFormat->NextFormat; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1039 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1040 | |
| 1041 | /* allocate storage for new format entry */ |
| 1042 | |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 1043 | lpNewFormat = (LPWINE_CLIPFORMAT)HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CLIPFORMAT)); |
| 1044 | if(lpNewFormat == NULL) { |
| 1045 | WARN("No more memory for a new format!"); |
| 1046 | return 0; |
| 1047 | } |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1048 | lpFormat->NextFormat = lpNewFormat; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1049 | lpNewFormat->wFormatID = LastRegFormat; |
| 1050 | lpNewFormat->wRefCount = 1; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1051 | |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 1052 | lpNewFormat->Name = (LPSTR)HEAP_strdupA(GetProcessHeap(), 0, FormatName); |
| 1053 | if(lpNewFormat->Name == NULL) { |
| 1054 | WARN("No more memory for the new format name!"); |
| 1055 | HeapFree(GetProcessHeap(), 0, lpNewFormat); |
| 1056 | return 0; |
| 1057 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1058 | |
| 1059 | lpNewFormat->wDataPresent = 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1060 | lpNewFormat->hData16 = 0; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1061 | lpNewFormat->hDataSrc32 = 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1062 | lpNewFormat->hData32 = 0; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1063 | lpNewFormat->drvData = 0; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1064 | lpNewFormat->PrevFormat = lpFormat; |
| 1065 | lpNewFormat->NextFormat = NULL; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1066 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1067 | /* Pass on the registration request to the driver */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 1068 | USER_Driver.pRegisterClipboardFormat( FormatName ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1069 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1070 | return LastRegFormat++; |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1075 | * RegisterClipboardFormatA (USER32.431) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1076 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1077 | UINT WINAPI RegisterClipboardFormatA( LPCSTR formatName ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1078 | { |
| 1079 | return RegisterClipboardFormat16( formatName ); |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1084 | * RegisterClipboardFormatW (USER32.432) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1085 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1086 | UINT WINAPI RegisterClipboardFormatW( LPCWSTR formatName ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1087 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1088 | LPSTR aFormat = HEAP_strdupWtoA( GetProcessHeap(), 0, formatName ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1089 | UINT ret = RegisterClipboardFormatA( aFormat ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1090 | HeapFree( GetProcessHeap(), 0, aFormat ); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1091 | return ret; |
| 1092 | } |
| 1093 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1094 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1095 | /************************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1096 | * GetClipboardFormatName16 (USER.146) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1097 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1098 | INT16 WINAPI GetClipboardFormatName16( UINT16 wFormat, LPSTR retStr, INT16 maxlen ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1099 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1100 | return GetClipboardFormatNameA( wFormat, retStr, maxlen ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1105 | * GetClipboardFormatNameA (USER32.223) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1106 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1107 | INT WINAPI GetClipboardFormatNameA( UINT wFormat, LPSTR retStr, INT maxlen ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1108 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1109 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1110 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1111 | TRACE("(%04X, %p, %d) !\n", wFormat, retStr, maxlen); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1112 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1113 | if (lpFormat == NULL || lpFormat->Name == NULL || |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1114 | lpFormat->wFormatID < CF_REGFORMATBASE) return 0; |
| 1115 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1116 | TRACE("Name='%s' !\n", lpFormat->Name); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1117 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1118 | lstrcpynA( retStr, lpFormat->Name, maxlen ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1119 | return strlen(retStr); |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | |
| 1123 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1124 | * GetClipboardFormatNameW (USER32.224) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1125 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1126 | INT WINAPI GetClipboardFormatNameW( UINT wFormat, LPWSTR retStr, INT maxlen ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1127 | { |
Dimitrie O. Paun | 4d48dd3 | 2000-04-30 12:22:18 +0000 | [diff] [blame] | 1128 | INT ret; |
| 1129 | LPSTR p = HeapAlloc( GetProcessHeap(), 0, maxlen ); |
| 1130 | if(p == NULL) return 0; /* FIXME: is this the correct failure value? */ |
| 1131 | |
| 1132 | ret = GetClipboardFormatNameA( wFormat, p, maxlen ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1133 | lstrcpynAtoW( retStr, p, maxlen ); |
| 1134 | HeapFree( GetProcessHeap(), 0, p ); |
| 1135 | return ret; |
| 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1140 | * SetClipboardViewer16 (USER.147) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1141 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1142 | HWND16 WINAPI SetClipboardViewer16( HWND16 hWnd ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1143 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1144 | TRACE("(%04x)\n", hWnd); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1145 | return SetClipboardViewer( hWnd ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1150 | * SetClipboardViewer (USER32.471) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1151 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1152 | HWND WINAPI SetClipboardViewer( HWND hWnd ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1153 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1154 | HWND hwndPrev = hWndViewer; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1155 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1156 | TRACE("(%04x): returning %04x\n", hWnd, hwndPrev); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1157 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1158 | hWndViewer = hWnd; |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 1159 | return hwndPrev; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1164 | * GetClipboardViewer16 (USER.148) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1165 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1166 | HWND16 WINAPI GetClipboardViewer16(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1167 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1168 | TRACE("()\n"); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1169 | return hWndViewer; |
| 1170 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1171 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1172 | |
| 1173 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1174 | * GetClipboardViewer (USER32.226) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1175 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1176 | HWND WINAPI GetClipboardViewer(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1177 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1178 | TRACE("()\n"); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 1179 | return hWndViewer; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | /************************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1184 | * ChangeClipboardChain16 (USER.149) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1185 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1186 | BOOL16 WINAPI ChangeClipboardChain16(HWND16 hWnd, HWND16 hWndNext) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1187 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1188 | return ChangeClipboardChain(hWnd, hWndNext); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1191 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1192 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1193 | * ChangeClipboardChain (USER32.22) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1194 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1195 | BOOL WINAPI ChangeClipboardChain(HWND hWnd, HWND hWndNext) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1196 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1197 | BOOL bRet = 0; |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 1198 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1199 | FIXME("(0x%04x, 0x%04x): stub?\n", hWnd, hWndNext); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1200 | |
| 1201 | if( hWndViewer ) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1202 | bRet = !SendMessage16( hWndViewer, WM_CHANGECBCHAIN, |
Alexandre Julliard | 530ee84 | 1996-10-23 16:59:13 +0000 | [diff] [blame] | 1203 | (WPARAM16)hWnd, (LPARAM)hWndNext); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1204 | else |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1205 | WARN("hWndViewer is lost\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1206 | |
| 1207 | if( hWnd == hWndViewer ) hWndViewer = hWndNext; |
| 1208 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1209 | return bRet; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1214 | * IsClipboardFormatAvailable16 (USER.193) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1215 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1216 | BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1217 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1218 | return IsClipboardFormatAvailable( wFormat ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | |
| 1222 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1223 | * IsClipboardFormatAvailable (USER32.340) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1224 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1225 | BOOL WINAPI IsClipboardFormatAvailable( UINT wFormat ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1226 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1227 | BOOL bRet; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1228 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1229 | if (wFormat == 0) /* Reject this case quickly */ |
| 1230 | bRet = FALSE; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1231 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1232 | /* If WINE is not the clipboard selection owner ask the clipboard driver */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame^] | 1233 | else if ( !USER_Driver.pIsSelectionOwner() ) |
| 1234 | bRet = USER_Driver.pIsClipboardFormatAvailable( (wFormat == CF_TEXT) ? |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1235 | CF_OEMTEXT : wFormat ); |
| 1236 | /* Check if the format is in the local cache */ |
| 1237 | else |
| 1238 | bRet = CLIPBOARD_IsPresent(wFormat); |
| 1239 | |
| 1240 | TRACE("(%04X)- ret(%d)\n", wFormat, bRet); |
| 1241 | return bRet; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | /************************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1246 | * GetOpenClipboardWindow16 (USER.248) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1247 | * FIXME: This wont work if an external app owns the selection |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1248 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1249 | HWND16 WINAPI GetOpenClipboardWindow16(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1250 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1251 | TRACE("()\n"); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1252 | return hWndClipWindow; |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1257 | * GetOpenClipboardWindow (USER32.277) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1258 | * FIXME: This wont work if an external app owns the selection |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1259 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1260 | HWND WINAPI GetOpenClipboardWindow(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1261 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1262 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1263 | return hWndClipWindow; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | |
| 1267 | /************************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1268 | * GetPriorityClipboardFormat16 (USER.402) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1269 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1270 | INT16 WINAPI GetPriorityClipboardFormat16( UINT16 *lpPriorityList, INT16 nCount) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1271 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1272 | FIXME("(%p,%d): stub\n", lpPriorityList, nCount ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1273 | return 0; |
| 1274 | } |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 1275 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1276 | |
| 1277 | /************************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1278 | * GetPriorityClipboardFormat (USER32.279) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1279 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1280 | INT WINAPI GetPriorityClipboardFormat( UINT *lpPriorityList, INT nCount ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1281 | { |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 1282 | int Counter; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1283 | TRACE("()\n"); |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 1284 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1285 | if(CountClipboardFormats() == 0) |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 1286 | { |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | for(Counter = 0; Counter <= nCount; Counter++) |
| 1291 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1292 | if(IsClipboardFormatAvailable(*(lpPriorityList+sizeof(INT)*Counter))) |
| 1293 | return *(lpPriorityList+sizeof(INT)*Counter); |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | return -1; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |