gdiplus: Fix swapped got-expected in brush test.
[wine/multimedia.git] / dlls / user32 / winstation.c
blob57ce952f034eaa680137c091aa150227f7fa4d2c
1 /*
2 * Window stations and desktops
4 * Copyright 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "ntstatus.h"
22 #define WIN32_NO_STATUS
24 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "winerror.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "wine/server.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
34 #include "user_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(winstation);
39 /* callback for enumeration functions */
40 struct enum_proc_lparam
42 NAMEENUMPROCA func;
43 LPARAM lparam;
46 static BOOL CALLBACK enum_names_WtoA( LPWSTR name, LPARAM lparam )
48 struct enum_proc_lparam *data = (struct enum_proc_lparam *)lparam;
49 char buffer[MAX_PATH];
51 if (!WideCharToMultiByte( CP_ACP, 0, name, -1, buffer, sizeof(buffer), NULL, NULL ))
52 return FALSE;
53 return data->func( buffer, data->lparam );
57 /***********************************************************************
58 * CreateWindowStationA (USER32.@)
60 HWINSTA WINAPI CreateWindowStationA( LPCSTR name, DWORD reserved, ACCESS_MASK access,
61 LPSECURITY_ATTRIBUTES sa )
63 WCHAR buffer[MAX_PATH];
65 if (!name) return CreateWindowStationW( NULL, reserved, access, sa );
67 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
69 SetLastError( ERROR_FILENAME_EXCED_RANGE );
70 return 0;
72 return CreateWindowStationW( buffer, reserved, access, sa );
76 /***********************************************************************
77 * CreateWindowStationW (USER32.@)
79 HWINSTA WINAPI CreateWindowStationW( LPCWSTR name, DWORD reserved, ACCESS_MASK access,
80 LPSECURITY_ATTRIBUTES sa )
82 HANDLE ret;
83 DWORD len = name ? strlenW(name) : 0;
85 if (len >= MAX_PATH)
87 SetLastError( ERROR_FILENAME_EXCED_RANGE );
88 return 0;
90 SERVER_START_REQ( create_winstation )
92 req->flags = 0;
93 req->access = access;
94 req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
95 ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
96 wine_server_add_data( req, name, len * sizeof(WCHAR) );
97 /* it doesn't seem to set last error */
98 wine_server_call( req );
99 ret = reply->handle;
101 SERVER_END_REQ;
102 return ret;
106 /******************************************************************************
107 * OpenWindowStationA (USER32.@)
109 HWINSTA WINAPI OpenWindowStationA( LPCSTR name, BOOL inherit, ACCESS_MASK access )
111 WCHAR buffer[MAX_PATH];
113 if (!name) return OpenWindowStationW( NULL, inherit, access );
115 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
117 SetLastError( ERROR_FILENAME_EXCED_RANGE );
118 return 0;
120 return OpenWindowStationW( buffer, inherit, access );
124 /******************************************************************************
125 * OpenWindowStationW (USER32.@)
127 HWINSTA WINAPI OpenWindowStationW( LPCWSTR name, BOOL inherit, ACCESS_MASK access )
129 HANDLE ret = 0;
130 DWORD len = name ? strlenW(name) : 0;
131 if (len >= MAX_PATH)
133 SetLastError( ERROR_FILENAME_EXCED_RANGE );
134 return 0;
136 SERVER_START_REQ( open_winstation )
138 req->access = access;
139 req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
140 wine_server_add_data( req, name, len * sizeof(WCHAR) );
141 if (!wine_server_call_err( req )) ret = reply->handle;
143 SERVER_END_REQ;
144 return ret;
148 /***********************************************************************
149 * CloseWindowStation (USER32.@)
151 BOOL WINAPI CloseWindowStation( HWINSTA handle )
153 BOOL ret;
154 SERVER_START_REQ( close_winstation )
156 req->handle = handle;
157 ret = !wine_server_call_err( req );
159 SERVER_END_REQ;
160 return ret;
164 /******************************************************************************
165 * GetProcessWindowStation (USER32.@)
167 HWINSTA WINAPI GetProcessWindowStation(void)
169 HWINSTA ret = 0;
171 SERVER_START_REQ( get_process_winstation )
173 if (!wine_server_call_err( req )) ret = reply->handle;
175 SERVER_END_REQ;
176 return ret;
180 /***********************************************************************
181 * SetProcessWindowStation (USER32.@)
183 BOOL WINAPI SetProcessWindowStation( HWINSTA handle )
185 BOOL ret;
187 SERVER_START_REQ( set_process_winstation )
189 req->handle = handle;
190 ret = !wine_server_call_err( req );
192 SERVER_END_REQ;
193 return ret;
197 /******************************************************************************
198 * EnumWindowStationsA (USER32.@)
200 BOOL WINAPI EnumWindowStationsA( WINSTAENUMPROCA func, LPARAM lparam )
202 struct enum_proc_lparam data;
203 data.func = func;
204 data.lparam = lparam;
205 return EnumWindowStationsW( enum_names_WtoA, (LPARAM)&data );
209 /******************************************************************************
210 * EnumWindowStationsW (USER32.@)
212 BOOL WINAPI EnumWindowStationsW( WINSTAENUMPROCW func, LPARAM lparam )
214 unsigned int index = 0;
215 WCHAR name[MAX_PATH];
216 BOOL ret = TRUE;
217 NTSTATUS status;
219 while (ret)
221 SERVER_START_REQ( enum_winstation )
223 req->index = index;
224 wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
225 status = wine_server_call( req );
226 name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
227 index = reply->next;
229 SERVER_END_REQ;
230 if (status == STATUS_NO_MORE_ENTRIES)
231 break;
232 if (status)
234 SetLastError( RtlNtStatusToDosError( status ) );
235 return FALSE;
237 ret = func( name, lparam );
239 return ret;
243 /***********************************************************************
244 * CreateDesktopA (USER32.@)
246 HDESK WINAPI CreateDesktopA( LPCSTR name, LPCSTR device, LPDEVMODEA devmode,
247 DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
249 WCHAR buffer[MAX_PATH];
251 if (device || devmode)
253 SetLastError( ERROR_INVALID_PARAMETER );
254 return 0;
256 if (!name) return CreateDesktopW( NULL, NULL, NULL, flags, access, sa );
258 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
260 SetLastError( ERROR_FILENAME_EXCED_RANGE );
261 return 0;
263 return CreateDesktopW( buffer, NULL, NULL, flags, access, sa );
267 /***********************************************************************
268 * CreateDesktopW (USER32.@)
270 HDESK WINAPI CreateDesktopW( LPCWSTR name, LPCWSTR device, LPDEVMODEW devmode,
271 DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
273 HANDLE ret;
274 DWORD len = name ? strlenW(name) : 0;
276 if (device || devmode)
278 SetLastError( ERROR_INVALID_PARAMETER );
279 return 0;
281 if (len >= MAX_PATH)
283 SetLastError( ERROR_FILENAME_EXCED_RANGE );
284 return 0;
286 SERVER_START_REQ( create_desktop )
288 req->flags = flags;
289 req->access = access;
290 req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
291 ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
292 wine_server_add_data( req, name, len * sizeof(WCHAR) );
293 /* it doesn't seem to set last error */
294 wine_server_call( req );
295 ret = reply->handle;
297 SERVER_END_REQ;
298 return ret;
302 /******************************************************************************
303 * OpenDesktopA (USER32.@)
305 HDESK WINAPI OpenDesktopA( LPCSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
307 WCHAR buffer[MAX_PATH];
309 if (!name) return OpenDesktopW( NULL, flags, inherit, access );
311 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
313 SetLastError( ERROR_FILENAME_EXCED_RANGE );
314 return 0;
316 return OpenDesktopW( buffer, flags, inherit, access );
320 HDESK open_winstation_desktop( HWINSTA hwinsta, LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
322 HANDLE ret = 0;
323 DWORD len = name ? strlenW(name) : 0;
324 if (len >= MAX_PATH)
326 SetLastError( ERROR_FILENAME_EXCED_RANGE );
327 return 0;
329 SERVER_START_REQ( open_desktop )
331 req->winsta = hwinsta;
332 req->flags = flags;
333 req->access = access;
334 req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
335 wine_server_add_data( req, name, len * sizeof(WCHAR) );
336 if (!wine_server_call( req )) ret = reply->handle;
338 SERVER_END_REQ;
339 return ret;
343 /******************************************************************************
344 * OpenDesktopW (USER32.@)
346 HDESK WINAPI OpenDesktopW( LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
348 return open_winstation_desktop( NULL, name, flags, inherit, access );
352 /***********************************************************************
353 * CloseDesktop (USER32.@)
355 BOOL WINAPI CloseDesktop( HDESK handle )
357 BOOL ret;
358 SERVER_START_REQ( close_desktop )
360 req->handle = handle;
361 ret = !wine_server_call_err( req );
363 SERVER_END_REQ;
364 return ret;
368 /******************************************************************************
369 * GetThreadDesktop (USER32.@)
371 HDESK WINAPI GetThreadDesktop( DWORD thread )
373 HDESK ret = 0;
375 SERVER_START_REQ( get_thread_desktop )
377 req->tid = thread;
378 if (!wine_server_call_err( req )) ret = reply->handle;
380 SERVER_END_REQ;
381 return ret;
385 /******************************************************************************
386 * SetThreadDesktop (USER32.@)
388 BOOL WINAPI SetThreadDesktop( HDESK handle )
390 BOOL ret;
392 SERVER_START_REQ( set_thread_desktop )
394 req->handle = handle;
395 ret = !wine_server_call_err( req );
397 SERVER_END_REQ;
398 if (ret) /* reset the desktop windows */
400 struct user_thread_info *thread_info = get_user_thread_info();
401 thread_info->top_window = 0;
402 thread_info->msg_window = 0;
404 return ret;
408 /******************************************************************************
409 * EnumDesktopsA (USER32.@)
411 BOOL WINAPI EnumDesktopsA( HWINSTA winsta, DESKTOPENUMPROCA func, LPARAM lparam )
413 struct enum_proc_lparam data;
414 data.func = func;
415 data.lparam = lparam;
416 return EnumDesktopsW( winsta, enum_names_WtoA, (LPARAM)&data );
420 /******************************************************************************
421 * EnumDesktopsW (USER32.@)
423 BOOL WINAPI EnumDesktopsW( HWINSTA winsta, DESKTOPENUMPROCW func, LPARAM lparam )
425 unsigned int index = 0;
426 WCHAR name[MAX_PATH];
427 BOOL ret = TRUE;
428 NTSTATUS status;
430 if (!winsta)
431 winsta = GetProcessWindowStation();
433 while (ret)
435 SERVER_START_REQ( enum_desktop )
437 req->winstation = winsta;
438 req->index = index;
439 wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
440 status = wine_server_call( req );
441 name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
442 index = reply->next;
444 SERVER_END_REQ;
445 if (status == STATUS_NO_MORE_ENTRIES)
446 break;
447 if (status)
449 SetLastError( RtlNtStatusToDosError( status ) );
450 return FALSE;
452 ret = func(name, lparam);
454 return ret;
458 /******************************************************************************
459 * OpenInputDesktop (USER32.@)
461 HDESK WINAPI OpenInputDesktop( DWORD flags, BOOL inherit, ACCESS_MASK access )
463 FIXME( "(%x,%i,%x): stub\n", flags, inherit, access );
464 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
465 return 0;
469 /***********************************************************************
470 * GetUserObjectInformationA (USER32.@)
472 BOOL WINAPI GetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
474 /* check for information types returning strings */
475 if (index == UOI_TYPE || index == UOI_NAME)
477 WCHAR buffer[MAX_PATH];
478 DWORD lenA;
480 if (!GetUserObjectInformationW( handle, index, buffer, sizeof(buffer), NULL )) return FALSE;
481 lenA = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
482 if (needed) *needed = lenA;
483 if (lenA > len)
485 SetLastError( ERROR_MORE_DATA );
486 return FALSE;
488 if (info) WideCharToMultiByte( CP_ACP, 0, buffer, -1, info, len, NULL, NULL );
489 return TRUE;
491 return GetUserObjectInformationW( handle, index, info, len, needed );
495 /***********************************************************************
496 * GetUserObjectInformationW (USER32.@)
498 BOOL WINAPI GetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
500 static const WCHAR desktopW[] = { 'D','e','s','k','t','o','p',0 };
501 static const WCHAR winstationW[] = { 'W','i','n','d','o','w','S','t','a','t','i','o','n',0 };
502 BOOL ret;
504 switch(index)
506 case UOI_FLAGS:
508 USEROBJECTFLAGS *obj_flags = info;
509 if (needed) *needed = sizeof(*obj_flags);
510 if (len < sizeof(*obj_flags))
512 SetLastError( ERROR_BUFFER_OVERFLOW );
513 return FALSE;
515 SERVER_START_REQ( set_user_object_info )
517 req->handle = handle;
518 req->flags = 0;
519 ret = !wine_server_call_err( req );
520 if (ret)
522 /* FIXME: inherit flag */
523 obj_flags->dwFlags = reply->old_obj_flags;
526 SERVER_END_REQ;
528 return ret;
530 case UOI_TYPE:
531 SERVER_START_REQ( set_user_object_info )
533 req->handle = handle;
534 req->flags = 0;
535 ret = !wine_server_call_err( req );
536 if (ret)
538 size_t size = reply->is_desktop ? sizeof(desktopW) : sizeof(winstationW);
539 if (needed) *needed = size;
540 if (len < size)
542 SetLastError( ERROR_MORE_DATA );
543 ret = FALSE;
545 else memcpy( info, reply->is_desktop ? desktopW : winstationW, size );
548 SERVER_END_REQ;
549 return ret;
551 case UOI_NAME:
553 WCHAR buffer[MAX_PATH];
554 SERVER_START_REQ( set_user_object_info )
556 req->handle = handle;
557 req->flags = 0;
558 wine_server_set_reply( req, buffer, sizeof(buffer) - sizeof(WCHAR) );
559 ret = !wine_server_call_err( req );
560 if (ret)
562 size_t size = wine_server_reply_size( reply );
563 buffer[size / sizeof(WCHAR)] = 0;
564 size += sizeof(WCHAR);
565 if (needed) *needed = size;
566 if (len < size)
568 SetLastError( ERROR_MORE_DATA );
569 ret = FALSE;
571 else memcpy( info, buffer, size );
574 SERVER_END_REQ;
576 return ret;
578 case UOI_USER_SID:
579 FIXME( "not supported index %d\n", index );
580 /* fall through */
581 default:
582 SetLastError( ERROR_INVALID_PARAMETER );
583 return FALSE;
588 /******************************************************************************
589 * SetUserObjectInformationA (USER32.@)
591 BOOL WINAPI SetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len )
593 return SetUserObjectInformationW( handle, index, info, len );
597 /******************************************************************************
598 * SetUserObjectInformationW (USER32.@)
600 BOOL WINAPI SetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len )
602 BOOL ret;
603 const USEROBJECTFLAGS *obj_flags = info;
605 if (index != UOI_FLAGS || !info || len < sizeof(*obj_flags))
607 SetLastError( ERROR_INVALID_PARAMETER );
608 return FALSE;
610 /* FIXME: inherit flag */
611 SERVER_START_REQ( set_user_object_info )
613 req->handle = handle;
614 req->flags = SET_USER_OBJECT_FLAGS;
615 req->obj_flags = obj_flags->dwFlags;
616 ret = !wine_server_call_err( req );
618 SERVER_END_REQ;
619 return ret;
623 /***********************************************************************
624 * GetUserObjectSecurity (USER32.@)
626 BOOL WINAPI GetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
627 PSECURITY_DESCRIPTOR sid, DWORD len, LPDWORD needed )
629 FIXME( "(%p %p %p len=%d %p),stub!\n", handle, info, sid, len, needed );
630 return TRUE;
633 /***********************************************************************
634 * SetUserObjectSecurity (USER32.@)
636 BOOL WINAPI SetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
637 PSECURITY_DESCRIPTOR sid )
639 FIXME( "(%p,%p,%p),stub!\n", handle, info, sid );
640 return TRUE;