home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / devcon / sanfrancisco_1989 / sf-devcon89.1 / commodities / aztec / popup / demowindow.c < prev    next >
C/C++ Source or Header  |  1992-08-27  |  3KB  |  161 lines

  1. /* demowindow.c -- Intuition Interface */
  2.  
  3. /*
  4. Copyright (c) 1987, 1988, 1989 Jim Mackraz and I&I Computing.
  5.  
  6. Executables based on this information may be used in software
  7. for Commodore Amiga computers.  All other rights reserved.
  8. This information is provided "as is"; no warranties are made.
  9. All use is at your own risk, and no liability or responsibility
  10. is assumed.
  11. */
  12.  
  13. #include "sysall.h"
  14.  
  15. #include <intuition/intuition.h>
  16.  
  17. #define D(x)    ;
  18. /* #define printf    kprintf */
  19.  
  20. extern struct MsgPort    *iport;
  21. extern ULONG            isigflag;
  22.  
  23. struct Window    *window = NULL;
  24.  
  25. #define SLEEPGADGET    (25)
  26. #define QUITGADGET  (26)
  27.  
  28. handleIMsg( msg )
  29. struct IntuiMessage    *msg;
  30. {
  31.     ULONG    class;
  32.     UWORD    code;
  33.     struct Gadget    *gaddress;
  34.  
  35.     class = msg->Class;
  36.     code = msg->Code;
  37.     gaddress = (struct Gadget *) msg->IAddress;
  38.  
  39.     ReplyMsg( msg );
  40.  
  41.     switch ( class )
  42.     {
  43.     case CLOSEWINDOW:
  44.         D( printf("close window (sleep)\n") );
  45.         shutdownWindow();
  46.         break;            /* not reached    */
  47.  
  48.     case REFRESHWINDOW:
  49.         D( printf("refresh window\n") );
  50.         BeginRefresh( window );
  51.         printMessage();
  52.         EndRefresh( window, 1L );
  53.         break;
  54.  
  55.     case GADGETUP:
  56.         switch ( gaddress->GadgetID )
  57.         {
  58.         case SLEEPGADGET:
  59.             shutdownWindow();
  60.             break;
  61.  
  62.         case QUITGADGET:
  63.             terminate();
  64.         }
  65.         break;
  66.     }
  67. }
  68.  
  69. /* save window positions and dims    */
  70. WORD    savewindow[ 4 ] =  { 134, 64, 362, 68 };
  71.  
  72. setupWindow()
  73. {
  74.     struct Window    *getNewWindow();
  75.  
  76.     if ( window )
  77.     {    
  78.         WindowToFront( window );
  79.         return;        /* already setup, nothing to re-init    */
  80.     }
  81.  
  82.     /* open window    */
  83.     if ( ! ( window = getNewWindow() ) ) return;
  84.  
  85.     iport = window->UserPort;
  86.     isigflag = 1L << iport->mp_SigBit;
  87.  
  88.     printMessage();
  89. }
  90.  
  91. shutdownWindow()
  92. {
  93.     WORD    *wp;
  94.  
  95.     if ( ! window ) return;
  96.  
  97.     /* save window position    */
  98.     wp = savewindow;
  99.     *wp++ = window->LeftEdge;
  100.     *wp++ = window->TopEdge;
  101.     *wp++ = window->Width;
  102.     *wp = window->Height;
  103.  
  104.     CloseWindow( window );
  105.     window = NULL;
  106.     iport = NULL;
  107.     isigflag = NULL;
  108. }
  109.  
  110. #define IFLAGS (CLOSEWINDOW | GADGETUP | REFRESHWINDOW )
  111.  
  112. #define WFLAGS \
  113.     (WINDOWCLOSE | WINDOWDRAG | WINDOWSIZING | WINDOWDEPTH | SIMPLE_REFRESH )
  114.  
  115. #define WTITLE    ((UBYTE *) " Commodities Demo Pop-up Window ")
  116.  
  117. struct  Window *
  118. getNewWindow()
  119. {
  120.     struct  Window  *OpenWindow();
  121.     struct  NewWindow   nw;
  122.     WORD    *wp = savewindow;
  123.  
  124.     nw.LeftEdge =   *wp++;
  125.     nw.TopEdge  =   *wp++;
  126.     nw.Width    =   *wp++;
  127.     nw.Height   =   *wp++;
  128.     nw.DetailPen    =   (UBYTE) -1;
  129.     nw.BlockPen =   (UBYTE) -1;
  130.     nw.IDCMPFlags   =  IFLAGS;
  131.  
  132.     nw.Flags    =   WFLAGS;
  133.  
  134.     nw.FirstGadget  =   NULL;
  135.     nw.CheckMark    =   NULL;
  136.     nw.Title    =   WTITLE;
  137.     nw.Screen   =   NULL;
  138.     nw.BitMap   =   NULL;
  139.     nw.MinWidth =   50;
  140.     nw.MinHeight=   30;
  141.     /* work around bug  */
  142.     nw.MaxWidth =   -1;
  143.     nw.MaxHeight    =   -1;
  144.     nw.Type     =   WBENCHSCREEN;
  145.  
  146.     return ((struct Window *) OpenWindow(&nw));
  147. }
  148.  
  149. extern char    hotkeybuff[];
  150.  
  151. struct IntuiText    msgitext[2] = {
  152.  { 1, 0, JAM1, 40, 30, NULL, (UBYTE *) "My Pop-Up Hotkey is:", &msgitext[1] },
  153.  { 3, 0, JAM1, 60, 41, NULL, (UBYTE *) hotkeybuff, NULL },
  154. };
  155.  
  156. printMessage()
  157. {
  158.     if ( window ) PrintIText( window->RPort, msgitext, 0L, 0L );
  159.     return;
  160. }
  161.