home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 10 / Fresh_Fish_10_2352.bin / new / dev / obero / oberon-a / examples / libraries / intuition / clonescreen.mod next >
Text File  |  1995-07-02  |  4KB  |  121 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: CloneScreen.mod $
  4.   Description: A port of clonescreen.c
  5.  
  6.                Clone an existing public screen.
  7.  
  8.      Requires: AmigaOS 2.04+ (Kickstart 37+)
  9.  
  10.    Created by: fjc (Frank Copeland)
  11.     $Revision: 1.5 $
  12.       $Author: fjc $
  13.         $Date: 1995/01/25 23:52:19 $
  14.  
  15. *************************************************************************)
  16.  
  17. <* STANDARD- *>
  18.  
  19. MODULE CloneScreen;
  20.  
  21. IMPORT
  22.   SYS := SYSTEM,
  23.   E := Exec,
  24.   U := Utility,
  25.   D := Dos,
  26.   G := Graphics,
  27.   I := Intuition,
  28.   Str := Strings;
  29.  
  30. CONST
  31.   VersionTag = "$VER: CloneScreen 1.3 (24.1.95)\r\n";
  32.  
  33.   pubScreenName = "Workbench";
  34.  
  35. (*------------------------------------*)
  36. PROCEDURE cloneScreen (pubScreenName : ARRAY OF CHAR);
  37.  
  38.   VAR
  39.     myScreen : I.ScreenPtr;
  40.     screenModeID : LONGINT;
  41.     pubScrFontName : E.LSTRPTR;
  42.     fontName : E.LSTRPTR;
  43.     fontNameSize : LONGINT;
  44.     pubScreenFont : G.TextAttr;
  45.     openedFont : G.TextFontPtr;
  46.     pubScreen : I.ScreenPtr;
  47.     screenDrawInfo : I.DrawInfoPtr;
  48.  
  49. <*$CopyArrays-*>
  50. BEGIN (* cloneScreen *)
  51.   pubScreen := I.LockPubScreen (pubScreenName);
  52.   IF pubScreen # NIL THEN
  53.     (*
  54.     ** Get the DrawInfo structure from the locked screen
  55.     ** This returns pen, depth and font info.
  56.     *)
  57.     screenDrawInfo := I.GetScreenDrawInfo (pubScreen);
  58.     IF screenDrawInfo # NIL THEN
  59.       screenModeID := G.GetVPModeID (SYS.ADR (pubScreen.viewPort));
  60.       IF screenModeID # G.invalidID THEN
  61.         (*
  62.         ** Get a copy of the font
  63.         ** The name of the font must be copied as the public screen may
  64.         ** go away at any time after we unlock it.
  65.         ** Allocate enough memory to copy the font name, create a
  66.         ** TextAttr that matches the font, and open the font.
  67.         *)
  68.         pubScrFontName := screenDrawInfo.font.message.node.name;
  69.         fontNameSize := 1 + Str.Length (pubScrFontName^);
  70.         (* Program will halt if allocation fails *)
  71.         SYS.NEW (fontName, fontNameSize);
  72.         COPY (pubScrFontName^, fontName^);
  73.         pubScreenFont.name := fontName;
  74.         pubScreenFont.ySize := screenDrawInfo.font.ySize;
  75.         pubScreenFont.style := screenDrawInfo.font.style;
  76.         pubScreenFont.flags := screenDrawInfo.font.flags;
  77.         openedFont := G.OpenFont (pubScreenFont);
  78.         IF openedFont # NIL THEN
  79.           (*
  80.           ** screenModeID may now be used in a call to
  81.           ** OpenScreenTags () with the tag saDisplayID
  82.           *)
  83.           myScreen := I.OpenScreenTagsA ( NIL,
  84.               I.saWidth,      LONG (pubScreen.width),
  85.               I.saHeight,     LONG (pubScreen.height),
  86.               I.saDepth,      LONG (screenDrawInfo.depth),
  87.               I.saOverscan,   I.oScanText,
  88.               I.saAutoScroll, E.LTRUE,
  89.               I.saPens,       screenDrawInfo.pens,
  90.               I.saFont,       SYS.ADR (pubScreenFont),
  91.               I.saDisplayID,  screenModeID,
  92.               I.saTitle,      SYS.ADR ("Cloned screen"),
  93.               U.end );
  94.           IF myScreen # NIL THEN
  95.             (*
  96.             ** Free the drawinfo an public screen as we don't
  97.             ** need them any more. We now have our own screen.
  98.             *)
  99.             I.FreeScreenDrawInfo (pubScreen, screenDrawInfo);
  100.             screenDrawInfo := NIL;
  101.             I.UnlockPubScreen (pubScreenName, pubScreen);
  102.             pubScreen := NIL;
  103.  
  104.             D.Delay (300); (* should be rest_of_program *)
  105.  
  106.             I.OldCloseScreen (myScreen)
  107.           END;
  108.           G.CloseFont (openedFont)
  109.         END
  110.       END
  111.     END
  112.   END
  113. END cloneScreen;
  114.  
  115. BEGIN (* CloneScreen *)
  116.   ASSERT (I.base.libNode.version >= 37);
  117.   ASSERT (G.base.libNode.version >= 37);
  118.  
  119.   cloneScreen (pubScreenName)
  120. END CloneScreen.
  121.