[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide



Using a DrawingArea in a ScrolledWindow

The ScrolledWindow widget provides a viewport onto a virtual scroll and allows the user to move the scroll with respect to the viewport by manipulating ScrollBars. ScrolledWindow offers two scrolling policies: automatic and application-defined. In automatic scrolling, the application provides the scroll widget; ScrolledWindow creates a fixed-size viewport and handles user interaction with the ScrollBars. In application-defined scrolling, the application provides the scroll widget and, if necessary, the viewport, and it handles all user interaction with the ScrollBars.

When using separate viewport and scroll widgets with either scrolling policy, an application can use a default DrawingArea as the scroll widget. When the XmNresizePolicy is XmRESIZE_ANY, the application can use XtSetValues of XmNx and XmNy to place children within the DrawingArea. The DrawingArea adjusts its size as necessary to enclose all the children. The application can also use XtSetValues of the DrawingArea's XmNwidth and XmNheight to change the size of the scroll widget.

An application can also use a DrawingArea as the viewport widget in application-defined scrolling. One approach is not to use a separate scroll widget but to maintain a virtual scroll, keeping the contents in internal data structures and displaying as much of the contents as will fit into the viewport. The application can use a default DrawingArea as the viewport widget.

Another approach to application-defined scrolling is to create one widget as a viewport and another, a child of the viewport, as the scroll. The application can expand the scroll widget as necessary to contain all the data. In response to user manipulation of the ScrollBars, the application can reposition the scroll widget with respect to the viewport. The viewport acts as a clipping region for its child, the scroll.

In this approach the application can use a DrawingArea as the viewport, the scroll widget, or both. When using a DrawingArea as the viewport, the application must position and resize the scroll child by using XtMoveWidget, XtResizeWidget, or XtConfigureWidget. Using XtSetValues for the child's geometry resources does not work because the parent's geometry manager does not permit the child to move or grow beyond the bounds of the parent.

When a DrawingArea is the viewport widget in a ScrolledWindow with application-defined scrolling, the XmNresizeCallback procedure must recompute the ScrollBars' XmNsliderSize and XmNpageIncrement and possibly other resources to reflect the new relation between the viewport and the scroll. It may also need to reposition and resize the scroll with respect to the viewport.

See Chapter 8 for more information on ScrolledWindow, including examples using DrawingAreas as scrolls in both automatic and application-defined scrolling.


[ Previous | Next | Contents | Glossary | Home | Search ]