[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
     The Mouse Trap functions:

     The following functions of Expand use the "MouseTrap":

     . MouseMenu()
     . MouseEdit()
     . MouseChoice()
     . MouseBrowse()

     For every of those functions the trap is implemented in a similar
     fashion, to make it possible to handle them centrally when needed.

     Currently the trap function is only called after keyboard input
     (Clicking the Left Button is equal to Enter, and Right with
     Escape), before processing the key, the functions call the
     mouseTrap function with two parameters: The first parameter is
     the Mode, which indicates why the Trap has been called. Currently
     the only value for Mode is 0 (always), but it is introduced for
     future extensions. The second parameter is the current item Number,
     which can be a Menu Item number, a Array index or a record number
     (not very useful, but alas), depending on the function you're using.

     One can inspect the last key with the LastKey() function, and act
     accordingly. The return value passed by the trap function is
     considered the actual key by the function. For example, returning
     K_ESC when K_F1 was pressed will make the function abort, as it
     thinks ESC was pressed. When the trap is not submitted (it is
     optionnal), a default trap function that plainly returns LastKey() is
     used instead (and often, that is enough).

     Resuming: The parameters supplied to the trap function are Mode
     (currently always 0, indicating Key processing) and item number.

     The return value of the MouseTrap thus changes the behaviour of the
     MouseXXXX() Function, These are the possible return values, and their
     action:

     Key:    Value:    Action:
     ------------------------------------------------------------------
     K_HOME     1        Move to the first selection. Be it the first
                         Menu item, or top of file.
     K_END      6        Move to the End of the selections. eg. the last
                         Choice in the array.
     K_UP       5        Move upward (toggles to end in MouseMenu())
     K_DOWN    24        Move down (also toggles in MouseMenu())
     K_PGUP    18        Move one page up (not in Menu)
     K_PGDN     3        guess (not in Menu)
     K_CTRL_B   2        This return value (Ctrl-B) reformats the screen
                         by redrawing all Menu-Items or selections or
                         whatever. Handy when you executed a Seek within
                         the MouseTrap of MouseEdit(), for instance.
     K_ENTER   13        Quit the function and return the current Item.
                         returns RecNo() for MouseEdit(), but the record
                         is also the current record at that time.
     K_ESC     27, 0     Both values are okay. This also Quits the
                         function by returning 0.
     <Space>   32        Ignore this key, and go on. As More keys may
                         be added to this list, it is best to return 32
                         when one doesn't want anything to happen with the
                         last key. <Space> will always be ignored by any of
                         the MouseXXX() functions.
     <Digits>, 33..      In the MouseMenu() function, the first Menu-Item
     <Letters> 127       whose first letter matches the key passed (or
                         pressed when no Trap is supplied) is selected, and
                         the function stops. In the MouseChoice() function,
                         the first Next (and wraps) array item that matches
                         the key pressed is selected, but the function is
                         not terminated (just as with Achoice()).
     ------------------------------------------------------------------

     Note that if you want [Ctrl-PgUp] also to make the selection bar
     move to the first item, you must do so by the following statements
     in your Trap function:

          if LastKey() = K_CTRL_PGUP
               return (K_HOME)
          elseif .....   /* check for other keys etc.. */

     The demo programs as provided by the Expand package implement some
     Trap functions, I refer to them if you want some code examples.

     Note that the Mouse-and-Something functions do not trigger any
     procedures that have been defined by the SET KEY commands. If
     you wish to do so for these functions, use a MouseTrap function
     like this one:

          Function MyMouseTrap(Mode,Nr)
          /* Mode will be 0, Nr the Item number */
          Local bKey := SetKey(LastKey())
          if bKey != NIL          /* Some procedure installed? */
          Eval(bKey, ProcName(2), ProcLine(2))
              return (32)
          endif
          /* now, handle the other stuff.. */
          do case
          case lastkey() == ... etc..
          .
          .
          endcase
          return Something.

     Now, Call the MouseEdit() function as follow:

       MouseEdit(1,1,23,78,'Name',{||NAME},{|Mode,Nr|MyMouseTrap(Mode,Nr)})

     Et Voila!

See Also: MouseMenu() MouseEdit() MouseChoice() MouseBrowse()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson