home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP25.EXE / CHP2506.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  2.2 KB  |  60 lines

  1. /*
  2.    Listing 25.6. A general-purpose browse cursor navigation function.
  3.    Author: Craig Yellick
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. #include "inkey.ch"
  12.  
  13. function Navigate(b, k)
  14. /*
  15.    Establish array of navigation keystrokes and the cursor
  16.    movement method to associate with each key. The array is
  17.    comprised of two-element arrays containing the inkey() value
  18.    of the key and a codeblock to execute when the key is pressed.
  19.  
  20.    This function gets passed a browse object and a potential
  21.    navigation key. If the key is found in the array its
  22.    associated navigation message is sent to the browse. Function
  23.    returns .t. if navigation was handled, .f. if not.
  24. */
  25. local n
  26.  
  27. //  Made static so it doesn't get re-initialized on every call.
  28. static keys_
  29.   if keys_ = nil
  30.     keys_ := { ;
  31.     {K_UP,       {|| b:up()      }},;  //  Up one row
  32.     {K_DOWN,     {|| b:down()    }},;  //  Down one row
  33.     {K_LEFT,     {|| b:left()    }},;  //  Left one column
  34.     {K_RIGHT,    {|| b:right()   }},;  //  Right one column
  35.     {K_PGUP,     {|| b:pageUp()  }},;  //  Up on page
  36.     {K_PGDN,     {|| b:pageDown()}},;  //  Down one page
  37.     {K_CTRL_PGUP,{|| b:goTop()   }},;  //  Up to the first record
  38.     {K_CTRL_PGDN,{|| b:goBottom()}},;  //  Down to the last record
  39.     {K_HOME,     {|| b:home()    }},;  //  First visible column
  40.     {K_END,      {|| b:end()     }},;  //  Last visible column
  41.     {K_CTRL_HOME,{|| b:panHome() }},;  //  First column
  42.     {K_CTRL_END, {|| b:panEnd()  }},;  //  Last column
  43.     {K_TAB,      {|| b:panRight()}},;  //  Pan to the right
  44.     {K_SH_TAB,   {|| b:panLeft() }} ;  //  Pan to the left
  45.     }
  46.   endif
  47.  
  48.   //  Search for the inkey() value in the cursor movement array.
  49.   //  If one is found, evaluate the code block associated with it.
  50.   //  Remember these are paired in arrays: {key, block}.
  51.   //
  52.   n := ascan(keys_, { | pair | k == pair[1] })
  53.   if n <> 0
  54.     eval(keys_[n, 2])
  55.   endif
  56.  
  57. return (n <> 0)
  58.  
  59. // end of file CHP2506.PRG
  60.