Viktor Szakáts wrote:
#2 is closer, but even that isn't fully compatible, unfortunately I don't have the time and tech env now to fully oversee the nPos == 0 case and do extensive side-by-side tests, so rather than messing up the code, I'd like to ask someone to jump on this if current state isn't good enough.

Attached new test code with repaint trick copied in.

Brgds,
Viktor

Hi,

I make a lots of achoice() tests, and my suggestion is
---CODE

     IF lUserFunc

// comment out
//       nUserFunc := Do( xUserFunc, nMode, nPos, nPos - nAtTop)

// Clipper do not call User Function in  AC_NOITEM mode
// fix
+         nUserFunc := IIF( nMode != AC_NOITEM,;
+           Do( xUserFunc, nMode, nPos, nPos - nAtTop), NIL )

// also dehighlight is needed if User Function defined to
// (3 entry)
        IF ISNUMBER( nUserFunc )

           DO CASE
           CASE nUserFunc == AC_ABORT .OR. nMode == AC_NOITEM
+               IF nPos != 0
+ DispLine( acItems[ nPos ], nTop + ( nPos - nAtTop ), nLeft, .T., .F., nNumCols )
+               ENDIF
              lFinished := .T.
              nPos      := 0
           CASE nUserFunc == AC_SELECT
+               IF nPos != 0
+ DispLine( acItems[ nPos ], nTop + ( nPos - nAtTop ), nLeft, .T., .F., nNumCols )
+              ENDIF
              lFinished := .T.
           CASE nUserFunc == AC_CONT .OR. nUserFunc == AC_REDRAW
              // Do nothing
              nMode := AC_CONT
           CASE nUserFunc == AC_GOTO
              // Do nothing. The next keystroke won't be read and
              // this keystroke will be processed as a goto.
              nMode := AC_GOTO
           ENDCASE

           IF nPos > 0 .AND. nMode != AC_GOTO

              nRowsClr := Min( nNumRows, nItems )
nMode := Ach_Limits( @nFrstItem, @nLastItem, @nItems, bSelect, alSelect, acItems )

              IF nMode == AC_NOITEM
                 nPos := 0
                 nAtTop := Max( 1, nPos - nNumRows + 1 )
              ELSE
DO WHILE nPos < nLastItem .AND. !Eval( bSelect, alSelect[ nPos ] )
                    nPos++
                 ENDDO

                 IF nPos > nLastItem
                    nPos := BETWEEN( nFrstItem, nPos, nLastItem )
                 ENDIF

                 nAtTop := Min( nAtTop, nPos )

                 IF nAtTop + nNumRows - 1 > nItems
nAtTop := BETWEEN( 1, nPos - nNumRows + 1, nItems - nNumRows + 1 )
                 ENDIF

                 IF nAtTop < 1
                    nAtTop := 1
                 ENDIF

              ENDIF

DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, nPos, nAtTop, nItems, bSelect, nRowsClr )
           ENDIF
        ELSE
+            IF nPos != 0
+ DispLine( acItems[ nPos ], nTop + ( nPos - nAtTop ), nLeft, .T., .F., nNumCols )
+           ENDIF
           nPos      := 0
           lFinished := .T.
        ENDIF
     ENDIF

---END CODE

and
My final test program
---CODE

#include "inkey.ch"
#include "achoice.ch"

function main()

//NIL, empty, numeric, and "not handled" - items
//must be inaccesible and invisible
local aMenu1 := {" --Visky--", "", "not handled"}
local aMenu2 := {" --Vodka--", " --Water--", NIL, "not handled"}
local aMenu3 := {" --Grapa--", 33, "not handled"}

//for AC_NOITEM mode test
local aMenu4 := {"","not handled"}

local lExit := .F.
local nCounter := 1
local nKeyPressed

//set to True for items (de)highlighting
//algoritm in clipper
public lHiLiTest := .F.

setcolor("W+/N, BG+/B, , , W/N")
cls
@ 2,1 SAY " --Visky--   --Vodka--   --Grapa--"
@ 3,14 SAY "--Water--"
do while !lExit

do case
   case nCounter == 1
     achoice(2, 1, 3, 11, aMenu1)
   case nCounter == 2
     achoice(2, 13, 3, 23, aMenu2, .T., "cUF")
   case nCounter == 3
     achoice(2, 25, 3, 35, aMenu3, .T.)
   case nCounter == 4
//User function cUF2() fill screen with exclamation marks
//in clipper it doe's not called in AC_NOITEM mode
     achoice(2, 37, 3, 47, aMenu4, .T., "cUF2")
endcase

nKeyPressed := lastkey()
if nKeyPressed == K_ESC
  lExit := .T.
elseif nKeyPressed == K_RIGHT
  nCounter := iif(nCounter == 4, 1, nCounter+1)
elseif nKeyPressed == K_LEFT
  nCounter := iif(nCounter == 1, 4, nCounter-1)
endif

enddo

return NIL

//Test for current and previous items
//highliting-dehighliting algoritm
function cUF( nMode, nCurElement, nRowPos )

local nRetVal := AC_CONT
local nKey := LASTKEY()

if lHiLiTest
  dispbox( 0, 0, maxrow(), maxcol(), repl("#",9), "GR+/G" )
endif

if nMode == AC_NOITEM
 nRetVal := AC_ABORT
elseif nMode == AC_EXCEPT
 do case
    case nKey == K_RETURN
      nRetVal := AC_SELECT
    otherwise
      nRetVal := AC_ABORT
  endcase
endif

return nRetVal


//test for AC_NOITEM mode
//Clipper in AC_NOITEM mode do not call User Function
function cUF2( nMode, nCurElement, nRowPos )

local nRetVal := AC_CONT
local nKey := LASTKEY()

dispbox( 0, 0, maxrow(), maxcol(), repl("!",9), "GR+/G" )

if nMode == AC_NOITEM
 nRetVal := AC_ABORT
elseif nMode == AC_EXCEPT
 do case
    case nKey == K_RETURN
      nRetVal := AC_SELECT
    otherwise
      nRetVal := AC_ABORT
  endcase
endif

return nRetVal

---END CODE

Best regards,
Vlad

_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to