home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / CLIPPER / OBJECTS / CTRRADIO.PRG < prev    next >
Text File  |  1992-12-04  |  3KB  |  100 lines

  1. #include "Objects.ch"
  2. #include "InKey.ch"
  3.  
  4. //────────────────────────────────────────────────────────────────────────────//
  5.  
  6. CLASS TCtrRadio FROM TControl
  7.  
  8.    DATA   nTop, nLeft, nBottom, nRight
  9.    DATA   cLabel
  10.    DATA   oMnuRadio
  11.  
  12.    METHOD New( nRow, nCol, bSetGet, acItems, cLabel, bWhen, bValid )
  13.    METHOD Display()
  14.    METHOD KeyApply( nKey )
  15.    METHOD SetFocus( lOnOff )
  16.  
  17. ENDCLASS
  18.  
  19. //────────────────────────────────────────────────────────────────────────────//
  20.  
  21. METHOD TCtrRadio::New( nRow, nCol, bSetGet, acItems, cLabel, bWhen, bValid )
  22.  
  23.    local nOption := Eval( bSetGet )
  24.    local nWidth  := 0
  25.  
  26.    DEFAULT cLabel := ""
  27.  
  28.    AEval( acItems, { | cItem | nWidth := Max( nWidth, Len( cItem ) + 1 ) } )
  29.  
  30.    ::Parent:New()
  31.  
  32.    ::oMnuRadio = TMenu():New( If( nOption == 0, 1, nOption ) )
  33.    ::nTop      = nRow
  34.    ::nLeft     = nCol
  35.    ::nBottom   = nRow + Len( acItems ) + 1
  36.    ::nRight    = nCol + nWidth + 6
  37.    ::bBlock    = bSetGet
  38.    ::cLabel    = cLabel
  39.  
  40.    AEval( acItems, { | cItem, n | AAdd( ::oMnuRadio:aoItems, TRadio():;
  41.       New( nRow + n, nCol + 1, PadR( cItem, nWidth ) ) ) } )
  42.  
  43. return Self
  44.  
  45. //────────────────────────────────────────────────────────────────────────────//
  46.  
  47. METHOD TCtrRadio::Display()
  48.    
  49.    @ ::nTop, ::nLeft TO ::nBottom, ::nRight
  50.    if ! Empty( ::cLabel )
  51.       @ ::nTop, ::nLeft + 1 SAY " " + ::cLabel + " "
  52.    endif
  53.  
  54.    ::oMnuRadio:aoItems[ ::oMnuRadio:nOption ]:lCheck = .t.
  55.    ::oMnuRadio:Display()
  56.  
  57. return
  58.  
  59. //────────────────────────────────────────────────────────────────────────────//
  60.  
  61. METHOD TCtrRadio::SetFocus( lOnOff )
  62.       
  63.    SetCursor( If( lOnOff, 0, 1 ) )
  64.    if lOnOff
  65.       ::oMnuRadio:aoItems[ ::oMnuRadio:nOption ]:SetFocus( lOnOff )
  66.    else
  67.       ::oMnuRadio:aoItems[ ::oMnuRadio:nOption ]:lFocus = .f.
  68.       ::oMnuRadio:aoItems[ ::oMnuRadio:nOption ]:lCheck = .t.
  69.       ::oMnuRadio:aoItems[ ::oMnuRadio:nOption ]:Display()
  70.       Eval( ::bBlock, ::oMnuRadio:nOption )
  71.    endif
  72.  
  73. return
  74.  
  75. //────────────────────────────────────────────────────────────────────────────//
  76.  
  77. METHOD TCtrRadio::KeyApply( nKey )
  78.  
  79.  
  80.    do case
  81.       case nKey == K_HOME
  82.            ::oMnuRadio:KeyApply( nKey )
  83.  
  84.       case nKey == K_END
  85.            ::oMnuRadio:KeyApply( nKey )
  86.  
  87.       case nKey == K_DOWN
  88.            ::oMnuRadio:KeyApply( nKey )
  89.  
  90.       case nKey == K_UP
  91.            ::oMnuRadio:KeyApply( nKey )
  92.  
  93.       otherwise
  94.            ::Parent:KeyApply( nKey )
  95.    endcase
  96.  
  97. return
  98.  
  99. //────────────────────────────────────────────────────────────────────────────//
  100.