A scrolled list is a CwList widget with scrolling
capability. All resources and callbacks associated with lists can be
applied to scrolled lists. The scrolling mechanism is handled
automatically.
Creating a scrolled list inserts a CwScrolledWindow parent between the list and the receiver of the creation message. In other words, createScrolledList:argBlock: returns an instance of CwList (the child of a CwScrolledWindow); however, the CwScrolledWindow is the child of the form. Form attachment messages must therefore be sent to the CwList's parent.
In the following example, a scrolled list widget is created as a child of a form. The list selection policy is set to XmSINGLESELECT. A singleSelection callback is added, corresponding to the selection policy.
| items shell form list | items := OrderedCollection new. "20 items are initialized as the list contents." 1 to: 20 do: [:i | items add: 'Item ', i printString].
shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: [:w | w title: 'Scrolled List Example'].
form := shell createForm: 'form' argBlock: nil. form manageChild.
list := form "Create the scrolled list. The list widget is answered, not the scrolled window." createScrolledList: 'list' argBlock: [:w | w "Set the scrolling policy to single selection, the number of visible items to one-half of the number of items, and the list's items to items." selectionPolicy: XmSINGLESELECT; visibleItemCount: items size // 2; items: items].
list addCallback: XmNsingleSelectionCallback receiver: self selector: #singleSelect:clientData:callData: clientData: nil. list manageChild.
"Note that the attachments are set on the parent of the list (which is a CwScrolledWindow). The scrolled window is the child of the form, not the list widget." list parent setValuesBlock: [:w | w topAttachment: XmATTACHFORM; topOffset: 10; bottomAttachment: XmATTACHFORM; bottomOffset: 10; leftAttachment: XmATTACHFORM; leftOffset: 10; rightAttachment: XmATTACHFORM; rightOffset: 10]. shell realizeWidget