[runtime] Added Crypt() overload that accepts and returns a BYTE array

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
USING System.Globalization
USING System.Text

/// <summary>
/// Encrypt or decrypt a string.
/// </summary>
/// <param name="cSource"></param>
/// <param name="cKey"></param>
/// <returns>
/// </returns>
FUNCTION Crypt(cSource AS STRING,cKey AS STRING) AS STRING
	LOCAL bSource AS BYTE[]
	LOCAL bDest  AS BYTE[]
    LOCAL enc     AS Encoding
    IF cSource?:Length == 0 .OR. cKey?:Length == 0
        RETURN cSource
    ENDIF
    enc         := StringHelpers.WinEncoding
    bSource     := enc:GetBytes(cSource)
    bDest := Crypt(bSource, cKey, FALSE)
    cSource := enc:GetString(bDest)
	RETURN cSource

/// <summary>
/// Encrypt or decrypt an array of bytes.
/// </summary>
/// <param name="bSource"></param>
/// <param name="cKey"></param>
/// <returns>
/// </returns>
FUNCTION Crypt(bSource AS BYTE[],cKey AS STRING) AS BYTE[]
	RETURN Crypt(bSource, cKey, TRUE)

FUNCTION Crypt(bSource AS BYTE[],cKey AS STRING,lCreateNewArray AS LOGIC) AS BYTE[]
	LOCAL bDest   AS BYTE[]
    LOCAL bKey    AS BYTE[]
    LOCAL enc     AS Encoding
    LOCAL keyLen  AS INT
    LOCAL sourceLen AS INT
    LOCAL uiCode1 AS WORD
    LOCAL uiCode2 AS WORD
    LOCAL uiRotate AS WORD
    LOCAL uiCounter AS WORD
    LOCAL bNibble  AS BYTE
    LOCAL nPos     AS INT
    LOCAL nKeyPos  AS INT
    LOCAL bCurrent AS BYTE
    IF bSource:Length == 0 .OR. cKey?:Length == 0
        RETURN bSource
    ENDIF
    enc         := StringHelpers.WinEncoding
    bKey        := enc:GetBytes(cKey)
    keyLen      := cKey:Length
    sourceLen   := bSource:Length
    IF lCreateNewArray
	    bDest       := BYTE[]{sourceLen}
	    System.Array.Copy(bSource, bDest, sourceLen)
    ELSE
    	bDest := bSource
    END IF
    uiCode1     := (WORD) (bKey[1] ~ keyLen)
    uiCode2     := 0xAAAA
    nPos        := 1
    nKeyPos     := keyLen+1
    bNibble     := 0
    DO WHILE nPos <= sourceLen
        IF nKeyPos > keyLen
            nKeyPos := 1
        ENDIF
        bCurrent  := bSource[nPos]  ~ bKey[nKeyPos]
        uiCode1   := (WORD) (uiCode1 ~ (uiCode1 >> 8))
        uiRotate  := (WORD) (uiCode1 & 0x0F)
        uiCode1   := (WORD) ((uiCode1 >> uiRotate)  | (uiCode1 << (16 - UiRotate)))
        uiCode1   := (WORD) (uICode1 ~ uiCode2)
        uiCode1   += 0x10
        uiCounter := (WORD) (uiCode1 & 0x1E)
        uiCounter += 2
        DO WHILE uiCounter > 0
            uiCounter --
            uiRotate := (BYTE) (uiCounter & 0x0F)
            uiCode2 := (WORD) ((uiCode2 >> uiRotate) | (uiCode2 << (16 - uiRotate)) )
            uiCode2 := (WORD) ((uiCode2 << 8) | (INT)( ( (uiCode2 >> 8) ~ 0xFF) ) )
            uiCode2 := (WORD) ((uiCode2 << 1) | (uiCode2 >> 15) )
            uiCode2 := (WORD)(uiCode2 ~ 0xAAAA )
            bNibble := (BYTE)(uiCode2 & 0xFF)

            bNibble := (BYTE)( (bNibble << 1) | (bNibble >> 7) )
            uiCode2 := (WORD)( (uiCode2 & 0xFF00) | bNibble )
            uiCounter--
        ENDDO
        bDest[nPos] := bCurrent ~ bNibble
        nPos ++
        nKeyPos++
    ENDDO
	RETURN bDest

/// <summary>
/// Encrypt or decrypt a string, changing the contents of the original string as well as returning the encrypted string.
/// </summary>
/// <param name="cSource"></param>
/// <param name="cKey"></param>
/// <returns>
/// </returns>
FUNCTION CryptA(cSource AS STRING,cKey AS STRING) AS STRING
	cSource := Crypt(cSource, cKey)
	RETURN cSource

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
USING System.Globalization
USING System.Text

/// <summary>
/// Encrypt or decrypt a string.
/// </summary>
/// <param name="cSource"></param>
/// <param name="cKey"></param>
/// <returns>
/// </returns>
FUNCTION Crypt(cSource AS STRING,cKey AS STRING) AS STRING
	LOCAL bSource AS BYTE[]
    LOCAL bKey    AS BYTE[]
    LOCAL enc     AS Encoding
    LOCAL keyLen  AS INT
    LOCAL sourceLen AS INT
    LOCAL uiCode1 AS WORD
    LOCAL uiCode2 AS WORD
    LOCAL uiRotate AS WORD
    LOCAL uiCounter AS WORD
    LOCAL bNibble  AS BYTE
    LOCAL nPos     AS INT
    LOCAL nKeyPos  AS INT
    LOCAL bCurrent AS BYTE
    IF cSource?:Length == 0 .OR. cKey?:Length == 0
        RETURN cSource
    ENDIF
    enc         := StringHelpers.WinEncoding
    bSource     := enc:GetBytes(cSource)
    bKey        := enc:GetBytes(cKey)
    keyLen      := cKey:Length
    sourceLen   := cSource:Length
    uiCode1     := (WORD) (bKey[1] ~ keyLen)
    uiCode2     := 0xAAAA
    nPos        := 1
    nKeyPos     := keyLen+1
    bNibble     := 0
    DO WHILE nPos <= sourceLen
        IF nKeyPos > keyLen
            nKeyPos := 1
        ENDIF
        bCurrent  := bSource[nPos]  ~ bKey[nKeyPos]
        uiCode1   := (WORD) (uiCode1 ~ (uiCode1 >> 8))
        uiRotate  := (WORD) (uiCode1 & 0x0F)
        uiCode1   := (WORD) ((uiCode1 >> uiRotate)  | (uiCode1 << (16 - UiRotate)))
        uiCode1   := (WORD) (uICode1 ~ uiCode2)
        uiCode1   += 0x10
        uiCounter := (WORD) (uiCode1 & 0x1E)
        uiCounter += 2
        DO WHILE uiCounter > 0
            uiCounter --
            uiRotate := (BYTE) (uiCounter & 0x0F)
            uiCode2 := (WORD) ((uiCode2 >> uiRotate) | (uiCode2 << (16 - uiRotate)) )
            uiCode2 := (WORD) ((uiCode2 << 8) | (INT)( ( (uiCode2 >> 8) ~ 0xFF) ) )
            uiCode2 := (WORD) ((uiCode2 << 1) | (uiCode2 >> 15) )
            uiCode2 := (WORD)(uiCode2 ~ 0xAAAA )
            bNibble := (BYTE)(uiCode2 & 0xFF)

            bNibble := (BYTE)( (bNibble << 1) | (bNibble >> 7) )
            uiCode2 := (WORD)( (uiCode2 & 0xFF00) | bNibble )
            uiCounter--
        ENDDO
        bSource[nPos] := bCurrent ~ bNibble
        nPos ++
        nKeyPos++
    ENDDO
    cSource := enc:GetString(bSource)
	RETURN cSource

/// <summary>
/// Encrypt or decrypt a string, changing the contents of the original string as well as returning the encrypted string.
/// </summary>
/// <param name="cSource"></param>
/// <param name="cKey"></param>
/// <returns>
/// </returns>
FUNCTION CryptA(cSource AS STRING,cKey AS STRING) AS STRING
	cSource := Crypt(cSource, cKey)
	RETURN cSource


FIX: class QDateTime moved to QtCore

FIX: class QDateTime moved to QtCore

/*

  Qt5xHb - bibliotecas de ligao entre Harbour/xHarbour e Qt Framework 5

  Copyright (C) 2012-2017 Marcos Antonio Gambeta <marcosgambeta@uol.com.br>

*/

#include "hbclass.ch"
#include "qt4xhb_clsid.ch"

REQUEST QDATE
REQUEST QTIME

CLASS QDateTime

   DATA pointer
   DATA class_id INIT Class_Id_QDateTime
   DATA class_flags INIT 0
   DATA self_destruction INIT .f.

   METHOD new1
   METHOD new2
   METHOD new3
   METHOD new4
   METHOD new
   METHOD delete
   METHOD addDays
   METHOD addMSecs
   METHOD addMonths
   METHOD addSecs
   METHOD addYears
   METHOD date
   METHOD daysTo
   METHOD isNull
   METHOD isValid
   METHOD msecsTo
   METHOD secsTo
   METHOD setDate
   METHOD setMSecsSinceEpoch
   METHOD setTime
   METHOD setTimeSpec
   METHOD setTime_t
   METHOD time
   METHOD timeSpec
   METHOD toLocalTime
   METHOD toMSecsSinceEpoch
   METHOD toString1
   METHOD toString2
   METHOD toString
   METHOD toTimeSpec
   METHOD toTime_t
   METHOD toUTC
   METHOD currentDateTime
   METHOD currentDateTimeUtc
   METHOD currentMSecsSinceEpoch
   METHOD fromMSecsSinceEpoch
   METHOD fromString1
   METHOD fromString2
   METHOD fromString
   METHOD fromTime_t
   METHOD newFrom
   METHOD newFromObject
   METHOD newFromPointer
   METHOD selfDestruction
   METHOD setSelfDestruction
   DESTRUCTOR destroyObject

