EZ
Up Prev Next Contents


3.3 Convert Private Resource Values

Resource values are strings. EZwgl can only convert resource values to the four basic data types: int, float, ulong and string. Although pointers can be used as configuration values, they cannot be specified by resources directly. If you need to convert resource values to pointers, you have to provide a convertion mechanism to translate strings to pointers. In the next example, we use resource to select a callback procedure for a button. Since there is only one private resource in this example, we'll extract it directly instead of registering it to the button widget.

#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"); }


static  EZ_ResourceSpec exampleResources[] =
{
   { 1234, "callback",  "Callback", "string"   },
};


int configure(void *widget, int option, EZ_Value *values)
{
  if(option == 1234)
   {
     if(!strncmp(values[0].value.str, "hi",2))
       EZ_AddWidgetCallBack(widget, EZ_CALLBACK, sayHi, NULL, 0);
     else if(!strncmp(values[0].value.str, "bye",3))
       EZ_AddWidgetCallBack(widget, EZ_CALLBACK, sayBye, NULL, 0);
   }
}

main(int ac, char **av)
{
  EZ_Widget *btn;

  EZ_Initialize(ac, av, 0);
  fprintf(stderr, "\nRun with: %s -xrm \"*btn.callback: hi\" \nor\n         %s -xrm \"*btn.callback: bye\"\n", av[0],av[0]);
  
  btn  =   EZ_CreateWidgetXrm(EZ_WIDGET_NORMAL_BUTTON,    NULL,
                              "Btn",               "btn",
                              EZ_LABEL_STRING,     "The callbacks of this button\nis set by Resource",
                              EZ_RESOURCES_HANDLE,  1, exampleResources, configure,
                              0);
  EZ_DisplayWidget(btn);
  EZ_EventMainLoop();
}


Up Prev Next Contents

HTML Documentation Maintainance:Arturo Espinosa <arturo@nuclecu.unam.mx>