Two example extended widgets are provided in the next two sections. The first, below, is a subclass of CwExtendedPrimitive, and the second, on page Example: a composite extended widget, is a subclass of CwExtendedComposite. The prefix 'Cew' is used to differentiate these new widgets from basic widgets. For simplicity, the examples do not include robust error-checking, nor does each widget provide a complete set of resources.The CewEntryField widget, shown below, has a label on the left and a text box on the right. It allows a user to enter text into its text box, and it invokes a valueChanged callback if a new value is present when the user either hits the tab key or clicks on a different widget.The extended widget is implemented using a CwForm as the primary widget with CwLabel and CwText children. A losingFocus callback on the CwText enables the widget to test entered data, and possibly call any registered valueChanged callbacks.CwExtendedPrimitive subclass: #CewEntryFieldlabel: resourceValuevalue: resourceValuevalueChangedCallback: resourceValuelabelWidget: aCwLabeltextWidget: aCwTextThe following code creates a CewEntryField instance, sets its name and label resources inside the create argBlock, and hooks a valueChanged callback to it. The new widget is shown in the diagram at the beginning of this section, on page Example: a primitive extended widget.The CewEntryField class can be subclassed to provide a slightly different extended widget by simply overriding one method, as in the following class definition for CewNumericEntryField:CewEntryField subclass: #CewNumericEntryField
|