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) |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 15 | */ |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 16 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 18 | #include <sys/types.h> |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 19 | #include <fcntl.h> |
| 20 | #include <unistd.h> |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 21 | #include <string.h> |
François Gouget | 44a1822 | 2000-12-19 04:53:20 +0000 | [diff] [blame] | 22 | |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 23 | #include "windef.h" |
François Gouget | 44a1822 | 2000-12-19 04:53:20 +0000 | [diff] [blame] | 24 | #include "winbase.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 25 | #include "wingdi.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" |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 30 | #include "user.h" |
Alexandre Julliard | 37a4639 | 2001-09-12 17:19:13 +0000 | [diff] [blame] | 31 | #include "win.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 32 | #include "clipboard.h" |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 33 | #include "debugtools.h" |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 35 | DEFAULT_DEBUG_CHANNEL(clipboard); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 36 | |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 37 | #define CF_REGFORMATBASE 0xC000 |
| 38 | |
Patrik Stridvall | e35d636 | 1998-12-07 09:13:40 +0000 | [diff] [blame] | 39 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 40 | * Clipboard context global variables |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 41 | */ |
| 42 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 43 | static HANDLE hClipLock = 0; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 44 | static BOOL bCBHasChanged = FALSE; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 45 | |
Alexandre Julliard | 37a4639 | 2001-09-12 17:19:13 +0000 | [diff] [blame] | 46 | static HWND hWndClipWindow; /* window that last opened clipboard */ |
| 47 | static HWND hWndClipOwner; /* current clipboard owner */ |
| 48 | static HANDLE16 hTaskClipOwner; /* clipboard owner's task */ |
| 49 | static HWND hWndViewer; /* start of viewers chain */ |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 50 | |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 51 | static WORD LastRegFormat = CF_REGFORMATBASE; |
| 52 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 53 | /* Clipboard cache initial data. |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 54 | * WARNING: This data ordering is dependent on the WINE_CLIPFORMAT structure |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 55 | * declared in clipboard.h |
| 56 | */ |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 57 | WINE_CLIPFORMAT ClipFormats[] = { |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 58 | { CF_TEXT, 1, 0, "Text", 0, 0, 0, 0, NULL, &ClipFormats[1]}, |
| 59 | { CF_BITMAP, 1, 0, "Bitmap", 0, 0, 0, 0, &ClipFormats[0], &ClipFormats[2]}, |
| 60 | { CF_METAFILEPICT, 1, 0, "MetaFile Picture", 0, 0, 0, 0, &ClipFormats[1], &ClipFormats[3]}, |
| 61 | { CF_SYLK, 1, 0, "Sylk", 0, 0, 0, 0, &ClipFormats[2], &ClipFormats[4]}, |
| 62 | { CF_DIF, 1, 0, "DIF", 0, 0, 0, 0, &ClipFormats[3], &ClipFormats[5]}, |
| 63 | { CF_TIFF, 1, 0, "TIFF", 0, 0, 0, 0, &ClipFormats[4], &ClipFormats[6]}, |
| 64 | { CF_OEMTEXT, 1, 0, "OEM Text", 0, 0, 0, 0, &ClipFormats[5], &ClipFormats[7]}, |
| 65 | { CF_DIB, 1, 0, "DIB", 0, 0, 0, 0, &ClipFormats[6], &ClipFormats[8]}, |
| 66 | { CF_PALETTE, 1, 0, "Palette", 0, 0, 0, 0, &ClipFormats[7], &ClipFormats[9]}, |
| 67 | { CF_PENDATA, 1, 0, "PenData", 0, 0, 0, 0, &ClipFormats[8], &ClipFormats[10]}, |
| 68 | { CF_RIFF, 1, 0, "RIFF", 0, 0, 0, 0, &ClipFormats[9], &ClipFormats[11]}, |
| 69 | { CF_WAVE, 1, 0, "Wave", 0, 0, 0, 0, &ClipFormats[10], &ClipFormats[12]}, |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 70 | { CF_UNICODETEXT, 1, 0, "Unicode Text", 0, 0, 0, 0, &ClipFormats[11], &ClipFormats[13]}, |
| 71 | { CF_OWNERDISPLAY, 1, 0, "Owner Display", 0, 0, 0, 0, &ClipFormats[12], &ClipFormats[14]}, |
| 72 | { CF_DSPTEXT, 1, 0, "DSPText", 0, 0, 0, 0, &ClipFormats[13], &ClipFormats[15]}, |
| 73 | { CF_DSPMETAFILEPICT, 1, 0, "DSPMetaFile Picture", 0, 0, 0, 0, &ClipFormats[14], &ClipFormats[16]}, |
| 74 | { CF_DSPBITMAP, 1, 0, "DSPBitmap", 0, 0, 0, 0, &ClipFormats[15], &ClipFormats[17]}, |
| 75 | { CF_HDROP, 1, 0, "HDROP", 0, 0, 0, 0, &ClipFormats[16], NULL} |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 76 | }; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 77 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 78 | |
| 79 | /************************************************************************** |
| 80 | * Internal Clipboard implementation methods |
| 81 | **************************************************************************/ |
| 82 | |
| 83 | |
| 84 | /************************************************************************** |
| 85 | * CLIPBOARD_LookupFormat |
| 86 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 87 | static LPWINE_CLIPFORMAT __lookup_format( LPWINE_CLIPFORMAT lpFormat, WORD wID ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 88 | { |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 89 | while(TRUE) |
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 | if (lpFormat == NULL || |
| 92 | lpFormat->wFormatID == wID) break; |
| 93 | lpFormat = lpFormat->NextFormat; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 94 | } |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 95 | return lpFormat; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 98 | LPWINE_CLIPFORMAT CLIPBOARD_LookupFormat( WORD wID ) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 99 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 100 | return __lookup_format( ClipFormats, wID ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 103 | /************************************************************************** |
| 104 | * CLIPBOARD_IsLocked |
| 105 | * Check if the clipboard cache is available to the caller |
| 106 | */ |
| 107 | BOOL CLIPBOARD_IsLocked() |
| 108 | { |
| 109 | BOOL bIsLocked = TRUE; |
| 110 | HANDLE16 hTaskCur = GetCurrentTask(); |
| 111 | |
| 112 | /* |
| 113 | * The clipboard is available: |
| 114 | * 1. if the caller's task has opened the clipboard, |
| 115 | * or |
| 116 | * 2. if the caller is the clipboard owners task, AND is responding to a |
| 117 | * WM_RENDERFORMAT message. |
| 118 | */ |
| 119 | if ( hClipLock == hTaskCur ) |
| 120 | bIsLocked = FALSE; |
| 121 | |
| 122 | else if ( hTaskCur == hTaskClipOwner ) |
| 123 | { |
| 124 | /* Check if we're currently executing inside a window procedure |
| 125 | * called in response to a WM_RENDERFORMAT message. A WM_RENDERFORMAT |
| 126 | * handler is not permitted to open the clipboard since it has been opened |
| 127 | * by another client. However the handler must have access to the |
| 128 | * clipboard in order to update data in response to this message. |
| 129 | */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 130 | #if 0 |
Alexandre Julliard | 8afe662 | 2001-07-26 20:12:22 +0000 | [diff] [blame] | 131 | MESSAGEQUEUE *queue = QUEUE_Current(); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 132 | |
| 133 | if ( queue |
| 134 | && queue->smWaiting |
| 135 | && queue->smWaiting->msg == WM_RENDERFORMAT |
| 136 | && queue->smWaiting->hSrcQueue |
| 137 | ) |
| 138 | bIsLocked = FALSE; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 139 | #else |
| 140 | /* FIXME: queue check no longer possible */ |
| 141 | bIsLocked = FALSE; |
| 142 | #endif |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 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 | |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 279 | if( wFormat == CF_TEXT || wFormat == CF_OEMTEXT || wFormat == CF_UNICODETEXT ) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 280 | return ClipFormats[CF_TEXT-1].wDataPresent || |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 281 | ClipFormats[CF_OEMTEXT-1].wDataPresent || |
| 282 | ClipFormats[CF_UNICODETEXT-1].wDataPresent; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 283 | else |
| 284 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 285 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 286 | if( lpFormat ) return (lpFormat->wDataPresent); |
| 287 | } |
| 288 | return FALSE; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 292 | * CLIPBOARD_IsCacheRendered |
| 293 | * Checks if any data needs to be rendered to the clipboard cache |
| 294 | * RETURNS: |
| 295 | * TRUE - All clipboard data is available in the cache |
| 296 | * FALSE - Some data is marked for delayed render and needs rendering |
| 297 | */ |
| 298 | BOOL CLIPBOARD_IsCacheRendered() |
| 299 | { |
| 300 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
| 301 | |
| 302 | /* check if all formats were rendered */ |
| 303 | while(lpFormat) |
| 304 | { |
| 305 | if( lpFormat->wDataPresent && !lpFormat->hData16 && !lpFormat->hData32 ) |
| 306 | return FALSE; |
| 307 | |
| 308 | lpFormat = lpFormat->NextFormat; |
| 309 | } |
| 310 | |
| 311 | return TRUE; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | /************************************************************************** |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 316 | * CLIPBOARD_IsMemoryObject |
| 317 | * Tests if the clipboard format specifies a memory object |
| 318 | */ |
| 319 | BOOL CLIPBOARD_IsMemoryObject( WORD wFormat ) |
| 320 | { |
| 321 | switch(wFormat) |
| 322 | { |
| 323 | case CF_BITMAP: |
| 324 | case CF_METAFILEPICT: |
| 325 | case CF_DSPTEXT: |
| 326 | case CF_ENHMETAFILE: |
| 327 | case CF_HDROP: |
| 328 | case CF_PALETTE: |
| 329 | case CF_PENDATA: |
| 330 | return FALSE; |
| 331 | default: |
| 332 | return TRUE; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | /*********************************************************************** |
| 337 | * CLIPBOARD_GlobalDupMem( HGLOBAL ) |
| 338 | * Helper method to duplicate an HGLOBAL chunk of memory into shared memory |
| 339 | */ |
| 340 | HGLOBAL CLIPBOARD_GlobalDupMem( HGLOBAL hGlobalSrc ) |
| 341 | { |
| 342 | HGLOBAL hGlobalDest; |
| 343 | PVOID pGlobalSrc, pGlobalDest; |
| 344 | DWORD cBytes; |
| 345 | |
| 346 | if ( !hGlobalSrc ) |
| 347 | return 0; |
| 348 | |
| 349 | cBytes = GlobalSize(hGlobalSrc); |
| 350 | if ( 0 == cBytes ) |
| 351 | return 0; |
| 352 | |
| 353 | /* Turn on the DDESHARE and _MOVEABLE flags explicitly */ |
| 354 | hGlobalDest = GlobalAlloc( GlobalFlags(hGlobalSrc) | GMEM_DDESHARE | GMEM_MOVEABLE, |
| 355 | cBytes ); |
| 356 | if ( !hGlobalDest ) |
| 357 | return 0; |
| 358 | |
| 359 | pGlobalSrc = GlobalLock(hGlobalSrc); |
| 360 | pGlobalDest = GlobalLock(hGlobalDest); |
| 361 | if ( !pGlobalSrc || !pGlobalDest ) |
| 362 | return 0; |
| 363 | |
| 364 | memcpy(pGlobalDest, pGlobalSrc, cBytes); |
| 365 | |
| 366 | GlobalUnlock(hGlobalSrc); |
| 367 | GlobalUnlock(hGlobalDest); |
| 368 | |
| 369 | return hGlobalDest; |
| 370 | } |
| 371 | |
| 372 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 373 | * CLIPBOARD_GetFormatName |
| 374 | * Gets the format name associated with an ID |
| 375 | */ |
| 376 | char * CLIPBOARD_GetFormatName(UINT wFormat) |
| 377 | { |
| 378 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
| 379 | return (lpFormat) ? lpFormat->Name : NULL; |
| 380 | } |
| 381 | |
| 382 | |
| 383 | /************************************************************************** |
| 384 | * CLIPBOARD_RenderFormat |
| 385 | */ |
| 386 | static BOOL CLIPBOARD_RenderFormat(LPWINE_CLIPFORMAT lpFormat) |
| 387 | { |
| 388 | /* |
| 389 | * If WINE is not the selection owner, and the format is available |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 390 | * we must ask the driver to render the data to the clipboard cache. |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 391 | */ |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 392 | TRACE("enter format=%d\n", lpFormat->wFormatID); |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 393 | if ( !USER_Driver.pIsSelectionOwner() |
| 394 | && USER_Driver.pIsClipboardFormatAvailable( lpFormat->wFormatID ) ) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 395 | { |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 396 | if ( !USER_Driver.pGetClipboardData( lpFormat->wFormatID ) ) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 397 | return FALSE; |
| 398 | } |
| 399 | /* |
| 400 | * If Wine owns the clipboard, and the data is marked for delayed render, |
| 401 | * render it now. |
| 402 | */ |
| 403 | else if( lpFormat->wDataPresent && !lpFormat->hData16 && !lpFormat->hData32 ) |
| 404 | { |
| 405 | if( IsWindow(hWndClipOwner) ) |
| 406 | { |
| 407 | /* Send a WM_RENDERFORMAT message to notify the owner to render the |
| 408 | * data requested into the clipboard. |
| 409 | */ |
| 410 | TRACE("Sending WM_RENDERFORMAT message\n"); |
Alexandre Julliard | cb25e25 | 2001-08-08 23:28:42 +0000 | [diff] [blame] | 411 | SendMessageW( hWndClipOwner, WM_RENDERFORMAT, (WPARAM)lpFormat->wFormatID, 0 ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 412 | } |
| 413 | else |
| 414 | { |
| 415 | WARN("\thWndClipOwner (%04x) is lost!\n", |
| 416 | hWndClipOwner); |
| 417 | CLIPBOARD_ReleaseOwner(); |
| 418 | lpFormat->wDataPresent = 0; |
| 419 | return FALSE; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | return (lpFormat->hData16 || lpFormat->hData32) ? TRUE : FALSE; |
| 424 | } |
| 425 | |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 426 | /************************************************************************** |
| 427 | * CLIPBOARD_ConvertText |
| 428 | * Returns number of required/converted characters - not bytes! |
| 429 | */ |
| 430 | static INT CLIPBOARD_ConvertText(WORD src_fmt, void const *src, INT src_size, |
| 431 | WORD dst_fmt, void *dst, INT dst_size) |
| 432 | { |
| 433 | UINT cp; |
| 434 | |
| 435 | if(src_fmt == CF_UNICODETEXT) |
| 436 | { |
| 437 | switch(dst_fmt) |
| 438 | { |
| 439 | case CF_TEXT: |
| 440 | cp = CP_ACP; |
| 441 | break; |
| 442 | case CF_OEMTEXT: |
| 443 | cp = CP_OEMCP; |
| 444 | break; |
| 445 | default: |
| 446 | return 0; |
| 447 | } |
| 448 | return WideCharToMultiByte(cp, 0, src, src_size, dst, dst_size, NULL, NULL); |
| 449 | } |
| 450 | |
| 451 | if(dst_fmt == CF_UNICODETEXT) |
| 452 | { |
| 453 | switch(src_fmt) |
| 454 | { |
| 455 | case CF_TEXT: |
| 456 | cp = CP_ACP; |
| 457 | break; |
| 458 | case CF_OEMTEXT: |
| 459 | cp = CP_OEMCP; |
| 460 | break; |
| 461 | default: |
| 462 | return 0; |
| 463 | } |
| 464 | return MultiByteToWideChar(cp, 0, src, src_size, dst, dst_size); |
| 465 | } |
| 466 | |
| 467 | if(!dst_size) return src_size; |
| 468 | |
| 469 | if(dst_size > src_size) dst_size = src_size; |
| 470 | |
| 471 | if(src_fmt == CF_TEXT ) |
| 472 | CharToOemBuffA(src, dst, dst_size); |
| 473 | else |
| 474 | OemToCharBuffA(src, dst, dst_size); |
| 475 | |
| 476 | return dst_size; |
| 477 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 478 | |
| 479 | /************************************************************************** |
| 480 | * CLIPBOARD_RenderText |
| 481 | * |
| 482 | * Renders text to the clipboard buffer converting between UNIX and DOS formats. |
| 483 | * |
| 484 | * RETURNS: pointer to the WINE_CLIPFORMAT if successful, NULL otherwise |
| 485 | * |
| 486 | * FIXME: Should be a pair of driver functions that convert between OEM text and Windows. |
| 487 | * |
| 488 | */ |
| 489 | static LPWINE_CLIPFORMAT CLIPBOARD_RenderText( UINT wFormat ) |
| 490 | { |
| 491 | LPWINE_CLIPFORMAT lpSource = ClipFormats; |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 492 | LPWINE_CLIPFORMAT lpTarget = NULL; |
| 493 | BOOL foundData = FALSE; |
| 494 | |
Aric Stewart | 039ae27 | 2001-02-12 19:16:05 +0000 | [diff] [blame] | 495 | /* Asked for CF_TEXT */ |
| 496 | if( wFormat == CF_TEXT) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 497 | { |
Aric Stewart | 039ae27 | 2001-02-12 19:16:05 +0000 | [diff] [blame] | 498 | if(ClipFormats[CF_TEXT-1].wDataPresent) |
| 499 | { |
| 500 | lpSource = &ClipFormats[CF_TEXT-1]; |
| 501 | lpTarget = &ClipFormats[CF_TEXT-1]; |
| 502 | foundData = TRUE; |
| 503 | TRACE("\t TEXT -> TEXT\n"); |
| 504 | } |
| 505 | else if(ClipFormats[CF_UNICODETEXT-1].wDataPresent) |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 506 | { |
| 507 | /* Convert UNICODETEXT -> TEXT */ |
| 508 | lpSource = &ClipFormats[CF_UNICODETEXT-1]; |
| 509 | lpTarget = &ClipFormats[CF_TEXT-1]; |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 510 | foundData = TRUE; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 511 | TRACE("\tUNICODETEXT -> TEXT\n"); |
| 512 | } |
| 513 | else if(ClipFormats[CF_OEMTEXT-1].wDataPresent) |
| 514 | { |
| 515 | /* Convert OEMTEXT -> TEXT */ |
| 516 | lpSource = &ClipFormats[CF_OEMTEXT-1]; |
| 517 | lpTarget = &ClipFormats[CF_TEXT-1]; |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 518 | foundData = TRUE; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 519 | TRACE("\tOEMTEXT -> TEXT\n"); |
| 520 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 521 | } |
Aric Stewart | 039ae27 | 2001-02-12 19:16:05 +0000 | [diff] [blame] | 522 | /* Asked for CF_OEMTEXT */ |
| 523 | else if( wFormat == CF_OEMTEXT) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 524 | { |
Aric Stewart | 039ae27 | 2001-02-12 19:16:05 +0000 | [diff] [blame] | 525 | if(ClipFormats[CF_OEMTEXT-1].wDataPresent) |
| 526 | { |
| 527 | lpSource = &ClipFormats[CF_OEMTEXT-1]; |
| 528 | lpTarget = &ClipFormats[CF_OEMTEXT-1]; |
| 529 | foundData = TRUE; |
| 530 | TRACE("\tOEMTEXT -> OEMTEXT\n"); |
| 531 | } |
| 532 | else if(ClipFormats[CF_UNICODETEXT-1].wDataPresent) |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 533 | { |
| 534 | /* Convert UNICODETEXT -> OEMTEXT */ |
| 535 | lpSource = &ClipFormats[CF_UNICODETEXT-1]; |
| 536 | lpTarget = &ClipFormats[CF_OEMTEXT-1]; |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 537 | foundData = TRUE; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 538 | TRACE("\tUNICODETEXT -> OEMTEXT\n"); |
| 539 | } |
| 540 | else if(ClipFormats[CF_TEXT-1].wDataPresent) |
| 541 | { |
| 542 | /* Convert TEXT -> OEMTEXT */ |
| 543 | lpSource = &ClipFormats[CF_TEXT-1]; |
| 544 | lpTarget = &ClipFormats[CF_OEMTEXT-1]; |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 545 | foundData = TRUE; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 546 | TRACE("\tTEXT -> OEMTEXT\n"); |
| 547 | } |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 548 | } |
Aric Stewart | 039ae27 | 2001-02-12 19:16:05 +0000 | [diff] [blame] | 549 | /* Asked for CF_UNICODETEXT */ |
| 550 | else if( wFormat == CF_UNICODETEXT ) |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 551 | { |
Aric Stewart | 039ae27 | 2001-02-12 19:16:05 +0000 | [diff] [blame] | 552 | if(ClipFormats[CF_UNICODETEXT-1].wDataPresent) |
| 553 | { |
| 554 | lpSource = &ClipFormats[CF_UNICODETEXT-1]; |
| 555 | lpTarget = &ClipFormats[CF_UNICODETEXT-1]; |
| 556 | foundData = TRUE; |
| 557 | TRACE("\tUNICODETEXT -> UNICODETEXT\n"); |
| 558 | } |
| 559 | else if(ClipFormats[CF_TEXT-1].wDataPresent) |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 560 | { |
| 561 | /* Convert TEXT -> UNICODETEXT */ |
| 562 | lpSource = &ClipFormats[CF_TEXT-1]; |
| 563 | lpTarget = &ClipFormats[CF_UNICODETEXT-1]; |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 564 | foundData = TRUE; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 565 | TRACE("\tTEXT -> UNICODETEXT\n"); |
| 566 | } |
| 567 | else if(ClipFormats[CF_OEMTEXT-1].wDataPresent) |
| 568 | { |
| 569 | /* Convert OEMTEXT -> UNICODETEXT */ |
| 570 | lpSource = &ClipFormats[CF_OEMTEXT-1]; |
| 571 | lpTarget = &ClipFormats[CF_UNICODETEXT-1]; |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 572 | foundData = TRUE; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 573 | TRACE("\tOEMTEXT -> UNICODETEXT\n"); |
| 574 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 575 | } |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 576 | if (!foundData) |
| 577 | { |
| 578 | if ((wFormat == CF_TEXT) || (wFormat == CF_OEMTEXT)) |
| 579 | { |
| 580 | lpSource = &ClipFormats[CF_UNICODETEXT-1]; |
| 581 | lpTarget = __lookup_format( ClipFormats, wFormat ); |
| 582 | } |
| 583 | else |
| 584 | { |
| 585 | lpSource = __lookup_format( ClipFormats, wFormat ); |
| 586 | lpTarget = lpSource; |
| 587 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /* First render the source text format */ |
| 591 | if ( !lpSource || !CLIPBOARD_RenderFormat(lpSource) ) return NULL; |
| 592 | |
| 593 | /* Convert to the desired target text format, if necessary */ |
| 594 | if( lpTarget != lpSource && !lpTarget->hData16 && !lpTarget->hData32 ) |
| 595 | { |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 596 | INT src_chars, dst_chars, alloc_size; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 597 | LPCSTR lpstrS; |
| 598 | LPSTR lpstrT; |
| 599 | |
| 600 | if (lpSource->hData32) |
| 601 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 602 | lpstrS = (LPSTR)GlobalLock(lpSource->hData32); |
| 603 | } |
| 604 | else |
| 605 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 606 | lpstrS = (LPSTR)GlobalLock16(lpSource->hData16); |
| 607 | } |
| 608 | |
| 609 | if( !lpstrS ) return NULL; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 610 | |
| 611 | /* Text always NULL terminated */ |
| 612 | if(lpSource->wFormatID == CF_UNICODETEXT) |
Aric Stewart | 096c1ae | 2001-02-20 01:54:08 +0000 | [diff] [blame] | 613 | src_chars = strlenW((LPCWSTR)lpstrS)+1; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 614 | else |
Aric Stewart | 096c1ae | 2001-02-20 01:54:08 +0000 | [diff] [blame] | 615 | src_chars = strlen(lpstrS)+1; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 616 | |
| 617 | /* Calculate number of characters in the destination buffer */ |
| 618 | dst_chars = CLIPBOARD_ConvertText(lpSource->wFormatID, lpstrS, src_chars, |
| 619 | lpTarget->wFormatID, NULL, 0); |
| 620 | if(!dst_chars) return NULL; |
| 621 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 622 | TRACE("\tconverting from '%s' to '%s', %i chars\n", |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 623 | lpSource->Name, lpTarget->Name, src_chars); |
| 624 | |
| 625 | /* Convert characters to bytes */ |
| 626 | if(lpTarget->wFormatID == CF_UNICODETEXT) |
| 627 | alloc_size = dst_chars * sizeof(WCHAR); |
| 628 | else |
| 629 | alloc_size = dst_chars; |
| 630 | |
| 631 | lpTarget->hData32 = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, alloc_size); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 632 | lpstrT = (LPSTR)GlobalLock(lpTarget->hData32); |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 633 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 634 | if( lpstrT ) |
| 635 | { |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 636 | CLIPBOARD_ConvertText(lpSource->wFormatID, lpstrS, src_chars, |
| 637 | lpTarget->wFormatID, lpstrT, dst_chars); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 638 | GlobalUnlock(lpTarget->hData32); |
| 639 | } |
| 640 | else |
| 641 | lpTarget->hData32 = 0; |
| 642 | |
| 643 | /* Unlock source */ |
| 644 | if (lpSource->hData32) |
| 645 | GlobalUnlock(lpSource->hData32); |
| 646 | else |
| 647 | GlobalUnlock16(lpSource->hData16); |
| 648 | } |
| 649 | |
| 650 | return (lpTarget->hData16 || lpTarget->hData32) ? lpTarget : NULL; |
| 651 | } |
| 652 | |
| 653 | /************************************************************************** |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 654 | * CLIPBOARD_EnumClipboardFormats (internal) |
| 655 | */ |
| 656 | static UINT CLIPBOARD_EnumClipboardFormats( UINT wFormat ) |
| 657 | { |
| 658 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
| 659 | BOOL bFormatPresent; |
| 660 | |
| 661 | if (wFormat == 0) /* start from the beginning */ |
| 662 | lpFormat = ClipFormats; |
| 663 | else |
| 664 | { |
| 665 | /* walk up to the specified format record */ |
| 666 | |
| 667 | if( !(lpFormat = __lookup_format( lpFormat, wFormat )) ) |
| 668 | return 0; |
| 669 | lpFormat = lpFormat->NextFormat; /* right */ |
| 670 | } |
| 671 | |
| 672 | while(TRUE) |
| 673 | { |
| 674 | if (lpFormat == NULL) return 0; |
| 675 | |
| 676 | if(CLIPBOARD_IsPresent(lpFormat->wFormatID)) |
| 677 | break; |
| 678 | |
| 679 | /* Query the driver if not yet in the cache */ |
| 680 | if (!USER_Driver.pIsSelectionOwner()) |
| 681 | { |
| 682 | if(lpFormat->wFormatID == CF_UNICODETEXT || |
| 683 | lpFormat->wFormatID == CF_TEXT || |
| 684 | lpFormat->wFormatID == CF_OEMTEXT) |
| 685 | { |
| 686 | if(USER_Driver.pIsClipboardFormatAvailable(CF_UNICODETEXT) || |
| 687 | USER_Driver.pIsClipboardFormatAvailable(CF_TEXT) || |
| 688 | USER_Driver.pIsClipboardFormatAvailable(CF_OEMTEXT)) |
| 689 | bFormatPresent = TRUE; |
| 690 | else |
| 691 | bFormatPresent = FALSE; |
| 692 | } |
| 693 | else |
| 694 | bFormatPresent = USER_Driver.pIsClipboardFormatAvailable(lpFormat->wFormatID); |
| 695 | |
| 696 | if(bFormatPresent) |
| 697 | break; |
| 698 | } |
| 699 | |
| 700 | lpFormat = lpFormat->NextFormat; |
| 701 | } |
| 702 | |
| 703 | TRACE("Next available format %d\n", lpFormat->wFormatID); |
| 704 | |
| 705 | return lpFormat->wFormatID; |
| 706 | } |
| 707 | |
| 708 | |
| 709 | /************************************************************************** |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 710 | * WIN32 Clipboard implementation |
| 711 | **************************************************************************/ |
| 712 | |
| 713 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 714 | * OpenClipboard (USER32.@) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 715 | * |
| 716 | * Note: Netscape uses NULL hWnd to open the clipboard. |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 717 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 718 | BOOL WINAPI OpenClipboard( HWND hWnd ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 719 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 720 | BOOL bRet; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 721 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 722 | TRACE("(%04x)...\n", hWnd); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 723 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 724 | if (!hClipLock) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 725 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 726 | hClipLock = GetCurrentTask(); |
| 727 | |
| 728 | /* Save current user of the clipboard */ |
Alexandre Julliard | 37a4639 | 2001-09-12 17:19:13 +0000 | [diff] [blame] | 729 | hWndClipWindow = WIN_GetFullHandle( hWnd ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 730 | bCBHasChanged = FALSE; |
| 731 | bRet = TRUE; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 732 | } |
| 733 | else bRet = FALSE; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 734 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 735 | TRACE(" returning %i\n", bRet); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 736 | return bRet; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
| 740 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 741 | * CloseClipboard (USER.138) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 742 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 743 | BOOL16 WINAPI CloseClipboard16(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 744 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 745 | return CloseClipboard(); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | |
| 749 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 750 | * CloseClipboard (USER32.@) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 751 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 752 | BOOL WINAPI CloseClipboard(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 753 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 754 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 755 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 756 | if (hClipLock == GetCurrentTask()) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 757 | { |
| 758 | hWndClipWindow = 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 759 | |
Alexandre Julliard | cb25e25 | 2001-08-08 23:28:42 +0000 | [diff] [blame] | 760 | if (bCBHasChanged && hWndViewer) SendMessageW( hWndViewer, WM_DRAWCLIPBOARD, 0, 0 ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 761 | hClipLock = 0; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 762 | } |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 763 | return TRUE; |
| 764 | } |
| 765 | |
| 766 | |
| 767 | /************************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 768 | * EmptyClipboard (USER.139) |
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 | BOOL16 WINAPI EmptyClipboard16(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 771 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 772 | return EmptyClipboard(); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
| 776 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 777 | * EmptyClipboard (USER32.@) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 778 | * Empties and acquires ownership of the clipboard |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 779 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 780 | BOOL WINAPI EmptyClipboard(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 781 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 782 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 783 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 784 | if (hClipLock != GetCurrentTask()) |
| 785 | { |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 786 | WARN("Clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 787 | return FALSE; |
| 788 | } |
| 789 | |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 790 | /* destroy private objects */ |
| 791 | |
Alexandre Julliard | cb25e25 | 2001-08-08 23:28:42 +0000 | [diff] [blame] | 792 | if (hWndClipOwner) SendMessageW( hWndClipOwner, WM_DESTROYCLIPBOARD, 0, 0 ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 793 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 794 | /* empty the cache */ |
| 795 | CLIPBOARD_EmptyCache(TRUE); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 796 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 797 | /* Assign ownership of the clipboard to the current client */ |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 798 | hWndClipOwner = hWndClipWindow; |
| 799 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 800 | /* Save the current task */ |
| 801 | hTaskClipOwner = GetCurrentTask(); |
| 802 | |
| 803 | /* Tell the driver to acquire the selection */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 804 | USER_Driver.pAcquireClipboard(); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 805 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 806 | return TRUE; |
| 807 | } |
| 808 | |
| 809 | |
| 810 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 811 | * GetClipboardOwner (USER32.@) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 812 | * 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] | 813 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 814 | HWND WINAPI GetClipboardOwner(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 815 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 816 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 817 | return hWndClipOwner; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | |
| 821 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 822 | * SetClipboardData (USER.141) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 823 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 824 | HANDLE16 WINAPI SetClipboardData16( UINT16 wFormat, HANDLE16 hData ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 825 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 826 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 827 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 828 | TRACE("(%04X, %04x) !\n", wFormat, hData); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 829 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 830 | /* NOTE: If the hData is zero and current owner doesn't match |
| 831 | * the window that opened the clipboard then this application |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 832 | * is screwed because WM_RENDERFORMAT will go to the owner. |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 833 | * (to become the owner it must call EmptyClipboard() before |
| 834 | * adding new data). |
| 835 | */ |
| 836 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 837 | if( CLIPBOARD_IsLocked() || !lpFormat || |
| 838 | (!hData && (!hWndClipOwner || (hWndClipOwner != hWndClipWindow))) ) |
| 839 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 840 | WARN("Invalid hData or clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 841 | return 0; |
| 842 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 843 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 844 | /* Pass on the request to the driver */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 845 | USER_Driver.pSetClipboardData(wFormat); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 846 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 847 | if ( lpFormat->wDataPresent || lpFormat->hData16 || lpFormat->hData32 ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 848 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 849 | CLIPBOARD_DeleteRecord(lpFormat, TRUE); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 850 | |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 851 | /* delete existing CF_UNICODETEXT/CF_TEXT/CF_OEMTEXT aliases */ |
| 852 | if(wFormat == CF_UNICODETEXT) |
| 853 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 854 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE); |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 855 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1], TRUE); |
| 856 | } |
| 857 | else if(wFormat == CF_TEXT) |
| 858 | { |
| 859 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_UNICODETEXT-1], TRUE); |
| 860 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1], TRUE); |
| 861 | } |
| 862 | else if(wFormat == CF_OEMTEXT) |
| 863 | { |
| 864 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_UNICODETEXT-1], TRUE); |
| 865 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE); |
| 866 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 867 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 868 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 869 | bCBHasChanged = TRUE; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 870 | lpFormat->wDataPresent = 1; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 871 | lpFormat->hData16 = hData; /* 0 is legal, see WM_RENDERFORMAT */ |
| 872 | lpFormat->hData32 = 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 873 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 874 | return lpFormat->hData16; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 877 | |
| 878 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 879 | * SetClipboardData (USER32.@) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 880 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 881 | HANDLE WINAPI SetClipboardData( UINT wFormat, HANDLE hData ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 882 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 883 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 884 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 885 | TRACE("(%08X, %08x) !\n", wFormat, hData); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 886 | |
| 887 | /* NOTE: If the hData is zero and current owner doesn't match |
| 888 | * the window that opened the clipboard then this application |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 889 | * is screwed because WM_RENDERFORMAT will go to the owner. |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 890 | * (to become the owner it must call EmptyClipboard() before |
| 891 | * adding new data). |
| 892 | */ |
| 893 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 894 | if( CLIPBOARD_IsLocked() || !lpFormat || |
| 895 | (!hData && (!hWndClipOwner || (hWndClipOwner != hWndClipWindow))) ) |
| 896 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 897 | WARN("Invalid hData or clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 898 | return 0; |
| 899 | } |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 900 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 901 | /* Tell the driver to acquire the selection */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 902 | USER_Driver.pAcquireClipboard(); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 903 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 904 | if ( lpFormat->wDataPresent && |
| 905 | (lpFormat->hData16 || lpFormat->hData32) ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 906 | { |
| 907 | CLIPBOARD_DeleteRecord(lpFormat, TRUE); |
| 908 | |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 909 | /* delete existing CF_UNICODETEXT/CF_TEXT/CF_OEMTEXT aliases */ |
| 910 | if(wFormat == CF_UNICODETEXT) |
| 911 | { |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 912 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE); |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 913 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1], TRUE); |
| 914 | } |
| 915 | else if(wFormat == CF_TEXT) |
| 916 | { |
| 917 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_UNICODETEXT-1], TRUE); |
| 918 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1], TRUE); |
| 919 | } |
| 920 | else if(wFormat == CF_OEMTEXT) |
| 921 | { |
| 922 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_UNICODETEXT-1], TRUE); |
| 923 | CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE); |
| 924 | } |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | bCBHasChanged = TRUE; |
| 928 | lpFormat->wDataPresent = 1; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 929 | lpFormat->hDataSrc32 = hData; /* Save the source handle */ |
| 930 | |
| 931 | /* |
| 932 | * Make a shared duplicate if the memory is not shared |
| 933 | * TODO: What should be done for non-memory objects |
| 934 | */ |
| 935 | if ( CLIPBOARD_IsMemoryObject(wFormat) && hData && !(GlobalFlags(hData) & GMEM_DDESHARE) ) |
| 936 | lpFormat->hData32 = CLIPBOARD_GlobalDupMem( hData ); |
| 937 | else |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 938 | lpFormat->hData32 = hData; /* 0 is legal, see WM_RENDERFORMAT */ |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 939 | |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 940 | lpFormat->hData16 = 0; |
| 941 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 942 | return lpFormat->hData32; /* Should we return lpFormat->hDataSrc32 */ |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 946 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 947 | * GetClipboardData (USER.142) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 948 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 949 | HANDLE16 WINAPI GetClipboardData16( UINT16 wFormat ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 950 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 951 | LPWINE_CLIPFORMAT lpRender = ClipFormats; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 952 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 953 | TRACE("(%04X)\n", wFormat); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 954 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 955 | if (CLIPBOARD_IsLocked()) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 956 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 957 | WARN("Clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 958 | return 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 959 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 960 | |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 961 | if( wFormat == CF_UNICODETEXT || wFormat == CF_TEXT || wFormat == CF_OEMTEXT ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 962 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 963 | lpRender = CLIPBOARD_RenderText(wFormat); |
| 964 | if ( !lpRender ) return 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 965 | } |
| 966 | else |
| 967 | { |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 968 | lpRender = __lookup_format( ClipFormats, wFormat ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 969 | if( !lpRender || !CLIPBOARD_RenderFormat(lpRender) ) return 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 972 | /* Convert between 32 -> 16 bit data, if necessary */ |
Francis Beaudet | 56ab55d | 1999-10-24 20:22:24 +0000 | [diff] [blame] | 973 | if( lpRender->hData32 && !lpRender->hData16 |
| 974 | && CLIPBOARD_IsMemoryObject(wFormat) ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 975 | { |
| 976 | int size; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 977 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 978 | size = sizeof( METAFILEPICT16 ); |
| 979 | else |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 980 | size = GlobalSize(lpRender->hData32); |
| 981 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 982 | lpRender->hData16 = GlobalAlloc16(GMEM_ZEROINIT, size); |
| 983 | if( !lpRender->hData16 ) |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 984 | ERR("(%04X) -- not enough memory in 16b heap\n", wFormat); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 985 | else |
| 986 | { |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 987 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
| 988 | { |
| 989 | FIXME("\timplement function CopyMetaFilePict32to16\n"); |
| 990 | FIXME("\tin the appropriate file.\n"); |
| 991 | #ifdef SOMEONE_IMPLEMENTED_ME |
| 992 | CopyMetaFilePict32to16( GlobalLock16(lpRender->hData16), |
| 993 | GlobalLock(lpRender->hData32) ); |
| 994 | #endif |
| 995 | } |
| 996 | else |
| 997 | { |
| 998 | memcpy( GlobalLock16(lpRender->hData16), |
| 999 | GlobalLock(lpRender->hData32), |
| 1000 | size ); |
| 1001 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1002 | GlobalUnlock16(lpRender->hData16); |
| 1003 | GlobalUnlock(lpRender->hData32); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1007 | TRACE("\treturning %04x (type %i)\n", |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1008 | lpRender->hData16, lpRender->wFormatID); |
| 1009 | return lpRender->hData16; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | |
| 1013 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1014 | * GetClipboardData (USER32.@) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1015 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1016 | HANDLE WINAPI GetClipboardData( UINT wFormat ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1017 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1018 | LPWINE_CLIPFORMAT lpRender = ClipFormats; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1019 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1020 | TRACE("(%08X)\n", wFormat); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1021 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1022 | if (CLIPBOARD_IsLocked()) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1023 | { |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 1024 | WARN("Clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1025 | return 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1026 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1027 | |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 1028 | if( wFormat == CF_UNICODETEXT || wFormat == CF_TEXT || wFormat == CF_OEMTEXT ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1029 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1030 | lpRender = CLIPBOARD_RenderText(wFormat); |
| 1031 | if ( !lpRender ) return 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1032 | } |
| 1033 | else |
| 1034 | { |
| 1035 | lpRender = __lookup_format( ClipFormats, wFormat ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1036 | if( !lpRender || !CLIPBOARD_RenderFormat(lpRender) ) return 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1039 | /* Convert between 16 -> 32 bit data, if necessary */ |
Francis Beaudet | 56ab55d | 1999-10-24 20:22:24 +0000 | [diff] [blame] | 1040 | if( lpRender->hData16 && !lpRender->hData32 |
| 1041 | && CLIPBOARD_IsMemoryObject(wFormat) ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1042 | { |
| 1043 | int size; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1044 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1045 | size = sizeof( METAFILEPICT ); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1046 | else |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1047 | size = GlobalSize16(lpRender->hData16); |
| 1048 | lpRender->hData32 = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1049 | size); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1050 | if( lpRender->wFormatID == CF_METAFILEPICT ) |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1051 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1052 | FIXME("\timplement function CopyMetaFilePict16to32\n"); |
| 1053 | FIXME("\tin the appropriate file.\n"); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1054 | #ifdef SOMEONE_IMPLEMENTED_ME |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1055 | CopyMetaFilePict16to32( GlobalLock16(lpRender->hData32), |
| 1056 | GlobalLock(lpRender->hData16) ); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1057 | #endif |
| 1058 | } |
| 1059 | else |
| 1060 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1061 | memcpy( GlobalLock(lpRender->hData32), |
| 1062 | GlobalLock16(lpRender->hData16), |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1063 | size ); |
| 1064 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1065 | GlobalUnlock(lpRender->hData32); |
| 1066 | GlobalUnlock16(lpRender->hData16); |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1069 | TRACE("\treturning %04x (type %i)\n", |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1070 | lpRender->hData32, lpRender->wFormatID); |
| 1071 | return lpRender->hData32; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1074 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1075 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1076 | * CountClipboardFormats (USER.143) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1077 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1078 | INT16 WINAPI CountClipboardFormats16(void) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1079 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1080 | return CountClipboardFormats(); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | |
| 1084 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1085 | * CountClipboardFormats (USER32.@) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1086 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1087 | INT WINAPI CountClipboardFormats(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1088 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1089 | INT FormatCount = 0; |
| 1090 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1091 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1092 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1093 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1094 | while(TRUE) |
| 1095 | { |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1096 | if (lpFormat == NULL) break; |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 1097 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1098 | if( lpFormat->wFormatID != CF_TEXT ) /* Don't count CF_TEXT */ |
| 1099 | { |
| 1100 | /* |
| 1101 | * The format is available if either: |
| 1102 | * 1. The data is already in the cache. |
| 1103 | * 2. The selection is not owned by us(WINE) and the data is |
| 1104 | * available to the clipboard driver. |
| 1105 | */ |
| 1106 | if ( lpFormat->wDataPresent || |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 1107 | ( !USER_Driver.pIsSelectionOwner() |
| 1108 | && USER_Driver.pIsClipboardFormatAvailable( lpFormat->wFormatID ) ) ) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1109 | { |
Juergen Schmied | 1c35dae | 2000-02-07 16:22:57 +0000 | [diff] [blame] | 1110 | TRACE("\tdata found for format 0x%04x(%s)\n", |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1111 | lpFormat->wFormatID, CLIPBOARD_GetFormatName(lpFormat->wFormatID)); |
| 1112 | FormatCount++; |
| 1113 | } |
| 1114 | } |
| 1115 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1116 | lpFormat = lpFormat->NextFormat; |
| 1117 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1118 | |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 1119 | /* these are equivalent, adjust the total */ |
| 1120 | FormatCount += (ClipFormats[CF_UNICODETEXT-1].wDataPresent || |
| 1121 | ClipFormats[CF_TEXT-1].wDataPresent || |
| 1122 | ClipFormats[CF_OEMTEXT-1].wDataPresent) ? 1 : 0; |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 1123 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1124 | TRACE("\ttotal %d\n", FormatCount); |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1125 | return FormatCount; |
| 1126 | } |
| 1127 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1128 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1129 | * EnumClipboardFormats (USER.144) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1130 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1131 | UINT16 WINAPI EnumClipboardFormats16( UINT16 wFormat ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1132 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1133 | return EnumClipboardFormats( wFormat ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | |
| 1137 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1138 | * EnumClipboardFormats (USER32.@) |
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 | UINT WINAPI EnumClipboardFormats( UINT wFormat ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1141 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1142 | TRACE("(%04X)\n", wFormat); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1143 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1144 | if (CLIPBOARD_IsLocked()) |
| 1145 | { |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 1146 | WARN("Clipboard not opened by calling task!\n"); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1147 | return 0; |
| 1148 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1149 | |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 1150 | return CLIPBOARD_EnumClipboardFormats(wFormat); |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | /************************************************************************** |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 1155 | * RegisterClipboardFormatA (USER32.@) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1156 | */ |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 1157 | UINT WINAPI RegisterClipboardFormatA( LPCSTR FormatName ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1158 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1159 | LPWINE_CLIPFORMAT lpNewFormat; |
| 1160 | LPWINE_CLIPFORMAT lpFormat = ClipFormats; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1161 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1162 | if (FormatName == NULL) return 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1163 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1164 | TRACE("('%s') !\n", FormatName); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1165 | |
| 1166 | /* walk format chain to see if it's already registered */ |
| 1167 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1168 | while(TRUE) |
| 1169 | { |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1170 | if ( !strcmp(lpFormat->Name,FormatName) ) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1171 | { |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1172 | lpFormat->wRefCount++; |
| 1173 | return lpFormat->wFormatID; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1174 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1175 | |
| 1176 | if ( lpFormat->NextFormat == NULL ) break; |
| 1177 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1178 | lpFormat = lpFormat->NextFormat; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1179 | } |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1180 | |
| 1181 | /* allocate storage for new format entry */ |
| 1182 | |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 1183 | lpNewFormat = (LPWINE_CLIPFORMAT)HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CLIPFORMAT)); |
| 1184 | if(lpNewFormat == NULL) { |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 1185 | WARN("No more memory for a new format!\n"); |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 1186 | return 0; |
| 1187 | } |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1188 | lpFormat->NextFormat = lpNewFormat; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1189 | lpNewFormat->wFormatID = LastRegFormat; |
| 1190 | lpNewFormat->wRefCount = 1; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1191 | |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 1192 | if (!(lpNewFormat->Name = HeapAlloc(GetProcessHeap(), 0, strlen(FormatName)+1 ))) |
| 1193 | { |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 1194 | WARN("No more memory for the new format name!\n"); |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 1195 | HeapFree(GetProcessHeap(), 0, lpNewFormat); |
| 1196 | return 0; |
| 1197 | } |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 1198 | strcpy( lpNewFormat->Name, FormatName ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1199 | |
| 1200 | lpNewFormat->wDataPresent = 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1201 | lpNewFormat->hData16 = 0; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1202 | lpNewFormat->hDataSrc32 = 0; |
Pascal Cuoq | 724f190 | 1998-10-26 10:58:16 +0000 | [diff] [blame] | 1203 | lpNewFormat->hData32 = 0; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1204 | lpNewFormat->drvData = 0; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1205 | lpNewFormat->PrevFormat = lpFormat; |
| 1206 | lpNewFormat->NextFormat = NULL; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1207 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1208 | /* Pass on the registration request to the driver */ |
Alexandre Julliard | 42d20f9 | 2000-08-10 01:16:19 +0000 | [diff] [blame] | 1209 | USER_Driver.pRegisterClipboardFormat( FormatName ); |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1210 | |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1211 | return LastRegFormat++; |
| 1212 | } |
| 1213 | |
| 1214 | |
| 1215 | /************************************************************************** |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 1216 | * RegisterClipboardFormat (USER.145) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1217 | */ |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 1218 | UINT16 WINAPI RegisterClipboardFormat16( LPCSTR FormatName ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1219 | { |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 1220 | return RegisterClipboardFormatA( FormatName ); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1225 | * RegisterClipboardFormatW (USER32.@) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1226 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1227 | UINT WINAPI RegisterClipboardFormatW( LPCWSTR formatName ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1228 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1229 | LPSTR aFormat = HEAP_strdupWtoA( GetProcessHeap(), 0, formatName ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1230 | UINT ret = RegisterClipboardFormatA( aFormat ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1231 | HeapFree( GetProcessHeap(), 0, aFormat ); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1232 | return ret; |
| 1233 | } |
| 1234 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1235 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1236 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1237 | * GetClipboardFormatName (USER.146) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1238 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1239 | INT16 WINAPI GetClipboardFormatName16( UINT16 wFormat, LPSTR retStr, INT16 maxlen ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1240 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1241 | return GetClipboardFormatNameA( wFormat, retStr, maxlen ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1246 | * GetClipboardFormatNameA (USER32.@) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1247 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1248 | INT WINAPI GetClipboardFormatNameA( UINT wFormat, LPSTR retStr, INT maxlen ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1249 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1250 | LPWINE_CLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1251 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1252 | TRACE("(%04X, %p, %d) !\n", wFormat, retStr, maxlen); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1253 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1254 | if (lpFormat == NULL || lpFormat->Name == NULL || |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1255 | lpFormat->wFormatID < CF_REGFORMATBASE) return 0; |
| 1256 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1257 | TRACE("Name='%s' !\n", lpFormat->Name); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1258 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1259 | lstrcpynA( retStr, lpFormat->Name, maxlen ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1260 | return strlen(retStr); |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1265 | * GetClipboardFormatNameW (USER32.@) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1266 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1267 | INT WINAPI GetClipboardFormatNameW( UINT wFormat, LPWSTR retStr, INT maxlen ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1268 | { |
Dimitrie O. Paun | 4d48dd3 | 2000-04-30 12:22:18 +0000 | [diff] [blame] | 1269 | INT ret; |
| 1270 | LPSTR p = HeapAlloc( GetProcessHeap(), 0, maxlen ); |
| 1271 | if(p == NULL) return 0; /* FIXME: is this the correct failure value? */ |
| 1272 | |
| 1273 | ret = GetClipboardFormatNameA( wFormat, p, maxlen ); |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 1274 | |
| 1275 | if (maxlen > 0 && !MultiByteToWideChar( CP_ACP, 0, p, -1, retStr, maxlen )) |
| 1276 | retStr[maxlen-1] = 0; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1277 | HeapFree( GetProcessHeap(), 0, p ); |
| 1278 | return ret; |
| 1279 | } |
| 1280 | |
| 1281 | |
| 1282 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1283 | * SetClipboardViewer (USER32.@) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1284 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1285 | HWND WINAPI SetClipboardViewer( HWND hWnd ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1286 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1287 | HWND hwndPrev = hWndViewer; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1288 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1289 | TRACE("(%04x): returning %04x\n", hWnd, hwndPrev); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1290 | |
Alexandre Julliard | 37a4639 | 2001-09-12 17:19:13 +0000 | [diff] [blame] | 1291 | hWndViewer = WIN_GetFullHandle( hWnd ); |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 1292 | return hwndPrev; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1297 | * GetClipboardViewer (USER32.@) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1298 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1299 | HWND WINAPI GetClipboardViewer(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1300 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1301 | TRACE("()\n"); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 1302 | return hWndViewer; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1307 | * ChangeClipboardChain (USER32.@) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1308 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1309 | BOOL WINAPI ChangeClipboardChain(HWND hWnd, HWND hWndNext) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1310 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1311 | BOOL bRet = 0; |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 1312 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1313 | FIXME("(0x%04x, 0x%04x): stub?\n", hWnd, hWndNext); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1314 | |
| 1315 | if( hWndViewer ) |
Alexandre Julliard | cb25e25 | 2001-08-08 23:28:42 +0000 | [diff] [blame] | 1316 | bRet = !SendMessageW( hWndViewer, WM_CHANGECBCHAIN, (WPARAM)hWnd, (LPARAM)hWndNext ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1317 | else |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1318 | WARN("hWndViewer is lost\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1319 | |
Alexandre Julliard | f44bbb8 | 2001-09-14 00:24:39 +0000 | [diff] [blame] | 1320 | if( WIN_GetFullHandle(hWnd) == hWndViewer ) hWndViewer = WIN_GetFullHandle( hWndNext ); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1321 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1322 | return bRet; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | /************************************************************************** |
Patrik Stridvall | 0c61028 | 2001-01-25 22:22:21 +0000 | [diff] [blame] | 1327 | * IsClipboardFormatAvailable (USER.193) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1328 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1329 | BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1330 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1331 | return IsClipboardFormatAvailable( wFormat ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1336 | * IsClipboardFormatAvailable (USER32.@) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1337 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1338 | BOOL WINAPI IsClipboardFormatAvailable( UINT wFormat ) |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1339 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1340 | BOOL bRet; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1341 | |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1342 | if (wFormat == 0) /* Reject this case quickly */ |
| 1343 | bRet = FALSE; |
Dmitry Timoshkov | 1df0d36 | 2000-12-11 01:09:56 +0000 | [diff] [blame] | 1344 | else |
Gerard Patel | 9289a5d | 2000-12-22 23:26:18 +0000 | [diff] [blame] | 1345 | { |
| 1346 | UINT iret = CLIPBOARD_EnumClipboardFormats(wFormat - 1); |
| 1347 | if ((wFormat == CF_TEXT) || (wFormat == CF_OEMTEXT) || (wFormat == CF_UNICODETEXT)) |
| 1348 | bRet = ((iret == CF_TEXT) || (iret == CF_OEMTEXT) || (iret == CF_UNICODETEXT)); |
| 1349 | else |
| 1350 | bRet = iret == wFormat; |
| 1351 | } |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1352 | TRACE("(%04X)- ret(%d)\n", wFormat, bRet); |
| 1353 | return bRet; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1358 | * GetOpenClipboardWindow (USER32.@) |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1359 | * FIXME: This wont work if an external app owns the selection |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1360 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1361 | HWND WINAPI GetOpenClipboardWindow(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1362 | { |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1363 | TRACE("()\n"); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 1364 | return hWndClipWindow; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1369 | * GetPriorityClipboardFormat (USER32.@) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1370 | */ |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 1371 | INT WINAPI GetPriorityClipboardFormat( UINT *list, INT nCount ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1372 | { |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 1373 | int i; |
Noel Borthwick | 2970067 | 1999-09-03 15:17:57 +0000 | [diff] [blame] | 1374 | TRACE("()\n"); |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 1375 | |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 1376 | if(CountClipboardFormats() == 0) return 0; |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 1377 | |
Alexandre Julliard | d23a82b | 2001-09-19 20:37:04 +0000 | [diff] [blame] | 1378 | for (i = 0; i < nCount; i++) |
| 1379 | if (IsClipboardFormatAvailable( list[i] )) return list[i]; |
Alexandre Julliard | 0623a6f | 1998-01-18 18:01:49 +0000 | [diff] [blame] | 1380 | return -1; |
Alexandre Julliard | fb9a919 | 1994-03-01 19:48:04 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame] | 1383 | |
| 1384 | /************************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 1385 | * GetClipboardSequenceNumber (USER32.@) |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame] | 1386 | * Supported on Win2k/Win98 |
| 1387 | * MSDN: Windows clipboard code keeps a serial number for the clipboard |
| 1388 | * for each window station. The number is incremented whenever the |
| 1389 | * contents change or are emptied. |
| 1390 | * If you do not have WINSTA_ACCESSCLIPBOARD then the function returns 0 |
| 1391 | */ |
| 1392 | DWORD WINAPI GetClipboardSequenceNumber(VOID) |
| 1393 | { |
| 1394 | FIXME("Returning 0, see windows/clipboard.c\n"); |
| 1395 | /* FIXME: Use serial numbers */ |
| 1396 | return 0; |
| 1397 | } |