[email protected] wrote:
Revision: 10594
          
http://harbour-project.svn.sourceforge.net/harbour-project/?rev=10594&view=rev
Author:   vszakats
Date:     2009-03-12 09:29:50 +0000 (Thu, 12 Mar 2009)

Log Message:
-----------
2009-03-12 10:28 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
  * source/rtl/achoice.prg
    ! Fixed to always dehilight active item on exit.
(probably could be done more efficiently, feel free to optimize it.)
      Please test.
I found 2 variants of more optimal fix, but don't know which is more optimal :)

Variant -1
Delete all previously posted
DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, 0, nAtTop, nItems, bSelect, nRowsClr )
lines
and add only one, before achoice() return point
[...]
  ENDDO
+ DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, 0, nAtTop, nItems, bSelect, nRowsClr )
  SetCursor( nSaveCsr )

  RETURN nPos
[...]
simplifies code, only 1 line of code to add, but redraw all visible lines.

Variant - 2
Delete all previously posted
DispPage( acItems, alSelect, nTop, nLeft, nRight, nNumRows, 0, nAtTop, nItems, bSelect, nRowsClr )
lines
and add in all CASE entry before lFinished := .T. (7-lines) and before nPos := 0 (if exist)
[...]
+ DispLine( acItems[ nPos ], nTop + ( nPos - nAtTop ), nLeft, .T., .F., nNumCols )
      nPos      := 0
      lFinished := .T.
[...]
add 7 lines of code, but redraw only one current line


I test both (OK), with extended (added NIL, EMPTY, NUMERIC array values, and UserFunction) previously posted sample
-----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"}

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

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., "cUserFunction")
   case nCounter == 3
     achoice(2, 25, 3, 35, aMenu3, .T., "cUserFunction")
endcase

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

enddo

return NIL

//do nothing, just for test
function cUserFunction( nMode, nCurElement, nRowPos )

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

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----------------


Brgds,
Vlad

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

Reply via email to