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 >
Text File  |  1992-12-04  |  2KB  |  112 lines

  1. #include "Inkey.ch"
  2. #include "Objects.ch"
  3.  
  4. //────────────────────────────────────────────────────────────────────────────//
  5.  
  6. CLASS TMenu
  7.  
  8.    DATA aoItems
  9.    DATA nOption
  10.    DATA lEnd
  11.  
  12.    METHOD New( nOption )
  13.    METHOD KeyApply( nKey )
  14.    METHOD SetOption( nOption )
  15.    METHOD Exec()
  16.    METHOD Display()
  17.  
  18. ENDCLASS
  19.  
  20. //────────────────────────────────────────────────────────────────────────────//
  21.  
  22. METHOD TMenu::New( nOption )
  23.  
  24.    DEFAULT nOption := 1
  25.  
  26.    ::aoItems := {}
  27.    ::nOption := nOption
  28.    ::lEnd    := .f.
  29.  
  30. return Self
  31.  
  32. //────────────────────────────────────────────────────────────────────────────//
  33.  
  34. METHOD TMenu::KeyApply( nKey )
  35.  
  36.    do case
  37.       case nKey == K_ESC
  38.            ::lEnd = .t.
  39.            ::SetOption( 0 )
  40.  
  41.       case nKey == K_ENTER
  42.            if ValType( ::aoItems[ ::nOption ]:uAction ) == "B"
  43.               Eval( ::aoItems[ ::nOption ]:uAction )
  44.            endif
  45.  
  46.       case nKey == K_UP
  47.            ::SetOption( If( ::nOption > 1, ::nOption - 1,  Len( ::aoItems ) ) )
  48.  
  49.       case nKey == K_DOWN
  50.            ::SetOption( If( ::nOption == Len( ::aoItems ), 1, ::nOption + 1 ) )
  51.  
  52.       case nKey == K_LEFT
  53.            ::SetOption( If( ::nOption > 1, ::nOption - 1,  Len( ::aoItems ) ) )
  54.  
  55.       case nKey == K_RIGHT
  56.            ::SetOption( If( ::nOption == Len( ::aoItems ), 1, ::nOption + 1 ) )
  57.  
  58.       case nKey == K_HOME
  59.            if ::nOption > 1
  60.               ::SetOption( 1 )
  61.            endif
  62.  
  63.       case nKey == K_END
  64.            if ::nOption < Len( ::aoItems )
  65.               ::SetOption( Len( ::aoItems ) )
  66.            endif
  67.  
  68.    endcase
  69.  
  70. return
  71.  
  72. //────────────────────────────────────────────────────────────────────────────//
  73.  
  74. METHOD TMenu::SetOption( nOption )
  75.  
  76.    if nOption != ::nOption
  77.       ::aoItems[ ::nOption ]:SetFocus( .f. )
  78.    endif
  79.  
  80.    ::nOption = nOption
  81.  
  82.    if ::nOption != 0
  83.       ::aoItems[ ::nOption ]:SetFocus( .t. )
  84.    endif
  85.  
  86. return
  87.  
  88. //────────────────────────────────────────────────────────────────────────────//
  89.  
  90. METHOD TMenu::Exec()
  91.  
  92.    ::lEnd = .f.
  93.  
  94.    ::Display()
  95.    ::aoItems[ ::nOption ]:SetFocus( .t. )
  96.  
  97.    do while ! ::lEnd
  98.       ::KeyApply( InKey( 0 ) )
  99.    enddo
  100.  
  101. return
  102.  
  103. //────────────────────────────────────────────────────────────────────────────//
  104.  
  105. METHOD TMenu::Display()
  106.  
  107.    AEval( ::aoItems, { | oItem | oItem:Display() } )
  108.  
  109. return
  110.  
  111. //────────────────────────────────────────────────────────────────────────────//
  112.