EZwgl clients may define private widget resources. Like application resources, the application writer must provide a conversion mechanism to translate private widget resources from string to their actual types.
In the next example, we use resource to select a callback procedure for a button.
#include "EZ.h"
static void sayHi(EZ_Widget *widget, void *data)
{ printf("Hello, there\n"); }
static void sayBye(EZ_Widget *widget, void *data)
{ printf("Goodbye!\n"); }
main(int ac, char **av)
{
EZ_Widget *btn;
EZ_Initialize(ac, av, 0);
btn = EZ_CreateWidgetXrm(EZ_WIDGET_NORMAL_BUTTON, NULL,
"Btn", "btn",
EZ_LABEL_STRING, "The callbacks of this button\nis set by Resource",
0);
/* select callback from resources */
{
char *value;
if(EZ_GetWidgetResource(btn, "callback", &value))
{
if(!strncmp(value, "hi",2)) EZ_AddWidgetCallBack(btn, EZ_CALLBACK, sayHi, NULL, 0);
else if(!strncmp(value, "bye",3)) EZ_AddWidgetCallBack(btn, EZ_CALLBACK, sayBye, NULL, 0);
}
}
EZ_DisplayWidget(btn);
EZ_EventMainLoop();
}