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

  1. ;/* Hide.c - Execute me to compile me with SAS/C 6.56
  2. sc DATA=NEAR NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 Hide.c
  3. slink FROM LIB:c.o,Hide.o TO Hide LIBRARY LIB:sc.lib,LIB:amiga.lib
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1991 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga,
  10. Inc. for use with the Amiga Mail Volume II technical publication.
  11. Amiga Mail Volume II contains additional information on the correct
  12. usage of the techniques and operating system functions presented in
  13. these examples.  The source and executable code of these examples may
  14. only be distributed in free electronic form, via bulletin board or
  15. as part of a fully non-commercial and freely redistributable
  16. diskette.  Both the source and executable code (including comments)
  17. must be included, without modification, in any copy.  This example
  18. may not be published in printed form or distributed with any
  19. commercial product. However, the programming techniques and support
  20. routines set forth in these examples may be used in the development
  21. of original executable software products for Commodore Amiga
  22. computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31. #include <intuition/intuition.h>
  32. #include <intuition/screens.h>
  33. #include <graphics/text.h>
  34. #include <libraries/gadtools.h>
  35. #include <workbench/startup.h>
  36. #include <workbench/workbench.h>
  37. #include "hide.h"
  38.  
  39. #ifdef LATTICE
  40. #include <clib/alib_protos.h>
  41. #include <clib/exec_protos.h>
  42. #include <clib/intuition_protos.h>
  43. #include <clib/gadtools_protos.h>
  44. #include <clib/graphics_protos.h>
  45. #include <clib/wb_protos.h>
  46.  
  47. /* disable SAS/C CTRL-C handing */
  48. int             CXBRK(void)
  49. {
  50.     return (0);
  51. }
  52. int             chkabort(void)
  53. {
  54.     return (0);
  55. }
  56.  
  57. #endif
  58.  
  59. struct IntuitionBase *IntuitionBase;
  60. struct GfxBase *GfxBase;
  61. struct WorkbenchBase *WorkbenchBase;
  62. struct Library *GadToolsBase;
  63.  
  64. LONG            main(void);
  65.  
  66. LONG
  67. main(void)
  68. {
  69.     struct Window  *window;
  70.     struct IntuiMessage *imsg;
  71.     struct Gadget  *gadgetcontext;
  72.     struct Gadget  *gadget, *hidegadget;
  73.     struct MsgPort *appport;
  74.     struct NewGadget ng;
  75.     struct TextExtent textextent;
  76.     struct AppIcon *appicon = NULL;
  77.     struct AppMessage *appmsg;
  78.     UWORD           left, top;
  79.     void           *visualinfo;
  80.     ULONG           signal, windowsignal, waitmask;
  81.     BOOL            ABORT = FALSE;
  82.     BOOL            CONTINUE, ICONIFY;
  83.  
  84.     if (IntuitionBase = OpenLibrary("intuition.library", 37))
  85.     {
  86.         /* Open GfxBase to use TextExtent() so we can handle proportional fonts */
  87.         if (GfxBase = OpenLibrary("graphics.library", 37))
  88.         {
  89.             /* Open gadtools for that lonely gadget */
  90.             if (GadToolsBase = OpenLibrary("gadtools.library", 37))
  91.             {
  92.                 if (WorkbenchBase = OpenLibrary("workbench.library", 37))
  93.                 {
  94.                     /* Message to receive appmessage on */
  95.                     if (appport = CreateMsgPort())
  96.                     {
  97.                         /* open a window with tags */
  98.                         left = top = 50;
  99.                         do
  100.                         {
  101.                             /* no NewWindow structure, tags only */
  102.                             if (window = OpenWindowTags(NULL,
  103.                                          /* Open at far left corner */
  104.                                          WA_Left, left,
  105.                                          WA_Top, top,
  106.                                          WA_Width, 150,
  107.                                          WA_Height, 80,
  108.                                          WA_Title, (LONG) "hide",
  109.                                          WA_Flags, WFLG_DRAGBAR |
  110.                                              WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  111.                                              WFLG_ACTIVATE | WFLG_SMART_REFRESH |
  112.                                              WFLG_NOCAREREFRESH,
  113.                                          WA_IDCMP,
  114.                                              IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  115.                                          TAG_DONE))
  116.                             {
  117.                                 windowsignal = 1L << window->UserPort->mp_SigBit;
  118.                                 /*
  119.                                  * Get the visual info gadtools needs for the
  120.                                  * screen we opened on
  121.                                  */
  122.                                 if (visualinfo = GetVisualInfoA(window->WScreen, NULL))
  123.                                 {
  124.  
  125.                                     /*
  126.                                      * Create a simple gadtools button and sort
  127.                                      * of lay it out
  128.                                      */
  129.                                     if (gadget = CreateContext(&gadgetcontext))
  130.                                     {
  131.  
  132.                                         /*
  133.                                          * Use TextExtent to handle
  134.                                          * proportional fonts
  135.                                          */
  136.                                         TextExtent(&(window->WScreen->RastPort),
  137.                                                    "Hide", 4, &textextent);
  138.                                         ng.ng_Width = textextent.te_Width + 8;
  139.                                         ng.ng_LeftEdge = (window->Width / 2)
  140.                                                               - (ng.ng_Width / 2);
  141.                                         ng.ng_Height = textextent.te_Height + 4;
  142.                                         ng.ng_TopEdge = (
  143.                                             (window->Height - window->BorderTop
  144.                                                 - window->BorderBottom) / 2)
  145.                                             + (ng.ng_Height / 2);
  146.                                         ng.ng_TextAttr = window->WScreen->Font;
  147.                                         ng.ng_GadgetText = "Hide";
  148.                                         ng.ng_VisualInfo = visualinfo;
  149.                                         ng.ng_GadgetID = 1;
  150.                                         ng.ng_Flags = PLACETEXT_IN;
  151.                                         hidegadget = gadget =
  152.                                             CreateGadget(BUTTON_KIND, gadget,
  153.                                                          &ng, TAG_END);
  154.                                         AddGList(window, gadget, -1, -1, NULL);
  155.                                         RefreshGList(gadget, window, NULL, -1);
  156.                                         GT_RefreshWindow(window, NULL);
  157.  
  158.                                         CONTINUE = TRUE;
  159.                                         waitmask = windowsignal|
  160.                                                        1L << appport->mp_SigBit;
  161.                                         do
  162.                                         {
  163.                                             signal = Wait(waitmask);
  164.  
  165.                                           if (signal & windowsignal)
  166.                                             {
  167.                                                 while (imsg = (struct IntuiMessage *)
  168.                                                     GetMsg(window->UserPort))
  169.                                                 {
  170.                                                     if (imsg->Class ==
  171.                                                             IDCMP_CLOSEWINDOW)
  172.                                                     {
  173.                                                         ABORT = TRUE;
  174.                                                         CONTINUE = FALSE;
  175.                                                         ICONIFY = FALSE;
  176.                                                     }
  177.                                                     else
  178.                                                     if (imsg->Class == IDCMP_GADGETUP)
  179.                                                         ICONIFY = TRUE;
  180.                                                     ReplyMsg((struct Message *) imsg);
  181.                                                 }
  182.                                             }
  183.                                             if (signal & (1L << appport->mp_SigBit))
  184.                                             {
  185.                                                 while (appmsg = (struct AppMessage *)
  186.                                                     GetMsg(appport))
  187.                                                 {
  188.  
  189.                                                     /*
  190.                                                      * If am->NumArgs is zero
  191.                                                      * the user double-clicked
  192.                                                      * on our icon, otherwise
  193.                                                      * one or more icons were
  194.                                                      * dropped on top of it.
  195.                                                      */
  196.                                                     if (appmsg->am_NumArgs == 0)
  197.                                                     {
  198.                                                         RemoveAppIcon(appicon);
  199.                                                         CONTINUE = FALSE;
  200.                                                     }
  201.                                                     ReplyMsg(
  202.                                                         (struct Message *) appmsg);
  203.                                                 }
  204.                                             }
  205.                                             if (ICONIFY)
  206.                                             {
  207.  
  208.                                                 /*
  209.                                                  * Add appicon, close window if
  210.                                                  * succesful
  211.                                                  */
  212.                                                 appicon = AddAppIcon(1, NULL, "Hide",
  213.                                                     appport, NULL, &AppIconDObj, NULL);
  214.                                                 if (appicon == NULL)
  215.                                                 {
  216.                                                     DisplayBeep(window->WScreen);
  217.                                                 }
  218.                                                 else
  219.                                                 {
  220.                                                     RemoveGadget(window, hidegadget);
  221.                                                     left = window->LeftEdge;
  222.                                                     top = window->TopEdge;
  223.                                                     CloseWindow(window);
  224.                                                     window = NULL;
  225.                                                     /* there is no window
  226.                                                      * message port anymore */
  227.                                                     waitmask =
  228.                                                         1L << appport->mp_SigBit;
  229.                                                 }
  230.                                                 ICONIFY = FALSE;
  231.                                             }
  232.                                         } while (CONTINUE == TRUE);
  233.                                         if (window)
  234.                                             RemoveGadget(window, hidegadget);
  235.                                         FreeGadgets(gadgetcontext);
  236.                                     }
  237.                                     FreeVisualInfo(visualinfo);
  238.                                 }
  239.  
  240.  
  241.                                 if (window)
  242.                                 {
  243.                                     left = window->LeftEdge;
  244.                                     top = window->TopEdge;
  245.                                     CloseWindow(window);
  246.                                 }
  247.                             }
  248.                         } while (ABORT == FALSE);
  249.                         DeleteMsgPort(appport);
  250.                     }
  251.                     CloseLibrary(WorkbenchBase);
  252.                 }
  253.                 CloseLibrary(GadToolsBase);
  254.             }
  255.             CloseLibrary(GfxBase);
  256.         }
  257.         CloseLibrary(IntuitionBase);
  258.     }
  259.     return (0);
  260. }
  261.