Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / user32 / winstation.c
blobc6c52b76e6ad16963cc8b55d8c3d826e3f3b7147
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 = wine_server_ptr_handle( 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 = wine_server_ptr_handle( 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 = wine_server_obj_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 ))
174 ret = wine_server_ptr_handle( reply->handle );
176 SERVER_END_REQ;
177 return ret;
181 /***********************************************************************
182 * SetProcessWindowStation (USER32.@)
184 BOOL WINAPI SetProcessWindowStation( HWINSTA handle )
186 BOOL ret;
188 SERVER_START_REQ( set_process_winstation )
190 req->handle = wine_server_obj_handle( handle );
191 ret = !wine_server_call_err( req );
193 SERVER_END_REQ;
194 return ret;
198 /******************************************************************************
199 * EnumWindowStationsA (USER32.@)
201 BOOL WINAPI EnumWindowStationsA( WINSTAENUMPROCA func, LPARAM lparam )
203 struct enum_proc_lparam data;
204 data.func = func;
205 data.lparam = lparam;
206 return EnumWindowStationsW( enum_names_WtoA, (LPARAM)&data );
210 /******************************************************************************
211 * EnumWindowStationsW (USER32.@)
213 BOOL WINAPI EnumWindowStationsW( WINSTAENUMPROCW func, LPARAM lparam )
215 unsigned int index = 0;
216 WCHAR name[MAX_PATH];
217 BOOL ret = TRUE;
218 NTSTATUS status;
220 while (ret)
222 SERVER_START_REQ( enum_winstation )
224 req->index = index;
225 wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
226 status = wine_server_call( req );
227 name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
228 index = reply->next;
230 SERVER_END_REQ;
231 if (status == STATUS_NO_MORE_ENTRIES)
232 break;
233 if (status)
235 SetLastError( RtlNtStatusToDosError( status ) );
236 return FALSE;
238 ret = func( name, lparam );
240 return ret;
244 /***********************************************************************
245 * CreateDesktopA (USER32.@)
247 HDESK WINAPI CreateDesktopA( LPCSTR name, LPCSTR device, LPDEVMODEA devmode,
248 DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
250 WCHAR buffer[MAX_PATH];
252 if (device || devmode)
254 SetLastError( ERROR_INVALID_PARAMETER );
255 return 0;
257 if (!name) return CreateDesktopW( NULL, NULL, NULL, flags, access, sa );
259 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
261 SetLastError( ERROR_FILENAME_EXCED_RANGE );
262 return 0;
264 return CreateDesktopW( buffer, NULL, NULL, flags, access, sa );
268 /***********************************************************************
269 * CreateDesktopW (USER32.@)
271 HDESK WINAPI CreateDesktopW( LPCWSTR name, LPCWSTR device, LPDEVMODEW devmode,
272 DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
274 HANDLE ret;
275 DWORD len = name ? strlenW(name) : 0;
277 if (device || devmode)
279 SetLastError( ERROR_INVALID_PARAMETER );
280 return 0;
282 if (len >= MAX_PATH)
284 SetLastError( ERROR_FILENAME_EXCED_RANGE );
285 return 0;
287 SERVER_START_REQ( create_desktop )
289 req->flags = flags;
290 req->access = access;
291 req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
292 ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
293 wine_server_add_data( req, name, len * sizeof(WCHAR) );
294 /* it doesn't seem to set last error */
295 wine_server_call( req );
296 ret = wine_server_ptr_handle( reply->handle );
298 SERVER_END_REQ;
299 return ret;
303 /******************************************************************************
304 * OpenDesktopA (USER32.@)
306 HDESK WINAPI OpenDesktopA( LPCSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
308 WCHAR buffer[MAX_PATH];
310 if (!name) return OpenDesktopW( NULL, flags, inherit, access );
312 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
314 SetLastError( ERROR_FILENAME_EXCED_RANGE );
315 return 0;
317 return OpenDesktopW( buffer, flags, inherit, access );
321 HDESK open_winstation_desktop( HWINSTA hwinsta, LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
323 HANDLE ret = 0;
324 DWORD len = name ? strlenW(name) : 0;
325 if (len >= MAX_PATH)
327 SetLastError( ERROR_FILENAME_EXCED_RANGE );
328 return 0;
330 SERVER_START_REQ( open_desktop )
332 req->winsta = wine_server_obj_handle( hwinsta );
333 req->flags = flags;
334 req->access = access;
335 req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
336 wine_server_add_data( req, name, len * sizeof(WCHAR) );
337 if (!wine_server_call( req )) ret = wine_server_ptr_handle( reply->handle );
339 SERVER_END_REQ;
340 return ret;
344 /******************************************************************************
345 * OpenDesktopW (USER32.@)
347 HDESK WINAPI OpenDesktopW( LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
349 return open_winstation_desktop( NULL, name, flags, inherit, access );
353 /***********************************************************************
354 * CloseDesktop (USER32.@)
356 BOOL WINAPI CloseDesktop( HDESK handle )
358 BOOL ret;
359 SERVER_START_REQ( close_desktop )
361 req->handle = wine_server_obj_handle( handle );
362 ret = !wine_server_call_err( req );
364 SERVER_END_REQ;
365 return ret;
369 /******************************************************************************
370 * GetThreadDesktop (USER32.@)
372 HDESK WINAPI GetThreadDesktop( DWORD thread )
374 HDESK ret = 0;
376 SERVER_START_REQ( get_thread_desktop )
378 req->tid = thread;
379 if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->handle );
381 SERVER_END_REQ;
382 return ret;
386 /******************************************************************************
387 * SetThreadDesktop (USER32.@)
389 BOOL WINAPI SetThreadDesktop( HDESK handle )
391 BOOL ret;
393 SERVER_START_REQ( set_thread_desktop )
395 req->handle = wine_server_obj_handle( handle );
396 ret = !wine_server_call_err( req );
398 SERVER_END_REQ;
399 if (ret) /* reset the desktop windows */
401 struct user_thread_info *thread_info = get_user_thread_info();
402 thread_info->top_window = 0;
403 thread_info->msg_window = 0;
405 return ret;
409 /******************************************************************************
410 * EnumDesktopsA (USER32.@)
412 BOOL WINAPI EnumDesktopsA( HWINSTA winsta, DESKTOPENUMPROCA func, LPARAM lparam )
414 struct enum_proc_lparam data;
415 data.func = func;
416 data.lparam = lparam;
417 return EnumDesktopsW( winsta, enum_names_WtoA, (LPARAM)&data );
421 /******************************************************************************
422 * EnumDesktopsW (USER32.@)
424 BOOL WINAPI EnumDesktopsW( HWINSTA winsta, DESKTOPENUMPROCW func, LPARAM lparam )
426 unsigned int index = 0;
427 WCHAR name[MAX_PATH];
428 BOOL ret = TRUE;
429 NTSTATUS status;
431 if (!winsta)
432 winsta = GetProcessWindowStation();
434 while (ret)
436 SERVER_START_REQ( enum_desktop )
438 req->winstation = wine_server_obj_handle( winsta );
439 req->index = index;
440 wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
441 status = wine_server_call( req );
442 name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
443 index = reply->next;
445 SERVER_END_REQ;
446 if (status == STATUS_NO_MORE_ENTRIES)
447 break;
448 if (status)
450 SetLastError( RtlNtStatusToDosError( status ) );
451 return FALSE;
453 ret = func(name, lparam);
455 return ret;
459 /******************************************************************************
460 * OpenInputDesktop (USER32.@)
462 HDESK WINAPI OpenInputDesktop( DWORD flags, BOOL inherit, ACCESS_MASK access )
464 FIXME( "(%x,%i,%x): stub\n", flags, inherit, access );
465 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
466 return 0;
470 /***********************************************************************
471 * GetUserObjectInformationA (USER32.@)
473 BOOL WINAPI GetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
475 /* check for information types returning strings */
476 if (index == UOI_TYPE || index == UOI_NAME)
478 WCHAR buffer[MAX_PATH];
479 DWORD lenA;
481 if (!GetUserObjectInformationW( handle, index, buffer, sizeof(buffer), NULL )) return FALSE;
482 lenA = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
483 if (needed) *needed = lenA;
484 if (lenA > len)
486 SetLastError( ERROR_MORE_DATA );
487 return FALSE;
489 if (info) WideCharToMultiByte( CP_ACP, 0, buffer, -1, info, len, NULL, NULL );
490 return TRUE;
492 return GetUserObjectInformationW( handle, index, info, len, needed );
496 /***********************************************************************
497 * GetUserObjectInformationW (USER32.@)
499 BOOL WINAPI GetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
501 static const WCHAR desktopW[] = { 'D','e','s','k','t','o','p',0 };
502 static const WCHAR winstationW[] = { 'W','i','n','d','o','w','S','t','a','t','i','o','n',0 };
503 BOOL ret;
505 switch(index)
507 case UOI_FLAGS:
509 USEROBJECTFLAGS *obj_flags = info;
510 if (needed) *needed = sizeof(*obj_flags);
511 if (len < sizeof(*obj_flags))
513 SetLastError( ERROR_BUFFER_OVERFLOW );
514 return FALSE;
516 SERVER_START_REQ( set_user_object_info )
518 req->handle = wine_server_obj_handle( handle );
519 req->flags = 0;
520 ret = !wine_server_call_err( req );
521 if (ret)
523 /* FIXME: inherit flag */
524 obj_flags->dwFlags = reply->old_obj_flags;
527 SERVER_END_REQ;
529 return ret;
531 case UOI_TYPE:
532 SERVER_START_REQ( set_user_object_info )
534 req->handle = wine_server_obj_handle( handle );
535 req->flags = 0;
536 ret = !wine_server_call_err( req );
537 if (ret)
539 size_t size = reply->is_desktop ? sizeof(desktopW) : sizeof(winstationW);
540 if (needed) *needed = size;
541 if (len < size)
543 SetLastError( ERROR_MORE_DATA );
544 ret = FALSE;
546 else memcpy( info, reply->is_desktop ? desktopW : winstationW, size );
549 SERVER_END_REQ;
550 return ret;
552 case UOI_NAME:
554 WCHAR buffer[MAX_PATH];
555 SERVER_START_REQ( set_user_object_info )
557 req->handle = wine_server_obj_handle( handle );
558 req->flags = 0;
559 wine_server_set_reply( req, buffer, sizeof(buffer) - sizeof(WCHAR) );
560 ret = !wine_server_call_err( req );
561 if (ret)
563 size_t size = wine_server_reply_size( reply );
564 buffer[size / sizeof(WCHAR)] = 0;
565 size += sizeof(WCHAR);
566 if (needed) *needed = size;
567 if (len < size)
569 SetLastError( ERROR_MORE_DATA );
570 ret = FALSE;
572 else memcpy( info, buffer, size );
575 SERVER_END_REQ;
577 return ret;
579 case UOI_USER_SID:
580 FIXME( "not supported index %d\n", index );
581 /* fall through */
582 default:
583 SetLastError( ERROR_INVALID_PARAMETER );
584 return FALSE;
589 /******************************************************************************
590 * SetUserObjectInformationA (USER32.@)
592 BOOL WINAPI SetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len )
594 return SetUserObjectInformationW( handle, index, info, len );
598 /******************************************************************************
599 * SetUserObjectInformationW (USER32.@)
601 BOOL WINAPI SetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len )
603 BOOL ret;
604 const USEROBJECTFLAGS *obj_flags = info;
606 if (index != UOI_FLAGS || !info || len < sizeof(*obj_flags))
608 SetLastError( ERROR_INVALID_PARAMETER );
609 return FALSE;
611 /* FIXME: inherit flag */
612 SERVER_START_REQ( set_user_object_info )
614 req->handle = wine_server_obj_handle( handle );
615 req->flags = SET_USER_OBJECT_FLAGS;
616 req->obj_flags = obj_flags->dwFlags;
617 ret = !wine_server_call_err( req );
619 SERVER_END_REQ;
620 return ret;
624 /***********************************************************************
625 * GetUserObjectSecurity (USER32.@)
627 BOOL WINAPI GetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
628 PSECURITY_DESCRIPTOR sid, DWORD len, LPDWORD needed )
630 FIXME( "(%p %p %p len=%d %p),stub!\n", handle, info, sid, len, needed );
631 if (needed)
632 *needed = sizeof(SECURITY_DESCRIPTOR);
633 if (len < sizeof(SECURITY_DESCRIPTOR))
635 SetLastError( ERROR_INSUFFICIENT_BUFFER );
636 return FALSE;
638 return InitializeSecurityDescriptor(sid, SECURITY_DESCRIPTOR_REVISION);
641 /***********************************************************************
642 * SetUserObjectSecurity (USER32.@)
644 BOOL WINAPI SetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
645 PSECURITY_DESCRIPTOR sid )
647 FIXME( "(%p,%p,%p),stub!\n", handle, info, sid );
648 return TRUE;