On Wed, 02 Jan 2008, Pritpal Bedi wrote:
> Though first approach decreases the quantum of redefinition of directives,
> but puts a runtime overhead to evaluate one IIF construct. Whereas in 2nd
> approach, you end up writing more directives but you save one PCODE
> evaluation at run-time.

Hi Pritpal,
All expressions like:
    IIF( .T., <exp1>, <exp2> )
or:
    IIF( .F., <exp1>, <exp2> )

Are fully optimized by compiler so only <exp1> (or <exp2> in second
case) are generated and you do not have even single PCODE overhead
at runtime. You can safely use it without worry about it. The same
hapens also for:
    IIF( <exp1>, <exp2>, <exp3> )
when <exp1> can be optimized at compile time, f.e.:
    IIF( 1 == 1, <exp1>, <exp2> )
or:
    IIF( NIL != NIL, <exp1>, <exp2> )
etc.

> My goal was not to rewrite the base code to include <hGT> as the last
> parameter to GT commands. I wanted it to be substituted by a Local/Public
> variable if one is not provided on lines with <GetList>.

IMHO the main problem is that you are changing parameters of standard
Clipper functions. It has important bad side effect:
New code which will use such extended functions will not be portable
to other xBase languages as long as you do not ask their authors to
make the same modification in standard screen functions - in most of
cases you will have very small chance that they agree so IMHO it's
bad design decisions which reduce users code portability to other
xbase projects.
Instead I strongly suggest to add new set of functions which will
accept window handler without touching standard Clipper ones.
I'm attaching scheme of source code for TWINDOW class which
can be used for multi window output.
I also suggest to make the same on C level and keep existing
functions not changed.
In fact for many people only HB_WSELECT() function will be necessary.
In CT3 is also possible to create many virtual windows and only
one function WSELECT() is enough to switch between them. Just ask
people who use CTWIN in their programs, also with BROWSE and GET
classes.

Now using PP you are trying to introduce default window handler when
it's not necessary. It means that you will have two default handlers.
One used when handler is not passed at all - this is the handler set
by HB_WSELECT(). The second one you try to add using PP. IMHO it only
makes things much more complicated.

> Now another question:
> Instead of changing the name of the function in #xtranslate , I can keep
> librray name as is, like:
> #xtranslate DispOutAt(<r>,<c>,<x>,[<l>],<g>) =>
> DispOutAt(<r>,<c>,<x>,[<l>],<g>)
> #xtranslate DispOutAt(<r>,<c>,<x>,[<l>])       =>
> DispOutAt(<r>,<c>,<x>,[<l>],hGT)
> I have tried but then compile keeps on translating forever. If this can be
> achieved in any way, a lot of amount of time will be saved.

single:

    #xtranslate DispOutAt(<r>,<c>,<x>[,<l>]) => ;
                DispOutAt(<r>,<c>,<x>,<l>,hGT)

is all what you need.

best regards,
Przemek
#include "hbclass.ch"

CREATE CLASS TWINDOW

   /* screen size */
   METHOD   SETMODE
   METHOD   MAXROW
   METHOD   MAXCOL

   /* cursor position and shape */
   METHOD   ROW
   METHOD   COL
   METHOD   SETPOS
   METHOD   SETCURSOR

   /* colors */
   METHOD   ISCOLOR
   METHOD   SETCOLOR
   METHOD   COLORSELECT
   METHOD   SETBLINK
   METHOD   NOSNOW
   METHOD   SHADOW
   METHOD   SETATTRIBUTE
   METHOD   COLORTON
   METHOD   NTOCOLOR

   /* screen update */
   METHOD   SAVESCREEN
   METHOD   RESTSCREEN
   METHOD   DISPBEGIN
   METHOD   DISPEND
   METHOD   DISPCOUNT
   METHOD   DISPBOX
   METHOD   DISPOUT
   METHOD   DISPOUTAT
   METHOD   QOUT
   METHOD   QQOUT
   METHOD   SCROLL

   /* keyboard */
   METHOD   INKEY
   METHOD   NEXTKEY
   METHOD   LASTKEY
   METHOD   PUTKEY
   METHOD   KEYBOARD
   METHOD   SETLASTKEY

   /* mouse */
   METHOD   MPRESENT
   METHOD   MHIDE
   METHOD   MSHOW
   METHOD   MROW
   METHOD   MCOL
   METHOD   MSETPOS
   METHOD   MSETCURSOR
   METHOD   MSETBOUNDS
   METHOD   MSAVESTATE
   METHOD   MRESTSTATE
   METHOD   MDBLCK
   METHOD   MLEFTDOWN
   METHOD   MRIGHTDOWN
   METHOD   MMIDDLEDOWN

   /* sound */
   METHOD   TONE
   METHOD   BELL

   /* CP translations */
   METHOD   SETDISPCP
   METHOD   SETKEYCP
   METHOD   SETTERMCP

   /* stdout / stderr */
   METHOD   OUTSTD
   METHOD   OUTERR

   /* misc */
   METHOD   ALERT
   
   /* GFX */
   METHOD   GFXPRIMITIVE
   METHOD   GFXTEXT

   /* GT management */
   METHOD   GTINFO
   METHOD   GTVERSION

