1c2d64ff159e7fee3309ae8874737d06ed0c5f99
[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
204 if ( !RtlCreateUnicodeStringFromAsciiz ( &DeviceName, (PCSZ)lpszDeviceName ) )
205 {
206 SetLastError ( ERROR_OUTOFMEMORY );
207 return FALSE;
208 }
209
210 /*
211 * NOTE: We don't need to convert between DEVMODEW and DEVMODEA because
212 * only dmBitsPerPel, dmPelsWidth, dmPelsHeight, dmDisplayFlags and
213 * dmDisplayFrequency fields are set.
214 */
215 rc = NtUserEnumDisplaySettings ( &DeviceName, iModeNum, (LPDEVMODEW)lpDevMode,
216 dwFlags );
217
218 RtlFreeUnicodeString ( &DeviceName );
219
220 return rc;
221 }
222
223
224 /*
225 * @implemented
226 */
227 BOOL
228 STDCALL
229 EnumDisplaySettingsA(
230 LPCSTR lpszDeviceName,
231 DWORD iModeNum,
232 LPDEVMODEA lpDevMode)
233 {
234 return EnumDisplaySettingsExA ( lpszDeviceName, iModeNum, lpDevMode, 0 );
235 }
236
237
238 /*
239 * @implemented
240 */
241 BOOL
242 STDCALL
243 EnumDisplaySettingsExW(
244 LPCWSTR lpszDeviceName,
245 DWORD iModeNum,
246 LPDEVMODEW lpDevMode,
247 DWORD dwFlags)
248 {
249 BOOL rc;
250 UNICODE_STRING DeviceName;
251
252 RtlInitUnicodeString ( &DeviceName, lpszDeviceName );
253
254 rc = NtUserEnumDisplaySettings ( &DeviceName, iModeNum, lpDevMode, dwFlags );
255
256 RtlFreeUnicodeString ( &DeviceName );
257
258 return rc;
259 }
260
261
262 /*
263 * @implemented
264 */
265 BOOL
266 STDCALL
267 EnumDisplaySettingsW(
268 LPCWSTR lpszDeviceName,
269 DWORD iModeNum,
270 LPDEVMODEW lpDevMode)
271 {
272 return EnumDisplaySettingsExW ( lpszDeviceName, iModeNum, lpDevMode, 0 );
273 }
274
275
276 /*
277 * @implemented
278 */
279 BOOL
280 STDCALL
281 GetMonitorInfoA(
282 HMONITOR hMonitor,
283 LPMONITORINFO lpmi)
284 {
285 if (lpmi->cbSize == sizeof (MONITORINFO))
286 {
287 return NtUserGetMonitorInfo(hMonitor, lpmi);
288 }
289 else if (lpmi->cbSize != sizeof (MONITORINFOEXA))
290 {
291 SetLastError(ERROR_INVALID_PARAMETER);
292 return FALSE;
293 }
294 else
295 {
296 MONITORINFOEXW miExW;
297 INT res;
298
299 miExW.cbSize = sizeof (MONITORINFOEXW);
300 if (!NtUserGetMonitorInfo(hMonitor, (LPMONITORINFO)&miExW))
301 {
302 return FALSE;
303 }
304 memcpy(lpmi, &miExW, sizeof (MONITORINFO));
305 res = WideCharToMultiByte(CP_THREAD_ACP, 0, miExW.szDevice, -1,
306 ((LPMONITORINFOEXA)lpmi)->szDevice, CCHDEVICENAME,
307 NULL, NULL);
308 if (res == 0)
309 {
310 DPRINT("WideCharToMultiByte() failed!\n");
311 return FALSE;
312 }
313 }
314
315 return TRUE;
316 }
317
318
319 /*
320 * @implemented
321 */
322 BOOL
323 STDCALL
324 GetMonitorInfoW(
325 HMONITOR hMonitor,
326 LPMONITORINFO lpmi)
327 {
328 return NtUserGetMonitorInfo(hMonitor, lpmi);
329 }
330
331
332 /*
333 * @implemented
334 */
335 HMONITOR
336 STDCALL
337 MonitorFromPoint(
338 IN POINT ptPoint,
339 IN DWORD dwFlags )
340 {
341 return NtUserMonitorFromPoint(ptPoint, dwFlags);
342 }
343
344
345 /*
346 * @implemented
347 */
348 HMONITOR
349 STDCALL
350 MonitorFromRect(
351 IN LPCRECT lpcRect,
352 IN DWORD dwFlags )
353 {
354 return NtUserMonitorFromRect(lpcRect, dwFlags);
355 }
356
357
358 /*
359 * @implemented
360 */
361 HMONITOR
362 STDCALL
363 MonitorFromWindow(
364 IN HWND hWnd,
365 IN DWORD dwFlags )
366 {
367 return NtUserMonitorFromWindow(hWnd, dwFlags);
368 }
369
370
371 /*
372 * @implemented
373 */
374 LONG
375 STDCALL
376 ChangeDisplaySettingsExA(
377 LPCSTR lpszDeviceName,
378 LPDEVMODEA lpDevMode,
379 HWND hwnd,
380 DWORD dwflags,
381 LPVOID lParam)
382 {
383 LONG rc;
384 UNICODE_STRING DeviceName;
385 PUNICODE_STRING pDeviceName = &DeviceName;
386 DEVMODEW DevModeW;
387 LPDEVMODEW pDevModeW = &DevModeW;
388
389 if (lpszDeviceName != NULL)
390 {
391 if ( !RtlCreateUnicodeStringFromAsciiz ( pDeviceName, (PCSZ)lpszDeviceName ) )
392 {
393 SetLastError ( ERROR_OUTOFMEMORY );
394 return DISP_CHANGE_BADPARAM; /* FIXME what to return? */
395 }
396 }
397 else
398 pDeviceName = NULL;
399
400 if (lpDevMode != NULL)
401 RosRtlDevModeA2W ( pDevModeW, lpDevMode );
402 else
403 pDevModeW = NULL;
404
405 rc = NtUserChangeDisplaySettings ( pDeviceName, pDevModeW, hwnd, dwflags, lParam );
406
407 if (lpszDeviceName != NULL)
408 RtlFreeUnicodeString ( &DeviceName );
409
410 return rc;
411 }
412
413
414 /*
415 * @implemented
416 */
417 LONG
418 STDCALL
419 ChangeDisplaySettingsA(
420 LPDEVMODEA lpDevMode,
421 DWORD dwflags)
422 {
423 return ChangeDisplaySettingsExA ( NULL, lpDevMode, NULL, dwflags, 0 );
424 }
425
426
427 /*
428 * @implemented
429 */
430 LONG
431 STDCALL
432 ChangeDisplaySettingsExW(
433 LPCWSTR lpszDeviceName,
434 LPDEVMODEW lpDevMode,
435 HWND hwnd,
436 DWORD dwflags,
437 LPVOID lParam)
438 {
439 LONG rc;
440 UNICODE_STRING DeviceName;
441 PUNICODE_STRING pDeviceName = &DeviceName;
442
443 if (lpszDeviceName != NULL)
444 RtlInitUnicodeString ( pDeviceName, lpszDeviceName );
445 else
446 pDeviceName = NULL;
447
448 rc = NtUserChangeDisplaySettings ( pDeviceName, lpDevMode, hwnd, dwflags, lParam );
449
450 if (lpszDeviceName != NULL)
451 RtlFreeUnicodeString ( pDeviceName );
452
453 return rc;
454 }
455
456
457 /*
458 * @implemented
459 */
460 LONG
461 STDCALL
462 ChangeDisplaySettingsW(
463 LPDEVMODEW lpDevMode,
464 DWORD dwflags)
465 {
466 return ChangeDisplaySettingsExW ( NULL, lpDevMode, NULL, dwflags, 0 );
467 }