Function TBHandleEvent() Foundation

Processes event codes (such as those returned by the function AppEvent()) for a TBrowse object.

TBHandleEvent( <oTBrowse>, <nEvent>, ;
               [<mp1>], [<mp2>], [<oXbp>]) --> nBrowseDirection
<oTBrowse> is a TBrowse object which is to process the event code.
<nEvent> is the numeric event returned from the function AppEvent().
<mp1> is the first message parameter of the function AppEvent().
<mp2> is the second message parameter of the function AppEvent().
<oXbp> is an Xbase Part which is to process the event instead of the TBrowse object (addressee of an event). This parameter is only relevant when Xbase Parts are used in the program. This parameter is provided by the function AppEvent() (see AppEvent()).

The function TBHandleEvent() returns a numeric code which identifies the direction in which the TBrowse cursor will be moved in the next stabilization cycle. The return value orients itself at the numeric keypad (2 means "down", 6 means "to the right", 1 means "lower left," etc). When the event code is not processed, the return value is zero and the Tbrowse cursor is not moved. If the event <nEvent> is linked to a code block by the function SetAppEvent(), the code block is evaluated and the function returns -1.


The function TBHandleEvent() implements the default behavior of TBrowse objects for the processing events such as those returned by the function AppEvent(). To handle mouse events it calls the function TBtoMousePos(). TBHandleEvent() is a service function for programming with TBrowse objects and its source code is contained in the file BROWUTIL.PRG. To process events using TBHandleEvent(), the function AppEvent() must be used in the code handling the Tbrowse object.

The default behavior for keyboard navigation of TBrowse objects implemented in the function TBHandleEvent() is listed in the following table:

Event processing with Tbrowse objects
Key Event constant Action
Up Arrow xbeK_UP Previous row
Down Arrow xbeK_DOWN Next row
Left Arrow xbeK_LEFT One column to the left
Right Arrow xbeK_RIGHT One column to the right
Home xbeK_HOME Left column in the window
End xbeK_END Right column in the window
Page Up xbeK_PGUP Previous screen
Page Down xbeK_PGDN Next screen
Ctrl+Left Arrow xbeK_CTRL_LEFT Scrolls columns left
Ctrl+Right Arrow xbeK_CTRL_RIGHT Scrolls columns right
Ctrl+Home xbeK_CTRL_HOME First column
Ctrl+End xbeK_CTRL_END Last column
Ctrl+Page Up xbeK_CTRL_PGUP First row of table
Ctrl+Page Down xbeK_CTRL_PGDN Last row of table
Left mouse button xbeM_LbClick TBrowse cursor is moved to the mouse pointer

The return value of TBHandleEvent() gives information about the direction in which the TBrowse cursor will be moved in the next stabilization cycle. Possible return values are as follows:

Return values of TBHandleEvent()
Return value Direction for TBrowse cursor
9 Right up
8 Up
7 Left up
6 Right
5 Mouse click in the TBrowse cursor, TBrowse cursor is not moved
4 Left
3 Right down
2 Down
1 Left down
0 Unknown event, TBrowse cursor is not moved
-1 TBrowse cursor is not moved, a SetAppEvent() code block is evaluated

// The example generates a TBrowse object and illustrates 
// how TBHandleEvent() can be used for navigating a TBrowse 
// object. 

#include "" 

   LOCAL oTB, nDirection, nEvent, mp1, mp2, oXbp 

   USE Address                      // open file 

   oTB := TBrowseDB( 2, 2, 22, 78 ) // creates TBrowse 
   AEval( DbStruct(), {|a| oTB:AddColumn(             ; 
                              TBColumn():new( a[1],   ; 
                                 FieldBlock(a[1]) ) ) } ) 

   nEvent     := 0 
   @ 1,1 TO 23,79 DOUBLE 
   oTB:forceStable()                // display complete TBrowse 

   DO WHILE nEvent <> xbeK_ESC      // terminate on Esc key 

      DO WHILE ! oTB:stabilize()    // incremental display 
         nEvent:= AppEvent( @mp1, @mp2, @oXbp, .01 ) 
         IF nEvent  > xbe_None     .AND. ; 
            nEvent <> xbeM_Motion 

      IF oTB:stable                  // TBrowse is stable 
         nEvent := xbeM_Motion       // filter out event 
         DO WHILE nEvent == xbeM_Motion  // "mouse is moved" 
            nEvent := AppEvent( @mp1, @mp2, @oXbp, 0 ) 
                                     // process event 
      nDirection := TBHandleEvent( oTB, nEvent, mp1, mp2, oXbp ) 

      @ MaxRow(),0                   // display browse direction 
      QQOut( "Browse direction:", nDirection ) 




If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.