source: trunk/src/user32/display.cpp@ 2804

Last change on this file since 2804 was 2804, checked in by sandervl, 26 years ago

Added new logging feature

File size: 19.1 KB
Line 
1/* $Id: display.cpp,v 1.5 2000-02-16 14:34:16 sandervl Exp $ */
2/*
3 * Display/Monitor Win32 apis
4 *
5 * Based on Wine code (991031)
6 *
7 * Copyright 1993 Robert J. Amstadt
8 * 1996 Alex Korobka
9 * Copyright 1998 Turchanov Sergey
10 *
11 * Copyright 1999 Christoph Bratschi
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16#include <os2win.h>
17#include <misc.h>
18#include <heapstring.h>
19#include "pmwindow.h"
20#include "monitor.h"
21#include "windef.h"
22
23#define DBG_LOCALLOG DBG_display
24#include "dbglocal.h"
25
26#define NRMODES 5
27#define NRDEPTHS 4
28struct {
29 int w,h;
30} modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
31int depths[4] = {8,16,24,32};
32
33
34/**********************************************************************/
35
36#define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
37
38MONITOR MONITOR_PrimaryMonitor;
39
40/* PM Monitor */
41
42/***********************************************************************
43 * PMDRV_MONITOR_Initialize
44 */
45void PMDRV_MONITOR_Initialize(MONITOR *pMonitor)
46{
47 dprintf(("MONITOR: PMDRV_Initialize"));
48
49 pMonitor->pDriverData = NULL;
50}
51
52/***********************************************************************
53 * PMDRV_MONITOR_Finalize
54 */
55void PMDRV_MONITOR_Finalize(MONITOR *pMonitor)
56{
57 dprintf(("MONITOR: PMDRV_Finalize"));
58}
59
60/***********************************************************************
61 * PMDRV_MONITOR_IsSingleWindow
62 */
63BOOL PMDRV_MONITOR_IsSingleWindow(MONITOR *pMonitor)
64{
65 dprintf(("MONITOR: PMDRV_IsSingleWindow"));
66
67 return TRUE; //CB: right???
68}
69
70/***********************************************************************
71 * PMDRV_MONITOR_GetWidth
72 *
73 * Return the width of the monitor
74 */
75int PMDRV_MONITOR_GetWidth(MONITOR *pMonitor)
76{
77 dprintf(("MONITOR: PMDRV_GetWidth"));
78
79 return GetSystemMetrics(SM_CXSCREEN);
80}
81
82/***********************************************************************
83 * PMDRV_MONITOR_GetHeight
84 *
85 * Return the height of the monitor
86 */
87int PMDRV_MONITOR_GetHeight(MONITOR *pMonitor)
88{
89 dprintf(("MONITOR: PMDRV_GetHeight"));
90
91 return GetSystemMetrics(SM_CYSCREEN);
92}
93
94/***********************************************************************
95 * PMDRV_MONITOR_GetDepth
96 *
97 * Return the depth of the monitor
98 */
99int PMDRV_MONITOR_GetDepth(MONITOR *pMonitor)
100{
101 dprintf(("MONITOR: PMDRV_GetDepth"));
102
103 return 24; //CB: change, right???
104}
105
106/***********************************************************************
107 * PMDRV_MONITOR_GetScreenSaveActive
108 *
109 * Returns the active status of the screen saver
110 */
111BOOL PMDRV_MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
112{
113 dprintf(("MONITOR: PMDRV_GetScreenSaveActive"));
114
115 return FALSE;
116}
117
118/***********************************************************************
119 * PMDRV_MONITOR_SetScreenSaveActive
120 *
121 * Activate/Deactivate the screen saver
122 */
123void PMDRV_MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
124{
125 dprintf(("MONITOR: PMDRV_SetScreenSaveActive"));
126}
127
128/***********************************************************************
129 * PMDRV_MONITOR_GetScreenSaveTimeout
130 *
131 * Return the screen saver timeout
132 */
133int PMDRV_MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
134{
135 dprintf(("MONITOR: PMDRV_GetScreenSaveTimeout"));
136
137 return 60*1000; //CB: stub
138}
139
140/***********************************************************************
141 * PMDRV_MONITOR_SetScreenSaveTimeout
142 *
143 * Set the screen saver timeout
144 */
145void PMDRV_MONITOR_SetScreenSaveTimeout(
146 MONITOR *pMonitor, int nTimeout)
147{
148 dprintf(("MONITOR: PMDRV_SetScreenSaveTimeout"));
149}
150
151MONITOR_DRIVER PM_MONITOR_Driver =
152{
153 PMDRV_MONITOR_Initialize,
154 PMDRV_MONITOR_Finalize,
155 PMDRV_MONITOR_IsSingleWindow,
156 PMDRV_MONITOR_GetWidth,
157 PMDRV_MONITOR_GetHeight,
158 PMDRV_MONITOR_GetDepth,
159 PMDRV_MONITOR_GetScreenSaveActive,
160 PMDRV_MONITOR_SetScreenSaveActive,
161 PMDRV_MONITOR_GetScreenSaveTimeout,
162 PMDRV_MONITOR_SetScreenSaveTimeout
163};
164
165MONITOR_DRIVER *MONITOR_Driver = &PM_MONITOR_Driver;
166
167/***********************************************************************
168 * MONITOR_GetMonitor
169 */
170static MONITOR *MONITOR_GetMonitor(HMONITOR hMonitor)
171{
172 if(hMonitor == xPRIMARY_MONITOR)
173 {
174 return &MONITOR_PrimaryMonitor;
175 }
176 else
177 {
178 return NULL;
179 }
180}
181
182/***********************************************************************
183 * MONITOR_Initialize
184 */
185void MONITOR_Initialize(MONITOR *pMonitor)
186{
187 MONITOR_Driver->pInitialize(pMonitor);
188}
189
190/***********************************************************************
191 * MONITOR_Finalize
192 */
193void MONITOR_Finalize(MONITOR *pMonitor)
194{
195 MONITOR_Driver->pFinalize(pMonitor);
196}
197
198/***********************************************************************
199 * MONITOR_IsSingleWindow
200 */
201BOOL MONITOR_IsSingleWindow(MONITOR *pMonitor)
202{
203 return MONITOR_Driver->pIsSingleWindow(pMonitor);
204}
205
206/***********************************************************************
207 * MONITOR_GetWidth
208 */
209int MONITOR_GetWidth(MONITOR *pMonitor)
210{
211 return MONITOR_Driver->pGetWidth(pMonitor);
212}
213
214/***********************************************************************
215 * MONITOR_GetHeight
216 */
217int MONITOR_GetHeight(MONITOR *pMonitor)
218{
219 return MONITOR_Driver->pGetHeight(pMonitor);
220}
221
222/***********************************************************************
223 * MONITOR_GetDepth
224 */
225int MONITOR_GetDepth(MONITOR *pMonitor)
226{
227 return MONITOR_Driver->pGetDepth(pMonitor);
228}
229
230/***********************************************************************
231 * MONITOR_GetScreenSaveActive
232 */
233BOOL MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
234{
235 return MONITOR_Driver->pGetScreenSaveActive(pMonitor);
236}
237
238/***********************************************************************
239 * MONITOR_SetScreenSaveActive
240 */
241void MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
242{
243 MONITOR_Driver->pSetScreenSaveActive(pMonitor, bActivate);
244}
245
246/***********************************************************************
247 * MONITOR_GetScreenSaveTimeout
248 */
249int MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
250{
251 return MONITOR_Driver->pGetScreenSaveTimeout(pMonitor);
252}
253
254/***********************************************************************
255 * MONITOR_SetScreenSaveTimeout
256 */
257void MONITOR_SetScreenSaveTimeout(MONITOR *pMonitor, int nTimeout)
258{
259 MONITOR_Driver->pSetScreenSaveTimeout(pMonitor, nTimeout);
260}
261
262/*****************************************************************************
263 * Name : BOOL WIN32API EnumDisplaySettingsA
264 * Purpose : The EnumDisplaySettings function obtains information about one
265 * of a display device's graphics modes. You can obtain information
266 * for all of a display device's graphics modes by making a series
267 * of calls to this function.
268 * Parameters: LPCTSTR lpszDeviceName specifies the display device
269 * DWORD iModeNum specifies the graphics mode
270 * LPDEVMODE lpDevMode points to structure to receive settings
271 * Variables :
272 * Result : If the function succeeds, the return value is TRUE.
273 * If the function fails, the return value is FALSE.
274 * Remark :
275 * Status :
276 *
277 * Author : Wine Port (991031)
278 *****************************************************************************/
279BOOL WIN32API EnumDisplaySettingsA(
280 LPCSTR name, /* [in] huh? */
281 DWORD n, /* [in] nth entry in display settings list*/
282 LPDEVMODEA devmode /* [out] devmode for that setting */
283)
284{
285 dprintf(("USER32: EnumDisplaySettingsA %d", n));
286 if (n==0) {
287 devmode->dmBitsPerPel = ScreenBitsPerPel;
288 devmode->dmPelsHeight = ScreenHeight;
289 devmode->dmPelsWidth = ScreenWidth;
290 return TRUE;
291 }
292 if ((n-1)<NRMODES*NRDEPTHS) {
293 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
294 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
295 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
296 return TRUE;
297 }
298 return FALSE;
299}
300
301/*****************************************************************************
302 * Name : BOOL WIN32API EnumDisplaySettingsW
303 * Purpose : The EnumDisplaySettings function obtains information about one
304 * of a display device's graphics modes. You can obtain information
305 * for all of a display device's graphics modes by making a series
306 * of calls to this function.
307 * Parameters: LPCTSTR lpszDeviceName specifies the display device
308 * DWORD iModeNum specifies the graphics mode
309 * LPDEVMODE lpDevMode points to structure to receive settings
310 * Variables :
311 * Result : If the function succeeds, the return value is TRUE.
312 * If the function fails, the return value is FALSE.
313 * Remark :
314 * Status :
315 *
316 * Author : Wine Port (991031)
317 *****************************************************************************/
318BOOL WIN32API EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode)
319{
320 LPSTR nameA = NULL;
321 DEVMODEA devmodeA;
322 BOOL ret;
323
324 if(name) {
325 nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
326 }
327 ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
328
329 if (ret) {
330 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
331 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
332 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
333 /* FIXME: convert rest too, if they are ever returned */
334 }
335 if(name)
336 HeapFree(GetProcessHeap(),0,nameA);
337 return ret;
338}
339//******************************************************************************
340//******************************************************************************
341LONG WIN32API ChangeDisplaySettingsA(LPDEVMODEA lpDevMode, DWORD dwFlags)
342{
343 // lpDevMode might be NULL when change to default desktop mode
344 // is being requested, this was the cause of trap
345 if ( !lpDevMode )
346 {
347 return(DISP_CHANGE_SUCCESSFUL);
348 }
349#ifdef DEBUG
350 if(lpDevMode) {
351 WriteLog("USER32: ChangeDisplaySettingsA FAKED %X\n", dwFlags);
352 WriteLog("USER32: ChangeDisplaySettingsA lpDevMode->dmBitsPerPel %d\n", lpDevMode->dmBitsPerPel);
353 WriteLog("USER32: ChangeDisplaySettingsA lpDevMode->dmPelsWidth %d\n", lpDevMode->dmPelsWidth);
354 WriteLog("USER32: ChangeDisplaySettingsA lpDevMode->dmPelsHeight %d\n", lpDevMode->dmPelsHeight);
355 }
356#endif
357 return(DISP_CHANGE_SUCCESSFUL);
358}
359/*****************************************************************************
360 * Name : LONG WIN32API ChangeDisplaySettingsW
361 * Purpose : The ChangeDisplaySettings function changes the display settings
362 * to the specified graphics mode.
363 * Parameters: LPDEVMODEW lpDevModeW
364 * DWORD dwFlags
365 * Variables :
366 * Result : DISP_CHANGE_SUCCESSFUL The settings change was successful.
367 * DISP_CHANGE_RESTART The computer must be restarted in order for the graphics mode to work.
368 * DISP_CHANGE_BADFLAGS An invalid set of flags was passed in.
369 * DISP_CHANGE_FAILED The display driver failed the specified graphics mode.
370 * DISP_CHANGE_BADMODE The graphics mode is not supported.
371 * DISP_CHANGE_NOTUPDATED Unable to write settings to the registry.
372 * Remark :
373 * Status : UNTESTED STUB
374 *
375 * Author : Patrick Haller [Wed, 1998/06/16 11:55]
376 *****************************************************************************/
377LONG WIN32API ChangeDisplaySettingsW(LPDEVMODEW lpDevMode,
378 DWORD dwFlags)
379{
380 dprintf(("USER32:ChangeDisplaySettingsW(%08xh,%08x) not implemented.\n",
381 lpDevMode,
382 dwFlags));
383
384 return (ChangeDisplaySettingsA((LPDEVMODEA)lpDevMode,
385 dwFlags));
386}
387//******************************************************************************
388//******************************************************************************
389LONG WIN32API ChangeDisplaySettingsExA(LPCSTR devname, LPDEVMODEA lpDevMode,
390 HWND hwnd, DWORD dwFlags, LPARAM lparam)
391{
392 // lpDevMode might be NULL when change to default desktop mode
393 // is being requested, this was the cause of trap
394 if ( !lpDevMode )
395 {
396 return(DISP_CHANGE_SUCCESSFUL);
397 }
398#ifdef DEBUG
399 if(lpDevMode) {
400 WriteLog("USER32: ChangeDisplaySettingsExA FAKED %X\n", dwFlags);
401 WriteLog("USER32: ChangeDisplaySettingsExA lpDevMode->dmBitsPerPel %d\n", lpDevMode->dmBitsPerPel);
402 WriteLog("USER32: ChangeDisplaySettingsExA lpDevMode->dmPelsWidth %d\n", lpDevMode->dmPelsWidth);
403 WriteLog("USER32: ChangeDisplaySettingsExA lpDevMode->dmPelsHeight %d\n", lpDevMode->dmPelsHeight);
404 }
405#endif
406 return(DISP_CHANGE_SUCCESSFUL);
407}
408//******************************************************************************
409//******************************************************************************
410LONG WIN32API ChangeDisplaySettingsExW(LPCWSTR devname, LPDEVMODEW lpDevMode,
411 HWND hwnd, DWORD dwFlags, LPARAM lparam)
412{
413 dprintf(("USER32:ChangeDisplaySettingsExW(%08xh,%08x) NOT implemented.\n",
414 lpDevMode,
415 dwFlags));
416
417 //TODO: Need unicode translation
418 return (ChangeDisplaySettingsExA((LPCSTR)devname, (LPDEVMODEA)lpDevMode,
419 hwnd, dwFlags, lparam));
420}
421//******************************************************************************
422//******************************************************************************
423BOOL WIN32API GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
424{
425 RECT rcWork;
426
427 dprintf(("USER32: GetMonitorInfoA\n"));
428
429 if ((hMonitor == xPRIMARY_MONITOR) &&
430 lpMonitorInfo &&
431 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
432 SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
433 {
434 lpMonitorInfo->rcMonitor.left = 0;
435 lpMonitorInfo->rcMonitor.top = 0;
436 lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
437 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
438 lpMonitorInfo->rcWork = rcWork;
439 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
440
441 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
442 lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
443
444 return TRUE;
445 }
446
447 return FALSE;
448}
449//******************************************************************************
450//******************************************************************************
451BOOL WIN32API GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
452{
453 RECT rcWork;
454
455 dprintf(("USER32: GetMonitorInfoW\n"));
456
457 if ((hMonitor == xPRIMARY_MONITOR) &&
458 lpMonitorInfo &&
459 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
460 SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
461 {
462 lpMonitorInfo->rcMonitor.left = 0;
463 lpMonitorInfo->rcMonitor.top = 0;
464 lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
465 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
466 lpMonitorInfo->rcWork = rcWork;
467 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
468
469 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
470 lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
471
472 return TRUE;
473 }
474
475 return FALSE;
476}
477//******************************************************************************
478//******************************************************************************
479HMONITOR WIN32API MonitorFromWindow(HWND hWnd, DWORD dwFlags)
480{
481 WINDOWPLACEMENT wp;
482
483 dprintf(("USER32: MonitorFromWindow\n"));
484
485 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
486 return xPRIMARY_MONITOR;
487
488 if (IsIconic(hWnd) ?
489 GetWindowPlacement(hWnd, &wp) :
490 GetWindowRect(hWnd, &wp.rcNormalPosition)) {
491
492 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
493 }
494
495 return NULL;
496}
497//******************************************************************************
498//******************************************************************************
499HMONITOR WIN32API MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
500{
501 dprintf(("USER32: MonitorFromRect\n"));
502
503 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
504 ((lprcScreenCoords->right > 0) &&
505 (lprcScreenCoords->bottom > 0) &&
506 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
507 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
508 {
509 return xPRIMARY_MONITOR;
510 }
511 return NULL;
512}
513//******************************************************************************
514//******************************************************************************
515HMONITOR WIN32API MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
516{
517 dprintf(("USER32: MonitorFromPoint\n"));
518
519 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
520 ((ptScreenCoords.x >= 0) &&
521 (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
522 (ptScreenCoords.y >= 0) &&
523 (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
524 {
525 return xPRIMARY_MONITOR;
526 }
527
528 return NULL;
529}
530//******************************************************************************
531//******************************************************************************
532BOOL WIN32API EnumDisplayMonitors(
533 HDC hdcOptionalForPainting,
534 LPRECT lprcEnumMonitorsThatIntersect,
535 MONITORENUMPROC lpfnEnumProc,
536 LPARAM dwData)
537{
538 dprintf(("USER32: EnumDisplayMonitors\n"));
539
540 RECT rcLimit;
541
542 if (!lpfnEnumProc)
543 return FALSE;
544
545 rcLimit.left = 0;
546 rcLimit.top = 0;
547 rcLimit.right = GetSystemMetrics(SM_CXSCREEN);
548 rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);
549
550 if (hdcOptionalForPainting)
551 {
552 RECT rcClip;
553 POINT ptOrg;
554
555 switch (GetClipBox(hdcOptionalForPainting, &rcClip))
556 {
557 default:
558 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
559 return FALSE;
560
561 OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
562 if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
563 (!lprcEnumMonitorsThatIntersect ||
564 IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
565
566 break;
567 }
568 /*fall thru */
569 case NULLREGION:
570 return TRUE;
571 case ERROR:
572 return FALSE;
573 }
574 } else {
575 if ( lprcEnumMonitorsThatIntersect &&
576 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
577
578 return TRUE;
579 }
580 }
581
582 return lpfnEnumProc(
583 xPRIMARY_MONITOR,
584 hdcOptionalForPainting,
585 &rcLimit,
586 dwData);
587}
588//******************************************************************************
589//******************************************************************************
Note: See TracBrowser for help on using the repository browser.