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