ShowPressTool.mesa
Last edited by Shore; December 4, 1982 12:15 am
Last edited by Wyatt; June 24, 1983 2:18 pm
Last Edited by: Donahue, May 27, 1983 1:55 pm
Last Edited by: Beach, June 22, 1983 6:16 pm
DIRECTORY
Buttons,
Commander USING [CommandProc, Register],
Containers,
Graphics USING [Scale, Translate],
GraphicsBasic,
IO,
MessageWindow USING [Append, Blink],
Process USING [Detach],
Real,
Rope,
Rules,
ShowPress USING [Close, DrawPressPage, Handle, Open, ShowPressError],
Sliders,
ViewerClasses USING [DestroyProc, PaintProc, ScrollProc, Viewer, ViewerRec, ViewerClass, ViewerClassRec],
ViewerOps USING [CreateViewer, PaintViewer, RegisterViewerClass], -- DestroyViewer
ViewerSpecs,
ViewerTools;
ShowPressTool: MONITOR
IMPORTS Buttons, Commander, Containers, Graphics, IO, MessageWindow, Process, Real, Rope, Rules, ShowPress, Sliders, ViewerOps, ViewerTools
EXPORTS ShowPress
= BEGIN
pressViewerClass: ViewerClasses.ViewerClass ← NEW[ViewerClasses.ViewerClassRec];
ShowData: TYPE = REF ShowDataRec;
ShowDataRec: TYPE = RECORD [
show: ShowPress.Handle,
pressContainer: Containers.Container ← NIL,
pressViewer: ViewerClasses.Viewer ← NIL,
pageNumberViewer: ViewerClasses.Viewer ← NIL,
pageNumberSlider: Sliders.Slider ← NIL,
pageNumber: INT ← 1,
top, height: REAL ];
pointsPerMica: REAL = 72.0/2540.0;
micasPerPoint: REAL = 2540.0/72.0;
pressPageSize: REAL = 11.0*72.0; -- points
viewerOverheadSize: INT = (ViewerSpecs.captionHeight + ViewerSpecs.menuHeight + ViewerSpecs.menuBarHeight + ViewerSpecs.windowBorderSize*2);
visibleGrey: GraphicsBasic.Color = [stipple, 0, 122645B/256, 122645B MOD 256];
invisibleGrey: GraphicsBasic.Color = [stipple, 0, 100040B/256, 100040B MOD 256];
CreateShowViewer: PUBLIC PROC[fileName: Rope.ROPE] RETURNS[pressViewer: ViewerClasses.Viewer] = {
my: ShowData;
curIndent: INTEGER ← 0;
topLine: INTEGER ← 0;
button: Buttons.Button;
rule: Rules.Rule;
file: ShowPress.Handle;
file ← ShowPress.Open[fileName !
ShowPress.ShowPressError => {
SELECT code FROM
CantReadFile => CONTINUE;
CantFindFonts => {
MessageWindow.Append[message: Rope.Concat["Can't Find Fonts for ", fileName], clearFirst: TRUE];
MessageWindow.Blink[];
GOTO Quit; };
ENDCASE => REJECT;
} ];
IF file = NIL THEN {
fileName ← Rope.Concat[fileName, ".press"];
file ← ShowPress.Open[fileName !
ShowPress.ShowPressError => {
MessageWindow.Append[message: Rope.Concat["Can't open Press viewer on ", fileName], clearFirst: TRUE];
MessageWindow.Blink[];
GOTO Quit; }
];
};
my ← NEW[ ShowDataRec ← [show: file, pageNumber: 1, top: pressPageSize, height: 0.0]];
my.pressContainer ← Containers.Create[
info: [
name: fileName,
iconic: FALSE,
data: my,
scrollable: FALSE],
paint: TRUE ];
button ← Buttons.Create[
info: [
name: "FirstPage",
wx: curIndent,
wy: topLine,
border: FALSE,
parent: my.pressContainer],
proc: FirstPage,
clientData: my,
documentation: "Left-click for the first page of the Press file",
paint: TRUE];
curIndent ← button.wx + button.ww;
button ← Buttons.Create[
info: [
name: "TurnPage",
wx: curIndent,
wy: topLine,
border: FALSE,
parent: my.pressContainer],
proc: TurnPage,
clientData: my,
documentation: "Left-click for next page; Right-click for previous page",
paint: TRUE];
curIndent ← button.wx + button.ww;
button ← Buttons.Create[
info: [
name: "LastPage",
wx: curIndent,
wy: topLine,
border: FALSE,
parent: my.pressContainer],
proc: LastPage,
clientData: my,
documentation: "Left-click for last page in Press file",
paint: TRUE];
curIndent ← button.wx + button.ww;
button ← Buttons.Create[
info: [
name: "Page",
wx: curIndent,
wy: topLine,
border: FALSE,
parent: my.pressContainer],
proc: PageNumber,
clientData: my,
documentation: "Left-click for selected page number",
paint: TRUE];
curIndent ← button.wx + button.ww;
my.pageNumberViewer ← ViewerTools.MakeNewTextViewer[
info: [
wx: curIndent,
wy: topLine+ViewerSpecs.windowBorderSize,
ww: 40,
wh: ViewerSpecs.scrollBarW+2*ViewerSpecs.windowBorderSize,
parent: my.pressContainer,
border: FALSE,
scrollable: FALSE],
paint: TRUE];
curIndent ← my.pageNumberViewer.wx + my.pageNumberViewer.ww;
my.pageNumberSlider ← Sliders.Create[
info: [
wx: curIndent,
wy: topLine,
ww: my.pressContainer.ww-curIndent,
wh: ViewerSpecs.scrollBarW+2*ViewerSpecs.windowBorderSize,
border: FALSE,
parent: my.pressContainer,
scrollable: FALSE],
filterProc: NormalizePageNumber,
sliderProc: PageNumberSlider,
orientation: horizontal,
foreground: visibleGrey,
background: invisibleGrey,
clientData: my,
paint: TRUE];
Containers.ChildXBound[my.pressContainer, my.pageNumberSlider];
rule ← Rules.Create[
info: [
parent: my.pressContainer,
wx: 0,
wy: topLine+ViewerSpecs.captionHeight+4*ViewerSpecs.windowBorderSize,
wh: ViewerSpecs.menuBarHeight]];
Containers.ChildXBound[my.pressContainer, rule];
my.pressViewer ← pressViewer ← ViewerOps.CreateViewer[
flavor: $Press,
info: [
name: fileName,
parent: my.pressContainer,
wx: 0,
wy: topLine+ViewerSpecs.captionHeight+5*ViewerSpecs.windowBorderSize,
border: FALSE,
scrollable: TRUE,
iconic: FALSE,
data: my],
paint: TRUE ];
Containers.ChildXBound[my.pressContainer, my.pressViewer];
Containers.ChildYBound[my.pressContainer, my.pressViewer];
DeltaPage[my, 1];
ViewerOps.PaintViewer[my.pressContainer, all];
EXITS
Quit => RETURN;
};
NormalizePageNumber: Sliders.FilterProc = TRUSTED {
my: ShowData ← NARROW[clientData];
RETURN [Real.FDiv[Real.RoundI[value*(my.show.lastPart-1)], (my.show.lastPart-1)]]
};
FirstPage: Buttons.ButtonProc = TRUSTED {
my: ShowData ← NARROW[clientData];
DeltaPage[my, 1];
Process.Detach[FORK ScrollIt[my.pressViewer, my, pressPageSize]];
};
TurnPage: Buttons.ButtonProc = TRUSTED {
my: ShowData ← NARROW[clientData];
where: INTIF mouseButton = red THEN +1 ELSE -1;
DeltaPage[my, MIN[MAX[my.pageNumber+where, 1], (my.show.lastPart-1)]];
Process.Detach[FORK ScrollIt[my.pressViewer, my, pressPageSize]];
};
LastPage: Buttons.ButtonProc = TRUSTED {
my: ShowData ← NARROW[clientData];
DeltaPage[my, (my.show.lastPart-1)];
Process.Detach[FORK ScrollIt[my.pressViewer, my, pressPageSize]];
};
PageNumber: Buttons.ButtonProc = TRUSTED {
my: ShowData ← NARROW[clientData];
stream: IO.STREAMIO.RIS[ViewerTools.GetContents[my.pageNumberViewer]];
where: INT ← stream.GetInt[];
DeltaPage[my, MIN[MAX[where, 1], (my.show.lastPart-1)]];
Process.Detach[FORK ScrollIt[my.pressViewer, my, pressPageSize]];
};
PageNumberSlider: Sliders.SliderProc = TRUSTED {
my: ShowData ← NARROW[clientData];
SELECT reason FROM
abort => {
ViewerTools.SetContents[my.pageNumberViewer, IO.PutFR["%-g", IO.real[my.pageNumber]]];
};
move => {
ViewerTools.SetContents[my.pageNumberViewer, IO.PutFR["%-g", IO.real[Real.RoundI[(my.show.lastPart-1)*value]]]];
};
set => {
DeltaPage[my, MIN[MAX[Real.RoundI[(my.show.lastPart-1)*value], 1], (my.show.lastPart-1)]];
Process.Detach[FORK ScrollIt[my.pressViewer, my, pressPageSize]];
};
ENDCASE;
};
PressPaint: ENTRY ViewerClasses.PaintProc = TRUSTED {
my: ShowData ← NARROW[self.data];
my.height ← self.ch;
IF my.height > my.top THEN my.top ← my.height;
Graphics.Translate[context, 0.0, my.height-my.top];
Graphics.Scale[context, pointsPerMica, pointsPerMica]; -- establish Press coord system
ShowPress.DrawPressPage[context: context, show: my.show, pageNumber: my.pageNumber
! ShowPress.ShowPressError => {
my: ShowData ← NARROW[self.data];
SELECT code FROM
NoSuchPage => {my.pageNumber ← my.pageNumber-1; RETRY;}
ENDCASE => REJECT
}
];
}; -- PressPaint
PressScroll: ViewerClasses.ScrollProc = TRUSTED {
my: ShowData ← NARROW[self.data];
SELECT op FROM
query => RETURN [
top: Real.Fix[(1.0-my.top/pressPageSize)*100.0],
bottom: Real.Fix[(1.0-(my.top-my.height)/pressPageSize)*100.0]];
up => IF my.top > my.height THEN {
Process.Detach[FORK ScrollIt[self, my, MAX[my.top-amount, my.height]]];
};
down => IF my.top < pressPageSize THEN {
Process.Detach[FORK ScrollIt[self, my, MIN[my.top+amount, pressPageSize]]];
};
thumb => {
Process.Detach[FORK ScrollIt[self, my, MAX[MIN[(100-amount)*pressPageSize/100, pressPageSize], my.height]]];
};
ENDCASE => ERROR;
}; -- PressScroll
PressDestroy: ViewerClasses.DestroyProc = TRUSTED {
my: ShowData ← NARROW[self.data];
my.show.Close[];
}; -- PressDestroy
ScrollIt: PROCEDURE [self: ViewerClasses.Viewer, data: ShowData, newvalue: REAL] = {
DeltaTop[data, newvalue];
ViewerOps.PaintViewer[viewer: self, hint: client];
};
DeltaPage: ENTRY PROCEDURE [data: ShowData, newvalue: INT] = {
data.pageNumber ← newvalue;
ViewerTools.SetContents[data.pageNumberViewer, IO.PutFR["%-g", IO.int[newvalue]]];
Sliders.SetContents[data.pageNumberSlider, Real.FDiv[newvalue, (data.show.lastPart-1)]];
};
DeltaTop: ENTRY PROCEDURE [data: ShowData, newvalue: REAL] = {
data.top ← newvalue;
};
MakeShowPress: Commander.CommandProc = TRUSTED {
fileName: Rope.ROPEIO.GetToken[IO.RIS[cmd.commandLine], IO.WhiteSpace];
[] ← CreateShowViewer[fileName];
}; -- MakeShowPress
pressViewerClass.paint ← PressPaint;
pressViewerClass.destroy ← PressDestroy;
pressViewerClass.scroll ← PressScroll;
ViewerOps.RegisterViewerClass[$Press, pressViewerClass];
Commander.Register[
key: "ShowPress",
proc: MakeShowPress,
doc: "Show a Press file through CedarGraphics" ];
END. -- ShowPressTool
Change Log
Created by Shore; September 13, 1982 7:17 pm
Changed by Shore; October 15, 1982 1:38 pm
converted to Cedar 3.4 (Menus)
Changed by Shore; December 4, 1982 12:15 am
converted to Cedar.Style
Changed by Wyatt; March 7, 1983 4:33 pm
converted to Cedar 4.0
Edited on May 27, 1983 6:15 pm, by Beach
Added thumbing to PressScroll.
Edited on June 24, 1983 2:17 pm, by Wyatt
UserExec -> Commander.