Ignore:
Timestamp:
Sep 12, 1999, 5:44:20 PM (26 years ago)
Author:
dengert
Message:

first implementation of GetDCEx

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/new/dc.cpp

    r903 r911  
    1 /* $Id: dc.cpp,v 1.2 1999-09-10 19:00:10 dengert Exp $ */
     1/* $Id: dc.cpp,v 1.3 1999-09-12 15:44:20 dengert Exp $ */
    22
    33/*
     
    2323#include <math.h>
    2424#include <limits.h>
     25#include "oslibwin.h"
    2526
    2627#ifndef OPEN32API
     
    103104#define GM_ADVANCED_W       2
    104105
    105 #define DCX_WINDOW                    0x00000001L
    106 #define DCX_CACHE                     0x00000002L
    107 #define DCX_NORESETATTRS              0x00000004L
    108 #define DCX_CLIPCHILDREN              0x00000008L
    109 #define DCX_CLIPSIBLINGS              0x00000010L
    110 #define DCX_PARENTCLIP                0x00000020L
    111 #define DCX_EXCLUDERGN                0x00000040L
    112 #define DCX_INTERSECTRGN              0x00000080L
    113 #define DCX_EXCLUDEUPDATE             0x00000100L
    114 #define DCX_INTERSECTUPDATE           0x00000200L
    115 #define DCX_LOCKWINDOWUPDATE          0x00000400L
    116 #define DCX_VALIDATE                  0x00200000L
     106#define DCX_WINDOW_W                    0x00000001L
     107#define DCX_CACHE_W                     0x00000002L
     108#define DCX_NORESETATTRS_W              0x00000004L
     109#define DCX_CLIPCHILDREN_W              0x00000008L
     110#define DCX_CLIPSIBLINGS_W              0x00000010L
     111#define DCX_PARENTCLIP_W                0x00000020L
     112#define DCX_EXCLUDERGN_W                0x00000040L
     113#define DCX_INTERSECTRGN_W              0x00000080L
     114#define DCX_EXCLUDEUPDATE_W             0x00000100L
     115#define DCX_INTERSECTUPDATE_W           0x00000200L
     116#define DCX_LOCKWINDOWUPDATE_W          0x00000400L
     117#define DCX_VALIDATE_W                  0x00200000L
     118
     119typedef struct _RGNDATAHEADER_W {
     120    DWORD       dwSize;
     121    DWORD       iType;
     122    DWORD       nCount;
     123    DWORD       nRgnSize;
     124    RECT        rcBound;
     125} RGNDATAHEADER_W, *LPRGNDATAHEADER_W;
     126
     127typedef struct _RGNDATA_W {
     128    RGNDATAHEADER_W     rdh;
     129    char                Buffer[1];
     130} RGNDATA_W , *PRGNDATA_W , *LPRGNDATA_W ;
     131
    117132
    118133/* Xform FLAGS */
     
    251266BOOL    OPEN32API _O32_EndPaint (HWND hwnd, const PAINTSTRUCT_W *lpps);
    252267int     OPEN32API _O32_GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase);
     268ULONG   OPEN32API _O32_GetRegionData (HRGN hrgn, ULONG count, PRGNDATA_W pData);
     269BOOL    OPEN32API _O32_DeleteObject (LHANDLE hgdiobj);
    253270
    254271#define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0))
     
    276293const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
    277294
    278 BOOL setPageXForm(pDCData pHps);
    279 BOOL changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
    280 LONG clientHeight(HWND hwnd, pDCData pHps);
     295BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps);
     296BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
     297LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps);
    281298
    282299void TestWideLine (pDCData pHps)
     
    314331//******************************************************************************
    315332
    316 int setMapMode(pDCData pHps, int mode)
     333int setMapMode(Win32BaseWindow *wnd, pDCData pHps, int mode)
    317334{
    318335   int    prevMode = 0;
     
    376393      if (pHps->lWndXExtSave && pHps->lWndYExtSave)
    377394      {
    378          changePageXForm( pHps, (PPOINTL)&pHps->windowExt,
     395         changePageXForm (wnd, pHps, (PPOINTL)&pHps->windowExt,
    379396                          pHps->lWndXExtSave, pHps->lWndYExtSave, NULL );
    380397         pHps->lWndXExtSave = pHps->lWndYExtSave = 0;
     
    382399      if (pHps->lVwpXExtSave && pHps->lVwpYExtSave)
    383400      {
    384          changePageXForm( pHps, NULL,
     401         changePageXForm (wnd, pHps, NULL,
    385402                          pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL );
    386403         pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0;
     
    388405   }
    389406
    390    setPageXForm(pHps);
     407   setPageXForm(wnd, pHps);
    391408
    392409   return prevMode;
    393410}
    394411
    395 BOOL setPageXForm(pDCData pHps)
     412BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps)
    396413{
    397414   MATRIXLF mlf;
    398415   BOOL rc = TRUE;
    399416
    400    pHps->height = clientHeight(0, pHps) - 1;
     417   pHps->height = clientHeight(wnd, 0, pHps) - 1;
    401418
    402419   double xScale =  pHps->viewportXExt / (double)pHps->windowExt.cx;
     
    445462}
    446463
    447 BOOL changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
     464BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
    448465{
    449466   BOOL result = FALSE;
     
    500517      }
    501518   }
    502    result = setPageXForm(pHps);
     519   result = setPageXForm(wnd, pHps);
    503520
    504521   return (result);
    505522}
    506523
    507 LONG clientHeight(HWND hwnd, pDCData pHps)
     524LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
    508525{
    509526   if ((hwnd == 0) && (pHps != 0))
     
    512529   if ((hwnd != 0) || (pHps == 0))
    513530   {
    514       Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
    515       return (wnd->getWindowHeight());
     531      if (wnd)
     532         return (wnd->getWindowHeight());
     533      else
     534         return OSLibQueryScreenHeight();
    516535   }
    517536   else if (pHps->bitmapHandle)
     
    549568}
    550569
    551 void selectClientArea(Win32BaseWindow *wnd, pDCData pHps, PRECTL prclPaint)
     570BOOL selectClientArea(Win32BaseWindow *wnd, pDCData pHps, PRECTL prclPaint)
    552571{
    553572   RECTL rcl;
    554573   HRGN hrgnRect;
    555574   HWND hwnd;
     575
     576   if (!wnd) return (FALSE);
    556577
    557578   pHps->isClient = TRUE;
     
    583604   pHps->isClientArea = TRUE;
    584605   GreDestroyRegion(pHps->hps, hrgnRect);
     606
     607   return (TRUE);
    585608}
    586609
     
    672695
    673696   if (hPS_ownDC == 0)
    674       setMapMode(pHps, MM_TEXT_W);
    675    else
    676       setPageXForm(pHps);
     697      setMapMode (wnd, pHps, MM_TEXT_W);
     698   else
     699      setPageXForm (wnd, pHps);
    677700
    678701   pHps->hdcType = TYPE_3;
     
    800823}
    801824
     825// This implementation of GetDCEx supports
     826// DCX_WINDOW
     827// DCX_CACHE
     828// DCX_EXCLUDERGN (complex regions allowed)
     829// DCX_INTERSECTRGN (complex regions allowed)
     830
     831HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
     832{
     833   USHORT sel = RestoreOS2FS();
     834   Win32BaseWindow *wnd = NULL;
     835   HWND     hWindow;
     836   BOOL     success;
     837   pDCData  pHps = NULL;
     838   HPS      hps  = NULLHANDLE;
     839   BOOL     drawingAllowed = TRUE;
     840   BOOL     isWindowOwnDC;
     841   BOOL     creatingOwnDC = FALSE;
     842   PS_Type  psType;
     843
     844   if (hwnd)
     845   {
     846      wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
     847      if (flags & DCX_WINDOW_W)
     848         hWindow = wnd->getOS2FrameWindowHandle();
     849      else
     850         hWindow = wnd->getOS2WindowHandle();
     851   }
     852   else
     853      hWindow = HWND_DESKTOP;
     854
     855dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x", hwnd, hrgn, flags, wnd));
     856
     857   isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : wnd->isOwnDC())
     858                 && !(flags & DCX_CACHE_W));
     859   if (isWindowOwnDC)
     860   {
     861      hps = wnd->getOwnDC();
     862      if (hps)
     863      {
     864         pDCData pHps = (pDCData)GpiQueryDCData (hps);
     865         if (!pHps)
     866            goto error;
     867
     868         if (flags & DCX_WINDOW_W)
     869            removeClientArea (pHps);
     870         else
     871            selectClientArea (wnd, pHps, 0);
     872
     873         setPageXForm (wnd, pHps);
     874
     875         pHps->hdcType = TYPE_1;
     876         SetFS(sel);
     877         return (HDC)hps;
     878      }
     879      else
     880         creatingOwnDC = TRUE;
     881   }
     882
     883   if (isWindowOwnDC)
     884   {
     885      SIZEL sizel = {0,0};
     886      hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
     887                         WinOpenWindowDC (hWindow),
     888                         &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
     889      psType = MICRO;
     890   }
     891   else
     892   {
     893      if (hWindow == HWND_DESKTOP)
     894         hps = WinGetScreenPS (hWindow);
     895      else
     896         hps = WinGetPS (hWindow);
     897
     898      psType = MICRO_CACHED;
     899   }
     900
     901   if (!hps)
     902      goto error;
     903
     904   HPSToHDC (hWindow, hps, NULL, NULL);
     905   pHps = (pDCData)GpiQueryDCData (hps);
     906
     907   if (!(flags & DCX_WINDOW_W)) {
     908      if (selectClientArea (wnd, pHps, 0))
     909         setMapMode (wnd, pHps, MM_TEXT_W);
     910   }
     911
     912   if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
     913   {
     914      ULONG BytesNeeded;
     915      PRGNDATA_W RgnData;
     916      PRECTL pr;
     917      int i;
     918
     919      if (!hrgn)
     920         goto error;
     921
     922      BytesNeeded = _O32_GetRegionData (hrgn, 0, NULL);
     923      RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
     924      if (RgnData == NULL)
     925          goto error;
     926      _O32_GetRegionData (hrgn, BytesNeeded, RgnData);
     927
     928      i = RgnData->rdh.nCount;
     929      pr = (PRECTL)(RgnData->Buffer);
     930
     931      success = TRUE;
     932      if (flags & DCX_EXCLUDERGN_W)
     933         for (; (i > 0) && success; i--, pr++)
     934            success &= GpiExcludeClipRectangle (pHps->hps, pr);
     935      else
     936         for (; (i > 0) && success; i--, pr++)
     937            success &= GpiIntersectClipRectangle (pHps->hps, pr);
     938      if (!success)
     939         goto error;
     940   }
     941
     942   if (creatingOwnDC)
     943      wnd->setOwnDC ((HDC)hps);
     944
     945   pHps->psType  = psType;
     946   pHps->hdcType = TYPE_1;
     947   GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
     948
     949   SetFS(sel);
     950   return (HDC)pHps->hps;
     951
     952error:
     953   /* Something went wrong; clean up
     954    */
     955   if (pHps)
     956   {
     957      if (pHps->hps)
     958      {
     959         if(pHps->psType == MICRO_CACHED)
     960            WinReleasePS(pHps->hps);
     961         else
     962            GpiDestroyPS(pHps->hps);
     963      }
     964
     965      if (pHps->hdc)     DevCloseDC(pHps->hdc);
     966      if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
     967
     968      _O32_DeleteObject (pHps->nullBitmapHandle);
     969   }
     970//   SET_ERROR_LAST();
     971   SetFS(sel);
     972   return NULL;
     973}
     974
     975HDC WIN32API GetDC (HWND hwnd)
     976{
     977  return GetDCEx (hwnd, NULL, 0);
     978}
     979
     980
    802981//******************************************************************************
    803982//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.