[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Here is a Harbour (xBase/Clipper) implementation:

Harbour contribution module 'hbtest' (Test framework utilities): contrib/hbtest/core.prg. Provides functions: ErrorMessage, XToStr, __StrToExp, __ByteIsDisplayable, __ByteEscape. Contains procedures: hbtest_Setup, hbtest_Call. This file provides utility functions

[Assistant]
#include "error.ch"

#define TEST_RESULT_COL1_WIDTH  1
#define TEST_RESULT_COL2_WIDTH  11
#define TEST_RESULT_COL3_WIDTH  44
#define TEST_RESULT_COL4_WIDTH  85

THREAD STATIC t_hParams := { => }

PROCEDURE hbtest_Setup( cName, xValue )

   IF HB_ISSTRING( cName ) .AND. ! Empty( cName )
      IF PCount() > 1
         t_hParams[ cName ] := xValue
      ELSEIF cName $ t_hParams
         hb_HDel( t_hParams, cName )
      ENDIF
   ENDIF

   RETURN

PROCEDURE hbtest_Call( cBlock, bBlock, xResultExpected )

   LOCAL xResult
   LOCAL oError
   LOCAL lPPError
   LOCAL lRTE
   LOCAL lFailed

   LOCAL bOut

   LOCAL cLangOld

   IF HB_ISSTRING( cBlock )
      lPPError := .F.
   ELSE
      cBlock := "[Preprocessor error]"
      lPPError := .T.
   ENDIF

   cLangOld := hb_langSelect( "en" )

   BEGIN SEQUENCE WITH ErrorBlock( {| oError | Break( oError ) } )
      xResult := Eval( bBlock )
      lRTE := .F.
   RECOVER USING oError
      xResult := ErrorMessage( oError )
      lRTE := .T.
   END SEQUENCE

   hb_langSelect( cLangOld )

   IF lRTE
      lFailed := !( XToStr( xResult, .F. ) == XToStr( xResultExpected, .F. ) )
   ELSE
      IF !( ValType( xResult ) == ValType( xResultExpected ) )
         IF HB_ISSTRING( xResultExpected ) .AND. ValType( xResult ) $ "ABOHPS"
            lFailed := !( XToStr( xResult, .F. ) == xResultExpected )
         ELSE
            lFailed := .T.
         ENDIF
      ELSE
         lFailed := !( xResult == xResultExpected )
      ENDIF
   ENDIF

   IF lFailed .OR. lPPError .OR. hb_HGetDef( t_hParams, "showall", .T. )
      bOut := hb_HGetDef( t_hParams, "output", {| cMsg | OutStd( cMsg ) } )
      IF lFailed
         Eval( bOut, ;
            PadR( iif( lFailed, "!", " " ), TEST_RESULT_COL1_WIDTH ) + " " + ;
            PadR( ProcName( 1 ) + "(" + hb_ntos( ProcLine( 1 ) ) + ")", TEST_RESULT_COL2_WIDTH ) + " " + ;
            RTrim( cBlock ) + ;
            hb_eol() + ;
            Space( 5 ) + "  Result: " + XToStr( xResult, .F. ) + ;
            hb_eol() + ;
            Space( 5 ) + "Expected: " + XToStr( xResultExpected, .F. ) + ;
            hb_eol() )
      ELSE
         Eval( bOut, ;
            PadR( iif( lFailed, "!", " " ), TEST_RESULT_COL1_WIDTH ) + " " + ;
            PadR( ProcName( 1 ) + "(" + hb_ntos( ProcLine( 1 ) ) + ")", TEST_RESULT_COL2_WIDTH ) + " " + ;
            PadR( cBlock, TEST_RESULT_COL3_WIDTH ) + " -> " + ;
            PadR( XToStr( xResult, .F. ), TEST_RESULT_COL4_WIDTH ) + " | " + ;
            XToStr( xResultExpected, .F. ) + ;
            hb_eol() )
      ENDIF
   ENDIF

   RETURN

STATIC FUNCTION ErrorMessage( oError )

   LOCAL cMessage := ""
   LOCAL tmp

   IF HB_ISNUMERIC( oError:severity )
      SWITCH oError:severity
      CASE ES_WHOCARES     ; cMessage += "M " ; EXIT
      CASE ES_WARNING      ; cMessage += "W " ; EXIT
      CASE ES_ERROR        ; cMessage += "E " ; EXIT
      CASE ES_CATASTROPHIC ; cMessage += "C " ; EXIT
      ENDSWITCH
   ENDIF
   IF HB_ISNUMERIC( oError:genCode )
      cMessage += hb_ntos( oError:genCode ) + " "
   ENDIF
   IF HB_ISSTRING( oError:subsystem )
      cMessage += oError:subsystem + " "
   ENDIF
   IF HB_ISNUMERIC( oError:subCode )
      cMessage += hb_ntos( oError:subCode ) + " "
   ENDIF
   IF HB_ISSTRING( oError:description )
      cMessage += oError:description + " "
   ENDIF
   IF ! Empty( oError:operation )
      cMessage += "(" + oError:operation + ") "
   ENDIF
   IF ! Empty( oError:filename )
      cMessage += "<" + oError:filename + "> "
   ENDIF
   IF HB_ISNUMERIC( oError:osCode )
      cMessage += "OS:" + hb_ntos( oError:osCode ) + " "
   ENDIF
   IF HB_ISNUMERIC( oError:tries )
      cMessage += "#:" + hb_ntos( oError:tries ) + " "
   ENDIF

   IF HB_ISARRAY( oError:Args )
      cMessage += "A:" + hb_ntos( Len( oError:Args ) ) + ":"
      FOR tmp := 1 TO Len( oError:Args )
         cMessage += ValType( oError:Args[ tmp ] ) + ":" + XToStr( oError:Args[ tmp ], .T. )
         IF tmp < Len( oError:Args )
            cMessage += ";"
         ENDIF
      NEXT
      cMessage += " "
   ENDIF

   IF oError:canDefault .OR. ;
      oError:canRetry .OR. ;
      oError:canSubstitute

      cMessage += "F:"
      IF oError:canDefault
         cMessage += "D"
      ENDIF
      IF oError:canRetry
         cMessage += "R"
      ENDIF
      IF oError:canSubstitute
         cMessage += "S"
      ENDIF
   ENDIF

   RETURN cMessage

STATIC FUNCTION XToStr( xValue, lInString )

   SWITCH ValType( xValue )
   CASE "N" ; RETURN hb_ntos( xValue )
   CASE "D" ; RETURN iif( lInString, "0d" + iif( Empty( xValue ), "00000000", DToS( xValue ) ), 'hb_SToD( "' + DToS( xValue ) + '" )' )
   CASE "U" ; RETURN "NIL"
   CASE "C"
   CASE "M"
      xValue := __StrToExp( xValue )
      RETURN iif( lInString, xValue, '"' + xValue + '"' )
   CASE "A"
   CASE "H"
   CASE "O"
      IF ! lInString
         RETURN hb_ValToExp( xValue, .T. )
      ENDIF
      EXIT
   ENDSWITCH

   RETURN hb_CStr( xValue )

STATIC FUNCTION __StrToExp( cStr )

   LOCAL cResult := ""

   LOCAL nLen, nPos
   LOCAL cByte

   nLen := hb_BLen( cStr )
   FOR nPos := 1 TO nLen
      cByte := hb_BSubStr( cStr, nPos, 1 )
      IF ! __ByteIsDisplayable( cByte ) .OR. cByte == '"'
         cResult += "\" + __ByteEscape( hb_BCode( cByte ) )
      ELSE
         cResult += cByte
      ENDIF
   NEXT

   RETURN cResult

STATIC FUNCTION __ByteIsDisplayable( cByte )
   RETURN ;
      hb_BCode( cByte ) >= 32 .AND. ;
      hb_BCode( cByte ) < 128

STATIC FUNCTION __ByteEscape( nByte )

   LOCAL cResult
   LOCAL nExp

   IF nByte == 0
      RETURN "0"
   ELSE
      cResult := ""
      FOR nExp := 2 TO 0 STEP -1
         cResult += SubStr( "01234567", Int( nByte / ( 8 ^ nExp ) ) + 1, 1 )
         nByte %= 8 ^ nExp
      NEXT
   ENDIF

   RETURN cResult


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour contribution module 'gtwvg' (): contrib/gtwvg/3state.prg. Defines classes: Wvg3State. This file provides platform-specific functionality

[Assistant]
#include "hbclass.ch"
#include "inkey.ch"
#include "hbgtinfo.ch"

#include "hbgtwvg.ch"
#include "wvtwin.ch"
#include "wvgparts.ch"

#ifndef __DBG_PARTS__
#xtranslate hb_traceLog( [<x,...>] ) =>
#endif

CREATE CLASS Wvg3State INHERIT WvgWindow, WvgDataRef

   VAR    autosize                              INIT .F.
   VAR    caption                               INIT ""
   VAR    pointerFocus                          INIT .T.
   VAR    selection                             INIT .F.

   METHOD new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD configure( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD destroy()

   METHOD setCaption( xCaption )

   ACCESS selected                              INLINE ::sl_lbClick
   ASSIGN selected( bBlock )                    INLINE ::sl_lbClick := bBlock

   METHOD handleEvent( nMessage, aNM )

ENDCLASS

METHOD Wvg3State:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::wvgWindow:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::style       := WS_CHILD + BS_AUTO3STATE
   ::className   := "BUTTON"
   ::objType     := objType3State

   RETURN Self

METHOD Wvg3State:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::wvgWindow:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::oParent:AddChild( Self )

   ::createControl()

   ::SetWindowProcCallback()

   IF ::visible
      ::show()
   ENDIF

   ::setCaption( ::caption )

   IF ::selection
      ::sendMessage( BM_SETCHECK, BST_CHECKED, 0 )
   ENDIF

   IF ::visible
      ::show()
   ENDIF

   ::editBuffer := wvg_Button_GetCheck( ::hWnd )

   RETURN Self

METHOD Wvg3State:handleEvent( nMessage, aNM )

   hb_traceLog( "       %s:handleEvent( %i )", ::ClassName(), nMessage )

   DO CASE
   CASE nMessage == HB_GTE_COMMAND
      IF aNM[ NMH_code ] == BN_CLICKED
         ::editBuffer := wvg_Button_GetCheck( ::hWnd )

         IF HB_ISBLOCK( ::sl_lbClick )
            Eval( ::sl_lbClick, ::editBuffer, , Self )
            RETURN 0
         ENDIF
      ENDIF

   CASE nMessage == HB_GTE_CTLCOLOR
      IF HB_ISNUMERIC( ::clr_FG )
         wvg_SetTextColor( aNM[ 1 ], ::clr_FG )
      ENDIF
      IF HB_ISNUMERIC( ::hBrushBG )
         wvg_SetBkMode( aNM[ 1 ], 1 )
         RETURN ::hBrushBG
      ELSE
         RETURN wvg_GetCurrentBrush( aNM[ 1 ] )
      ENDIF

   ENDCASE

   RETURN 1

METHOD PROCEDURE Wvg3State:destroy()

   hb_traceLog( "          %s:destroy()", ::ClassName() )

   ::WvgWindow:destroy()

   RETURN

METHOD Wvg3State:configure( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::Initialize( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   RETURN Self

METHOD Wvg3State:setCaption( xCaption )

   IF HB_ISSTRING( xCaption )
      ::caption := xCaption
      wvg_SendMessageText( ::hWnd, WM_SETTEXT, 0, ::caption )
   ENDIF

   RETURN Self


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement these Harbour functions: Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/ctrand.prg. Provides functions: Random, Rand. This file provides legacy compatibility functions

[Assistant]
FUNCTION Random( lMode )
   RETURN iif( HB_ISLOGICAL( lMode ) .AND. lMode, ;
      hb_RandomInt( -32768, 32767 ), hb_RandomInt( 0, 65535 ) )

FUNCTION Rand( nStart )

   IF nStart != NIL
      hb_RandomSeed( nStart )
   ENDIF

   RETURN hb_Random()


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Write a Harbour program with procedures: Main. Harbour contribution module 'hbtip' (Internet protocol utilities (FTP, HTTP, SMTP, POP3)): contrib/hbtip/tests/dbtohtml.prg. Contains procedures: Main. This file provides network protocol implementations

[Assistant]
#require "hbtip"
#require "hbtest"

PROCEDURE Main()

   LOCAL oDoc, oNode, oTable, oRow, oCell
   LOCAL i, j

   IF ! hbtest_Table()
      ? "Error: Test database couldn't be created"
      RETURN
   ENDIF

   oDoc          := THtmlDocument():New()

   oNode         := oDoc:head + "meta"
   oNode:name    := "Generator"
   oNode:content := "THtmlDocument"

   oNode         := oDoc:body:h1
   oNode:text    := "My address book"

   oNode         := oDoc:body + "p"

   oNode         := oNode + 'font size="5"'
   oNode:text    := "This is a "

   oNode         := oNode + "b"

   oNode         := oNode + 'font color="blue"'
   oNode:text    := "sample "

   oNode         := oNode - "font"

   oNode         := oNode - "b"

   oNode:text    := "database!"

   oNode         := oNode - "font"

   oNode         := oNode + "hr"
   HB_SYMBOL_UNUSED( oNode )

   oTable        := oDoc:body:table
   oTable:attr   := 'border="0" width="100%" cellspacing="0" cellpadding="0"'

   oRow          := oTable  + 'tr bgcolor="lightcyan"'
   FOR i := 1 TO FCount()
      oCell      := oRow + "th"
      oCell:text := FieldName( i )
      oCell      := oCell - "th"
      HB_SYMBOL_UNUSED( oCell )
   NEXT

   oRow := oRow - "tr"
   HB_SYMBOL_UNUSED( oRow )

   FOR i := 1 TO 10
      oRow         := oTable + "tr"
      oRow:bgColor := iif( RecNo() % 2 == 0, "lightgrey", "white" )

      FOR j := 1 TO FCount()
         oCell      := oRow + "td"
         oCell:text := FieldGet( j )
         oCell      := oCell - "td"
         HB_SYMBOL_UNUSED( oCell )
      NEXT

      oRow := oRow - "tr"
      HB_SYMBOL_UNUSED( oRow )

      dbSkip()
   NEXT

   oNode := oDoc:body + "hr"
   HB_SYMBOL_UNUSED( oNode )
   oNode := oDoc:body + "p"

   oNode:text := "10 records from database " + Alias()

   dbCloseArea()

   IF oDoc:writeFile( "address.html" )
      ? "File created:", "address.html"
   ELSE
      ? "Error:", FError()
   ENDIF

   WAIT
   ? tip_HtmlToStr( oDoc:body:getText() )

   hb_run( "address.html" )

   hb_vfErase( "address.html" )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Define Harbour macros and constants: Harbour header file: include/hbstrict.ch. Defines constants: HB_STRICT_CH_. Declares 1 preprocessor translations. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_STRICT_CH_
#define HB_STRICT_CH_

#translate if( <x>, <y>, <z> ) => iif()

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour header file: include/hbmemvar.ch. Defines 8 constants including: HB_MEMVAR_CH_, HB_MV_NOT_FOUND, HB_MV_UNKNOWN, HB_MV_ERROR, HB_MV_PUBLIC. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_MEMVAR_CH_
#define HB_MEMVAR_CH_

#define HB_MV_NOT_FOUND        -2
#define HB_MV_UNKNOWN          -1
#define HB_MV_ERROR             0
#define HB_MV_PUBLIC            1
#define HB_MV_PRIVATE_GLOBAL    2
#define HB_MV_PRIVATE_LOCAL     4
#define HB_MV_PRIVATE           6

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour Runtime Library file: src/rtl/checkbox.prg. Defines classes: CheckBox. Provides functions: _CheckBox_, CheckBox. This file provides utility functions

[Assistant]
#include "hbclass.ch"

#include "button.ch"
#include "color.ch"
#include "setcurs.ch"

#ifdef HB_COMPAT_C53

CREATE CLASS CheckBox FUNCTION HBCheckBox

   EXPORTED:

   VAR cargo

   METHOD display()
   METHOD hitTest( nMRow, nMCol )
   METHOD killFocus()
   METHOD select( lState )
   METHOD setFocus()

   METHOD bitmaps( aBitmaps ) SETGET
   METHOD buffer() SETGET
   METHOD capCol( nCapCol ) SETGET
   METHOD capRow( nCapRow ) SETGET
   METHOD caption( cCaption ) SETGET
   METHOD col( nCol ) SETGET
   METHOD colorSpec( cColorSpec ) SETGET
   METHOD fBlock( bFBlock ) SETGET
   METHOD hasFocus() SETGET
   METHOD message( cMessage ) SETGET
   METHOD row( nRow ) SETGET
   METHOD sBlock( bSBlock ) SETGET
   METHOD style( cStyle ) SETGET
   METHOD typeOut() SETGET

   METHOD Init( nRow, nCol, cCaption )

   PROTECTED:

   VAR aBitmaps   INIT { "check_f.bmu", "check_e.bmu" }
   VAR lBuffer    INIT .F.
   VAR nCapCol
   VAR nCapRow
   VAR cCaption
   VAR nCol
   VAR cColorSpec
   VAR bFBlock
   VAR lHasFocus  INIT .F.
   VAR cMessage   INIT ""
   VAR nRow
   VAR bSBlock
   VAR cStyle     INIT hb_UTF8ToStr( "[√ ]" )

   VAR nCursor

ENDCLASS

METHOD setFocus() CLASS CheckBox

   IF ! ::lHasFocus
      ::nCursor := SetCursor( SC_NONE )
      ::lHasFocus := .T.
      ::display()

      IF HB_ISEVALITEM( ::bFBlock )
         Eval( ::bFBlock )
      ENDIF
   ENDIF

   RETURN Self

METHOD select( lState ) CLASS CheckBox

   LOCAL lOldState := ::lBuffer

   ::lBuffer := iif( HB_ISLOGICAL( lState ), lState, ! ::lBuffer )

   IF lOldState != ::lBuffer
      ::display()

      IF HB_ISEVALITEM( ::bSBlock )
         Eval( ::bSBlock )
      ENDIF
   ENDIF

   RETURN Self

METHOD killFocus() CLASS CheckBox

   IF ::lHasFocus
      ::lHasFocus := .F.

      IF HB_ISEVALITEM( ::bFBlock )
         Eval( ::bFBlock )
      ENDIF

      ::display()
      SetCursor( ::nCursor )
   ENDIF

   RETURN Self

METHOD hitTest( nMRow, nMCol ) CLASS CheckBox

   LOCAL nPosAccel
   LOCAL nLenCaption

   IF nMRow == ::nRow .AND. ;
      nMCol >= ::nCol .AND. ;
      nMCol < ::nCol + 3
      RETURN HTCLIENT
   ENDIF

   nLenCaption := Len( ::cCaption )

   IF ( nPosAccel := At( "&", ::cCaption ) ) > 0 .AND. ;
      nPosAccel < nLenCaption
      nLenCaption--
   ENDIF

   IF nMRow == ::nCapRow .AND. ;
      nMCol >= ::nCapCol .AND. ;
      nMCol < ::nCapCol + nLenCaption
      RETURN HTCAPTION
   ENDIF

   RETURN HTNOWHERE

METHOD display() CLASS CheckBox

   LOCAL cColor
   LOCAL cStyle := ::cStyle
   LOCAL cCaption
   LOCAL nPos

   DispBegin()

   hb_DispOutAt( ::nRow, ::nCol + 1, iif( ::lBuffer, SubStr( cStyle, 2, 1 ), SubStr( cStyle, 3, 1 ) ), ;
      hb_ColorIndex( ::cColorSpec, iif( ::lHasFocus, 1, 0 ) ) )

   cColor := hb_ColorIndex( ::cColorSpec, 2 )
   hb_DispOutAt( ::nRow, ::nCol, Left( cStyle, 1 ), cColor )
   hb_DispOutAt( ::nRow, ::nCol + 2, Right( cStyle, 1 ), cColor )

   IF ! Empty( cCaption := ::cCaption )

      IF ( nPos := At( "&", cCaption ) ) == 0
      ELSEIF nPos == Len( cCaption )
         nPos := 0
      ELSE
         cCaption := Stuff( cCaption, nPos, 1, "" )
      ENDIF

      IF ::lHasFocus
         cColor := hb_ColorIndex( ::cColorSpec, 3 )
      ENDIF

      hb_DispOutAt( ::nCapRow, ::nCapCol, cCaption, cColor )

      IF ! ::lHasFocus .AND. nPos != 0
         hb_DispOutAt( ::nCapRow, ::nCapCol + nPos - 1, SubStr( cCaption, nPos, 1 ), ;
            hb_ColorIndex( ::cColorSpec, 3 ) )
      ENDIF
   ENDIF

   DispEnd()

   RETURN Self

METHOD bitmaps( aBitmaps ) CLASS CheckBox

   IF aBitmaps != NIL
      ::aBitmaps := __eInstVar53( Self, "BITMAPS", aBitmaps, "A", 1001 )
   ENDIF

   RETURN ::aBitmaps

METHOD buffer() CLASS CheckBox
   RETURN ::lBuffer

METHOD capCol( nCapCol ) CLASS CheckBox

   IF nCapCol != NIL
      ::nCapCol := __eInstVar53( Self, "CAPCOL", nCapCol, "N", 1001 )
   ENDIF

   RETURN ::nCapCol

METHOD capRow( nCapRow ) CLASS CheckBox

   IF nCapRow != NIL
      ::nCapRow := __eInstVar53( Self, "CAPROW", nCapRow, "N", 1001 )
   ENDIF

   RETURN ::nCapRow

METHOD caption( cCaption ) CLASS CheckBox

   IF cCaption != NIL
      ::cCaption := __eInstVar53( Self, "CAPTION", cCaption, "C", 1001 )
   ENDIF

   RETURN ::cCaption

METHOD col( nCol ) CLASS CheckBox

   IF nCol != NIL
      ::nCol := __eInstVar53( Self, "COL", nCol, "N", 1001 )
   ENDIF

   RETURN ::nCol

METHOD colorSpec( cColorSpec ) CLASS CheckBox

   IF cColorSpec != NIL
      ::cColorSpec := __eInstVar53( Self, "COLORSPEC", cColorSpec, "C", 1001, ;
         {|| ! Empty( hb_ColorIndex( cColorSpec, 3 ) ) .AND. Empty( hb_ColorIndex( cColorSpec, 4 ) ) } )
   ENDIF

   RETURN ::cColorSpec

METHOD fBlock( bFBlock ) CLASS CheckBox

   IF PCount() > 0
      ::bFBlock := iif( bFBlock == NIL, NIL, __eInstVar53( Self, "FBLOCK", bFBlock, "B", 1001 ) )
   ENDIF

   RETURN ::bFBlock

METHOD hasFocus() CLASS CheckBox
   RETURN ::lHasFocus

METHOD message( cMessage ) CLASS CheckBox

   IF cMessage != NIL
      ::cMessage := __eInstVar53( Self, "MESSAGE", cMessage, "C", 1001 )
   ENDIF

   RETURN ::cMessage

METHOD row( nRow ) CLASS CheckBox

   IF nRow != NIL
      ::nRow := __eInstVar53( Self, "ROW", nRow, "N", 1001 )
   ENDIF

   RETURN ::nRow

METHOD sBlock( bSBlock ) CLASS CheckBox

   IF PCount() > 0
      ::bSBlock := iif( bSBlock == NIL, NIL, __eInstVar53( Self, "SBLOCK", bSBlock, "B", 1001 ) )
   ENDIF

   RETURN ::bSBlock

METHOD style( cStyle ) CLASS CheckBox

   IF cStyle != NIL
      ::cStyle := __eInstVar53( Self, "STYLE", cStyle, "C", 1001, {|| Len( cStyle ) == 0 .OR. Len( cStyle ) == 4 } )
   ENDIF

   RETURN ::cStyle

METHOD typeOut() CLASS CheckBox
   RETURN .F.

METHOD Init( nRow, nCol, cCaption ) CLASS CheckBox

   LOCAL cColor

   __defaultNIL( @cCaption, "" )

   ::caption := cCaption
   ::capRow  := nRow
   ::capCol  := nCol + 3 + 1
   ::row     := nRow
   ::col     := nCol

   IF IsDefColor()
      ::cColorSpec := "W/N,W+/N,W/N,W+/N"
   ELSE
      cColor := SetColor()
      ::cColorSpec := ;
         hb_ColorIndex( cColor, CLR_UNSELECTED ) + "," + ;
         hb_ColorIndex( cColor, CLR_ENHANCED   ) + "," + ;
         hb_ColorIndex( cColor, CLR_STANDARD   ) + "," + ;
         hb_ColorIndex( cColor, CLR_BACKGROUND )
   ENDIF

   RETURN Self

FUNCTION _CheckBox_( lState, cCaption, cMessage, cColorSpec, bFBlock, bSBlock, cStyle, aBitmaps )

   LOCAL o := HBCheckBox():New( Row(), Col(), cCaption )

   o:select( lState )
   o:caption   := cCaption
   o:message   := cMessage
   o:colorSpec := cColorSpec
   o:fBlock    := bFBlock
   o:sBlock    := bSBlock
   o:style     := cStyle
   o:bitmaps   := aBitmaps

   RETURN o

FUNCTION CheckBox( nRow, nCol, cCaption )
   RETURN HBCheckBox():New( nRow, nCol, cCaption )

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Write the following Harbour (xBase/Clipper) code:

Harbour contribution module 'xhb' (Extended Harbour functions): contrib/xhb/regexrpl.prg. Provides functions: hb_regexReplace. This file provides legacy compatibility functions

[Assistant]
#define MATCH_STRING  1
#define MATCH_START   2
#define MATCH_END     3

FUNCTION hb_regexReplace( cRegex, cString, cReplace, lCaseSensitive, lNewLine, nMaxMatches, nGetMatch )

   LOCAL aMatches, aMatch
   LOCAL cReturn
   LOCAL nOffSet := 0
   LOCAL cSearch, nStart, nLenSearch, nLenReplace

   aMatches := hb_regexAll( cRegEx, cString, lCaseSensitive, lNewLine, nMaxMatches, nGetMatch, .F. )
   cReturn := cString

   IF ! Empty( aMatches )
      FOR EACH aMatch IN aMatches
         IF HB_ISARRAY( aMatch ) .AND. Len( aMatch ) >= 1 .AND. ;
            HB_ISARRAY( aMatch[ 1 ] )
            aMatch := aMatch[ 1 ]
            IF Len( aMatch ) == 3
               cSearch := aMatch[ MATCH_STRING ]
               nStart  := aMatch[ MATCH_START ]
               nLenSearch  := Len( cSearch )
               nLenReplace := Len( cReplace )
               cReturn := Stuff( cReturn, nStart - nOffSet, nLenSearch, cReplace )
               nOffSet += nLenSearch - nLenReplace
            ENDIF
         ENDIF
      NEXT

   ENDIF

   RETURN cReturn


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour test program: tests/mt/mttest12.prg. This test file tests specific function APIs

[Assistant]
thread static t_var1 := { "A", "B", "C" }
thread static t_var2 := { "A" => "qwe", "B" => "asd" }
thread static t_var3 := 1235.567
thread static t_var4 := "text"

proc main()
testvar("initial main thread values")
aadd( t_var1, "X" )
t_var2[ "X" ] := "zxc"
t_var3 += 100000
t_var4 := upper( t_var4 )
testvar("modified main thread values")
hb_threadJoin( hb_threadStart( @thFunc() ) )
testvar("modified main thread values")
return

proc testvar( cMsg )
? cMsg
? "t_var1:", hb_valtoExp( t_var1 )
? "t_var2:", hb_valtoExp( t_var2 )
? "t_var3:", hb_valtoExp( t_var3 )
? "t_var4:", hb_valtoExp( t_var4 )
wait
?
return

proc thFunc()
testvar("initial child thread values")
aadd( t_var1, "Y" )
t_var2[ "Y" ] := "abc"
t_var3 -= 500000
t_var4 += " CHANGED"
testvar("modified child thread values")
return


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Write the following Harbour (xBase/Clipper) code:

Harbour test program: tests/setkeys.prg. Contains procedures: Main, SubMain. This test file tests specific function APIs

[Assistant]
#include "inkey.ch"

PROCEDURE Main()

   LOCAL GetList := {}
   LOCAL alpha, bravo, charlie, k
   LOCAL F8Active := .T.

   Set( _SET_DATEFORMAT, "yyyy-mm-dd" )

   CLS

   @ 2, 2 SAY "Press <F10> to popup alert box of current get, not active if empty"
   @ 3, 2 SAY "Press <F9> to disable all setkeys, except <F9> to restore (uses hb_SetKeySave())"
   @ 4, 2 SAY "Press <F8> to test setkey w/ array, hb_SetKeyCheck(), and hb_SetKeyGet()"
   @ 5, 2 SAY "Press <F7> to active/deactive <F8>"

   alpha   := "alpha    "
   bravo   := 123
   charlie := Date()

   @ 10, 10 GET alpha
   @ 11, 10 GET bravo
   @ 12, 10 GET charlie

   SetKey( K_F10, {|| Alert( Transform( GetActive():varGet(), NIL ) ) }, ;
      {|| ! Empty( GetActive():varGet() ) } )
   SetKey( K_F9, {|| k := hb_SetKeySave( NIL ), ;
      SetKey( K_F9, {|| hb_SetKeySave( k ) } ) } )
   SetKey( K_F8, {|| SubMain() }, {|| F8Active } )
   SetKey( K_F7, {|| F8Active := ! F8Active } )

   READ
   ? alpha, bravo, charlie

   RETURN

STATIC PROCEDURE SubMain()

   LOCAL n
   LOCAL bF8Action, bF8Active
   LOCAL aKeyArray := { hb_keyCode( "1" ), hb_keyCode( "2" ), hb_keyCode( "4" ), hb_keyCode( "5" ) }

   bF8Action := hb_SetKeyGet( K_F8, @bF8Active )
   SetKey( K_F8, NIL )

   hb_SetKeyArray( aKeyArray, {| x | QOut( hb_keyChar( x ) ) } )
   DO WHILE ( n := Inkey( 0 ) ) != K_ESC
      IF hb_SetKeyCheck( n, ProcName(), ProcLine(), ReadVar() )
         ?? " hit hot"
      ELSE
         ? hb_keyChar( n )
         ?? " hit cold"
      ENDIF
   ENDDO

   hb_SetKeyArray( aKeyArray, NIL )
   SetKey( K_F8, bF8Action, bF8Active )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Here is a Harbour (xBase/Clipper) implementation:

Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/tests/ontick.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#require "hbnf"

PROCEDURE Main()

   CLS

   ft_OnTick( {|| OutStd( hb_MilliSeconds(), hb_eol() ) } )

   Inkey( 0 )

   ft_OnTick( {|| OutStd( hb_MilliSeconds(), hb_eol() ) }, 18 )

   Inkey( 0 )

   ft_OnTick()

   Inkey( 0 )

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour contribution module 'hbwin' (Windows API wrapper functions): contrib/hbwin/tests/oletst4.prg. Contains procedures: Main. This file provides platform-specific functionality

[Assistant]
#require "hbwin"

PROCEDURE Main()

   LOCAL oObject, oTime, oInfo
   LOCAL p1, p2, p3, p4, p5, p6, p7

   oObject := win_oleCreateObject( "MyOleObjServer" )

   IF ! Empty( oObject )
      oTime := oObject:timer()
      ? "TIMER:"
      ? "      date:", oTime:date
      ? "      time:", oTime:time
      ? "       now:", oTime:now
      oInfo := oObject:info()
      ? "INFO:"
      ? "        os:", oInfo:os
      ? "       ver:", oInfo:ver
      ? "  compiler:", oInfo:compiler
      ? "     build:", oInfo:build
      ?
      ? "REF:", oObject:ref( @p1, @p2, @p3, @p4, @p5, @p6, @p7 )
      ? "        p1:", hb_ValToExp( p1 )
      ? "        p2:", hb_ValToExp( p2 )
      ? "        p3:", hb_ValToExp( p3 )
      ? "        p4:", hb_ValToExp( p4 )
      ? "        p5:", p5:className()
      ? "        p6:", hb_ValToExp( p6 )
      ? "        p7:", hb_ValToExp( p7 )
   ELSE
      ? "Can not access 'MyOleObjServer' OLE server."
   ENDIF

   WAIT

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement these Harbour functions: Harbour extra library: extras/httpsrv/_cgifunc.prg. Provides 11 functions including: uhttpd_GetVars, uhttpd_SplitUrl, uhttpd_SplitString, uhttpd_URLEncode, uhttpd_URLDecode. This file implements server functionality

[Assistant]
#include "error.ch"
#include "fileio.ch"

#define CRLF ( Chr( 13 ) + Chr( 10 ) )
#xtranslate Throw( <oErr> ) => ( Eval( ErrorBlock(), <oErr> ), Break( <oErr> ) )

MEMVAR _SERVER, _GET, _POST, _COOKIE, _REQUEST, _HTTP_REQUEST

FUNCTION uhttpd_GetVars( cFields, cSeparator )

   LOCAL hHashVars := { => }
   LOCAL aField, cField, aFields
   LOCAL cName, xValue

   __defaultNIL( @cSeparator, "&" )

   aFields := uhttpd_Split( cSeparator, cFields )

   FOR EACH cField in aFields
      aField := uhttpd_Split( "=", cField, 1 )
      IF Len( aField ) == 1
         hHashVars[ aField[ 1 ] ] := NIL
         LOOP
      ELSEIF Len( aField ) != 2
         LOOP
      ENDIF

      cName  := LTrim( aField[ 1 ] )
      xValue := uhttpd_UrlDecode( aField[ 2 ] )

      IF SubStr( cName, Len( cName ) - 1 ) == "[]"
         cName := SubStr( cName, 1, Len( cName ) - 2 )
         hHashVars[ cName ] := { xValue }
      ELSE

         IF hb_HPos( hHashVars, cName ) > 0
            IF ! HB_ISARRAY( hHashVars[ cName ] )

               hHashVars[ cName ] := { hHashVars[ cName ] }
            ENDIF
            AAdd( hHashVars[ cName ], xValue )
         ELSE
            hHashVars[ cName ] := xValue
         ENDIF

      ENDIF
   NEXT

   RETURN hHashVars

FUNCTION uhttpd_SplitUrl( cUrl )

   LOCAL hUrl := { => }
   LOCAL nPos, cTemp, cUserNamePassword, cHostnamePort
   LOCAL cProto, cHost, cPort, nPort, cUser, cPass, cPath, cQuery, cFragment
   LOCAL cUri

   hb_HCaseMatch( hUrl, .F. )

   cTemp := cUrl
   cUri  := ""

   nPos := At( ":
   IF nPos > 0
      cProto := Left( cTemp, nPos - 1 )

      cTemp := SubStr( cTemp, nPos + 3 )
   ELSE
      cProto := ""
   ENDIF

   cUri += cProto + iif( ! Empty( cProto ), ":

   nPos := At( "@", cTemp )
   IF nPos > 0
      cUserNamePassword := Left( cTemp, nPos - 1 )

      cTemp := SubStr( cTemp, nPos + 1 )

      nPos := At( ":", cUserNamePassword )
      IF nPos > 0
         cUser := Left( cUserNamePassword, nPos - 1 )
         cPass := SubStr( cUserNamePassword, nPos + 1 )
      ELSE
         cUser := cUserNamePassword
         cPass := ""
      ENDIF
   ELSE
      cUser := ""
      cPass := ""
   ENDIF

   nPos := RAt( "#", cTemp )
   IF nPos > 0
      cFragment := SubStr( cTemp, nPos + 1 )

      cTemp := SubStr( cTemp, 1, nPos - 1 )

   ELSE
      cFragment := ""
   ENDIF

   nPos := RAt( "?", cTemp )
   IF nPos > 0
      cQuery := SubStr( cTemp, nPos + 1 )

      cTemp := SubStr( cTemp, 1, nPos - 1 )

   ELSE
      cQuery := ""
   ENDIF

   cUri += cTemp

   nPos := RAt( "/", cTemp )
   IF nPos > 0
      cPath := SubStr( cTemp, nPos )

      cTemp := SubStr( cTemp, 1, nPos - 1 )

   ELSE
      cPath := "/"
   ENDIF

   cHostnamePort := cTemp

   nPos := At( ":", cHostnamePort )
   IF nPos > 0
      cHost := Left( cHostnamePort, nPos - 1 )
      cPort := SubStr( cHostnamePort, nPos + 1 )
      nPort := Val( cPort )
      IF nPort <= 0
         nPort := -1
      ENDIF
   ELSE
      cHost := cHostnamePort
      nPort := -1
   ENDIF

   hUrl[ "SCHEME" ]   := cProto
   hUrl[ "HOST" ]     := cHost
   hUrl[ "PORT" ]     := nPort
   hUrl[ "USER" ]     := cUser
   hUrl[ "PASS" ]     := cPass
   hUrl[ "PATH" ]     := cPath
   hUrl[ "QUERY" ]    := cQuery
   hUrl[ "FRAGMENT" ] := cFragment
   hUrl[ "URI" ]      := cURI

   hb_HAutoAdd( hUrl, .F. )

   RETURN hUrl

FUNCTION uhttpd_SplitString( cString, cDelim, lRemDelim, nCount )

   LOCAL nEOLPos
   LOCAL cBuffer := cString
   LOCAL aLines  := {}, cLine
   LOCAL nHowMany := 0

   __defaultNIL( @cDelim, ( Chr( 13 ) + Chr( 10 ) ) )
   __defaultNIL( @lRemDelim, .T. )
   __defaultNIL( @nCount, -1 )

   DO WHILE ( nEOLPos := At( cDelim, cBuffer ) ) > 0
      nHowMany++
      IF lRemDelim
         cLine := Left( cBuffer, nEOLPos - 1 )
      ELSE
         cLine := Left( cBuffer, ( nEOLPos + Len( cDelim ) ) - 1 )
      ENDIF

      AAdd( aLines, cLine )
      cBuffer := SubStr( cBuffer, nEOLPos + Len( cDelim ) )
      IF nCount > -1
         IF nHowMany >= nCount
            EXIT
         ENDIF
      ENDIF
   ENDDO

   IF Len( cBuffer ) > 0
      AAdd( aLines, cBuffer )
   ENDIF

   RETURN aLines

FUNCTION uhttpd_URLEncode( cString, lComplete )

#ifdef HB_USE_HBTIP

   __defaultNIL( @lComplete, .T. )

   RETURN TIPENCODERURL_ENCODE( cString, lComplete )
#else
   LOCAL cRet := "", i, nVal, cChar

   __defaultNIL( @lComplete, .T. )

   FOR i := 1 TO Len( cString )
      cChar := SubStr( cString, i, 1 )
      DO CASE
      CASE cChar == " "
         cRet += "+"

      CASE ( cChar >= "A" .AND. cChar <= "Z" ) .OR. ;
           ( cChar >= "a" .AND. cChar <= "z" ) .OR. ;
           ( cChar >= "0" .AND. cChar <= "9" ) .OR. ;
           cChar == "." .OR. cChar == "," .OR. cChar == "&" .OR. ;
           cChar == "/" .OR. cChar == ";" .OR. cChar == "_"
         cRet += cChar

      CASE iif( ! lComplete, cChar == ":" .OR. cChar == "?" .OR. cChar == "=", .F. )
         cRet += cChar

      OTHERWISE
         nVal := Asc( cChar )
         cRet += "%" + hb_NumToHex( nVal )
      ENDCASE
   NEXT

   RETURN cRet

FUNCTION uhttpd_URLDecode( cString )

#ifdef HB_USE_HBTIP
   RETURN TIPENCODERURL_DECODE( cString )
#else
   LOCAL cRet := "", i, cChar

   FOR i := 1 TO Len( cString )
      cChar := SubStr( cString, i, 1 )
      DO CASE
      CASE cChar == "+"
         cRet += " "

      CASE cChar == "%"
         i++
         cRet += Chr( hb_HexToNum( SubStr( cString, i, 2 ) ) )
         i++

      OTHERWISE
         cRet += cChar

      ENDCASE

   NEXT

   RETURN cRet
#endif

FUNCTION uhttpd_DateToGMT( dDate, cTime, nDayToAdd, nSecsToAdd )

   LOCAL aDays   := { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
   LOCAL aMonths := { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }

   __defaultNIL( @dDate, Date() )
   __defaultNIL( @cTime, Time() )
   __defaultNIL( @nDayToAdd, 0 )
   __defaultNIL( @nSecsToAdd, 0 )

   cTime := uhttpd_AddSecondsToTime( cTime, nSecsToAdd, @nDayToAdd )
   dDate += nDayToAdd

   RETURN ;
      aDays[ DoW( dDate ) ] + ", " + ;
      StrZero( Day( dDate ), 2 ) + " " + ;
      aMonths[ Month( dDate ) ] + " " + ;
      StrZero( Year( dDate ), 4 ) + " " + ;
      cTime + " GMT"

FUNCTION uhttpd_AddSecondsToTime( cTime, nSecsToAdd, nDaysAdded )

   LOCAL nOneDaySeconds := 86400
   LOCAL cNewTime, nSecs

   __defaultNIL( @cTime, Time() )
   __defaultNIL( @nSecsToAdd, 0 )

   __defaultNIL( @nDaysAdded, 0 )

   IF nSecsToAdd != 0
      nSecs      := Secs( cTime ) + nSecsToAdd
      nDaysAdded += Int( nSecs / nOneDaySeconds )
      nSecs      := nSecs - nDaysAdded
      cNewTime   := TString( nSecs )
   ELSE
      cNewTime := cTime
   ENDIF

   RETURN cNewTime

FUNCTION uhttpd_OutputString( cString, aTranslate, lProtected )

   LOCAL cHtml

   __defaultNIL( @lProtected, .F. )
   __defaultNIL( @aTranslate, { { '"', """ }, { " ", " " } } )

   IF lProtected
      cHtml := uhttpd_HtmlSpecialChars( cString )
   ELSE
      cHtml := uhttpd_TranslateStrings( cString, aTranslate )
   ENDIF

   RETURN cHtml

FUNCTION uhttpd_HtmlSpecialChars( cString, cQuote_style )

   LOCAL aTranslations := { ;
      { "&", "&" }, ;
      { "<", "<"  }, ;
      { ">", ">"  } }

   RETURN uhttpd_HtmlConvertChars( cString, cQuote_style, aTranslations )

FUNCTION uhttpd_HtmlConvertChars( cString, cQuote_style, aTranslations )

   __defaultNIL( @cQuote_style, "ENT_COMPAT" )

   DO CASE
   CASE cQuote_style == "ENT_COMPAT"
      AAdd( aTranslations, { '"', """ } )
   CASE cQuote_style == "ENT_QUOTES"
      AAdd( aTranslations, { '"', """ } )
      AAdd( aTranslations, { "'", "'" } )
   CASE cQuote_style == "ENT_NOQUOTES"
   ENDCASE

   RETURN uhttpd_TranslateStrings( cString, aTranslations )

FUNCTION uhttpd_CRLF2BR( cString )

   LOCAL aTranslations := { ;
      { CRLF, "<br />" } }


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User]
Write the following Harbour (xBase/Clipper) code:

Harbour utility program: utils/hbtest/rt_class.prg. Contains procedures: Main_CLASS. This file is part of the test framework

[Assistant]
#include "rt_main.ch"

#include "rt_vars.ch"

#include "hbclass.ch"

MEMVAR objHolder, cDtorResult

PROCEDURE Main_CLASS()

   LOCAL oValue, aRef

   PRIVATE objHolder, cDtorResult

#ifdef __HARBOUR__

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 0 )
   HBTEST oValue:type                     IS 0
   HBTEST oValue := NIL                   IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS "No references to self."

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 1 )
   HBTEST oValue:type                     IS 1
   HBTEST oValue := NIL                   IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS "Reference to self in instance variable."

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 2 )
   HBTEST oValue:type                     IS 2
   HBTEST oValue := NIL                   IS "E 45 BASE 1301 Object destructor failure (Reference to freed block) OS:0 #:0 "
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS "Reference to self in class variable."

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 3 )
   HBTEST oValue:type                     IS 3
   HBTEST oValue := NIL                   IS "E 45 BASE 1301 Object destructor failure (Reference to freed block) OS:0 #:0 "
   HBTEST ValType( objHolder )            IS "A"
   HBTEST Len( objHolder )                IS 0
   HBTEST cDtorResult                     IS "Reference to self in private memvar."

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 0 )
   HBTEST oValue:type                     IS 0

   aRef := { oValue, NIL }; aRef[ 2 ] := aRef; aRef := NIL
   HBTEST oValue := NIL                   IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS ""
   HBTEST hb_gcAll()                      IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS "No references to self."

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 1 )
   HBTEST oValue:type                     IS 1

   aRef := { oValue, NIL }; aRef[ 2 ] := aRef; aRef := NIL
   HBTEST oValue := NIL                   IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS ""
   HBTEST hb_gcAll()                      IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS "Reference to self in instance variable."

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 2 )
   HBTEST oValue:type                     IS 2

   aRef := { oValue, NIL }; aRef[ 2 ] := aRef; aRef := NIL
   HBTEST oValue := NIL                   IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS ""
   HBTEST hb_gcAll()                      IS "E 45 BASE 1302 Object destructor failure (Reference to freed block) OS:0 #:0 "
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS "Reference to self in class variable."

   HBTEST cDtorResult := ""               IS ""
   HBTEST objHolder := NIL                IS NIL
   oValue := DTORCLASS():NEW( 3 )
   HBTEST oValue:type                     IS 3

   aRef := { oValue, NIL }; aRef[ 2 ] := aRef; aRef := NIL
   HBTEST oValue := NIL                   IS NIL
   HBTEST objHolder                       IS NIL
   HBTEST cDtorResult                     IS ""
   HBTEST hb_gcAll()                      IS "E 45 BASE 1302 Object destructor failure (Reference to freed block) OS:0 #:0 "
   HBTEST ValType( objHolder )            IS "A"
   HBTEST Len( objHolder )                IS 0
   HBTEST cDtorResult                     IS "Reference to self in private memvar."

   oValue := IVARSCLASS4():new()

   HBTEST oValue:x1                       IS "(x1)"
   HBTEST oValue:y1                       IS "(y1)"
   HBTEST oValue:z1                       IS "(z1)"
   HBTEST oValue:x2                       IS "(x2)"
   HBTEST oValue:y2                       IS "(y2)"
   HBTEST oValue:z2                       IS "(z2)"
   HBTEST oValue:x3                       IS "(x3)"
   HBTEST oValue:y3                       IS "(y3)"
   HBTEST oValue:z3                       IS "(z3)"
   HBTEST oValue:x4                       IS "(x4)"
   HBTEST oValue:y4                       IS "(y4)"
   HBTEST oValue:z4                       IS "(z4)"
   HBTEST INSTANCE_DATA( oValue )         IS "[12]: (x1) (y1) (z1) (x2) (y2) (z2) (x3) (y3) (z3) (x4) (y4) (z4)"
   HBTEST __cls_CntClsData( oValue:IVARSCLASS1:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:IVARSCLASS2:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:IVARSCLASS3:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:IVARSCLASS4:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:classH )             IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS1:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS2:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS3:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS4:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:classH )             IS 0

   HBTEST oValue:x1 := " X1 "             IS " X1 "
   HBTEST oValue:y1 := " Y1 "             IS " Y1 "
   HBTEST oValue:z1 := " Z1 "             IS " Z1 "
   HBTEST oValue:x2 := " X2 "             IS " X2 "
   HBTEST oValue:y2 := " Y2 "             IS " Y2 "
   HBTEST oValue:z2 := " Z2 "             IS " Z2 "
   HBTEST oValue:x3 := " X3 "             IS " X3 "
   HBTEST oValue:y3 := " Y3 "             IS " Y3 "
   HBTEST oValue:z3 := " Z3 "             IS " Z3 "
   HBTEST oValue:x4 := " X4 "             IS " X4 "
   HBTEST oValue:y4 := " Y4 "             IS " Y4 "
   HBTEST oValue:z4 := " Z4 "             IS " Z4 "

   HBTEST oValue:x1                       IS " X1 "
   HBTEST oValue:y1                       IS " Y1 "
   HBTEST oValue:z1                       IS " Z1 "
   HBTEST oValue:x2                       IS " X2 "
   HBTEST oValue:y2                       IS " Y2 "
   HBTEST oValue:z2                       IS " Z2 "
   HBTEST oValue:x3                       IS " X3 "
   HBTEST oValue:y3                       IS " Y3 "
   HBTEST oValue:z3                       IS " Z3 "
   HBTEST oValue:x4                       IS " X4 "
   HBTEST oValue:y4                       IS " Y4 "
   HBTEST oValue:z4                       IS " Z4 "
   HBTEST INSTANCE_DATA( oValue )         IS "[12]:  X1   Y1   Z1   X2   Y2   Z2   X3   Y3   Z3   X4   Y4   Z4 "
   HBTEST __cls_CntClsData( oValue:IVARSCLASS1:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:IVARSCLASS2:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:IVARSCLASS3:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:IVARSCLASS4:classH ) IS 0
   HBTEST __cls_CntClsData( oValue:classH )             IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS1:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS2:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS3:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:IVARSCLASS4:classH ) IS 0
   HBTEST __cls_CntShrData( oValue:classH )             IS 0

   HBTEST oValue:IVARSCLASS1:x1 := "[X1]"    IS "[X1]"
   HBTEST oValue:IVARSCLASS1:y1 := "[Y1]"    IS "[Y1]"
   HBTEST oValue:IVARSCLASS1:z1 := "[Z1]"    IS "[Z1]"

   HBTEST oValue:x1                       IS "[X1]"
   HBTEST oValue:y1                       IS "[Y1]"
   HBTEST oValue:z1                       IS "[Z1]"


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour header file: include/hbsetup.ch. Defines constants: HB_SETUP_CH_, HB_CLP_UNDOC, HB_COMPAT_C53, HB_LEGACY_LEVEL4, HB_LEGACY_LEVEL5. Defines Harbour internal constants and macros

[Assistant]
#ifndef HB_SETUP_CH_
#define HB_SETUP_CH_

#define HB_CLP_UNDOC
#define HB_COMPAT_C53

#ifndef HB_LEGACY_OFF
#define HB_LEGACY_LEVEL4
#endif

#define HB_LEGACY_LEVEL5

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Create Harbour OOP classes for the functionality described: Harbour contribution module 'gtwvg' (): contrib/gtwvg/activex.prg. Defines classes: WvgActiveXControl. This file provides platform-specific functionality

[Assistant]
#include "hbclass.ch"
#include "inkey.ch"
#include "hbgtinfo.ch"

#include "hbgtwvg.ch"
#include "wvtwin.ch"
#include "wvgparts.ch"

#ifndef __DBG_PARTS__
#xtranslate hb_traceLog( [<x,...>] ) =>
#endif

CREATE CLASS WvgActiveXControl INHERIT WvgWindow

   VAR    oOLE
   VAR    CLSID                              INIT ""
   VAR    server                             INIT NIL
   VAR    license                            INIT NIL
   VAR    controlFlags                       INIT 0
   VAR    default                            INIT .F.
   VAR    cancel                             INIT .F.

   VAR    interface
   VAR    interfaceName

   VAR    lSubStdEvents                      INIT .F.

   VAR    hEvents                            INIT { => }
   VAR    hContainer

   VAR    ClassName

   METHOD new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
   METHOD create( oParent, oOwner, aPos, aSize, aPresParams, lVisible, cCLSID, cLicense )
   METHOD Destroy()
   METHOD execEvent( nEvent, ... )
   METHOD handleEvent( nEvent, aNM )
   METHOD mapEvent( nEvent, bBlock )

   METHOD inheritPresParams()
   METHOD presParamsChanged()
   METHOD setInputFocus()
   METHOD subscribeStdEvents()
   METHOD unsubscribeStdEvents()
   METHOD keyDown()
   METHOD click()
   METHOD dblClick()
   METHOD mouseDown()
   METHOD mouseUp()
   METHOD mouseMove()
   METHOD activate()

   ERROR HANDLER OnError()

ENDCLASS

METHOD WvgActiveXControl:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::wvgWindow:new( oParent, oOwner, aPos, aSize, aPresParams, lVisible )

   ::style      := WS_CHILD + WS_VISIBLE + WS_CLIPCHILDREN + WS_CLIPSIBLINGS
   ::exStyle    := WS_EX_CLIENTEDGE
   ::objType    := objTypeActiveX
   ::className  := "WIN_OLEAUTO"

   RETURN Self

METHOD WvgActiveXControl:Create( oParent, oOwner, aPos, aSize, aPresParams, lVisible, cCLSID, cLicense )

   LOCAL hObj, hWnd

   ::WvgWindow:create( @oParent, @oOwner, aPos, aSize, aPresParams, lVisible )

   __defaultNIL( @cCLSID, ::CLSID )
   __defaultNIL( @cLicense, ::license )

   ::CLSID      := cCLSID
   ::license    := cLicense
   ::hContainer := iif( HB_ISOBJECT( ::oParent ), ::oParent:getHWND(), ::oParent )

   IF ! HB_ISNUMERIC( ::hContainer ) .OR. ! HB_ISSTRING( ::CLSID )
      RETURN NIL
   ENDIF

   ::hWnd := NIL
   ::nID  := iif( HB_ISOBJECT( ::oParent ), ::oParent:GetControlId(), ::getControlID() )
   ::oOLE := win_oleAuto()

   win_axInit()

   hWnd := wapi_CreateWindowEx( ::exStyle, "AtlAxWin", ::CLSID, ::style, ::aPos[ 1 ], ::aPos[ 2 ], ;
                                ::aSize[ 1 ], ::aSize[ 2 ], win_N2P( ::hContainer ), 0, NIL, NIL )
   IF Empty( hWnd )
      RETURN NIL
   ENDIF
   ::hWnd := win_P2N( hWnd )
   ::pWnd := hWnd

   hObj := __axGetControl( ::pWnd )
   IF Empty( hObj )
      RETURN NIL
   ENDIF
   ::oOLE:__hObj := hObj
   __axDoVerb( ::pWnd, -4 )

   IF ! Empty( ::hEvents )
      ::oOle:__hSink := __axRegisterHandler( ::oOle:__hObj, {| nEvent, ... | ::execEvent( nEvent, ... ) } )
   ENDIF

   IF HB_ISOBJECT( ::oParent )
      ::oParent:addChild( Self )
   ENDIF

   ::setPosAndSize()
   IF ::visible
      ::show()
   ELSE
      ::hide()
   ENDIF
   IF ::isParentCrt()
      ::oParent:setFocus()
   ENDIF

   RETURN Self

METHOD PROCEDURE WvgActiveXControl:execEvent( nEvent, ... )

   IF hb_HHasKey( ::hEvents, nEvent )
      Eval( ::hEvents[ nEvent ], ... )
   ENDIF

   RETURN

METHOD WvgActiveXControl:handleEvent( nEvent, aNM )

   LOCAL nHandled := 0

   HB_SYMBOL_UNUSED( aNM )

   SWITCH nEvent

   CASE HB_GTE_RESIZED
      IF ::isParentCrt()
         ::rePosition()
      ENDIF
      IF HB_ISBLOCK( ::sl_resize )
         Eval( ::sl_resize, , , Self )
      ENDIF
      EXIT

   CASE HB_GTE_ANY
      EXIT

   ENDSWITCH

   RETURN nHandled

METHOD WvgActiveXControl:OnError()

   RETURN hb_ExecFromArray( ::oOLE, __GetMessage(), hb_AParams() )

METHOD PROCEDURE WvgActiveXControl:Destroy()

   IF ! Empty( ::oOLE )
      IF ! Empty( ::oOLE:__hObj )
         IF wapi_IsWindow( ::pWnd )
            wapi_DestroyWindow( ::pWnd )
         ENDIF
         ::oOle := NIL
         ::hWnd := NIL
      ENDIF
   ENDIF
   RETURN

METHOD WvgActiveXControl:mapEvent( nEvent, bBlock )

   IF HB_ISNUMERIC( nEvent ) .AND. HB_ISBLOCK( bBlock )
      ::hEvents[ nEvent ] := bBlock
   ENDIF

   RETURN Self

METHOD WvgActiveXControl:inheritPresParams()
   RETURN .T.

METHOD WvgActiveXControl:presParamsChanged()
   RETURN Self

METHOD WvgActiveXControl:setInputFocus()
   RETURN Self

METHOD WvgActiveXControl:subscribeStdEvents()
   RETURN NIL

METHOD WvgActiveXControl:unsubscribeStdEvents()
   RETURN Self

METHOD WvgActiveXControl:keyDown()
   RETURN Self

METHOD WvgActiveXControl:click()
   RETURN Self

METHOD WvgActiveXControl:dblClick()
   RETURN Self

METHOD WvgActiveXControl:mouseDown()
   RETURN Self

METHOD WvgActiveXControl:mouseUp()
   RETURN Self

METHOD WvgActiveXControl:mouseMove()
   RETURN Self

METHOD WvgActiveXControl:activate()
   RETURN Self


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Write Harbour functions: ft_WoY, ft_DoY. Harbour contribution module 'hbnf' (NanForum Toolkit - legacy Clipper compatibility functions): contrib/hbnf/woy.prg. Provides functions: ft_WoY, ft_DoY. This file provides legacy compatibility functions

[Assistant]
FUNCTION ft_WoY( dInDate )

   LOCAL nFirstDays, nDayOffset, nWkNumber, cCentury

   IF HB_ISDATE( dInDate )

      cCentury := Left( DToS( dInDate ), 4 )

      nFirstDays := 8 - DoW( hb_SToD( cCentury + "0101" ) )

      nWkNumber := 1

      nDayOffset := ( dInDate - hb_SToD( cCentury + "0101" ) ) - nFirstDays + 1

      DO WHILE nDayOffset > 0
         ++nWkNumber
         nDayOffset -= 7
      ENDDO

   ELSE
      nWkNumber := NIL
   ENDIF

   RETURN nWkNumber

FUNCTION ft_DoY( dInDate )

   LOCAL nDayNum

   IF HB_ISDATE( dInDate )
      nDayNum := ( dInDate - hb_SToD( Left( DToS( dInDate ), 4 ) + "0101" ) ) + 1
   ELSE
      nDayNum := NIL
   ENDIF

   RETURN nDayNum


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour contribution module 'gtwvg' (): contrib/gtwvg/paint.prg. Provides 11 functions including: WvtPaintObjects, WvtSetPaint, wvg_SetPaint, wvg_GetPaint, wvg_DelPaint. Contains procedures: wvg_InsertPaint. This file provides platform-specific functionality

[Assistant]
#include "wvtwin.ch"

#include "hbgtinfo.ch"

THREAD STATIC t_paint_ := { { "", {} } }

FUNCTION WvtPaintObjects()

   LOCAL i, lExe, nLeft, nRight, b, tlbr_, aBlocks, nBlocks

   aBlocks := WvtSetPaint()

   IF ( nBlocks := Len( aBlocks ) ) > 0
      tlbr_ := wvt_GetPaintRect()

      FOR i := 1 TO nBlocks
         lExe := .T.

         IF aBlocks[ i ][ 3 ] != NIL .AND. ! Empty( aBlocks[ i ][ 3 ] )

            DO CASE
            CASE aBlocks[ i ][ 3 ][ 1 ] == WVT_BLOCK_GRID_V
               b := aBlocks[ i ][ 3 ][ 6 ]
               IF Len( b:aColumnsSep ) == 0
                  lExe := .F.
               ELSE
                  nLeft  := b:aColumnsSep[ 1 ]
                  nRight := b:aColumnsSep[ Len( b:aColumnsSep ) ]
                  IF tlbr_[ 1 ] > aBlocks[ i ][ 3 ][ 4 ] .OR. ;
                     tlbr_[ 3 ] < aBlocks[ i ][ 3 ][ 2 ] .OR. ;
                     tlbr_[ 2 ] > nRight + 1 .OR. ;
                     tlbr_[ 4 ] < nLeft - 2
                     lExe := .F.
                  ENDIF
               ENDIF

            CASE aBlocks[ i ][ 3 ][ 1 ] == WVT_BLOCK_GETS
               IF tlbr_[ 1 ] > aBlocks[ i ][ 3 ][ 4 ] .OR. ;
                  tlbr_[ 3 ] < aBlocks[ i ][ 3 ][ 2 ] .OR. ;
                  tlbr_[ 2 ] > aBlocks[ i ][ 3 ][ 5 ] .OR. ;
                  tlbr_[ 4 ] < aBlocks[ i ][ 3 ][ 3 ]
                  lExe := .F.
               ENDIF

            OTHERWISE

               IF tlbr_[ 1 ] > aBlocks[ i ][ 3 ][ 4 ] .OR. ;
                  tlbr_[ 3 ] < aBlocks[ i ][ 3 ][ 2 ] .OR. ;
                  tlbr_[ 2 ] > aBlocks[ i ][ 3 ][ 5 ] .OR. ;
                  tlbr_[ 4 ] < aBlocks[ i ][ 3 ][ 3 ]
                  lExe := .F.
               ENDIF
            ENDCASE
         ENDIF

         IF lExe
            Eval( aBlocks[ i ][ 2 ] )
         ENDIF
      NEXT
   ENDIF

   RETURN 0

FUNCTION WvtSetPaint( a_ )

   THREAD STATIC t

   LOCAL o

   IF t == NIL
      t := {}
   ENDIF

   o := t

   IF a_ != NIL
      t := a_
   ENDIF

   RETURN o

FUNCTION wvg_SetPaint( cID, nAction, xData, aAttr )

   LOCAL n, n1, oldData

   IF xData != NIL
      IF ( n := AScan( t_paint_, {| e_ | e_[ 1 ] == cID } ) ) > 0
         IF ( n1 := AScan( t_paint_[ n ][ 2 ], {| e_ | e_[ 1 ] == nAction } ) ) > 0
            oldData := t_paint_[ n ][ 2 ][ n1 ][ 2 ]
            t_paint_[ n ][ 2 ][ n1 ][ 2 ] := xData
            t_paint_[ n ][ 2 ][ n1 ][ 3 ] := aAttr
         ELSE
            AAdd( t_paint_[ n ][ 2 ], { nAction, xData, aAttr } )
         ENDIF
      ELSE
         AAdd( t_paint_, { cID, {} } )
         n := Len( t_paint_ )
         AAdd( t_paint_[ n ][ 2 ], { nAction, xData, aAttr } )
      ENDIF
   ENDIF

   RETURN oldData

FUNCTION wvg_GetPaint( cID )

   LOCAL n

   IF ( n := AScan( t_paint_, {| e_ | e_[ 1 ] == cID } ) ) > 0
      RETURN t_paint_[ n ][ 2 ]
   ENDIF

   RETURN {}

FUNCTION wvg_DelPaint( cID, nAction )

   LOCAL xData, n1, n

   IF ( n := AScan( t_paint_, {| e_ | e_[ 1 ] == cID } ) ) > 0
      IF ( n1 := AScan( t_paint_[ n ][ 2 ], {| e_ | e_[ 1 ] == nAction } ) ) > 0
         xData := t_paint_[ n ][ 2 ][ n1 ][ 2 ]
         t_paint_[ n ][ 2 ][ n1 ][ 2 ] := {|| .T. }
      ENDIF
   ENDIF

   RETURN xData

FUNCTION wvg_PurgePaint( cID, lDummy )

   LOCAL n, aPaint

   __defaultNIL( @lDummy, .F. )

   IF ( n := AScan( t_paint_, {| e_ | e_[ 1 ] == cID } ) ) > 0
      aPaint := t_paint_[ n ]
      hb_ADel( t_paint_, n, .T. )
   ENDIF

   IF lDummy
      WvtSetPaint( {} )
   ENDIF

   RETURN aPaint

PROCEDURE wvg_InsertPaint( cID, aPaint, lSet )

   LOCAL n

   __defaultNIL( @lSet, .F. )

   IF ( n := AScan( t_paint_, {| e_ | e_[ 1 ] == cID } ) ) > 0
      t_paint_[ n ] := aPaint
   ELSE
      AAdd( t_paint_, aPaint )
   ENDIF

   IF lSet
      WvtSetPaint( aPaint )
   ENDIF

   RETURN

FUNCTION wvt_SetDlgCoMode( nMode )

   STATIC sMode := 0

   LOCAL nOldMode

   nOldMode := sMode
   IF HB_ISNUMERIC( nMode ) .AND. nMode <= 1 .AND. nMode >= 0
      sMode := nMode
   ENDIF

   RETURN nOldMode

FUNCTION wvt_MakeDlgTemplate( nTop, nLeft, nRows, nCols, aOffSet, cTitle, nStyle, ;
      cFaceName, nPointSize, nWeight, lItalic, nHelpId, nExStyle )

   LOCAL aDlg := { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} }
   LOCAL aXY, nX, nY, nW, nH, nXM, nYM
   LOCAL nBaseUnits, nBaseUnitsX, nBaseUnitsY
   LOCAL aFont
   LOCAL nMode := wvt_SetDlgCoMode()

   aFont := wvt_GetFontInfo()

   IF nMode == 0
      __defaultNIL( @aOffSet, {} )
      ASize( aOffSet, 4 )
      __defaultNIL( @aOffSet[ 1 ], 0 )
      __defaultNIL( @aOffSet[ 2 ], 0 )
      __defaultNIL( @aOffSet[ 3 ], 0 )
      __defaultNIL( @aOffSet[ 4 ], 0 )

      nBaseUnits  := wvg_GetDialogBaseUnits()
      nBaseUnitsX := wvg_LOWORD( nBaseUnits )
      nBaseUnitsY := wvg_HIWORD( nBaseUnits )

      nW := aFont[ 7 ]
   AAdd( aDlg[ 1 ], iif( HB_ISSTRING( cTitle ), cTitle, "" ) )

   IF hb_bitAnd( nStyle, DS_SETFONT ) == DS_SETFONT
      AAdd( aDlg[ 1 ], iif( HB_ISNUMERIC( nPointSize ), nPointSize, 8 ) )
      AAdd( aDlg[ 1 ], iif( HB_ISNUMERIC( nWeight    ), nWeight, 400 ) )
      AAdd( aDlg[ 1 ], iif( HB_ISLOGICAL( lItalic    ), lItalic, .F. ) )
      AAdd( aDlg[ 1 ], iif( HB_ISSTRING(  cFaceName  ), cFaceName, "MS Sans Serif" ) )
   ENDIF

   RETURN aDlg

FUNCTION wvt_AddDlgItem( aDlg, nTop, nLeft, nRows, nCols, aOffSet, ;
      cnId, cnDlgClass, nStyle, cText, nHelpId, nExStyle )

   LOCAL aXY, nX, nY, nW, nH, nXM, nYM
   LOCAL nBaseUnits, nBaseUnitsX, nBaseUnitsY
   LOCAL nBottom, nRight
   LOCAL nMode := wvt_SetDlgCoMode()

   IF nMode == 0
      nBottom := nTop  + nRows - 1
      nRight  := nLeft + nCols - 1

      __defaultNIL( @aOffSet, {} )

      ASize( aOffSet, 4 )

      __defaultNIL( @aOffSet[ 1 ], 0 )
      __defaultNIL( @aOffSet[ 2 ], 0 )
      __defaultNIL( @aOffSet[ 3 ], 0 )
      __defaultNIL( @aOffSet[ 4 ], 0 )

      nBaseUnits  := wvg_GetDialogBaseUnits()
      nBaseUnitsX := wvg_LOWORD( nBaseUnits )
      nBaseUnitsY := wvg_HIWORD( nBaseUnits )

      aXY := wvt_GetXYFromRowCol( nTop, nLeft )
      nX  := aXY[ 1 ] + aOffSet[ 2 ]
      nY  := aXY[ 2 ] + aOffSet[ 1 ]

      aXY := wvt_GetXYFromRowCol( nBottom + 1, nRight + 1 )
      nW  := aXY[ 1 ] + aOffSet[ 4 ] - nX
      nH  := aXY[ 2 ] + aOffSet[ 3 ] - nY

      nXM :=  5.25
      nYM := 10.25

      nX := nX
   AAdd( aDlg[ 11 ], iif( HB_ISSTRING( cText ), cText, iif( HB_ISNUMERIC( cText ), cText, "" ) ) )
   AAdd( aDlg[ 12 ], 0 )

   RETURN aDlg

FUNCTION wvt_CreateDialog( acnDlg, lOnTop, cbDlgProc, ncIcon, nTimerTicks, hMenu )

   LOCAL hDlg, cType, xTemplate, nDlgMode

   IF HB_ISSTRING( cbDlgProc )
      cbDlgProc := Upper( cbDlgProc )
   ENDIF

   cType    := ValType( acnDlg )
   nDlgMode := iif( cType == "C", 0, iif( cType == "N", 1, 2 ) )

   IF cType == "A"
      xTemplate := wvt__MakeDlgTemplate( acnDlg[ 1 ], acnDlg[  2 ], acnDlg[  3 ], acnDlg[  4 ], ;
         acnDlg[ 5 ], acnDlg[  6 ], acnDlg[  7 ], acnDlg[  8 ], ;
         acnDlg[ 9 ], acnDlg[ 10 ], acnDlg[ 11 ], acnDlg[ 12 ] )
   ELSE
      xTemplate := acnDlg
   ENDIF

   hDlg := wvt_CreateDialogDynamic( xTemplate, lOnTop, cbDlgProc, nDlgMode )

   IF hDlg != 0
      IF ncIcon != NIL
         wvt_DlgSetIcon( hDlg, ncIcon )
      ENDIF

      IF HB_ISNUMERIC( nTimerTicks )
         wvg_SetTimer( hDlg, 1001, nTimerTicks )
      ENDIF

      IF hMenu != NIL
         wvg_SetMenu( hDlg, hMenu )
      ENDIF
   ENDIF

   RETURN hDlg

FUNCTION wvt_DialogBox( acnDlg, cbDlgProc, hWndParent )

   LOCAL nResult, cType, xTemplate, nDlgMode

   IF HB_ISSTRING( cbDlgProc )
      cbDlgProc := Upper( cbDlgProc )
   ENDIF

   cType    := ValType( acnDlg )
   nDlgMode := iif( cType == "C", 0, iif( cType == "N", 1, 2 ) )

   IF cType == "A"
      xTemplate := wvt__MakeDlgTemplate( acnDlg[ 1 ], acnDlg[  2 ], acnDlg[  3 ], acnDlg[  4 ], ;
         acnDlg[ 5 ], acnDlg[  6 ], acnDlg[  7 ], acnDlg[  8 ], ;
         acnDlg[ 9 ], acnDlg[ 10 ], acnDlg[ 11 ], acnDlg[ 12 ] )


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour contribution module 'hbct' (CA-Tools compatibility library): contrib/hbct/tests/wordrem.prg. Contains procedures: Main. This file provides legacy compatibility functions

[Assistant]
#ifdef __HARBOUR__
#require "hbct"
#endif

PROCEDURE Main()

   ctinit()

   ? "Begin test of WordRem()"
   ?

   ? "Simple tests:"
   ? '  WordRem( "abcd", "0ab1cd" ) == "0ab1" ? ----> "' + WordRem( "abcd", "0ab1cd" ) + '"'
   ? '  WordRem( "abcd", "ab0cd1" ) == "0cd1" ? ----> "' + WordRem( "abcd", "ab0cd1" ) + '"'
   ?

   ? "End test of WordRem()"
   ?

   ctexit()

   RETURN


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement these Harbour functions: Harbour contribution module 'hbmisc' (Miscellaneous utility functions): contrib/hbmisc/tests/pe.prg. Provides functions: MyMemoEdit, Example_Text, Example_Text_Raw. Contains procedures: Main. This file provides utility functions

[Assistant]
#require "hbmisc"

PROCEDURE Main( cFile )

   LOCAL cText
   LOCAL lEdit := .T.

   IF cFile == NIL
      cText := Example_Text()
   ELSE
      IF hb_FileMatch( cFile, __FILE__ )
         lEdit := .F.
      ENDIF
      cText := MemoRead( cFile )
   ENDIF

   cText := MyMemoEdit( cText, 0, 0, MaxRow(), MaxCol(), lEdit )
   hb_MemoWrit( hb_FNameExtSet( __FILE__, ".out" ), cText )

   RETURN

STATIC FUNCTION MyMemoEdit( cText, nTop, nLeft, nBottom, nRight, lEdit )

   LOCAL oED

   oED := EditorNew( nTop, nLeft, nBottom, nRight, 254, , , , Len( cText )
      ? "Editor not created"
   ENDIF

   RETURN cText

STATIC FUNCTION Example_Text()
   RETURN StrTran( Example_Text_Raw(), "~", hb_BChar( 168 ) )

STATIC FUNCTION Example_Text_Raw()
#pragma __cstream | RETURN %s

 ~2Lorem ipsum dolor sit amet, consectetur adipiscing elit.~1
~3 ========================================================

 Integer a dolor eu lorem luctus cursus. Proin varius dui quis felis.
 Sed vitae lacus ac mauris cursus vehicula. Nulla sodales fringilla
 lorem. Praesent odio mi, interdum eget, facilisis et, elementum
 luctus, enim. Vivamus sed est. Cras leo dolor, mollis et, suscipit
 sed, interdum ac, elit. Phasellus cursus, arcu nec bibendum cursus,
 dolor mi vestibulum leo, ut cursus orci sem id dolor. Morbi porttitor
 libero nec risus. Duis diam justo, blandit sed, fermentum eu,
 consectetur at, arcu. Quisque felis ipsum, facilisis quis, ultrices
 sed, venenatis aliquam, urna. Cras sit amet risus. Pellentesque
 dictum. In hac habitasse platea dictumst.

 Nunc odio elit, mattis et, rutrum id, faucibus vitae, ipsum. Donec
 aliquet sem sed augue. Aliquam erat volutpat. Etiam ultrices, metus
 a tristique ornare, tellus urna congue nunc, vitae iaculis risus
 enim quis magna.

~5This file have to be separated with CR/LF characters~1
#pragma __endtext


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour test program: tests/big5_gen.prg. Provides functions: array_to_code, hash_to_array, min_size, calc_size, conv_get. This test file tests specific function APIs

[Assistant]
proc main()
   local cLine, aVal, aVal2, aValU, aValU2, hVal, aInd, ;
         n, nn, nBG5, nU16, nMin, nMax, nUMin, nUMax, cResult, nBit

   aVal  := afill( array( 0x10000 ), 0 )
   aValU := afill( array( 0x10000 ), 0 )
   nMin  := nUMin := 0xFFFF
   nMax  := nUMax := 0x0000

   for each cLine in hb_aTokens( hb_memoRead( "BIG5.TXT" ), hb_eol() )
      if cLine = "0x" .and. ( n := hb_at( "0x", cLine, 7 ) ) != 0
         nBG5 := hb_hexToNum( substr( cLine, 3, 4 ) )
         nU16 := hb_hexToNum( substr( cLine, n + 2, 4 ) )
         if nBG5 == 0 .or. nU16 == 0
            ? "unrecognized line:", cLine:__enumIndex()
            return
         elseif nBG5 > 0xFFFF .or. nU16 > 0xFFFF
            ? "wrong character range at line:", cLine:__enumIndex()
            return
         endif
         aVal[ nBG5 ] := nU16
         if nBG5 > nMax
            nMax := nBG5
         endif
         if nBG5 < nMin
            nMin := nBG5
         endif
         if nU16 > nUMax
            nUMax := nU16
         endif
         if nU16 < nUMin
            nUMin := nU16
         endif
      endif
   next

   for n := 1 to len( aVal )
      if aVal[ n ] != 0
         aValU[ aVal[ n ] ] := n
      endif
   next

   ? "BIG5->UCS16 tables."
   ? "raw size:", hb_ntos( ( nMax - nMin + 1 )
   ? "minimal size:", hb_ntos( n ), ;
     "for", hb_ntos( hb_bitshift( 1, nBit ) ), "byte blocks, (from: "+hb_ntos( nMin ) + ")"
   calc_size( aVal, nMin, nMax, nBit, @hVal, @aInd, @nn )
   aVal2 := hash_to_array( hVal )

   cResult := ;
      "" + hb_eol() + ;
       hb_eol()

   cResult += '#include "hbapi.h"' + hb_eol()
   cResult += hb_eol()
   cResult += "#define HB_BIG5_FIRST   0x" + hb_numToHex( nMin, 4 ) + hb_eol()
   cResult += "#define HB_BIG5_LAST    0x" + hb_numToHex( nMax, 4 ) + hb_eol()
   cResult += "#define HB_BIG5_BITS    " + hb_ntos( nBit ) + hb_eol()
   cResult += hb_eol()

   cResult += array_to_code( aInd, "s_big5index", nn )
   cResult += hb_eol()
   cResult += array_to_code( aVal2, "s_big5_ucs16", 2 )
   cResult += hb_eol()
   cResult += index_func( "s_big5_to_ucs16", "s_big5index", "s_big5_ucs16", ;
                          "HB_BIG5_FIRST", "HB_BIG5_LAST", "HB_BIG5_BITS" )

   check_conv( aVal, aInd, aVal2, nMin, nMax, nBit )

   ?
   ? "UCS16->BIG5 tables."
   ? "raw size:", hb_ntos( ( nUMax - nUMin + 1 )
   ? "minimal size:", hb_ntos( n ), ;
     "for", hb_ntos( hb_bitshift( 1, nBit ) ), "byte blocks, (from: "+hb_ntos( nUMin ) + ")"
   calc_size( aValU, nUMin, nUMax, nBit, @hVal, @aInd, @nn )
   aValU2 := hash_to_array( hVal )

   cResult += hb_eol()
   cResult += "#define HB_U16_FIRST    0x" + hb_numToHex( nUMin, 4 ) + hb_eol()
   cResult += "#define HB_U16_LAST     0x" + hb_numToHex( nUMax, 4 ) + hb_eol()
   cResult += "#define HB_U16_BITS     " + hb_ntos( nBit ) + hb_eol()
   cResult += hb_eol()
   cResult += array_to_code( aInd, "s_ucs16index", nn )
   cResult += hb_eol()
   cResult += array_to_code( aValU2, "s_ucs16_big5", 2 )
   cResult += hb_eol()
   cResult += index_func( "s_ucs16_to_big5", "s_ucs16index", "s_ucs16_big5", ;
                          "HB_U16_FIRST", "HB_U16_LAST", "HB_U16_BITS" )

   check_conv( aValU, aInd, aValU2, nUMin, nUMax, nBit )

   hb_memowrit( "big5.c", cResult )
return

static function array_to_code( aVal, cName, nn )
   local cResult, l, n

   cResult := "static const " + ;
              iif( nn == 1, "HB_BYTE", "HB_USHORT" ) + " " + ;
              cName + "[ " + hb_ntos( len( aVal ) ) + " ] =" + hb_eol()
   cResult += "{" + hb_eol()
   l := 0
   for n := 1 to len( aVal )
      if ++l > iif( nn == 1, 12, 8 )
         l := 1
         cResult += ","
         cResult += hb_eol()
         cResult += "   "
      elseif n == 1
         cResult += "   "
      else
         cResult += ", "
      endif
      cResult += "0x"
      cResult += hb_numToHex( aVal[ n ], nn
   cResult += "};" + hb_eol()
return cResult;

static function hash_to_array( hVal )
   local aVal := {}, cLine, n
   for each cLine in hVal
      for n := 1 to len( cLine ) step( 2 )
         aadd( aVal, bin2w( substr( cLine, n, 2 ) ) )
      next
   next
return aVal

function min_size( aVal, nMin, nMax, nBit )
   local n, nM, nS, nSize, nMinX
   nSize := 0xFFFFFF
   nMinX := nMin
#ifdef DO_START_OPT
   for nM := hb_bitAnd( nMin, 0xFF00 ) to nMin
#else
   for nM := nMin to nMin
#endif
      for n := 1 to 16
         nS := calc_size( aVal, nM, nMax, n )
         if nS < nSize
            nSize := nS
            nBit := n
            nMinX := nM
         endif
      next
   next
   nMin := nMinX
return nSize

function calc_size( aVal, nMin, nMax, nBit, hVal, aInd, nn )
   local nLine, n, cLine, c

   nLine := int( 2 ^ nBit )

   cLine := ""
   hVal := {=>}
   aInd := {}
   for n := nMin to nMax
      cLine += i2bin( iif( n == 0, 0, aVal[ n ] ) )
      if len( cLine ) == nLine
         cLine := ""
      endif
   next
   if ! cLine == ""
      for each c in hVal
         if c = cLine
            cLine := c
            exit
         endif
      next
      hVal[ cLine ] := cLine
      aadd( aInd, hb_hpos( hVal, cLine ) - 1 )
   endif
   nn := iif( len( aInd ) > 256, 2, 1 )
   n := len( aInd )
   cResult := "static HB_USHORT " + cName + "( int n )" + hb_eol() + ;
              "{" + hb_eol() + ;
              "   n -= " + cMin + ";" + hb_eol() + ;
              "   if( n >= 0 && n <= ( " + cMax + " - " + cMin + " ) )" + hb_eol() + ;
              "   {" + hb_eol() + ;
              "      return " + cNameConv + "[ ( " + cNameInd + ;
                     "[ n >> " + cBit + " ] << " + cBit + " ) +" + hb_eol() + ;
              space( len( cNameConv ) + 15 ) + ;
                     "( n & ( ( 1 << " + cBit + " ) - 1 ) ) ];" + hb_eol() + ;
              "   }" + hb_eol() + ;
              "   return 0;" + hb_eol() + ;
              "}" + hb_eol()

return cResult

static function conv_get( n, aInd, aVal2, nMin, nMax, nBit )
   local nDiv
   if n >= nMin .and. n <= nMax
      nDiv := 2 ^ nBit
      n -= nMin
      return aVal2[ aInd[ n / nDiv + 1 ]
         ? "Wrong decoding:", n, aVal[ n ], nVal, len( aVal ), nMax, hb_eol()
         break
      endif
   next
return nil


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Harbour Runtime Library file: src/debug/tbrwtext.prg. Defines classes: HBBrwText. This file provides utility functions

[Assistant]
#pragma -b-

#define HB_CLS_NOTOBJECT
#include "hbclass.ch"

CREATE CLASS HBBrwText

   VAR cFileName
   VAR aRows
   VAR nRows
   VAR nLineNoLen
   VAR nActiveLine
   VAR lLineNumbers
   VAR nRow
   VAR nFirstCol
   VAR nCol

   VAR oBrw

   VAR nLineOffset   INIT 1
   VAR nMaxLineLen
   VAR nTabWidth     INIT 4

   VAR nTop
   VAR nLeft
   VAR nBottom
   VAR nRight

   VAR nWidth
   VAR nHeight

   METHOD New( nTop, nLeft, nBottom, nRight, cFileName, cColors, lLineNumbers )

   METHOD RefreshAll() INLINE ::oBrw:ForceStable():RefreshAll(), Self
   METHOD ForceStable() INLINE ::oBrw:ForceStable(), Self
   METHOD RefreshCurrent() INLINE ::oBrw:RefreshCurrent(), Self
   METHOD GotoLine( n )
   METHOD SetActiveLine( n )
   METHOD GetLine()
   METHOD GetLineText()
   METHOD GetLineColor()
   METHOD Search( cString, lCaseSensitive, nMode )

   METHOD GoFirst()
   METHOD GoLast()
   METHOD Skip( n )
   METHOD GoNext()
   METHOD GoPrev()

   METHOD Resize( nTop, nLeft, nBottom, nRight )

   METHOD Up() INLINE ::oBrw:Up():ForceStable(), Self
   METHOD Down() INLINE ::oBrw:Down():ForceStable(), Self
   METHOD PageUp() INLINE ::oBrw:PageUp():ForceStable(), Self
   METHOD PageDown() INLINE ::oBrw:PageDown():ForceStable(), Self
   METHOD GoTop() INLINE ::oBrw:GoTop():ForceStable(), Self
   METHOD GoBottom() INLINE ::oBrw:GoBottom():ForceStable(), Self

   METHOD Home() INLINE iif( ::nLineOffset > 1, ( ::nLineOffset := 1, ::oBrw:RefreshAll():ForceStable() ), ), Self
   METHOD End() INLINE ::nLineOffset := Max( 1, ::nMaxLineLen - ( ::nWidth - iif( ::lLineNumbers, ::nLineNoLen, 0 ) ) + 1 ), ::oBrw:RefreshAll():ForceStable(), Self

   METHOD Right() INLINE iif( ::nLineOffset < ::nMaxLineLen + iif( ::lLineNumbers, ::nLineNoLen, 0 ), ( ::nLineOffset++, ::oBrw:RefreshAll():ForceStable() ), ), Self
   METHOD Left() INLINE iif( ::nLineOffset > 1, ( ::nLineOffset--, ::oBrw:RefreshAll():ForceStable() ), ), Self

   METHOD RowPos() INLINE ::nRow

   METHOD LoadFile( cFileName )

   VAR colorSpec IS colorSpec IN oBrw

ENDCLASS

METHOD New( nTop, nLeft, nBottom, nRight, cFileName, cColors, lLineNumbers ) CLASS HBBrwText

   LOCAL oCol

   ::nTop := nTop
   ::nLeft := nLeft
   ::nBottom := nBottom
   ::nRight := nRight

   ::nWidth := nRight - nLeft + 1
   ::nHeight := nBottom - nTop

   ::lLineNumbers := lLineNumbers

   ::oBrw := HBDbBrowser():New( ::nTop, ::nLeft, ::nBottom, ::nRight )

   ::oBrw:colorSpec := cColors

   oCol := HBDbColumnNew( "", {|| ::GetLineText() } )

   oCol:colorBlock := {|| ::GetLineColor() }

   ::oBrw:AddColumn( oCol )

   ::oBrw:goTopBlock := {|| ::nRow := 1 }
   ::oBrw:goBottomBlock := {|| ::nRow := ::nRows }
   ::oBrw:skipBlock := {| n | ::Skip( n ) }

   IF ! Empty( cFileName )
      ::LoadFile( cFileName )
   ENDIF

   RETURN Self

METHOD GotoLine( n ) CLASS HBBrwText

   ::oBrw:MoveCursor( n - ::nRow )
   ::RefreshAll()

   RETURN Self

METHOD SetActiveLine( n ) CLASS HBBrwText

   ::nActiveLine := n
   ::RefreshAll()

   RETURN Self

METHOD GetLine() CLASS HBBrwText
   RETURN iif( ::lLineNumbers, PadR( hb_ntos( ::nRow ) + ":", ::nLineNoLen ), "" ) + ;
      MemoLine( ::aRows[ ::nRow ], ::nMaxLineLen, 1, ::nTabWidth, .F. )

METHOD GetLineText() CLASS HBBrwText
   RETURN PadR( SubStr( ::GetLine(), ::nLineOffset ), ::nWidth )

METHOD GetLineColor() CLASS HBBrwText

   LOCAL aColor

   IF __dbgIsBreak( __dbg():pInfo, ::cFileName, ::nRow ) >= 0
      aColor := iif( ::nRow == ::nActiveLine, { 4, 4 }, { 3, 3 } )
   ELSE
      aColor := iif( ::nRow == ::nActiveLine, { 2, 2 }, { 1, 1 } )
   ENDIF

   RETURN aColor

METHOD PROCEDURE LoadFile( cFileName ) CLASS HBBrwText

   LOCAL nMaxLineLen := 0
   LOCAL cLine

   ::cFileName := cFileName
   ::aRows := __dbgTextToArray( MemoRead( cFileName ) )
   ::nRows := Len( ::aRows )
   ::nLineNoLen := Len( hb_ntos( ::nRows ) ) + 2

   FOR EACH cLine IN ::aRows
      nMaxLineLen := Max( nMaxLineLen, ;
         Len( RTrim( MemoLine( cLine, Len( cLine ) + 256, 1, ::nTabWidth, .F. ) ) ) )
   NEXT
   ::nMaxLineLen := nMaxLineLen
   ::nLineOffset := 1

   RETURN

METHOD Resize( nTop, nLeft, nBottom, nRight ) CLASS HBBrwText

   LOCAL lResize := .F.

   IF HB_ISNUMERIC( nTop ) .AND. nTop != ::nTop
      ::nTop := nTop
      lResize := .T.
   ENDIF
   IF HB_ISNUMERIC( nLeft ) .AND. nLeft != ::nLeft
      ::nLeft := nLeft
      lResize := .T.
   ENDIF
   IF HB_ISNUMERIC( nBottom ) .AND. nBottom != ::nBottom
      ::nBottom := nBottom
      lResize := .T.
   ENDIF
   IF HB_ISNUMERIC( nRight ) .AND. nRight != ::nRight
      ::nRight := nRight
      lResize := .T.
   ENDIF
   IF lResize
      ::oBrw:Resize( nTop, nLeft, nBottom, nRight )
      ::nWidth := ::nRight - ::nLeft + 1
   ENDIF

   RETURN Self

METHOD Search( cString, lCaseSensitive, nMode ) CLASS HBBrwText

   LOCAL bMove
   LOCAL lFound := .F.
   LOCAL n

   IF ! lCaseSensitive
      cString := Upper( cString )
   ENDIF

   SWITCH hb_defaultValue( nMode, 0 )
   CASE 0
      ::GoTop()
      bMove := {|| ::Skip( 1 ) }
      EXIT
   CASE 1
      bMove := {|| ::Skip( 1 ) }
      EXIT
   CASE 2
      bMove := {|| ::Skip( -1 ) }
      EXIT
   ENDSWITCH

   n := ::nRow

   DO WHILE Eval( bMove ) != 0
      IF cString $ iif( lCaseSensitive, ::aRows[ ::nRow ], Upper( ::aRows[ ::nRow ] ) )
         lFound := .T.
         ::oBrw:MoveCursor( ::nRow - n )
         ::RefreshAll()
         EXIT
      ENDIF
   ENDDO

   RETURN lFound

METHOD GoFirst() CLASS HBBrwText

   ::nRow := 1

   RETURN .T.

METHOD GoLast() CLASS HBBrwText

   ::nRow := ::nRows

   RETURN .T.

METHOD Skip( n ) CLASS HBBrwText

   LOCAL nSkipped := 0

   IF n > 0
      IF ::nRow < ::nRows
         nSkipped := Min( ::nRows - ::nRow, n )
         ::nRow += nSkipped
      ENDIF
   ELSEIF n < 0
      IF ::nRow > 1
         nSkipped := Max( 1 - ::nRow, n )
         ::nRow += nSkipped
      ENDIF
   ENDIF

   RETURN nSkipped

METHOD GoPrev() CLASS HBBrwText

   LOCAL lMoved := .F.

   IF ::nRow > 1
      ::nRow--
      lMoved := .T.
   ENDIF

   RETURN lMoved

METHOD GoNext() CLASS HBBrwText

   LOCAL lMoved := .F.

   IF ::nRow < ::nRows
      ::nRow++
      lMoved := .T.
   ENDIF

   RETURN lMoved


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Create Harbour preprocessor definitions: Header file for contribution module 'hbpgsql' (PostgreSQL database client library): contrib/hbpgsql/postgres.ch. Defines 10 constants including: HBPOSTGRES_CH_, CONNECTION_OK, CONNECTION_BAD, CONNECTION_STARTED, CONNECTION_MADE. Defines error handling constants and codes

[Assistant]
#ifndef HBPOSTGRES_CH_
#define HBPOSTGRES_CH_

#define CONNECTION_OK                   0
#define CONNECTION_BAD                  1
#define CONNECTION_STARTED              2
#define CONNECTION_MADE                 3
#define CONNECTION_AWAITING_RESPONSE    4
#define CONNECTION_AUTH_OK              5
#define CONNECTION_SETENV               6
#define CONNECTION_SSL_STARTUP          7
#define CONNECTION_NEEDED               8

#define PGRES_POLLING_FAILED            0
#define PGRES_POLLING_READING           1
#define PGRES_POLLING_WRITING           2
#define PGRES_POLLING_OK                3
#define PGRES_POLLING_ACTIVE            4

#define PGRES_EMPTY_QUERY               0
#define PGRES_COMMAND_OK                1
#define PGRES_TUPLES_OK                 2
#define PGRES_COPY_OUT                  3
#define PGRES_COPY_IN                   4
#define PGRES_BAD_RESPONSE              5
#define PGRES_NONFATAL_ERROR            6
#define PGRES_FATAL_ERROR               7

#define PQTRANS_IDLE                    0
#define PQTRANS_ACTIVE                  1
#define PQTRANS_INTRANS                 2
#define PQTRANS_INERROR                 3
#define PQTRANS_UNKNOWN                 4

#define HBPG_META_FIELDNAME             1
#define HBPG_META_FIELDTYPE             2
#define HBPG_META_FIELDLEN              3
#define HBPG_META_FIELDDEC              4
#define HBPG_META_TABLE                 5
#define HBPG_META_TABLECOL              6
#define HBPG_META_LEN_                  6

#define PQERRORS_TERSE                  0
#define PQERRORS_DEFAULT                1
#define PQERRORS_VERBOSE                2

#define PQPING_OK                       0
#define PQPING_REJECT                   1
#define PQPING_NO_RESPONSE              2
#define PQPING_NO_ATTEMPT               3

#define PG_DIAG_SEVERITY                hb_BCode( "S" )
#define PG_DIAG_SQLSTATE                hb_BCode( "C" )
#define PG_DIAG_MESSAGE_PRIMARY         hb_BCode( "M" )
#define PG_DIAG_MESSAGE_DETAIL          hb_BCode( "D" )
#define PG_DIAG_MESSAGE_HINT            hb_BCode( "H" )
#define PG_DIAG_STATEMENT_POSITION      hb_BCode( "P" )
#define PG_DIAG_INTERNAL_POSITION       hb_BCode( "p" )
#define PG_DIAG_INTERNAL_QUERY          hb_BCode( "q" )
#define PG_DIAG_CONTEXT                 hb_BCode( "W" )
#define PG_DIAG_SCHEMA_NAME             hb_BCode( "s" )
#define PG_DIAG_TABLE_NAME              hb_BCode( "t" )
#define PG_DIAG_COLUMN_NAME             hb_BCode( "c" )
#define PG_DIAG_DATATYPE_NAME           hb_BCode( "d" )
#define PG_DIAG_CONSTRAINT_NAME         hb_BCode( "n" )
#define PG_DIAG_SOURCE_FILE             hb_BCode( "F" )
#define PG_DIAG_SOURCE_LINE             hb_BCode( "L" )
#define PG_DIAG_SOURCE_FUNCTION         hb_BCode( "R" )

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Write Harbour functions: StrToHtml. Harbour extra library: extras/hbxlsxml/xlsxml.prg. Defines classes: ExcelWriterXML. Provides functions: StrToHtml. This file provides spreadsheet generation capabilities

[Assistant]
#include "hbclass.ch"
#include "fileio.ch"

CREATE CLASS ExcelWriterXML

   VAR    styles                                  INIT {}
   VAR    formatErrors                            INIT { => }
   VAR    sheets                                  INIT {}
   VAR    lShowErrorSheet                         INIT .F.
   VAR    overwriteFile                           INIT .F.
   VAR    docFileName
   VAR    cDocTitle
   VAR    cDocSubject
   VAR    cDocAuthor
   VAR    cDocCreated
   VAR    cDocManager
   VAR    cDocCompany
   VAR    cDocVersion                             INIT "11.9999"

   VAR    cError                                  INIT ""
   VAR    errors                                  INIT .F.

   METHOD New( fileName )
   METHOD setOverwriteFile( overwrite )
   METHOD showErrorSheet( show )
   METHOD addError( cFunction, cMessage )
   METHOD getDefaultStyle()
   METHOD addStyle( id )
   METHOD addSheet( id )
   METHOD checkSheetID( id )
   METHOD checkStyleID( id )
   METHOD writeData( target )
   METHOD docTitle( title )
   METHOD docSubject( subject )
   METHOD docAuthor( author )
   METHOD docManager( manager )
   METHOD docCompany( company )

ENDCLASS

METHOD ExcelWriterXML:new( fileName )

   LOCAL style

   style := ::addStyle( "DEFAULT" )
   style:name( "Normal" )
   style:alignVertical( "Bottom" )

   IF Empty( fileName )
      fileName := "file.xml"
   ENDIF

   ::docFileName := fileName
   ::cDocCreated := DToS( Date() ) + "T" + Time() + "Z"

   RETURN SELF

METHOD ExcelWriterXML:setOverwriteFile( overwrite )

   hb_default( @overwrite, .F. )

   ::overwriteFile := overwrite

   RETURN NIL

METHOD ExcelWriterXML:showErrorSheet( show )

   hb_default( @show, .T. )

   ::lShowErrorSheet := show

   RETURN NIL

METHOD ExcelWriterXML:addError( cFunction, cMessage )

   ::formatErrors += { ;
      "FUNCTION" => cFunction, ;
      "MESSAGE"  => cMessage  }

   RETURN NIL

METHOD ExcelWriterXML:getDefaultStyle()

   RETURN ::styles[ 1 ]

METHOD ExcelWriterXML:addStyle( id )

   LOCAL style

   STATIC s_styleNum := 1

   IF Empty( id )
      id := NIL
   ENDIF

   IF id == NIL
      id := "CustomStyle" + hb_ntos( s_styleNum )
      s_styleNum++
   ENDIF

   WHILE ! ::checkStyleID( id )
      id := "CustomStyle" + hb_ntos( s_styleNum )
      s_styleNum++
   ENDDO

   style := ExcelWriterXML_Style():new( id )
   AAdd( ::styles, style )

   RETURN style

METHOD ExcelWriterXML:addSheet( id )

   LOCAL sheet

   STATIC s_sheetNum := 1

   IF id == NIL
      id := "Sheet" + hb_ntos( s_sheetNum )
      s_sheetNum++
   ENDIF

   WHILE ! ::checkSheetID( id )
      id := "Sheet" + hb_ntos( s_sheetNum )
      s_sheetNum++
   ENDDO

   sheet := ExcelWriterXML_Sheet():New( id )
   AAdd( ::sheets, sheet )

   RETURN sheet

METHOD ExcelWriterXML:checkSheetID( id )

   LOCAL sheet

   IF Len( ::sheets ) > 0
      FOR EACH sheet IN ::sheets
         IF id == sheet:getID()
            RETURN .F.
         ENDIF
      NEXT
   ELSE
      RETURN .T.
   ENDIF

   RETURN .T.

METHOD ExcelWriterXML:checkStyleID( id )

   LOCAL style

   IF Len( ::styles ) > 0
      FOR EACH style IN ::styles
         IF id == style:getID()
            RETURN .F.
         ENDIF
      NEXT
   ELSE
      RETURN .T.
   ENDIF

   RETURN .T.

METHOD ExcelWriterXML:writeData( target )

   LOCAL style, sheet, xml := "", handle, fileExists, format

   LOCAL docTitle   := ""
   LOCAL docSubject := ""
   LOCAL docAuthor  := ""
   LOCAL docCreated := ""
   LOCAL docManager := ""
   LOCAL docCompany := ""

   IF target == NIL
      ::cError := "Target filename missing!"
      ::errors := .T.
      RETURN .T.
   ENDIF

   fileExists := hb_FileExists( target )
   IF fileExists .AND. ! ::overwriteFile
      ::cError := target + " exists and overwriteFile is set to false"
      ::errors := .T.
      RETURN .F.
   ENDIF
   handle := hb_FCreate( target, FC_NORMAL, FO_EXCLUSIVE )
   IF handle == F_ERROR
      ::cError := "Not able to open " + target + " for writing"
      ::errors := .T.
      RETURN .F.
   ENDIF

   IF ::lShowErrorSheet
      format := ::addStyle( "formatErrorsHeader" )
      format:setFontBold()
      format:bgColor( "red" )
   ENDIF

   IF ! Empty( ::cDocTitle   ); docTitle   := "<Title>"   + StrToHtmlSpecial( ::cDocTitle   ) + "</Title>"   + hb_eol(); ENDIF
   IF ! Empty( ::cDocSubject ); docSubject := "<Subject>" + StrToHtmlSpecial( ::cDocSubject ) + "</Subject>" + hb_eol(); ENDIF
   IF ! Empty( ::cDocAuthor  ); docAuthor  := "<Author>"  + StrToHtmlSpecial( ::cDocAuthor  ) + "</Author>"  + hb_eol(); ENDIF
   IF ! Empty( ::cDocCreated ); docCreated := "<Created>" + StrToHtmlSpecial( ::cDocCreated ) + "</Created>" + hb_eol(); ENDIF
   IF ! Empty( ::cDocManager ); docManager := "<Manager>" + StrToHtmlSpecial( ::cDocManager ) + "</Manager>" + hb_eol(); ENDIF
   IF ! Empty( ::cDocCompany ); docCompany := "<Company>" + StrToHtmlSpecial( ::cDocCompany ) + "</Company>" + hb_eol(); ENDIF

   xml := '<?xml version="1.0"?>' + hb_eol()
   xml += '<?mso-application progid="Excel.Sheet"?>' + hb_eol()
   xml += "<Workbook" + hb_eol()
   xml += 'xmlns="urn:schemas-microsoft-com:office:spreadsheet"' + hb_eol()
   xml += 'xmlns:o="urn:schemas-microsoft-com:office:office"' + hb_eol()
   xml += 'xmlns:x="urn:schemas-microsoft-com:office:excel"' + hb_eol()
   xml += 'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"' + hb_eol()
   xml += 'xmlns:html="http:
   xml += '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">' + hb_eol()
   IF ! Empty( ::cDocTitle   ); xml += "   " + docTitle  ; ENDIF
   IF ! Empty( ::cDocSubject ); xml += "   " + docSubject; ENDIF
   IF ! Empty( ::cDocAuthor  ); xml += "   " + docAuthor ; ENDIF
   IF ! Empty( ::cDocCreated ); xml += "   " + docCreated; ENDIF
   IF ! Empty( ::cDocManager ); xml += "   " + docManager; ENDIF
   IF ! Empty( ::cDocCompany ); xml += "   " + docCompany; ENDIF
   xml += "   <Version>" + ::cDocVersion + "</Version>" + hb_eol()
   xml += "</DocumentProperties>" + hb_eol()
   xml += '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel" />' + hb_eol()
   xml += "<Styles>" + hb_eol()

   FWrite( handle, xml )
   xml := ""

   FOR EACH style IN ::styles
      xml += style:getStyleXML()
   NEXT
   xml += "</Styles>" + hb_eol()

   FWrite( handle, xml )
   xml := ""

   IF Len( ::sheets ) == 0
      ::addSheet()
   ENDIF
   IF Len( ::sheets ) > 0
      FOR EACH sheet IN ::sheets
         xml += sheet:getSheetXML( handle )
         IF Len( sheet:getErrors() ) > 0
            ::errors := .T.
         ENDIF
      NEXT
   ENDIF
   IF Len( ::formatErrors ) > 0
      ::errors := .T.
   ENDIF

   xml += "</Workbook>"

   FWrite( handle, xml )
   xml := ""
   FClose( handle )

   RETURN .T.

METHOD ExcelWriterXML:docTitle( title )

   IF HB_ISSTRING( title )
      ::cDocTitle := title
   ENDIF

   RETURN NIL

METHOD ExcelWriterXML:docSubject( subject )

   IF HB_ISSTRING( subject )
      ::cDocSubject := subject
   ENDIF

   RETURN NIL

METHOD ExcelWriterXML:docAuthor( author )

   IF HB_ISSTRING( author )
      ::cDocAuthor := author
   ENDIF

   RETURN NIL

METHOD ExcelWriterXML:docManager( manager )

   IF HB_ISSTRING( manager )
      ::cDocManager := manager
   ENDIF

   RETURN NIL

METHOD ExcelWriterXML:docCompany( company )

   IF HB_ISSTRING( company )
      ::cDocCompany := company
   ENDIF

   RETURN NIL

FUNCTION StrToHtml( xtxt )

   LOCAL afrm, i, xret := "", xpos

   afrm := { ;
      { "á", "á" }, ;
      { "â", "â"  }, ;
      { "à", "à" }, ;
      { "ã", "ã" }, ;
      { "ç", "ç" }, ;
      { "é", "é" }, ;
      { "ê", "ê"  }, ;
      { "í", "í" }, ;
      { "ó", "ó" }, ;
      { "ô", "ô"  }, ;
      { "õ", "õ" }, ;
      { "ú", "ú" }, ;
      { "ü", "ü"   }, ;
      { "Á", "Á" }, ;
      { "Â", "Â"  }, ;
      { "À", "À" }, ;
      { "Ã", "Ã" }, ;
      { "Ç", "Ç" }, ;
      { "É", "É" }, ;


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement this Harbour module: Header file for contribution module 'xhb' (Extended Harbour functions): contrib/xhb/hbrpc.ch. Defines 10 constants including: RPC_CH, RPC_LOOP_NONE, RPC_LOOP_SUMMARY, RPC_LOOP_ALLDATA, RPC_LOOP_CONFIRMATION

[Assistant]
#ifndef RPC_CH
#define RPC_CH

#define RPC_LOOP_NONE            0
#define RPC_LOOP_SUMMARY         1
#define RPC_LOOP_ALLDATA         2
#define RPC_LOOP_CONFIRMATION    3

#define RPC_STATUS_ERROR         -1
#define RPC_STATUS_NONE          0
#define RPC_STATUS_CONNECTING    1
#define RPC_STATUS_CONNECTED     2
#define RPC_STATUS_LOGGED        3
#define RPC_STATUS_WAITING       4

#define RPCS_STATUS_BUSY         -2
#define RPCS_STATUS_ERROR        -1
#define RPCS_STATUS_NONE         0
#define RPCS_STATUS_CHALLENGE    1
#define RPCS_STATUS_LOGGED       2
#define RPCS_STATUS_RUNNING      3
#define RPCS_STATUS_CLOSED      10

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Generate Harbour code for: Harbour header file: include/hbmath.ch. Defines 10 constants including: HB_MATH_CH_, HB_MATH_ERR_UNKNOWN, HB_MATH_ERR_NONE, HB_MATH_ERR_DOMAIN, HB_MATH_ERR_SING. Defines keyboard input constants

[Assistant]
#ifndef HB_MATH_CH_
#define HB_MATH_CH_

#define HB_MATH_ERR_UNKNOWN              -1
#define HB_MATH_ERR_NONE                  0
#define HB_MATH_ERR_DOMAIN                1
#define HB_MATH_ERR_SING                  2
#define HB_MATH_ERR_OVERFLOW              3
#define HB_MATH_ERR_UNDERFLOW             4
#define HB_MATH_ERR_TLOSS                 5
#define HB_MATH_ERR_PLOSS                 6

#define HB_MATH_ERRMODE_DEFAULT           0
#define HB_MATH_ERRMODE_CDEFAULT          1
#define HB_MATH_ERRMODE_USER              2
#define HB_MATH_ERRMODE_USERDEFAULT       3
#define HB_MATH_ERRMODE_USERCDEFAULT      4

#define HB_MATHERRORBLOCK_RETVAL   1
#define HB_MATHERRORBLOCK_HANDLED  2

#endif


[System] You are an expert Harbour (xBase/Clipper) programmer. Write clean, efficient code following Harbour conventions. Use proper Hungarian notation for variable names (c=character, n=numeric, l=logical, a=array, o=object, b=codeblock).

[User] Implement these Harbour functions: Harbour contribution module 'gtwvg' (): contrib/gtwvg/tests/_utils.prg. Provides 14 functions including: wvt_Paint, Wvt_Mouse, WvtSetBlocks, WvtSetObjects, SetMouseCheck. Contains procedures: WvtSetKeys. This file provides platform-specific functionality

[Assistant]
#include "inkey.ch"
#include "hbgtinfo.ch"

#define WVT_OBJ_TYPE               1
#define WVT_OBJ_ID                 2
#define WVT_OBJ_ROW                3
#define WVT_OBJ_COL                4
#define WVT_OBJ_ROWTO              5
#define WVT_OBJ_COLTO              6
#define WVT_OBJ_ONDISP             7
#define WVT_OBJ_ONMOUSEOVER        8
#define WVT_OBJ_ONBUTTONDOWN       9
#define WVT_OBJ_ONBUTTONUP        10
#define WVT_OBJ_TOOLTIP           11
#define WVT_OBJ_STATE             12
#define WVT_OBJ_DUMMY             13

#define WVT_OBJ_VRBLS             13

#define OBJ_TYPE_BUTTON            1

#define OBJ_STATE_HIDE             0
#define OBJ_STATE_DISP             1
#define OBJ_STATE_MOUSEOVER        2
#define OBJ_STATE_BUTTONDOWN       3
#define OBJ_STATE_BUTTONUP         4

THREAD STATIC t_keys_ := {, , , , , , , , , , , , , , , , , , , }
THREAD STATIC t_pic_ := {, , , , , , , , , , , , , , , , , , , }

PROCEDURE WvtSetKeys( lSet )

   IF lSet
      t_keys_[  2 ] := SetKey( K_F2, {|| WvtNextGets()         } )
      t_keys_[  3 ] := SetKey( K_F3, {|| WvtWindowExpand( 1 )  } )
      t_keys_[  4 ] := SetKey( K_F4, {|| WvtWindowExpand( -1 ) } )
      t_keys_[  5 ] := SetKey( K_F5, {|| WvtMyBrowse()         } )
      t_keys_[  6 ] := SetKey( K_F6, {|| wvt_Minimize()        } )
      t_keys_[  7 ] := SetKey( K_F7, {|| WvtPartialScreen()    } )
      t_keys_[  8 ] := SetKey( K_F8, {|| WvtLines()            } )
      t_keys_[  9 ] := SetKey( K_F9, {|| wvt_ChooseFont()      } )
      t_keys_[ 10 ] := SetKey( K_F10, {|| wvt_ChooseColor()     } )
   ELSE
      SetKey( K_F2,  t_keys_[ 2 ] )
      SetKey( K_F3,  t_keys_[ 3 ] )
      SetKey( K_F4,  t_keys_[ 4 ] )
      SetKey( K_F5,  t_keys_[ 5 ] )
      SetKey( K_F6,  t_keys_[ 6 ] )
      SetKey( K_F7,  t_keys_[ 7 ] )
      SetKey( K_F8,  t_keys_[ 8 ] )
      SetKey( K_F9,  t_keys_[ 9 ] )
      SetKey( K_F10, t_keys_[ 10 ] )
   ENDIF

   RETURN

FUNCTION wvt_Paint()

   LOCAL aBlocks := WvtSetBlocks()

   AEval( aBlocks, {| e | Eval( e ) } )

   WvtPaintObjects()

   RETURN 0

FUNCTION Wvt_Mouse( nKey, nRow, nCol )

   LOCAL nLen, aObjects := WvtSetObjects()
   LOCAL nObj

   STATIC s_nLastObj := 0
   STATIC s_nLastKey := 0

   IF ( nLen := Len( aObjects ) ) == 0
      RETURN NIL
   ENDIF

   IF ! SetMouseCheck()
      RETURN NIL
   ENDIF

   IF nKey == -1000001
      FOR nObj := 1 TO nLen
         DO CASE
         CASE aObjects[ nObj ][ WVT_OBJ_STATE ] == OBJ_STATE_DISP
            Eval( aObjects[ nObj ][ WVT_OBJ_ONDISP ] )
         CASE aObjects[ nObj ][ WVT_OBJ_STATE ] == OBJ_STATE_MOUSEOVER
            Eval( aObjects[ nObj ][ WVT_OBJ_ONMOUSEOVER ] )
         CASE aObjects[ nObj ][ WVT_OBJ_STATE ] == OBJ_STATE_BUTTONDOWN
            Eval( aObjects[ nObj ][ WVT_OBJ_ONBUTTONDOWN ] )
         CASE aObjects[ nObj ][ WVT_OBJ_STATE ] == OBJ_STATE_BUTTONUP
            Eval( aObjects[ nObj ][ WVT_OBJ_ONDISP ] )
         CASE aObjects[ nObj ][ WVT_OBJ_STATE ] == OBJ_STATE_HIDE

         ENDCASE
      NEXT
      RETURN NIL
   ENDIF

   nObj := AScan( aObjects, {| e_ | e_[ WVT_OBJ_ROW   ] <= nRow .AND. ;
      e_[ WVT_OBJ_ROWTO ] >= nRow .AND. ;
      e_[ WVT_OBJ_COL   ] <= nCol .AND. ;
      e_[ WVT_OBJ_COLTO ] >= nCol     } )
   IF nObj == 0
      IF s_nLastObj > 0
         aObjects[ s_nLastObj ][ WVT_OBJ_STATE ] := OBJ_STATE_DISP
         Eval( aObjects[ s_nLastObj ][ WVT_OBJ_ONDISP ] )
         s_nLastObj := 0
      ENDIF
      RETURN NIL
   ENDIF

   IF s_nLastObj == nObj .AND. s_nLastKey == nKey
      RETURN NIL
   ENDIF

   s_nLastObj := nObj
   s_nLastKey := nKey

   DO CASE
   CASE nKey == K_MOUSEMOVE
      IF aObjects[ s_nLastObj ][ WVT_OBJ_STATE ] != OBJ_STATE_MOUSEOVER
         aObjects[ s_nLastObj ][ WVT_OBJ_STATE ] := OBJ_STATE_MOUSEOVER
         IF aObjects[ nObj ][ WVT_OBJ_ONMOUSEOVER ] != NIL
            Eval( aObjects[ nObj ][ WVT_OBJ_ONMOUSEOVER ] )
         ENDIF
      ENDIF

   CASE nKey == K_LBUTTONDOWN
      aObjects[ s_nLastObj ][ WVT_OBJ_STATE ] := OBJ_STATE_BUTTONDOWN
      IF aObjects[ nObj ][ WVT_OBJ_ONBUTTONDOWN ] != NIL
         Eval( aObjects[ nObj ][ WVT_OBJ_ONBUTTONDOWN ] )
      ENDIF

   CASE nKey == K_LBUTTONUP
      aObjects[ s_nLastObj ][ WVT_OBJ_STATE ] := OBJ_STATE_DISP
      IF aObjects[ nObj ][ WVT_OBJ_ONBUTTONUP ] != NIL
         Eval( aObjects[ nObj ][ WVT_OBJ_ONBUTTONUP ] )
      ENDIF

   ENDCASE

   RETURN NIL

FUNCTION WvtSetBlocks( a_ )

   LOCAL o

   THREAD STATIC t := {}

   o := AClone( t )

   IF a_ != NIL
      t := AClone( a_ )
   ENDIF

   RETURN o

FUNCTION WvtSetObjects( aObject )

   LOCAL oObjects

   THREAD STATIC t_aObjects := {}

   oObjects := AClone( t_aObjects )

   IF aObject != NIL
      IF Empty( aObject )
         t_aObjects := {}
      ELSE
         IF HB_ISARRAY( aObject[ 1 ] )
            AEval( aObject, {| e_ | AAdd( t_aObjects, e_ ) } )
         ELSE
            ASize( aObject, WVT_OBJ_VRBLS )

            hb_default( @aObject[ WVT_OBJ_STATE ], OBJ_STATE_DISP )

            AAdd( t_aObjects, aObject )
         ENDIF
      ENDIF
   ENDIF

   RETURN oObjects

FUNCTION SetMouseCheck( lYes )

   LOCAL lOYes
   STATIC s_lSYes := .T.

   lOYes := s_lSYes
   IF lYes != NIL
      s_lSYes := lYes
   ENDIF

   RETURN lOYes

FUNCTION WvtWindowExpand( nUnits )

   STATIC s_nUnits := 18

   s_nUnits += nUnits

   wvt_SetFont( "Courier New", s_nUnits )

   RETURN .T.

FUNCTION VouChoice( aChoices )

   LOCAL scr, clr, nChoice

   hb_default( @aChoices, { "One", "Two", "Three", "Four", "Five", "Six", "Seven" } )

   scr := SaveScreen( 7, 48, 13, 55 )
   clr := SetColor( "N/W*,GR+/B*,,,GR+/B" )

   nChoice := AChoice( 7, 48, 13, 55, aChoices )

   SetColor( clr )
   RestScreen( 7, 48, 13, 55, scr )

   RETURN nChoice

FUNCTION Hb_Clear()

   CLS

   RETURN .F.

FUNCTION MyMenuProcedure( nID )

   SWITCH nID
   CASE 101
      Alert( "Procedure 101" )
      EXIT
   CASE 102
      Alert( "Procedure 102" )
      EXIT
   ENDSWITCH

   RETURN .T.

FUNCTION BuildWvgToolBar( oDA, nActiveX )

   LOCAL oTBar

   hb_default( @nActiveX, 0 )

   oTBar := WvgToolBar():new( oDA, , { 0, 0 }, { oDA:currentSize()[ 1 ], 30 }, , .T. )

   oTBar:style        := WVGTOOLBAR_STYLE_FLAT
   oTBar:borderStyle  := WVGFRAME_RECT

   oTBar:buttonWidth  := 40
   oTBar:buttonHeight := 26

   oTBar:imageWidth   := 26
   oTBar:imageHeight  := 24

   oTBar:showToolTips := .T.

   oTBar:create()

   oTBar:addItem( "New"       , hb_DirBase() + "v_new.bmp"    )
   oTBar:addItem( "Select"    , hb_DirBase() + "v_selct1.bmp" )
   oTBar:addItem( "Calendar"  , hb_DirBase() + "v_calend.bmp" )
   oTBar:addItem( "Tools"     , hb_DirBase() + "v_lock.bmp"   )
   oTBar:addItem( "Index"     , hb_DirBase() + "v_index.bmp"  )
   oTBar:addItem( "Show"      , hb_DirBase() + "v_clclt.bmp"  )
   oTBar:addItem( "Hide"      , hb_DirBase() + "v_notes1.bmp" )

   RETURN oTBar

FUNCTION SetGT( nIndex, pGT )

   LOCAL oldGT
   STATIC s_pGT_ := { NIL, NIL, NIL }

   oldGT := s_pGT_[ nIndex ]
   IF PCount() == 2
      s_pGT_[ nIndex ] := pGT
   ENDIF

   RETURN oldGT

FUNCTION SetFonts( hFont )

   LOCAL oldFont

   THREAD STATIC t_ahFonts := {}
   oldFont := t_ahFonts
   IF ! Empty( hFont )
      AAdd( t_ahFonts, hFont )
   ENDIF

   RETURN oldFont

FUNCTION SetIcons( hIcon )

   LOCAL oldIcon

   THREAD STATIC t_ahIcons := {}
   oldIcon := t_ahIcons
   IF ! Empty( hIcon )
      AAdd( t_ahIcons, hIcon )
   ENDIF

   RETURN oldIcon

FUNCTION Popups( nID, lDestroy )

   THREAD STATIC t_hPop_ := { , , , , , , , , }

   LOCAL hPop, hPop1
   LOCAL nPrompt := MF_ENABLED + MF_STRING

   IF nID == NIL
      wvt_SetPopupMenu()
      RETURN NIL
   ENDIF

   IF lDestroy != NIL
      Wvt_DestroyMenu( t_hPop_[ nID ] )
      RETURN NIL
   ENDIF

   hPop := t_hPop_[ nID ]

   DO CASE
   CASE nID == 1

      IF hPop == NIL
         hPop := Wvt_CreatePopupMenu()
         Wvt_AppendMenu( hPop, nPrompt, K_F2, "Second Get Screen" )
         Wvt_AppendMenu( hPop, nPrompt, K_F3, "Expand Window"     )