Text preview for : WManSelection.mesa_Oct77.pdf part of xerox WManSelection.mesa Oct77 xerox mesa 3.0_1977 listing WManSelection.mesa_Oct77.pdf



Back to : WManSelection.mesa_Oct77. | Home

WManSelection.mesa 25-0CT-11 15:24:43 Page 1


--File: WManSelection.mesa
--Edited by Sandman October 1. 1911 9:20 AM
DIRECTORY
WindowDefs: FROM "windowdefs".
StreamDefs: FROM "streamdefs".
SystemDefs: FROM "systemdefs".
MenuDefs: FROM "menudefs".
RectangleDefs: FROM "rectangledefs",
WManagerDefs: FROM "wmanagerdefs";
DEFINITIONS FROM StreamDefs. MenuDefs. WindowDefs. RectangleDefs. WManagerDefs;
WManSelection: PROGRAM[WMState: WMDataHandle]
IMPORTS WindowDefs, StreamDefs. SystemDefs. MenuDefs, RectangleDefs. WManagerDefs
EXPORTS WManagerDefs
SHARES StreamDefs. MenuDefs. WManagerDefs ~
BEGIN
OPEN WMState;
CR: CHARACTER = 15C:
Space: CHARACTER = 40C:
MenuSelect: PUBLIC PROCEDURE
[w: WindowHandle. x: xCoord. y: yCoord]=
BEGIN
-- define locals
index: INTEGER ~ -1;
mapx: xCoord:
mapy: yCoord;
defaultmenu: DESCRIPTOR FOR ARRAY OF MenuItem =
DESCRIPTOR[BASE[menuarray]. LENGTH[menuarray]];
-- check if a menu
IF w.menu = NIL THEN
w.menu ~ CreateMenu[defaultmenu]:
-- paste it up there
[mapx. mapy] ~ CursorToMapCoords[defaultmapdata. x. y];
mapy ~ MIN[mapy. MAX[O.(w.rectangle.bitmap.height)
-(LENGTH[w.menu.array]*defaultlineheight+2)]];
DisplayMenu[w.menu. w.rectangle.bitmap. mapx. mapy]:
-- while the button is down select menu items
WHILE GetMouseButton[] = Blue DO
-- convert to rectangle coords
x ~ xcursorloct:
y ~ ycursorloc t ;
-- and see if in menu
[x. y] ~ CursorToRectangleCoords[w.menu.rectangle. x. y]:
IF x > a AND x <= w.menu.rectangle.cw
AND y > a AND y <= w.menu.rectangle.ch
THEN index ~ y/defaultlineheight
ELSE index ~ -1:
MarkMenu I tem[w. menu. index];
ENDLOOP:
-- and restore menus region and contents underneath
ClearMenu[w.menu]:
-- see if command selected
IF index # -1 THEN
w. menu. arr aye index] . proc[w. x cursor 1oct. ycursor 1oct] ;
END:

TextSelect: PUBLIC PROCEDURE
[w: WindowHandle. x: xCoord. y: yCoord]-
BEGIN
-- Declare locals
line. width: INTEGER:
xpos: xCoord:
5 a ve i nde x, i ndex: S t ream In dex:
sel: POTNTrR TO Selection:
exsel: POINTER TO Selection:
Ir w.file H NIL THEN
BfGIN
-- first find character under the bug and then mark the selection
sel ... SystemOefs.AllocatelieapNode[SI7f[Selection]]:
exsel ... SystemDefs.AllocatelieapNode[SIZE[Select ion]]:
WManSelection.mesa 25-0CT-77 15:24:43 Page 2


