home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / CLIPPER / OBJECT / BUTTON.PRG next >
Text File  |  1992-12-04  |  2KB  |  88 lines

  1. #include "Objects.ch"
  2. #include "Inkey.ch"
  3.  
  4. //----------------------------------------------------------------------------//
  5.  
  6. CLASS TButton FROM TControl
  7.  
  8.    DATA nRow, nCol, cText, cBack
  9.  
  10.    METHOD New( nRow, nCol, cText, bAction )
  11.    METHOD Display()
  12.    METHOD KeyApply( nKey )
  13.    METHOD SetFocus( lOnOff )
  14.  
  15. ENDCLASS
  16.  
  17. //----------------------------------------------------------------------------//
  18.  
  19. METHOD TButton::New( nRow, nCol, cText, bAction )
  20.  
  21.    DEFAULT bAction := { || nil }
  22.  
  23.    ::Parent:New()
  24.  
  25.    ::nRow    := nRow
  26.    ::nCol    := nCol
  27.    ::cText   := cText
  28.    ::cBack   := SaveScreen( nRow, nCol, nRow + 1, nCol + Len( cText ) )
  29.    ::bAction := bAction
  30.  
  31. return self
  32.  
  33. //----------------------------------------------------------------------------//
  34.  
  35. METHOD TButton::Display()
  36.  
  37.    BtnDraw( ::nRow, ::nCol, ::cText, If( ::HasFocus, 127, 112 ), 123 )
  38.  
  39. return
  40.  
  41. //----------------------------------------------------------------------------//
  42.  
  43. METHOD TButton::KeyApply( nKey )
  44.  
  45.    If nKey == K_ENTER .or. nKey == K_SPACE
  46.       RestScreen( ::nRow, ::nCol, ::nRow + 1, ::nCol + Len( ::cText ), ;
  47.           ::cBack )
  48.  
  49.       ScrSayHot( ::nRow, ::nCol + 1, ::cText, "W+/W", "BG+/W" )
  50.  
  51.       InKey( 0.5 )
  52.       Eval( ::bAction )
  53.       RestScreen( ::nRow, ::nCol, ::nRow + 1, ::nCol + Len( ::cText ), ;
  54.           ::cBack )
  55.       ::Display()
  56.    else
  57.       ::Parent:KeyApply( nKey )
  58.    endif
  59.  
  60. return
  61.  
  62. //----------------------------------------------------------------------------//
  63.  
  64. METHOD TButton::SetFocus( lOnOff )
  65.  
  66.    SetCursor( If( lOnOff, 0, 1 ) )
  67.    ::Parent:SetFocus( lOnOff )
  68.  
  69. return
  70.  
  71. //----------------------------------------------------------------------------//
  72.  
  73. function nBtnOk()                             // Friend Function
  74.  
  75.    KEYBOARD Chr( K_CTRL_W )
  76.  
  77. return 1
  78.  
  79. //----------------------------------------------------------------------------//
  80.  
  81. function nBtnCancel()                        // Friend Function
  82.  
  83.    KEYBOARD Chr( K_ESC )
  84.  
  85. return 0
  86.  
  87. //----------------------------------------------------------------------------//
  88.