home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
CLIPPER
/
OBJECT
/
MENU.PRG
< prev
next >
Wrap
Text File
|
1992-12-04
|
2KB
|
112 lines
#include "Inkey.ch"
#include "Objects.ch"
//────────────────────────────────────────────────────────────────────────────//
CLASS TMenu
DATA aoItems
DATA nOption
DATA lEnd
METHOD New( nOption )
METHOD KeyApply( nKey )
METHOD SetOption( nOption )
METHOD Exec()
METHOD Display()
ENDCLASS
//────────────────────────────────────────────────────────────────────────────//
METHOD TMenu::New( nOption )
DEFAULT nOption := 1
::aoItems := {}
::nOption := nOption
::lEnd := .f.
return Self
//────────────────────────────────────────────────────────────────────────────//
METHOD TMenu::KeyApply( nKey )
do case
case nKey == K_ESC
::lEnd = .t.
::SetOption( 0 )
case nKey == K_ENTER
if ValType( ::aoItems[ ::nOption ]:uAction ) == "B"
Eval( ::aoItems[ ::nOption ]:uAction )
endif
case nKey == K_UP
::SetOption( If( ::nOption > 1, ::nOption - 1, Len( ::aoItems ) ) )
case nKey == K_DOWN
::SetOption( If( ::nOption == Len( ::aoItems ), 1, ::nOption + 1 ) )
case nKey == K_LEFT
::SetOption( If( ::nOption > 1, ::nOption - 1, Len( ::aoItems ) ) )
case nKey == K_RIGHT
::SetOption( If( ::nOption == Len( ::aoItems ), 1, ::nOption + 1 ) )
case nKey == K_HOME
if ::nOption > 1
::SetOption( 1 )
endif
case nKey == K_END
if ::nOption < Len( ::aoItems )
::SetOption( Len( ::aoItems ) )
endif
endcase
return
//────────────────────────────────────────────────────────────────────────────//
METHOD TMenu::SetOption( nOption )
if nOption != ::nOption
::aoItems[ ::nOption ]:SetFocus( .f. )
endif
::nOption = nOption
if ::nOption != 0
::aoItems[ ::nOption ]:SetFocus( .t. )
endif
return
//────────────────────────────────────────────────────────────────────────────//
METHOD TMenu::Exec()
::lEnd = .f.
::Display()
::aoItems[ ::nOption ]:SetFocus( .t. )
do while ! ::lEnd
::KeyApply( InKey( 0 ) )
enddo
return
//────────────────────────────────────────────────────────────────────────────//
METHOD TMenu::Display()
AEval( ::aoItems, { | oItem | oItem:Display() } )
return
//────────────────────────────────────────────────────────────────────────────//