home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / ShowHelp / Fake_ModalDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-06  |  1.3 KB  |  48 lines  |  [TEXT/KAHL]

  1. #include "Show_help.h"
  2.  
  3. #define        MODAL_MASK    0x017F    // don't take disk, OS, or high-level events
  4.  
  5. /*    ---------------------------------------------------------------------
  6.     Fake_ModalDialog        ModalDialog cannot be used to handle movable
  7.                             modal dialogs (without skanky hacks) because
  8.                             it prevents one from switching to another
  9.     application, even if the window is not of the dBoxProc type.  Therefore
  10.     I use this routine, which simulates much of what ModalDialog does.
  11.     ---------------------------------------------------------------------
  12. */
  13. pascal void Fake_ModalDialog( ModalFilterProcPtr filterProc,short *itemHit )
  14. {
  15.     EventRecord        event;
  16.     Boolean            handled;
  17.     DialogPtr        front, which_dialog;
  18.     short            what_hit;
  19.     
  20.     *itemHit = 0;
  21.     front = FrontWindow();
  22.     
  23.     do {
  24.         GetNextEvent( MODAL_MASK, &event );
  25.         handled = filterProc( front, &event, itemHit );
  26.         if (!handled)
  27.         {
  28.             if (IsDialogEvent(&event))
  29.             {
  30.                 if (DialogSelect( &event, &which_dialog, &what_hit ))
  31.                 {
  32.                     if (which_dialog == front)
  33.                     {
  34.                         *itemHit = what_hit;
  35.                     }
  36.                 }
  37.                 if (which_dialog == front)
  38.                     handled = true;
  39.             }
  40.             /*
  41.                 Beep if there is a mouse click on another window
  42.                 owned by this application.
  43.             */
  44.             if ( !handled && (event.what == mouseDown) )
  45.                 SysBeep(1);
  46.         }
  47.     } while (*itemHit == 0);
  48. }