mfmediaengine: Remove unnecessary import library.
[wine.git] / dlls / win32u / clipboard.c
blobdca01708803a1a4c1dad57e2eb285a1e471c1b63
1 /*
2 * WIN32 clipboard implementation
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Alex Korobka
6 * Copyright 1999 Noel Borthwick
7 * Copyright 2003 Ulrich Czekalla for CodeWeavers
8 * Copyright 2016 Alexandre Julliard
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #if 0
27 #pragma makedep unix
28 #endif
30 #include "win32u_private.h"
31 #include "wine/server.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(clipboard);
37 /* get a debug string for a format id */
38 static const char *debugstr_format( UINT id )
40 WCHAR buffer[256];
41 DWORD le = GetLastError();
42 BOOL r = NtUserGetClipboardFormatName( id, buffer, ARRAYSIZE(buffer) );
43 SetLastError(le);
45 if (r)
46 return wine_dbg_sprintf( "%04x %s", id, debugstr_w(buffer) );
48 switch (id)
50 #define BUILTIN(id) case id: return #id;
51 BUILTIN(CF_TEXT)
52 BUILTIN(CF_BITMAP)
53 BUILTIN(CF_METAFILEPICT)
54 BUILTIN(CF_SYLK)
55 BUILTIN(CF_DIF)
56 BUILTIN(CF_TIFF)
57 BUILTIN(CF_OEMTEXT)
58 BUILTIN(CF_DIB)
59 BUILTIN(CF_PALETTE)
60 BUILTIN(CF_PENDATA)
61 BUILTIN(CF_RIFF)
62 BUILTIN(CF_WAVE)
63 BUILTIN(CF_UNICODETEXT)
64 BUILTIN(CF_ENHMETAFILE)
65 BUILTIN(CF_HDROP)
66 BUILTIN(CF_LOCALE)
67 BUILTIN(CF_DIBV5)
68 BUILTIN(CF_OWNERDISPLAY)
69 BUILTIN(CF_DSPTEXT)
70 BUILTIN(CF_DSPBITMAP)
71 BUILTIN(CF_DSPMETAFILEPICT)
72 BUILTIN(CF_DSPENHMETAFILE)
73 #undef BUILTIN
74 default: return wine_dbg_sprintf( "%04x", id );
78 /**************************************************************************
79 * NtUserCountClipboardFormats (win32u.@)
81 INT WINAPI NtUserCountClipboardFormats(void)
83 INT count = 0;
85 user_driver->pUpdateClipboard();
87 SERVER_START_REQ( get_clipboard_formats )
89 wine_server_call( req );
90 count = reply->count;
92 SERVER_END_REQ;
94 TRACE( "returning %d\n", count );
95 return count;
98 /**************************************************************************
99 * NtUserIsClipboardFormatAvailable (win32u.@)
101 BOOL WINAPI NtUserIsClipboardFormatAvailable( UINT format )
103 BOOL ret = FALSE;
105 if (!format) return FALSE;
107 user_driver->pUpdateClipboard();
109 SERVER_START_REQ( get_clipboard_formats )
111 req->format = format;
112 if (!wine_server_call_err( req )) ret = (reply->count > 0);
114 SERVER_END_REQ;
115 TRACE( "%s -> %u\n", debugstr_format( format ), ret );
116 return ret;
119 /**************************************************************************
120 * NtUserGetUpdatedClipboardFormats (win32u.@)
122 BOOL WINAPI NtUserGetUpdatedClipboardFormats( UINT *formats, UINT size, UINT *out_size )
124 BOOL ret;
126 if (!out_size)
128 SetLastError( ERROR_NOACCESS );
129 return FALSE;
132 user_driver->pUpdateClipboard();
134 SERVER_START_REQ( get_clipboard_formats )
136 if (formats) wine_server_set_reply( req, formats, size * sizeof(*formats) );
137 ret = !wine_server_call_err( req );
138 *out_size = reply->count;
140 SERVER_END_REQ;
142 TRACE( "%p %u returning %u formats, ret %u\n", formats, size, *out_size, ret );
143 if (!ret && !formats && *out_size) SetLastError( ERROR_NOACCESS );
144 return ret;
147 /**************************************************************************
148 * NtUserGetPriorityClipboardFormat (win32u.@)
150 INT WINAPI NtUserGetPriorityClipboardFormat( UINT *list, INT count )
152 int i;
154 TRACE( "%p %u\n", list, count );
156 if (NtUserCountClipboardFormats() == 0)
157 return 0;
159 for (i = 0; i < count; i++)
160 if (NtUserIsClipboardFormatAvailable( list[i] ))
161 return list[i];
163 return -1;
166 /**************************************************************************
167 * NtUserGetClipboardFormatName (win32u.@)
169 INT WINAPI NtUserGetClipboardFormatName( UINT format, WCHAR *buffer, INT maxlen )
171 char buf[sizeof(ATOM_BASIC_INFORMATION) + 255 * sizeof(WCHAR)];
172 ATOM_BASIC_INFORMATION *abi = (ATOM_BASIC_INFORMATION *)buf;
173 UINT length = 0;
175 if (format < MAXINTATOM || format > 0xffff) return 0;
176 if (maxlen <= 0)
178 SetLastError( ERROR_MORE_DATA );
179 return 0;
181 if (!set_ntstatus( NtQueryInformationAtom( format, AtomBasicInformation,
182 buf, sizeof(buf), NULL )))
183 return 0;
185 length = min( abi->NameLength / sizeof(WCHAR), maxlen - 1 );
186 if (length) memcpy( buffer, abi->Name, length * sizeof(WCHAR) );
187 buffer[length] = 0;
188 return length;
191 /**************************************************************************
192 * NtUserGetClipboardOwner (win32u.@)
194 HWND WINAPI NtUserGetClipboardOwner(void)
196 HWND owner = 0;
198 SERVER_START_REQ( get_clipboard_info )
200 if (!wine_server_call_err( req )) owner = wine_server_ptr_handle( reply->owner );
202 SERVER_END_REQ;
204 TRACE( "returning %p\n", owner );
205 return owner;
208 /**************************************************************************
209 * NtUserGetClipboardViewer (win32u.@)
211 HWND WINAPI NtUserGetClipboardViewer(void)
213 HWND viewer = 0;
215 SERVER_START_REQ( get_clipboard_info )
217 if (!wine_server_call_err( req )) viewer = wine_server_ptr_handle( reply->viewer );
219 SERVER_END_REQ;
221 TRACE( "returning %p\n", viewer );
222 return viewer;
225 /**************************************************************************
226 * NtUserGetOpenClipboardWindow (win32u.@)
228 HWND WINAPI NtUserGetOpenClipboardWindow(void)
230 HWND window = 0;
232 SERVER_START_REQ( get_clipboard_info )
234 if (!wine_server_call_err( req )) window = wine_server_ptr_handle( reply->window );
236 SERVER_END_REQ;
238 TRACE( "returning %p\n", window );
239 return window;
242 /**************************************************************************
243 * NtUserGetClipboardSequenceNumber (win32u.@)
245 DWORD WINAPI NtUserGetClipboardSequenceNumber(void)
247 DWORD seqno = 0;
249 SERVER_START_REQ( get_clipboard_info )
251 if (!wine_server_call_err( req )) seqno = reply->seqno;
253 SERVER_END_REQ;
255 TRACE( "returning %u\n", seqno );
256 return seqno;
259 /**************************************************************************
260 * NtUserAddClipboardFormatListener (win32u.@)
262 BOOL WINAPI NtUserAddClipboardFormatListener( HWND hwnd )
264 BOOL ret;
266 SERVER_START_REQ( add_clipboard_listener )
268 req->window = wine_server_user_handle( hwnd );
269 ret = !wine_server_call_err( req );
271 SERVER_END_REQ;
272 return ret;
275 /**************************************************************************
276 * NtUserRemoveClipboardFormatListener (win32u.@)
278 BOOL WINAPI NtUserRemoveClipboardFormatListener( HWND hwnd )
280 BOOL ret;
282 SERVER_START_REQ( remove_clipboard_listener )
284 req->window = wine_server_user_handle( hwnd );
285 ret = !wine_server_call_err( req );
287 SERVER_END_REQ;
288 return ret;