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

  1. /* clonescreen.c
  2. ** clone an existing public screen.
  3. **
  4. ** SAS/C 5.10a
  5. ** lc -b1 -cfist -v -y clonescreen
  6. ** blink FROM LIB:c.o clonescreen.o TO clonescreen LIB LIB:lc.lib LIB:amiga.lib
  7. */
  8.  
  9. #define INTUI_V36_NAMES_ONLY
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/screens.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <clib/intuition_protos.h>
  20.  
  21. #include <string.h>
  22.  
  23. #ifdef LATTICE
  24. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  25. int chkabort(void) { return(0); }  /* really */
  26. #endif
  27.  
  28. VOID cloneScreen( UBYTE * );
  29.  
  30. struct Library *IntuitionBase;
  31. struct GfxBase *GfxBase;
  32.  
  33. /*
  34. ** Open all libraries for the cloneScreen() subroutine.
  35. */
  36. VOID main(int argc, char **argv)
  37. {
  38. UBYTE *pub_screen_name = "Workbench";
  39.  
  40. IntuitionBase = OpenLibrary("intuition.library",0);
  41. if (IntuitionBase != NULL)
  42.     {
  43.     /* Require version 37 of Intuition. */
  44.     if (IntuitionBase->lib_Version >= 37)
  45.         {
  46.         /* Note the two methods of getting the library version
  47.         ** that you really want.
  48.         */
  49.         GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37);
  50.         if (GfxBase != NULL)
  51.             {
  52.             cloneScreen(pub_screen_name);
  53.  
  54.             CloseLibrary((struct Library *)GfxBase);
  55.             }
  56.         }
  57.     CloseLibrary(IntuitionBase);
  58.     }
  59. }
  60.  
  61. /* Clone a public screen whose name is passed to the routine.
  62. **    Width, Height, Depth, Pens, Font and DisplayID attributes are
  63. ** all copied from the screen.
  64. **    Overscan is assumed to be OSCAN_TEXT, as there is no easy way to
  65. ** find the overscan type of an existing screen.
  66. **    AutoScroll is turned on, as it does not hurt.  Screens that are
  67. ** smaller than the display clip will not scroll.
  68. */
  69.  
  70. VOID cloneScreen(UBYTE *pub_screen_name)
  71. {
  72. struct Screen *my_screen;
  73. ULONG  screen_modeID;
  74. UBYTE *pub_scr_font_name;
  75. UBYTE *font_name;
  76. ULONG  font_name_size;
  77. struct TextAttr pub_screen_font;
  78. struct TextFont *opened_font;
  79.  
  80. struct Screen   *pub_screen = NULL;
  81. struct DrawInfo *screen_drawinfo = NULL;
  82.  
  83. /* name is a (UBYTE *) pointer to the name of the public screen to clone */
  84. pub_screen = LockPubScreen(pub_screen_name);
  85. if (pub_screen != NULL)
  86.     {
  87.     /* Get the DrawInfo structure from the locked screen
  88.     ** This returns pen, depth and font info.
  89.     */
  90.     screen_drawinfo = GetScreenDrawInfo(pub_screen);
  91.     if (screen_drawinfo != NULL)
  92.         {
  93.         screen_modeID = GetVPModeID(&(pub_screen->ViewPort));
  94.         if( screen_modeID != INVALID_ID )
  95.             {
  96.             /* Get a copy of the font
  97.             ** The name of the font must be copied as the public screen may
  98.             ** go away at any time after we unlock it.
  99.             ** Allocate enough memory to copy the font name, create a
  100.             ** TextAttr that matches the font, and open the font.
  101.             */
  102.             pub_scr_font_name = screen_drawinfo->dri_Font->tf_Message.mn_Node.ln_Name;
  103.             font_name_size = 1 + strlen(pub_scr_font_name);
  104.             font_name = AllocMem(font_name_size, MEMF_CLEAR);
  105.             if (font_name != NULL)
  106.                 {
  107.                 strcpy(font_name, pub_scr_font_name);
  108.                 pub_screen_font.ta_Name  = font_name;
  109.                 pub_screen_font.ta_YSize = screen_drawinfo->dri_Font->tf_YSize;
  110.                 pub_screen_font.ta_Style = screen_drawinfo->dri_Font->tf_Style;
  111.                 pub_screen_font.ta_Flags = screen_drawinfo->dri_Font->tf_Flags;
  112.  
  113.                 opened_font = OpenFont(&pub_screen_font);
  114.                 if (opened_font != NULL)
  115.                     {
  116.                     /* screen_modeID may now be used in a call to
  117.                     ** OpenScreenTagList() with the tag SA_DisplayID.
  118.                     */
  119.                     my_screen = OpenScreenTags(NULL,
  120.                         SA_Width,      pub_screen->Width,
  121.                         SA_Height,     pub_screen->Height,
  122.                         SA_Depth,      screen_drawinfo->dri_Depth,
  123.                         SA_Overscan,   OSCAN_TEXT,
  124.                         SA_AutoScroll, TRUE,
  125.                         SA_Pens,       (ULONG)(screen_drawinfo->dri_Pens),
  126.                         SA_Font,       (ULONG)&pub_screen_font,
  127.                         SA_DisplayID,  screen_modeID,
  128.                         SA_Title,      "Cloned Screen",
  129.                         TAG_END);
  130.                     if (my_screen != NULL)
  131.                         {
  132.                         /* Free the drawinfo and public screen as we don't
  133.                         ** need them any more.  We now have our own screen.
  134.                         */
  135.                         FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  136.                         screen_drawinfo = NULL;
  137.                         UnlockPubScreen(pub_screen_name,pub_screen);
  138.                         pub_screen = NULL;
  139.  
  140.                         Delay(300);   /* should be rest_of_program */
  141.  
  142.                         CloseScreen(my_screen);
  143.                         }
  144.                     CloseFont(opened_font);
  145.                     }
  146.                 FreeMem(font_name, font_name_size);
  147.                 }
  148.             }
  149.         }
  150.     }
  151.  
  152. /* These are freed in the main loop if OpenScreenTagList() does
  153. ** not fail.  If something goes wrong, free them here.
  154. */
  155. if (screen_drawinfo != NULL )
  156.     FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  157. if (pub_screen != NULL )
  158.     UnlockPubScreen(pub_screen_name,pub_screen);
  159. }
  160.