## 3.2 Adding Private Widget Resources

You can add private widget resources to one widget or to all widgets of a given type, e.g frames. For this you need

- a list of resource names and their value types, and

- a configuration procedure specifies how the resources will be used.

The resource specification is of the following type.

    typedef struct {
      int     option;     /* referenced in configure, must >1024 */
      char    *iname;     /* instance name */
      char    *cname;     /* class name, may be NULL */
      char    *vtypes;    /* value type, e.g  "float, float" */
    } EZ_ResourceSpec;

A list of resources looks like the next example.

    #define COUNTER_INIT_VALUE   1025
    #define COUNTER_INCREMENT    1026
    #define COUNTER_TEST         1027
    EZ_ResourceSpec counterResources[] =
    {
      {COUNTER_INIT_VALUE,  "initValue", "InitValue", "int"},
      {COUNTER_INCREMENT,   "increment", "Increment", "int"},
      {COUNTER_TEST,        "test",      "Test",      "int,float,string,pointer,int"},
    };

The configuration procedure has the prototype

       int (*configure)(EZ_Widget *widget,int opt, EZ_Value *values);

and here is a sample procedure.

    int counterConfigure(EZ_Widget *widget, int opt, EZ_Value *values)
    {
      switch(opt)
       {
        case COUNTER_INIT_VALUE:
          {
            int i = values[0].value.i;
            ez_SetCounter(widget, i);
          }
         break;
        case COUNTER_INCREMENT:
          {
            int i = values[0].value.i;
            ez_counter *ptr = (ez_counter *)EZ_GetWidgetPtrData(widget);
            ptr->increment1 = i;
          }
         break;
        case COUNTER_TEST:
          {
            int   i = values[0].value.i;
            char  c = values[1].value.c;
            float f = values[2].value.f;
            char *str = value[3].value.p;  /* have to copy in real applications */
            fprintf(stderr, "%d, %c,%f, %s\n", i, c, f, str);
          }
         break;
        default:
         break;
     }
    }

The command responsible for registering resources to all widgets of a given type is

    void EZ_RegisterResourcesAll(int widget_type, int nresrc, EZ_ResourceSpec *resources,
             int (*configure)(EZ_Widget *widget, int opt, EZ_Value *values) );

To register resources for a single widget, use the configuration option `EZ_RESOURCES_HANDLE` in `EZ_CreateWidget`. For example,

     counter = EZ_CreateWidget(Counter_TYPE,
               EZ_RESOURCES_HANDLE, 3, counterResources, counterConfigure,
               COUNTER_INIT_VALUE, 10,
               0);

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