home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Intuition / Screens / clonescreen.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  7KB  |  185 lines

  1. ;/* clonescreen.c - clone an existing public screen.
  2. lc -b1 -cfist -v -y -j73 clonescreen
  3. blink FROM LIB:c.o clonescreen.o TO clonescreen LIB LIB:lc.lib LIB:amiga.lib
  4. quit
  5. */
  6.  
  7.  
  8. /*
  9. Copyright (c) 1992 Commodore-Amiga, Inc.
  10.  
  11. This example is provided in electronic form by Commodore-Amiga, Inc. for
  12. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  13. published by Addison-Wesley (ISBN 0-201-56774-1).
  14.  
  15. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  16. information on the correct usage of the techniques and operating system
  17. functions presented in these examples.  The source and executable code
  18. of these examples may only be distributed in free electronic form, via
  19. bulletin board or as part of a fully non-commercial and freely
  20. redistributable diskette.  Both the source and executable code (including
  21. comments) must be included, without modification, in any copy.  This
  22. example may not be published in printed form or distributed with any
  23. commercial product.  However, the programming techniques and support
  24. routines set forth in these examples may be used in the development
  25. of original executable software products for Commodore Amiga computers.
  26.  
  27. All other rights reserved.
  28.  
  29. This example is provided "as-is" and is subject to change; no
  30. warranties are made.  All use is at your own risk. No liability or
  31. responsibility is assumed.
  32. */
  33.  
  34. #define INTUI_V36_NAMES_ONLY
  35.  
  36. #include <exec/types.h>
  37. #include <exec/memory.h>
  38. #include <intuition/intuition.h>
  39. #include <intuition/screens.h>
  40.  
  41. #include <clib/exec_protos.h>
  42. #include <clib/dos_protos.h>
  43. #include <clib/graphics_protos.h>
  44. #include <clib/intuition_protos.h>
  45.  
  46. #include <string.h>
  47.  
  48. #ifdef LATTICE
  49. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  50. int chkabort(void) { return(0); }  /* really */
  51. #endif
  52.  
  53. VOID cloneScreen( UBYTE * );
  54.  
  55. struct Library *IntuitionBase;
  56. struct GfxBase *GfxBase;
  57.  
  58. /*
  59. ** Open all libraries for the cloneScreen() subroutine.
  60. */
  61. VOID main(int argc, char **argv)
  62. {
  63. UBYTE *pub_screen_name = "Workbench";
  64.  
  65. IntuitionBase = OpenLibrary("intuition.library",0);
  66. if (IntuitionBase != NULL)
  67.     {
  68.     /* Require version 37 of Intuition. */
  69.     if (IntuitionBase->lib_Version >= 37)
  70.         {
  71.         /* Note the two methods of getting the library version
  72.         ** that you really want.
  73.         */
  74.         GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37);
  75.         if (GfxBase != NULL)
  76.             {
  77.             cloneScreen(pub_screen_name);
  78.  
  79.             CloseLibrary((struct Library *)GfxBase);
  80.             }
  81.         }
  82.     CloseLibrary(IntuitionBase);
  83.     }
  84. }
  85.  
  86. /* Clone a public screen whose name is passed to the routine.
  87. **    Width, Height, Depth, Pens, Font and DisplayID attributes are
  88. ** all copied from the screen.
  89. **    Overscan is assumed to be OSCAN_TEXT, as there is no easy way to
  90. ** find the overscan type of an existing screen.
  91. **    AutoScroll is turned on, as it does not hurt.  Screens that are
  92. ** smaller than the display clip will not scroll.
  93. */
  94.  
  95. VOID cloneScreen(UBYTE *pub_screen_name)
  96. {
  97. struct Screen *my_screen;
  98. ULONG  screen_modeID;
  99. UBYTE *pub_scr_font_name;
  100. UBYTE *font_name;
  101. ULONG  font_name_size;
  102. struct TextAttr pub_screen_font;
  103. struct TextFont *opened_font;
  104.  
  105. struct Screen   *pub_screen = NULL;
  106. struct DrawInfo *screen_drawinfo = NULL;
  107.  
  108. /* name is a (UBYTE *) pointer to the name of the public screen to clone */
  109. pub_screen = LockPubScreen(pub_screen_name);
  110. if (pub_screen != NULL)
  111.     {
  112.     /* Get the DrawInfo structure from the locked screen
  113.     ** This returns pen, depth and font info.
  114.     */
  115.     screen_drawinfo = GetScreenDrawInfo(pub_screen);
  116.     if (screen_drawinfo != NULL)
  117.         {
  118.         screen_modeID = GetVPModeID(&(pub_screen->ViewPort));
  119.         if( screen_modeID != INVALID_ID )
  120.             {
  121.             /* Get a copy of the font
  122.             ** The name of the font must be copied as the public screen may
  123.             ** go away at any time after we unlock it.
  124.             ** Allocate enough memory to copy the font name, create a
  125.             ** TextAttr that matches the font, and open the font.
  126.             */
  127.             pub_scr_font_name = screen_drawinfo->dri_Font->tf_Message.mn_Node.ln_Name;
  128.             font_name_size = 1 + strlen(pub_scr_font_name);
  129.             font_name = AllocMem(font_name_size, MEMF_CLEAR);
  130.             if (font_name != NULL)
  131.                 {
  132.                 strcpy(font_name, pub_scr_font_name);
  133.                 pub_screen_font.ta_Name  = font_name;
  134.                 pub_screen_font.ta_YSize = screen_drawinfo->dri_Font->tf_YSize;
  135.                 pub_screen_font.ta_Style = screen_drawinfo->dri_Font->tf_Style;
  136.                 pub_screen_font.ta_Flags = screen_drawinfo->dri_Font->tf_Flags;
  137.  
  138.                 opened_font = OpenFont(&pub_screen_font);
  139.                 if (opened_font != NULL)
  140.                     {
  141.                     /* screen_modeID may now be used in a call to
  142.                     ** OpenScreenTagList() with the tag SA_DisplayID.
  143.                     */
  144.                     my_screen = OpenScreenTags(NULL,
  145.                         SA_Width,      pub_screen->Width,
  146.                         SA_Height,     pub_screen->Height,
  147.                         SA_Depth,      screen_drawinfo->dri_Depth,
  148.                         SA_Overscan,   OSCAN_TEXT,
  149.                         SA_AutoScroll, TRUE,
  150.                         SA_Pens,       (ULONG)(screen_drawinfo->dri_Pens),
  151.                         SA_Font,       (ULONG)&pub_screen_font,
  152.                         SA_DisplayID,  screen_modeID,
  153.                         SA_Title,      "Cloned Screen",
  154.                         TAG_END);
  155.                     if (my_screen != NULL)
  156.                         {
  157.                         /* Free the drawinfo and public screen as we don't
  158.                         ** need them any more.  We now have our own screen.
  159.                         */
  160.                         FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  161.                         screen_drawinfo = NULL;
  162.                         UnlockPubScreen(pub_screen_name,pub_screen);
  163.                         pub_screen = NULL;
  164.  
  165.                         Delay(300);   /* should be rest_of_program */
  166.  
  167.                         CloseScreen(my_screen);
  168.                         }
  169.                     CloseFont(opened_font);
  170.                     }
  171.                 FreeMem(font_name, font_name_size);
  172.                 }
  173.             }
  174.         }
  175.     }
  176.  
  177. /* These are freed in the main loop if OpenScreenTagList() does
  178. ** not fail.  If something goes wrong, free them here.
  179. */
  180. if (screen_drawinfo != NULL )
  181.     FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  182. if (pub_screen != NULL )
  183.     UnlockPubScreen(pub_screen_name,pub_screen);
  184. }
  185.