home *** CD-ROM | disk | FTP | other *** search
/ ftp.fox-toolkit.org / 2014.05.ftp.fox-toolkit.org.tar / ftp.fox-toolkit.org / pub / eventloop.txt < prev    next >
Text File  |  2001-02-26  |  4KB  |  103 lines

  1. The FOX Event Loop
  2. Daniel Gehriger
  3.  
  4.  
  5. The FOX event loop waits for, and dispatches:
  6.         (1) GUI events,
  7.         (2) timer events,
  8.         (3) signaled file handles (descriptors),
  9.         (4) signals.
  10. In addition, the event loop also handles
  11.         (5) idle time updating, also known as "chores".
  12.  
  13.  
  14. To retrieve the next event, the event loop calls the FXApp member function
  15.  
  16.          bool getNextEvent(FXRawEvent& msg, FXbool blocking).
  17.  
  18.  
  19. If the second parameter, blocking, is TRUE, the function will block (not return)
  20. until:
  21.         - either a GUI event (1) occurred,
  22.         - a file handle (3) has been signaled,
  23.         - or a timer (2) is due.
  24.  
  25. The getNextEvent function returns true if a new GUI event (1) occurred. In this
  26. case, the first parameter, msg, contains a new event message. In any other case
  27. the function returns false.
  28.  
  29. Note that if getNextEvent returns due to an expired timer event (2), this will
  30. only be dispateched the NEXT time you call getNextEvent.
  31.  
  32.  
  33. Here is how the most important part of the event loop works:
  34.  
  35.  
  36. bool FXApp::getNextEvent(FXRawEvent& msg, FXbool blocking)
  37. {
  38.     1. check list of timers(2) and handle ALL past due timers.
  39.  
  40.     2. check list of signals(5) and handle them.
  41.  
  42.     3. check if there are  GUI events(1) in the message queue
  43.  
  44.         3.1. -> if there are GUI events, return TRUE and pass the message in
  45.             "msg" to the caller function.
  46.  
  47.         3.2. -> if there are no GUI events, continue:
  48.  
  49.     4. check list of chores(5) and handle (and remove) the next in the list.
  50.  
  51.     5. check if FXApp::refresher points to a widget in the FOX widget tree,
  52.         meaning that a GUI updated is needed for it.
  53.  
  54.         5.1. -> if FXApp::refresher points at some widget, send a SEL_UPDATE
  55.             event to it. Then repoint FXApp::refresher to the next widget,
  56.             found by depth-first traversal. At this point, getNextEvent()
  57.             returns with FALSE, indicating that no GUI event is in the message
  58.             queue. The next time getNextEvent() is called, the next widget will
  59.             be sent the SEL_UPDATE event.
  60.  
  61.         5.2. -> if FXApp::refresher was NULL, this means that all widgets have
  62.             been updated during past getNextEvent() calls. If the application
  63.             requested another GUI refresh by calling FXApp::refresh(), we now
  64.             start over by pointing FXApp::refresher to the application's root
  65.             window, and exit with FALSE.
  66.  
  67.         5.3. -> if no widget needs updating, and no new GUI update has been
  68.             requested, continue:
  69.  
  70.         6. check if new chores(5) have been added to its list of chores. If so,
  71.             exit with FALSE.
  72.  
  73.         7. check once again, just as in 3., for GUI events(1). They could have
  74.             appeared during (4) to (6).
  75.  
  76.             7.1 -> if there are GUI events, return TRUE and pass the message in
  77.                 "msg" to the caller function.
  78.  
  79.             7.2 -> if there are no GUI events, continue:
  80.  
  81.         8. if the caller requested getNextEvent() not to block ("blocking"
  82.             = FALSE), return with FALSE.
  83.  
  84.         9. check the list of timers(2).
  85.  
  86.             9.1. -> if there are due timers, calculate the time until the next
  87.                 timer is due. Then block until the due time, waiting for new GUI
  88.                 events(1) or signaled file descriptors (3).
  89.  
  90.             9.2. -> if there are no due timers, block indefinitely, waiting for
  91.                 new GUI events(1) or signaled file descriptors (3).
  92.  
  93.         10. if 9.1. returned due to the timeout, return FALSE. The due timer
  94.             will be handled in step 1. the next time getNextEvent() is called.
  95.  
  96.         11. if 9.1/9.2 returned due to signaled file descriptors(3), handle
  97.             these.
  98.  
  99.         12. if 9.1/9.2 returned due to new GUI events(1), return TRUE and pass
  100.             the message in "msg" to the caller function.
  101.  
  102.         13. otherwise, return FALSE.
  103. }