5.9 Format Functions
The format functions have to be defined in the application as follows:
DM_Boolean DML_default DM_CALLBACK Functionname
(
DM_FmtRequest far * req,
DM_FmtFormat far * fmt,
FPTR *fmtPriv,
DM_FmtContent far * cont,
FPTR *contPriv,
DM_FmtDisplay far * dpy
)
The format function is defined in the dialog script as follows:
function formatfunc Functionname;
Parameters
DM_FmtRequest far * req
This parameter passes on the actual task which is taken on by the format function. The task in the element "task" is transferred to this structure.
DM_FmtFormat far * fmt
In this parameter a pointer on format-specific information is passed on.
In this parameter the format function can file format-specific, private data. This data is only known to the application and is thus not considered by Dialog Manager.
DM_FmtContent far * cont
In this parameter a pointer is transferred to a structure in which the actual contents of the field is to be saved. The relevant elements always have to be updated.
FPTR *contPriv
In this parameter contents-specific, private data can be filed by the format function. The contents of this data is only known to the application and is thus not considered by the Dialog Manager.
DM_FmtDisplay far * dpy
In this parameter a pointer is transferred to the structure in which the actual display information is saved. If required, this structure always has to be updated in order for the affiliated edittext in the window system to be displayed correctly.
Example
/* function for special handling of edittext user input */
function formatfunc My_Formatter ();
/* format resource using a format function */
format MyFormat "NN.NN.NN" My_Formatter;
The function is assigned to an input field in the following way:
/* here the date can be entered */
/* the single entered keys are checked by the formatfunc */
child edittext E1
{
.width 10;
.xleft 10;
.ytop 1;
.format MyFormat;
}
This function is realized in C as follows:
DM_Boolean DML_default DM_CALLBACK My_Formatter __6(
(DM_FmtRequest far *, req),
(DM_FmtFormat far *, fmt),
(FPTR *, fmtPriv),
(DM_FmtContent far *, cont),
(FPTR *, contPriv),
(DM_FmtDisplay far *, dpy))
{
DM_Boolean retval;
switch (req->task)
{
/*
** implement a format for inserting a date
** like 'dd.mm.yy'
** there should be some more code for correct handling
** (especially when 'delete' or 'backspace' is pressed)
**
** if the input is less than max
** the input is ok and can be processed
** by the DefaultFormatter
*/
case FMTK_modify:
{
char max = GetMax(dpy);
if ((!req->targs.modify.strlength
&& (dpy->curpos == dpy->length))
|| ((req->targs.modify.strlength == 1)
&& (req->targs.modify.string[0] >= '0')
&& (req->targs.modify.string[0] <= max)))
{
retval = DM_FmtDefaultProc(req, fmt,
(DM_FmtFormatDef **) (FPTR) fmtPriv, cont,
(DM_FmtContentDef **) (FPTR) contPriv, dpy);
}
else
retval = FALSE;
}
break;
default:
/*
** if no special handling is neccessary
** use standard formatter
*/
retval = DM_FmtDefaultProc(req, fmt,
(DM_FmtFormatDef **) (FPTR) fmtPriv,
cont, (DM_FmtContentDef **) (FPTR) contPriv, dpy);
break;
}
return (retval);
}
See Also
Resource format
Chapter “Format Function” in manual “Rule Language”