NewClockImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Eric Nickell, December 8, 1986 8:57:35 am PST
Bloomenthal, December 8, 1986 11:21:22 pm PST
DIRECTORY
Atom, BasicTime, Buttons, Commander, CommandTool, Convert, IO, MessageWindow, Process, Rope, UserProfile, ViewerOps;
NewClockImpl: CEDAR PROGRAM
IMPORTS Atom, BasicTime, Buttons, CommandTool, Convert, IO, MessageWindow, Process, Rope, UserProfile, ViewerOps
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
CurrentTime:
PROC
RETURNS [time:
ROPE] ~ {
unpacked: BasicTime.Unpacked ~ BasicTime.Unpack[time: BasicTime.Now[]];
hour: CARDINAL ← unpacked.hour;
IF NOT military AND hour > 12 THEN hour ← hour-12;
IF hour = 0 THEN hour ← 12;
time ← IO.PutFR["%2g:%02g", IO.card[hour], IO.card[unpacked.minute]];
IF seconds THEN time ← IO.PutFR["%g:%02g", IO.rope[time], IO.card[unpacked.second]];
};
start: ROPE ~ "12:00";
seconds: BOOL ← FALSE;
military: BOOL ← FALSE;
style: ATOM ← $WhiteOnBlack;
StyleInit: UserProfile.ProfileChangedProc = {
style ← Atom.MakeAtom[UserProfile.Token["NewClock.ButtonStyle", "WhiteOnBlack"]];
seconds ← UserProfile.Boolean["NewClock.Seconds", FALSE];
military ← UserProfile.Boolean["NewClock.Military", FALSE];
};
UpdateButtonNow: Buttons.ButtonProc = {
SELECT mouseButton
FROM
red => Buttons.ReLabel[button: NARROW[parent], newName: CurrentTime[]];
yellow => {
clock: BOOL ← FALSE;
Proc: TYPE ~ ViewerOps.EnumProc;
p1: Proc ~ {IF Rope.Equal[v.name, "Clock"] THEN clock ← TRUE};
p2: Proc ~ {IF Rope.Equal[v.name, "Clock"] THEN ViewerOps.OpenIcon[v]};
ViewerOps.EnumerateViewers[p1];
IF
NOT clock
THEN [] ← CommandTool.DoCommand
["///Commands/Clock",
NEW[Commander.CommandObject ← [IO.RIS[NIL], IO.ROS[], IO.ROS[], NIL]]];
ViewerOps.EnumerateViewers[p2];
};
blue => MessageWindow.Append[
Convert.RopeFromTime[from: BasicTime.Now[], includeDayOfWeek: TRUE], TRUE];
ENDCASE;
};
UpdateButton:
PROC [button: Buttons.Button] ~ {
Buttons.SetDisplayStyle[button: button, style: style];
DO
Buttons.ReLabel[button: button, newName: CurrentTime[]];
Process.Pause[ticks: Process.SecondsToTicks[IF seconds THEN 1 ELSE 30]];
ENDLOOP;
};
UserProfile.CallWhenProfileChanges[StyleInit];
TRUSTED {
Process.Detach[
FORK UpdateButton[
Buttons.Create[
info: [name: IF seconds THEN "12:00:00" ELSE "12:00"],
proc: UpdateButtonNow,
paint: FALSE]
]];
};
END.