home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / requester / nonmodal / requester.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  3.9 KB  |  218 lines

  1. /*
  2. *  $
  3. *  $ FILE     : requester.c
  4. *  $ VERSION  : 1
  5. *  $ REVISION : 2
  6. *  $ DATE     : 08-Dec-93 19:19
  7. *  $
  8. *  $ Author   : mvk
  9. *  $
  10. **
  11. **  This example shows how to use the egsrequest.library.
  12. **  It is an example for non modal requester.
  13. **  You can request a lot of messages without waiting for
  14. **  response from the user.
  15. **  For example the Filerequester:  The user make some
  16. **  mistakes (select a File as a Device) then you can give
  17. **  him a requester.
  18. **
  19. **  (c) by VIONA-Development 1992/94
  20. **
  21. */
  22.  
  23.  
  24. /*
  25. ** Init-Routines
  26. */
  27.  
  28. #include "global.h"
  29.  
  30. /*
  31. **
  32. */
  33.  
  34. ER_FileRequestPtr    freq;
  35. ER_SimpleReqPtr      sreq,sreq1,sreq2,sreq3;
  36. EI_EIntuiMsgPtr      msg;
  37. ER_ReqContextPtr     mycon;
  38. ER_RequestPtr        req;
  39.  
  40. struct     MsgPort  *port;
  41.  
  42.  
  43. void myError(char *string,int ende)
  44. {
  45.  
  46.   if ( string != NULL)
  47.       printf("%s\n",string);
  48.  
  49.   CloseLibraries(OpenStruct);
  50.  
  51.   if (ende)
  52.        exit(0);
  53.  
  54. }
  55.  
  56. /*
  57. **
  58. ** Open the Libraries
  59. **
  60. */
  61.  
  62. BOOL InitLibraries(struct OpenStructTyp *OS)
  63. {
  64.  struct OpenStructTyp *p = &OS[0];
  65.  
  66.  while (p->Var != NULL)
  67.  {
  68.    if ((*(p->Var) = (ULONG)OpenLibrary(p->Name,p->Version)) == NULL)
  69.        {
  70.        printf(" Can't open %s version %d",p->Name, p->Version);
  71.        return FALSE;
  72.        }
  73.        else
  74.        {  p ++; }
  75.  }
  76.    return TRUE;
  77. }
  78. /**/
  79.  
  80. /*
  81. **
  82. ** Close Libs
  83. **
  84. */
  85.  
  86. void CloseLibraries(struct OpenStructTyp *OS)
  87. {
  88.  struct OpenStructTyp *p = &OS[0];
  89.  
  90.  while (p->Name != NULL)
  91.  {
  92.     CloseLibrary((void *)(*(p->Var)));
  93.     *(p->Var) = NULL;
  94.     p++;
  95.  }
  96. }
  97.  
  98.  
  99. main()
  100. {
  101.  
  102.     if ( InitLibraries(OpenStruct) == FALSE)
  103.          myError("Can't OpenLibrary",10);
  104.  
  105.     port = CreatePort(NULL,0);
  106.  
  107.     if ( port == NULL )
  108.         myError("Can't create port",10);
  109.  
  110.     mycon = ER_CreateReqContext();
  111.  
  112.     if (mycon != NULL)
  113.     {
  114.         /*
  115.         ** Create the context for all
  116.         */
  117.  
  118.         freq=ER_CreateFileReq(mycon);
  119.         sreq=ER_CreateSimpleReq(mycon,
  120.            " ! ERROR ! | You select a filename | as a device !",
  121.            " YES | MAY BE | NO ");
  122.  
  123.         sreq1=ER_CreateSimpleReq(mycon,
  124.            " ! ERROR ! | The selected path | doesn't exists !",
  125.            " YES | MAY BE | NO ");
  126.  
  127.         sreq2=ER_CreateSimpleReq(mycon,
  128.            " ! ERROR ! | You select a wrong | devicename !",
  129.            " YES | MAY BE | NO ");
  130.  
  131.         sreq3=ER_CreateSimpleReq(mycon,
  132.            " This is a demo | for non modal  | requesters !",
  133.            " YES ");
  134.  
  135.         /*
  136.         ** Init Port in requester struct for use
  137.         ** non modal requesters.
  138.         **
  139.         ** Without a port the the OpenRequest will create
  140.         ** a own port. So that any requester have an own
  141.         ** MsgPort (modal).
  142.         **
  143.         **
  144.         */
  145.  
  146.         freq->Req.Port=port;
  147.         sreq->Req.Port=port;
  148.         sreq1->Req.Port=port;
  149.         sreq2->Req.Port=port;
  150.         sreq3->Req.Port=port;
  151.  
  152.         if (freq != NULL && sreq != NULL)
  153.         if ( (sreq1 != NULL) && (sreq2 != NULL) && (sreq3 != NULL) )
  154.         {
  155.  
  156.               freq->Req.Title="Titel1";
  157.               sreq->Req.Title="Titel2";
  158.               sreq1->Req.Title="Titel3";
  159.               sreq2->Req.Title="Titel4";
  160.               sreq3->Req.Title="Titel5";
  161.  
  162.  
  163.             if ( ER_OpenRequest((ER_RequestPtr)freq,NULL)  &&
  164.                  ER_OpenRequest((ER_RequestPtr)sreq,NULL)  &&                             ER_OpenRequest((ER_RequestPtr)sreq1,NULL) &&
  165.                  ER_OpenRequest((ER_RequestPtr)sreq1,NULL) &&
  166.                  ER_OpenRequest((ER_RequestPtr)sreq2,NULL) &&
  167.                  ER_OpenRequest((ER_RequestPtr)sreq3,NULL)
  168.                  ){
  169.  
  170.              while(freq->Req.RWindow)
  171.              {
  172.                  WaitPort(port);
  173.  
  174.                  msg=(EI_EIntuiMsgPtr)GetMsg((struct MsgPort *)port);
  175.  
  176.                 /*
  177.                 ** Find the Requester for the msg
  178.                 **
  179.                 ** if req == NULL the msg
  180.                 ** is not from a EGS Requester
  181.                 **
  182.                 */
  183.  
  184.                  if (msg != NULL)
  185.                 req = ER_FindRequest(mycon,msg);
  186.  
  187.                 if (req != NULL)
  188.                 {
  189.                     /*
  190.                     ** Handle the msg !
  191.                     ** For example close Requester
  192.                     */
  193.  
  194.                     ER_IterateRequest(req, msg);
  195.  
  196.    //                             printf("Selected gadget%d\n",sreq->Selected);
  197.  
  198.                 }
  199.  
  200.                  ReplyMsg((struct Message *)msg);
  201.  
  202.                } // while
  203.  
  204.              printf("Name = %s \n\n",freq->Name);
  205.  
  206.         } // if
  207.        }
  208.     }
  209.  
  210.       if( mycon != NULL )
  211.          ER_DeleteReqContext(mycon);
  212.  
  213.       myError(NULL,10);
  214.  
  215. }/* END */
  216.  
  217.  
  218.