[comp.windows.x] Observation of scroll bar behavior in XmScrolledWindow

paul@tredysvr.Tredydev.Unisys.COM (Paul Siu) (01/16/91)

While playing around with the XmScrolledWindow widget, and the XmText widget,
I discover that while there are many ways to create a text window with scroll-
bars, there are really only 3 main methods:

   1) By setting XmNscrollHorizontal and XmNscrollVertical resource in the
      XmText widget to TRUE.
   2) By setting XmNscrollingPolicy resource in the XmScrolledWindow widget to
      XmAUTOMATIC.
   3) By setting XmNscrollingPolicy resource in the XmScrolledWindow widget to
      XmAPPLICATION_DEFINED.

Before one discuss the three method, let's look at the XmText widget and the
XmScrolledWindow widget.  The XmScrolledWindow widget is a manager widget that
provides containment for a work area widget, a horizontal scroll-bar, and a
vertical scroll-bar.  The work area widget is often a text widget, but can be
XmDrawingArea widget or other kinds of display widget.  We'll limit the
discussion on the text widget.

Look up XmScrolledWindow's description in the Motif Programmer's Reference,
and it will tell you that there are basically two method to control the
scroll-bars.  The manual will also tell you to create a text widget, and
scroll-bar widget, then use XmScrolledWindowSetArea or use XtSetValues to add
the widgets to the scrolled window.  You'll find later that this is only
necessary only for method #3.

One important item that the manual does not tell you is that the text, and
scroll-bar widgets must be first created as the children of the scrolled
window.  Failure to do so will leave you with a text widget that is display,
but cannot accept input or output.

Let's now go to method #3.  We first create the scrolled window widget, then
the text and scroll-bar widget as the scrolled window's children.  We then
use the routine XmScrolledWindowSetAreas to attach the text, and scroll-bars
to the scrolled window.  The scrolled window's scrolling policy automatically
defaults to XmAPPLICATION_DEFINED any way, so you don't have to set it.

Method #3's scroll-bar have no direct connection to your text widget.  It will
not adjust the widget for you as you add text, nor will it scroll the text
when you use the scroll-bar's control.  You must write callback routines so
the application itself can control them.  I do not know how to do this, so I
can't help you there.  I think an example is in Douglas Young's book, but it's
on drawing areas, not text widgets.

Method #2 does not require you to create two scroll bars because the text
widget automatically create them for you.  You must set the XmNscrollingPolicy
to Xm_AUTOMATIC at the scrolled window's creation either by argument list, or
by resource file.  You must do this at creation time because you cannot set it
with XtSetValues later.  You do not need to use XmScrolledWindowSetAreas to
attach the text widget because it attaches it automatically.

The two scroll-bar is supposed to automatically managed the text widget,
unfortunately, it doesn't work as well as it should.  When you type past the
edge of the screen, the text entry will continue, but it will not scroll the
screen automatically for you, so you end up typing blind.  If you set the
text widget resource XmNwordWrap, the text widget will handle automatic word
breaks.  The biggest problem with method #2 is the scroll-bars.  When you
scroll past your screen, you'll get mysterious patches of gray areas that turn
black when you click on them.  I have no idea why, but typing in the areas can
crash the entire server!

Method #1 is not mentioned in the reference manual under scrolled window, but
is listed under XmText.  Like the other method #2, you create a scrolled
window widget, and a text widget as a children of scrolled window.  You set the
text widget's XmNscrollHorizontal and XmNscrollVertical to TRUE at the time of
the text widget's creation either by passing arguments or using resource files
(Actually, you do not need to set the two resources, they default to true as
long as you do not use set XmNscrollPolicy to XmAUTOMATIC.).  Two scroll-bars
will automatically be created, and managed automatically.  You do not need to
call XmScrolledWindowSetAreas(), and in fact you shouldn't.

Scroll-bars from method #1 behaves differently than method #2.  When you type
past the edge of the screen, it will automatically scroll so you can keep the
cursor in view.  Word wrap does not work no matter what you set the resource
XmNwordWrap to.  While word wrap does not work, you don't get strange gray
patches that crash your server like method #2 does.  This method is used when
you call XmCreateScrolledText().

Well, here's my two cents worth any way.  If there's anyone on the net that
has information about scrolling windows, and text widgets, please e-mail it
to me.  I am still a bit frustrated by it.

Paul Siu
paul@tredysvr.tredydev.unisys.com