WindowManagerImpl.mesa;
Edited by McGregor on December 14, 1982 10:55 am
Last Edited by: Maxwell, February 8, 1983 3:58 pm
Last Edited by: Paul Rovner, June 15, 1983 6:15 pm
Last Edited by: Doug Wyatt, December 8, 1983 3:19 pm
DIRECTORY
Carets USING [ResumeCarets, SuspendCarets],
ColorWorld USING [TurnOffColor, TurnOnColor],
Cursors USING [CursorType, GetCursor, SetCursor],
InputFocus USING [CaptureButtons, inputEnabled, ReleaseButtons, WindowManagerTIPTable],
Interminal USING [terminal],
InterminalExtra USING [InsertAction],
Graphics USING [black, ClipBox, Color, Context, DrawBox, Scale, SetColor, SetStipple,
Translate, white],
Menus USING [AppendMenuEntry, CreateEntry, CreateMenu, MenuEntry, Menu,
MenuProc, ReplaceMenuEntry, SetGuarded],
MenusPrivate USING [ClearMenu, DrawMenu, HitMenu, MarkMenu],
MessageWindow USING [Append, Blink],
PrincOpsUtils USING [IsBound],
TIPUser USING [TIPScreenCoords, TIPScreenCoordsRec],
Terminal USING [BlinkBWDisplay],
ViewerClasses USING [Column, ScrollOp, Viewer],
ViewerMenus,
ViewerOps USING [AcquireContext, ChangeColumn, CloseViewer, EnumerateViewers, EnumProc,
InitialiseColorPainting, InvisiblePaint, MouseInViewer, PaintViewer, ReleaseContext,
TopViewer, XYWH2Box],
ViewerSpecs USING [captionHeight, scrollBarW, windowBorderSize],
WindowManager,
WindowManagerPrivate;
WindowManagerImpl: CEDAR MONITOR
IMPORTS Carets, ColorWorld, Cursors, Graphics, InputFocus, Interminal, InterminalExtra, Menus, MenusPrivate, MessageWindow, PrincOpsUtils, ViewerMenus, ViewerOps, Terminal
EXPORTS WindowManager, WindowManagerPrivate
SHARES InputFocus, Menus, ViewerClasses, ViewerOps =
BEGIN OPEN Cursors, ViewerClasses, ViewerSpecs;
Zone: TYPE = {none, menu, scroll, caption, client} ;
trackingState: Zone ← none;
CursorZone: PROC [v: Viewer, mousePos: TIPUser.TIPScreenCoords] RETURNS [z: Zone] =
BEGIN OPEN v;
RETURN[SELECT TRUE FROM
parent=NIL AND column#static AND mousePos.mouseY IN [wh-captionHeight..wh] => caption,
scrollable AND mousePos.mouseX IN [0..scrollBarW] AND mousePos.mouseY IN [0..ch] => scroll,
menu#NIL AND mousePos.mouseY IN ((cy-wy)+ch..wh-captionHeight) => menu,
ENDCASE => none
]
END;
ProcessWindowResults: PUBLIC PROC [self: Viewer, input: LIST OF REF ANY] = BEGIN
not monitored since notifier is synchronous
zone: Zone;
newZone: BOOL;
shift, control: BOOLFALSE;
mousePos: TIPUser.TIPScreenCoords;
FOR l: LIST OF REF ANY ← input, l.rest UNTIL l = NIL DO WITH l.first SELECT FROM
z: ATOM => BEGIN OPEN InputFocus;
IF newZone THEN SELECT trackingState FROM-- old feedback
scroll  => {ReleaseButtons[]; RemoveScrollFeedback[]};
menu  => {ReleaseButtons[]; MenusPrivate.ClearMenu[feedbackViewer.menu,
feedbackViewer]; feedbackViewer ← NIL};
caption => {ReleaseButtons[]; RemoveCaptionFeedback[]};
ENDCASE;
IF newZone THEN SELECT zone FROM-- first time stuff
scroll  => {CaptureButtons[ProcessWindowResults, WindowManagerTIPTable,
self];
PostScrollFeedback[self]};
menu  => {CaptureButtons[ProcessWindowResults, WindowManagerTIPTable,
self];
feedbackViewer ← self;
SetC[bullseye]};
caption => {CaptureButtons[ProcessWindowResults, WindowManagerTIPTable,
self];
PostCaptionFeedback[self];
SetC[bullseye]};
ENDCASE => SetC[textPointer];
SELECT trackingState ← zone FROM-- zone specific ops
scroll  => SELECT z FROM
$M   => SetC[scrollUpDown];
$RU   => HitScroll[self, mousePos.mouseY, up, shift, control];
$RD, $RM => SetC[scrollUp];
$YU   => HitScroll[self, mousePos.mouseY, thumb, shift, control];
$YD, $YM => SetC[scrollRight];
$BU   => HitScroll[self, mousePos.mouseY, down, shift, control];
$BD, $BM => SetC[scrollDown];
$Control  => control ← TRUE;
$Shift   => shift ← TRUE;
ENDCASE  => NULL;
menu  => SELECT z FROM
$RU   => MenusPrivate.HitMenu[self.menu,
self, mousePos, red, shift, control];
$BU   => MenusPrivate.HitMenu[self.menu,
self, mousePos, blue, shift, control];
$YU   => MenusPrivate.HitMenu[self.menu,
self, mousePos, yellow, shift, control];
$RM, $BM, $YM
=> {MenusPrivate.MarkMenu[self.menu,
self, mousePos]};
$RD, $BD, $YD
=> MenusPrivate.MarkMenu[self.menu,
self, mousePos];
$Control  => control ← TRUE;
$Shift   => shift ← TRUE;
ENDCASE  => NULL;
caption  => SELECT z FROM
$RU   => MenusPrivate.HitMenu[windowMenu,
self, mousePos, red, shift, control];
$BU   => MenusPrivate.HitMenu[windowMenu,
self, closePos, blue, FALSE, FALSE];
$YU   => MenusPrivate.HitMenu[windowMenu,
self, growPos, yellow, FALSE, FALSE];
$RM, $RD => MenusPrivate.MarkMenu[windowMenu,
self, mousePos];
$BM, $BD => MenusPrivate.MarkMenu[windowMenu,
self, closePos];
$YM, $YD => MenusPrivate.MarkMenu[windowMenu,
self, growPos];
$Control  => control ← TRUE;
$Shift   => shift ← TRUE;
ENDCASE  => NULL;
ENDCASE;
END;
z: TIPUser.TIPScreenCoords => {
client: BOOLFALSE;
mousePos ← z;
IF mousePos.mouseX = 0 --AND trackingState = scroll-- THEN mousePos.mouseX ← 1;
IF trackingState#none THEN [self, client] ← ViewerOps.MouseInViewer[mousePos];
zone ← IF client OR self=NIL THEN none ELSE CursorZone[self, mousePos];
newZone ← trackingState#zone OR (zone=caption AND self#feedbackViewer)
OR (zone=scroll AND self#feedbackViewer);
};
z: REF CHAR => TRUSTED {Interminal.terminal.BlinkBWDisplay[]};
ENDCASE => NULL;
ENDLOOP;
END;
AlterColumn: PROC [v: Viewer, mx: INTEGER] = BEGIN
column: ViewerClasses.Column;
right: BOOL ~ mx >= v.ww/2;
column ← SELECT v.column FROM
left => IF right THEN right ELSE IF colorDisplayOn THEN color ELSE right,
right => IF ~right THEN left ELSE IF colorDisplayOn THEN color ELSE left,
color => IF right THEN right ELSE left,
ENDCASE => ERROR;
ViewerOps.ChangeColumn[v, column];
END;
SetC: PROC [cursor: CursorType] = INLINE
{IF waitCount=0 AND GetCursor[]#cursor THEN SetCursor[cursor]};
HitScroll: PROC [v: Viewer, y: LONG INTEGER, op: ScrollOp, shift, control: BOOL] = BEGIN
RemoveScrollFeedback[];
IF v.parent=NIL OR v.class.coordSys#top THEN y ← v.ch-y; -- client coords
IF v.class.scroll#NIL THEN [] ← v.class.scroll[v, op,
SELECT op FROM
up, down => y,
ENDCASE => (100*y)/v.ch, -- percent
shift, control];
SetC[scrollUpDown]; -- put the cursor back
PostScrollFeedback[v];
END;
feedbackViewer: Viewer ← NIL;
PostScrollFeedback: PROC [v: Viewer] = BEGIN
visible: CARDINAL = 122645B;
inVisible: CARDINAL = 100040B;
context: Graphics.Context;
baseY, baseX, top, bottom: INTEGER;
relY1, relY2: INT; -- so won't overflow
IF feedbackViewer#NIL OR v.class.scroll=NIL THEN RETURN;
IF ~v.init THEN RETURN; -- avoid a race condition bug
[top, bottom] ← v.class.scroll[v, query, 0];
IF top>100 OR bottom>100 THEN RETURN;
Carets.SuspendCarets[];
context ← ViewerOps.AcquireContext[v.parent, v.column=color
! ViewerOps.InvisiblePaint => GOTO Punt];
IF v.parent#NIL AND v.parent.class.coordSys=top THEN BEGIN-- flip origin
Graphics.Translate[context, 0, v.parent.ch];
Graphics.Scale[context, 1, -1];
baseY ← v.parent.ch - v.wy - v.wh + (IF v.border THEN windowBorderSize ELSE 0);
END
ELSE baseY ← v.wy + (IF v.border THEN windowBorderSize ELSE 0);
baseX ← v.wx + (IF v.border THEN windowBorderSize ELSE 0);
relY1 ← baseY;
relY2 ← (LONG[100-bottom]*v.ch)/100+baseY;
Graphics.SetStipple[context, inVisible];
Graphics.DrawBox[context, [baseX, relY1, baseX+scrollBarW, relY2]];
relY1 ← relY2;
relY2 ← relY2 + (LONG[bottom-top]*v.ch)/100;
Graphics.SetStipple[context, visible];
Graphics.DrawBox[context, [baseX, relY1, baseX+scrollBarW, relY2]];
Graphics.SetStipple[context, inVisible];
Graphics.DrawBox[context, [baseX, relY2, baseX+scrollBarW, baseY+v.ch]];
ViewerOps.ReleaseContext[context];
feedbackViewer ← v; Carets.ResumeCarets[];
EXITS Punt => {feedbackViewer ← NIL; Carets.ResumeCarets[]};
END;
RemoveScrollFeedback: PROC = BEGIN
context: Graphics.Context;
baseX, baseY: INTEGER;
IF feedbackViewer=NIL THEN RETURN;
Carets.SuspendCarets[];
context ← ViewerOps.AcquireContext[feedbackViewer.parent, feedbackViewer.column=color
! ViewerOps.InvisiblePaint => GOTO Punt];
IF feedbackViewer.parent#NIL AND feedbackViewer.parent.class.coordSys=top THEN BEGIN
flip origin
Graphics.Translate[context, 0, feedbackViewer.parent.ch];
Graphics.Scale[context, 1, -1];
baseY ← feedbackViewer.parent.ch - feedbackViewer.wy - feedbackViewer.wh +
(IF feedbackViewer.border THEN windowBorderSize ELSE 0);
END
ELSE baseY ← feedbackViewer.wy + (IF feedbackViewer.border THEN windowBorderSize ELSE 0);
baseX ← feedbackViewer.wx + (IF feedbackViewer.border THEN windowBorderSize ELSE 0);
Graphics.SetColor[context, Graphics.white];
Graphics.DrawBox[context, [baseX, baseY, baseX+scrollBarW, baseY+feedbackViewer.ch]];
ViewerOps.ReleaseContext[context];
GOTO Punt;
EXITS Punt => {feedbackViewer ← NIL; Carets.ResumeCarets[]};
END;
DrawCaptionMenu: PUBLIC ENTRY PROC [v: Viewer, guard: BOOL] =
{ENABLE UNWIND => NULL; InternalDrawCaptionMenu[v, guard]};
InternalDrawCaptionMenu: INTERNAL PROC [v: Viewer, guard: BOOL] = BEGIN OPEN v;
x, y: INTEGER;
context: Graphics.Context;
IF feedbackViewer#v OR iconic OR ~visible THEN RETURN;
context ← ViewerOps.AcquireContext[parent, column=color
! ViewerOps.InvisiblePaint => GOTO Punt];
x ← wx+windowBorderSize;
y ← wy+wh-captionHeight;
Graphics.ClipBox[context, ViewerOps.XYWH2Box[x, y, ww-(2*windowBorderSize),
captionHeight]];
Graphics.SetColor[context, Graphics.white];
Graphics.DrawBox[context, ViewerOps.XYWH2Box[x, y, ww, captionHeight]];
Graphics.SetColor[context, Graphics.black];
IF guard THEN Menus.SetGuarded[destroyEntry,
guardDestroy OR (newVersion AND link=NIL AND ~saveInProgress)];
MenusPrivate.DrawMenu[windowMenu, context, x, y];
ViewerOps.ReleaseContext[context];
EXITS Punt => NULL;
END;
PostCaptionFeedback: ENTRY PROC [v: Viewer] = BEGIN
ENABLE UNWIND => NULL;
IF feedbackViewer#v THEN BEGIN-- remove old
IF feedbackViewer#NIL THEN
MenusPrivate.ClearMenu[windowMenu, feedbackViewer, FALSE];
feedbackViewer ← v;
END;
InternalDrawCaptionMenu[v, TRUE];
END;
RemoveCaptionFeedback: ENTRY PROC = BEGIN
ENABLE UNWIND => NULL;
IF feedbackViewer#NIL THEN BEGIN
MenusPrivate.ClearMenu[windowMenu, feedbackViewer, FALSE];
ViewerOps.PaintViewer[feedbackViewer, caption];
feedbackViewer ← NIL;
END;
END;
waitCount: PUBLIC INTEGER ← 0;
WaitCursor: PUBLIC ENTRY PROC [cursor: Cursors.CursorType ← hourGlass] = BEGIN
ENABLE UNWIND => NULL;
IF InputFocus.inputEnabled THEN SetCursor[cursor];
waitCount ← waitCount + 1;
END;
UnWaitCursor: PUBLIC ENTRY PROC = BEGIN
ENABLE UNWIND => NULL;
waitCount ← MAX[0, waitCount - 1];
IF waitCount=0 THEN RestoreCursor[];
END;
RestoreCursor: PUBLIC PROC = TRUSTED
{IF InputFocus.inputEnabled THEN InterminalExtra.InsertAction[[contents: deltaMouse[[0,0]]]]};
StartColorViewers: PUBLIC PROC [screenPos: WindowManager.ScreenPos,
bitsPerPixel: CARDINAL] = BEGIN
IF colorDisplayOn THEN StopColorViewers[];
IF PrincOpsUtils.IsBound[ColorWorld.TurnOnColor] THEN
colorDisplayOn ← ColorWorld.TurnOnColor[bitsPerPixel, (screenPos=left)]
ELSE colorDisplayOn ← FALSE;
IF ~colorDisplayOn THEN BEGIN
MessageWindow.Append["Sorry, you don't have a color display.", TRUE];
MessageWindow.Blink[];
RETURN;
END;
ViewerOps.InitialiseColorPainting[];
Menus.ReplaceMenuEntry[windowMenu, tNopEntry, tColorEntry];
growPos^ ← [growEntry.xPos+1, FALSE, 0];
closePos^ ← [closeEntry.xPos+1, FALSE, 0];
END;
StopColorViewers: PUBLIC PROC = BEGIN
DoColorViewer: ViewerOps.EnumProc = BEGIN
IF v.column=color THEN BEGIN
ViewerOps.CloseViewer[v];
ViewerOps.ChangeColumn[v, left];
END;
END;
IF ~colorDisplayOn THEN RETURN;
ViewerOps.EnumerateViewers[DoColorViewer];
ColorWorld.TurnOffColor[];
colorDisplayOn ← FALSE;
Menus.ReplaceMenuEntry[windowMenu, tColorEntry, tNopEntry];
growPos^ ← [growEntry.xPos+1, FALSE, 0];
closePos^ ← [closeEntry.xPos+1, FALSE, 0];
END;
BuildWindowMenus: PROC = BEGIN
windowMenu ← Menus.CreateMenu[];
Menus.AppendMenuEntry[windowMenu, destroyEntry ← Menus.CreateEntry[name: "Destroy",
proc: ViewerMenus.Destroy, fork: FALSE, documentation: "Edits will be discarded..."]];
Menus.AppendMenuEntry[windowMenu, Menus.CreateEntry[name: "Adjust",
proc: ViewerMenus.Adjust, fork: FALSE]];
Menus.AppendMenuEntry[windowMenu, Menus.CreateEntry[name: "Top",
proc: Top, fork: FALSE]];
Menus.AppendMenuEntry[windowMenu, Menus.CreateEntry[name: "<--",
proc: ViewerMenus.Left, fork: FALSE]];
Menus.AppendMenuEntry[windowMenu, Menus.CreateEntry[name: "-->",
proc: ViewerMenus.Right, fork: FALSE]];
Menus.AppendMenuEntry[windowMenu, tNopEntry ← Menus.CreateEntry["", NIL]];
tColorEntry ← Menus.CreateEntry[name: "Color", proc: ViewerMenus.Color, fork: FALSE];
Menus.AppendMenuEntry[windowMenu, growEntry ← Menus.CreateEntry[name: "Grow",
proc: ViewerMenus.Grow, fork: FALSE]];
Menus.AppendMenuEntry[windowMenu, closeEntry ← Menus.CreateEntry[name: "Close",
proc: ViewerMenus.Close, fork: FALSE]];
growPos ← NEW[TIPUser.TIPScreenCoordsRec ← [growEntry.xPos+1, FALSE, 0]];
closePos ← NEW[TIPUser.TIPScreenCoordsRec ← [closeEntry.xPos+1, FALSE, 0]];
END;
this should be in ViewerMenus
Top: Menus.MenuProc = {ViewerOps.TopViewer[NARROW[parent]]};
colorDisplayOn: PUBLIC BOOLFALSE; -- color display status
windowMenu: PUBLIC Menus.Menu;
destroyEntry, closeEntry, growEntry, tColorEntry, tNopEntry: Menus.MenuEntry;
growPos, closePos: TIPUser.TIPScreenCoords;
BuildWindowMenus[];
END.