Bind to a variable :
The idea is to link a selectable object to a variable: when the user selects or unselects this object, the variable binded is automatically updated. There are two cases :
int radio_choice = RADIO1; /* a global variable */
ObjcAttach( OC_FORM, win, RADIO1, BIND_VAR, & radio_choice, 0);
ObjcAttach( OC_FORM, win, RADIO2, BIND_VAR, & radio_choice, 0);
ObjcAttach( OC_FORM, win, RADIO3, BIND_VAR, & radio_choice, 0);
ObjcAttach( OC_FORM, win, RADIO4, BIND_VAR, & radio_choice, 0);
int but1_state = 0; /* 1 if the BUT1 object is selected */
ObjcAttach( OC_FORM, win, BUT1, BIND_VAR, & but1_state, 0);
It is possible to attribute a variable to a specific bit
(because bit field are often used to represent several options)
:
int options = 0x1; /* means the BUT1 object is selected */
/* Attach to bit 0 of options */
ObjcAttach( OC_FORM, win, BUT1, BIND_BIT, & options, 0x1);
/* Attach to bit 1 of options */
ObjcAttach( OC_FORM, win, BUT2, BIND_BIT, & options, 0x2);
If the simple SELECTABLE objects represent the value of a variable, the EXIT or TOUCHEXIT objects often require a complex operation. For example, the OK button closes the form or the SAVE button save the parameters. For that purpose, these objects may be linked to a function. If the user selects these objects, the binded function is invoked. Thus, it is not neccessary to write a WM_FORM event function to handle a form. Example :
/* This function unselected the selected objet and
* close the window. A binded object function has the
* following prototype:
* void Func( WINDOW *win, // window descriptor
* int index, // index of the selected object
* int type); // OC_FORM or OC_TOOLBAR
*/
void OkBut( WINDOW *win, int index, int type) {
ObjcChange( type, win, index, NORMAL, 1);
ApplWrite( app.id, WM_CLOSED, win->handle);
}
ObjcAttach( OC_FORM, win, OK_BUT, BIND_FUNC, OkBut);