[comp.sys.amiga.tech] Scroll bars for word-wrapped text?

mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) (11/21/88)

I've got an application that needs to put text in a window - wrapped n
word boundaries, and then allow the user to page back & forth through
the text.

Scroll bars are the obvious solution. But I don't see an easy way to
make them work "right". The problem is the word wrapping - I don't
know how many lines (or characters) will fit in the window until after
I've displayed it. Currently, I just display the text starting where I
left off, and then resize the scroll bar gadget after it's displayed.
This produces some interesting (and predictable) results.

I know there's gotta be a way to do this so the scroll bar works
correctly. Anyone got any suggestions? Or better yet, code?

	Thanx,
	<mike
--
The weather is here, I wish you were beautiful.		Mike Meyer
My thoughts aren't too clear, but don't run away.	mwm@berkeley.edu
My girlfriend's a bore, my job is too dutiful.		ucbvax!mwm
Hell nobody's perfect, would you like to play?		mwm@ucbjade.BITNET

papa@pollux.usc.edu (Marco Papa) (11/21/88)

In article <17286@agate.BERKELEY.EDU> mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) writes:
|I've got an application that needs to put text in a window - wrapped n
|word boundaries, and then allow the user to page back & forth through
|the text.
|Scroll bars are the obvious solution. But I don't see an easy way to
|make them work "right". The problem is the word wrapping - I don't
|know how many lines (or characters) will fit in the window until after
|I've displayed it. Currently, I just display the text starting where I
|left off, and then resize the scroll bar gadget after it's displayed.
|This produces some interesting (and predictable) results.
|
|I know there's gotta be a way to do this so the scroll bar works
|correctly. Anyone got any suggestions? Or better yet, code?

Open the window with the NEWSIZE IDCMP flag and wait for NEWSIZE messages
that inform you that the window has been resized.   Then examine the sizes
in the Window structure and together with font height and width you will be
able to compute how many characters can stay in each line and how many lines
you can use. [I've been using this in the capture buffer window of A-Talk III,
which is GIMMEZEROZERO window. In which case you should look at 
Window-|GZZHeight and Width]

-- Marco Papa 'Doc'
P.S.
Mike, you've been silent for long. Welcome back!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
uucp:...!pollux!papa       BIX:papa       ARPAnet:pollux!papa@oberon.usc.edu
 "There's Alpha, Beta, Gamma and Diga!" -- Leo Schwab [quoting Rick Unland]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) (11/22/88)

In article <13556@oberon.USC.EDU> papa@pollux.usc.edu (Marco Papa) writes:
<Open the window with the NEWSIZE IDCMP flag and wait for NEWSIZE messages
<that inform you that the window has been resized.   Then examine the sizes
<in the Window structure and together with font height and width you will be
<able to compute how many characters can stay in each line and how many lines
<you can use. [I've been using this in the capture buffer window of A-Talk III,
<which is GIMMEZEROZERO window. In which case you should look at 
<Window-|GZZHeight and Width]

I've been doing that. In fact, I had that working perfectly. Until I
added one last feature (which was mentioned in the original article):

<|The problem is the word wrapping - I don't
<|know how many lines (or characters) will fit in the window until after
<|I've displayed it.

Given that I've got the window size in lines & characters, and I want
to display the "end" of the text. Assume I've got four lines to
display. One will wrap to fit perfectly on three display lines, one
fits on one line, leaving most of the display line blank, and the last
one needs two 1/2 lines bcause it breaks a _long_ word onto the next
line, leaving most of the first one blank. Now, for various window
heights (1, 2, ... 7 lines) how do I correctly determine which line to
start the display on? Now resize horizontally to make things
different, and repeat.

	<mike
--
Tell me how d'you get to be				Mike Meyer
As beautiful as that?					mwm@berkeley.edu
How did you get your mind				ucbvax!mwm
To tilt like your hat?					mwm@ucbjade.BITNET

papa@pollux.usc.edu (Marco Papa) (11/22/88)

In article <17332@agate.BERKELEY.EDU| mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) writes:
|I've been doing that. In fact, I had that working perfectly. Until I
|added one last feature (which was mentioned in the original article):
|
|<|The problem is the word wrapping - I don't
|<|know how many lines (or characters) will fit in the window until after
|<|I've displayed it.
|
|Given that I've got the window size in lines & characters, and I want
|to display the "end" of the text. Assume I've got four lines to
|display. One will wrap to fit perfectly on three display lines, one
|fits on one line, leaving most of the display line blank, and the last
|one needs two 1/2 lines bcause it breaks a _long_ word onto the next
|line, leaving most of the first one blank. Now, for various window
|heights (1, 2, ... 7 lines) how do I correctly determine which line to
|start the display on? Now resize horizontally to make things
|different, and repeat.

Sorry I misunderstood your problem.  This has nothing to do with the 
Amiga per se, but is a general problem that has been solved by
a variety of editor writers.    Your best bet is to have either 
Unipress Emacs or Gnu Emacs sources around and take a look at the 
algorithm they use.  Very likely there is more than one way of doing it.

-- Marco Papa 'Doc'
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
uucp:...!pollux!papa       BIX:papa       ARPAnet:pollux!papa@oberon.usc.edu
 "There's Alpha, Beta, Gamma and Diga!" -- Leo Schwab [quoting Rick Unland]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=