The application-drawn list widget (EwDrawnList) allows an
application to draw arbitrary graphics to represent each object in the
list. It combines list behavior with a drawing area-based
widget. Following is an example of a drawn list widget:
An application hooks the displayCallback to draw the items in the list. If the items in the list have different sizes, an application should hook the measureCallback to specify the height of each individual item in the list. If all items have the same height, the itemHeight resource can be used to specify the height in pixels.
The applicationDrawnStates resource allows for the specification of visuals for any of the emphasis states in the list, such as selection emphasis or cursored emphasis. Applications can choose to allow the drawn list to provide these emphasis visuals. In the following code, a list of CgFontStructs is added to a drawn list, and each font name in the list is drawn with the font that it describes.
Object subclass: #DrawnListExample instanceVariableNames: 'fontStructs' classVariableNames: " poolDictionaries: 'CgConstants CwConstants EwConstants'
open | shell drawnList | shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: [:w | w title: 'Drawn List Example']. fontStructs := ((CgDisplay default listFonts: '*' maxnames: 100) collect: [:fontName | CgDisplay default loadQueryFont: fontName]) asOrderedCollection.
drawnList := shell createScrolledDrawnList: 'drawnList' argBlock: [ :w | w items: fontStructs]. drawnList addCallback: XmNdisplayCallback receiver: self selector: #display:clientData:callData: clientData: nil;
addCallback: XmNmeasureCallback receiver: self selector: #measure:clientData:callData: clientData: nil; addCallback: XmNdestroyCallback receiver: self selector: #destroy:clientData:callData: clientData: nil. drawnList manageChild. shell realizeWidget.
display: widget clientData: clientData callData: callData "Display the fontStruct by drawing its font name in the upper left-hand corner of the specified rectangle, using the fontStruct as the font."
| fontStruct | fontStruct := callData object. callData gc setFont: fontStruct font. callData drawable drawString: callData gc x: callData x y: callData y + fontStruct ascent string: fontStruct name
measure: widget clientData: clientData callData: callData "Measure the fontStruct by querying its height." | fontStruct | fontStruct := callData object. callData height: fontStruct height
destroy: widget clientData: clientData callData: callData "Destroy the fontStruct collection." fontStructs do: [:fontStruct | fontStruct freeFont].