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