Ignore:
Timestamp:
Nov 27, 1999, 3:16:35 PM (26 years ago)
Author:
cbratschi
Message:

edit fixes, monitor API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/display.cpp

    r1818 r1860  
    1 /* $Id: display.cpp,v 1.1 1999-11-23 19:34:19 sandervl Exp $ */
     1/* $Id: display.cpp,v 1.2 1999-11-27 14:16:34 cbratschi Exp $ */
    22/*
    33 * Display/Monitor Win32 apis
     
    66 *
    77 * Copyright 1993 Robert J. Amstadt
    8  *           1996 Alex Korobka
     8 *           1996 Alex Korobka
     9 * Copyright 1998 Turchanov Sergey
     10 *
     11 * Copyright 1999 Christoph Bratschi
    912 *
    1013 * Project Odin Software License can be found in LICENSE.TXT
     
    1518#include <heapstring.h>
    1619#include "pmwindow.h"
     20#include "monitor.h"
     21#include "windef.h"
    1722
    1823#define NRMODES 5
    1924#define NRDEPTHS 4
    2025struct {
    21         int w,h;
     26        int w,h;
    2227} modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
    2328int depths[4] = {8,16,24,32};
     29
     30
     31/**********************************************************************/
     32
     33#define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
     34
     35MONITOR MONITOR_PrimaryMonitor;
     36
     37/* PM Monitor */
     38
     39/***********************************************************************
     40 *              PMDRV_MONITOR_Initialize
     41 */
     42void PMDRV_MONITOR_Initialize(MONITOR *pMonitor)
     43{
     44  dprintf(("MONITOR: PMDRV_Initialize"));
     45
     46  pMonitor->pDriverData = NULL;
     47}
     48
     49/***********************************************************************
     50 *              PMDRV_MONITOR_Finalize
     51 */
     52void PMDRV_MONITOR_Finalize(MONITOR *pMonitor)
     53{
     54  dprintf(("MONITOR: PMDRV_Finalize"));
     55}
     56
     57/***********************************************************************
     58 *              PMDRV_MONITOR_IsSingleWindow
     59 */
     60BOOL PMDRV_MONITOR_IsSingleWindow(MONITOR *pMonitor)
     61{
     62  dprintf(("MONITOR: PMDRV_IsSingleWindow"));
     63
     64  return TRUE; //CB: right???
     65}
     66
     67/***********************************************************************
     68 *              PMDRV_MONITOR_GetWidth
     69 *
     70 * Return the width of the monitor
     71 */
     72int PMDRV_MONITOR_GetWidth(MONITOR *pMonitor)
     73{
     74  dprintf(("MONITOR: PMDRV_GetWidth"));
     75
     76  return GetSystemMetrics(SM_CXSCREEN);
     77}
     78
     79/***********************************************************************
     80 *              PMDRV_MONITOR_GetHeight
     81 *
     82 * Return the height of the monitor
     83 */
     84int PMDRV_MONITOR_GetHeight(MONITOR *pMonitor)
     85{
     86  dprintf(("MONITOR: PMDRV_GetHeight"));
     87
     88  return GetSystemMetrics(SM_CYSCREEN);
     89}
     90
     91/***********************************************************************
     92 *              PMDRV_MONITOR_GetDepth
     93 *
     94 * Return the depth of the monitor
     95 */
     96int PMDRV_MONITOR_GetDepth(MONITOR *pMonitor)
     97{
     98  dprintf(("MONITOR: PMDRV_GetDepth"));
     99
     100  return 24; //CB: change, right???
     101}
     102
     103/***********************************************************************
     104 *              PMDRV_MONITOR_GetScreenSaveActive
     105 *
     106 * Returns the active status of the screen saver
     107 */
     108BOOL PMDRV_MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
     109{
     110  dprintf(("MONITOR: PMDRV_GetScreenSaveActive"));
     111
     112  return FALSE;
     113}
     114
     115/***********************************************************************
     116 *              PMDRV_MONITOR_SetScreenSaveActive
     117 *
     118 * Activate/Deactivate the screen saver
     119 */
     120void PMDRV_MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
     121{
     122  dprintf(("MONITOR: PMDRV_SetScreenSaveActive"));
     123}
     124
     125/***********************************************************************
     126 *              PMDRV_MONITOR_GetScreenSaveTimeout
     127 *
     128 * Return the screen saver timeout
     129 */
     130int PMDRV_MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
     131{
     132  dprintf(("MONITOR: PMDRV_GetScreenSaveTimeout"));
     133
     134  return 60*1000; //CB: stub
     135}
     136
     137/***********************************************************************
     138 *              PMDRV_MONITOR_SetScreenSaveTimeout
     139 *
     140 * Set the screen saver timeout
     141 */
     142void PMDRV_MONITOR_SetScreenSaveTimeout(
     143  MONITOR *pMonitor, int nTimeout)
     144{
     145  dprintf(("MONITOR: PMDRV_SetScreenSaveTimeout"));
     146}
     147
     148MONITOR_DRIVER PM_MONITOR_Driver =
     149{
     150  PMDRV_MONITOR_Initialize,
     151  PMDRV_MONITOR_Finalize,
     152  PMDRV_MONITOR_IsSingleWindow,
     153  PMDRV_MONITOR_GetWidth,
     154  PMDRV_MONITOR_GetHeight,
     155  PMDRV_MONITOR_GetDepth,
     156  PMDRV_MONITOR_GetScreenSaveActive,
     157  PMDRV_MONITOR_SetScreenSaveActive,
     158  PMDRV_MONITOR_GetScreenSaveTimeout,
     159  PMDRV_MONITOR_SetScreenSaveTimeout
     160};
     161
     162MONITOR_DRIVER *MONITOR_Driver = &PM_MONITOR_Driver;
     163
     164/***********************************************************************
     165 *              MONITOR_GetMonitor
     166 */
     167static MONITOR *MONITOR_GetMonitor(HMONITOR hMonitor)
     168{
     169  if(hMonitor == xPRIMARY_MONITOR)
     170    {
     171      return &MONITOR_PrimaryMonitor;
     172    }
     173  else
     174    {
     175      return NULL;
     176    }
     177}
     178
     179/***********************************************************************
     180 *              MONITOR_Initialize
     181 */
     182void MONITOR_Initialize(MONITOR *pMonitor)
     183{
     184  MONITOR_Driver->pInitialize(pMonitor);
     185}
     186
     187/***********************************************************************
     188 *              MONITOR_Finalize
     189 */
     190void MONITOR_Finalize(MONITOR *pMonitor)
     191{
     192  MONITOR_Driver->pFinalize(pMonitor);
     193}
     194
     195/***********************************************************************
     196 *              MONITOR_IsSingleWindow
     197 */
     198BOOL MONITOR_IsSingleWindow(MONITOR *pMonitor)
     199{
     200  return MONITOR_Driver->pIsSingleWindow(pMonitor);
     201}
     202
     203/***********************************************************************
     204 *              MONITOR_GetWidth
     205 */
     206int MONITOR_GetWidth(MONITOR *pMonitor)
     207{
     208  return MONITOR_Driver->pGetWidth(pMonitor);
     209}
     210
     211/***********************************************************************
     212 *              MONITOR_GetHeight
     213 */
     214int MONITOR_GetHeight(MONITOR *pMonitor)
     215{
     216  return MONITOR_Driver->pGetHeight(pMonitor);
     217}
     218
     219/***********************************************************************
     220 *              MONITOR_GetDepth
     221 */
     222int MONITOR_GetDepth(MONITOR *pMonitor)
     223{
     224  return MONITOR_Driver->pGetDepth(pMonitor);
     225}
     226
     227/***********************************************************************
     228 *              MONITOR_GetScreenSaveActive
     229 */
     230BOOL MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
     231{
     232  return MONITOR_Driver->pGetScreenSaveActive(pMonitor);
     233}
     234
     235/***********************************************************************
     236 *              MONITOR_SetScreenSaveActive
     237 */
     238void MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
     239{
     240  MONITOR_Driver->pSetScreenSaveActive(pMonitor, bActivate);
     241}
     242
     243/***********************************************************************
     244 *              MONITOR_GetScreenSaveTimeout
     245 */
     246int MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
     247{
     248  return MONITOR_Driver->pGetScreenSaveTimeout(pMonitor);
     249}
     250
     251/***********************************************************************
     252 *              MONITOR_SetScreenSaveTimeout
     253 */
     254void MONITOR_SetScreenSaveTimeout(MONITOR *pMonitor, int nTimeout)
     255{
     256  MONITOR_Driver->pSetScreenSaveTimeout(pMonitor, nTimeout);
     257}
    24258
    25259/*****************************************************************************
     
    36270 *             If the function fails, the return value is FALSE.
    37271 * Remark    :
    38  * Status    : 
     272 * Status    :
    39273 *
    40274 * Author    : Wine Port (991031)
    41275 *****************************************************************************/
    42276BOOL WIN32API EnumDisplaySettingsA(
    43         LPCSTR name,            /* [in] huh? */
    44         DWORD n,                /* [in] nth entry in display settings list*/
    45         LPDEVMODEA devmode      /* [out] devmode for that setting */
    46 ) 
    47 {
    48         dprintf(("USER32:  EnumDisplaySettingsA %d", n));
    49         if (n==0) {
    50                 devmode->dmBitsPerPel = ScreenBitsPerPel;
    51                 devmode->dmPelsHeight = ScreenHeight;
    52                 devmode->dmPelsWidth = ScreenWidth;
    53                 return TRUE;
    54         }
    55         if ((n-1)<NRMODES*NRDEPTHS) {
    56                 devmode->dmBitsPerPel   = depths[(n-1)/NRMODES];
    57                 devmode->dmPelsHeight   = modes[(n-1)%NRMODES].h;
    58                 devmode->dmPelsWidth    = modes[(n-1)%NRMODES].w;
    59                 return TRUE;
    60         }
    61         return FALSE;
     277        LPCSTR name,            /* [in] huh? */
     278        DWORD n,                /* [in] nth entry in display settings list*/
     279        LPDEVMODEA devmode      /* [out] devmode for that setting */
     280)
     281{
     282        dprintf(("USER32:  EnumDisplaySettingsA %d", n));
     283        if (n==0) {
     284                devmode->dmBitsPerPel = ScreenBitsPerPel;
     285                devmode->dmPelsHeight = ScreenHeight;
     286                devmode->dmPelsWidth = ScreenWidth;
     287                return TRUE;
     288        }
     289        if ((n-1)<NRMODES*NRDEPTHS) {
     290                devmode->dmBitsPerPel   = depths[(n-1)/NRMODES];
     291                devmode->dmPelsHeight   = modes[(n-1)%NRMODES].h;
     292                devmode->dmPelsWidth    = modes[(n-1)%NRMODES].w;
     293                return TRUE;
     294        }
     295        return FALSE;
    62296}
    63297
     
    75309 *             If the function fails, the return value is FALSE.
    76310 * Remark    :
    77  * Status    : 
     311 * Status    :
    78312 *
    79313 * Author    : Wine Port (991031)
    80314 *****************************************************************************/
    81 BOOL WIN32API EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) 
     315BOOL WIN32API EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode)
    82316{
    83317 LPSTR    nameA = NULL;
    84  DEVMODEA devmodeA; 
     318 DEVMODEA devmodeA;
    85319 BOOL     ret;
    86320
    87         if(name) {
    88                 nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
     321        if(name) {
     322                nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
    89323        }
    90         ret = EnumDisplaySettingsA(nameA,n,&devmodeA); 
    91 
    92         if (ret) {
    93                 devmode->dmBitsPerPel   = devmodeA.dmBitsPerPel;
    94                 devmode->dmPelsHeight   = devmodeA.dmPelsHeight;
    95                 devmode->dmPelsWidth    = devmodeA.dmPelsWidth;
    96                 /* FIXME: convert rest too, if they are ever returned */
    97         }
     324        ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
     325
     326        if (ret) {
     327                devmode->dmBitsPerPel   = devmodeA.dmBitsPerPel;
     328                devmode->dmPelsHeight   = devmodeA.dmPelsHeight;
     329                devmode->dmPelsWidth    = devmodeA.dmPelsWidth;
     330                /* FIXME: convert rest too, if they are ever returned */
     331        }
    98332        if(name)
    99                 HeapFree(GetProcessHeap(),0,nameA);
    100         return ret;
     333                HeapFree(GetProcessHeap(),0,nameA);
     334        return ret;
    101335}
    102336//******************************************************************************
     
    150384//******************************************************************************
    151385//******************************************************************************
    152 LONG WIN32API ChangeDisplaySettingsExA(LPCSTR devname, LPDEVMODEA lpDevMode, 
     386LONG WIN32API ChangeDisplaySettingsExA(LPCSTR devname, LPDEVMODEA lpDevMode,
    153387                                       HWND hwnd, DWORD dwFlags, LPARAM lparam)
    154388{
     
    171405//******************************************************************************
    172406//******************************************************************************
    173 LONG WIN32API ChangeDisplaySettingsExW(LPCWSTR devname, LPDEVMODEW lpDevMode, 
     407LONG WIN32API ChangeDisplaySettingsExW(LPCWSTR devname, LPDEVMODEW lpDevMode,
    174408                                       HWND hwnd, DWORD dwFlags, LPARAM lparam)
    175409{
     
    184418//******************************************************************************
    185419//******************************************************************************
    186 BOOL WIN32API GetMonitorInfoA(HMONITOR,LPMONITORINFO)
    187 {
    188   dprintf(("USER32:  GetMonitorInfoA not supported!!\n"));
    189   return(FALSE);
    190 }
    191 //******************************************************************************
    192 //******************************************************************************
    193 BOOL WIN32API GetMonitorInfoW(HMONITOR,LPMONITORINFO)
    194 {
    195   dprintf(("USER32:  GetMonitorInfoW not supported!!\n"));
    196   return(FALSE);
    197 }
    198 //******************************************************************************
    199 //******************************************************************************
    200 HMONITOR WIN32API MonitorFromWindow(HWND hwnd, DWORD dwFlags)
    201 {
    202   dprintf(("USER32:  MonitorFromWindow not correctly supported??\n"));
    203   //Attention: Win32 hwnd!
    204 
    205   return(0);
    206 }
    207 //******************************************************************************
    208 //******************************************************************************
    209 HMONITOR WIN32API MonitorFromRect(LPRECT rect, DWORD dwFlags)
    210 {
    211   dprintf(("USER32:  MonitorFromRect not correctly supported??\n"));
    212   return(0);
    213 }
    214 //******************************************************************************
    215 //******************************************************************************
    216 HMONITOR WIN32API MonitorFromPoint(POINT point, DWORD dwflags)
    217 {
    218   dprintf(("USER32:  MonitorFromPoint not correctly supported??\n"));
    219   return(0);
    220 }
    221 //******************************************************************************
    222 //******************************************************************************
    223 BOOL WIN32API EnumDisplayMonitors(HDC,LPRECT,MONITORENUMPROC,LPARAM)
    224 {
    225   dprintf(("USER32:  EnumDisplayMonitors not supported??\n"));
    226   return(FALSE);
    227 }
    228 //******************************************************************************
    229 //******************************************************************************
     420BOOL WIN32API GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
     421{
     422    RECT rcWork;
     423
     424    dprintf(("USER32:  GetMonitorInfoA\n"));
     425
     426    if ((hMonitor == xPRIMARY_MONITOR) &&
     427        lpMonitorInfo &&
     428        (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
     429        SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
     430    {
     431        lpMonitorInfo->rcMonitor.left = 0;
     432        lpMonitorInfo->rcMonitor.top  = 0;
     433        lpMonitorInfo->rcMonitor.right  = GetSystemMetrics(SM_CXSCREEN);
     434        lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
     435        lpMonitorInfo->rcWork = rcWork;
     436        lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
     437       
     438        if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
     439            lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
     440
     441        return TRUE;
     442    }
     443
     444    return FALSE;
     445}
     446//******************************************************************************
     447//******************************************************************************
     448BOOL WIN32API GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
     449{
     450    RECT rcWork;
     451
     452    dprintf(("USER32:  GetMonitorInfoW\n"));
     453
     454    if ((hMonitor == xPRIMARY_MONITOR) &&
     455        lpMonitorInfo &&
     456        (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
     457        SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
     458    {
     459        lpMonitorInfo->rcMonitor.left = 0;
     460        lpMonitorInfo->rcMonitor.top  = 0;
     461        lpMonitorInfo->rcMonitor.right  = GetSystemMetrics(SM_CXSCREEN);
     462        lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
     463        lpMonitorInfo->rcWork = rcWork;
     464        lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
     465
     466        if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
     467            lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
     468
     469        return TRUE;
     470    }
     471
     472    return FALSE;
     473}
     474//******************************************************************************
     475//******************************************************************************
     476HMONITOR WIN32API MonitorFromWindow(HWND hWnd, DWORD dwFlags)
     477{
     478   WINDOWPLACEMENT wp;
     479
     480    dprintf(("USER32:  MonitorFromWindow\n"));
     481
     482    if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
     483        return xPRIMARY_MONITOR;
     484
     485    if (IsIconic(hWnd) ?
     486            GetWindowPlacement(hWnd, &wp) :
     487            GetWindowRect(hWnd, &wp.rcNormalPosition)) {
     488
     489        return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
     490    }
     491
     492    return NULL;
     493}
     494//******************************************************************************
     495//******************************************************************************
     496HMONITOR WIN32API MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
     497{
     498    dprintf(("USER32:  MonitorFromRect\n"));
     499
     500      if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
     501        ((lprcScreenCoords->right > 0) &&
     502        (lprcScreenCoords->bottom > 0) &&
     503        (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
     504        (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
     505    {
     506        return xPRIMARY_MONITOR;
     507    }
     508    return NULL;
     509}
     510//******************************************************************************
     511//******************************************************************************
     512HMONITOR WIN32API MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
     513{
     514  dprintf(("USER32:  MonitorFromPoint\n"));
     515
     516  if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
     517      ((ptScreenCoords.x >= 0) &&
     518      (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
     519      (ptScreenCoords.y >= 0) &&
     520      (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
     521  {
     522    return xPRIMARY_MONITOR;
     523  }
     524
     525  return NULL;
     526}
     527//******************************************************************************
     528//******************************************************************************
     529BOOL WIN32API EnumDisplayMonitors(
     530        HDC             hdcOptionalForPainting,
     531        LPRECT         lprcEnumMonitorsThatIntersect,
     532        MONITORENUMPROC lpfnEnumProc,
     533        LPARAM          dwData)
     534{
     535  dprintf(("USER32:  EnumDisplayMonitors\n"));
     536
     537    RECT rcLimit;
     538
     539    if (!lpfnEnumProc)
     540        return FALSE;
     541
     542    rcLimit.left   = 0;
     543    rcLimit.top    = 0;
     544    rcLimit.right  = GetSystemMetrics(SM_CXSCREEN);
     545    rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);
     546
     547    if (hdcOptionalForPainting)
     548    {
     549        RECT    rcClip;
     550        POINT   ptOrg;
     551
     552        switch (GetClipBox(hdcOptionalForPainting, &rcClip))
     553        {
     554        default:
     555            if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
     556                return FALSE;
     557
     558            OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
     559            if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
     560                (!lprcEnumMonitorsThatIntersect ||
     561                     IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
     562
     563                break;
     564            }
     565            /*fall thru */
     566        case NULLREGION:
     567             return TRUE;
     568        case ERROR:
     569             return FALSE;
     570        }
     571    } else {
     572        if (    lprcEnumMonitorsThatIntersect &&
     573                !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
     574
     575            return TRUE;
     576        }
     577    }
     578
     579    return lpfnEnumProc(
     580            xPRIMARY_MONITOR,
     581            hdcOptionalForPainting,
     582            &rcLimit,
     583            dwData);
     584}
     585//******************************************************************************
     586//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.