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

  1. ;/* visiblewindow.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 visiblewindow.c
  3. Blink FROM LIB:c.o,visiblewindow.o TO visiblewindow LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. **
  6. ** open a window on the visible part of a screen, with the window as large
  7. ** as the visible part of the screen.  It is assumed that the visible part
  8. ** of the screen is OSCAN_TEXT, which how the user has set their preferences.
  9. */
  10. #define INTUI_V36_NAMES_ONLY
  11.  
  12. #include <exec/types.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/intuitionbase.h>
  15. #include <graphics/displayinfo.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/graphics_protos.h>
  20.  
  21. #ifdef LATTICE
  22. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  23. int chkabort(void) { return(0); }  /* really */
  24. #endif
  25.  
  26. /* Minimum window width and height:
  27. ** These values should really be calculated dynamically given the size
  28. ** of the font and the window borders.  Here, to keep the example simple
  29. ** they are hard-coded values.
  30. */
  31. #define MIN_WINDOW_WIDTH  (100)
  32. #define MIN_WINDOW_HEIGHT (50)
  33.  
  34. /* minimum and maximum calculations...Note that each argument is
  35. ** evaluated twice (don't use max(a++,foo(c))).
  36. */
  37. #define max(a,b) ((a)>(b)?(a):(b))
  38. #define min(a,b) ((a)<=(b)?(a):(b))
  39.  
  40. struct Library *IntuitionBase;
  41. struct Library *GfxBase;
  42.  
  43. /* our function prototypes */
  44. VOID handle_window_events(struct Window *win);
  45. VOID fullScreen(VOID);
  46.  
  47. /*
  48. ** open all the libraries and run the code.  Cleanup when done.
  49. */
  50. VOID main(int argc, char **argv)
  51. {
  52. /* these calls are only valid if we have Intuition version 37 or greater */
  53. if (GfxBase = OpenLibrary("graphics.library",37))
  54.     {
  55.     if (IntuitionBase = OpenLibrary("intuition.library",37))
  56.         {
  57.         fullScreen();
  58.  
  59.         CloseLibrary(IntuitionBase);
  60.         }
  61.     CloseLibrary(GfxBase);
  62.     }
  63. }
  64.  
  65.  
  66. /*
  67. ** Open a window on the default public screen, then leave it open until the
  68. ** user selects the close gadget. The window is full-sized, positioned in the
  69. ** currently visible OSCAN_TEXT area.
  70. */
  71. VOID fullScreen(VOID)
  72. {
  73. struct Window *test_window;
  74. struct Screen *pub_screen;
  75. struct Rectangle rect;
  76. ULONG screen_modeID;
  77. LONG width, height, left, top;
  78.  
  79. left  = 0;   /* set some reasonable defaults for left, top, width and height. */
  80. top   = 0;   /* we'll pick up the real values with the call to QueryOverscan(). */
  81. width = 640;
  82. height= 200;
  83.  
  84. /* get a lock on the default public screen */
  85. if (NULL != (pub_screen = LockPubScreen(NULL)))
  86.     {
  87.     /* this technique returns the text overscan rectangle of the screen that we
  88.     ** are opening on.  If you really need the actual value set into the display
  89.     ** clip of the screen, use the VideoControl() command of the graphics library
  90.     ** to return a copy of the ViewPortExtra structure.  See the Graphics
  91.     ** library chapter and Autodocs for more details.
  92.     **
  93.     ** GetVPModeID() is a graphics call...
  94.     */
  95.  
  96.     screen_modeID = GetVPModeID(&pub_screen->ViewPort);
  97.     if(screen_modeID != INVALID_ID)
  98.         {
  99.         if (QueryOverscan(screen_modeID, &rect, OSCAN_TEXT))
  100.             {
  101.             /* make sure window coordinates are positive or zero */
  102.             left = max(0, -pub_screen->LeftEdge);
  103.             top  = max(0, -pub_screen->TopEdge);
  104.  
  105.             /* get width and height from size of display clip */
  106.             width  = rect.MaxX - rect.MinX + 1;
  107.             height = rect.MaxY - rect.MinY + 1;
  108.  
  109.             /* adjust height for pulled-down screen (only show visible part) */
  110.             if (pub_screen->TopEdge > 0)
  111.                 height -= pub_screen->TopEdge;
  112.  
  113.             /* insure that window fits on screen */
  114.             height = min(height, pub_screen->Height);
  115.             width  = min(width,  pub_screen->Width);
  116.  
  117.             /* make sure window is at least minimum size */
  118.             width  = max(width,  MIN_WINDOW_WIDTH);
  119.             height = max(height, MIN_WINDOW_HEIGHT);
  120.             }
  121.         }
  122.  
  123.     /* open the window on the public screen */
  124.     test_window = OpenWindowTags(NULL,
  125.             WA_Left, left,            WA_Width,  width,
  126.             WA_Top,  top,             WA_Height, height,
  127.             WA_CloseGadget, TRUE,
  128.             WA_IDCMP,       IDCMP_CLOSEWINDOW,
  129.             WA_PubScreen,   pub_screen,
  130.             TAG_END);
  131.  
  132.     /* unlock the screen.  The window now acts as a lock on the screen,
  133.     ** and we do not need the screen after the window has been closed.
  134.     */
  135.     UnlockPubScreen(NULL, pub_screen);
  136.  
  137.     /* if we have a valid window open, run the rest of the
  138.     ** program, then clean up when done.
  139.     */
  140.     if (test_window)
  141.         {
  142.         handle_window_events(test_window);
  143.         CloseWindow(test_window);
  144.         }
  145.     }
  146. }
  147.  
  148.  
  149. /*
  150. ** Wait for the user to select the close gadget.
  151. */
  152. VOID handle_window_events(struct Window *win)
  153. {
  154. struct IntuiMessage *msg;
  155. BOOL done = FALSE;
  156.  
  157. while (! done)
  158.     {
  159.     /* we only have one signal bit, so we do not have to check which
  160.     ** bit(s) broke the Wait() (i.e. the return value of Wait)
  161.     */
  162.     Wait(1L << win->UserPort->mp_SigBit);
  163.  
  164.     while ( (! done) &&
  165.             (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  166.         {
  167.         /* use a switch statement if looking for multiple event types */
  168.         if (msg->Class == IDCMP_CLOSEWINDOW)
  169.             done = TRUE;
  170.  
  171.         ReplyMsg((struct Message *)msg);
  172.         }
  173.     }
  174. }
  175.