Subsections

ScrolledWindow and ScrollBar Widgets

      

We have already seen scrollbars in action with Text (Chapter 10) and List widgets (Chapter 11). More generally, Motif provides a ScrolledWindow widget that allows scrolling of any widget contained within it. This means that we can place a large view area inside a smaller one and then view portions of the view area.

As we have seen, Motif actually provides convenience functions to produce ready made ScrolledText and ScrolledList widgets. These are, in fact, Text or List widgets contained inside a ScrolledWindow widget.

ScrollBars are the basic components of scrolling. A ScrolledWindow widget may contain either, or both of, horizontal and vertical ScrollBars. Many application will typically use ScrollBars. In the majority of instances, ScrollBar widgets will be created automatically by higher level widgets (e.g. ScrolledWindow, ScrolledText or ScrolledList). Occasionally, greater control over the default settings of the ScrollBar will be required. Sometimes, these resources can be set as resources of the higher level widget, other times the resources will need to be set explicitly. In this chapter, we will highlight important ScrollBar resources and illustrate how they can be set in both of the above scenarios.

ScrolledWindow Widgets

 

ScrolledWindow widgets can be created manually with XtVaCreateManagedWidget() , with the xmScrolledWindowWidgetClass  pointer or with XmCreateScrolledWindow()  function.

Associated definitions for this widget class etc. are included in the <Xm/ScrolledW.h> header file.

Useful resources include:

XmNhorizontal, XmNvertical
   -- The identifiers (IDs) of component ScrollBar widgets of the ScrolledWindow. One or both may be present.
XmNscrollingPolicy
  -- Either defined as XmAUTOMATIC or XmAPPLICATION_DEFINED. If the scrolling policy is XmAUTOMATIC then scrolling is taken care of otherwise the application must create and control XmScrollBar widgets itself.
XmNscrolBarDisplayPolicy
  -- Either defined as XmAS_NEEDED or XmSTATIC, as with List Scrolling.
XmNvisualPolicy
  -- Either defined as XmCONSTANT or XmVARIABLE. If constant then scrolled window cannot resize itself.
XmNworkWindow
  -- The widget to be scrolled.

ScrollBar Widgets

 

You may have to create ScrollBars yourself, especially if the scrolling policy is defined as XmAPPLICATION_DEFINED. Alternatively, you may get the ID of a ScrollBar from a ScrolledWindow (e.g. XmNhorizontal resource).

To create a ScrollBar, use XtVaCreateManagedWidget()  with
xmScrollBarWidgetClass  or use XmCreateScrollBar() .

To obtain a horizontal ScrollBar ID from a ScrolledWindow:

   Arg args[1]; /* Arg array */
   int n = 1; /* number arguments */
   Widget scrollwin,scrollbar; 


   scrollwin = XmCreateScrolledWindow(.....)
   ......

   XtSetArg(args[0], XmNhorizontal, &scrollbar);
   XtGetValues(scrollwin, args, n);

Typical ScrollBar resources include:  

XmNsliderSize
  -- A slider may be divided up into unit lengths. This resource sets its size.
XmNmaximum
  -- The largest size (measured in unit lengths) a ScrollBar can have.
XmNminimum
  -- The smallest ScrollBar size.
XmNincrement
  -- The number of unit lengths the Scale will change when moved with mouse.
XmNorientation
  -- XmVERTICAL (Default) or XmHORIZONTAL layout of the widget.
XmNvalue
  -- The current position of the Scale.
XmNpageIncrement
  -- Controls how much the underlying work window moves relative to a ScrollBar movement.

The Callback resources for a ScrollBar  are:

XmNvalueChangedCallback
  -- Called if the ScrollBar value changes.
XmNdecrementCallback, XmNincrementCallBack
   -- Called if the ScrollBar value changes up or down.
XmNdragCallback
  -- Called on continuous Scale value updates.
XmNpageDecrementCallback, XmNpageIncrementCallback
   -- Called on movement of work window.
XmNtoTopCallback, XmNtoBottomCallback
   -- Called if ScrollBar is moved to minimum or maximum values.


Dave Marshall
1/5/1999