5.5 Reloading Functions

Functions which are declared as reloading functions in the dialog description have to be declared in C as follows:

DM_Boolean DML_default DM_CALLBACK Functionname
(
  DM_ContentArgs *data
)

if the function is defined in the dialog script as follows

function contentfunc Functionname();

or as

DM_Boolean DML_c DM_CALLBACK Functionname
(
  DM_ContentArgs *data
)

if the function is defined in the dialog script as

function c contentfunc Functionname ();

The parameter of this function is already fixed by Dialog Manager and cannot be changed. This function is called whenever the tablefield, which has defined this function as reloading function, has been scrolled to an area in which contents in DM is no longer available and therefore the contents has to be reloaded again by the application.

Example

In the dialog a reloading function is defined as follows:

!! Fills up the tablefield on scrolling

!! if it becomes necessary

function contentfunc CONTENT();

This function is then linked to a tablefield

child tablefield T1

{

  .visible true;

  .xauto 0;

  .xleft 1;

  .xright 1;

  .yauto 0;

  .ytop 0;

  .ybottom 1;

  .posraster true;

  .sizeraster true;

  .fieldfocusable false;

  .fieldshadow false;

  .contentfunc CONTENT;

  .edittext null;

  .selection[sel_row] true;

  .selection[sel_header] false;

  .selection[sel_single] false;

  .colcount 3;

  .rowcount 30;

  .rowheadshadow true;

  .rowheader 1;

  .colfirst 1;

  .rowfirst 2;

  .colwidth[0] 12;

  .rowheight[0] 1;

  .rowlinewidth[0] 1;

  .rowlinewidth[1] 3;

  .sensitive[1,1] false;

  .content[1,1] "Name";

  .sensitive[1,2] false;

  .content[1,2] "Vorname";

  .sensitive[1,3] false;

  .content[1,3] "Wohnort";

  .xraster 10;

  .yraster 16;

}

The realization of the function C then is as follows:

/*

** Function to fill up the tablefield dynamically

** on scrolling, if rows are reached

** which have not been filled yet.

*/

 

void DML_default DM_CALLBACK CONTENT __1(

(DM_ContentArgs *, args))

{

  int i;

  int spos;

  int vpos;

  int length;

  FILE *f ;

 

  char ** strvec;

  char * buffer;

  char * start;

  char * end;

 

  DM_VectorValue vector;

  DM_Value startIdx;

  DM_Value endIdx;

 

  /*

  ** Opening file from which the tablefield content

  ** is to be read.

  */

  if (!(f = fopen("bsp.dat","r")))

  {

    DM_TraceMessage("Cannot open In-File", DMF_LogFile);

    return;

  }

  /*

  ** Allocation of memory to be able to store

  ** the rows already read before assigning it to the object.

  ** temporarily To do so, the DM_functions are used.

  */

  strvec  = (char **) DM_Malloc ( (CONT_ROWS * COLUMNS)

        * sizeof (char*) );

  buffer  = (char *) DM_Malloc (STR_LEN * sizeof (char) );

 

  /*

  ** first tablefield row to be filled

  */

  startIdx.type = DT_index;

  startIdx.value.index.first = args->loadfirst - 1;

  startIdx.value.index.second = 1;

  /*

  ** first tablefield row to be filled

  */

  endIdx.type = DT_index;

  endIdx.value.index.first = startIdx.value.index.first +

        (ushort) CONT_ROWS - 1;

  endIdx.value.index.second = COLUMNS;

 

  vector.type = DT_string;

  vector.vector.stringPtr = strvec;

 

  spos = 0;

  vpos = 0;

 

  /*

  ** Reading in the file to the buffer.

  ** In doing so, after every blank a new element

  ** in the tablefield is started.

  */

  while ( !feof(f) && (spos++ < CONT_ROWS) )

  {

    if (fgets(buffer ,STR_LEN-1, f))

    {

      i = 0;

      end = buffer;

 

      while (*end && isspace(*end))

        end++;

 

      while (*end && (i++ < COLUMNS))

      {

        start = end;

        length = 1;

 

        while (*end && !isspace(*end))

        {

          length++;

          end++;

        }

        if (*end)

          *end++ = '\0';

        strvec[vpos]=(char *) DM_Malloc( (lenght+1) *

            sizeof(char));

        strcpy(strvec[vpos],start);

        vpos++;

        while(*end && isspace(*end))

          end++;

      }

 

        while (i++ < COLUMNS)

      {

        strvec[vpos] = (char *) DM_Malloc(sizeof(char));

        strvec[vpos++]="\0";

      }

    }

  }

  /*

  ** Setting the number of valid entries in the vector.

  */

  vector.count = (ushort) vpos;

 

  /*

  ** Assigning the established vector to the tablefield.

  */

  DM_SetVectorValue(args->object, AT_field,

        &startIdx, &endIdx, &vector, 0);

 

  /*

  ** Releasing memory which has been allocated

  ** in this function.

  */

  while (--vpos >= 0 )

    DM_Free(strvec[vpos]);

  DM_Free(strvec);

  DM_Free(buffer);

 

}