-- GCellprivateDefs.mesa
-- Last Edited by: Sturgis, July 10, 1984 9:11:03 pm PDT

DIRECTORY
   Expressions USING[AnalyzedExpression, AnalyzedIdentifier, IdTableSet],
   Dependencies USING[Action, DataItem],
   GCell USING[GCellItemDescriptor, GCellItemJustification, GCellItemMode, GCellItemRowColSumMode, GCellItemValueMode],
   IO USING[STREAM],
   NewCalcGlobal USING[Displayer, Document],
   Rope USING[ROPE],
   StructureNodes USING[DisplayArray, StructureNode],
   ViewerClasses USING[Viewer];
   
GCellPrivateDefs: DEFINITIONS =

BEGIN OPEN Dependencies, Expressions, GCell, IO, NewCalcGlobal, Rope, ViewerClasses;
	

	

GCell: TYPE = REF GCellBody;
GCellBody: PUBLIC TYPE = RECORD[
	da: StructureNodes.DisplayArray,
	selfI, selfJ: CARDINAL ← 0,
	
	document: NewCalcGlobal.Document,
	displayer: NewCalcGlobal.Displayer,
	gcaSn: StructureNodes.StructureNode,
	vParent: Viewer,
	
	rowSummer, colSummer: Action ← NIL,
	
	screenLead: INTEGER ← 0,
	screenSpace: INTEGER ← 0,
	
	textLead: INTEGER ← 0,
	textSpace: INTEGER ← 2, -- eventually this will become changeable by GCellTool
	textNLines: INTEGER ← 0, -- set by preshow
	
	lastPrePaintY, lastPrePaintX, lastPrePaintL, lastPrePaintR, lastPrePaintW: INTEGER ← 0, 
	unPainted: BOOLEAN ← TRUE,
	
	
	nItems: CARDINAL ← 0,
	items: Item ← NIL
	];
	

Item: TYPE = REF ItemBody;
ItemBody: TYPE = RECORD[
	da: StructureNodes.DisplayArray,
	selfI, selfJ: CARDINAL ← 0,
	selfItemX: CARDINAL ← 0,
	
	mode: GCellItemMode,
	justification: GCellItemJustification,
	rowSumMode: GCellItemRowColSumMode,
   colSumMode: GCellItemRowColSumMode,
   valueMode: GCellItemValueMode,
	idName: ROPE,
	expressionText: ROPE,
	zeroValText: ROPE,
	
	created: BOOLEAN ← TRUE,

	expressionBad: BOOLEAN ← TRUE,
	expression: AnalyzedExpression ← [NIL],
	
	evalAction:  Action ← NIL, -- created only if expression is not simple constant
	
	firstTime: BOOLEAN ← TRUE, -- set false after value is first displayed
	value: REAL ← 0,
	valueChanges: DataItem ← NIL, -- created only if information passes through this item
	
	
	idBad: BOOLEAN ← TRUE,
	id: AnalyzedIdentifier ← [NIL],
	
	assignAction: Action ← NIL, -- created only if there is an identifier
	
	buttonText: ROPE,
	buttonTextDirty: BOOLEAN ← FALSE, -- set true when buttonText changed
	buttonTextAnalyzed: BOOLEAN← FALSE, -- set false when text becomes dirty, is set true when analyzed
	buttonShapeDirty: BOOLEAN ← FALSE, -- set true when shape recomputed, textDirty is set false at that time.
	
	buttonL, buttonA, buttonB, buttonR, buttonW: INTEGER ← 0,
	buttonHeight: INTEGER ← 0,
	textL, textA, textB, textR, textW: INTEGER ← 0,
	
	viewerX, viewerY, viewerW: INTEGER ← 0,
	dirty: BOOLEAN ← TRUE,
	viewer: Viewer ← NIL,
	viewerMode: ItemViewerMode ← nil,
	editable: BOOLEAN ← FALSE,
	
	next: Item ← NIL];

ItemViewerMode: TYPE = {nil, button, textBox};

ItemRefDesc: TYPE = REF ItemRefDescBody;
ItemRefDescBody: TYPE = RECORD[da: StructureNodes.DisplayArray, I, J: CARDINAL, itemX: CARDINAL];

-- procedures supplied to GCellImplA by GCellImplB

ReadOneItem: PROCEDURE[from: STREAM, version: CARDINAL] RETURNS[GCellItemDescriptor];
CreateItem: PROCEDURE[idTables: IdTableSet, gc: GCell, da: StructureNodes.DisplayArray, selfI, selfJ, selfItemX: CARDINAL, desc: GCellItemDescriptor, show: BOOLEAN] RETURNS[item: Item];
AnalyzeItemExpression: PROCEDURE[idTables: IdTableSet, gc: GCell, item: Item];
HandleItemValueChanges: PROCEDURE[gc: GCell, item: Item];
DoItemRowSum: PROCEDURE[gc: GCell, item: Item, sum: REAL] RETURNS[REAL];
ClearGCell: PROCEDURE[gc: GCell];
GetItemDescriptor: PROCEDURE[item: Item] RETURNS[GCellItemDescriptor];
ItemAcceptsSelection: PROCEDURE[item: Item] RETURNS[BOOLEAN];
ForceItemSelection: PROCEDURE[gcSn: StructureNodes.StructureNode, gc: GCell, item: Item];
WriteOneItem: PROCEDURE[desc: GCellItemDescriptor, to: STREAM];
SubstituteInItem: PROCEDURE[idTables: IdTableSet, gc: GCell, item: Item, newText: Rope.ROPE, oldText: Rope.ROPE];
CheckItemForDirtyData: PROCEDURE[gc: GCell, item: Item];
ComputeTextShape: PROCEDURE[item: Item];
ShowItem: PROCEDURE[item: Item, L, R, W: INTEGER, to: STREAM];	
AnalyzeItemId: PROCEDURE[idTables: IdTableSet, gc: GCell, item: Item];
DoItemColSum: PROCEDURE[gc: GCell, item: Item, sum: REAL] RETURNS[REAL];
PrePaintItem: PROCEDURE[gc: GCell, item: Item, y, x, L, R, W: INTEGER];
PaintItem: PROCEDURE[gc: GCell, item: Item, dirtyOnly: BOOLEAN];
NoteCoordinatesItem: PROCEDURE[item: Item, document: NewCalcGlobal.Document, da: StructureNodes.DisplayArray, I, J, x: CARDINAL];

END..

-- February 28, 1983 4:50 pm: Sturgis, started GCellPrivateDefs.mesa
-- March 1, 1983 1:44 pm: add ncGlobal to NoteCoordinates item.
-- March 3, 1983 2:33 pm: remove idTables from GCell, and modify appropriate procedures to take idTables as an argument.