## Presentation Device Driver Reference for OS/2

[prev][next][parent][TOC]

### GreEscape DEVESC_SETJOBPROPERTIES - Remarks

DEVESC_SETJOBPROPERTIES is used to set information in the printer's job properties structure. This structure is known only to the printer presentation driver and this escape is the only way for an application to set values inside the structure.

Since DEVESC_SETJOBPROPERTIES is new, applications will call GreEscape DEVESC_QUERYESCSUPPORT to determine if you support this DevEscape.

The DevEscape path has a handle to a device context (HDC) that should already have printer property information associated with the HDC. Job property information may change or may be dependent upon the printer property information in the HDC. In that case, if an application passes job properties for a different device or for a different spooler printer name, then misleading information will be returned.

You should test the input job properties to make sure that they are valid. This includes passing tests such as whether they contain your driver's signature string, whether the device name is yours, and whether the values are within proper ranges (only landscape or portrait). If these tests fail, then fail the call.

    LONG ENGENTRY Escape (HDC       hdc,
                          LONG      lEscape,
                          LONG      cInCount,
                          PBYTE     pInData,
                          PLONG     pcOutCount,
                          PBYTE     pOutData,
                          PDDC      pddc,
                          ULONG     ulFunction)
    {
       switch (lEscape)
       {
       case DEVESC_SETJOBPROPERTIES:
       {
          INT            cbQueries   = cInCount;
          PBYTE          pbQueries   = pInData;
          PDJP_ITEM      pISet       = (PDJP_ITEM)pbQueries;
          BOOL           fError      = FALSE;
          ULONG          ulMaxSize;

          if (GRE_234 > globals.ulGreVersion)
          {
             assertstring ("Not supported on pre-DAX engine!\n");
             lrc = DEVESC_NOTIMPLEMENTED;
             break;
          }

          pGoodDrivData = ReturnDriverData (pddc->pdb,
                                            pdi,
                                            pddc->pdb->hmcbHeap,
                                            pDrivData,
                                            pddc->pdb->pszPrinterName,
                                            TRUE,
                                            pDevice,
                                            pDriver);
          assertF (pGoodDrivData);

          /* Is the size of the input driver data is not the same as
          ** the size of our good data?
          */
          if (pDrivData->cb != pGoodDrivData->cb)
             lrc = DEV_PROP_BUF_TOO_SMALL;

          /* Or, if the two don't compare, then fail the call.
          */
          if (0 != memcmp (pDrivData, pGoodDrivData, pGoodDrivData->cb))
             lrc = DEV_INV_INP_JOBPROPERTIES;

          // Update the job properties with the input set list
          do
          {
             DBPRINTF (("Set '%s'/%d.  Query type '%s'/%d. Simple value = %d\n",
                        pszProperty (pISet->ulProperty),
                        pISet->ulProperty,
                        pszType (pISet->lType),
                        pISet->lType,
                        pISet->ulValue));

             switch (pISet->ulProperty)
             {
             case DJP_SJ_ORIENTATION:
             {
                if (pISet->ulValue == DJP_ORI_PORTRAIT)
                {
                   pJobProp->ulOrientation = ORIENTATION_PORTRAIT;
                }
                else if (pISet->ulValue == DJP_ORI_LANDSCAPE)
                {
                   pJobProp->ulOrientation = ORIENTATION_LANDSCAPE;
                }
                else
                {
                   pISet->lType = DJP_ERROR_OUT_OF_RANGE;
                }
                break;
             }

             case DJP_CJ_RESOLUTION:
             {
                PDJPT_RESOLUTION   pRes         = DJP_ELEMENTP (*pISet, DJPT_RESOLUTION);
                PRESINFO           pResInfo     = pDriver->pRES;
                ULONG              ulNumDefined = pDriver->ulNumRes;
                PULONG             pulResDevice = pDevice->pulRES;
                ULONG              ulNumDevice    =   pDevice - > usNumRes ;
                  BOOL                  fFound         =   FALSE ;
                  register   INT         i ,   j ;

                  for   ( i   =   0 ;   ! fFound   & &   i   <   ulNumDevice ;   i + + ,   pulResDevice + + )
                  {
                     for   ( j   =   0 ;   j   <   ulNumDefined ;   j + + )
                     {
                        if   ( pResInfo [ j ] . ulResID   = =   * pulResDevice )
                        {
                            if   ( pRes - > usXResolution   = =   pResInfo [ j ] . ulXRes   & &
                                pRes - > usYResolution   = =   pResInfo [ j ] . ulYRes    )
                            {
                               fFound   =   TRUE ;
                               pJobProp - > ulDefResID   =   * pulResDevice ;
                               break ;
                            }
                        }
                     }
                  }

                  if   ( ! fFound )
                     pISet - > lType   =   DJP _ ERROR _ OUT _ OF _ RANGE ;
                  break ;
              }

              case   DJP _ SJ _ BITSPERPEL :
              case   DJP _ SJ _ COLOR :
              {
                  PPRINTMODE         pPrintMode      =   pDriver - > pPrintModes ;
                  ULONG               ulNumDefined    =   pDriver - > ulNumPrintModes ;
                  PULONG              pulPrintModes   =   pDevice - > pulPrintModes ;
                  ULONG               ulNumDevice     =   pDevice - > usNumPrintModes ;
                  PDJPT _ BITSPERPEL   pTmp            =   DJP _ ELEMENTP   ( * pISet ,   DJPT _ BITSPERPEL ) ;
                  BOOL                fFound          =   FALSE ;
                  register   INT       i ,   j ;

                  for   ( i   =   0 ;   ! fFound   & &   i   <   ulNumDevice ;   i + + ,   pulPrintModes + + )
                  {
                     fFound   =   FALSE ;

                     for   ( j   =   0 ;   j   <   ulNumDefined ;   j + + )
                     {
                        if   ( pPrintMode [ j ] . ulPrintModeID   = =   * pulPrintModes )
                        {
                            if   ( DJP _ SJ _ BITSPERPEL   = =   pISet - > ulProperty )
                            {
                               if   ( * pTmp   = =   pPrintMode [ j ] . usLogBitCount )
                               {
                                  pJobProp - > ulDefPrintModeID   =   * pulPrintModes ;
                                  fFound   =   TRUE ;
                                  break ;
                               }
                            }
                            else
                            {
                               if   ( ( ( 1       = =   pPrintMode [ j ] . usBitsPerPel )   & &
                                    ( * pTmp   = =   DJP _ CLR _ MONOCHROME )            )   | |
                                   ( ( 1       <    pPrintMode [ j ] . usBitsPerPel )   & &
                                    ( * pTmp   = =   DJP _ CLR _ COLOR )                  )    )
                               {
                                  pJobProp - > ulDefPrintModeID   =   * pulPrintModes ;
                                  fFound   =   TRUE ;
                                  break ;
                               }
                            }
                        }
                     }
                  }

                  if   ( ! fFound )
                     pISet - > lType   =   DJP _ ERROR _ OUT _ OF _ RANGE ;
                  break ;
              }

              case   DJP _ SJ _ PAPERSIZE :
              {
                  ULONG              ulNumDefined   =   pDevice - > ulNumForms ;
                  PFORMINFO2        pFormInfo      =   pDevice - > pFORMS ;
                  PDJPT _ PAPERSIZE   pSize          =   DJP _ ELEMENTP   ( * pISet ,   DJPT _ PAPERSIZE ) ;
                  BOOL               fFound         =   FALSE ;
                  LONG               lRet ;
                  register   INT   i ;

                  for   ( i   =   0 ;   i   <   ulNumDefined ;   i + + )
                  {
                     lRet   =   pFormInfo [ i ] . ulDJPid ;

                     if   ( DJP _ PSI _ NONE   ! =   lRet   & &   * pSize   = =   lRet )
                     {
                        fFound   =   TRUE ;
                        break ;
                     }
                  }

                  if   ( fFound )
                  {
                     ULONG    ulDefaultConnID    =   pJobProp - > ulDefConnID ,
                             ulDefaultFormID    =   0 ,
                             ulDefaultTrayID    =   0 ,
                             ulDefaultMediaID   =   0 ;
                     BOOL     bOK ;

                     / /   Ask   for   the   current   connection   id
                     bOK   =   GetIDsFromConnID   ( pDriver ,
                                               pDevice ,
                                               ulDefaultConnID ,
                                               & ulDefaultTrayID ,
                                               & ulDefaultFormID ,
                                               & ulDefaultMediaID ) ;

                     if   ( bOK )
                        / /   Get   a   new   connection   id
                        bOK   =   NewConnection   ( pdb ,
                                               pGoodDrivData - > szDeviceName ,
                                               & ulDefaultConnID ,
                                               pFormInfo [ i ] . ulFormID ,   / /   Override   form
                                               ulDefaultTrayID ,
                                               ulDefaultMediaID ,
                                               FALSE ) ;                   / /   Dont   create   a   new   one !

                     / /   Set   it !
                     if   ( bOK )
                        pJobProp - > ulDefConnID   =   ulDefaultConnID ;
                     else
                        pISet - > lType   =   DJP _ ERROR _ OUT _ OF _ RANGE ;
                  }
                  else
                  {
                     pISet - > lType   =   DJP _ ERROR _ OUT _ OF _ RANGE ;
                  }
                  break ;
              }

              case   DJP _ CJ _ FORM :
              {
                  ULONG              ulNumDefined ;
                  ULONG              ulNumDevice ;
                  PDJPT _ FORM        pDJPForm       =   DJP _ ELEMENTP   ( * pISet ,   DJPT _ FORM ) ;
                  PFORMINFO2        pFormInfo      =   ( PFORMINFO2 ) NULL ;
                  PTRAYINFO         pTrayInfo      =   ( PTRAYINFO ) NULL ;
                  PMEDIAINFO        pMediaInfo     =   ( PMEDIAINFO ) NULL ;
                  CHAR               szTempName [ 32 ] ;
                  BOOL               bOK ;
                  register   INT      i ,   j ;

                  ulNumDevice   =   pDevice - > ulNumForms ;
                  for   ( i   =   0 ;   i   <   ulNumDevice ;   i + + )
                  {
                     FormNameFromID   ( pDriver ,
                                       pDevice ,
                                       szTempName ,
                                       pDevice - > pFORMS [ i ] . ulFormID ) ;

                     if   ( 0   = =   strcmp   ( pDJPForm - > szFormname ,   szTempName ) )
                     {
                        pFormInfo   =   ( PFORMINFO2 )   & pDevice - > pFORMS [ i ] ;
                        break ;
                     }
                  }

                  if   ( pDJPForm - > szTrayname [ 0 ] )
                  {
                     ulNumDevice    =   pDevice - > usNumTrays ;
                     ulNumDefined   =   pDriver - > ulNumTrays ;

                     for   ( i   =   0 ;   i   <   ulNumDefined   & &   ! pTrayInfo ;   i + + )
                     {
                        for   ( j   =   0 ;   j   <   ulNumDevice ;   j + + )
                        {
                            if   ( pDriver - > pTRAYS [ i ] . ulTrayID   = =   pDevice - > pulTRAYS [ j ] )
                            {
                               TrayNameFromID   ( pDriver ,
                                                pDevice ,
                                                szTempName ,
                                                pDriver - > pTRAYS [ i ] . ulTrayID ) ;

                               if   ( 0   = =   strcmp   ( pDJPForm - > szTrayname ,   szTempName ) )
                               {
                                  pTrayInfo   =   ( PTRAYINFO )   & pDriver - > pTRAYS [ i ] ;
                                  break ;
                               }
                            }
                        }
                     }
                  }

                  if   ( pDJPForm - > szMedianame [ 0 ] )
                  {
                     ulNumDevice    =   pDevice - > ulNumMedias ;
                     ulNumDefined   =   pDriver - > ulNumMedias ;

                     for   ( i   =   0 ;   i   <   ulNumDefined   & &   ! pMediaInfo ;   i + + )
                     {
                        for   ( j   =   0 ;   j   <   ulNumDevice ;   j + + )
                        {
                            if   ( pDriver - > pMEDIAS [ i ] . ulMediaID   = =   pDevice - > pulMEDIAS [ j ] )
                            {
                               MediaNameFromID   ( pDriver ,
                                                  pDevice ,
                                                  szTempName ,
                                                  pDriver - > pMEDIAS [ i ] . ulMediaID ) ;

                               if   ( 0   = =   strcmp   ( pDJPForm - > szMedianame ,   pszTempName ) )
                               {
                                  pMediaInfo   =   ( PMEDIAINFO )   & pDriver - > pMEDIAS [ i ] ;
                                  break ;
                               }
                            }
                        }
                     }
                  }

                  if   ( pFormInfo )
                  {
                     ULONG    ulDefaultConnID    =   pJobProp - > ulDefConnID ,
                             ulDefaultFormID    =   0 ,
                             ulDefaultTrayID    =   0 ,
                             ulDefaultMediaID   =   0 ;

                     / /   Ask   for   the   current   connection   id
                     bOK   =   GetIDsFromConnID   ( pDriver ,
                                               pDevice ,
                                               ulDefaultConnID ,
                                               & ulDefaultTrayID ,
                                               & ulDefaultFormID ,
                                               & ulDefaultMediaID ) ;

                     ulDefaultFormID   =   pFormInfo - > ulFormID ;
                     if   ( pTrayInfo )
                        ulDefaultTrayID   =   pTrayInfo - > ulTrayID ;
                     if   ( pMediaInfo )
                        ulDefaultMediaID   =   pMediaInfo - > ulMediaID ;

                     bOK   =   NewConnection   ( pdb ,
                                            pGoodDrivData - > szDeviceName ,
                                            & ulDefaultConnID ,
                                            ulDefaultFormID ,
                                            ulDefaultTrayID ,
                                            ulDefaultMediaID ,
                                            FALSE ) ;              / /   Dont   create   a   new   one !
                  }
                  else
                     bOK   =   FALSE ;

                  if   ( bOK )
                     pJobProp - > ulDefConnID   =   ulDefaultConnID ;
                  else
                     pISet - > lType   =   DJP _ ERROR _ OUT _ OF _ RANGE ;
                  break ;
              }

              case   DJP _ SJ _ COPIES :
              {
                  if   ( 0   <   pISet - > ulValue   & &   pISet - > ulValue   <   100 )
                     pJobProp - > ulCopies   =   pISet - > ulValue ;
                  else
                     pISet - > lType   =   DJP _ ERROR _ OUT _ OF _ RANGE ;
                  break ;
              }

              case   DJP _ SJ _ PRINTQUALITY :
              case   DJP _ SJ _ TRAYTYPE :
              case   DJP _ SJ _ MEDIA :
              case   DJP _ SJ _ MEDIA _ COLOR :
              case   DJP _ CJ _ MIXEDFORMS :
              case   DJP _ SJ _ FONTDOWNLOADING :
              case   DJP _ SJ _ DUPLEX :
              case   DJP _ SJ _ COLLATE :
              case   DJP _ SJ _ FEED :
              case   DJP _ SJ _ SCALING :
              case   DJP _ SJ _ FORMFEEDCONTROL :
              case   DJP _ SJ _ N _ UP :
              default :
                  pISet - > lType   =   DJP _ ERROR _ NOT _ SUPPORTED ;
                  DBPRINTF   ( ( " Unknow   set   ' % s '   =   % d ! \ n " ,
                               pszProperty   ( pISet - > ulProperty ) ,
                               pISet - > ulProperty ) ) ;
                  break ;
              }

              / /   Move   to   the   set   item
              pISet   =   DJP _ NEXT _ STRUCTP   ( pISet ) ;

           }   while   ( pISet - > ulProperty   ! =   DJP _ NONE ) ;

           cbDrivData   =   cbParm2 ;
           pDrivData    =   ( PDRIVDATA ) pbParm2 ;

           / *   Copy   the   updated   job   properties   onto   the   user ' s   job   properties
           * /
           ulMaxSize   =   min   ( pGoodDrivData - > cb ,   cbDrivData ) ;
           memcpy   ( pDrivData ,   pGoodDrivData ,   ulMaxSize ) ;
           pDrivData - > cb   =   ulMaxSize ;

           if   ( fError )
           {
              GplErrSetWarning   ( PMERR _ DATATYPE _ ENTRY _ INVALID ) ;
              ulrc   =   DEV _ ERROR ;
           }
           else
           {
              ulrc   =   DEV _ OK ;
           }
           break ;
        }
        }

        return   lrc ;
    }