END CLASS

PROCEDURE destroyObject () CLASS QDateTime
   IF ::self_destruction
      ::delete()
   ENDIF
RETURN

#pragma BEGINDUMP

/*

  Qt5xHb - bibliotecas de ligao entre Harbour/xHarbour e Qt Framework 5

  Copyright (C) 2012-2017 Marcos Antonio Gambeta <marcosgambeta@uol.com.br>

*/

#include <Qt>

#ifndef __XHARBOUR__
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include <QDateTime>
#endif
#endif

#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapierr.h"
#include "hbvm.h"
#include "hbstack.h"

#ifndef __XHARBOUR__
#include "hbapicls.h"
#define ISNIL HB_ISNIL
#define ISLOG HB_ISLOG
#define ISNUM HB_ISNUM
#define ISCHAR HB_ISCHAR
#define ISPOINTER HB_ISPOINTER
#define ISOBJECT HB_ISOBJECT
#define ISARRAY HB_ISARRAY
#endif

#include "qt4xhb_clsid.h"
#include "qt4xhb_utils.h"

#ifdef __XHARBOUR__
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include <QDateTime>
#endif
#endif

/*
QDateTime ()
*/
HB_FUNC_STATIC( QDATETIME_NEW1 )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
  QDateTime * o = new QDateTime (  );
  PHB_ITEM self = hb_stackSelfItem();
  PHB_ITEM ptr = hb_itemPutPtr( NULL,(QDateTime *) o );
  hb_objSendMsg( self, "_pointer", 1, ptr );
  hb_itemRelease( ptr );
  PHB_ITEM des = hb_itemPutL( NULL, true );
  hb_objSendMsg( self, "_SELF_DESTRUCTION", 1, des );
  hb_itemRelease( des );
  hb_itemReturn( self );
#endif
}

/*
QDateTime ( const QDate & date )
*/
HB_FUNC_STATIC( QDATETIME_NEW2 )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
  QDate * par1 = (QDate *) _qtxhb_itemGetPtr(1);
  QDateTime * o = new QDateTime ( *par1 );
  PHB_ITEM self = hb_stackSelfItem();
  PHB_ITEM ptr = hb_itemPutPtr( NULL,(QDateTime *) o );
  hb_objSendMsg( self, "_pointer", 1, ptr );
  hb_itemRelease( ptr );
  PHB_ITEM des = hb_itemPutL( NULL, true );
  hb_objSendMsg( self, "_SELF_DESTRUCTION", 1, des );
  hb_itemRelease( des );
  hb_itemReturn( self );
#endif
}

/*
QDateTime ( const QDate & date, const QTime & time, Qt::TimeSpec spec = Qt::LocalTime )
*/
HB_FUNC_STATIC( QDATETIME_NEW3 )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
  QDate * par1 = (QDate *) _qtxhb_itemGetPtr(1);
  QTime * par2 = (QTime *) _qtxhb_itemGetPtr(2);
  int par3 = ISNIL(3)? (int) Qt::LocalTime : hb_parni(3);
  QDateTime * o = new QDateTime ( *par1, *par2,  (Qt::TimeSpec) par3 );
  PHB_ITEM self = hb_stackSelfItem();
  PHB_ITEM ptr = hb_itemPutPtr( NULL,(QDateTime *) o );
  hb_objSendMsg( self, "_pointer", 1, ptr );
  hb_itemRelease( ptr );
  PHB_ITEM des = hb_itemPutL( NULL, true );
  hb_objSendMsg( self, "_SELF_DESTRUCTION", 1, des );
  hb_itemRelease( des );
  hb_itemReturn( self );
#endif
}

/*
QDateTime ( const QDateTime & other )
*/
HB_FUNC_STATIC( QDATETIME_NEW4 )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
  QDateTime * par1 = (QDateTime *) _qtxhb_itemGetPtr(1);
  QDateTime * o = new QDateTime ( *par1 );
  PHB_ITEM self = hb_stackSelfItem();
  PHB_ITEM ptr = hb_itemPutPtr( NULL,(QDateTime *) o );
  hb_objSendMsg( self, "_pointer", 1, ptr );
  hb_itemRelease( ptr );
  PHB_ITEM des = hb_itemPutL( NULL, true );
  hb_objSendMsg( self, "_SELF_DESTRUCTION", 1, des );
  hb_itemRelease( des );
  hb_itemReturn( self );
#endif
}

//[1]QDateTime ()
//[2]QDateTime ( const QDate & date )
//[3]QDateTime ( const QDate & date, const QTime & time, Qt::TimeSpec spec = Qt::LocalTime )
//[4]QDateTime ( const QDateTime & other )

HB_FUNC_STATIC( QDATETIME_NEW )
{
  if( ISNUMPAR(0) )
  {
    HB_FUNC_EXEC( QDATETIME_NEW1 );
  }
  else if( ISNUMPAR(1) && ISQDATE(1) )
  {
    HB_FUNC_EXEC( QDATETIME_NEW2 );
  }
  else if( ISBETWEEN(2,3) && ISQDATE(1) && ISQTIME(2) && (ISNUM(3)||ISNIL(3)) )
  {
    HB_FUNC_EXEC( QDATETIME_NEW3 );
  }
  else if( ISNUMPAR(1) && ISQDATETIME(1) )
  {
    HB_FUNC_EXEC( QDATETIME_NEW4 );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

HB_FUNC_STATIC( QDATETIME_DELETE )
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
  QDateTime * obj = (QDateTime *) hb_itemGetPtr( hb_objSendMsg( hb_stackSelfItem(), "POINTER", 0 ) );
  if( obj )
  {
    delete obj;
    obj = NULL;
    PHB_ITEM self = hb_stackSelfItem();
    PHB_ITEM ptr = hb_itemPutPtr( NULL, NULL );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
  }
  hb_itemReturn( hb_stackSelfItem() );
#endif
}

/*
QDateTime addDays ( int ndays ) const
*/
HB_FUNC_STATIC( QDATETIME_ADDDAYS )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * ptr = new QDateTime( obj->addDays ( (int) hb_parni(1) ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
QDateTime addMSecs ( qint64 msecs ) const
*/
HB_FUNC_STATIC( QDATETIME_ADDMSECS )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * ptr = new QDateTime( obj->addMSecs ( (qint64) hb_parni(1) ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
QDateTime addMonths ( int nmonths ) const
*/
HB_FUNC_STATIC( QDATETIME_ADDMONTHS )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * ptr = new QDateTime( obj->addMonths ( (int) hb_parni(1) ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
QDateTime addSecs ( int s ) const
*/
HB_FUNC_STATIC( QDATETIME_ADDSECS )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * ptr = new QDateTime( obj->addSecs ( (int) hb_parni(1) ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
QDateTime addYears ( int nyears ) const
*/
HB_FUNC_STATIC( QDATETIME_ADDYEARS )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * ptr = new QDateTime( obj->addYears ( (int) hb_parni(1) ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
QDate date () const
*/
HB_FUNC_STATIC( QDATETIME_DATE )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDate * ptr = new QDate( obj->date (  ) );
    _qt4xhb_createReturnClass ( ptr, "QDATE", true );
  }
}

/*
int daysTo ( const QDateTime & other ) const
*/
HB_FUNC_STATIC( QDATETIME_DAYSTO )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * par1 = (QDateTime *) _qtxhb_itemGetPtr(1);
    hb_retni( obj->daysTo ( *par1 ) );
  }
}

/*
bool isNull () const
*/
HB_FUNC_STATIC( QDATETIME_ISNULL )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retl( obj->isNull (  ) );
  }
}

/*
bool isValid () const
*/
HB_FUNC_STATIC( QDATETIME_ISVALID )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retl( obj->isValid (  ) );
  }
}

/*
qint64 msecsTo ( const QDateTime & other ) const
*/
HB_FUNC_STATIC( QDATETIME_MSECSTO )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * par1 = (QDateTime *) _qtxhb_itemGetPtr(1);
    hb_retni( obj->msecsTo ( *par1 ) );
  }
}

/*
int secsTo ( const QDateTime & other ) const
*/
HB_FUNC_STATIC( QDATETIME_SECSTO )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * par1 = (QDateTime *) _qtxhb_itemGetPtr(1);
    hb_retni( obj->secsTo ( *par1 ) );
  }
}

