{U4BOXER2} METHODS OF TBox; FUNCTION TBox.CREATE(object: TObject; itsHeap: THeap): TBox; BEGIN {$IFC fTrace}BP(11);{$ENDC} SELF := NewObject(itsHeap, THISCLASS); WITH SELF DO BEGIN shapeLRect := zeroLRect; color := colorGray; END; {$IFC fTrace}EP;{$ENDC} END; {This draws a particular box} PROCEDURE TBox.Draw; VAR lPat: LPattern; BEGIN {$IFC fTrace}BP(10);{$ENDC} PenNormal; IF LRectIsVisible(SELF.shapeLRect) THEN {this box needs to be drawn} BEGIN {Get a Quickdraw pattern to represent the box's color} CASE SELF.color OF colorWhite: lPat := lPatWhite; colorLtGray: lPat := lPatLtGray; colorGray: lPat := lPatGray; colorDkGray: lPat := lPatDkGray; colorBlack: lPat := lPatBlack; OTHERWISE lPat := lPatWhite; {this case should not happen} END; {Fill the box with the pattern, and draw a frame around it} FillLRect(SELF.shapeLRect, lPat); FrameLRect(SELF.shapeLRect); END; {$IFC fTrace}EP;{$ENDC} END; {This calls the DoToHandle Procedure once for each handle LRect; user of this method must set up the pen pattern and mode before calling} PROCEDURE TBox.PaintHandles; VAR hLRect, shapeLRect: LRect; dh, dv: LONGINT; PROCEDURE MoveHandleAndPaint(hOffset, vOffset: LONGINT); BEGIN OffsetLRect(hLRect, hOffset, vOffset); PaintLRect(hLRect); END; BEGIN {$IFC fTrace}BP(10);{$ENDC} SetLRect(hLRect, -3, -2, 3, 2); shapeLRect := SELF.shapeLRect; WITH shapeLRect DO BEGIN dh := right - left; dv := bottom - top; MoveHandleAndPaint(left, top); {draw top left handle} END; MoveHandleAndPaint(dh, 0); {then top right} MoveHandleAndPaint(0, dv); {then bottom right} MoveHandleAndPaint(-dh, 0); {finally bottom left} {$IFC fTrace}EP;{$ENDC} END; END; METHODS OF TBoxView; FUNCTION TBoxView.CREATE(object: TObject; itsHeap: THeap; itsPanel: TPanel; itsExtent: LRect) : TBoxView; BEGIN {$IFC fTrace}BP(11);{$ENDC} IF object = NIL THEN object := NewObject(itsHeap, THISCLASS); SELF := TBoxView(itsPanel.NewView(object, itsExtent, TPrintManager.CREATE(NIL, itsHeap), stdMargins, TRUE)); {$IFC fTrace}EP;{$ENDC} END; {This returns the box containing a certain point} FUNCTION TBoxView.BoxWith(LPt: LPoint): TBox; VAR box: TBox; s: TListScanner; BEGIN {$IFC fTrace}BP(11);{$ENDC} boxWith := NIL; s := SELF.boxList.Scanner; WHILE s.Scan(box) DO IF LPtInLRect(LPt, box.shapeLRect) THEN boxWith := box; {$IFC fTrace}EP;{$ENDC} END; {This draws the list of boxes} PROCEDURE TBoxView.Draw; VAR box: TBox; s: TListScanner; BEGIN {$IFC fTrace}BP(10);{$ENDC} s := SELF.boxList.Scanner; WHILE s.Scan(box) DO box.Draw; {$IFC fTrace}EP;{$ENDC} END; PROCEDURE TBoxView.InitBoxList (itsHeap: THeap); VAR box: TBox; boxList: TList; BEGIN {$IFC fTrace}BP(10);{$ENDC} boxList := TList.CREATE(NIL, itsHeap, 0); SELF.boxList := boxList; {create and append the first box} box := TBox.CREATE(NIL, itsHeap); {$H-} SetLRect(box.shapeLRect, 20,20, 100, 100); {$H+} SELF.boxList.InsLast(box); {create and append the second box} box := TBox.CREATE(NIL, itsHeap); {$H-} SetLRect(box.shapeLRect, 200, 100, 300, 130); {$H+} SELF.boxList.InsLast(box); {$IFC fTrace}EP;{$ENDC} END; FUNCTION TBoxView.NoSelection: TSelection; BEGIN {$IFC fTrace}BP(11);{$ENDC} NoSelection := TBoxSelection.CREATE(NIL, SELF.Heap, SELF, nothingKind, zeroLPt); {$IFC fTrace}EP;{$ENDC} END; END; METHODS OF TBoxSelection; FUNCTION TBoxSelection.CREATE(object: TObject; itsHeap: THeap; itsView: TView; itsKind: INTEGER; itsAnchorLPt: LPoint): TBoxSelection; BEGIN {$IFC fTrace}BP(11);{$ENDC} IF object = NIL THEN object := NewObject(itsHeap, THISCLASS); SELF := TBoxSelection(TSelection.CREATE(object, itsHeap, itsView, itsKind, itsAnchorLPt)); SELF.box := NIL; {$IFC fTrace}EP;{$ENDC} END; {This draws the handles on the selected box} PROCEDURE TBoxSelection.Highlight(highTransit: THighTransit); BEGIN {$IFC fTrace}BP(11);{$ENDC} IF SELF.kind <> nothingKind THEN BEGIN thePad.SetPenToHighlight(highTransit); {set the drawing mode according to desired highlighting} SELF.box.PaintHandles; {draw the handles on the box} END; {$IFC fTrace}EP;{$ENDC} END; {This is another way to make a new selection, when the user presses the mouse button} {Just keep the old selection object and replace its data fields with new values. This isn't the} {standard paradigm for creating new selection objects, but it certainly works (at least in this case).} PROCEDURE TBoxSelection.MousePress(mouseLPt: LPoint); VAR boxView: TBoxView; aSelection: TSelection; panel: TPanel; box: TBox; BEGIN {$IFC fTrace}BP(11);{$ENDC} WITH SELF DO BEGIN anchorLPt := mouseLPt; currLPt := mouseLPt; END; boxView := TBoxView(SELF.view); panel := SELF.panel; panel.Highlight(SELF, hOntoOff); {Turn off the old highlighting} box := boxView.BoxWith(mouseLPt); {Find the box the user clicked on} IF box = NIL THEN SELF.kind := nothingKind ELSE SELF.kind := boxSelectionKind; SELF.box := box; panel.Highlight(SELF, hOffToOn); {Turn on the highlighting for the newly selected box} self.MarkChanged; {Allow the document to be saved so that any changes made can become permanent} {$IFC fTrace}EP;{$ENDC} END; {This is called when the user moves the mouse after pressing the button} PROCEDURE TBoxSelection.MouseMove(mouseLPt: LPoint); VAR diffLPt: LPoint; shapeLRect: LRect; PROCEDURE InvalTheBox(invalRect: LRect); BEGIN {$IFC fTrace}BP(11);{$ENDC} InsetLRect(invalRect, -3,-2); {need to expand the invalidation rectangle to invalidate } SELF.panel.InvalLRect(invalRect); {highlighting as well as box} {$IFC fTrace}EP;{$ENDC} END; BEGIN {$IFC fTrace}BP(11);{$ENDC} IF SELF.kind <> nothingKind THEN BEGIN {How far did mouse move?} LPtMinusLPt(mouseLPt, SELF.currLPt, diffLPt); {Move it if delta is nonzero} IF NOT EqualLPt(diffLPt, zeroLPt) THEN BEGIN SELF.currLPt := mouseLPt; shapeLRect := SELF.box.shapeLRect; {Compute old and new positions of box} InvalTheBox(shapeLRect); OffsetLRect(shapeLRect, diffLPt.h, diffLPt.v); InvalTheBox(shapeLRect); SELF.box.shapeLRect := shapeLRect; END END; {$IFC fTrace}EP;{$ENDC} END; END; METHODS OF TBoxProcess; FUNCTION TBoxProcess.CREATE: TBoxProcess; BEGIN {$IFC fTrace}BP(11);{$ENDC} SELF := TBoxProcess(TProcess.CREATE(NewObject(mainHeap, THISCLASS), mainHeap)); {$IFC fTrace}EP;{$ENDC} END; FUNCTION TBoxProcess.NewDocManager(volumePrefix: TFilePath; openAsTool: BOOLEAN): TDocManager; BEGIN {$IFC fTrace}BP(11);{$ENDC} NewDocManager := TBoxDocManager.CREATE(NIL, mainHeap, volumePrefix); {$IFC fTrace}EP;{$ENDC} END; END; METHODS OF TBoxDocManager; FUNCTION TBoxDocManager.CREATE(object: TObject; itsHeap: THeap; itsPathPrefix: TFilePath) : TBoxDocManager; BEGIN {$IFC fTrace}BP(11);{$ENDC} IF object = NIL THEN object := NewObject(itsHeap, THISCLASS); SELF := TBoxDocManager(TDocManager.CREATE(object, itsHeap, itsPathPrefix)); {$IFC fTrace}EP;{$ENDC} END; FUNCTION TBoxDocManager.NewWindow(heap: THeap; wmgrID: TWindowID):TWindow; BEGIN {$IFC fTrace}BP(11);{$ENDC} NewWindow := TBoxWindow.CREATE(NIL, heap, wmgrID); {$IFC fTrace}EP;{$ENDC} END; END; METHODS OF TBoxWindow; FUNCTION TBoxWindow.CREATE(object: TObject; itsHeap: THeap; itsWmgrID: TWindowID): TBoxWindow; BEGIN {$IFC fTrace}BP(10);{$ENDC} IF object = NIL THEN object := NewObject(itsHeap, THISCLASS); SELF := TBoxWindow(TWindow.CREATE(object, itsHeap, itsWmgrID, TRUE)); {$IFC fTrace}EP;{$ENDC} END; PROCEDURE TBoxWindow.BlankStationery; VAR viewLRect: LRect; panel: TPanel; boxView: TBoxView; aSelection: TBoxSelection; BEGIN {$IFC fTrace}BP(10);{$ENDC} panel := TPanel.CREATE(NIL, SELF.Heap, SELF, 0, 0, [aScroll, aSplit], [aScroll, aSplit]); SetLRect(viewLRect, 0, 0, 5000, 3000); boxView := TBoxView.CREATE(NIL, SELF.Heap, panel, viewLRect); boxView.InitBoxList(SELF.Heap); {$IFC fTrace}EP;{$ENDC} END; END;