indent with astyle v1.15.3: --style=ansi -c -s3 -S --convert-tabs
[reactos.git] / reactos / subsys / win32k / ntuser / clipboard.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * PURPOSE: Clipboard routines
23 * FILE: subsys/win32k/ntuser/clipboard.c
24 * PROGRAMER: Filip Navara <xnavara@volny.cz>
25 */
26
27 #include <w32k.h>
28
29 #define NDEBUG
30 #include <debug.h>
31
32 #define CHECK_LOCK \
33 if (ClipboardThread && ClipboardThread != PsGetWin32Thread()) \
34 { \
35 SetLastWin32Error(ERROR_LOCKED); \
36 return FALSE; \
37 }
38
39 PW32THREAD ClipboardThread;
40 HWND ClipboardWindow;
41 HWND tempClipboardWindow;
42 HANDLE hCBData;
43 UINT uCBFormat;
44
45 ULONG FASTCALL
46 IntGetClipboardFormatName(UINT format, PUNICODE_STRING FormatName)
47 {
48
49 return IntGetAtomName((RTL_ATOM)format, FormatName->Buffer,
50 FormatName->MaximumLength);
51 }
52
53 UINT FASTCALL
54 IntEnumClipboardFormats(UINT format)
55 {
56
57 CHECK_LOCK
58
59 if (!hCBData)
60 return FALSE;
61 //UNIMPLEMENTED;
62 return 1;
63 }
64
65 BOOL STDCALL
66 NtUserOpenClipboard(HWND hWnd, DWORD Unknown1)
67 {
68 CHECK_LOCK
69
70 tempClipboardWindow = hWnd;
71 ClipboardThread = PsGetWin32Thread();
72 return TRUE;
73 }
74
75 BOOL STDCALL
76 NtUserCloseClipboard(VOID)
77 {
78 CHECK_LOCK
79
80 ClipboardWindow = 0;
81 ClipboardThread = NULL;
82 return TRUE;
83 }
84
85 /*
86 * @unimplemented
87 */
88 HWND STDCALL
89 NtUserGetOpenClipboardWindow(VOID)
90 {
91 /*
92 UNIMPLEMENTED
93 return 0;
94 */
95 return ClipboardWindow;
96 }
97
98 BOOL STDCALL
99 NtUserChangeClipboardChain(HWND hWndRemove, HWND hWndNewNext)
100 {
101 UNIMPLEMENTED
102 return 0;
103 }
104
105 DWORD STDCALL
106 NtUserCountClipboardFormats(VOID)
107 {
108 UNIMPLEMENTED
109 return 0;
110 }
111
112 DWORD STDCALL
113 NtUserEmptyClipboard(VOID)
114 {
115 CHECK_LOCK
116
117 // if (!hCBData)
118 // return FALSE;
119
120 // FIXME!
121 // GlobalUnlock(hCBData);
122 // GlobalFree(hCBData);
123 hCBData = NULL;
124 uCBFormat = 0;
125 ClipboardWindow = tempClipboardWindow;
126
127 return TRUE;
128 }
129
130 HANDLE STDCALL
131 NtUserGetClipboardData(UINT uFormat, DWORD Unknown1)
132 {
133 CHECK_LOCK
134
135 if ((uFormat==1 && uCBFormat==13) || (uFormat==13 && uCBFormat==1))
136 uCBFormat = uFormat;
137
138 if (uFormat != uCBFormat)
139 return FALSE;
140
141 return hCBData;
142 }
143
144 INT STDCALL
145 NtUserGetClipboardFormatName(UINT format, PUNICODE_STRING FormatName,
146 INT cchMaxCount)
147 {
148 NTSTATUS Status;
149 PWSTR Buf;
150 UNICODE_STRING SafeFormatName, BufFormatName;
151 ULONG Ret;
152
153 if((cchMaxCount < 1) || !FormatName)
154 {
155 SetLastWin32Error(ERROR_INVALID_PARAMETER);
156 return 0;
157 }
158
159 /* copy the FormatName UNICODE_STRING structure */
160 Status = MmCopyFromCaller(&SafeFormatName, FormatName, sizeof(UNICODE_STRING));
161 if(!NT_SUCCESS(Status))
162 {
163 SetLastNtError(Status);
164 return 0;
165 }
166
167 /* Allocate memory for the string */
168 Buf = ExAllocatePoolWithTag(PagedPool, cchMaxCount * sizeof(WCHAR), TAG_STRING);
169 if(!Buf)
170 {
171 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
172 return 0;
173 }
174
175 /* Setup internal unicode string */
176 BufFormatName.Length = 0;
177 BufFormatName.MaximumLength = min(cchMaxCount * sizeof(WCHAR), SafeFormatName.MaximumLength);
178 BufFormatName.Buffer = Buf;
179
180 if(BufFormatName.MaximumLength < sizeof(WCHAR))
181 {
182 ExFreePool(Buf);
183 SetLastWin32Error(ERROR_INVALID_PARAMETER);
184 return 0;
185 }
186
187 if (format >= 0xC000)
188 {
189 Ret = IntGetClipboardFormatName(format, &BufFormatName);
190 }
191 else
192 {
193 SetLastNtError(NO_ERROR);
194 return 0;
195 }
196
197 /* copy the UNICODE_STRING buffer back to the user */
198 Status = MmCopyToCaller(SafeFormatName.Buffer, BufFormatName.Buffer, BufFormatName.MaximumLength);
199 if(!NT_SUCCESS(Status))
200 {
201 ExFreePool(Buf);
202 SetLastNtError(Status);
203 return 0;
204 }
205
206 BufFormatName.MaximumLength = SafeFormatName.MaximumLength;
207 BufFormatName.Buffer = SafeFormatName.Buffer;
208
209 /* update the UNICODE_STRING structure (only the Length member should change) */
210 Status = MmCopyToCaller(FormatName, &BufFormatName, sizeof(UNICODE_STRING));
211 if(!NT_SUCCESS(Status))
212 {
213 ExFreePool(Buf);
214 SetLastNtError(Status);
215 return 0;
216 }
217
218 ExFreePool(Buf);
219 return Ret;
220 }
221
222 HWND STDCALL
223 NtUserGetClipboardOwner(VOID)
224 {
225 return ClipboardWindow;
226 }
227
228 DWORD STDCALL
229 NtUserGetClipboardSequenceNumber(VOID)
230 {
231 UNIMPLEMENTED
232 return 0;
233 }
234
235 HWND STDCALL
236 NtUserGetClipboardViewer(VOID)
237 {
238 UNIMPLEMENTED
239 return 0;
240 }
241
242 INT STDCALL
243 NtUserGetPriorityClipboardFormat(UINT *paFormatPriorityList, INT cFormats)
244 {
245 UNIMPLEMENTED
246 return 0;
247 }
248
249 BOOL STDCALL
250 NtUserIsClipboardFormatAvailable(UINT format)
251 {
252 //UNIMPLEMENTED
253
254 if (format != 1 && format != 13)
255 {
256 DbgPrint("Clipboard Format unavailable (%d)\n", format);
257 return FALSE;
258 }
259
260 if ((format==1 && uCBFormat==13) || (format==13 && uCBFormat==1))
261 uCBFormat = format;
262
263 if (format != uCBFormat)
264 return FALSE;
265
266 return TRUE;
267 }
268
269 //SetClipboardData(CF_UNICODETEXT, hdst);
270 HANDLE STDCALL
271 NtUserSetClipboardData(UINT uFormat, HANDLE hMem, DWORD Unknown2)
272 {
273 // LPVOID pMem;
274 CHECK_LOCK
275
276
277 if (uFormat != 1 && uFormat != 13)
278 {
279 DbgPrint("Clipboard unsupported format (%d)\n", uFormat);
280 return FALSE;
281 }
282
283 if (hMem)
284 {
285 uCBFormat = uFormat;
286 hCBData = hMem;
287 //pMem = GlobalLock(hMem);
288 /*
289 switch (uFormat) {
290 default:
291 DbgPrint("Clipboard unsupported format (%d)\n", uFormat);
292 return FALSE;
293 case CF_TEXT: // 1
294 break;
295 case CF_UNICODETEXT: // 13
296 break;
297 case CF_BITMAP: // 2
298 break;
299 case CF_OEMTEXT: // 7
300 break;
301 } */
302 }
303 else
304 {
305 //the window provides data in the specified format
306 }
307 return hMem;
308 }
309
310 HWND STDCALL
311 NtUserSetClipboardViewer(HWND hWndNewViewer)
312 {
313 HWND hwndPrev = 0;
314 DbgPrint("NtUserSetClipboardViewer is UNIMPLEMENTED (%p): returning %p\n", hWndNewViewer, hwndPrev);
315 return hwndPrev;
316 }
317
318 /* EOF */