/*
void setDate ( const QDate & date )
*/
HB_FUNC_STATIC( QDATETIME_SETDATE )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDate * par1 = (QDate *) _qtxhb_itemGetPtr(1);
    obj->setDate ( *par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setMSecsSinceEpoch ( qint64 msecs )
*/
HB_FUNC_STATIC( QDATETIME_SETMSECSSINCEEPOCH )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setMSecsSinceEpoch ( (qint64) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setTime ( const QTime & time )
*/
HB_FUNC_STATIC( QDATETIME_SETTIME )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QTime * par1 = (QTime *) _qtxhb_itemGetPtr(1);
    obj->setTime ( *par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setTimeSpec ( Qt::TimeSpec spec )
*/
HB_FUNC_STATIC( QDATETIME_SETTIMESPEC )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    obj->setTimeSpec (  (Qt::TimeSpec) par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setTime_t ( uint seconds )
*/
HB_FUNC_STATIC( QDATETIME_SETTIME_T )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setTime_t ( (uint) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
QTime time () const
*/
HB_FUNC_STATIC( QDATETIME_TIME )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QTime * ptr = new QTime( obj->time (  ) );
    _qt4xhb_createReturnClass ( ptr, "QTIME", true );
  }
}

/*
Qt::TimeSpec timeSpec () const
*/
HB_FUNC_STATIC( QDATETIME_TIMESPEC )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int i = obj->timeSpec (  );
    hb_retni( i );
  }
}

/*
QDateTime toLocalTime () const
*/
HB_FUNC_STATIC( QDATETIME_TOLOCALTIME )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * ptr = new QDateTime( obj->toLocalTime (  ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
qint64 toMSecsSinceEpoch () const
*/
HB_FUNC_STATIC( QDATETIME_TOMSECSSINCEEPOCH )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->toMSecsSinceEpoch (  ) );
  }
}

/*
QString toString ( const QString & format ) const
*/
HB_FUNC_STATIC( QDATETIME_TOSTRING1 )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QString par1 = QLatin1String( hb_parc(1) );
    hb_retc( (const char *) obj->toString ( par1 ).toLatin1().data() );
  }
}

/*
QString toString ( Qt::DateFormat format = Qt::TextDate ) const
*/
HB_FUNC_STATIC( QDATETIME_TOSTRING2 )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = ISNIL(1)? (int) Qt::TextDate : hb_parni(1);
    hb_retc( (const char *) obj->toString (  (Qt::DateFormat) par1 ).toLatin1().data() );
  }
}

//[1]QString toString ( const QString & format ) const
//[2]QString toString ( Qt::DateFormat format = Qt::TextDate ) const

HB_FUNC_STATIC( QDATETIME_TOSTRING )
{
  if( ISNUMPAR(1) && ISCHAR(1) )
  {
    HB_FUNC_EXEC( QDATETIME_TOSTRING1 );
  }
  else if( ISBETWEEN(0,1) && (ISNUM(1)||ISNIL(1)) )
  {
    HB_FUNC_EXEC( QDATETIME_TOSTRING2 );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

/*
QDateTime toTimeSpec ( Qt::TimeSpec specification ) const
*/
HB_FUNC_STATIC( QDATETIME_TOTIMESPEC )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    QDateTime * ptr = new QDateTime( obj->toTimeSpec (  (Qt::TimeSpec) par1 ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
uint toTime_t () const
*/
HB_FUNC_STATIC( QDATETIME_TOTIME_T )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->toTime_t (  ) );
  }
}

/*
QDateTime toUTC () const
*/
HB_FUNC_STATIC( QDATETIME_TOUTC )
{
  QDateTime * obj = (QDateTime *) _qtxhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QDateTime * ptr = new QDateTime( obj->toUTC (  ) );
    _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
  }
}

/*
static QDateTime currentDateTime ()
*/
HB_FUNC_STATIC( QDATETIME_CURRENTDATETIME )
{
  QDateTime * ptr = new QDateTime( QDateTime::currentDateTime (  ) );
  _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
}

/*
static QDateTime currentDateTimeUtc ()
*/
HB_FUNC_STATIC( QDATETIME_CURRENTDATETIMEUTC )
{
  QDateTime * ptr = new QDateTime( QDateTime::currentDateTimeUtc (  ) );
  _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
}

/*
static qint64 currentMSecsSinceEpoch ()
*/
HB_FUNC_STATIC( QDATETIME_CURRENTMSECSSINCEEPOCH )
{
  hb_retni( QDateTime::currentMSecsSinceEpoch (  ) );
}

/*
static QDateTime fromMSecsSinceEpoch ( qint64 msecs )
*/
HB_FUNC_STATIC( QDATETIME_FROMMSECSSINCEEPOCH )
{
  QDateTime * ptr = new QDateTime( QDateTime::fromMSecsSinceEpoch ( (qint64) hb_parni(1) ) );
  _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
}

/*
static QDateTime fromString ( const QString & string, Qt::DateFormat format = Qt::TextDate )
*/
HB_FUNC_STATIC( QDATETIME_FROMSTRING1 )
{
  QString par1 = QLatin1String( hb_parc(1) );
  int par2 = ISNIL(2)? (int) Qt::TextDate : hb_parni(2);
  QDateTime * ptr = new QDateTime( QDateTime::fromString ( par1,  (Qt::DateFormat) par2 ) );
  _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
}

/*
static QDateTime fromString ( const QString & string, const QString & format )
*/
HB_FUNC_STATIC( QDATETIME_FROMSTRING2 )
{
  QString par1 = QLatin1String( hb_parc(1) );
  QString par2 = QLatin1String( hb_parc(2) );
  QDateTime * ptr = new QDateTime( QDateTime::fromString ( par1, par2 ) );
  _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
}

//[1]QDateTime fromString ( const QString & string, Qt::DateFormat format = Qt::TextDate )
//[2]QDateTime fromString ( const QString & string, const QString & format )

