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