Programmer Reference : Common Widgets : Button and label widgets : Icon and pixmap label and button widgets
Icon and pixmap label and button widgets
The contents of CwLabel, CwPushButton,CwCascadeButton, and CwToggleButton widgets can be a string, an icon or a pixmap.

Label and button
When the labelType resource is XmSTRING, the labelString resource specifies the string to display. The default type is string. When labelType is XmICON, labelIcon specifies the icon to use, and when labelType is XmPIXMAP, labelPixmap specifies the pixmap to display. Consult "Using pixmaps" for more information on using pixmaps and icons.
The code below creates a widget tree containing a pixmap button. Icon buttons and labels are created in a similar manner. Note that pixmap is an instance variable.
| shell button questionMark pixmap |
shell := CwTopLevelShell
createApplicationShell: 'shell'
argBlock: [:w | w title: 'Pixmap Button Example'].
button := shell
"Create the push button."
createPushButton: 'button'
argBlock: nil.
button
addCallback: XmNdestroyCallback
receiver: self
selector: #destroy:clientData:callData:
clientData: nil.
questionMark :=
"Initialize the data for the pixmap."
#(0 0 0 0 255 0 192 255 3 224 255 7
240 255 15 248 255 31 248 255 31 252 255 63
252 227 63 252 193 63 252 193 63 252 193 63
248 224 63 248 240 31 0 248 31 0 252 15
0 252 7 0 254 3 0 254 3 0 254 1
0 254 1 0 252 0 0 252 0 0 0 0
0 252 0 0 254 1 0 254 1 0 254 1
0 254 1 0 252 0 0 0 0 0 0 0).
"Realize the shell without mapping it so we have access to the
button's window and palette without making the shell appear."
shell
mappedWhenManaged: false;
realizeWidget.
pixmap := button screen rootWindow
"Create the pixmap. Note that the background color of the pixmap will be
the same as the button's background color."
createPixmapFromBitmapData: questionMark
width: 24
height: 32
fg: button window blackPixel
bg: (button window getPalette
nearestPixelValue: button backgroundColor)
depth: button depth.
button
setValuesBlock: [:w |
w
"Complete the button's initialization."
labelType: XmPIXMAP;
labelPixmap: pixmap].
button manageChild.
shell mapWidget.
destroy: widget clientData: clientData callData: callData
pixmap freePixmap.
Last modified date: 12/21/2017