Title Banner

Previous Book Contents Book Index Next

Newton Developer Technical Information: Newton Programmer's Guide: 2.1 OS Addendum /
Chapter 3 - Word Processing Views / Using Word Processing Views


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 the SetupScrollers 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

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,

The *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

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,

The TXWord implementation of *ViewUpdateScrollersScript calls a local method, GetTextHeight, to return the actual text height in the view. Although TXWord uses a non-paged word-processing view, the GetTextHeight 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.

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.
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 GetTextHeight to return the actual text height. The TXWord:GetTextHeight method is shown in Listing 3-5.

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.
The 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

GetTextHeight:

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,

The GetTextHeight method uses an application variable, ourGlobalBoxTopCoordinate, in its computation of the text height. This value is set in the ViewSetupFormScript 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 the protoXXXScroller 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 the RefreshViews 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.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
26 APR 1997



Navigation graphic, see text links

Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help