HB_FUNC_STATIC( QDATETIME_FROMSTRING )
{
  if( ISBETWEEN(1,2) && ISCHAR(1) && (ISNUM(2)||ISNIL(2)) )
  {
    HB_FUNC_EXEC( QDATETIME_FROMSTRING1 );
  }
  else if( ISNUMPAR(2) && ISCHAR(1) && ISCHAR(2) )
  {
    HB_FUNC_EXEC( QDATETIME_FROMSTRING2 );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

/*
static QDateTime fromTime_t ( uint seconds )
*/
HB_FUNC_STATIC( QDATETIME_FROMTIME_T )
{
  QDateTime * ptr = new QDateTime( QDateTime::fromTime_t ( (uint) hb_parni(1) ) );
  _qt4xhb_createReturnClass ( ptr, "QDATETIME", true );
}

HB_FUNC_STATIC( QDATETIME_NEWFROM )
{
  PHB_ITEM self = hb_stackSelfItem();
  if( hb_pcount() == 1 && ISOBJECT(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_objSendMsg( hb_param(1, HB_IT_OBJECT ), "POINTER", 0 ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else if( hb_pcount() == 1 && ISPOINTER(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_param(1, HB_IT_POINTER ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  hb_itemReturn( self );
}

HB_FUNC_STATIC( QDATETIME_NEWFROMOBJECT )
{
  //PHB_ITEM self = hb_stackSelfItem();
  //if( hb_pcount() == 1 && ISOBJECT(1) )
  //{
  //  PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_objSendMsg( hb_param(1, HB_IT_OBJECT ), "POINTER", 0 ) ) );
  //  hb_objSendMsg( self, "_pointer", 1, ptr );
  //  hb_itemRelease( ptr );
  //  PHB_ITEM des = hb_itemPutL( NULL, false );
  //  hb_objSendMsg( self, "_self_destruction", 1, des );
  //  hb_itemRelease( des );
  //}
  //hb_itemReturn( self );
  HB_FUNC_EXEC( QDATETIME_NEWFROM );
}

HB_FUNC_STATIC( QDATETIME_NEWFROMPOINTER )
{
  //PHB_ITEM self = hb_stackSelfItem();
  //if( hb_pcount() == 1 && ISPOINTER(1) )
  //{
  //  PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_param(1, HB_IT_POINTER ) ) );
  //  hb_objSendMsg( self, "_pointer", 1, ptr );
  //  hb_itemRelease( ptr );
  //  PHB_ITEM des = hb_itemPutL( NULL, false );
  //  hb_objSendMsg( self, "_self_destruction", 1, des );
  //  hb_itemRelease( des );
  //}
  //hb_itemReturn( self );
  HB_FUNC_EXEC( QDATETIME_NEWFROM );
}

HB_FUNC_STATIC( QDATETIME_SELFDESTRUCTION )
{
  hb_retl( (bool) hb_itemGetL( hb_objSendMsg( hb_stackSelfItem(), "SELF_DESTRUCTION", 0 ) ) );
}

HB_FUNC_STATIC( QDATETIME_SETSELFDESTRUCTION )
{
  PHB_ITEM self = hb_stackSelfItem();
  if( hb_pcount() == 1 && ISLOG(1) )
  {
    PHB_ITEM des = hb_itemPutL( NULL, hb_parl(1) );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  hb_itemReturn( self );
}

#pragma ENDDUMP


add some experimental stuff (currently commented out)

-- see also http://cs.ioc.ee/~james/papers/Relative_Monads.pdf
-- "Monads Need Not Be Endofunctors"
-- which references Fiore, Plotkin and Turi's work
-- Hamana also has much to say (http://www.cs.gunma-u.ac.jp/~hamana/)
--

import "Inventory.prg"

kind Usage = VAR | NORMAL

data Tm :: Usage ~> Inventory Tag ~> * where
  -- lambda
  Lm :: Label t -> Tm u [inv; t]i -> Tm NORMAL inv
  -- argument access
  Arg :: Tm VAR [ups; t]i
  Up :: Tm VAR [ups; t]i -> Tm VAR [ups; t, t']i
  -- the lambda introducing the argument
  Enc :: Tm VAR inv -> Tm NORMAL inv
  -- application
  App :: Tm u inv -> Tm v inv -> Tm NORMAL inv
  -- recursive let
  Let :: Label t -> Tm u [inv; t]i ->  Tm v [inv; t]i -> Tm NORMAL inv
 deriving syntax (tm) Nat(Arg, Up) LeftPair(App) Item(Enc)

{- THIS IS NOT READY YET!
sink :: Tag ~> Nat ~> Inventory Tag
{sink t 0t} = [inv; t]i
{sink t (1+n)t} = [{sink t n}; t']i

prop Tm' :: Inventory Tag ~> * where
  Arg' :: Tm' inv -> Label t -> Tm' [inv; t]i

varLemma :: Label t -> Nat' n -> Tm' {sink t n} -> exists (inv :: Inventory Tag) (t' :: Tag) . Tm' [inv; t']i
varLemma t 0v = undefined

var :: Label t -> Nat' n -> Tm {sink t n}
var l 0v = 0tm
var l 1v = Up $ var l 0v
var l 2v = Up $ var l 1v
var l 3v = Up $ var l 2v
--var l (1+v)v = Up $  (var l v)
--  where theorem hyp = varLemma l v
-}

-- (closed) identity function
--
identity :: Tm NORMAL []i
identity = Lm `a 0tm

-- ($) = \f . \a . f a
--
---dollar :: Tm NORMAL []i
---dollar = Lm `f (Lm `a (var `f 1v, var `a 0v)tm)

-- bottom = \n . bottom n
bottom = Lm `n ((0tm)tm, 0tm)tm

-- y = \a . a a
y = Lm `a ((0tm)tm, (0tm)tm)tm

-- let a = a in a
leta :: Tm NORMAL []i
leta = Let `a 0tm 0tm

-- see also http://cs.ioc.ee/~james/papers/Relative_Monads.pdf
-- "Monads Need Not Be Endofunctors"
-- which references Fiore, Plotkin and Turi's work
-- Hamana also has much to say (http://www.cs.gunma-u.ac.jp/~hamana/)
--

import "Inventory.prg"

kind Usage = VAR | NORMAL

data Tm :: Usage ~> Inventory Tag ~> * where
  -- lambda
  Lm :: Label t -> Tm u [inv; t]i -> Tm NORMAL inv
  -- argument access
  Arg :: Tm VAR [ups; t]i
  Up :: Tm VAR [ups; t]i -> Tm VAR [ups; t, t']i
  -- the lambda introducing the argument
  Enc :: Tm VAR inv -> Tm NORMAL inv
  -- application
  App :: Tm u inv -> Tm v inv -> Tm NORMAL inv
  -- recursive let
  Let :: Label t -> Tm u [inv; t]i ->  Tm v [inv; t]i -> Tm NORMAL inv
 deriving syntax (tm) Nat(Arg, Up) LeftPair(App) Item(Enc)

-- (closed) identity function
--
identity :: Tm NORMAL []i
identity = Lm `a 0tm

-- ($) = \f . \a . f a
--
dollar :: Tm NORMAL []i
dollar = Lm `f (Lm `a (1tm, 0tm)tm)

-- bottom = \n . bottom n
bottom = Lm `n ((0tm)tm, 0tm)tm

-- y = \a . a a
y = Lm `a ((0tm)tm, (0tm)tm)tm

-- let a = a in a
leta :: Tm NORMAL []i
leta = Let `a 0tm 0tm


[Runtime] Allow date calculations with Decimals and Int64

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
USING System
USING System.Runtime.Serialization
USING System.Globalization
USING System.Runtime.InteropServices
USING System.Runtime.CompilerServices
USING XSharp
USING System.Diagnostics
BEGIN NAMESPACE XSharp
	/// Internal type that implements the VO Compatible DATE type

	/// This type has many operators and implicit converters that normally are never directly called from user code.
	/// It holds year, month, day in 32 bits. For date calculations it uses the System.DateTime calculation logic.
	/// There are implicit converters between Date and DateTime.
	///
	/// <seealso cref="T:XSharp.IDate"/>
	/// <seealso cref="T:XSharp.RDD.DbDate"/>
	[DebuggerDisplay("{ToString(),nq}", Type := "DATE" )];
	[DebuggerTypeProxy(TYPEOF(DateDebugView))];
	[StructLayout(LayoutKind.Explicit,Pack := 1)];
	PUBLIC STRUCTURE __Date IMPLEMENTS System.IComparable, ;
		System.IFormattable, ;
		System.IConvertible, ;
		IDate, ;
		IComparable<__Date>, ;
		IEquatable<__Date>
		// This structure uses an explicit layout to map
		// year, month and date into 32 bits
		// the _ymd field is for convenience, so we can do a single numeric comparison
		// to determine equality or relative comparisons in stead of doing 3 comparisons
		// for date calculation we use the Value PROPERTY which returns a System.DateTime type
		// Note that the Vulcan type uses a datetime which takes 8 bytes. We only use 4 bytes
		#region fields
			[FieldOffSet(00)] PRIVATE _ymd   AS System.Int32
			[FieldOffSet(00)] PRIVATE _year  AS System.UInt16
			[FieldOffSet(02)] PRIVATE _month AS System.Byte
			[FieldOffSet(03)] PRIVATE _day   AS System.Byte
		#endregion

		#region STATIC fields
			/// <exclude />
			STATIC INITONLY PUBLIC  _NULL_DATE AS DATE
			/// <exclude />
			CONST  CLIPPER_MIN_DATE := 2415386U AS DWORD	// 1901-01-01
			/// <exclude />
			CONST  CLIPPER_MAX_DATE := 4606840U AS DWORD	// 7900-12-31
			/// <exclude />
			STATIC INITONLY _dtCalc AS Datetime

		#endregion

		#region datetime conversions
            /// Return DATE value as DateTime.
			PUBLIC PROPERTY @@Value AS System.DateTime
				GET
					IF (_ymd == 0)
						RETURN System.DateTime.MinValue
					ENDIF
					RETURN System.DateTime{_year, _month, _day}
				END GET
				SET
				    IF VALUE != DateTime.MinValue
					    _year  := (WORD) VALUE:Year
					    _month := (BYTE) VALUE:Month
					    _day   := (BYTE) VALUE:Day
				    ELSE
					    _ymd := 0
				    ENDIF
				END SET
			END PROPERTY
		#endregion

		#region constructors
			STATIC CONSTRUCTOR()
				_NULL_DATE  := DATE{}
				_dtCalc     := DateTime{1901,1,1}
				RETURN
			/// Construct a date from a DateTime value.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(dt AS System.DateTime)
                _ymd := _year := _month := _day := 0
                IF dt != DateTime.MinValue
				    _year  := (WORD) dt:Year
				    _month := (BYTE) dt:Month
				    _day   := (BYTE) dt:Day
                ELSE
                    _ymd := 0
                ENDIF
				RETURN

			/// Construct a date from another IDate type.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(d AS IDate)
                _ymd := 0
				_year  := (WORD) d:Year
				_month := (BYTE) d:Month
				_day   := (BYTE) d:Day
				RETURN

			/// Construct a date from a number of Ticks.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(ticks AS INT64)
				SELF(System.DateTime{ticks})
				RETURN

			/// Construct a date from a string. This assumes the string is in current Date format
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(strDate AS STRING)
				LOCAL dValue := CToD(strDate) AS DATE
                _year := _month := _day := 0
				_ymd := dValue:_ymd

			/// Construct a date from a string using the specified Date Format.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(strDate AS STRING, strFormat AS STRING)
				LOCAL dValue := CToD(strDate,strFormat) AS DATE
                _year := _month := _day := 0
				_ymd := dValue:_ymd

			/// Construct a date from year, month, day
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(year AS INT, month AS INT, day AS INT)
                _ymd := _year := _month := _day := 0
                IF year != 0 .AND. month != 0 .AND. day != 0
				    TRY
					    // this may throw an exception when the combination is not valid
                        IF (year == 1 .AND. month == 1 .AND. day == 1)
                            // this is DateTime.Mindate, but a valid date in VO
					        _year  := 1
					        _month := 1
					        _day   := 1
                        ELSE
  				            VAR dt := System.DateTime{year, month, day}
					        _year  := (WORD) dt:Year
					        _month := (BYTE) dt:Month
					        _day   := (BYTE) dt:Day
                        ENDIF
				    CATCH
        				_ymd := 0 // null_date
					    NOP
                     END TRY
                ELSE
				    _ymd := 0 // null_date
                ENDIF
				RETURN

			/// Construct a date from year, month, day
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(year AS DWORD, month AS DWORD, day AS DWORD)
				// Chain to Int constructor
				SELF( (INT) year, (INT) month, (INT) day)
				RETURN

		#endregion

		#region methods
			/// <inheritdoc />
			METHOD CompareTo(o AS OBJECT) AS LONG
				VAR rhs := (DATE)o
				RETURN _ymd:CompareTo(rhs:_ymd)

			/// <inheritdoc />
			METHOD CompareTo(rhs AS DATE) AS LONG
				RETURN _ymd:CompareTo(rhs:_ymd)

			/// <inheritdoc />
			OVERRIDE METHOD GetHashCode() AS LONG
				RETURN _ymd:GetHashCode()

			/// <inheritdoc />
			METHOD GetTypeCode() AS System.TypeCode
				RETURN TypeCode.DateTime
		#endregion
		#region Operators
			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR ++(lhs AS DATE) AS DATE
				RETURN lhs:Add(1)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS USUAL) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS REAL8) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS LONG) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR +(lhs AS DATE, days AS INT64) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR +(lhs AS DATE, ts AS System.TimeSpan) AS DATE
				RETURN lhs:Add(ts)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS DWORD) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS UINT64) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR --(lhs AS DATE) AS DATE
				RETURN lhs:Subtract(1)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, rhs AS DATE) AS LONG
				RETURN lhs:Subtract(rhs)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS USUAL) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS REAL8) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS LONG) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS INT64) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, ts AS System.TimeSpan) AS DATE
				RETURN lhs:Subtract(ts)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS DWORD) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS UINT64) AS DATE
				RETURN lhs:Subtract(days)

		#endregion
		#region Equality Operators

			/// <inheritdoc />
			METHOD Equals(lhs AS DATE) AS LOGIC
				RETURN _ymd == lhs:_ymd

			/// <inheritdoc />
			OVERRIDE METHOD Equals(o AS OBJECT) AS LOGIC
				IF o != NULL
					IF o:getType() == TYPEOF(DATE)
						RETURN SELF:Equals(  (DATE) o)
					ELSEIF o:getType() == TYPEOF(System.DateTime)
						RETURN SELF:Equals( DATE{ (System.DateTime) o})
					ENDIF
				ENDIF
			RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR ==(lhs AS DATE, rhs AS DATE) AS LOGIC
				RETURN (lhs:_ymd == rhs:_ymd)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR !=(lhs AS DATE, rhs AS DATE) AS LOGIC
				RETURN (lhs:_ymd != rhs:_ymd)

		#endregion
		#region Implicit and Explicit converters

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(dvalue AS DATE) AS DWORD
				// convert to julian date like vo
				// # of days since 1-1-1901 + 2415386
				LOCAL nDays AS DWORD
				nDays := (DWORD) (dValue:@@Value - _dtCalc):Days + CLIPPER_MIN_DATE
				RETURN nDays

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(dValue AS DATE) AS INT
				LOCAL nDays AS LONG
				nDays := (INT) ((dValue:@@Value - _dtCalc):Days + CLIPPER_MIN_DATE)
				RETURN nDays

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(dw AS DWORD ) AS DATE
				// convert julian date to our date
				LOCAL result := _NULL_DATE AS DATE
				IF dw >= CLIPPER_MIN_DATE .AND. dw <= CLIPPER_MAX_DATE
					LOCAL dt AS DateTime
					dt := _dtCalc:AddDays ( (INT) dw -CLIPPER_MIN_DATE)
					result := DATE{dt}
				ENDIF
				RETURN result

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(i AS INT) AS DATE
				LOCAL result := _NULL_DATE AS DATE
				IF i >= CLIPPER_MIN_DATE .AND. i <= CLIPPER_MAX_DATE
					LOCAL dt AS DateTime
					dt := _dtCalc:AddDays ( i - CLIPPER_MIN_DATE)
					result := DATE{dt}
				ENDIF
				RETURN result

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR IMPLICIT(v AS System.DateTime) AS DATE
				RETURN DATE{v}

			/// <exclude />
			METHOD ToDateTime() AS System.DateTime
				RETURN SELF:@@Value

			/// <exclude />
			METHOD FromDateTime(dtvalue AS System.DateTime) AS DATE
				RETURN DATE{dtvalue}

		#endregion
		#region Comparison Operators
			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR >(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for > comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN FALSE
				ELSEIF lhs:_year > rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month > rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day > rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR >=(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for > comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN TRUE
				ELSEIF lhs:_year > rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month > rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day >= rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR IMPLICIT(v AS DATE) AS System.DateTime
				RETURN v:@@Value

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR <(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for < comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN FALSE
				ELSEIF lhs:_year < rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month < rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day < rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR <=(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for < comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN TRUE
				ELSEIF lhs:_year < rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month < rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day <= rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE
		#endregion

		#region ADD and Subtract Methods
			/// <exclude />
			METHOD Add(days AS USUAL) AS DATE
				IF days:IsInteger
					RETURN SELF:Add( (INT64) days)
				ELSEIF days:IsNumeric
					 RETURN SELF:Add( (REAL8) days)
				ELSE
					THROW Error.ArgumentError(__ENTITY__,NAMEOF(days),1, "Incompatible argument for Date:Add()",{days})
				ENDIF
			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS REAL8) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}
			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS LONG) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}
			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS INT64) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(span AS System.TimeSpan) AS DATE
				VAR res := SELF:@@Value:Add(span)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS DWORD) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS UINT64) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(lhs AS DATE) AS LONG
				LOCAL span AS System.TimeSpan
				span := (System.TimeSpan)(SELF:@@Value - lhs:@@Value)
				RETURN span:Days

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS USUAL) AS DATE
				IF days:IsInteger
					RETURN SELF:Add( -(INT64) days)
				ELSEIF days:IsNumeric
					 RETURN SELF:Add( -(REAL8) days)
				ELSE
					THROW Error.ArgumentError(__ENTITY__,NAMEOF(days), 1, "Incompatible argument for Date:Subtract()", {days})
				ENDIF

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS REAL8) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS LONG) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS INT64) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(ts AS System.TimeSpan) AS DATE
				RETURN SELF:Add(-ts)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS DWORD) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS UINT64) AS DATE
				RETURN SELF:Add(-(INT64)days)
		#endregion

		#region IConvertable
			// forward most methods to the DateTime class so there will
			// be a proper (localized) error message
			/// <inheritdoc />
			METHOD IConvertible.ToBoolean(provider AS System.IFormatProvider) AS LOGIC
				RETURN ((IConvertible)@@Value):ToBoolean(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToByte(provider AS System.IFormatProvider) AS BYTE
				RETURN ((IConvertible)@@Value):ToByte(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToChar(provider AS System.IFormatProvider) AS CHAR
				RETURN ((IConvertible)@@Value):ToChar(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToDateTime(provider AS System.IFormatProvider) AS System.DateTime
				RETURN @@Value

			/// <inheritdoc />
			METHOD IConvertible.ToDecimal(provider AS System.IFormatProvider) AS Decimal
				RETURN ((IConvertible)@@Value):ToDecimal(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToDouble(provider AS System.IFormatProvider) AS REAL8
				RETURN ((IConvertible)@@Value):ToDouble(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToInt16(provider AS System.IFormatProvider) AS SHORT
				RETURN ((IConvertible)@@Value):ToInt16(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToInt32(provider AS System.IFormatProvider) AS LONG
				RETURN ((IConvertible)@@Value):ToInt32(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToInt64(provider AS System.IFormatProvider) AS INT64
				RETURN ((IConvertible)@@Value):ToInt64(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToSByte(provider AS System.IFormatProvider) AS SByte
				RETURN ((IConvertible)@@Value):ToSByte(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToSingle(provider AS System.IFormatProvider) AS REAL4
				RETURN ((IConvertible)@@Value):ToSingle(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToType(conversionType AS System.Type, provider AS System.IFormatProvider) AS OBJECT
				IF conversionType == TYPEOF(DATE)
					RETURN SELF
				ELSEIF conversionType == TYPEOF(System.DateTime)
					RETURN SELF:@@Value
				ENDIF
				RETURN ((IConvertible)@@Value):ToType(conversionType, provider)

			/// <inheritdoc />
			METHOD IConvertible.ToUInt16(provider AS System.IFormatProvider) AS WORD
				RETURN ((IConvertible)@@Value):ToUInt16(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToUInt32(provider AS System.IFormatProvider) AS DWORD
				RETURN ((IConvertible)@@Value):ToUInt32(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToUInt64(provider AS System.IFormatProvider) AS UINT64
				RETURN ((IConvertible)@@Value):ToUInt64(provider)
		#endregion

		#region ToString()
			// Use DateTime ToString() methods as helpers
			/// <inheritdoc />
			OVERRIDE METHOD ToString() AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
			RETURN DToC(SELF)
			/// <inheritdoc />
			METHOD ToString(provider AS System.IFormatProvider) AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
				RETURN @@Value:ToString(provider)
			/// <inheritdoc cref="M:System.DateTime.ToString(System.String)"/>
			METHOD ToString(s AS STRING) AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
				RETURN @@Value:ToString(s)
			/// <inheritdoc />
			METHOD ToString(s AS STRING, fp AS System.IFormatProvider) AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
				IF (s == NULL)
					s := XSharp.RuntimeState.DateFormat
				ENDIF
				RETURN @@Value:ToString(s, fp)
		#endregion
		#region properties

			/// <inheritdoc />
			PROPERTY IsEmpty AS LOGIC
				GET
					RETURN _ymd == 0
				END GET
			END PROPERTY
			/// <inheritdoc />
			PROPERTY Month	AS INT GET _month
			/// <inheritdoc />
			PROPERTY Year	AS INT GET _year
			/// <inheritdoc />
			PROPERTY Day	AS INT GET _day
			// Next properties for easy access in right type
			INTERNAL PROPERTY DYear		AS DWORD GET _year
			INTERNAL PROPERTY DMonth	AS DWORD GET _month
			INTERNAL PROPERTY DDay		AS DWORD GET _day

			INTERNAL CLASS DateDebugView
				PRIVATE _value AS DATE
				PUBLIC CONSTRUCTOR (d AS DATE)
					_value := d

				PUBLIC PROPERTY Year	AS INT GET _value:Year
				PUBLIC PROPERTY Month	AS INT GET _value:Month
				PUBLIC PROPERTY Day		AS INT GET _value:Day

			END CLASS

		#endregion

		#region STATIC Properties

			/// <exclude />
			STATIC METHOD NullDate AS DATE
				RETURN  _NULL_DATE

		#endregion
	END STRUCTURE
END NAMESPACE

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
USING System
USING System.Runtime.Serialization
USING System.Globalization
USING System.Runtime.InteropServices
USING System.Runtime.CompilerServices
USING XSharp
USING System.Diagnostics
BEGIN NAMESPACE XSharp
	/// Internal type that implements the VO Compatible DATE type

	/// This type has many operators and implicit converters that normally are never directly called from user code.
	/// It holds year, month, day in 32 bits. For date calculations it uses the System.DateTime calculation logic.
	/// There are implicit converters between Date and DateTime.
	///
	/// <seealso cref="T:XSharp.IDate"/>
	/// <seealso cref="T:XSharp.RDD.DbDate"/>
	[DebuggerDisplay("{ToString(),nq}", Type := "DATE" )];
	[DebuggerTypeProxy(TYPEOF(DateDebugView))];
	[StructLayout(LayoutKind.Explicit,Pack := 1)];
	PUBLIC STRUCTURE __Date IMPLEMENTS System.IComparable, ;
		System.IFormattable, ;
		System.IConvertible, ;
		IDate, ;
		IComparable<__Date>, ;
		IEquatable<__Date>
		// This structure uses an explicit layout to map
		// year, month and date into 32 bits
		// the _ymd field is for convenience, so we can do a single numeric comparison
		// to determine equality or relative comparisons in stead of doing 3 comparisons
		// for date calculation we use the Value PROPERTY which returns a System.DateTime type
		// Note that the Vulcan type uses a datetime which takes 8 bytes. We only use 4 bytes
		#region fields
			[FieldOffSet(00)] PRIVATE _ymd   AS System.Int32
			[FieldOffSet(00)] PRIVATE _year  AS System.UInt16
			[FieldOffSet(02)] PRIVATE _month AS System.Byte
			[FieldOffSet(03)] PRIVATE _day   AS System.Byte
		#endregion

		#region STATIC fields
			/// <exclude />
			STATIC INITONLY PUBLIC  _NULL_DATE AS DATE
			/// <exclude />
			CONST  CLIPPER_MIN_DATE := 2415386U AS DWORD	// 1901-01-01
			/// <exclude />
			CONST  CLIPPER_MAX_DATE := 4606840U AS DWORD	// 7900-12-31
			/// <exclude />
			STATIC INITONLY _dtCalc AS Datetime

		#endregion

		#region datetime conversions
            /// Return DATE value as DateTime.
			PUBLIC PROPERTY @@Value AS System.DateTime
				GET
					IF (_ymd == 0)
						RETURN System.DateTime.MinValue
					ENDIF
					RETURN System.DateTime{_year, _month, _day}
				END GET
				SET
				    IF VALUE != DateTime.MinValue
					    _year  := (WORD) VALUE:Year
					    _month := (BYTE) VALUE:Month
					    _day   := (BYTE) VALUE:Day
				    ELSE
					    _ymd := 0
				    ENDIF
				END SET
			END PROPERTY
		#endregion

		#region constructors
			STATIC CONSTRUCTOR()
				_NULL_DATE  := DATE{}
				_dtCalc     := DateTime{1901,1,1}
				RETURN
			/// Construct a date from a DateTime value.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(dt AS System.DateTime)
                _ymd := _year := _month := _day := 0
                IF dt != DateTime.MinValue
				    _year  := (WORD) dt:Year
				    _month := (BYTE) dt:Month
				    _day   := (BYTE) dt:Day
                ELSE
                    _ymd := 0
                ENDIF
				RETURN

			/// Construct a date from another IDate type.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(d AS IDate)
                _ymd := 0
				_year  := (WORD) d:Year
				_month := (BYTE) d:Month
				_day   := (BYTE) d:Day
				RETURN

			/// Construct a date from a number of Ticks.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(ticks AS INT64)
				SELF(System.DateTime{ticks})
				RETURN

			/// Construct a date from a string. This assumes the string is in current Date format
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(strDate AS STRING)
				LOCAL dValue := CToD(strDate) AS DATE
                _year := _month := _day := 0
				_ymd := dValue:_ymd

			/// Construct a date from a string using the specified Date Format.
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(strDate AS STRING, strFormat AS STRING)
				LOCAL dValue := CToD(strDate,strFormat) AS DATE
                _year := _month := _day := 0
				_ymd := dValue:_ymd

			/// Construct a date from year, month, day
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(year AS INT, month AS INT, day AS INT)
                _ymd := _year := _month := _day := 0
                IF year != 0 .AND. month != 0 .AND. day != 0
				    TRY
					    // this may throw an exception when the combination is not valid
                        IF (year == 1 .AND. month == 1 .AND. day == 1)
                            // this is DateTime.Mindate, but a valid date in VO
					        _year  := 1
					        _month := 1
					        _day   := 1
                        ELSE
  				            VAR dt := System.DateTime{year, month, day}
					        _year  := (WORD) dt:Year
					        _month := (BYTE) dt:Month
					        _day   := (BYTE) dt:Day
                        ENDIF
				    CATCH
        				_ymd := 0 // null_date
					    NOP
                     END TRY
                ELSE
				    _ymd := 0 // null_date
                ENDIF
				RETURN

			/// Construct a date from year, month, day
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			CONSTRUCTOR(year AS DWORD, month AS DWORD, day AS DWORD)
				// Chain to Int constructor
				SELF( (INT) year, (INT) month, (INT) day)
				RETURN

		#endregion

		#region methods
			/// <inheritdoc />
			METHOD CompareTo(o AS OBJECT) AS LONG
				VAR rhs := (DATE)o
				RETURN _ymd:CompareTo(rhs:_ymd)

			/// <inheritdoc />
			METHOD CompareTo(rhs AS DATE) AS LONG
				RETURN _ymd:CompareTo(rhs:_ymd)

			/// <inheritdoc />
			OVERRIDE METHOD GetHashCode() AS LONG
				RETURN _ymd:GetHashCode()

			/// <inheritdoc />
			METHOD GetTypeCode() AS System.TypeCode
				RETURN TypeCode.DateTime
		#endregion
		#region Operators
			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR ++(lhs AS DATE) AS DATE
				RETURN lhs:Add(1)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS USUAL) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS REAL8) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS LONG) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR +(lhs AS DATE, days AS INT64) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR +(lhs AS DATE, ts AS System.TimeSpan) AS DATE
				RETURN lhs:Add(ts)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS DWORD) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR +(lhs AS DATE, days AS UINT64) AS DATE
				RETURN lhs:Add(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR --(lhs AS DATE) AS DATE
				RETURN lhs:Subtract(1)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, rhs AS DATE) AS LONG
				RETURN lhs:Subtract(rhs)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS USUAL) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS REAL8) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS LONG) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS INT64) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, ts AS System.TimeSpan) AS DATE
				RETURN lhs:Subtract(ts)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS DWORD) AS DATE
				RETURN lhs:Subtract(days)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			STATIC OPERATOR -(lhs AS DATE, days AS UINT64) AS DATE
				RETURN lhs:Subtract(days)

		#endregion
		#region Equality Operators

			/// <inheritdoc />
			METHOD Equals(lhs AS DATE) AS LOGIC
				RETURN _ymd == lhs:_ymd

			/// <inheritdoc />
			OVERRIDE METHOD Equals(o AS OBJECT) AS LOGIC
				IF o != NULL
					IF o:getType() == TYPEOF(DATE)
						RETURN SELF:Equals(  (DATE) o)
					ELSEIF o:getType() == TYPEOF(System.DateTime)
						RETURN SELF:Equals( DATE{ (System.DateTime) o})
					ENDIF
				ENDIF
			RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR ==(lhs AS DATE, rhs AS DATE) AS LOGIC
				RETURN (lhs:_ymd == rhs:_ymd)

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR !=(lhs AS DATE, rhs AS DATE) AS LOGIC
				RETURN (lhs:_ymd != rhs:_ymd)

		#endregion
		#region Implicit and Explicit converters

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(dvalue AS DATE) AS DWORD
				// convert to julian date like vo
				// # of days since 1-1-1901 + 2415386
				LOCAL nDays AS DWORD
				nDays := (DWORD) (dValue:@@Value - _dtCalc):Days + CLIPPER_MIN_DATE
				RETURN nDays

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(dValue AS DATE) AS INT
				LOCAL nDays AS LONG
				nDays := (INT) ((dValue:@@Value - _dtCalc):Days + CLIPPER_MIN_DATE)
				RETURN nDays

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(dw AS DWORD ) AS DATE
				// convert julian date to our date
				LOCAL result := _NULL_DATE AS DATE
				IF dw >= CLIPPER_MIN_DATE .AND. dw <= CLIPPER_MAX_DATE
					LOCAL dt AS DateTime
					dt := _dtCalc:AddDays ( (INT) dw -CLIPPER_MIN_DATE)
					result := DATE{dt}
				ENDIF
				RETURN result

			/// <include file="RTComments.xml" path="Comments/Converter/*" />
			STATIC OPERATOR EXPLICIT(i AS INT) AS DATE
				LOCAL result := _NULL_DATE AS DATE
				IF i >= CLIPPER_MIN_DATE .AND. i <= CLIPPER_MAX_DATE
					LOCAL dt AS DateTime
					dt := _dtCalc:AddDays ( i - CLIPPER_MIN_DATE)
					result := DATE{dt}
				ENDIF
				RETURN result

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR IMPLICIT(v AS System.DateTime) AS DATE
				RETURN DATE{v}

			/// <exclude />
			METHOD ToDateTime() AS System.DateTime
				RETURN SELF:@@Value

			/// <exclude />
			METHOD FromDateTime(dtvalue AS System.DateTime) AS DATE
				RETURN DATE{dtvalue}

		#endregion
		#region Comparison Operators
			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR >(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for > comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN FALSE
				ELSEIF lhs:_year > rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month > rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day > rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR >=(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for > comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN TRUE
				ELSEIF lhs:_year > rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month > rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day >= rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR IMPLICIT(v AS DATE) AS System.DateTime
				RETURN v:@@Value

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR <(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for < comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN FALSE
				ELSEIF lhs:_year < rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month < rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day < rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE

			/// <include file="RTComments.xml" path="Comments/Operator/*" />
			STATIC OPERATOR <=(lhs AS DATE, rhs AS DATE) AS LOGIC
				// note: cannot use _ymd for < comparison because that would depend
				//       on the processor layout
				IF lhs:_ymd == rhs:_ymd
					RETURN TRUE
				ELSEIF lhs:_year < rhs:_year
					RETURN TRUE
				ELSEIF lhs:_year == rhs:_year
					IF lhs:_month < rhs:_month
						RETURN TRUE
					ELSEIF lhs:_month == rhs:_month .AND. lhs:_day <= rhs:_day
						RETURN TRUE
					ENDIF
				ENDIF
				RETURN FALSE
		#endregion

		#region ADD and Subtract Methods
			/// <exclude />
			METHOD Add(days AS USUAL) AS DATE
				IF days:IsLong
					RETURN SELF:Add( (LONG) days)
				ELSEIF days:IsFloat
					 RETURN SELF:Add( (REAL8) days)
				ELSE
					THROW Error.ArgumentError(__ENTITY__,NAMEOF(days), "Incompatible argument for Date:Add()")
				ENDIF
			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS REAL8) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}
			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS LONG) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}
			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS INT64) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(span AS System.TimeSpan) AS DATE
				VAR res := SELF:@@Value:Add(span)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS DWORD) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Add(days AS UINT64) AS DATE
				VAR res := SELF:@@Value:AddDays(days)
				RETURN DATE{res}

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(lhs AS DATE) AS LONG
				LOCAL span AS System.TimeSpan
				span := (System.TimeSpan)(SELF:@@Value - lhs:@@Value)
				RETURN span:Days

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS USUAL) AS DATE
				IF days:IsLong
					RETURN SELF:Add( -(LONG) days)
				ELSEIF days:IsFloat
					 RETURN SELF:Add( -(REAL8) days)
				ELSE
					THROW Error.ArgumentError(__ENTITY__,NAMEOF(days), "Incompatible argument for Date:Subtract()")
				ENDIF

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS REAL8) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS LONG) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS INT64) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(ts AS System.TimeSpan) AS DATE
				RETURN SELF:Add(-ts)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS DWORD) AS DATE
				RETURN SELF:Add(-days)

			/// <exclude />
            [MethodImpl(MethodImplOptions.AggressiveInlining)];
			METHOD Subtract(days AS UINT64) AS DATE
				RETURN SELF:Add(-(INT64)days)
		#endregion

		#region IConvertable
			// forward most methods to the DateTime class so there will
			// be a proper (localized) error message
			/// <inheritdoc />
			METHOD IConvertible.ToBoolean(provider AS System.IFormatProvider) AS LOGIC
				RETURN ((IConvertible)@@Value):ToBoolean(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToByte(provider AS System.IFormatProvider) AS BYTE
				RETURN ((IConvertible)@@Value):ToByte(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToChar(provider AS System.IFormatProvider) AS CHAR
				RETURN ((IConvertible)@@Value):ToChar(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToDateTime(provider AS System.IFormatProvider) AS System.DateTime
				RETURN @@Value

			/// <inheritdoc />
			METHOD IConvertible.ToDecimal(provider AS System.IFormatProvider) AS Decimal
				RETURN ((IConvertible)@@Value):ToDecimal(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToDouble(provider AS System.IFormatProvider) AS REAL8
				RETURN ((IConvertible)@@Value):ToDouble(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToInt16(provider AS System.IFormatProvider) AS SHORT
				RETURN ((IConvertible)@@Value):ToInt16(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToInt32(provider AS System.IFormatProvider) AS LONG
				RETURN ((IConvertible)@@Value):ToInt32(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToInt64(provider AS System.IFormatProvider) AS INT64
				RETURN ((IConvertible)@@Value):ToInt64(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToSByte(provider AS System.IFormatProvider) AS SByte
				RETURN ((IConvertible)@@Value):ToSByte(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToSingle(provider AS System.IFormatProvider) AS REAL4
				RETURN ((IConvertible)@@Value):ToSingle(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToType(conversionType AS System.Type, provider AS System.IFormatProvider) AS OBJECT
				IF conversionType == TYPEOF(DATE)
					RETURN SELF
				ELSEIF conversionType == TYPEOF(System.DateTime)
					RETURN SELF:@@Value
				ENDIF
				RETURN ((IConvertible)@@Value):ToType(conversionType, provider)

			/// <inheritdoc />
			METHOD IConvertible.ToUInt16(provider AS System.IFormatProvider) AS WORD
				RETURN ((IConvertible)@@Value):ToUInt16(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToUInt32(provider AS System.IFormatProvider) AS DWORD
				RETURN ((IConvertible)@@Value):ToUInt32(provider)

			/// <inheritdoc />
			METHOD IConvertible.ToUInt64(provider AS System.IFormatProvider) AS UINT64
				RETURN ((IConvertible)@@Value):ToUInt64(provider)
		#endregion

		#region ToString()
			// Use DateTime ToString() methods as helpers
			/// <inheritdoc />
			OVERRIDE METHOD ToString() AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
			RETURN DToC(SELF)
			/// <inheritdoc />
			METHOD ToString(provider AS System.IFormatProvider) AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
				RETURN @@Value:ToString(provider)
			/// <inheritdoc cref="M:System.DateTime.ToString(System.String)"/>
			METHOD ToString(s AS STRING) AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
				RETURN @@Value:ToString(s)
			/// <inheritdoc />
			METHOD ToString(s AS STRING, fp AS System.IFormatProvider) AS STRING
				IF (_ymd == 0)
					RETURN RuntimeState.NullDateString
				ENDIF
				IF (s == NULL)
					s := XSharp.RuntimeState.DateFormat
				ENDIF
				RETURN @@Value:ToString(s, fp)
		#endregion
		#region properties

			/// <inheritdoc />
			PROPERTY IsEmpty AS LOGIC
				GET
					RETURN _ymd == 0
				END GET
			END PROPERTY
			/// <inheritdoc />
			PROPERTY Month	AS INT GET _month
			/// <inheritdoc />
			PROPERTY Year	AS INT GET _year
			/// <inheritdoc />
			PROPERTY Day	AS INT GET _day
			// Next properties for easy access in right type
			INTERNAL PROPERTY DYear		AS DWORD GET _year
			INTERNAL PROPERTY DMonth	AS DWORD GET _month
			INTERNAL PROPERTY DDay		AS DWORD GET _day

			INTERNAL CLASS DateDebugView
				PRIVATE _value AS DATE
				PUBLIC CONSTRUCTOR (d AS DATE)
					_value := d

				PUBLIC PROPERTY Year	AS INT GET _value:Year
				PUBLIC PROPERTY Month	AS INT GET _value:Month
				PUBLIC PROPERTY Day		AS INT GET _value:Day

			END CLASS

		#endregion

		#region STATIC Properties

			/// <exclude />
			STATIC METHOD NullDate AS DATE
				RETURN  _NULL_DATE

		#endregion
	END STRUCTURE
END NAMESPACE


codegen/QtWebEngineWidgets: updated

codegen/QtWebEngineWidgets: updated

Modified:
codegen/QtWebEngineWidgets/QWebEnginePage.prg

%%
%% Qt5xHb - Bindings libraries for Harbour/xHarbour and Qt Framework 5
%%
%% Copyright (C) 2018 Marcos Antonio Gambeta <marcosgambeta AT outlook DOT com>
%%

$header

#include "hbclass.ch"

$addRequests

$beginClassFrom=QObject

$addMethods

$addSignals

$endClass

$destructor

#pragma BEGINDUMP

$includes=5,4,0

#include <QAction>
#include <QMenu>

$prototype=explicit QWebEnginePage(QObject *parent = 0)
$constructor=5,4,0|new|QObject *=0

$deleteMethod=5,4,0

$prototype=QWebEngineHistory *history() const
$method=5,4,0|QWebEngineHistory *|history|

$prototype=QWidget *view() const
$method=5,4,0|QWidget *|view|

$prototype=void setView(QWidget *view)
$method=5,4,0|void|setView|QWidget *

$prototype=bool hasSelection() const
$method=5,4,0|bool|hasSelection|

$prototype=QString selectedText() const
$method=5,4,0|QString|selectedText|

$prototype=QAction *action(WebAction action) const
$method=5,4,0|QAction *|action|QWebEnginePage::WebAction

$prototype=virtual void triggerAction(WebAction action, bool checked = false)
$virtualMethod=5,4,0|void|triggerAction|QWebEnginePage::WebAction,bool=false

$prototype=virtual bool event(QEvent*)
$virtualMethod=5,4,0|bool|event|QEvent *

$prototype=void findText(const QString &subString, FindFlags options = 0, const QWebEngineCallback<bool> &resultCallback = QWebEngineCallback<bool>())
%% TODO: implementar
%% $method=5,4,0|void|findText|const QString &,QWebEnginePage::FindFlags=0,const QWebEngineCallback<bool> &=QWebEngineCallback<bool>()

$prototype=QMenu *createStandardContextMenu()
$method=5,4,0|QMenu *|createStandardContextMenu|

$prototype=void setFeaturePermission(const QUrl &securityOrigin, Feature feature, PermissionPolicy policy)
$method=5,4,0|void|setFeaturePermission|const QUrl &,QWebEnginePage::Feature,QWebEnginePage::PermissionPolicy

$prototype=void load(const QUrl &url)
$method=5,4,0|void|load|const QUrl &

$prototype=void setHtml(const QString &html, const QUrl &baseUrl = QUrl())
$method=5,4,0|void|setHtml|const QString &,const QUrl &=QUrl()

$prototype=void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl())
$method=5,4,0|void|setContent|const QByteArray &,const QString &=QString(),const QUrl &=QUrl()

$prototype=void toHtml(const QWebEngineCallback<const QString &> &resultCallback) const
%% TODO: implementar
%% $method=5,4,0|void|toHtml|const QWebEngineCallback<const QString &> &

$prototype=void toPlainText(const QWebEngineCallback<const QString &> &resultCallback) const
%% TODO: implementar
%% $method=5,4,0|void|toPlainText|const QWebEngineCallback<const QString &> &

$prototype=QString title() const
$method=5,4,0|QString|title|

$prototype=QUrl url() const
$method=5,4,0|QUrl|url|

$prototype=void setUrl(const QUrl &url)
$method=5,4,0|void|setUrl|const QUrl &

$prototype=QUrl requestedUrl() const
$method=5,4,0|QUrl|requestedUrl|

$prototype=QUrl iconUrl() const
$method=5,4,0|QUrl|iconUrl|

$prototype=qreal zoomFactor() const
$method=5,4,0|qreal|zoomFactor|

$prototype=void setZoomFactor(qreal factor)
$method=5,4,0|void|setZoomFactor|qreal

$prototype=void runJavaScript(const QString& scriptSource)
$internalMethod=5,4,0|void|runJavaScript,runJavaScript1|const QString &

$prototype=void runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback)
%% TODO: implementar
%% $internalMethod=5,4,0|void|runJavaScript,runJavaScript2|const QString &,const QWebEngineCallback<const QVariant &> &

//[1]void runJavaScript(const QString& scriptSource)
//[2]void runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback)

HB_FUNC( QWEBENGINEPAGE_RUNJAVASCRIPT )
{
  if( ISNUMPAR(1) && ISCHAR(1) )
  {
    QWebEnginePage_runJavaScript1();
  }
%%  else if( ISNUMPAR(2) && ISCHAR(1) && ISARRAY(2) )
%%  {
%%    QWebEnginePage_runJavaScript2();
%%  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}
$addMethod=runJavaScript

$prototype=QWebEngineSettings *settings() const
$method=5,4,0|QWebEngineSettings *|settings|

$beginSignals
$signal=5,4,0|loadStarted()
$signal=5,4,0|loadProgress(int)
$signal=5,4,0|loadFinished(bool)
$signal=5,4,0|linkHovered(QString)
$signal=5,4,0|selectionChanged()
$signal=5,4,0|geometryChangeRequested(QRect)
$signal=5,4,0|windowCloseRequested()
$signal=5,4,0|featurePermissionRequested(QUrl,QWebEnginePage::Feature)
$signal=5,4,0|featurePermissionRequestCanceled(QUrl,QWebEnginePage::Feature)
$signal=5,4,0|authenticationRequired(QUrl,QAuthenticator*)
$signal=5,4,0|proxyAuthenticationRequired(QUrl,QAuthenticator*,QString)
$signal=5,4,0|titleChanged(QString)
$signal=5,4,0|urlChanged(QUrl)
$signal=5,4,0|iconUrlChanged(QUrl)
$endSignals

#pragma ENDDUMP

%%
%% Qt5xHb - Bindings libraries for Harbour/xHarbour and Qt Framework 5
%%
%% Copyright (C) 2018 Marcos Antonio Gambeta <marcosgambeta AT outlook DOT com>
%%

$header

#include "hbclass.ch"

$addRequests

$beginClassFrom=QObject

$addMethods

$addSignals

$endClass

$destructor

#pragma BEGINDUMP

$includes=5,4,0

#include <QAction>
#include <QMenu>

$prototype=explicit QWebEnginePage(QObject *parent = 0)
$constructor=5,4,0|new|QObject *=0

$deleteMethod=5,4,0

$prototype=QWebEngineHistory *history() const
$method=5,4,0|QWebEngineHistory *|history|

$prototype=QWidget *view() const
$method=5,4,0|QWidget *|view|

$prototype=void setView(QWidget *view)
$method=5,4,0|void|setView|QWidget *

$prototype=bool hasSelection() const
$method=5,4,0|bool|hasSelection|

$prototype=QString selectedText() const
$method=5,4,0|QString|selectedText|

$prototype=QAction *action(WebAction action) const
$method=5,4,0|QAction *|action|QWebEnginePage::WebAction

$prototype=virtual void triggerAction(WebAction action, bool checked = false)
$virtualMethod=5,4,0|void|triggerAction|QWebEnginePage::WebAction,bool=false

$prototype=virtual bool event(QEvent*)
$virtualMethod=5,4,0|bool|event|QEvent *

$prototype=void findText(const QString &subString, FindFlags options = 0, const QWebEngineCallback<bool> &resultCallback = QWebEngineCallback<bool>())
%% TODO: implementar
%% $method=5,4,0|void|findText|const QString &,QWebEnginePage::FindFlags=0,const QWebEngineCallback<bool> &=QWebEngineCallback<bool>()

$prototype=QMenu *createStandardContextMenu()
$method=5,4,0|QMenu *|createStandardContextMenu|

$prototype=void setFeaturePermission(const QUrl &securityOrigin, Feature feature, PermissionPolicy policy)
$method=5,4,0|void|setFeaturePermission|const QUrl &,QWebEnginePage::Feature,QWebEnginePage::PermissionPolicy

$prototype=void load(const QUrl &url)
$method=5,4,0|void|load|const QUrl &

$prototype=void setHtml(const QString &html, const QUrl &baseUrl = QUrl())
$method=5,4,0|void|setHtml|const QString &,const QUrl &=QUrl()

$prototype=void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl())
$method=5,4,0|void|setContent|const QByteArray &,const QString &=QString(),const QUrl &=QUrl()

$prototype=void toHtml(const QWebEngineCallback<const QString &> &resultCallback) const
%% TODO: implementar
%% $method=5,4,0|void|toHtml|const QWebEngineCallback<const QString &> &

$prototype=void toPlainText(const QWebEngineCallback<const QString &> &resultCallback) const
%% TODO: implementar
%% $method=5,4,0|void|toPlainText|const QWebEngineCallback<const QString &> &

$prototype=QString title() const
$method=5,4,0|QString|title|

$prototype=QUrl url() const
$method=5,4,0|QUrl|url|

$prototype=void setUrl(const QUrl &url)
$method=5,4,0|void|setUrl|const QUrl &

$prototype=QUrl requestedUrl() const
$method=5,4,0|QUrl|requestedUrl|

$prototype=QUrl iconUrl() const
$method=5,4,0|QUrl|iconUrl|

$prototype=qreal zoomFactor() const
$method=5,4,0|qreal|zoomFactor|

$prototype=void setZoomFactor(qreal factor)
$method=5,4,0|void|setZoomFactor|qreal

$prototype=void runJavaScript(const QString& scriptSource)
$internalMethod=5,4,0|void|runJavaScript,runJavaScript1|const QString &

$prototype=void runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback)
%% TODO: implementar
%% $internalMethod=5,4,0|void|runJavaScript,runJavaScript2|const QString &,const QWebEngineCallback<const QVariant &> &

//[1]void runJavaScript(const QString& scriptSource)
//[2]void runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback)

HB_FUNC( QWEBENGINEPAGE_RUNJAVASCRIPT )
{
  if( ISNUMPAR(1) && ISCHAR(1) )
  {
    QWebEnginePage_runJavaScript1();
  }
%%  else if( ISNUMPAR(2) && ISCHAR(1) && ISARRAY(2) )
%%  {
%%    QWebEnginePage_runJavaScript2();
%%  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

$prototype=QWebEngineSettings *settings() const
$method=5,4,0|QWebEngineSettings *|settings|

$beginSignals
$signal=5,4,0|loadStarted()
$signal=5,4,0|loadProgress(int)
$signal=5,4,0|loadFinished(bool)
$signal=5,4,0|linkHovered(QString)
$signal=5,4,0|selectionChanged()
$signal=5,4,0|geometryChangeRequested(QRect)
$signal=5,4,0|windowCloseRequested()
$signal=5,4,0|featurePermissionRequested(QUrl,QWebEnginePage::Feature)
$signal=5,4,0|featurePermissionRequestCanceled(QUrl,QWebEnginePage::Feature)
$signal=5,4,0|authenticationRequired(QUrl,QAuthenticator*)
$signal=5,4,0|proxyAuthenticationRequired(QUrl,QAuthenticator*,QString)
$signal=5,4,0|titleChanged(QString)
$signal=5,4,0|urlChanged(QUrl)
$signal=5,4,0|iconUrlChanged(QUrl)
$endSignals

#pragma ENDDUMP