ENDCLASS

#pragma begindump
#include "hbset.h"
#include "hbapigt.h"
#include "hbapiitm.h"
#include "hbapierr.h"
#include "hbgtcore.h"

#define M_BUTTON_LEFT   0
#define M_BUTTON_RIGHT  1
#define M_BUTTON_MIDDLE 2

static PHB_GT hb_gt_getBasePtr( PHB_GT * pOldGT )
{
   /* This functions will retrieve GT context from self object,
    * store current GT handler in pOldGT and then will set new GT
    * context as current one locking it until hb_gt_restoreBasePtr()
    * will be called
    */
   *pOldGT = NULL;
   return hb_gt_Base();
}

static void hb_gt_restoreBasePtr( PHB_GT pOldGT )
{
   /* This functions will unlock current GT context and then will restore
    * the previous one
    */
   HB_SYMBOL_UNUSED( pOldGT );
}




static void hb_getScreenRange( PHB_GT pGT, int * piMin, int * piMax,
                               BOOL fNoCheck, BOOL fVertical )
{
   int iFrom, iTo, iMax;

   if( fVertical )
   {
      iMax  = HB_GTSELF_MAXROW( pGT );
      iFrom = hb_parni( 1 );
      iTo   = ISNUM( 3 ) ? hb_parni( 3 ) : iMax;
   }
   else
   {
      iMax = HB_GTSELF_MAXCOL( pGT );
      iFrom = hb_parni( 2 );
      iTo   = ISNUM( 4 ) ? hb_parni( 4 ) : iMax;
   }

   if( iFrom < 0 )
      iFrom = 0;
   else if( iFrom > iMax && !fNoCheck )
      iFrom = iMax;

   if( iTo < 0 )
      iTo = 0;
   else if( iTo > iMax && !fNoCheck )
      iTo = iMax;

   if( iFrom > iTo )
   {
      *piMin = iTo;
      *piMax = iFrom;
   }
   else
   {
      *piMin = iFrom;
      *piMax = iTo;
   }
}

static char * hb_itemStringCon( PHB_ITEM pItem, ULONG * pulLen, BOOL * pfFree )
{
   if( HB_IS_LOGICAL( pItem ) )
   {
      *pulLen = 1;
      *pfFree = FALSE;
      return ( char * ) ( hb_itemGetL( pItem ) ? "T" : "F" );
   }
   return hb_itemString( pItem, pulLen, pfFree );
}

static int hb_colorParam( PHB_GT pGT, int iParam )
{
   char * pszColor = hb_parc( iParam );
   if( pszColor && *pszColor )
      return HB_GTSELF_COLORNUM( pGT, pszColor );
   else if( ISNUM( iParam ) )
      return hb_parni( iParam );
   else
      return 7;
}

static void hb_consoleOut( BOOL fNewLine )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      USHORT uiPCount = hb_pcount();
      USHORT uiParam;

      if( fNewLine )
      {
         const char * szCrLf = hb_conNewLine();
         HB_GTSELF_WRITE( pGT, ( BYTE * ) szCrLf, strlen( szCrLf ) );
      }

      for( uiParam = 1; uiParam <= uiPCount; uiParam++ )
      {
         char * pStr;
         ULONG ulLen;
         BOOL fFree;

         pStr = hb_itemString( hb_param( 1, HB_IT_ANY ), &ulLen, &fFree );
         HB_GTSELF_WRITE( pGT, ( BYTE * ) pStr, ulLen );
         if( fFree )
            hb_xfree( pStr );
         if( uiParam < uiPCount )
            HB_GTSELF_WRITE( pGT, ( BYTE * ) " ", 1 );
      }

      HB_GTSELF_FLUSH( pGT );

      hb_gt_restoreBasePtr( pOldGT );
   }
}

