
CHAPTER 4: User-Interface Tools Defining behavior with event callbacks and listeners 80
The Build button event handler builds a resource string from the collected values, and returns it from the
dialog invocation function; the script then saves the resource string to a file. That resource string can later
be used to create and display the user-configured alert box.
The resource specification format can also be used to create a single element or container and its child
elements. For instance, if the
alertBuilderResource in the example did not contain the panel
btnPnlResource, you could define that resource separately, then add it to the dialog as follows:
var btnPnlResource =
"btnPnl: Panel { orientation:’row’, \
text: ’Build it’, \
testBtn: Button { text:’Test’ }, \
buildBtn: Button { text:’Build’, properties:{name:’ok’} }, \
cancelBtn: Button { text:’Cancel’, properties:{name:’cancel’} } \
}";
dlg = new Window(alertBuilderResource);
dlg.btnPnl = dlg.add(btnPnlResource);
dlg.show();
Defining behavior with event callbacks and listeners
You must define the behavior of your controls in order for them to respond to user interaction. You can do
this by defining event-handling callback functions as part of the definition of the control or window. To
respond to a specific event, define a handler function for it, and assign a reference to that function in the
corresponding property of the window or control object. Different types of windows and controls respond
to different actions, or events:
X Windows generate events when the user moves or resizes the window. To handle these events, define
callback functions for onMove
, onMoving, onResize, and onResizing. To respond to the user opening
or closing the window, define callback functions for onShow
and onClose.
Kommentare zu diesen Handbüchern