[line, xpos, width, index] ~ ResolveBugToPosition[w, x, y]:
saveindex ~ index:
sel1' ~ Selection[xpos, xpos+width, line, 1 ine, index, index]:
MakeSe1ection[w, sell;
check for extensions
WHILE GetMouseButton[] = Red 00
IF x # xcursorloc1' OR y # ycursorloc1' THEN
BEGIN
x ~ xcursorloc1': y ~ ycursorloc1':
[line. xpos. width, index] ~ Reso1veBugToPosition[w, x, y]:
IF NOT Equa1Index[saveindex, index] THEN
BEGIN
IF (line >= w.selection.1eft11ne) ANO
(xpos >= w.se1ection.leftx)
THEN exse11' ~ Se1ection[sel.1eftx, xpos+width,
se1.1eft1ine, line, se1.1eftindex, index]
ELSE exse11' ~ Se1ection[xpos, se1.rightx, line,
se1.right1ine, index, sel.rlghtindex]:
MakeSe1ection[w, exse1]:
savelndex ~ index;
END:
ENO:
ENOLOOP:
SystemOefs.FreeHeapNode[se1]:
SystemOefs.FreeHeapNode[exse1]:
END:
END:
WordSe1ect: PUBLIC PROCEDURE
[w: WindowHand1e, x: xCoord, y: yCoord]=
BEGIN
-- Declare Locals
1 ine: INTEGER:
saveindex. index: StreamIndex:
se1: POINTER TO Selection:
exse1: POINTER TO Selection:
IF w.file # NIL THEN
BEGIN
-- first find word under the bug and then mark the selection
se1 ~ SystemOefs.A11ocateHeapNode[SIZE[Se1ection]]:
exse1 ~ SystemDefs.A110cateHeapNode[SIZE[Se1ection]]:
[line, , , index] ~ Reso1veBugToPosition[w, x, y]:
saveindex ~ index:
--check both ways for space to find whole word
se1. 1eft1ine ~ line:
ExtendTheWord[w,se1,index]:
MakeSe1ection[w, se1]:
check for extensions
WHILE GetMouseButton[] = Yellow DO
IF x # xcursor10c1' OR y # ycursor10c1' THEN
BEGIN
x ~ xcursor1oc1'; y ~ ycursor10c1':
[line. , . index] ~ Reso1veBugToPosition[w, x, y];
IF NOT Equa1Index[saveindex, index] THEN
BEGIN
--extend the word and the selection
exse1. 1eft1ine ~ line:
ExtendTheWord[w.exse1,index];
IF (exsel. 1eft1ine )= w.se1ection. 1eftline} AND
(exsel.1eftx )= w.se1ection. 1eftx}
THEN exse1' ~ Selection[se1.1eftx. , sel.leftline, , sel.leftindex, ]
ELSE exse" .. Selection[, se1.rightx, . se1.rightline, , se1.rightindex];
MakeSelection[w, exse1];
saveindex ~ index;
END;
END;
ENOlOOP;
SystemOefs.FreelleapNode[sel];
SyslemOefs.freelleapNode[exse1];
END;
ENO;
rxtendTheWord: PROC[oUR[ [w: Windowllandle, se1: POINTER TO Selection, pos: StreamIndex]
BEGIN
declare- locals
-- note that oldend/start point to previous word
WManSelection.mesa 25-0CT-77 16:24:43 Page 3


-- and end/start refer to current word
-- save points to index of current character
savedindex, oldend, oldstart, save: StreamIndex:
start, end: StreamIndex:
leftpos, rightpos: xCoord:
oldleft, oldright: xCoord:
savewidth, nlines, width, lineno: INTEGER:
char: CHARACTER:
firsttime: BOOLEAN p TRUE:
lastline, overtheline: BOOLEAN p FALSE:
oldchar, newchar: {sp, ch, cc, xtra}:
linestarts: DESCRIPTOR FOR ARRAY OF StreamIndex:
nlines p (w.rectangle.ch/w.ds.lineheight)-l:
linestarts p DESCRIPTOR[GetLineTable[],nlines]:
saved index p GetIndex[w.file]: lineno p sel.leftline:
IF lineno = nlines THEN lastline p TRUE;
SetIndex[w.file, linestarts[lineno - 1]]:
oldend p oldstart p start pend p GetIndex[w.file];
savewidth p oldleft p oldright ~ leftpos ~ rightpos p leftmargin:
WHILE GrEqualIndex[pos,start] 00
IF NOT firsttime THEN oldchar ~ newchar;
save p GetIndex[w.file]:
char p w.file.get[w.file
I StreamError =) EXIT]:
width p IF char = l1C THEN ComputeTabWidth[w.ds.pfont.rightpos]
ELSE ComputeCharWidth[char, w.ds.pfont];
IF NOT lastline THEN
BEGIN
IF save = linestarts[lineno] THEN
BEGIN
overtheline p TRUE;
lineno p lineno + 1;
IF lineno = nlines THEN
BEGIN
lastline p TRUE:
savewidth p savewidth + width:
END:
rightpos p leftmargin:
END;
END
ELSE
BEGIN
savewidth p savewidth + width:
IF savewidth )= w.rectangle.cw THEN EXIT;
END;
IF char = CR THEN
BEGIN
IF overtheline AND rightpos leftmargin THEN
BEGIN
rightpos p oldright:
lineno ~ lineno - 1:
END:
EXIT:
END:
SELECT char FROM
IN ['a .. 'z],IN ['A .. 'Z] =) newchar ~ chi
IN ['0 .. '9] =) newchar ~ Chi
=Space =) newchar ~ sp:
ENDCASE =) newchar ~ xtra:
IF firsltime OR oldchar # newchar TfIEN
BEGIN
oldstart ~ start: oldend pend:
oldleft ~ leftpos; oldright ~ rightpos:
start ~ end ~ save:
leftpos ~ rightpos:
rightpos ~ rightpos + width:
firsttime ~ FALSE;
END
ELSE
BEGIN
rightpos ~ rightpos + width:
end ~ save:
Ir EqualIndex[w.eofindex, Getlndex[w.file]] THEN EXIT:
[NO:
REPEAT
WManSelection.mesa 25-0CT-77 15:24:43 Page 4


FINISHED ->
BEGIN
start ~ oldstart; end ~ oldend;
leftpos ~ oldleft; rightpos ~ oldright:
END;
ENDLOOP;
SetIndex[w.file. savedindex]:
sel.rightline ~ MAX[sel.leftline,lineno];
selt ~ Selection[
leftpos, rightpos, MIN[sel.leftline,lineno], , start, end];
RETURN
END:
ComputeTabWidth: PROCEDURE [font: FAptr, x: xCoord]
RETURNS [CARDINAL] =
BEGIN
tw: CARDINAL = ComputeCharWidth[' ,font]