home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / system / kepler7.mod (.txt) < prev    next >
Oberon Text  |  1977-12-31  |  7KB  |  205 lines

  1. Syntax10.Scn.Fnt
  2. (* Semesterarbeit Wintersemester 91/92 von Samuel Urech
  3.     Erweiterung des Graphikeditors Kepler um Texte
  4.     Programmiersprache: Oberon-2 auf Ceres-1
  5.     Autor: Samuel Urech, Tannenrauchstrasse 35/107, 8038 Z
  6.                 Tel. 01 481 92 92    Stud.Nr. 87-906-434
  7.     Datum: 20.11.91            Stand: 12.2.92
  8.     adapted to V4: J. Templ, 27.09.93
  9. MODULE Kepler7;
  10.     IMPORT Display, Oberon, Fonts, Files, TextFrames, Texts, MenuViewers,
  11.     KeplerPorts, KeplerGraphs, KeplerFrames, Kepler2;
  12.     CONST
  13.         MM = 1;
  14.         CR = 0DX;
  15.         menu = "System.Close  System.Copy  System.Grow  Edit.Search  Edit.Replace  Kepler7.Update ";
  16.     TYPE
  17.         Text* = POINTER TO TextDesc;
  18.         TextDesc* = RECORD
  19.             (KeplerFrames.ButtonDesc)
  20.             text* : Texts.Text
  21.         END;
  22.         Frame* = POINTER TO FrameDesc;
  23.         FrameDesc* = RECORD
  24.             (TextFrames.FrameDesc)
  25.             keplerText* : Text;
  26.             graph* : KeplerGraphs.Graph
  27.         END;
  28. (* ----------------------------------------  Hilfsprozeduren  ------------------------------------- *)
  29.     PROCEDURE CopyText( srcText : Texts.Text; VAR dstText : Texts.Text );
  30.     (* srcText wird auf dstText kopiert, der alte Inhalt von dstText wird gel
  31. scht. *)
  32.         VAR b : Texts.Buffer;
  33.     BEGIN
  34.         NEW( dstText );
  35.         Texts.Open( dstText, "" );
  36.         dstText.notify := srcText.notify;
  37.         NEW( b );
  38.         Texts.OpenBuf( b );
  39.         Texts.Save( srcText, 0, srcText.len, b );
  40.         Texts.Append( dstText, b )
  41.     END CopyText;
  42. (* -----------------------------------  Text-Methoden  ------------------------------------- *)
  43.     PROCEDURE (t : Text) HandleMouse* (f: KeplerFrames.Frame; x, y: INTEGER; keys: SET);
  44.         VAR X, Y: INTEGER;
  45.             keySum: SET;
  46.             newText: Texts.Text;
  47.             tf: Frame;
  48.             v: MenuViewers.Viewer;
  49.     BEGIN
  50.         IF keys = {MM} THEN
  51.             keySum := keys;
  52.             REPEAT
  53.                 f.TrackMouse(x, y, keys);
  54.                 KeplerFrames.GetMouse(f, x, y, keys);
  55.                 keySum := keySum + keys;
  56.             UNTIL keys = {};
  57.             IF keySum = {MM} THEN
  58.                 CopyText(t.text, newText);
  59.                 NEW(tf);
  60.                 TextFrames.Open( tf, newText, 0);
  61.                 tf.keplerText := t;
  62.                 tf.graph := f.G;
  63.                 Oberon.AllocateUserViewer(Oberon.Mouse.X, X, Y);
  64.                 v := MenuViewers.New(TextFrames.NewMenu("KeplerText", menu), tf, TextFrames.menuH, X, Y);
  65.             END
  66.         END
  67.     END HandleMouse;
  68.     PROCEDURE ( t : Text ) Draw*( f : KeplerPorts.Port );
  69.         VAR r : Texts.Reader;
  70.             ch : CHAR;
  71.             line : ARRAY 256 OF CHAR;
  72.             i, xBase, xOff, y, lineHeight, oldNegOff, negOff : INTEGER;
  73.             lineBeg : LONGINT;
  74.             curFont : Fonts.Font;
  75.             curCol, curVoff : SHORTINT;
  76.     BEGIN
  77.         lineBeg := 0;
  78.         Texts.OpenReader( r, t.text, lineBeg );
  79.         Texts.Read( r, ch );
  80.         xBase := t.p[ 0 ].x;
  81.         xOff := 0;
  82.         y := t.p[ 0 ].y;
  83.         oldNegOff := 0;
  84.         negOff := 0;
  85.         WHILE ~ r.eot DO
  86.             lineHeight := 4 * r.fnt.maxY + r.voff;
  87.             WHILE ( ~ r.eot ) & ( ch # CR ) DO
  88.                 IF 4 * r.fnt.maxY + r.voff > lineHeight THEN lineHeight := 4 * r.fnt.maxY + r.voff; END;
  89.                 IF r.voff + 4 * r.fnt.minY < negOff THEN negOff := r.voff + 4 * r.fnt.minY; END;
  90.                 Texts.Read( r, ch );
  91.             END;
  92.             xOff := 0;
  93.             Texts.OpenReader( r, t.text, lineBeg );
  94.             Texts.Read( r, ch );
  95.             IF ( ch = CR ) & ( f IS KeplerPorts.BalloonPort ) THEN
  96.                 line[ 0 ] := "l";
  97.                 line[ 1 ] := 0X;
  98.                 f.DrawString( xBase, y - lineHeight + oldNegOff, line, r.fnt, r.col, Display.replace );
  99.             END;
  100.             WHILE ( ~ r.eot ) & ( ch # CR ) DO
  101.                 i := 0;
  102.                 curFont := r.fnt;
  103.                 curCol := r.col;
  104.                 curVoff := r.voff;
  105.                 WHILE ( ~ r.eot ) & ( ch # CR ) & ( curFont = r.fnt ) & ( curCol = r.col ) & ( curVoff = r.voff ) & ( i < 255 ) DO
  106.                     line[ i ] := ch;
  107.                     INC( i );
  108.                     Texts.Read( r, ch );
  109.                 END;
  110.                 line[ i ] := 0X;
  111.                 f.DrawString( xBase + xOff, y + curVoff - lineHeight + oldNegOff, line, curFont, curCol, Display.replace );
  112.                 INC( xOff, KeplerPorts.StringWidth( line, curFont ) );
  113.             END;
  114.             DEC( y, lineHeight - oldNegOff );
  115.             oldNegOff := negOff;
  116.             negOff := 0;
  117.             lineBeg := Texts.Pos( r );
  118.             Texts.Read( r, ch );
  119.         END
  120.     END Draw;
  121.     PROCEDURE ( t : Text ) Read*( VAR r : Files.Rider );
  122.     BEGIN
  123.         NEW( t.text );
  124.         Texts.Load( r, t.text);
  125.         t.text.notify := TextFrames.NotifyDisplay;
  126.         t.Read^( r );
  127.     END Read;
  128.     PROCEDURE ( t : Text ) Write*( VAR r : Files.Rider );
  129.     BEGIN
  130.         Texts.Store( r, t.text);
  131.         t.Write^( r );
  132.     END Write;
  133. (* -------------------------------------------  Text-Commands  ---------------------------------- *)
  134.     PROCEDURE Update*;
  135.     (* Schreibt den Text aus dem Viewer, von dem aus der Befehl aufgerufen wurde, an seine Ursprungsposition zur
  136. ck. *)
  137.         VAR f : Frame;
  138.             balloon1, balloon2 : KeplerPorts.BalloonPort;
  139.             textCorner : Kepler2.Offset;
  140.             dx, dy : INTEGER;
  141.             T: Texts.Text; R: Texts.Reader; ch: CHAR;
  142.     BEGIN
  143.         IF Oberon.Par.vwr.dsc.next IS Frame THEN
  144.             f := Oberon.Par.vwr.dsc.next( Frame );
  145.             NEW( balloon1 );
  146.             KeplerPorts.InitBalloon( balloon1 );
  147.             f.keplerText.Draw( balloon1 );
  148.             CopyText( f.text, f.keplerText.text );
  149.             NEW( balloon2 );
  150.             KeplerPorts.InitBalloon( balloon2 );
  151.             f.keplerText.Draw( balloon2 );
  152.             textCorner := f.keplerText.p[ 1 ]( Kepler2.Offset );
  153.             IF ( balloon2.W <= 0 ) OR ( balloon2.H <= 0 ) THEN 
  154.                 dx := 100 - textCorner.dx;
  155.                 dy := (-100) - textCorner.dy;
  156.                 textCorner.dx := 100;
  157.                 textCorner.dy := -100;
  158.             ELSE
  159.                 dx := balloon2.W - textCorner.dx;
  160.                 dy := -balloon2.H - textCorner.dy;
  161.                 textCorner.dx := balloon2.W;
  162.                 textCorner.dy := -balloon2.H;
  163.             END; (* IF *)
  164.             f.graph.Move( textCorner, dx, dy );
  165.             textCorner.Calc;
  166.             f.keplerText.Draw( balloon1 );
  167.             textCorner.Draw( balloon1 );
  168.             f.graph.notify( KeplerGraphs.restore, f.graph, f.keplerText, balloon1 );
  169.             T := Oberon.Par.vwr.dsc(TextFrames.Frame).text;
  170.             Texts.OpenReader(R, T, T.len - 1); Texts.Read(R, ch);
  171.             IF ch = "!" THEN Texts.Delete(T, T.len - 1, T.len) END
  172.         END
  173.     END Update;
  174.     PROCEDURE NewText*;
  175.         VAR t: Text;
  176.             corner: Kepler2.Offset;
  177.             sel: Texts.Text;
  178.             beg, end, time: LONGINT;
  179.             b: Texts.Buffer;
  180.             balloon: KeplerPorts.BalloonPort;
  181.             W: Texts.Writer;
  182.     BEGIN
  183.         IF KeplerFrames.nofpts >= 1 THEN
  184.             NEW(t);
  185.             NEW(corner);
  186.             NEW(corner.c);
  187.             t.text := TextFrames.Text("");
  188.             t.nofpts := 2; t.cmd := ""; t.par := "";
  189.             KeplerFrames.ConsumePoint(t.p[0]);
  190.             corner.c.nofpts := 1;
  191.             corner.c.p[0] := t.p[0]; INC(t.p[0].refcnt );
  192.             t.p[1] := corner; corner.refcnt := 1;
  193.             Oberon.GetSelection(sel, beg, end, time);
  194.             IF (time < 0) OR (beg = end) THEN Texts.OpenWriter(W); Texts.WriteString(W, "no selection"); Texts.Append(t.text, W.buf)
  195.             ELSE NEW(b); Texts.OpenBuf(b); Texts.Save(sel, beg, end, b); Texts.Append(t.text, b);
  196.             END ;
  197.             NEW(balloon); KeplerPorts.InitBalloon(balloon); t.Draw(balloon);
  198.             corner.dx := balloon.W; corner.dy := -balloon.H;
  199.             corner.Calc;
  200.             KeplerFrames.Focus.Append(corner);
  201.             KeplerFrames.Focus.Append(t)
  202.         END
  203.     END NewText;
  204. END Kepler7.
  205.