<> <> DIRECTORY Cursors, InputFocus, LFUtil, TIPUser, ViewerClasses, WindowManager, UserTerminal ; LFUtilImpl: CEDAR MONITOR IMPORTS Cursors, InputFocus, TIPUser, WindowManager EXPORTS LFUtil ~ BEGIN topY, leftX, sourceBottom, sourceHeight, sourceLeft, sourceWidth: INTEGER; mode: {waitingForUpperLeft, waitingForLowerRight, done} _ done; ready: CONDITION; GetArea: PUBLIC ENTRY PROC RETURNS [sMin, fMin: INTEGER, sSize, fSize: NAT] = { ENABLE UNWIND => NULL; mode _ waitingForUpperLeft; InputFocus.CaptureButtons[BoxAdjustNotify, vaTIP]; Cursors.SetCursor[blank]; Cursors.AddCursorCorner[upperLeft]; UNTIL mode = done DO WAIT ready ENDLOOP; sMin _ 808 - (sourceBottom + sourceHeight); sSize _ sourceHeight; fMin _ sourceLeft; fSize _ sourceWidth; }; Clip: PROC [position: TIPUser.TIPScreenCoords] RETURNS [x, y: INTEGER] = BEGIN x _ position.mouseX; y _ position.mouseY; END; BoxAdjustNotify: ENTRY ViewerClasses.NotifyProc ~ { ENABLE UNWIND => {InputFocus.ReleaseButtons[]; WindowManager.RestoreCursor[]}; mouseX, mouseY: INTEGER _ 0; FOR list: LIST OF REF ANY _ input, list.rest UNTIL list = NIL DO WITH list.first SELECT FROM x: ATOM => SELECT x FROM $Abort => BEGIN InputFocus.ReleaseButtons[]; WindowManager.RestoreCursor[]; END; $Move => BEGIN END; $End => BEGIN IF mode = waitingForUpperLeft THEN { mode _ waitingForLowerRight; Cursors.SetCursor[blank]; Cursors.AddCursorCorner[lowerRight]; topY _ mouseY; leftX _ mouseX; } ELSE IF mode = waitingForLowerRight THEN { mode _ done; IF topY < mouseY THEN {t: NAT _ topY; topY _ mouseY; mouseY _ t}; IF leftX > mouseX THEN {t: NAT _ leftX; leftX _ mouseX; mouseX _ t}; sourceBottom _ mouseY; sourceHeight _ topY - mouseY + 1; sourceLeft _ leftX; sourceWidth _ mouseX - leftX + 1; InputFocus.ReleaseButtons[]; WindowManager.RestoreCursor[]; NOTIFY ready; }; END; ENDCASE => NULL; z: TIPUser.TIPScreenCoords => [mouseX, mouseY] _ Clip[z]; ENDCASE => ERROR; ENDLOOP; }; vaTIP: TIPUser.TIPTable _ TIPUser.InstantiateNewTIPTable["/Indigo/CedarViewers/Viewers/ViewerAdjust.tip"]; END.