Scrolling the Word-processing View
This section describes how to handle scrolling in your word-processing views. You must first set up your scrollers. The TXWord program uses theSetupScrollers
method for this purpose. This method, which is shown in Listing 3-3, is called after the editor view and scroll arrows have been created.Listing 3-3 The SetScrollers method
The *SetupScrollers:
func() begin scroller.scrollview:= editor; scroller.viewRect := editor:GetScrollableRect(); // note: GetScrollableRect returns the scroll area in // global coordinate values, omitting the ruler area local visualArea := :GetScrollableRect(); scroller.viewRect := clone(:LocalBox()); scroller.viewRect.bottom:= visualArea.bottom - visualArea.top; scroller.scrollRec:= RelBounds(0,0, scroller.viewRect.right, :GetTotalHeight()); end,
protoTXView:*ViewUpdateScrollersScript
method is called when something happens that might affect the the scroll arrows; for example, if more text is added, which causes the maximum height or thumb position to change. The TXWord version of this method is shown in Listing 3-4.Listing 3-4 The TXWord *
ViewUpdateScrollersScript
method
The TXWord implementation of *ViewUpdateScrollersScript:
func(updateMaxValue, scrolled) begin if updateMaxValue then begin // use editor's GetTextHeight method to get the height scroller.scrollRect.bottom := :GetTextHeight(); scroller.dataRect := scroller.scrollRect; end; if scrolled then scroller.yPos := :GetScrollValues().y; if call kViewIsOpenFunc with (scroller) then scroller:AdjustArrows(); end,
ViewUpdateScrollersScript
calls a local method,GetTextHeight
, to return the actual text height in the view. Although TXWord uses a non-paged word-processing view, theGetTextHeight
method is included to illustrate how you would implement scrolling in a non-paged word-processing view.You need to use a method such as
GetTextHeight
if you are implementing a read-write, non-paged view.
When the user adds text to such a view, the new text can appear outside of the view's text region. To get around this, you typically create the view with an arbitrarily large height and write a function such as
- Note
- Recall that when you initialize a read-write, non-paged view, you need to specify the text height as your view height in your call to the *
SetGeometry
method.![]()
GetTextHeight
to return the actual text height. TheTXWord:GetTextHeight
method is shown in Listing 3-5.
The
- Note
- You do not need to be concerned with this situation if your word-processing view is a read-only view, because the text height never changes in such a view.
![]()
GetTextHeight
method returns the actual text height in the view. This method is not required if your word-processing view is paged, because paged views automatically adjust their height as the user adds text.Listing 3-5 The TXWord
GetTextHeight
method
TheGetTextHeight:
func() begin local chars := :GetCountCharacters(); local maxInfo:= :CharToPoint(chars); local globalY:= maxInfo.y + maxInfo.lineHeight; // take the scroll position into consideration... globalY := globalY + :GetScrollValues().y; return globalY - ourGlobalBoxTopCoordinate; end,
GetTextHeight
method uses an application variable,ourGlobalBoxTopCoordinate
, in its computation of the text height. This value is set in theViewSetupFormScript
method.The final scrolling method,
ViewScroll2DScript
, method is called when the user taps the scroll arrows. You only need to implement this method if you are using theprotoXXXScroller
methods. The TXWord version of this method is shown in Listing 3-6.Listing 3-6 The TXWord
ViewScroll2DScript
method
ViewScroll2DScript: func(direction, extras) begin if direction = 'up then :Scroll({x:0, y: - kScrollDist}); else // direction = 'down :Scroll({x:0, y: kScrollDist }); scroller.yPos := :GetScrollValues().y; if call kViewIsOpenFunc with (scroller) then scroller:AdjustArrows();// this is a protoXXXScroller method RefreshViews(); end,The TXWord implementation of
ViewScroll2DScript
scrolls the view up or down and then calls theRefreshViews
function to redraw the view.
- Note
- The call to the
RefreshViews
function in Listing 3-6 is required for the scroller to update. The *protoTXView
automatically updates whenever it receives a scroll message.![]()
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help