(* Copyright (C) 1992, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* *) (* Last modified on Fri Jan 8 14:09:59 PST 1993 by mhb *) (* modified on Tue Jun 16 23:42:53 PDT 1992 by muller *) MODULE gallery EXPORTS Main; IMPORT Axis, FileStream, HVSplit, Image, List, M3Config, PackSplit, PaintOp, ParseParams, Pixmap, PixmapVBT, Rd, Scan, Split, Text, TextList, TextVBT, Thread, Trestle, TrestleComm, VBT, UnixUtils; <* FATAL Thread.Alerted, TrestleComm.Failure *> CONST PIXMAPDIR = "gallery-pixmaps"; PROCEDURE AddChild (image: VBT.T; name: Text.T) = BEGIN IF image = NIL THEN image := TextVBT.New("unreadable") END; Split.AddChild( pack, HVSplit.Cons(Axis.T.Ver, image, TextVBT.New(name))) END AddChild; PROCEDURE GetPixmap (rd: Rd.T): VBT.T = VAR image: Image.Raw; op : PaintOp.T; BEGIN TRY image := Image.FromRd(rd) EXCEPT Rd.Failure, Image.Error => RETURN NIL END; TYPECASE image OF | Image.RawBitmap => op := PaintOp.BgFg; | Image.RawPixmap => op := PaintOp.Copy; ELSE <* ASSERT FALSE *> END; RETURN PixmapVBT.New(Image.Unscaled(image), op) END GetPixmap; PROCEDURE Get (file: Text.T): VBT.T = <* FATAL UnixUtils.Error *> VAR rd: Rd.T; BEGIN IF NOT UnixUtils.ProbeFile(file, FALSE) OR UnixUtils.IsDirectory(file) THEN RETURN NIL END; TRY rd := FileStream.OpenRead(file); TRY RETURN GetPixmap(rd) FINALLY Rd.Close(rd) END EXCEPT Rd.Failure => END; RETURN NIL END Get; PROCEDURE ScanDir (dir: Text.T): TextList.T = BEGIN IF UnixUtils.IsDirectory(dir) THEN TRY RETURN UnixUtils.Directory(dir) EXCEPT UnixUtils.Error => END; END; RETURN NIL END ScanDir; VAR pack := PackSplit.New( Axis.T.Hor, 1.5, 1.5, Pixmap.Gray, PaintOp.BgFg); <* FATAL Scan.BadFormat *> BEGIN ParseParams.BeginParsing(); IF ParseParams.NextParameter = ParseParams.NumParameters THEN VAR lib := NARROW(List.First(M3Config.Lib()), TEXT); dirs := TextList.List1(lib & "/" & PIXMAPDIR); files : TextList.T; BEGIN WHILE dirs # NIL DO files := ScanDir(dirs.first); WHILE files # NIL DO AddChild(Get(dirs.first & "/" & files.first), files.first); files := files.tail END; dirs := dirs.tail END END ELSE WHILE ParseParams.NextParameter < ParseParams.NumParameters DO WITH parm = ParseParams.GetNext() DO AddChild(Get(parm), parm) END; END; END; ParseParams.EndParsing(); Trestle.Install(pack); Trestle.AwaitDelete(pack); END gallery.