Copy rpoolmgr.h from trunk
[reactos.git] / reactos / lib / user32 / misc / display.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 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 /* $Id$
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/misc/dde.c
23 * PURPOSE: DDE
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include "user32.h"
32 #include <rosrtl/devmode.h>
33 #include <win32k/ntuser.h>
34 #define NDEBUG
35 #include <debug.h>
36
37 /* FUNCTIONS *****************************************************************/
38
39 /*
40 * @implemented
41 */
42 BOOL STDCALL
43 EnumDisplayDevicesA(
44 LPCSTR lpDevice,
45 DWORD iDevNum,
46 PDISPLAY_DEVICEA lpDisplayDevice,
47 DWORD dwFlags)
48 {
49 BOOL rc;
50 UNICODE_STRING Device;
51 DISPLAY_DEVICEW DisplayDeviceW;
52
53 if ( !RtlCreateUnicodeStringFromAsciiz ( &Device, (PCSZ)lpDevice ) )
54 {
55 SetLastError ( ERROR_OUTOFMEMORY );
56 return FALSE;
57 }
58
59 DisplayDeviceW.cb = lpDisplayDevice->cb;
60 rc = NtUserEnumDisplayDevices (
61 &Device,
62 iDevNum,
63 &DisplayDeviceW,
64 dwFlags );
65
66 /* Copy result from DisplayDeviceW to lpDisplayDevice */
67 lpDisplayDevice->StateFlags = DisplayDeviceW.StateFlags;
68 WideCharToMultiByte(CP_ACP,0,
69 DisplayDeviceW.DeviceName,wcslen(DisplayDeviceW.DeviceName),
70 lpDisplayDevice->DeviceName,sizeof(lpDisplayDevice->DeviceName) / sizeof(lpDisplayDevice->DeviceName[0]),
71 NULL,NULL);
72 WideCharToMultiByte(CP_ACP,0,
73 DisplayDeviceW.DeviceString,wcslen(DisplayDeviceW.DeviceString),
74 lpDisplayDevice->DeviceString,sizeof(lpDisplayDevice->DeviceString) / sizeof(lpDisplayDevice->DeviceString[0]),
75 NULL,NULL);
76 WideCharToMultiByte(CP_ACP,0,
77 DisplayDeviceW.DeviceID,wcslen(DisplayDeviceW.DeviceID),
78 lpDisplayDevice->DeviceID,sizeof(lpDisplayDevice->DeviceID) / sizeof(lpDisplayDevice->DeviceID[0]),
79 NULL,NULL);
80 WideCharToMultiByte(CP_ACP,0,
81 DisplayDeviceW.DeviceKey,wcslen(DisplayDeviceW.DeviceKey),
82 lpDisplayDevice->DeviceKey,sizeof(lpDisplayDevice->DeviceKey) / sizeof(lpDisplayDevice->DeviceKey[0]),
83 NULL,NULL);
84
85 RtlFreeUnicodeString ( &Device );
86
87 return rc;
88 }
89
90
91 /*
92 * @implemented
93 */
94 BOOL
95 STDCALL
96 EnumDisplayDevicesW(
97 LPCWSTR lpDevice,
98 DWORD iDevNum,
99 PDISPLAY_DEVICE lpDisplayDevice,
100 DWORD dwFlags)
101 {
102 UNICODE_STRING Device;
103 BOOL rc;
104
105 RtlInitUnicodeString ( &Device, lpDevice );
106
107 rc = NtUserEnumDisplayDevices (
108 &Device,
109 iDevNum,
110 lpDisplayDevice,
111 dwFlags );
112
113 RtlFreeUnicodeString ( &Device );
114
115 return rc;
116 }
117
118
119 /*
120 * @implemented
121 */
122 BOOL
123 STDCALL
124 EnumDisplayMonitors(
125 HDC hdc,
126 LPCRECT lprcClip,
127 MONITORENUMPROC lpfnEnum,
128 LPARAM dwData)
129 {
130 INT iCount, i;
131 HMONITOR *hMonitorList;
132 LPRECT pRectList;
133 HANDLE hHeap;
134
135 /* get list of monitors/rects */
136 iCount = NtUserEnumDisplayMonitors(hdc, lprcClip, NULL, NULL, 0);
137 if (iCount < 0)
138 {
139 /* FIXME: SetLastError() */
140 return FALSE;
141 }
142 if (iCount == 0)
143 {
144 return TRUE;
145 }
146
147 hHeap = GetProcessHeap();
148 hMonitorList = HeapAlloc(hHeap, 0, sizeof (HMONITOR) * iCount);
149 if (hMonitorList == NULL)
150 {
151 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
152 return FALSE;
153 }
154 pRectList = HeapAlloc(hHeap, 0, sizeof (RECT) * iCount);
155 if (pRectList == NULL)
156 {
157 HeapFree(hHeap, 0, hMonitorList);
158 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
159 return FALSE;
160 }
161
162 iCount = NtUserEnumDisplayMonitors(hdc, lprcClip, hMonitorList, pRectList, iCount);
163 if (iCount <= 0)
164 {
165 /* FIXME: SetLastError() */
166 return FALSE;
167 }
168
169 /* enumerate list */
170 for (i = 0; i < iCount; i++)
171 {
172 HMONITOR hMonitor = hMonitorList[i];
173 LPRECT pMonitorRect = pRectList + i;
174 HDC hMonitorDC = NULL;
175
176 if (hdc != NULL)
177 {
178 /* make monitor DC */
179 hMonitorDC = hdc;
180 }
181
182 if (!lpfnEnum(hMonitor, hMonitorDC, pMonitorRect, dwData))
183 break;
184 }
185
186 return TRUE;
187 }
188
189
190 /*
191 * @implemented
192 */
193 BOOL
194 STDCALL
195 EnumDisplaySettingsExA(
196 LPCSTR lpszDeviceName,
197 DWORD iModeNum,
198 LPDEVMODEA lpDevMode,
199 DWORD dwFlags)
200 {
201 BOOL rc;
202 UNICODE_STRING DeviceName;
203 LPDEVMODEW lpDevModeW;
204
205 lpDevModeW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
206 sizeof(DEVMODEW) + lpDevMode->dmDriverExtra);
207 if ( lpDevModeW == NULL )
208 {
209 SetLastError ( ERROR_OUTOFMEMORY );
210 return FALSE;
211 }
212
213 if ( !RtlCreateUnicodeStringFromAsciiz ( &DeviceName, (PCSZ)lpszDeviceName ) )
214 {
215 SetLastError ( ERROR_OUTOFMEMORY );
216 return FALSE;
217 }
218
219 lpDevModeW->dmSize = sizeof(DEVMODEW);
220 lpDevModeW->dmDriverExtra = 0;
221
222 rc = NtUserEnumDisplaySettings ( &DeviceName, iModeNum, lpDevModeW,
223 dwFlags );
224
225 RosRtlDevModeW2A ( lpDevMode, lpDevModeW );
226
227 RtlFreeUnicodeString ( &DeviceName );
228 HeapFree ( GetProcessHeap(), 0, lpDevModeW );
229
230 return rc;
231 }
232
233
234 /*
235 * @implemented
236 */
237 BOOL
238 STDCALL
239 EnumDisplaySettingsA(
240 LPCSTR lpszDeviceName,
241 DWORD iModeNum,
242 LPDEVMODEA lpDevMode)
243 {
244 return EnumDisplaySettingsExA ( lpszDeviceName, iModeNum, lpDevMode, 0 );
245 }
246
247
248 /*
249 * @implemented
250 */
251 BOOL
252 STDCALL
253 EnumDisplaySettingsExW(
254 LPCWSTR lpszDeviceName,
255 DWORD iModeNum,
256 LPDEVMODEW lpDevMode,
257 DWORD dwFlags)
258 {
259 BOOL rc;
260 UNICODE_STRING DeviceName;
261
262 RtlInitUnicodeString ( &DeviceName, lpszDeviceName );
263
264 rc = NtUserEnumDisplaySettings ( &DeviceName, iModeNum, lpDevMode, dwFlags );
265
266 RtlFreeUnicodeString ( &DeviceName );
267
268 return rc;
269 }
270
271
272 /*
273 * @implemented
274 */
275 BOOL
276 STDCALL
277 EnumDisplaySettingsW(
278 LPCWSTR lpszDeviceName,
279 DWORD iModeNum,
280 LPDEVMODEW lpDevMode)
281 {
282 return EnumDisplaySettingsExW ( lpszDeviceName, iModeNum, lpDevMode, 0 );
283 }
284
285
286 /*
287 * @implemented
288 */
289 BOOL
290 STDCALL
291 GetMonitorInfoA(
292 HMONITOR hMonitor,
293 LPMONITORINFO lpmi)
294 {
295 if (lpmi->cbSize == sizeof (MONITORINFO))
296 {
297 return NtUserGetMonitorInfo(hMonitor, lpmi);
298 }
299 else if (lpmi->cbSize != sizeof (MONITORINFOEXA))
300 {
301 SetLastError(ERROR_INVALID_PARAMETER);
302 return FALSE;
303 }
304 else
305 {
306 MONITORINFOEXW miExW;
307 INT res;
308
309 miExW.cbSize = sizeof (MONITORINFOEXW);
310 if (!NtUserGetMonitorInfo(hMonitor, (LPMONITORINFO)&miExW))
311 {
312 return FALSE;
313 }
314 memcpy(lpmi, &miExW, sizeof (MONITORINFO));
315 res = WideCharToMultiByte(CP_THREAD_ACP, 0, miExW.szDevice, -1,
316 ((LPMONITORINFOEXA)lpmi)->szDevice, CCHDEVICENAME,
317 NULL, NULL);
318 if (res == 0)
319 {
320 DPRINT("WideCharToMultiByte() failed!\n");
321 return FALSE;
322 }
323 }
324
325 return TRUE;
326 }
327
328
329 /*
330 * @implemented
331 */
332 BOOL
333 STDCALL
334 GetMonitorInfoW(
335 HMONITOR hMonitor,
336 LPMONITORINFO lpmi)
337 {
338 return NtUserGetMonitorInfo(hMonitor, lpmi);
339 }
340
341
342 /*
343 * @implemented
344 */
345 HMONITOR
346 STDCALL
347 MonitorFromPoint(
348 IN POINT ptPoint,
349 IN DWORD dwFlags )
350 {
351 return NtUserMonitorFromPoint(ptPoint, dwFlags);
352 }
353
354
355 /*
356 * @implemented
357 */
358 HMONITOR
359 STDCALL
360 MonitorFromRect(
361 IN LPCRECT lpcRect,
362 IN DWORD dwFlags )
363 {
364 return NtUserMonitorFromRect(lpcRect, dwFlags);
365 }
366
367
368 /*
369 * @implemented
370 */
371 HMONITOR
372 STDCALL
373 MonitorFromWindow(
374 IN HWND hWnd,
375 IN DWORD dwFlags )
376 {
377 return NtUserMonitorFromWindow(hWnd, dwFlags);
378 }
379
380
381 /*
382 * @implemented
383 */
384 LONG
385 STDCALL
386 ChangeDisplaySettingsExA(
387 LPCSTR lpszDeviceName,
388 LPDEVMODEA lpDevMode,
389 HWND hwnd,
390 DWORD dwflags,
391 LPVOID lParam)
392 {
393 LONG rc;
394 UNICODE_STRING DeviceName;
395 PUNICODE_STRING pDeviceName = &DeviceName;
396 DEVMODEW DevModeW;
397 LPDEVMODEW pDevModeW = &DevModeW;
398
399 if (lpszDeviceName != NULL)
400 {
401 if ( !RtlCreateUnicodeStringFromAsciiz ( pDeviceName, (PCSZ)lpszDeviceName ) )
402 {
403 SetLastError ( ERROR_OUTOFMEMORY );
404 return DISP_CHANGE_BADPARAM; /* FIXME what to return? */
405 }
406 }
407 else
408 pDeviceName = NULL;
409
410 if (lpDevMode != NULL)
411 RosRtlDevModeA2W ( pDevModeW, lpDevMode );
412 else
413 pDevModeW = NULL;
414
415 rc = NtUserChangeDisplaySettings ( pDeviceName, pDevModeW, hwnd, dwflags, lParam );
416
417 if (lpszDeviceName != NULL)
418 RtlFreeUnicodeString ( &DeviceName );
419
420 return rc;
421 }
422
423
424 /*
425 * @implemented
426 */
427 LONG
428 STDCALL
429 ChangeDisplaySettingsA(
430 LPDEVMODEA lpDevMode,
431 DWORD dwflags)
432 {
433 return ChangeDisplaySettingsExA ( NULL, lpDevMode, NULL, dwflags, 0 );
434 }
435
436
437 /*
438 * @implemented
439 */
440 LONG
441 STDCALL
442 ChangeDisplaySettingsExW(
443 LPCWSTR lpszDeviceName,
444 LPDEVMODEW lpDevMode,
445 HWND hwnd,
446 DWORD dwflags,
447 LPVOID lParam)
448 {
449 LONG rc;
450 UNICODE_STRING DeviceName;
451 PUNICODE_STRING pDeviceName = &DeviceName;
452
453 if (lpszDeviceName != NULL)
454 RtlInitUnicodeString ( pDeviceName, lpszDeviceName );
455 else
456 pDeviceName = NULL;
457
458 rc = NtUserChangeDisplaySettings ( pDeviceName, lpDevMode, hwnd, dwflags, lParam );
459
460 if (lpszDeviceName != NULL)
461 RtlFreeUnicodeString ( pDeviceName );
462
463 return rc;
464 }
465
466
467 /*
468 * @implemented
469 */
470 LONG
471 STDCALL
472 ChangeDisplaySettingsW(
473 LPDEVMODEW lpDevMode,
474 DWORD dwflags)
475 {
476 return ChangeDisplaySettingsExW ( NULL, lpDevMode, NULL, dwflags, 0 );
477 }