home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / blockinput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  4.7 KB  |  195 lines

  1. ;/* blockinput.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 blockinput.c
  3. Blink FROM LIB:c.o,blockinput.o TO blockinput LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. **
  6. ** To use a window as a requester, first bring up a zero-sized requester
  7. ** attached to the main window (this provides the blocking feature).
  8. ** Then, bring up your second window, or bring up a busy pointer.  The
  9. ** following example illustrates bringing up a busy pointer.
  10.  
  11. ** blockinput.c -- program to demonstrate how to block the input from a
  12. ** window using a minimal requester, and how to put up a busy pointer.
  13. */
  14. #define INTUI_V36_NAMES_ONLY
  15.  
  16. #include <exec/types.h>
  17. #include <intuition/intuition.h>
  18.  
  19. #include <clib/exec_protos.h>
  20. #include <clib/intuition_protos.h>
  21.  
  22. #include <stdio.h>
  23.  
  24. #ifdef LATTICE
  25. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  26. int chkabort(void) { return(0); }  /* really */
  27. #endif
  28.  
  29. /* our function prototypes */
  30. BOOL beginWait(struct Window *win, struct Requester *waitRequest);
  31. VOID endWait(struct Window *win, struct Requester *waitRequest);
  32. VOID processIDCMP(struct Window *win);
  33.  
  34. struct Library *IntuitionBase;
  35.  
  36. /* data for a busy pointer.
  37. ** this data must be in chip memory!!!
  38. */
  39. UWORD __chip waitPointer[] =
  40.     {
  41.     0x0000, 0x0000,     /* reserved, must be NULL */
  42.  
  43.     0x0400, 0x07C0,
  44.     0x0000, 0x07C0,
  45.     0x0100, 0x0380,
  46.     0x0000, 0x07E0,
  47.     0x07C0, 0x1FF8,
  48.     0x1FF0, 0x3FEC,
  49.     0x3FF8, 0x7FDE,
  50.     0x3FF8, 0x7FBE,
  51.     0x7FFC, 0xFF7F,
  52.     0x7EFC, 0xFFFF,
  53.     0x7FFC, 0xFFFF,
  54.     0x3FF8, 0x7FFE,
  55.     0x3FF8, 0x7FFE,
  56.     0x1FF0, 0x3FFC,
  57.     0x07C0, 0x1FF8,
  58.     0x0000, 0x07E0,
  59.  
  60.     0x0000, 0x0000,     /* reserved, must be NULL */
  61.     };
  62.  
  63.  
  64.  
  65. /*
  66. ** main()
  67. **
  68. ** Open a window and display a busy-pointer for a short time then wait for
  69. ** the user to hit the close gadget (in processIDCMP()).  Normally, the
  70. ** application would bracket sections of code where it wishes to block window
  71. ** input with the beginWait() and endWait() functions.
  72. */
  73. VOID main (int argc, char **argv)
  74. {
  75. struct Window *win;
  76.  
  77. if (IntuitionBase = OpenLibrary("intuition.library",37))
  78.     {
  79.     if (win = OpenWindowTags(NULL,
  80.                         WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_INTUITICKS,
  81.                         WA_Activate, TRUE,
  82.                         WA_Width,  320,
  83.                         WA_Height, 100,
  84.                         WA_CloseGadget, TRUE,
  85.                         WA_DragBar, TRUE,
  86.                         WA_DepthGadget, TRUE,
  87.                         WA_SizeGadget, TRUE,
  88.                         WA_MaxWidth, ~0,
  89.                         WA_MaxHeight, ~0,
  90.                         TAG_END))
  91.         {
  92.         processIDCMP(win);
  93.         CloseWindow(win);
  94.         }
  95.     CloseLibrary(IntuitionBase);
  96.     }
  97. }
  98.  
  99.  
  100.  
  101. /*
  102. ** beginWait()
  103. **
  104. ** Clear the requester with InitRequester.  This makes a requester of
  105. ** width = 0, height = 0, left = 0, top = 0; in fact, everything is zero.
  106. ** This requester will simply block input to the window until
  107. ** EndRequest is called.
  108. **
  109. ** The pointer is set to a reasonable 4-color busy pointer, with proper offsets.
  110. */
  111. BOOL beginWait(struct Window *win, struct Requester *waitRequest)
  112. {
  113. extern UWORD __chip waitPointer[];
  114.  
  115. InitRequester(waitRequest);
  116. if (Request(waitRequest, win))
  117.     {
  118.     SetPointer(win, waitPointer, 16, 16, -6, 0);
  119.     SetWindowTitles(win,"Busy - Input Blocked",(UBYTE *)~0);
  120.     return(TRUE);
  121.     }
  122. else
  123.     return(FALSE);
  124. }
  125.  
  126.  
  127.  
  128. /*
  129. ** endWait()
  130. **
  131. ** Routine to reset the pointer to the system default, and remove the
  132. ** requester installed with beginWait().
  133. */
  134. VOID endWait(struct Window *win, struct Requester *waitRequest)
  135. {
  136. ClearPointer(win);
  137. EndRequest(waitRequest, win);
  138. SetWindowTitles(win,"Not Busy",(UBYTE *)~0);
  139. }
  140.  
  141.  
  142. /*
  143. ** processIDCMP()
  144. **
  145. ** Wait for the user to close the window.
  146. */
  147. VOID processIDCMP(struct Window *win)
  148. {
  149. WORD done;
  150. struct IntuiMessage *msg;
  151. ULONG class;
  152. struct Requester myreq;
  153. UWORD tick_count;
  154.  
  155. done = FALSE;
  156.  
  157. /* Put up a requester with no imagery (size zero). */
  158. if (beginWait(win,&myreq))
  159.     {
  160.     /*
  161.     ** Insert code here for a window to act as the requester.
  162.     */
  163.  
  164.     /* We'll count down INTUITICKS, which come about ten times
  165.     ** a second.  We'll keep the busy state for about three seconds.
  166.     */
  167.     tick_count = 30;
  168.     }
  169.  
  170. while (!done)
  171.     {
  172.     Wait(1L << win->UserPort->mp_SigBit);
  173.  
  174.     while (NULL != (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  175.         {
  176.         class = msg->Class;
  177.         ReplyMsg((struct Message *)msg);
  178.  
  179.         switch (class)
  180.             {
  181.             case IDCMP_CLOSEWINDOW:
  182.                 done = TRUE;
  183.                 break;
  184.  
  185.             case IDCMP_INTUITICKS:
  186.                 if (tick_count > 0)
  187.                     {
  188.                     if (--tick_count == 0)  endWait(win,&myreq);
  189.                     }
  190.                 break;
  191.             }
  192.         }
  193.     }
  194. }
  195.