5.4 Object Callback Functions

Functions which are declared as object callback functions in the dialog descriptions, have to be declared in C as follows:

DM_Boolean DML_default DM_CALLBACK Functionname
(
  DM_CallBackArgs *data
)

if the function in the dialog script is defined as

function callback Functionname() for Events;

or as

DM_Boolean DML_c DM_CALLBACK Functionname
(
  DM_CallBackArgs *data
)

if the function in the dialog script is defined as

function c callback Functionname() for Events;

The parameter of this function is already fixed by DM and cannot be changed. This function is always called, if an event indicated with the function has occurred at the corresponding object.

The return value TRUE here means that rules are to be processed normally after having called this function; the return value FALSE prevents such a rule processing.

Example

The definition of a callback function in the dialog script is as follows:

function callback CheckFilename() for deselect, modified;

The object is assigned at the relevant object:

child edittext File

{

  .xleft 14;

  .ytop 0;

  .width 20;

  .function CheckFilename;

  .content "list.dlg";

}

The following function is to check whether the user input represents a valid file name.

DM_Boolean DML_default DM_CALLBACK CheckFilename __1(

(DM_CallBackArgs *, data))

{

  DM_Value value;            /* structure for DM_SetValue */

  FILE *fptr;                /* file pointer */

  DM_ID id;                /* Identifier of object */

 

 

  /* get the current content */

  if (DM_GetValue(data->object, AT_content, 0,

    &value, DMF_GetLocalString))

    /* check the datatype */

    if(value.type == DT_string)

    {

      /* try to open the file */

      if(!((fptr = fopen(value.value.string, "r"))))

      {

        /*

         * the file can not be opened for reading.

         * activate the edittext again

         */

        value.type = DT_boolean;

        value.value.boolean = TRUE;

        DM_SetValue(data->object, AT_active, 0, &value,

            DMF_Inhibit);

/*

         * The file cannot be read. So don't continue

         * processing with the rules

         */

        return (FALSE);

      }

      else

        fclose(fptr);

 

        /*

         * Everything is ok. So let the rule be

         * processed normally

         */

        return(TRUE);

    }

 

    /* To many errors don't continue the rule processing */

    return (FALSE);

}