e9de23e4e4a5d3db06411e7ec40d4782a1137a02
[reactos.git] / reactos / dll / win32 / 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
33 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(user32);
35
36 #define SIZEOF_DEVMODEA_300 124
37 #define SIZEOF_DEVMODEA_400 148
38 #define SIZEOF_DEVMODEA_500 156
39 #define SIZEOF_DEVMODEW_300 188
40 #define SIZEOF_DEVMODEW_400 212
41 #define SIZEOF_DEVMODEW_500 220
42
43 /* FUNCTIONS *****************************************************************/
44
45 /*
46 * @implemented
47 */
48 BOOL WINAPI
49 EnumDisplayDevicesA(
50 LPCSTR lpDevice,
51 DWORD iDevNum,
52 PDISPLAY_DEVICEA lpDisplayDevice,
53 DWORD dwFlags)
54 {
55 BOOL rc;
56 UNICODE_STRING Device;
57 DISPLAY_DEVICEW DisplayDeviceW;
58
59 if ( !RtlCreateUnicodeStringFromAsciiz ( &Device, (PCSZ)lpDevice ) )
60 {
61 SetLastError ( ERROR_OUTOFMEMORY );
62 return FALSE;
63 }
64
65 RtlZeroMemory(&DisplayDeviceW, sizeof(DISPLAY_DEVICEW));
66 DisplayDeviceW.cb = sizeof(DISPLAY_DEVICEW);
67 rc = NtUserEnumDisplayDevices (
68 &Device,
69 iDevNum,
70 &DisplayDeviceW,
71 dwFlags );
72 if (rc)
73 {
74 /* Copy result from DisplayDeviceW to lpDisplayDevice */
75 lpDisplayDevice->StateFlags = DisplayDeviceW.StateFlags;
76 WideCharToMultiByte(CP_ACP,0,
77 DisplayDeviceW.DeviceName,wcslen(DisplayDeviceW.DeviceName),
78 lpDisplayDevice->DeviceName,sizeof(lpDisplayDevice->DeviceName) / sizeof(lpDisplayDevice->DeviceName[0]),
79 NULL,NULL);
80 WideCharToMultiByte(CP_ACP,0,
81 DisplayDeviceW.DeviceString,wcslen(DisplayDeviceW.DeviceString),
82 lpDisplayDevice->DeviceString,sizeof(lpDisplayDevice->DeviceString) / sizeof(lpDisplayDevice->DeviceString[0]),
83 NULL,NULL);
84 WideCharToMultiByte(CP_ACP,0,
85 DisplayDeviceW.DeviceID,wcslen(DisplayDeviceW.DeviceID),
86 lpDisplayDevice->DeviceID,sizeof(lpDisplayDevice->DeviceID) / sizeof(lpDisplayDevice->DeviceID[0]),
87 NULL,NULL);
88 WideCharToMultiByte(CP_ACP,0,
89 DisplayDeviceW.DeviceKey,wcslen(DisplayDeviceW.DeviceKey),
90 lpDisplayDevice->DeviceKey,sizeof(lpDisplayDevice->DeviceKey) / sizeof(lpDisplayDevice->DeviceKey[0]),
91 NULL,NULL);
92 }
93
94 RtlFreeUnicodeString ( &Device );
95
96 return rc;
97 }
98
99
100 /*
101 * @implemented
102 */
103 BOOL
104 WINAPI
105 EnumDisplayDevicesW(
106 LPCWSTR lpDevice,
107 DWORD iDevNum,
108 PDISPLAY_DEVICE lpDisplayDevice,
109 DWORD dwFlags)
110 {
111 UNICODE_STRING Device;
112 BOOL rc;
113
114 RtlInitUnicodeString ( &Device, lpDevice );
115
116 rc = NtUserEnumDisplayDevices (
117 &Device,
118 iDevNum,
119 lpDisplayDevice,
120 dwFlags );
121
122 return rc;
123 }
124
125
126 /*
127 * @implemented
128 */
129 BOOL
130 WINAPI
131 EnumDisplayMonitors(
132 HDC hdc,
133 LPCRECT lprcClip,
134 MONITORENUMPROC lpfnEnum,
135 LPARAM dwData)
136 {
137 INT iCount, i;
138 HMONITOR *hMonitorList;
139 LPRECT pRectList;
140 HANDLE hHeap;
141
142 /* get list of monitors/rects */
143 iCount = NtUserEnumDisplayMonitors(hdc, lprcClip, NULL, NULL, 0);
144 if (iCount < 0)
145 {
146 /* FIXME: SetLastError() */
147 return FALSE;
148 }
149 if (iCount == 0)
150 {
151 return TRUE;
152 }
153
154 hHeap = GetProcessHeap();
155 hMonitorList = HeapAlloc(hHeap, 0, sizeof (HMONITOR) * iCount);
156 if (hMonitorList == NULL)
157 {
158 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
159 return FALSE;
160 }
161 pRectList = HeapAlloc(hHeap, 0, sizeof (RECT) * iCount);
162 if (pRectList == NULL)
163 {
164 HeapFree(hHeap, 0, hMonitorList);
165 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
166 return FALSE;
167 }
168
169 iCount = NtUserEnumDisplayMonitors(hdc, lprcClip, hMonitorList, pRectList, iCount);
170 if (iCount <= 0)
171 {
172 /* FIXME: SetLastError() */
173 HeapFree(hHeap, 0, hMonitorList);
174 HeapFree(hHeap, 0, pRectList);
175 return FALSE;
176 }
177
178 /* enumerate list */
179 for (i = 0; i < iCount; i++)
180 {
181 HMONITOR hMonitor = hMonitorList[i];
182 LPRECT pMonitorRect = pRectList + i;
183 HDC hMonitorDC = NULL;
184
185 if (hdc != NULL)
186 {
187 /* make monitor DC */
188 hMonitorDC = hdc;
189 }
190
191 if (!lpfnEnum(hMonitor, hMonitorDC, pMonitorRect, dwData))
192 break;
193 }
194 HeapFree(hHeap, 0, hMonitorList);
195 HeapFree(hHeap, 0, pRectList);
196 return TRUE;
197 }
198
199
200 /*
201 * @implemented
202 */
203 BOOL
204 WINAPI
205 EnumDisplaySettingsExA(
206 LPCSTR lpszDeviceName,
207 DWORD iModeNum,
208 LPDEVMODEA lpDevMode,
209 DWORD dwFlags)
210 {
211 NTSTATUS Status;
212 UNICODE_STRING usDeviceName, *pusDeviceName = NULL;
213 DEVMODEW DevModeW;
214
215 if (lpszDeviceName)
216 {
217 if (!RtlCreateUnicodeStringFromAsciiz(&usDeviceName, (PCSZ)lpszDeviceName))
218 {
219 SetLastError(ERROR_OUTOFMEMORY);
220 return FALSE;
221 }
222 pusDeviceName = &usDeviceName;
223 }
224
225 memset(&DevModeW,0, sizeof(DEVMODEW));
226 DevModeW.dmSize = sizeof(DEVMODEW);
227
228 Status = NtUserEnumDisplaySettings(pusDeviceName, iModeNum, &DevModeW, dwFlags);
229
230 if (pusDeviceName)
231 {
232 RtlFreeUnicodeString (&usDeviceName);
233 }
234
235 if (!NT_SUCCESS(Status))
236 {
237 return FALSE;
238 }
239
240 #define COPYS(f,len) WideCharToMultiByte( CP_THREAD_ACP, 0, DevModeW.f, len, (LPSTR)lpDevMode->f, len, NULL, NULL )
241 #define COPYN(f) lpDevMode->f = DevModeW.f
242 COPYS(dmDeviceName, CCHDEVICENAME );
243 COPYN(dmSpecVersion);
244 COPYN(dmDriverVersion);
245 switch (lpDevMode->dmSize)
246 {
247 case SIZEOF_DEVMODEA_300:
248 case SIZEOF_DEVMODEA_400:
249 case SIZEOF_DEVMODEA_500:
250 break;
251 default:
252 lpDevMode->dmSize = SIZEOF_DEVMODEA_300;
253 break;
254 }
255 COPYN(dmDriverExtra);
256 COPYN(dmFields);
257 COPYN(dmPosition.x);
258 COPYN(dmPosition.y);
259 COPYN(dmScale);
260 COPYN(dmCopies);
261 COPYN(dmDefaultSource);
262 COPYN(dmPrintQuality);
263 COPYN(dmColor);
264 COPYN(dmDuplex);
265 COPYN(dmYResolution);
266 COPYN(dmTTOption);
267 COPYN(dmCollate);
268 COPYS(dmFormName,CCHFORMNAME);
269 COPYN(dmLogPixels);
270 COPYN(dmBitsPerPel);
271 COPYN(dmPelsWidth);
272 COPYN(dmPelsHeight);
273 COPYN(dmDisplayFlags); // aka dmNup
274 COPYN(dmDisplayFrequency);
275
276 if (lpDevMode->dmSize <= SIZEOF_DEVMODEW_300)
277 return TRUE; // we're done with 0x300 fields
278
279 COPYN(dmICMMethod);
280 COPYN(dmICMIntent);
281 COPYN(dmMediaType);
282 COPYN(dmDitherType);
283 COPYN(dmReserved1);
284 COPYN(dmReserved2);
285
286 if (lpDevMode->dmSize <= SIZEOF_DEVMODEW_400)
287 return TRUE; // we're done with 0x400 fields
288
289 COPYN(dmPanningWidth);
290 COPYN(dmPanningHeight);
291
292 return TRUE;
293 }
294
295
296 /*
297 * @implemented
298 */
299 BOOL
300 WINAPI
301 EnumDisplaySettingsA(
302 LPCSTR lpszDeviceName,
303 DWORD iModeNum,
304 LPDEVMODEA lpDevMode)
305 {
306 return EnumDisplaySettingsExA ( lpszDeviceName, iModeNum, lpDevMode, 0 );
307 }
308
309
310 /*
311 * @implemented
312 */
313 BOOL
314 WINAPI
315 EnumDisplaySettingsExW(
316 LPCWSTR lpszDeviceName,
317 DWORD iModeNum,
318 LPDEVMODEW lpDevMode,
319 DWORD dwFlags)
320 {
321 NTSTATUS Status;
322 UNICODE_STRING usDeviceName, *pusDeviceName = NULL;
323
324 if (lpszDeviceName)
325 {
326 RtlInitUnicodeString(&usDeviceName, lpszDeviceName);
327 pusDeviceName = &usDeviceName;
328 }
329
330 Status = NtUserEnumDisplaySettings(pusDeviceName, iModeNum, lpDevMode, dwFlags);
331
332 return NT_SUCCESS(Status);
333 }
334
335
336 /*
337 * @implemented
338 */
339 BOOL
340 WINAPI
341 EnumDisplaySettingsW(
342 LPCWSTR lpszDeviceName,
343 DWORD iModeNum,
344 LPDEVMODEW lpDevMode)
345 {
346 return EnumDisplaySettingsExW ( lpszDeviceName, iModeNum, lpDevMode, 0 );
347 }
348
349
350 /*
351 * @implemented
352 */
353 BOOL
354 WINAPI
355 GetMonitorInfoA(
356 HMONITOR hMonitor,
357 LPMONITORINFO lpmi)
358 {
359 if (lpmi->cbSize == sizeof (MONITORINFO))
360 {
361 return NtUserGetMonitorInfo(hMonitor, lpmi);
362 }
363 else if (lpmi->cbSize != sizeof (MONITORINFOEXA))
364 {
365 SetLastError(ERROR_INVALID_PARAMETER);
366 return FALSE;
367 }
368 else
369 {
370 MONITORINFOEXW miExW;
371 INT res;
372
373 miExW.cbSize = sizeof (MONITORINFOEXW);
374 if (!NtUserGetMonitorInfo(hMonitor, (LPMONITORINFO)&miExW))
375 {
376 return FALSE;
377 }
378 memcpy(lpmi, &miExW, sizeof (MONITORINFO));
379 res = WideCharToMultiByte(CP_THREAD_ACP, 0, miExW.szDevice, -1,
380 ((LPMONITORINFOEXA)lpmi)->szDevice, CCHDEVICENAME,
381 NULL, NULL);
382 if (res == 0)
383 {
384 WARN("WideCharToMultiByte() failed!\n");
385 return FALSE;
386 }
387 }
388
389 return TRUE;
390 }
391
392
393 /*
394 * @implemented
395 */
396 BOOL
397 WINAPI
398 GetMonitorInfoW(
399 HMONITOR hMonitor,
400 LPMONITORINFO lpmi)
401 {
402 return NtUserGetMonitorInfo(hMonitor, lpmi);
403 }
404
405
406 /*
407 * @implemented
408 */
409 HMONITOR
410 WINAPI
411 MonitorFromPoint(
412 IN POINT ptPoint,
413 IN DWORD dwFlags )
414 {
415 return NtUserMonitorFromPoint(ptPoint, dwFlags);
416 }
417
418
419 /*
420 * @implemented
421 */
422 HMONITOR
423 WINAPI
424 MonitorFromRect(
425 IN LPCRECT lpcRect,
426 IN DWORD dwFlags )
427 {
428 return NtUserMonitorFromRect(lpcRect, dwFlags);
429 }
430
431
432 /*
433 * @implemented
434 */
435 HMONITOR
436 WINAPI
437 MonitorFromWindow(
438 IN HWND hWnd,
439 IN DWORD dwFlags )
440 {
441 return NtUserMonitorFromWindow(hWnd, dwFlags);
442 }
443
444
445 /*
446 * @implemented
447 */
448 LONG
449 WINAPI
450 ChangeDisplaySettingsExA(
451 LPCSTR lpszDeviceName,
452 LPDEVMODEA lpDevMode,
453 HWND hwnd,
454 DWORD dwflags,
455 LPVOID lParam)
456 {
457 LONG rc;
458 UNICODE_STRING DeviceName;
459 PUNICODE_STRING pDeviceName = &DeviceName;
460
461 if (lpszDeviceName != NULL)
462 {
463 if ( !RtlCreateUnicodeStringFromAsciiz ( pDeviceName, (PCSZ)lpszDeviceName ) )
464 {
465 SetLastError ( ERROR_OUTOFMEMORY );
466 return DISP_CHANGE_BADPARAM; /* FIXME what to return? */
467 }
468 }
469 else
470 pDeviceName = NULL;
471
472 if (lpDevMode != NULL)
473 {
474 LPDEVMODEW pDevModeW;
475 pDevModeW = GdiConvertToDevmodeW(lpDevMode);
476 if(pDevModeW)
477 {
478 rc = NtUserChangeDisplaySettings ( pDeviceName, pDevModeW, hwnd, dwflags, lParam );
479 RtlFreeHeap(GetProcessHeap(), 0, pDevModeW);
480 }
481 else
482 rc = DISP_CHANGE_SUCCESSFUL;
483 }
484 else
485 rc = NtUserChangeDisplaySettings ( pDeviceName, NULL, hwnd, dwflags, lParam );
486
487 if (lpszDeviceName != NULL)
488 RtlFreeUnicodeString ( &DeviceName );
489
490 return rc;
491 }
492
493
494 /*
495 * @implemented
496 */
497 LONG
498 WINAPI
499 ChangeDisplaySettingsA(
500 LPDEVMODEA lpDevMode,
501 DWORD dwflags)
502 {
503 if(lpDevMode)
504 lpDevMode->dmDriverExtra = 0;
505 return ChangeDisplaySettingsExA ( NULL, lpDevMode, NULL, dwflags, 0 );
506 }
507
508
509 /*
510 * @implemented
511 */
512 LONG
513 WINAPI
514 ChangeDisplaySettingsExW(
515 LPCWSTR lpszDeviceName,
516 LPDEVMODEW lpDevMode,
517 HWND hwnd,
518 DWORD dwflags,
519 LPVOID lParam)
520 {
521 LONG rc;
522 UNICODE_STRING DeviceName;
523 PUNICODE_STRING pDeviceName = &DeviceName;
524
525 if (lpszDeviceName != NULL)
526 RtlInitUnicodeString ( pDeviceName, lpszDeviceName );
527 else
528 pDeviceName = NULL;
529
530 rc = NtUserChangeDisplaySettings ( pDeviceName, lpDevMode, hwnd, dwflags, lParam );
531
532 return rc;
533 }
534
535
536 /*
537 * @implemented
538 */
539 LONG
540 WINAPI
541 ChangeDisplaySettingsW(
542 LPDEVMODEW lpDevMode,
543 DWORD dwflags)
544 {
545 if(lpDevMode)
546 lpDevMode->dmDriverExtra = 0;
547 return ChangeDisplaySettingsExW ( NULL, lpDevMode, NULL, dwflags, 0 );
548 }