home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-3 / pub.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  11KB  |  245 lines

  1. ;/* Pub.c -  V36 Simple public screen example.
  2. ;   Compiled with SAS/C 6.56
  3. sc NMINC STRMERGE NOSTKCHK LINK IGNORE=73 Pub.c
  4. quit
  5.  
  6. Copyright (c) 1990 Commodore-Amiga, Inc.
  7.  
  8. This example is provided in electronic form by Commodore-Amiga,
  9. Inc. for use with the Amiga Mail Volume II technical publication.
  10. Amiga Mail Volume II contains additional information on the correct
  11. usage of the techniques and operating system functions presented in
  12. these examples.  The source and executable code of these examples may
  13. only be distributed in free electronic form, via bulletin board or
  14. as part of a fully non-commercial and freely redistributable
  15. diskette.  Both the source and executable code (including comments)
  16. must be included, without modification, in any copy.  This example
  17. may not be published in printed form or distributed with any
  18. commercial product. However, the programming techniques and support
  19. routines set forth in these examples may be used in the development
  20. of original executable software products for Commodore Amiga
  21. computers.
  22.  
  23. All other rights reserved.
  24.  
  25. This example is provided "as-is" and is subject to change; no
  26. warranties are made.  All use is at your own risk. No liability or
  27. responsibility is assumed.
  28. */
  29.  
  30. #include <intuition/intuition.h>
  31. #include <intuition/screens.h>
  32. #include <graphics/displayinfo.h>
  33. #include <libraries/gadtools.h>
  34. #include <exec/memory.h>
  35. #include <dos/dosextens.h>
  36.  
  37. #include <clib/exec_protos.h>
  38. #include <clib/gadtools_protos.h>
  39. #include <clib/intuition_protos.h>
  40.  
  41. #include <pragmas/exec_pragmas.h>
  42. #include <pragmas/gadtools_pragmas.h>
  43. #include <pragmas/intuition_pragmas.h>
  44.  
  45. struct IntuitionBase *IntuitionBase;
  46. struct Library *GadToolsBase;
  47. extern struct Library *SysBase;
  48.  
  49. static UWORD dri_Pens[] =
  50. {0, 1, 1, 2, 1, 3, 1, 0, 3, ~0};
  51.  
  52. /* Gadtools menu stuff */
  53. #define QUIT 1
  54. struct NewMenu sdm_menu[] =
  55. {
  56.     {NM_TITLE, "Project", 0, 0, 0, 0,},
  57.     {NM_ITEM, "Quit", "Q", 0, 0, (void *) QUIT,},
  58.     {NM_END, NULL, 0, 0, 0, 0,},
  59. };
  60.  
  61. struct EasyStruct failedES =
  62. {
  63.     sizeof(struct EasyStruct), 0, "AMPub",
  64.     "%s",
  65.     "OK",
  66. };
  67.  
  68. void main(void);
  69.  
  70. void
  71. main(void)
  72. {
  73.  
  74.     struct Screen *pubscreen;
  75.     struct Window *window;
  76.     struct Menu *menu;
  77.     void *vi;
  78.  
  79.     struct IntuiMessage *msg;
  80.     UBYTE defaultpubname[MAXPUBSCREENNAME];
  81.     UWORD oldstatus;
  82.     UWORD oldmodes;
  83.     ULONG signal, wsignal, lastsignal, allocsignal;
  84.     ULONG oserror;
  85.     BOOL ABORT = FALSE;
  86.     BOOL CLOSEDOWN = FALSE;
  87.     struct Task *task;
  88.  
  89.     /* Fails silently if not V36 */
  90.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  91.         if (GadToolsBase = OpenLibrary("gadtools.library", 36)) {
  92.             if ((allocsignal = AllocSignal(-1)) != -1) {
  93.                 lastsignal = 1 << allocsignal;
  94.  
  95.                 /* We'll use our task address to get signaled when the last
  96.                  * visitor window leaves. */
  97.                 task =
  98.                   (struct Task *)&((struct Process *)FindTask(NULL))->pr_Task;
  99.  
  100.                 /* Get the name of the currently default
  101.                  * public screen (normally WB) */
  102.                 GetDefaultPubScreen(defaultpubname);
  103.  
  104.                 /* Note that no checking is done to make sure the
  105.                  * public screen name is unique.  If the public name is
  106.                  * not unique, OSERR_PUBNOTUNIQUE is returned in an
  107.                  * application supplied variable as data for the SA_ErrorCode
  108.                  * tag.  In this case however, if OpenScreen fails, for
  109.                  * whatever reason, we just bail out.
  110.                  */
  111.  
  112.                 if (pubscreen = OpenScreenTags(NULL,
  113.                                  SA_DisplayID, HIRES_KEY,
  114.                                  SA_Depth, 2,
  115.                                  SA_Title,  "AmigaMail Test Public Screen",
  116.                                  SA_PubName,"AmigaMail Test Public Screen",
  117.  
  118.                                  SA_PubSig, allocsignal,
  119.                                  SA_PubTask, task,
  120.                                           /* Normally you'd supply 0L, if you
  121.                                           * the task which opened the screen to
  122.                                           * be signaled.
  123.                                           */
  124.                                  SA_Pens, dri_Pens, SA_ErrorCode, &oserror,
  125.                                  TAG_END)) {
  126.                     if (menu = CreateMenus(sdm_menu, TAG_DONE)) {
  127.                         if (window = OpenWindowTags(NULL,
  128.                                       WA_Top, pubscreen->BarHeight + 1,
  129.                                       WA_Height, pubscreen->Height
  130.                                                  - (pubscreen->BarHeight + 1),
  131.                                       WA_CustomScreen, pubscreen,
  132.                                       WA_IDCMP, MENUPICK,
  133.                                       WA_Flags, ACTIVATE|BACKDROP|
  134.                                                     BORDERLESS|NOCAREREFRESH,
  135.                                       TAG_END)) {
  136.  
  137.                             vi = GetVisualInfo(pubscreen, TAG_END);
  138.                             if (LayoutMenus(menu, vi, TAG_DONE)) {
  139.                                 SetMenuStrip(window, menu);
  140.  
  141.                                 /* Now we have a screen, named "AmigaMail Test
  142.                                  * Public Screen", which is still marked
  143.                                  * private, but ready to be made public.
  144.                                  */
  145.                                 oldstatus = PubScreenStatus(pubscreen, 0);
  146.                                 /* Now it is really public. We'll make it the
  147.                                  * default (and shanghai attempts to open
  148.                                  * windows on the Workbench.
  149.                                  */
  150.                                 SetDefaultPubScreen(
  151.                                                "AmigaMail Test Public Screen");
  152.  
  153.                                 oldmodes = SetPubScreenModes(SHANGHAI|
  154.                                                              POPPUBSCREEN);
  155.  
  156.                                 wsignal = 1 << window->UserPort->mp_SigBit;
  157.  
  158.                                 do {
  159.                                     signal = Wait(wsignal|lastsignal);
  160.                                     /* The last visitor just left our screen */
  161.                                     if (signal & lastsignal) {
  162.                                         if (CLOSEDOWN)
  163.                                             if ((oldstatus =
  164.                                                  PubScreenStatus(pubscreen,
  165.                                                            PSNF_PRIVATE)) & 1)
  166.                                                 ABORT = TRUE;
  167.                                     }
  168.  
  169.                                     /* If not wsignal, this while-loop will not
  170.                                      * be executed.
  171.                                      */
  172.                                     while(msg = (struct IntuiMessage *)
  173.                                           GetMsg(window->UserPort)) {
  174.                                     if (msg->Class == MENUPICK) {
  175.                                             if ((UWORD)(MENU_USERDATA
  176.                                                     (ItemAddress(menu,
  177.                                                         msg->Code))) == QUIT) {
  178.                                             /* If we can't make our screen
  179.                                              * private again, we got
  180.                                              * visitor window(s). Note
  181.                                              * window(s) you open without
  182.                                              * specifiying SA_PubScreenName,
  183.                                              * are NOT considered visitor
  184.                                              * windows.  So it's easy to try
  185.                                              * to make your public screen
  186.                                              * private again, without having
  187.                                              * to close down your own windows
  188.                                              * first.
  189.                                              */
  190.  
  191.                                             if ((oldstatus =
  192.                                                  PubScreenStatus(pubscreen,
  193.                                                           PSNF_PRIVATE)) & 1) {
  194.                                                 ABORT = TRUE;
  195.                                                 }
  196.                                             else {
  197.                                                 /* Close as soon as possible */
  198.                                                      CLOSEDOWN = TRUE;
  199.                                                     EasyRequest(window,
  200.                                                                 &failedES,
  201.                                                                 NULL,
  202.                        "Can't make screen private.\nPlease close all windows");
  203.                                                 }
  204.                                             }
  205.                                         }
  206.                                         ReplyMsg((struct Message *)msg);
  207.                                     }
  208.                                 } while (ABORT == FALSE);
  209.  
  210.                                 /* Restore orignal default */
  211.                                 SetDefaultPubScreen(defaultpubname);
  212.                                 ClearMenuStrip(window);
  213.                                 FreeVisualInfo(vi);
  214.                             } else
  215.                                 EasyRequest(NULL,
  216.                                             &failedES,
  217.                                             NULL,
  218.                                             "Can't layout menu's");
  219.                             CloseWindow(window);
  220.                         } else
  221.                             EasyRequest(NULL,
  222.                                         &failedES,
  223.                                         NULL,
  224.                                         "Can't open window");
  225.                         FreeMenus(menu);
  226.                     } else EasyRequest(NULL,
  227.                                        &failedES,
  228.                                        NULL,
  229.                                        "Can't create menu's");
  230.                     CloseScreen(pubscreen);
  231.                 } else
  232.                     EasyRequest(NULL,
  233.                                 &failedES,
  234.                                 NULL,
  235.                                 "Can't open public screen");
  236.                 FreeSignal(allocsignal);
  237.             } else
  238.             EasyRequest(NULL, &failedES, NULL, "No signal available");
  239.             CloseLibrary(GadToolsBase);
  240.         }
  241.     CloseLibrary(IntuitionBase);
  242.     }
  243. }
  244.  
  245.