/* Check whether an ID has been used on a form */ static bool widgCheckIDForm(W_FORM *psForm, UDWORD id) { WIDGET *psCurr; W_FORMGETALL sGetAll; /* Check the widgets on the form */ formInitGetAllWidgets(psForm, &sGetAll); psCurr = formGetAllWidgets(&sGetAll); while (psCurr != NULL) { if (psCurr->id == id) { return true; } if (psCurr->type == WIDG_FORM) { /* Another form so recurse */ if (widgCheckIDForm((W_FORM *)psCurr, id)) { return true; } } psCurr = psCurr->psNext; if (!psCurr) { /* Got to the end of this list see if there is another */ psCurr = formGetAllWidgets(&sGetAll); } } return false; }
/* Call any callbacks for the widgets on a form */ static void widgProcessCallbacks(W_CONTEXT *psContext) { WIDGET *psCurr; W_CONTEXT sFormContext, sWidgContext; SDWORD xOrigin, yOrigin; W_FORMGETALL sFormCtl; /* Initialise the form context */ sFormContext.psScreen = psContext->psScreen; /* Initialise widget context */ formGetOrigin(psContext->psForm, &xOrigin, &yOrigin); sWidgContext.psScreen = psContext->psScreen; sWidgContext.psForm = psContext->psForm; sWidgContext.mx = psContext->mx - xOrigin; sWidgContext.my = psContext->my - yOrigin; sWidgContext.xOffset = psContext->xOffset + xOrigin; sWidgContext.yOffset = psContext->yOffset + yOrigin; /* Go through all the widgets on the form */ formInitGetAllWidgets(psContext->psForm, &sFormCtl); psCurr = formGetAllWidgets(&sFormCtl); while (psCurr) { for(;psCurr; psCurr = psCurr->psNext) { /* Call the callback */ if (psCurr->callback) { psCurr->callback(psCurr, &sWidgContext); } /* and then recurse */ if (psCurr->type == WIDG_FORM) { sFormContext.psForm = (W_FORM *)psCurr; sFormContext.mx = sWidgContext.mx - psCurr->x; sFormContext.my = sWidgContext.my - psCurr->y; sFormContext.xOffset = sWidgContext.xOffset + psCurr->x; sFormContext.yOffset = sWidgContext.yOffset + psCurr->y; widgProcessCallbacks(&sFormContext); } } /* See if the form has any more widgets on it */ psCurr = formGetAllWidgets(&sFormCtl); } }
/* Initialise a form and all it's widgets */ static void widgStartForm(W_FORM *psForm) { WIDGET *psCurr; W_FORMGETALL sGetAll; /* Initialise this form */ // This whole function should be redundant, since all widgets are initialised when created... //formInitialise(psForm); /*Initialise the widgets on the form */ formInitGetAllWidgets(psForm, &sGetAll); psCurr = formGetAllWidgets(&sGetAll); while (psCurr != NULL) { switch (psCurr->type) { case WIDG_FORM: widgStartForm((W_FORM *)psCurr); break; case WIDG_LABEL: break; case WIDG_BUTTON: buttonInitialise((W_BUTTON *)psCurr); break; case WIDG_EDITBOX: ((W_EDITBOX *)psCurr)->initialise(); break; case WIDG_BARGRAPH: break; case WIDG_SLIDER: sliderInitialise((W_SLIDER *)psCurr); break; default: ASSERT(!"Unknown widget type", "Unknown widget type"); break; } psCurr = psCurr->psNext; if (!psCurr) { /* Got to the end of this list see if there is another */ psCurr = formGetAllWidgets(&sGetAll); } } }
/* Free a tabbed form widget */ static void formFreeTabbed(W_TABFORM *psWidget) { WIDGET *psCurr; W_FORMGETALL sGetAll; ASSERT( psWidget != NULL, "formFreeTabbed: Invalid form pointer" ); formFreeTips(psWidget); formInitGetAllWidgets((W_FORM *)psWidget,&sGetAll); psCurr = formGetAllWidgets(&sGetAll); while (psCurr) { widgReleaseWidgetList(psCurr); psCurr = formGetAllWidgets(&sGetAll); } delete psWidget; }
/* Find a widget on a form from it's id number */ static WIDGET *widgFormGetFromID(W_FORM *psForm, UDWORD id) { WIDGET *psCurr, *psFound; W_FORMGETALL sGetAll; /* See if the form matches the ID */ if (psForm->id == id) { return (WIDGET *)psForm; } /* Now search the widgets on the form */ psFound = NULL; formInitGetAllWidgets(psForm,&sGetAll); psCurr = formGetAllWidgets(&sGetAll); while (psCurr && !psFound) { if (psCurr->id == id) { psFound = psCurr; } else if (psCurr->type == WIDG_FORM) { psFound = widgFormGetFromID((W_FORM *)psCurr, id); } psCurr = psCurr->psNext; if (!psCurr) { /* Got to the end of this list see if there is another */ psCurr = formGetAllWidgets(&sGetAll); } } return psFound; }