Builder Xcessory calls the creation function when it requires a new copy of the resource type editor. To implement the editor creation function, create the widgets that comprise your editor. Builder Xcessory creates any surrounding widgets (such as the XmDialogShell and the OK, Reset, and Dismiss buttons).
Simple editor
In the case of the simple editor, Builder Xcessory does impose some constraints on its size. Builder Xcessory passes any required resource values to the creation function in an Xt resource argument list.
Widget Hierarchy Generated in the Creation Function
The widget hierarchy you generate in the creation function should be a singly-rooted tree. That is, all widgets of your simple or extended resource type editors should descend from a single container.
Creation Function Prototype
The creation function has the following function prototype:
-
Widget EditorCreateFunc(Widget parent, ArgList pargs,
Cardinal pc, XtPointer data)
parent
Parent widget passed to the creation function by Builder Xcessory. Create a container child (for example, a XmForm or XmRowColumn) of parent and build your editor widget hierarchy in that container.
pargs Resource argument list for the widget resource that you apply to the container widget for your editor's hierarchy.
pc Count of the widget resources applied to the container widget for your editor's hierarchy.
If you plan to add any resources yourself, use the XtMergeArgLists function to combine your resource list with that provided by Builder Xcessory.
data Pointer to generic data. You can use data in any way you want. Simply allocate memory and assign the pointer to data. The data pointer is passed to all of the other functions associated with this instance of the type editor.
Once the function finishes building the appropriate widget hierarchy, it returns the top-level container widget that it created.
To highlight the use of the resource type editor creation function, we'll examine the functions for the XmNjustify resource of the XmDumbLabel widget. Source code for all of the justify resource editor functions is in the file {BX}/xcessory/examples/AddEditor.c.
In this case, both the simple and extended editors build the same widget hierarchy. The only difference between the two editors is that the simple editor builds a horizontal radio box, but the extended editor builds a vertical radio box.
Simple Editor Creation Function
The following code is from the simple editor creation function:
- JustifyWidgets *wids = BuildCommonData(data);
- n = 0;
- XtSetArg(args[n],XmNorientation,XmHORIZONTAL);n++;
- margs = XtMergeArgLists(parg, pc, args, n);
- radio = XmCreateRadioBox(parent,"justifyExtBox",margs,
- pc + n);
...Create toggle button gadgets...
- SetRscEditorUpdate(wids->sngl_left,XmNdisarmCallback);
- SetRscEditorUpdate(wids->sngl_cntr,XmNdisarmCallback);
- SetRscEditorUpdate(wids->sngl_right,XmNdisarmCallback);
- XtManageChild(radio);
- return(radio);
- }
This example also shows the use of the simple utility function, SetRscEditorUpdate. When you supply your own Resource Editor entry, Builder Xcessory does not create an automated OK/Cancel button pair to confirm resource settings. One problem with this is that Builder Xcessory updates various internal data when you click OK.
Allowing Builder Xcessory to Update Internal Structures
SetRscEditorUpdate
To allow Builder Xcessory to update its internal structures, you must set a callback for Builder Xcessory to use. Use the function call SetRscEditorUpdate to set a callback for Builder Xcessory to use.
Only use this utility function in the code to create a simple resource type editor. SetRscEditorUpdate is not necessary in an extended editor.
SetRscEditorUpdate function prototype
SetRscEditorUpdate has the following function prototype:
- void SetRscEditorUpdate(Widget wgt, char *callback_name)
wgt Widget whose callback signals Builder Xcessory to update its internal data. For example, if you provide your own OK button, use that button as the wgt parameter.
callback_name
Name of the callback that should be used to signal Builder Xcessory. Builder Xcessory sets a callback function on wgt using the callback list specified by callback_name.