Application-drawn buttons
Application-drawn button widgets (CwDrawnButton) enable the application to draw arbitrary graphics on a button. Drawn buttons behave like push buttons except that they can be drawn on like drawing area widgets. See the example below.

Application-drawn buttons
As with the push-button widget, the application can add an activate callback to be run when the button is pressed. As with the drawing area widget, expose and resize callbacks can be added to notify the application when the button requires redrawing and when it has changed size. Consult "Drawing operations" chapter for more information on drawing graphics.
In the code below, a drawn button is created and drawn.
Object subclass: #DrawnButtonExample
instanceVariableNames: 'gc '
classVariableNames: ''
poolDictionaries: 'CwConstants CgConstants '
open
| shell button |
shell := CwTopLevelShell
createApplicationShell: 'shell'
argBlock: [:w | w title: 'Drawn Button Example'].
button := shell
createDrawnButton: 'button'
argBlock: nil.
button
addCallback: XmNactivateCallback
receiver: self
selector: #button:clientData:callData:
clientData: nil;
addCallback: XmNexposeCallback
receiver: self
selector: #expose:clientData:callData:
clientData: nil;
addCallback: XmNdestroyCallback
receiver: self
selector: #destroy:clientData:callData:
clientData: nil.
button manageChild.
shell realizeWidget.
gc := button window
createGC: None
values: nil.
activate: widget clientData: clientData callData: callData
"The drawn button has been pressed."
Transcript cr; show: 'The pixmap button has been pressed.'.
expose: widget clientData: clientData callData: callData
"The drawn button has been exposed. Redraw the button."
| x |
callData event count = 0
ifTrue: [
0 to: 10 do: [:i |
x := widget width * i // 10.
widget window
drawLine: gc
x1: x
y1: 0
x2: widget width - x
y2: widget height - 1]].
destroy: widget clientData: clientData callData: callData
gc freeGC.
Last modified date: 12/21/2017