ColorDisplayImpl.mesa
Created from old ColorDisplay by Mik Lamming and Ken Pier
Last Edited by: Nickell, June 7, 1984 1:12:42 pm PDT
Last Edited by: Beach, August 17, 1984 5:24:14 pm PDT
Last Edited by: Pier, November 19, 1984 3:10:48 pm PST
DIRECTORY
ColorDisplay,
InterminalExtraExtra USING [ColorDisplayOnLeft, SwitchSideOfColorDisplay],
List USING [Car, Cdr, Cons],
MonitorToolDefsExtras USING [Start640Monitor, Start1024Monitor],
Rope USING [Equal, ROPE],
Terminal USING [ColorMode, Current, GetColorMode],
UserProfile USING [Number, Token],
ViewerClasses USING [Viewer],
ViewerOps USING [ChangeColumn, CloseViewer, ComputeColumn, EnumerateViewers, EnumProc, OpenIcon],
WindowManager USING [colorDisplayOn, ScreenPos, StartColorViewers, StopColorViewers];
ColorDisplayImpl: CEDAR PROGRAM
IMPORTS InterminalExtraExtra, List, MonitorToolDefsExtras, Rope, Terminal, UserProfile, ViewerOps, WindowManager
EXPORTS ColorDisplay
~ {
bppLast and sideLast are examined only when the color display is off. This lets the ColorDisplay package know where to default them to when the color display is turned on again. NOTE: Every call to the ColorDisplay package will cause these values to be updated with the actual state of the machine, if it is on.
bppLast: PUBLIC CARDINAL ← 8;
onLeftLast: PUBLIC BOOLEANTRUE;
monitorTypeLast: PUBLIC Rope.ROPE ← "640x480";
DefaultBpp, Bpp: PUBLIC PROC RETURNS [bpp: CARDINAL] ~ { --Has side effect of remembering bpp
IF WindowManager.colorDisplayOn THEN {
OPEN Terminal;
colorMode: ColorMode ← GetColorMode[Current[]];
bpp ← (IF colorMode.full THEN 24 ELSE colorMode.bitsPerPixelChannelA);
}
ELSE bpp ← bppLast;
bppLast ← bpp;      --Remember the setting of the screen
};
DefaultOnLeft, OnLeft: PUBLIC PROC RETURNS [onLeft: BOOLEAN] ~ {
onLeft ← IF WindowManager.colorDisplayOn THEN InterminalExtraExtra.ColorDisplayOnLeft[] ELSE onLeftLast;
onLeftLast ← onLeft;
};
DefaultOn: PUBLIC PROC RETURNS [BOOLEAN] ~ {
RETURN[WindowManager.colorDisplayOn];
};
DefaultMonitorType: PUBLIC PROC RETURNS [Rope.ROPE] ~ {
RETURN[monitorTypeLast];
};
SetColorDisplayStatus: PUBLIC PROC
[on: BOOLEAN ← DefaultOn[],
onLeft: BOOLEAN ← DefaultOnLeft[],
bpp: CARDINAL ← DefaultBpp[],
monitorType: Rope.ROPE ← DefaultMonitorType[]]
~ {
SELECT TRUE FROM
Check for nothing changed
(on=WindowManager.colorDisplayOn AND bpp=Bpp[] AND monitorType=monitorTypeLast AND onLeft=OnLeft[]) => RETURN;
Check for just switching sides.
(on=WindowManager.colorDisplayOn AND bpp=Bpp[] AND monitorType=monitorTypeLast AND on) => InterminalExtraExtra.SwitchSideOfColorDisplay[];
Otherwise, we need to check the whole ball of wax
ENDCASE => TRUSTED {
colorViewerList, colorIconList: LIST OF REF ANYNIL; --Really only viewers, tho
ListColorViewers: PROC ~ TRUSTED {   --Constructs a list of the color viewers
EnumColorViewers: ViewerOps.EnumProc ~ TRUSTED {
IF v.column=color THEN
IF v.iconic THEN colorIconList ← List.Cons[v,colorIconList]
ELSE colorViewerList ← List.Cons[v,colorViewerList];
};
ViewerOps.EnumerateViewers[enum: EnumColorViewers];
};
ReopenColorViewers: PROC ~ TRUSTED {  --Reopen the listed color viewers
reopenList: LIST OF REF ANY ← colorViewerList;
Reopen the viewers that were OPEN on the color display
WHILE reopenList#NIL DO
v: ViewerClasses.Viewer ← NARROW[List.Car[reopenList]];
reopenList ← NARROW[List.Cdr[reopenList]];
ViewerOps.CloseViewer[v];
ViewerOps.ChangeColumn[v, color];
ViewerOps.OpenIcon[icon: v, paint: FALSE];
ENDLOOP;
ViewerOps.ComputeColumn[color];
Reset the icons that WOULD have been opened on the color display back there
reopenList ← colorIconList;
WHILE reopenList#NIL DO
v: ViewerClasses.Viewer ← NARROW[List.Car[reopenList]];
reopenList ← NARROW[List.Cdr[reopenList]];
ViewerOps.ChangeColumn[v, color];
ENDLOOP;
};
side: WindowManager.ScreenPos ← IF onLeft THEN left ELSE right;
onLeftLast ← onLeft;
bppLast ← bpp;
monitorTypeLast ← monitorType;  --Back up the given parameters
ListColorViewers[];
WindowManager.StopColorViewers[];
IF on THEN {
SELECT TRUE FROM
Rope.Equal[s1: monitorType, s2: "640x480", case: FALSE] => MonitorToolDefsExtras.Start640Monitor[bitsPerPixel: bpp, pos: side];
Rope.Equal[s1: monitorType, s2: "1024x768", case: FALSE] => MonitorToolDefsExtras.Start1024Monitor[bitsPerPixel: bpp, pos: side];
ENDCASE => WindowManager.StartColorViewers[screenPos: side, bitsPerPixel: bpp];
ReopenColorViewers[];
};
};
};
GetColorDisplayStatus: PUBLIC PROC RETURNS [on, onLeft: BOOLEAN, bpp: CARDINAL, monitorType: Rope.ROPE] ~ {
on ← WindowManager.colorDisplayOn;
onLeft ← OnLeft[];
bpp ← Bpp[];
monitorType ← monitorTypeLast;
};
GetColorDisplayProfile: PUBLIC PROC RETURNS [on, onLeft: BOOLEAN, bpp: CARDINAL, monitorType: Rope.ROPE] ~ {
RightOrLeft: PROC RETURNS[rl: Rope.ROPE] ~ INLINE {
rl ← IF onLeftLast THEN "left" ELSE "right"};
tBpp: INTEGER;   --Temporary bits per pixel
on ← WindowManager.colorDisplayOn;
SELECT tBpp ← UserProfile.Number["ColorDisplay.BitsPerPoint", Bpp[]] FROM
1,2,4,8,24 => bpp ← tBpp;
ENDCASE => bpp ← Bpp[];
onLeft ← Rope.Equal[UserProfile.Token["ColorDisplay.Side", RightOrLeft[]], "left", FALSE];
monitorType ← UserProfile.Token["ColorDisplay.Type", monitorTypeLast];
};
Init: PROC[] RETURNS[] ~ {
Read the user profile to establish the initial back settings...
[,onLeftLast, bppLast, monitorTypeLast] ← GetColorDisplayProfile[];
};
Init[];
}.