home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Precognition / MsgWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-15  |  4.4 KB  |  191 lines

  1. /* =====================================================
  2. **   Created by the Precognition Interface Builder
  3. ** =====================================================
  4. **
  5. **  Link this file with 'Precognition.lib'
  6. **
  7. */
  8.  
  9. #include "Precognition.h"
  10. #include "Intuition_Utils.h"
  11. #include "chainedwindows.h"
  12. #include "MsgWindow.h"
  13. #ifndef __GNUC__
  14. #include <clib/exec_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #endif
  18. #ifdef __GNUC__
  19. #include <proto/exec.h>
  20. #include <proto/intuition.h>
  21. #include <proto/graphics.h>
  22. #endif
  23. #ifdef __SASC
  24. #include <proto/exec.h>
  25. #include <proto/intuition.h>
  26. #include <proto/graphics.h>
  27. #endif
  28. #include <string.h>
  29. #include "BuilderWindow.h"
  30.  
  31. extern struct MsgPort *shared_port;
  32. extern struct Screen *screen;
  33.  
  34. /*
  35. ** The event loop is terminated when 'MsgWindow_Done' is true.
  36. */
  37.  
  38.  
  39. struct MsgWindow
  40. {
  41.    pcgWindow           w;
  42.    BoolGadget           bg_ok;
  43.    struct IntuiText  text;
  44.    BOOL              done;
  45. };
  46.  
  47. /*=============== Prototypes ====================*/
  48.  
  49.  
  50.    void  MsgWindow_Init (
  51.               struct MsgWindow *window,
  52.               struct Screen *screen,
  53.               char *text );
  54.  
  55.    void  MsgWindow_CleanUp ( struct MsgWindow *window );
  56.  
  57.    ULONG MsgWindow_Respond (
  58.               struct MsgWindow *window,
  59.               struct IntuiMessage *event );
  60.  
  61.  
  62. extern struct BuilderWindow builderwindow;
  63.  
  64. void MsgWindow_Init ( window, screen, text )
  65.    struct MsgWindow *window;
  66.    struct Screen *screen;
  67.    char *text;
  68. {
  69.  
  70.    pcg_3DPens    pens;
  71.  
  72.    window->done = FALSE;
  73. /*   pens = StandardPens(); */
  74.    pens = StandardScreenPens( screen );
  75.  
  76.    /* Initialize the window */
  77.    pcgWindow_Init( &window->w,
  78.       0, 12, 464, 75, /* LeftEdge, TopEdge, Width, Height */
  79.       100, 50, 65535, 65535, /* min width & height, max width & height */
  80.       "Precognition Builder", /* title */
  81.       REFRESHWINDOW, /* IDCMPFlags */
  82.       WINDOWDRAG | WINDOWDEPTH | SIMPLE_REFRESH | ACTIVATE, /* Flags */
  83.       screen );
  84.  
  85.    window->w.SharedUserPort = shared_port;
  86.  
  87.    BoolGadget_Init( &window->bg_ok,
  88.       182, 56, 96, 14, /* LeftEdge, TopEdge, Width, Height */
  89.       pens, "OK" );
  90.    SetTextAlignment( (GraphicObject *)&window->bg_ok, tx_XCENTER | tx_YCENTER, 0, 0 );
  91.    AddWindowPObject( &window->w, (GraphicObject*) &window->bg_ok );
  92.  
  93.    window->text.FrontPen  = 1;
  94.    window->text.BackPen   = 0;
  95.    window->text.DrawMode  = JAM1;
  96.    window->text.LeftEdge  = 10;
  97.    window->text.TopEdge   = 20;
  98.    window->text.ITextFont = &pcg_Topaz80;
  99.    window->text.IText     = text;
  100.    window->text.NextText  = NULL;
  101.  
  102. }
  103.  
  104.  
  105. void MsgWindow_CleanUp ( window )
  106.    struct MsgWindow *window;
  107. {
  108.    CleanUp( (PObject *)&window->w );
  109.    CleanUp( (PObject *)&window->bg_ok );
  110. }
  111.  
  112.  
  113. ULONG MsgWindow_Respond ( window, event )
  114.      struct MsgWindow *window;
  115.      struct IntuiMessage *event;
  116. {
  117.  
  118.    ULONG response, r;
  119.    struct Window *intuition_window;
  120.  
  121.    response = 0L;
  122.  
  123.    /* check to see if 'event' happenned in this window */
  124.    intuition_window = iWindow(&window->w);
  125.    if( event->IDCMPWindow == intuition_window )
  126.    {
  127.       switch( event->Class )
  128.       {
  129.  
  130.          case REFRESHWINDOW:
  131.             BeginRefresh( intuition_window );
  132.             Refresh( (Interactor *)&window->w );
  133.             PrintIText( RPort( &window->w ), &window->text, 0, 0 );
  134.             EndRefresh( intuition_window, TRUE );
  135.             break;
  136.  
  137.          default:
  138.             r = Respond( (Interactor *)&window->bg_ok, event );
  139.             if( r & CHANGED_STATE )
  140.             {  /* bg_ok was hit. */
  141.                response |= r;
  142.                window->done = TRUE;
  143.             }
  144.             break;
  145.  
  146.       } /* end switch */
  147.  
  148.    } /* end if */
  149.  
  150.    return response;
  151. }
  152.  
  153.  
  154. void do_MsgWindow( char *text )
  155. {
  156.    struct MsgWindow MsgWindow;
  157.    struct Window *iw;              /* Intuition window */
  158.    struct IntuiMessage *imsg, event;
  159.  
  160.    EnableAllChainedWindows( FALSE );
  161.  
  162.    MsgWindow_Init( &MsgWindow, screen, text );
  163.  
  164.    if( ( iw = pcgOpenWindow( &MsgWindow.w ) ) != NULL )
  165.    {
  166.       PrintIText( RPort( &MsgWindow.w ), &MsgWindow.text, 0, 0 );
  167.  
  168.       /*====== Event Loop ================*/
  169.       while ( ! MsgWindow.done )
  170.       {
  171.          imsg = WaitForMessage( shared_port );
  172.          event = *imsg;
  173.          ReplyMsg( (struct Message *)imsg );
  174.  
  175.          MsgWindow_Respond( &MsgWindow, &event );
  176.  
  177.       }
  178.  
  179.       pcgCloseWindow( &MsgWindow.w );
  180.    }
  181.    else /* Error : window couldn't be openned. */
  182.    {
  183.       ; /*** YOUR ERROR HANDLING HERE ***/
  184.    }
  185.  
  186.    MsgWindow_CleanUp( &MsgWindow );
  187.    EnableAllChainedWindows( TRUE );
  188.  
  189. }
  190.  
  191.