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 / SavePrompt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-15  |  6.1 KB  |  235 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 "SavePrompt.h"
  13. #ifndef __GNUC__
  14. #include <clib/exec_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/exec_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 <stdio.h> /* added for sprintf() prototype -- EDB */
  30. #include "BuilderWindow.h"
  31.  
  32. extern struct MsgPort *shared_port;
  33. extern struct Screen *screen;
  34.  
  35. /*
  36. ** The event loop is terminated when 'SavePrompt_Done' is true.
  37. */
  38.  
  39.  
  40. struct SavePrompt
  41. {
  42.    pcgWindow           w;
  43.    BoolGadget           bg_save;
  44.    BoolGadget           bg_dontsave;
  45.    BoolGadget           bg_cancel;
  46.    struct IntuiText  text;
  47.    BOOL              done;
  48.    int               result;
  49. };
  50.  
  51. char saveprompt_text[80];
  52.  
  53. /*=============== Prototypes ====================*/
  54.  
  55.  
  56.    void  SavePrompt_Init (
  57.               struct SavePrompt *window,
  58.               struct Screen *screen );
  59.  
  60.    void  SavePrompt_CleanUp ( struct SavePrompt *window );
  61.  
  62.    ULONG SavePrompt_Respond (
  63.               struct SavePrompt *window,
  64.               struct IntuiMessage *event );
  65.  
  66.  
  67. extern struct BuilderWindow builderwindow;
  68.  
  69. void SavePrompt_Init ( window, screen )
  70.    struct SavePrompt *window;
  71.    struct Screen *screen;
  72. {
  73.  
  74.    pcg_3DPens    pens;
  75.    char *objectname;
  76.  
  77.    window->done = FALSE;
  78. /*   pens = StandardPens();  */
  79.    pens = StandardScreenPens( screen );
  80.  
  81.    /* Initialize the window */
  82.    pcgWindow_Init( &window->w,
  83.       0, 12, 464, 75, /* LeftEdge, TopEdge, Width, Height */
  84.       100, 50, 65535, 65535, /* min width & height, max width & height */
  85.       "Save your work?", /* title */
  86.       REFRESHWINDOW, /* IDCMPFlags */
  87.       WINDOWDRAG | WINDOWDEPTH | SIMPLE_REFRESH | ACTIVATE, /* Flags */
  88.       screen );
  89.  
  90.    window->w.SharedUserPort = shared_port;
  91.  
  92.    BoolGadget_Init( &window->bg_save,
  93.       8, 56, 96, 14, /* LeftEdge, TopEdge, Width, Height */
  94.       pens, "SAVE" );
  95.    SetTextAlignment( (GraphicObject *)&window->bg_save, tx_XCENTER | tx_YCENTER, 0, 0 );
  96.    AddWindowPObject( &window->w, (GraphicObject *)&window->bg_save );
  97.  
  98.    BoolGadget_Init( &window->bg_dontsave,
  99.       182, 56, 96, 14, /* LeftEdge, TopEdge, Width, Height */
  100.       pens, "DON'T SAVE" );
  101.    SetTextAlignment( (GraphicObject *)&window->bg_dontsave, tx_XCENTER | tx_YCENTER, 0, 0 );
  102.    AddWindowPObject( &window->w, (GraphicObject *)&window->bg_dontsave );
  103.  
  104.    BoolGadget_Init( &window->bg_cancel,
  105.       360, 56, 96, 14, /* LeftEdge, TopEdge, Width, Height */
  106.       pens, "CANCEL" );
  107.    SetTextAlignment( (GraphicObject *)&window->bg_cancel, tx_XCENTER | tx_YCENTER, 0, 0 );
  108.    AddWindowPObject( &window->w, (GraphicObject *)&window->bg_cancel );
  109.  
  110.    objectname = PObjectName( (struct PObject *)&builderwindow );
  111.    sprintf( saveprompt_text, "Project \"%s\" has not been saved.", objectname );
  112.  
  113.    window->text.FrontPen  = 1;
  114.    window->text.BackPen   = 0;
  115.    window->text.DrawMode  = JAM1;
  116.    window->text.LeftEdge  = 10;
  117.    window->text.TopEdge   = 20;
  118.    window->text.ITextFont = &pcg_Topaz80;
  119.    window->text.IText     = saveprompt_text;
  120.    window->text.NextText  = NULL;
  121.  
  122. }
  123.  
  124.  
  125. void SavePrompt_CleanUp ( window )
  126.    struct SavePrompt *window;
  127. {
  128.    CleanUp( (PObject *)&window->w );
  129.    CleanUp( (PObject *)&window->bg_save );
  130.    CleanUp( (PObject *)&window->bg_dontsave );
  131.    CleanUp( (PObject *)&window->bg_cancel );
  132. }
  133.  
  134.  
  135. ULONG SavePrompt_Respond ( window, event )
  136.      struct SavePrompt *window;
  137.      struct IntuiMessage *event;
  138. {
  139.  
  140.    ULONG response, r;
  141.    struct Window *intuition_window;
  142.  
  143.    response = 0L;
  144.  
  145.    /* check to see if 'event' happenned in this window */
  146.    intuition_window = iWindow( &window->w );
  147.    if( event->IDCMPWindow == intuition_window )
  148.    {
  149.       switch( event->Class )
  150.       {
  151.  
  152.          case REFRESHWINDOW:
  153.             BeginRefresh( intuition_window );
  154.             Refresh( (Interactor *)&window->w );
  155.             PrintIText( RPort( &window->w ), &window->text, 0, 0 );
  156.             EndRefresh( intuition_window, TRUE );
  157.             break;
  158.  
  159.          default:
  160.             r = Respond( (Interactor *)&window->bg_save, event );
  161.             if( r & CHANGED_STATE )
  162.             {  /* bg_save was hit. */
  163.                response |= r;
  164.                window->done = TRUE;
  165.                window->result = SP_SAVE;
  166.             }
  167.  
  168.             r = Respond( (Interactor *)&window->bg_dontsave, event );
  169.             if( r & CHANGED_STATE )
  170.             {  /* bg_dontsave was hit. */
  171.                response |= r;
  172.                window->done = TRUE;
  173.                window->result = SP_DONT_SAVE;
  174.             }
  175.  
  176.             r = Respond( (Interactor *)&window->bg_cancel, event );
  177.             if( r & CHANGED_STATE )
  178.             {  /* bg_cancel was hit. */
  179.                response |= r;
  180.                window->done = TRUE;
  181.                window->result = SP_CANCEL;
  182.             }
  183.  
  184.             break;
  185.  
  186.       } /* end switch */
  187.  
  188.    } /* end if */
  189.  
  190.    return response;
  191. }
  192.  
  193.  
  194. int do_SavePrompt( void )
  195. {
  196.    struct SavePrompt SavePrompt;
  197.    struct Window *iw;              /* Intuition window */
  198.    struct IntuiMessage *imsg, event;
  199.    int result;
  200.  
  201.    EnableAllChainedWindows( FALSE );
  202.  
  203.    SavePrompt_Init( &SavePrompt, screen );
  204.  
  205.    if( ( iw = pcgOpenWindow( &SavePrompt.w ) ) != NULL )
  206.    {
  207.       PrintIText( RPort( &SavePrompt.w ), &SavePrompt.text, 0, 0 );
  208.  
  209.       /*====== Event Loop ================*/
  210.       while( ! SavePrompt.done )
  211.       {
  212.          imsg = WaitForMessage( shared_port );
  213.          event = *imsg;
  214.          ReplyMsg( (struct Message *)imsg );
  215.  
  216.          SavePrompt_Respond( &SavePrompt, &event );
  217.  
  218.       }
  219.  
  220.       pcgCloseWindow( &SavePrompt.w );
  221.    }
  222.    else /* Error : window couldn't be openned. */
  223.    {
  224.       ; /*** YOUR ERROR HANDLING HERE ***/
  225.    }
  226.  
  227.    result = SavePrompt.result;
  228.    SavePrompt_CleanUp( &SavePrompt );
  229.    EnableAllChainedWindows( TRUE );
  230.  
  231.    return result;
  232. }
  233.  
  234.  
  235.