5.7 Canvas Functions
Functions which are declared as canvas functions in the dialog descriptions have to be programmed in C independently of the window system. The underlying window system is usually accessed to carry out the desired actions.
DM_Boolean DML_default DM_CALLBACK Functionname
(
DM_CanvasUserArgs *canvasargs
)
if the function is defined in the dialog script as
function canvasfunc 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 canvasfunc Functionname();
Example
In the dialog a canvas function is defined as follows:
function canvasfunc CallbackCanvas();
The assignment to the canvas is as follows:
child canvas Canvas
{
.borderwidth 1;
.xauto 0;
.xleft 1;
.xright 1;
.yauto 0;
.ytop 1;
.ybottom 5;
.canvasfunc CallbackCanvas;
}
A realization for the window system Motif then is as follows:
DM_Boolean DML_default DM_CALLBACK CallbackCanvas (data)
DM_CanvasUserArgs *data;
{
switch (data->reason)
{
case CCR_expose:
if (data->xevent)
{
DM_TraceMessage("CCR_expose width %d height %d",
DMF_LogFile | DMF_InhibitTag | DMF_Printf,
data->xevent->xexpose.width,
data->xevent->xexpose.height);
if (data->xevent->xexpose.count == 0)
DoExpose(data->widget, x0, y0);
}
break;
case CCR_input:
switch (data->xevent->type)
{
case ButtonPress:
switch (data->xevent->xbutton.button)
{
case Button1:
x0 = data->xevent->xbutton.x;
y0 = data->xevent->xbutton.y;
DoExpose(data->widget, x0, y0);
break;
}
break;
}
break;
case CCR_start:
DM_TraceMessage("CCR_start ** ", DMF_LogFile |
DMF_InhibitTag);
/* fallthrough */
case CCR_resize:
{
Arg args[2];
XtSetArg(args[ 0 ], XmNwidth, NULL);
XtSetArg(args[ 1 ], XmNheight, NULL);
XtGetValues(data->widget, args, 2);
width = args[0].value;
height = args[1].value;
DM_TraceMessage("Resize height %d width %d event %ld",
DMF_LogFile | DMF_InhibitTag | DMF_Printf,
height, width, (long) data->xevent);
}
break;
case CCR_stop:
break;
}
/*
** On Motif the return value of the canvas function is ignored.
** On Windows the message processing is stopped if the
** return value is TRUE.
** So the default return value of the canvas function is FALSE.
*/
return FALSE;
}