static void hb_stdOutErr( BOOL fStdErr )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      USHORT uiPCount = hb_pcount();
      USHORT uiParam;

      for( uiParam = 1; uiParam <= uiPCount; uiParam++ )
      {
         char * pStr;
         ULONG ulLen;
         BOOL fFree;

         pStr = hb_itemString( hb_param( 1, HB_IT_ANY ), &ulLen, &fFree );
         if( fStdErr )
            HB_GTSELF_OUTSTD( pGT, ( BYTE * ) pStr, ulLen );
         else
            HB_GTSELF_OUTERR( pGT, ( BYTE * ) pStr, ulLen );
         if( fFree )
            hb_xfree( pStr );
         if( uiParam < uiPCount )
         {
            if( fStdErr )
               HB_GTSELF_OUTSTD( pGT, ( BYTE * ) " ", 1 );
            else
               HB_GTSELF_OUTERR( pGT, ( BYTE * ) " ", 1 );
         }
      }
      HB_GTSELF_FLUSH( pGT );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SETMODE )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iRows, iCols;

      HB_GTSELF_GETSIZE( pGT, &iRows, &iCols );

      if( ISNUM( 1 ) )
         iRows = hb_parni( 1 );
      if( ISNUM( 2 ) )
         iCols = hb_parni( 2 );

      hb_retl( HB_GTSELF_SETMODE( pGT, iRows, iCols ) );

      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MAXROW )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if( ISLOG( 1 ) && hb_parl( 1 ) )
      {
         int iHeight, iWidth;

         HB_GTSELF_GETSIZE( pGT, &iHeight, &iWidth );
         hb_retni( iHeight - 1 );
      }
      else
         hb_retni( HB_GTSELF_MAXROW( pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MAXCOL )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if( ISLOG( 1 ) && hb_parl( 1 ) )
      {
         int iHeight, iWidth;

         HB_GTSELF_GETSIZE( pGT, &iHeight, &iWidth );
         hb_retni( iWidth - 1 );
      }
      else
         hb_retni( HB_GTSELF_MAXCOL( pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_ROW )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iRow, iCol;

      HB_GTSELF_GETPOS( pGT, &iRow, &iCol );
      hb_retni( iRow );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_COL )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iRow, iCol;

      HB_GTSELF_GETPOS( pGT, &iRow, &iCol );
      hb_retni( iCol );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SETPOS )
{
   if( ISNUM( 1 ) && ISNUM( 2 ) )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         HB_GTSELF_SETPOS( pGT, hb_parni( 1 ), hb_parni( 2 ) );
         HB_GTSELF_FLUSH( pGT );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_SETCURSOR )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retni( HB_GTSELF_GETCURSORSTYLE( pGT ) );
      if( ISNUM( 1 ) )
      {
         HB_GTSELF_SETCURSORSTYLE( pGT, hb_parni( 1 ) );
         HB_GTSELF_FLUSH( pGT );
      }
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_ISCOLOR )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retl( HB_GTSELF_ISCOLOR( pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SETCOLOR )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      char * pszNewColor = hb_parc( 1 );
      char szOldColor[ CLR_STRLEN ];

      HB_GTSELF_GETCOLORSTR( pGT, szOldColor );
      if( pszNewColor )
         HB_GTSELF_SETCOLORSTR( pGT, pszNewColor );
      hb_retc( szOldColor );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_COLORSELECT )
{
   if( ISNUM( 1 ) )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         HB_GTSELF_COLORSELECT( pGT, hb_parni( 1 ) );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_SETBLINK )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retl( HB_GTSELF_GETBLINK( pGT ) );
      if( ISLOG( 1 ) )
         HB_GTSELF_SETBLINK( pGT, hb_parl( 1 ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_NOSNOW )
{
   if( ISLOG( 1 ) )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         HB_GTSELF_SETSNOWFLAG( pGT, hb_parl( 1 ) );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_SHADOW )
{
   if( hb_pcount() >= 4 )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         HB_GTSELF_DRAWSHADOW( pGT, hb_parni( 1 ), hb_parni( 2 ),
                                    hb_parni( 3 ), hb_parni( 4 ),
                                    hb_colorParam( pGT, 5 ) );
         HB_GTSELF_FLUSH( pGT );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_SETATTRIBUTE )
{
   if( hb_pcount() > 4 )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         HB_GTSELF_SETATTRIBUTE( pGT, hb_parni( 1 ), hb_parni( 2 ),
                                      hb_parni( 3 ), hb_parni( 4 ),
                                      hb_colorParam( pGT, 5 ) );
         HB_GTSELF_FLUSH( pGT );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_COLORTON )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retni( HB_GTSELF_COLORNUM( pGT, hb_parcx( 1 ) ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_NTOCOLOR )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      char szColorString[ 10 ];
      int colors[ 1 ];
      colors[ 0 ] = hb_parni( 1 );
      HB_GTSELF_COLORSTOSTRING( pGT, colors, 1, szColorString, 10 );
      hb_retc( szColorString );

      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SAVESCREEN )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iTop, iLeft, iBottom, iRight;
      ULONG  ulSize;
      BYTE * pBuffer;
      BOOL fNoCheck = ISLOG( 5 ) && hb_parl( 5 );

      hb_getScreenRange( pGT, &iTop, &iBottom, fNoCheck, TRUE );
      hb_getScreenRange( pGT, &iLeft, &iRight, fNoCheck, FALSE );

      ulSize = HB_GTSELF_RECTSIZE( pGT, iTop, iLeft, iBottom, iRight );
      pBuffer = hb_xgrab( ulSize + 1 );
      HB_GTSELF_SAVE( pGT, iTop, iLeft, iBottom, iRight, pBuffer );

      hb_retclen_buffer( ( char * ) pBuffer, ulSize );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_RESTSCREEN )
{
   if( ISCHAR( 5 ) )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         int iTop, iLeft, iBottom, iRight;
         BOOL fNoCheck = ISLOG( 6 ) && hb_parl( 6 );

         hb_getScreenRange( pGT, &iTop, &iBottom, fNoCheck, TRUE );
         hb_getScreenRange( pGT, &iLeft, &iRight, fNoCheck, FALSE );

         HB_GTSELF_REST( pGT, iTop, iLeft, iBottom, iRight, ( BYTE * ) hb_parc( 
5 ) );
         HB_GTSELF_FLUSH( pGT );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_DISPBEGIN )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_DISPBEGIN( pGT );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_DISPEND )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_DISPEND( pGT );
      HB_GTSELF_FLUSH( pGT );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_DISPCOUNT )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retni( HB_GTSELF_DISPCOUNT( pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_DISPBOX )
{
   if( ISNUM( 1 ) && ISNUM( 2 ) && ISNUM( 3 ) && ISNUM( 4 ) )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         char * pszBox = hb_parc( 5 );
         char * pszColor = hb_parc( 6 );
         int iTop, iLeft, iBottom, iRight, iColor;

         iTop    = hb_parni( 1 );
         iLeft   = hb_parni( 2 );
         iBottom = hb_parni( 3 );
         iRight  = hb_parni( 4 );
         iColor = pszColor ? HB_GTSELF_COLORNUM( pGT, pszColor ) :
                             HB_GTSELF_GETCOLOR( pGT );
         if( pszBox )
            HB_GTSELF_BOX( pGT, iTop, iLeft, iBottom, iRight,
                           ( BYTE * ) ( *pszBox ? pszBox : "         " ),
                           iColor );
         else if( hb_parni( 5 ) == 2 )
            HB_GTSELF_BOXD( pGT, iTop, iLeft, iBottom, iRight,
                            ( BYTE * ) _B_DOUBLE, iColor );
         else
            HB_GTSELF_BOXS( pGT, iTop, iLeft, iBottom, iRight,
                            ( BYTE * ) _B_SINGLE, iColor );

         HB_GTSELF_SETPOS( pGT, iTop + 1, iLeft + 1 );
         HB_GTSELF_FLUSH( pGT );

         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_DISPOUT )
{
   if( hb_pcount() > 0 )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         char * pszColor = hb_parc( 2 );
         char szOldColor[ CLR_STRLEN ];
         char * pStr;
         ULONG ulLen;
         BOOL fFree;

         if( pszColor )
         {
            HB_GTSELF_GETCOLORSTR( pGT, szOldColor );
            HB_GTSELF_SETCOLORSTR( pGT, pszColor );
         }

         pStr = hb_itemStringCon( hb_param( 1, HB_IT_ANY ), &ulLen, &fFree );

         HB_GTSELF_WRITE( pGT, ( BYTE * ) pStr, ulLen );
         HB_GTSELF_FLUSH( pGT );

         if( fFree )
            hb_xfree( pStr );

         if( pszColor )
            HB_GTSELF_SETCOLORSTR( pGT, szOldColor );

         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_DISPOUTAT )
{
   if( hb_pcount() >= 3 )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         char * pszColor = hb_parc( 4 );
         char szOldColor[ CLR_STRLEN ];
         char * pStr;
         ULONG ulLen;
         BOOL fFree;

         if( pszColor )
         {
            HB_GTSELF_GETCOLORSTR( pGT, szOldColor );
            HB_GTSELF_SETCOLORSTR( pGT, pszColor );
         }

         pStr = hb_itemStringCon( hb_param( 3, HB_IT_ANY ), &ulLen, &fFree );

         HB_GTSELF_WRITEAT( pGT, hb_parni( 1 ), hb_parni( 2 ),
                                 ( BYTE * ) pStr, ulLen );
         HB_GTSELF_FLUSH( pGT );

         if( fFree )
            hb_xfree( pStr );

         if( pszColor )
            HB_GTSELF_SETCOLORSTR( pGT, szOldColor );

         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_QOUT )
{
   hb_consoleOut( TRUE );
}

HB_FUNC( TWINDOW_QQOUT )
{
   if( hb_pcount() > 0 )
      hb_consoleOut( FALSE );
}

HB_FUNC( TWINDOW_SCROLL )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iTop, iLeft, iBottom, iRight;
      int iMaxRow = HB_GTSELF_MAXROW( pGT );
      int iMaxCol = HB_GTSELF_MAXCOL( pGT );

      iTop = hb_parni( 1 );
      if( iTop < 0 )
         iTop = 0;
      else if( iTop > iMaxRow )
         iTop = iMaxRow;

      iLeft = hb_parni( 2 );
      if( iLeft < 0 )
         iLeft = 0;
      else if( iLeft > iMaxCol )
         iLeft = iMaxCol;

      if( ISNUM( 3 ) )
      {
         iBottom = hb_parni( 3 );
         if( iBottom < 0 )
            iBottom = 0;
         else if( iBottom > iMaxRow )
            iBottom = iMaxRow;
      }
      else
         iBottom = iMaxRow;

      if( ISNUM( 4 ) )
      {
         iRight = hb_parni( 4 );
         if( iRight < 0 )
            iRight = 0;
         else if( iRight > iMaxCol )
            iRight = iMaxCol;
      }
      else
         iRight = iMaxCol;

      if( iTop <= iBottom && iLeft <= iRight )
      {
         HB_GTSELF_SCROLL( pGT, iTop, iLeft, iBottom, iRight,
                           HB_GTSELF_GETCOLOR( pGT ), ' ',
                           hb_parni( 5 ), hb_parni( 6 ) );
         HB_GTSELF_FLUSH( pGT );
      }

      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_INKEY )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      USHORT uiPCount = hb_pcount();
      BOOL fWait = uiPCount == 1 || ( uiPCount > 1 && ISNUM( 1 ) );
      double dSeconds = hb_parnd( 1 );
      int iEventMask = ISNUM( 2 ) ? hb_parni( 2 ) : hb_setGetEventMask();

      hb_retni( HB_GTSELF_INKEYGET( pGT, fWait, dSeconds, iEventMask ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_NEXTKEY )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iEventMask = ISNUM( 1 ) ? hb_parni( 1 ) : hb_setGetEventMask();

      hb_retni( HB_GTSELF_INKEYNEXT( pGT, iEventMask ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_LASTKEY )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iEventMask = ISNUM( 1 ) ? hb_parni( 1 ) : INKEY_ALL;

      hb_retni( HB_GTSELF_INKEYLAST( pGT, iEventMask ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_PUTKEY )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if( ISNUM( 1 ) )
         HB_GTSELF_INKEYPUT( pGT, hb_parni( 1 ) );
      else if( ISCHAR( 1 ) )
      {
         PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
         char * szText = hb_itemGetCPtr( pText );
         ULONG ulLen = hb_itemGetCLen( pText ), ulIndex;

         for( ulIndex = 0; ulIndex < ulLen; ulIndex++ )
            HB_GTSELF_INKEYPUT( pGT, ( UCHAR ) szText[ ulIndex ] );
      }
      else if( ISARRAY( 1 ) )
      {
         PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY );
         ULONG ulElements = hb_arrayLen( pArray ), ulIndex;

         for( ulIndex = 1; ulIndex <= ulElements; ulIndex++ )
         {
            if( hb_arrayGetType( pArray, ulIndex ) & HB_IT_NUMERIC )
               HB_GTSELF_INKEYPUT( pGT, hb_arrayGetNI( pArray, ulIndex ) );
         }
      }
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_KEYBOARD )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_INKEYRESET( pGT );
      if( ISCHAR( 1 ) )
         HB_GTSELF_INKEYSETTEXT( pGT, hb_parc( 1 ), hb_parclen( 1 ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SETLASTKEY )
{
   if( ISNUM( 1 ) )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         HB_GTSELF_INKEYSETLAST( pGT, hb_parni( 1 ) );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_MPRESENT )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retl( HB_GTSELF_MOUSEISPRESENT( pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MHIDE )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_MOUSESETCURSOR( pGT, FALSE );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MSHOW )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_MOUSESETCURSOR( pGT, TRUE );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MROW )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retni( HB_GTSELF_MOUSEROW( pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MCOL )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retni( HB_GTSELF_MOUSECOL( pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MSETPOS )
{
   if( ISNUM( 1 ) && ISNUM( 2 ) )
   {
      PHB_GT pGT, pOldGT;
      pGT = hb_gt_getBasePtr( &pOldGT );
      if( pGT )
      {
         HB_GTSELF_MOUSESETPOS( pGT, hb_parni( 1 ), hb_parni( 2 ) );
         hb_gt_restoreBasePtr( pOldGT );
      }
   }
}

HB_FUNC( TWINDOW_MSETCURSOR )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retl( HB_GTSELF_MOUSEGETCURSOR( pGT ) );
      if( ISLOG( 1 ) )
         HB_GTSELF_MOUSESETCURSOR( pGT, hb_parl( 1 ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MSETBOUNDS )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_MOUSESETBOUNDS( pGT, hb_parni( 1 ), hb_parni( 2 ),
                                ISNUM( 3 ) ? hb_parni( 3 ) : HB_GTSELF_MAXROW( 
pGT ),
                                ISNUM( 4 ) ? hb_parni( 4 ) : HB_GTSELF_MAXCOL( 
pGT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MSAVESTATE )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iLen = HB_GTSELF_MOUSESTORAGESIZE( pGT );

      if( iLen > 0 )
      {
         BYTE * pBuffer = ( BYTE * ) hb_xgrab( iLen + 1 );

         HB_GTSELF_MOUSESAVESTATE( pGT, pBuffer );
         hb_retclen_buffer( ( char * ) pBuffer, iLen );
      }
      else
         hb_retc( NULL );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MRESTSTATE )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if( hb_parclen( 1 ) == ( ULONG ) HB_GTSELF_MOUSESTORAGESIZE( pGT ) )
         HB_GTSELF_MOUSERESTORESTATE( pGT, hb_parc( 1 ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MDBLCK )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retni( HB_GTSELF_MOUSEGETDOUBLECLICKSPEED( pGT ) );
      if( ISNUM( 1 ) )
         HB_GTSELF_MOUSESETDOUBLECLICKSPEED( pGT, hb_parni( 1 ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MLEFTDOWN )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retl( HB_GTSELF_MOUSEBUTTONSTATE( pGT, M_BUTTON_LEFT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MRIGHTDOWN )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retl( HB_GTSELF_MOUSEBUTTONSTATE( pGT, M_BUTTON_RIGHT ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_MMIDDLEDOWN )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retl( HB_GTSELF_MOUSEBUTTONSTATE( pGT, M_BUTTON_MIDDLE ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_BELL )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_BELL( pGT );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_TONE )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if( ISNUM( 1 ) )
      {
         PHB_GT pGT, pOldGT;
         pGT = hb_gt_getBasePtr( &pOldGT );
         if( pGT )
         {
            HB_GTSELF_TONE( pGT, hb_parnd( 1 ), ( ISNUM( 2 ) ? hb_parnd( 2 ) : 
1.0 ) );
            hb_gt_restoreBasePtr( pOldGT );
         }
      }
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SETDISPCP )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if ( ISCHAR( 1 ) )
      {
         if ( hb_pcount() == 2 && ISLOG(2) )
            HB_GTSELF_SETDISPCP( pGT, hb_parc( 1 ), NULL, hb_parl( 2 ) );
         else
            HB_GTSELF_SETDISPCP( pGT, hb_parc( 1 ), hb_parc( 2 ), hb_parl( 3 ) 
);
      }
      else
         hb_errRT_BASE_SubstR( EG_ARG, 1089, NULL, "HB_SETDISPCP", 
HB_ERR_ARGS_BASEPARAMS );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SETKEYCP )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if ( ISCHAR( 1 ) )
         HB_GTSELF_SETKEYCP( pGT, hb_parc( 1 ), hb_parc( 2 ) );
      else
         hb_errRT_BASE_SubstR( EG_ARG, 1089, NULL, "HB_SETKEYCP", 
HB_ERR_ARGS_BASEPARAMS );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_SETTERMCP )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if ( ISCHAR(1) )
      {
         if ( hb_pcount() == 2 && ISLOG(2) )
         {
            HB_GTSELF_SETDISPCP( pGT, hb_parc( 1 ), NULL, hb_parl( 2 ) );
            HB_GTSELF_SETKEYCP( pGT, hb_parc( 1 ), NULL );
         }
         else
         {
            HB_GTSELF_SETDISPCP( pGT, hb_parc( 1 ), hb_parc( 2 ), hb_parl( 3 ) 
);
            HB_GTSELF_SETKEYCP( pGT, hb_parc( 1 ), hb_parc( 2 ) );
         }
      }
      else
         hb_errRT_BASE_SubstR( EG_ARG, 1089, NULL, "HB_SETTERMCP", 
HB_ERR_ARGS_BASEPARAMS );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_OUTSTD )
{
   hb_stdOutErr( TRUE );
}

HB_FUNC( TWINDOW_OUTERR )
{
   hb_stdOutErr( FALSE );
}

HB_FUNC( TWINDOW_ALERT )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      int iClrNorm = hb_colorParam( pGT, 3 ),
          iClrHigh = hb_colorParam( pGT, 4 );

      hb_retni( HB_GTSELF_ALERT( pGT, hb_param( 1, HB_IT_ANY ), hb_param( 2, 
HB_IT_ANY ),
                                 iClrNorm, iClrHigh, hb_parnd( 5 ) ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_GFXPRIMITIVE )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retni( HB_GTSELF_GFXPRIMITIVE( pGT, hb_parni( 1 ), hb_parni( 2 ),
                                             hb_parni( 3 ), hb_parni( 4 ),
                                             hb_parni( 5 ), hb_parni( 6 ) ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_GFXTEXT )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      HB_GTSELF_GFXTEXT( pGT, hb_parni( 1 ), hb_parni( 2 ),
                         hb_parc( 3 ),  hb_parni( 4 ),
                         hb_parni( 5 ), hb_parni( 6 ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_GTINFO )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      if( ISNUM( 1 ) )
      {
         HB_GT_INFO gtInfo;

         gtInfo.pNewVal = hb_param( 2, HB_IT_ANY );
         gtInfo.pResult = NULL;

         HB_GTSELF_INFO( pGT, hb_parni( 1 ), &gtInfo );
         if( gtInfo.pResult )
            hb_itemReturnRelease( gtInfo.pResult );
      }
      else
         hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, "HB_GTINFO", 
HB_ERR_ARGS_BASEPARAMS );
      hb_gt_restoreBasePtr( pOldGT );
   }
}

HB_FUNC( TWINDOW_GTVERSION )
{
   PHB_GT pGT, pOldGT;
   pGT = hb_gt_getBasePtr( &pOldGT );
   if( pGT )
   {
      hb_retc( HB_GTSELF_VERSION( pGT, hb_parni( 1 ) ) );
      hb_gt_restoreBasePtr( pOldGT );
   }
}
#pragma enddump
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to