Smart CODE
Your on-line guide to the generated code

NAME
UserCallbackProc - Get/Set Smart Code Stubs

INTRODUCTION
If you are using Get/Set Smart Code (for toolkit-independant programming), you do not write code into the X-Designer stubs file. Each tookit needs its own stubs (and its own stubs file).

For Smart Code, the callback in the X-Designer stubs file will be preconfigured to callout to this UserCallbackProc. If you are developing in Motif and MFC in C++, the same callout routine will be called by both sets of callbacks. Where a new toolkit requires a different language (eg the AWT requires Java), the Smart Code API is designed so that migration from one language to another is a cosmetic exercise.

When the routine is called, you have access to a data object containing all the elements in the group associated with the callback. This group data object can be used to access and modify the values of any control in the group, without the need for programming with the Motif, MFC or Java AWT API.

In C, the callout is a routine. Smart Code data is passed in as arguments. In C++ and Java the callout is a class, a subclass of the Smart Code Data class. Its doit() method is called, and Smart Code data is accessed through getter methods, for example getGroup() and getPollInterval().

SYNOPSIS

C


typedef void (*UserCallbackProc)( sc_data_t *, GROUPNAME_t*, void *)
	sc_data_t * data;
	GROUPNAME_t* group;
	void* client_data;
C++

class METHODNAME_user: public sc_data_c
{
	void doit() {
		GROUPNAME_c * g = (GROUPNAME_c *)getGroup();
	}
};

sc_data_c *
getNew_METHODNAME()
{
	return (sc_data_c*) new METHODNAME_user;
}
Java

public class METHODNAME_user extends SCData
{
	public void doit() {
		GROUPNAME_c g = (GROUPNAME_c)getGroup();
	}

	public static METHODNAME_user getNew()
	{
		return  new METHODNAME_user();
	}
}

Inputs
This routine has access to the SmartCode data structure, the group, and client data, where provided by the user. In the C version, all three are arguments to the function. In C++ and Java, the class is a subclass of the SmartCode data class, and is the instance of the data class. Client data and the group are available through getter methods.

Other Notes
In C, you write your code inside the stub function. In C++ and Java, the stub doit() method will be called, but the entire class is available for you to reprogram.

GROUPNAME and METHODNAME will be replaced in the generated code by the name you have given to your group, and your callback method.

DESCRIPTION

USAGE
The Get/Set Smart Code callout is a toolkit-independent replacement for raw toolkit callbacks. It is intended to be programmed directly with application code. The following examples show how the same processing code is written in C, C++ and in Java.

EXAMPLES
Toolkit-Independent Programming example
LanguageUsage
C

void
doit_callback_user (sc_data_t * d, mygroup_t* g, void* client_data)
{
	int ix  = SC_GET(SelectionByIndex,g->optionMenu1);
	int val = SC_GET(State,g->toggle1);

	if (ix == val)
		SC_SET(Value,g->text1, "ok");
	else {
		SC_SET(Value,g->text1, "Changed!!");
		SC_SET(SelectionByIndex,g->optionMenu1,val);
	}
}
C++

class doit_method: public sc_data_c
{
	void doit() {
		mygroup_c * g = (mygroup_c*) getGroup();
		int ix  = g->optionMenu1->getSelectionByIndex();
		int val = g->toggle1->getState();

		if (ix == val)
			g->text1->setValue("ok");
		else {
			g->text1->setValue("Changed!!");
			g->optionMenu1->setSelectionByIndex( val);
		}
	}
};
Java

public class doit_method extends SCData
{
	public void doit() {
		mygroup_c g = (mygroup_c) getGroup();
		int ix   = g.optionMenu1.getSelectionByIndex();
		boolean togval = g.toggle1.getState();
		int val = 0;

		if (togval)
			val = 1;

		if (ix == val)
			g.text1.setValue("ok");
		else {
			g.text1.setValue("Changed!!");
			g.optionMenu1.setSelectionByIndex( val);
		}
	}
}

SEE ALSO