home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v2.zip / DDKX86 / DBCSDD / SRC_DBCS / VDHWNDW / VIOCSUBS.C < prev    next >
C/C++ Source or Header  |  1995-04-14  |  29KB  |  1,058 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT (C) Microsoft Corporation, 1989                                 */
  4. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  5. /*                                                                           */
  6. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  7. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  8. /*    drivers. You may use this code in accordance with the IBM License      */
  9. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  10. /*    Copyright statement may not be removed.                                */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13.  
  14. /****************************************************************************
  15.  *
  16.  * SOURCE FILE NAME = VIOCSUBS.C
  17.  *
  18.  * DESCRIPTIVE NAME = Avio 'c' subroutines
  19.  *
  20.  *
  21.  * VERSION      V2.0
  22.  *
  23.  * DATE
  24.  *
  25.  * DESCRIPTION
  26.  *
  27.  * FUNCTIONS
  28.  *
  29.  * NOTES        NONE
  30.  *
  31.  * STRUCTURES   NONE
  32.  *
  33.  * EXTERNAL REFERENCES
  34.  *
  35.  *              NONE
  36.  *
  37.  * EXTERNAL FUNCTIONS
  38.  *
  39. */
  40. /*
  41. ** Include Statements for all external files.
  42. */
  43.  
  44. #define INCL_DOS
  45. #define INCL_SUB
  46. #define INCL_ERRORS
  47. #define INCL_WINWINDOWMGR
  48. #define INCL_WINMESSAGEMGR
  49. #define INCL_WINSYS
  50. #define INCL_GPIREGIONS
  51. #define INCL_GPIBITMAPS
  52. #define INCL_DEV
  53. #define INCL_OS2STD             /* Needed for NULL definition in OS2STD.H */
  54. #include <OS2.H>
  55.  
  56. #define INCL_WINP
  57. #define INCL_AVIOP
  58. //#include <OS2P.H>
  59.  
  60. #include <pmwinx.h>
  61. #include <PMAVIOP.H>
  62.  
  63. #define INCL_DDIMISC
  64. #define INCL_DDIGRE
  65. #define INCL_GREALL
  66. #include <PMDDI.H>
  67.  
  68. #include <VIOT.H>
  69.  
  70. /***************************************************************************
  71.  *
  72.  * FUNCTION NAME = CopyDc
  73.  *
  74.  * DESCRIPTION   = Copy Dc - copy the loaded data from one Dc
  75.  *                 to another. N.B Assumes a valid Dc handles
  76.  *                 passed - no error checking.
  77.  *
  78.  * INPUT         = NONE
  79.  * OUTPUT        = NONE
  80.  *
  81.  * RETURN-NORMAL = NONE
  82.  * RETURN-ERROR  = NONE
  83.  *
  84.  **************************************************************************/
  85.  
  86. BOOL pascal near CopyDc( SrcDcH, TrgDcH )
  87.  
  88.     HDC SrcDcH;
  89.     HDC TrgDcH;
  90. {
  91.  
  92.     ULONG CodePage;
  93.  
  94.     /*
  95.     **  Copy the Loaded LCIDs and code page
  96.     */
  97.  
  98.  
  99.     CodePage = GreGetCodePage(SrcDcH);
  100.  
  101.     if( GreSetCodePage(TrgDcH, CodePage) == GPI_ERROR )
  102.         return(RcErr);
  103.  
  104.     if( GreCopyDCLoadData(TrgDcH, 2, SrcDcH) == GPI_ERROR )
  105.         return(RcErr);
  106.     else
  107.         return(RcOk);
  108. }
  109.  
  110. /***************************************************************************
  111.  *
  112.  * FUNCTION NAME = AvioCreatePS
  113.  *
  114.  * DESCRIPTION   = Create Ps - internal routine
  115.  *                 Create an Avio ps.
  116.  *
  117.  * INPUT         = NONE
  118.  * OUTPUT        = NONE
  119.  *
  120.  * RETURN-NORMAL = NONE
  121.  * RETURN-ERROR  = NONE
  122.  *
  123.  **************************************************************************/
  124.  
  125. extern USHORT pascal near AvioCreatePS( lpPS , VioH)
  126.  
  127.      VioPresentationSpace FAR * lpPS;
  128.      USHORT VioH;
  129.  
  130. {
  131.     HDC   NewIcH;
  132.     char *IcBlock[2];
  133.  
  134.     /*
  135.     **  Create an Ic and associate it with the Vio.
  136.     */
  137.  
  138.  
  139.     IcBlock[ADDRESS] = 0L;
  140.     IcBlock[DRIVER_NAME] = "DISPLAY";
  141.     NewIcH = DevOpenDC( 0L, OD_INFO, (char far *) "*",
  142.                                         2L, IcBlock, 0L);
  143.     if (NewIcH != 0)
  144.     {
  145.  
  146.  
  147.         /*
  148.         **  Set the Vio handle into the new Ic, the Ic handle into
  149.         **  the Vio, turn off the associated bit.
  150.         */
  151.  
  152.  
  153.         if( GreSetHandle(NewIcH, (ULONG)VioH, AVIO_PS_HANDLE_INDEX)
  154.                       == GPI_ERROR )
  155.             return(ERROR_VIO_SEE_ERROR_LOG);
  156.  
  157.         lpPS -> hConsoleDisplayContext = NewIcH;
  158.         lpPS -> rgfAVio &= !fAssociated;  /* not associated       */
  159.  
  160.         return(RcOk);
  161.     }
  162.  
  163.  
  164.     /*
  165.     **  Creating the Ic failed - return error code so memory may be
  166.     **  freed.
  167.     */
  168.  
  169.  
  170.     else
  171.         return(ERROR_VIO_SEE_ERROR_LOG);
  172. }
  173.  
  174. /***************************************************************************
  175.  *
  176.  * FUNCTION NAME = SetTextGrays(Environment)
  177.  *
  178.  * DESCRIPTION   =
  179.  *
  180.  *    This routine adjusts the following fields in an AVio presentation
  181.  *    space:
  182.  *
  183.  *        WindowHeight
  184.  *        WindowWidth
  185.  *        WindowOriginRow
  186.  *        PartialCellAdjust
  187.  *
  188.  * The adjustments are necessary to maintain the illusion of having
  189.  * the AVio origin at the top left corner of the LVB and the client
  190.  * window.  In fact the origin coordinates are relative to the
  191.  * bottom left corners of the LVB and the client window.  The
  192.  * PartialCellAdjust field holds a small pel offset used when the
  193.  * client window's height is not an exact multiple of the current
  194.  * cell height.
  195.  *
  196.  * INPUT         = NONE
  197.  * OUTPUT        = NONE
  198.  *
  199.  * RETURN-NORMAL = NONE
  200.  * RETURN-ERROR  = NONE
  201.  *
  202.  **************************************************************************/
  203.  
  204. BOOL PASCAL NEAR AdjustWindowOriginAndShape(lpPS)
  205.  
  206. VioPresentationSpace FAR * lpPS;
  207.  
  208. {
  209.  
  210.     /*
  211.     **  Local variables
  212.     */
  213.  
  214.     HDC    hdc;
  215.     HWND   hwnd;
  216.     USHORT TLOrg, usCellHeight, usCellWidth, usYPels, usXPels;
  217.     RECTL  rcClient;
  218.  
  219.     if(!(hwnd = WinWindowFromDC(lpPS->hConsoleDisplayContext)))
  220.         return(TRUE);                                          /*@P2C*/
  221.  
  222.     if (!WinQueryWindowRect(hwnd, &rcClient)) return(FALSE);
  223.  
  224.     usCellHeight = lpPS -> CellImageHeight;
  225.     usCellWidth  = lpPS -> CellImageWidth;
  226.  
  227.     TLOrg = ( (lpPS -> WindowHeight == 0) &&
  228.               (lpPS -> WindowOriginRow == 0) )
  229.                 ? 0
  230.                 : (lpPS -> BufferRowCount -
  231.                    lpPS -> WindowHeight   -
  232.                    lpPS -> WindowOriginRow);
  233.  
  234.     usYPels = (USHORT) (rcClient.yTop   - rcClient.yBottom);
  235.     usXPels = (USHORT) (rcClient.xRight - rcClient.xLeft);
  236.  
  237.     lpPS -> WindowHeight = (usYPels + usCellHeight - 1)
  238.                            / usCellHeight;
  239.     lpPS -> WindowWidth  = (usXPels + usCellWidth - 1)
  240.                            / usCellWidth;
  241.     lpPS -> PartialCellAdjust =
  242.         (BYTE) (usYPels - lpPS->WindowHeight * usCellHeight);
  243.  
  244.     lpPS -> WindowOriginRow = lpPS -> BufferRowCount -
  245.                               lpPS -> WindowHeight - TLOrg;
  246.     return(TRUE);
  247. }
  248.  
  249. /***************************************************************************
  250.  *
  251.  * FUNCTION NAME = AvioAssociate
  252.  *
  253.  * DESCRIPTION   = Associate a Vio with a Dc.
  254.  *
  255.  * INPUT         = NONE
  256.  * OUTPUT        = NONE
  257.  *
  258.  * RETURN-NORMAL = NONE
  259.  * RETURN-ERROR  = NONE
  260.  *
  261.  **************************************************************************/
  262.  
  263. extern USHORT pascal near AvioAssociate( lpPS, VioH, InDcH )
  264.  
  265.      VioPresentationSpace FAR * lpPS;
  266.      USHORT VioH;
  267.      HDC    InDcH;
  268.  
  269. {
  270.  
  271.     /*
  272.     **  Local Variables
  273.     */
  274.  
  275.  
  276.     char   *IcBlock[2];
  277.     USHORT  AssVioH;
  278.     HDC     NewIcH;
  279.  
  280.     /*
  281.     **  Request was to dissociate
  282.     */
  283.  
  284.  
  285.     if (InDcH == 0)
  286.     {
  287.  
  288.        /*
  289.        **  Request was to dissociate and we are currently associated
  290.        */
  291.  
  292.  
  293.        if ((lpPS -> rgfAVio) & fAssociated)  /* associated        */
  294.        {
  295.  
  296.  
  297.            /*
  298.            **  Create an Ic, copy relevant data out of the Dc and
  299.            **  remove the Vio handle from the Dc.
  300.            */
  301.  
  302.  
  303.            IcBlock[ADDRESS] = 0L;
  304.            IcBlock[DRIVER_NAME] = "DISPLAY";
  305.            NewIcH = DevOpenDC( 0L, OD_INFO, (char far *) "*",
  306.                                        2L, IcBlock, 0L);
  307.            if (NewIcH != 0)
  308.            {
  309.  
  310.                /*
  311.                **  Set the Vio handle into the new Ic before CopyDC
  312.                **  so that any loaded fonts can be copied
  313.                */
  314.  
  315.  
  316.                if( GreSetHandle(NewIcH,
  317.                                 (ULONG)VioH,
  318.                                 AVIO_PS_HANDLE_INDEX) == GPI_ERROR )
  319.                    return(ERROR_VIO_SEE_ERROR_LOG);
  320.  
  321.                if( CopyDc(lpPS -> hConsoleDisplayContext, NewIcH) == RcErr )
  322.                {
  323.                    GreCloseDC(NewIcH); /* release just created IC    */
  324.                    return(ERROR_VIO_SEE_ERROR_LOG);
  325.                }
  326.  
  327.                if( GreSetHandle(lpPS -> hConsoleDisplayContext,
  328.                                 (ULONG)NullVioHandle,
  329.                                 AVIO_PS_HANDLE_INDEX) == GPI_ERROR )
  330.                    return(ERROR_VIO_SEE_ERROR_LOG);
  331.  
  332.  
  333.                /*
  334.                **  Set                                 the Ic handle
  335.                **  into the Vio, turn off the associated bit.
  336.                */
  337.  
  338.  
  339.                lpPS -> hConsoleDisplayContext = NewIcH;
  340.                lpPS -> rgfAVio &= !fAssociated; /* not associated */
  341.                return(RcOk);
  342.            }
  343.  
  344.            else
  345.  
  346.            /*
  347.            **  Creating the Ic failed - so get out
  348.            */
  349.            {
  350.                return(ERROR_VIO_SEE_ERROR_LOG);
  351.            }
  352.        }
  353.  
  354.  
  355.        /*
  356.        **  Request was to dissociate and we are not currently
  357.        **  associated
  358.        */
  359.  
  360.  
  361.        else
  362.        {
  363.            return(RcOk);
  364.        }
  365.     }
  366.  
  367.     /*
  368.     **  Request was to perform an association
  369.     */
  370.  
  371.  
  372.     else
  373.     {
  374.  
  375.  
  376.        /*
  377.        **  Ensure that neither the Dc nor the Vio is currently
  378.        **  associated
  379.        */
  380.  
  381.  
  382.        if ((lpPS -> rgfAVio) & fAssociated)  /* associated        */
  383.        {
  384.            return(ERROR_VIO_ASSOCIATED_DC);
  385.        }
  386.  
  387.        else
  388.        {
  389.            AssVioH = (USHORT) GreGetHandle(InDcH, AVIO_PS_HANDLE_INDEX);
  390.  
  391.  
  392.            /*
  393.            **  Error return from the read handle call - error has
  394.            **  been logged so just get out
  395.            */
  396.  
  397.  
  398.            if (AssVioH == VioHandleError)
  399.            {
  400.                return(ERROR_VIO_SEE_ERROR_LOG);
  401.            }
  402.  
  403.            else if (AssVioH != NullVioHandle)
  404.            {
  405.                return(ERROR_VIO_ASSOCIATED_DC);
  406.            }
  407.  
  408.  
  409.            /*
  410.            **  Neither Vio nor Dc is currently associated so perform
  411.            **  the association.
  412.            */
  413.  
  414.  
  415.            else
  416.            {
  417.  
  418.  
  419.                /*
  420.                **  Set the Vio handle into the Dc     before CopyDC
  421.                **  so that any loaded fonts can be copied
  422.                */
  423.  
  424.  
  425.               if( GreSetHandle(InDcH,
  426.                                (ULONG)VioH,
  427.                                AVIO_PS_HANDLE_INDEX) == GPI_ERROR )
  428.                   return(ERROR_VIO_SEE_ERROR_LOG);
  429.  
  430.  
  431.               /*
  432.               **  Copy the loaded data from the Ic to the Dc, then
  433.               **  throw away the old Ic.
  434.               */
  435.  
  436.  
  437.               if( CopyDc(lpPS -> hConsoleDisplayContext, InDcH) == RcErr )
  438.               {
  439.                   GreSetHandle(InDcH,
  440.                                (ULONG)NullVioHandle,
  441.                                AVIO_PS_HANDLE_INDEX);
  442.                   return(ERROR_VIO_SEE_ERROR_LOG);
  443.               }
  444.  
  445.               if( GreCloseDC(lpPS -> hConsoleDisplayContext) == GPI_ERROR )
  446.                   return(ERROR_VIO_SEE_ERROR_LOG);
  447.  
  448.  
  449.               /*
  450.               **  Set the Dc handle
  451.               **  into the Vio, turn off the associated bit.
  452.               */
  453.  
  454.  
  455.               lpPS -> hConsoleDisplayContext = InDcH;
  456.               lpPS -> rgfAVio |= fAssociated; /* associated       */
  457.  
  458.               /*
  459.               **  Set up the window information in the Vio.
  460.               */
  461.  
  462.  
  463.               NULLCHARRECT();
  464.  
  465.               if (AdjustWindowOriginAndShape(lpPS))
  466.                   return(RcOk);
  467.  
  468.               else
  469.                   return(ERROR_VIO_SEE_ERROR_LOG);
  470.  
  471.            }
  472.        }
  473.    }
  474. }
  475.  
  476. /***************************************************************************
  477.  *
  478.  * FUNCTION NAME = AvioDestroyPS
  479.  *
  480.  * DESCRIPTION   = Vio Destroy Ps (VioDestroyPs)
  481.  *
  482.  * INPUT         = NONE
  483.  * OUTPUT        = NONE
  484.  *
  485.  * RETURN-NORMAL = NONE
  486.  * RETURN-ERROR  = NONE
  487.  *
  488.  **************************************************************************/
  489.  
  490. extern USHORT pascal near AvioDestroyPS( lpPS )
  491.  
  492. VioPresentationSpace FAR * lpPS;
  493.  
  494. {
  495.  
  496.     /*
  497.     **  If the Vio is currently associated - that's an error
  498.     */
  499.  
  500.  
  501.     if ((lpPS -> rgfAVio) & fAssociated)     /* associated        */
  502.     {
  503.         return(ERROR_VIO_ASSOCIATED_DC);
  504.     }
  505.  
  506.     /*
  507.     **  All's well - throw away the Ic.
  508.     */
  509.  
  510.  
  511.     else
  512.     {
  513.         if( GreCloseDC(lpPS -> hConsoleDisplayContext) == GPI_ERROR )
  514.             return(ERROR_VIO_SEE_ERROR_LOG);
  515.  
  516.         else
  517.             return(RcOk);
  518.     }
  519. }
  520.  
  521. /***************************************************************************
  522.  *
  523.  * FUNCTION NAME = AvioSetDeviceCellSize
  524.  *
  525.  * DESCRIPTION   = Vio Set Device Cell Size
  526.  *
  527.  * INPUT         = NONE
  528.  * OUTPUT        = NONE
  529.  *
  530.  * RETURN-NORMAL = NONE
  531.  * RETURN-ERROR  = NONE
  532.  *
  533.  **************************************************************************/
  534.  
  535. extern USHORT pascal near AvioSetDeviceCellSize( lpPS, NewCellWidth,
  536.                                                  NewCellHeight )
  537.  
  538.      VioPresentationSpace FAR * lpPS;
  539.      USHORT NewCellWidth;
  540.      USHORT NewCellHeight;
  541.  
  542. {
  543.  
  544.     /*
  545.     **  Local Variables
  546.     */
  547.  
  548.  
  549.     VIOFONTCELLSIZE Smallest;                                           /*@P1C*/
  550.     GridRectRef GridRect;
  551.     LONG InCnt, OutCnt, InDat, res;                                     /*@P1A*/
  552.  
  553.     /*
  554.     **  Get the smallest device cell size from the device caps
  555.     */
  556.  
  557.  
  558.     if (!DevQueryCaps(lpPS -> hConsoleDisplayContext,
  559.                       CAPS_SMALL_CHAR_WIDTH,
  560.                       2L,
  561.                       (PLONG)&Smallest))
  562.  
  563.          return(ERROR_VIO_SEE_ERROR_LOG);                               /*@P1C*/
  564.  
  565.      /*
  566.      **  Check if the display device supports DEVESC_QUERYVIOCELLSIZE
  567.      */
  568.  
  569.  
  570.     InCnt = 4L;                                                         /*@P1A*/
  571.     InDat = DEVESC_QUERYVIOCELLSIZES;                                   /*@P1A*/
  572.  
  573.     res = DevEscape(lpPS -> hConsoleDisplayContext,
  574.                     DEVESC_QUERYESCSUPPORT,
  575.                     InCnt,
  576.                     (PBYTE)&InDat,
  577.                     &OutCnt,
  578.                     (PBYTE)&OutCnt);                                    /*@P1A*/
  579.  
  580.     if (res == DEVESC_ERROR)
  581.         return(ERROR_VIO_SEE_ERROR_LOG);           /*@P1A*/
  582.  
  583.     if (res == DEVESC_NOTIMPLEMENTED)                                   /*@P1A*/
  584.     {
  585.  
  586.         /*
  587.         **  Check the input values against the device caps. If either
  588.         **  value is less than the corresponding device small cell
  589.         **  size value then use the device small value. The engine
  590.         **  will otherwise use the default value.
  591.         */
  592.  
  593.         if ( (NewCellWidth  < (USHORT)Smallest.cx) ||
  594.              (NewCellHeight < (USHORT)Smallest.cy))
  595.  
  596.         {
  597.             NewCellWidth  = (USHORT)Smallest.cx;                        /*@P1C*/
  598.             NewCellHeight = (USHORT)Smallest.cy;                        /*@P1C*/
  599.         }
  600.     }
  601.  
  602.     else                                                                /*@P1A*/
  603.     {
  604.         LONG NumCellSizes;                                              /*@P1A*/
  605.         USHORT Size, rc, i, Count;                                      /*@P1A*/
  606.         SEL    Selector;                                                /*@P1A*/
  607.  
  608.         typedef struct
  609.            {
  610.             VIOSIZECOUNT NumSizes;
  611.             VIOFONTCELLSIZE CellSizes[1];
  612.             } VIOCELLINFO;                                              /*@P1A*/
  613.  
  614.         VIOCELLINFO FAR *pVioCellInfo;                                  /*@P1A*/
  615.         VIOFONTCELLSIZE SmallWth, Current;                              /*@P1A*/
  616.         BOOL ExactMatch = FALSE;                                        /*@P3A*/
  617.  
  618.         /*
  619.         ** Check how many device cell sizes are supported by the
  620.         ** device so that sufficient storage can be allocated to
  621.         ** receive all the sizes.
  622.         */
  623.  
  624.         InCnt = 0L;                                                     /*@P1A*/
  625.         InDat = 0L;                                                     /*@P1A*/
  626.         OutCnt = sizeof(LONG);                                          /*@P1A*/
  627.  
  628.         res = DevEscape(lpPS -> hConsoleDisplayContext,
  629.                         DEVESC_QUERYVIOCELLSIZES,
  630.                         InCnt,
  631.                         (PBYTE)&InDat,
  632.                         &OutCnt,
  633.                         (PBYTE)&NumCellSizes);                          /*@P1A*/
  634.  
  635.         if (res != DEV_OK)
  636.             return(ERROR_VIO_SEE_ERROR_LOG);             /*@P1A*/
  637.  
  638.         /*
  639.         **  Allocate storage to accommodate cell information
  640.         */
  641.  
  642.  
  643.         Size = (USHORT)(sizeof(VIOSIZECOUNT) +
  644.                         (NumCellSizes * sizeof(VIOFONTCELLSIZE)));      /*@P1A*/
  645.  
  646.         rc = DosAllocSeg(Size,
  647.                          &Selector,
  648.                          0);                                            /*@P1A*/
  649.  
  650.         if (rc != NO_ERROR)
  651.             return(rc);                             /*@P1A,@P5*/
  652.  
  653.         pVioCellInfo = MAKEP(Selector,0);                               /*@P1A*/
  654.         OutCnt = Size;                                                  /*@P1A*/
  655.  
  656.         res = DevEscape(lpPS -> hConsoleDisplayContext,
  657.                         DEVESC_QUERYVIOCELLSIZES,
  658.                         InCnt,
  659.                         (PBYTE)&InDat,
  660.                         &OutCnt,
  661.                         (PBYTE)pVioCellInfo);                           /*@P1A*/
  662.  
  663.         if (res != DEV_OK)
  664.             return(ERROR_VIO_SEE_ERROR_LOG);             /*@P1A*/
  665.  
  666.         /*
  667.         **  Locate smallest cell size by width.
  668.         */
  669.  
  670.  
  671.         SmallWth = (*pVioCellInfo).CellSizes[0];                        /*@P1A*/
  672.         Count = (USHORT)(*pVioCellInfo).NumSizes.count;/*returned number  @P1A*/
  673.  
  674.         for (i=1;i<Count;i++)                                           /*@P1A*/
  675.         {
  676.             Current = (*pVioCellInfo).CellSizes[i];                     /*@P1A*/
  677.             if ( (Current.cx == NewCellWidth) &&                        /*@P3A*/
  678.                  (Current.cy == NewCellHeight))                         /*@P3A*/
  679.             {
  680.                 ExactMatch = TRUE;                                      /*@P3A*/
  681.                 break;                                                  /*@P3A*/
  682.             }
  683.  
  684.             if ( (Current.cx < SmallWth.cx) ||
  685.                 ((Current.cx == SmallWth.cx) && (Current.cy < SmallWth.cy)))
  686.  
  687.             {
  688.                 SmallWth = Current;                                     /*@P1A*/
  689.             }
  690.         }
  691.  
  692.         /*
  693.         **  Check the input values against the smallest width
  694.         **  cell size. If either value is less than the
  695.         **  corresponding smallest width cell size value then use the
  696.         **  device small value. The engine will otherwise use the
  697.         **  default value.
  698.         */
  699.  
  700.         if ( !ExactMatch &&                                             /*@P3C*/
  701.             ((NewCellWidth  < (USHORT)SmallWth.cx) ||                   /*@P3C*/
  702.              (NewCellHeight < (USHORT)SmallWth.cy)))                    /*@P3C*/
  703.         {
  704.             NewCellWidth  = (USHORT)Smallest.cx;                        /*@P1A*/
  705.             NewCellHeight = (USHORT)Smallest.cy;                        /*@P1A*/
  706.         }
  707.  
  708.         /*
  709.         **  Release allocated storage
  710.         */
  711.  
  712.  
  713.         rc = DosFreeSeg(Selector);                                      /*@P1A*/
  714.  
  715.     }
  716.  
  717.     lpPS -> CellImageHeight = NewCellHeight;
  718.     lpPS -> CellImageWidth  = NewCellWidth;
  719.  
  720.     /*
  721.     **  Call engine to set the best fit.
  722.     */
  723.  
  724.  
  725.     GridRect.StartRow    = 0;
  726.     GridRect.StartColumn = 0;
  727.     GridRect.RectWidth   = 0;
  728.     GridRect.RectDepth   = 0;
  729.  
  730.     if( GreCharRect( lpPS -> hConsoleDisplayContext,
  731.                      lpPS,
  732.                      &GridRect ) != RcOk )
  733.         return(ERROR_VIO_SEE_ERROR_LOG);
  734.  
  735.  
  736.     /*
  737.     **  Set up the Vio window fields based on the new device cell
  738.     **  size.
  739.     */
  740.  
  741.  
  742.     if (AdjustWindowOriginAndShape(lpPS))
  743.         return(RcOk);
  744.  
  745.     else
  746.         return(ERROR_VIO_SEE_ERROR_LOG);
  747.  
  748. }
  749.  
  750. /***************************************************************************
  751.  *
  752.  * FUNCTION NAME = AvioSetOrg
  753.  *
  754.  * DESCRIPTION   = Set the origin in the LVB
  755.  *
  756.  * INPUT         = NONE
  757.  * OUTPUT        = NONE
  758.  *
  759.  * RETURN-NORMAL = NONE
  760.  * RETURN-ERROR  = NONE
  761.  *
  762.  **************************************************************************/
  763.  
  764. extern USHORT pascal near AvioSetOrg( lpPS, TLOrgRow, TLOrgCol )
  765.  
  766.      VioPresentationSpace FAR * lpPS;
  767.      USHORT TLOrgRow;
  768.      USHORT TLOrgCol;
  769.  
  770. {
  771.  
  772.     /*
  773.     **  Local Variables
  774.     */
  775.  
  776.  
  777.     HWND        WindowH;
  778.     HDC         hdc;
  779.     HPS         hps;
  780.     RECTL       rectlNew, rectlPrev, rectlTail[2];
  781.     HRGN        hrgnTail, hrgnPrev, hrgnNew;
  782.     RGNRECT     rgnrect;
  783.     GridRectRef GridRect;
  784.     SHORT       sNewOrgRow, sPelAdjustment;
  785.  
  786.     sNewOrgRow = lpPS -> BufferRowCount - lpPS -> WindowHeight - TLOrgRow;
  787.  
  788.     if (   sNewOrgRow == lpPS->WindowOriginRow  &&
  789.            TLOrgCol == lpPS->WindowOriginColumn   )
  790.         return(RcOk);
  791.  
  792.     /*
  793.     **  Invalidate the area that the LVB currently occupies.
  794.     */
  795.  
  796.  
  797.     WindowH = WinWindowFromDC(hdc= lpPS -> hConsoleDisplayContext);
  798.  
  799.     hps = (HPS) (((ULONG) hdc) | 1L);  /* Kludge to get MicroPsHandle */
  800.  
  801.     rectlPrev.xLeft   = (LONG)((SHORT)(-(lpPS -> WindowOriginColumn)) *
  802.                                (SHORT)(lpPS -> CellImageWidth));
  803.  
  804.     rectlPrev.yBottom = (LONG)((SHORT)(-(lpPS -> WindowOriginRow)) *
  805.                                (SHORT)(lpPS -> CellImageHeight));
  806.  
  807.     rectlPrev.xRight  = rectlPrev.xLeft +
  808.                         (LONG)((SHORT)(lpPS -> BufferColumnCount) *
  809.                                (SHORT)(lpPS -> CellImageWidth));
  810.  
  811.     rectlPrev.yTop    = rectlPrev.yBottom +
  812.                         (LONG)((SHORT)(lpPS -> BufferRowCount) *
  813.                                (SHORT)(lpPS -> CellImageHeight));
  814.  
  815.     sPelAdjustment     = (SHORT) (signed char) lpPS -> PartialCellAdjust;
  816.     rectlPrev.yBottom += sPelAdjustment;
  817.  
  818.     if (!WinInvalidateRect(WindowH, (PRECTL)&rectlPrev, FALSE))
  819.         return(ERROR_VIO_SEE_ERROR_LOG);
  820.  
  821.     /*
  822.     **  Set new origin into presentation space and redraw LVB.
  823.     */
  824.  
  825.  
  826.     lpPS -> WindowOriginRow    = sNewOrgRow;
  827.     lpPS -> WindowOriginColumn = TLOrgCol;
  828.     GridRect.StartRow    = 0;
  829.     GridRect.StartColumn = 0;
  830.     GridRect.RectWidth   = lpPS -> BufferColumnCount;
  831.     GridRect.RectDepth   = lpPS -> BufferRowCount;
  832.  
  833.     if( GreCharRect( lpPS -> hConsoleDisplayContext,
  834.                      lpPS,
  835.                      &GridRect ) != RcOk )
  836.         return(ERROR_VIO_SEE_ERROR_LOG);
  837.  
  838.     /*
  839.     **  Validate the area that the LVB now occupies.
  840.     */
  841.  
  842.     hrgnPrev= GpiCreateRegion(hps, 1L, (PRECTL) &rectlPrev);
  843.     hrgnTail= hrgnPrev;
  844.  
  845.     rectlNew.xLeft   = (LONG)((SHORT)(-(lpPS -> WindowOriginColumn)) *
  846.                               (SHORT)(lpPS -> CellImageWidth));
  847.  
  848.     rectlNew.yBottom = (LONG)((SHORT)(-(lpPS -> WindowOriginRow)) *
  849.                               (SHORT)(lpPS -> CellImageHeight));
  850.  
  851.     rectlNew.xRight  = rectlNew.xLeft +
  852.                        (LONG)((SHORT)(lpPS -> BufferColumnCount) *
  853.                               (SHORT)(lpPS -> CellImageWidth));
  854.  
  855.     rectlNew.yTop    = rectlNew.yBottom +
  856.                        (LONG)((SHORT)(lpPS -> BufferRowCount) *
  857.                               (SHORT)(lpPS -> CellImageHeight));
  858.  
  859.     rectlNew.yBottom += sPelAdjustment;
  860.  
  861.     hrgnNew= GpiCreateRegion(hps, 1L, (PRECTL) &rectlNew);
  862.  
  863.     GpiCombineRegion(hps, hrgnTail, hrgnPrev, hrgnNew, CRGN_DIFF);
  864.  
  865.     rgnrect.ircStart    = 0;
  866.     rgnrect.crc         = 2;
  867.     rgnrect.crcReturned = 0;
  868.     rgnrect.usDirection = RECTDIR_LFRT_TOPBOT;
  869.  
  870.     GpiQueryRegionRects(hps, hrgnTail, (PRECTL) NULL,
  871.                         (PRGNRECT) & rgnrect, (PRECTL) rectlTail);
  872.  
  873.     if (rgnrect.crcReturned > 0)
  874.         WinFillRect(hps, (PRECTL) &rectlTail[0], SYSCLR_WINDOW);
  875.  
  876.     if (rgnrect.crcReturned > 1)
  877.         WinFillRect(hps, (PRECTL) &rectlTail[1], SYSCLR_WINDOW);
  878.  
  879.     GreDestroyRegion(hps, hrgnPrev);
  880.     GreDestroyRegion(hps, hrgnNew );
  881.  
  882.     if (!WinValidateRect(WindowH, (PRECTL)&rectlNew, FALSE))
  883.         return(ERROR_VIO_SEE_ERROR_LOG);
  884.  
  885.     /*
  886.     **  Redraw cursor
  887.     */
  888.  
  889.  
  890.     if( GreUpdateCursor( lpPS -> hConsoleDisplayContext,
  891.                          lpPS ) != RcOk )
  892.         return(ERROR_VIO_SEE_ERROR_LOG);
  893.  
  894.     return(RcOk);
  895.  
  896. }
  897.  
  898. /***************************************************************************
  899.  *
  900.  * FUNCTION NAME = AvioDeleteSetId
  901.  *
  902.  * DESCRIPTION   = Vio Delete SetId
  903.  *
  904.  * INPUT         = NONE
  905.  * OUTPUT        = NONE
  906.  *
  907.  * RETURN-NORMAL = NONE
  908.  * RETURN-ERROR  = NONE
  909.  *
  910.  **************************************************************************/
  911.  
  912. extern USHORT pascal near AvioDeleteSetId( lpPS, Lcid )
  913.  
  914.      VioPresentationSpace FAR * lpPS;
  915.      LONG   Lcid;
  916.  
  917. {
  918.  
  919.     if( Lcid == -1L )
  920.     {
  921.  
  922.         LONG  n = 3L;
  923.         LONG  types[3], lcids[3];
  924.         STR8  names[3];
  925.         USHORT i;
  926.  
  927.         if( GreQuerySetIds(lpPS -> hConsoleDisplayContext,
  928.                            n,
  929.                            types,
  930.                            names,
  931.                            lcids,
  932.                            LCID_RANGE_AVIO) == GPI_ERROR )
  933.             return(ERROR_VIO_SEE_ERROR_LOG);
  934.  
  935.         for ( i=0; i<3; i++ )
  936.         {
  937.             if(  ( lcids[i] != 0L )  &&
  938.                  ( GreDeleteSetId(lpPS -> hConsoleDisplayContext,
  939.                                   lcids[i]) == GPI_ERROR ))
  940.                 return(ERROR_VIO_SEE_ERROR_LOG);
  941.         }
  942.  
  943.     }
  944.  
  945.     else
  946.     {
  947.         if( (Lcid < 1) || (Lcid > 3) )
  948.             return(ERROR_VIO_INVALID_PARMS);
  949.  
  950.         if( GreDeleteSetId(lpPS -> hConsoleDisplayContext,
  951.                            -(Lcid + 1)) == GPI_ERROR )
  952.             return(ERROR_VIO_SEE_ERROR_LOG);
  953.     }
  954.  
  955.     return(RcOk);
  956. }
  957.  
  958. /***************************************************************************
  959.  *
  960.  * FUNCTION NAME = AvioQuerySetIds
  961.  *
  962.  * DESCRIPTION   = Vio Query SetIds
  963.  *
  964.  * INPUT         = NONE
  965.  * OUTPUT        = NONE
  966.  *
  967.  * RETURN-NORMAL = NONE
  968.  * RETURN-ERROR  = NONE
  969.  *
  970.  **************************************************************************/
  971.  
  972. extern USHORT pascal near AvioQuerySetIds( lpPS, n, types, names, Lcids)
  973.  
  974.      VioPresentationSpace FAR * lpPS;
  975.      LONG   n;
  976.      PLONG  types, Lcids;
  977.      PSTR8  names;
  978.  
  979. {
  980.  
  981.     /*
  982.     **  Local Variables
  983.     */
  984.  
  985.  
  986.     USHORT i;
  987.  
  988.     if( (n < 1) || (n > 3) )
  989.         return(ERROR_VIO_INVALID_PARMS);
  990.  
  991.     if( GreQuerySetIds(lpPS -> hConsoleDisplayContext,
  992.                        n,
  993.                        types,
  994.                        names,
  995.                        Lcids,
  996.                        LCID_RANGE_AVIO) == GPI_ERROR )
  997.         return(ERROR_VIO_SEE_ERROR_LOG);
  998.  
  999.     for ( i=0; i<(USHORT)n; i++ )
  1000.     {
  1001.         if( Lcids[i] != 0L )
  1002.             (LONG)Lcids[i] = -((LONG)Lcids[i] + 1);
  1003.     }
  1004.  
  1005.     return(RcOk);
  1006. }
  1007.  
  1008. /***************************************************************************
  1009.  *
  1010.  * FUNCTION NAME = AvioQueryFonts
  1011.  *
  1012.  * DESCRIPTION   = Vio Query Fonts
  1013.  *
  1014.  * INPUT         = NONE
  1015.  * OUTPUT        = NONE
  1016.  *
  1017.  * RETURN-NORMAL = NONE
  1018.  * RETURN-ERROR  = NONE
  1019.  *
  1020.  **************************************************************************/
  1021.  
  1022. extern USHORT pascal near AvioQueryFonts( lpPS, options, facename,
  1023.                                           fonts, count, metrics,
  1024.                                           remfonts )
  1025.      VioPresentationSpace FAR * lpPS;
  1026.      ULONG  options;
  1027.      PSZ    facename;
  1028.      PLONG  fonts, remfonts;
  1029.      LONG   count;
  1030.      PFONTMETRICS metrics;
  1031.  
  1032. {
  1033.  
  1034.     /*
  1035.     **  Local Variables
  1036.     */
  1037.  
  1038.  
  1039.     LONG EngVal;
  1040.  
  1041.     EngVal =  GreQueryFonts(lpPS -> hConsoleDisplayContext,
  1042.                             options,
  1043.                             facename,
  1044.                             metrics,
  1045.                             count,
  1046.                             fonts);
  1047.  
  1048.     if( EngVal == -1L )
  1049.         return(ERROR_VIO_SEE_ERROR_LOG);
  1050.  
  1051.     else
  1052.     {
  1053.        *remfonts = EngVal;
  1054.         return( RcOk );
  1055.     }
  1056.  
  1057. }
  1058.