home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase Pro v7.0 / DATA1.CAB / Sample_Custom / Seeker.cc < prev   
Encoding:
C/C++ Source or Header  |  1997-11-20  |  3.4 KB  |  118 lines

  1. //------------------------------------------------------------------------
  2. //
  3. //  Seeker.cc  --  Incremental search custom control
  4. //
  5. //  
  6. //  Visual dBASE Samples Group
  7. //
  8. //  $Revision:   1.1  $
  9. //
  10. //  Copyright (c) 1997, Borland International, Inc. 
  11. //  All rights reserved.
  12. //
  13. //------------------------------------------------------------------------
  14. //
  15.  
  16. CLASS Seeker( oCont, cName ) of Entryfield( oCont, cName ) CUSTOM
  17.  
  18.   protect lNear, lExact, lFound, lRefresh, nMaxPos
  19.   protect seekRowset
  20.  
  21.   // Set stock properties
  22.   this.selectAll := true
  23.   this.value     := ""
  24.   
  25.   // Custom properties
  26.   this.rowset    = null    // Set to override form.rowset
  27.   this.tabAfter  = 0       // Automatically tab after typing N chars
  28.   this.seek      = this.xSeek
  29.  
  30.   // Internal properties
  31.   this.lNear     = ( SET( "NEAR"  ) == "ON" )
  32.   this.lExact    = ( SET( "EXACT" ) == "ON" )
  33.   this.lRefresh  = this.form.RefreshAlways
  34.   this.lFound    = true
  35.   this.nMaxPos   = 0       // Max position of cursor in entryfield
  36.  
  37.   FUNCTION onGotFocus
  38.     if form.rowset == null       // Xbase settings
  39.       this.lNear    = ( SET( "NEAR"  ) == "ON" )
  40.       this.lExact   = ( SET( "EXACT" ) == "ON" )
  41.       this.lRefresh = form.RefreshAlways
  42.       set near on                // To do incremental matching
  43.       set exact off              // To return FOUND() .T. on substring match
  44.       form.RefreshAlways = .t.
  45.       this.seek     = this.xSeek // Use method with Xbase SEEK()
  46.     else
  47.       // For OODML, use findKeyNearest(), which always does a
  48.       // partial key match (like EXACT OFF)
  49.       this.seek     = this.oSeek
  50.       // Assign protected object reference to either form's rowset
  51.       // or control's rowset
  52.       this.seekRowset = iif( this.rowset == null, form.rowset, this.rowset )
  53.     endif
  54.     this.lFound  = .t.
  55.     this.nMaxPos = 0
  56.  
  57.   FUNCTION key( nChar, nPosition )
  58.     if nextkey() # 0
  59.       // Wait until there are no keystrokes pending, and...
  60.       RETURN ( nChar # 255 )     // ...ignore keystroke if special key
  61.     endif
  62.     if nChar == 255
  63.       if .not. empty( this.value ) .and. ;
  64.           ( this.lFound .or. nPosition <= this.nMaxPos )
  65.         this.lFound = this.seek()
  66.       endif
  67.       if this.tabAfter > 0
  68.         // Stuff tab if position is greater than tabAfter
  69.         nChar = iif( nPosition > this.tabAfter, 9, 0 )
  70.       else
  71.         nChar = 0
  72.       endif
  73.       this.nMaxPos = max( nPosition, ;
  74.           min( this.nMaxPos, len( trim( this.Value ))) )
  75.     else
  76.       if nChar >= 32 .and. nChar < 255
  77.         // Stuff special key to refire key event
  78.         keyboard "{255}"
  79.       endif
  80.     endif
  81.     RETURN nChar
  82.  
  83.   FUNCTION xSeek
  84.     local lRet
  85.     lRet = seek( this.normalizedValue() )
  86.     if eof()               // Always move record pointer to real record
  87.       goto bottom
  88.     endif
  89.     RETURN lRet
  90.  
  91.   FUNCTION oSeek
  92.     local lRet
  93.     lRet = this.seekRowset.findKeyNearest( this.normalizedValue() )
  94.     if ( this.seekRowset.endOfSet )
  95.       this.seekRowset.next( -1 )
  96.     endif
  97.     RETURN lRet
  98.  
  99.   FUNCTION normalizedValue
  100.     RETURN upper( trim( this.value ))
  101.  
  102.   FUNCTION onLostFocus
  103.     if form.rowset == null
  104.       if .not. this.lNear
  105.         set near off
  106.       endif
  107.       if this.lExact
  108.         set exact on
  109.       endif
  110.       form.RefreshAlways = this.lRefresh
  111.     endif
  112.  
  113. ENDCLASS
  114.  
  115.  
  116.  
  117.  
  118.