Scrolled-window widgets
The scrolled-window widget (CwScrolledWindow) can scroll any other widget by positioning it behind a clipping area. No special processing by the application is required to implement scrolling. Any widget tree can be scrolled simply by making it the work region of a CwScrolledWindow or CwMainWindow widget.
Create a scrolled-window widget by sending the createScrolledWindow:argBlock: message to its parent. Next, create the widget to be scrolled. Make it the work region for the scrolled window by using the setAreas:verticalScrollbar:workRegion: message.
Scrolled-window widgets support two scrolling policies, specified by the scrollingPolicy resource. These are XmAPPLICATIONDEFINED (the default) and XmAUTOMATIC. When the scrolling policy is XmAUTOMATIC, the scrolled window handles all aspects of scrolling, including creation of the scroll bars. The application can be notified of scroll bar movements by adding callbacks.
When the scrolling policy is XmAPPLICATIONDEFINED, the application must handle all aspects of scrolling, including creation of scroll bars. Set the scroll bars using the setAreas:... message.
The scrollBarDisplayPolicy resource defines whether or not scrollbars are always showing (XmSTATIC) or displayed only if the work region exceeds the clip area (XmASNEEDED).
The
scrollingPolicy and
scrollBarDisplayPolicy resources can only be set at creation time.
The following example creates a scrolled window containing several buttons in a vertical row-column. The scrolling policy is XmAUTOMATIC.
| shell scroll buttons |
shell := CwTopLevelShell
createApplicationShell: 'shell'
argBlock: [:w |
w title: 'Scrolled Buttons'].
"Creates a scrolled window with automatic
scrolling policy. The default
scrollBarDisplayPolicy, XmSTATIC, is used."
scroll := shell
createScrolledWindow: 'scroll'
"The default scrollBarDisplayPolicy."
argBlock: [:w | w scrollingPolicy: XmAUTOMATIC].
buttons := scroll
"Creates a row-column that will contain the buttons to be scrolled."
createRowColumn: 'buttons'
argBlock: nil.
buttons manageChild.
(Collection withAllSubclasses collect: :class | class name])
asSortedCollection do: [:name |
(buttons
"Creates the push buttons using the Collection class hierarchy names."
createPushButton: name
argBlock: nil)
manageChild].
"Sets the scrolled-window areas."
scroll
"Only the work region needs to be set."
setAreas: nil
"The scroll bars are created automatically because the scrolling policy
is XmAUTOMATIC."
verticalScrollbar: nil
workRegion: buttons.
scroll manageChild.
shell realizeWidget.
Last modified date: 04/18/2020