/* 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; }
/* Add a slider to a form */ bool widgAddSlider(W_SCREEN *psScreen, const W_SLDINIT* psInit) { W_SLIDER *psSlider; W_FORM *psForm; ASSERT( psScreen != NULL, "widgAddEditBox: Invalid screen pointer" ); if (widgCheckIDForm((W_FORM *)psScreen->psForm, psInit->id)) { ASSERT(false, "widgSlider: ID number has already been used (%d)", psInit->id); return false; } /* Find the form to put the slider on */ if (psInit->formID == 0) { psForm = (W_FORM *)psScreen->psForm; } else { psForm = (W_FORM *)widgGetFromID(psScreen, psInit->formID); if (!psForm || psForm->type != WIDG_FORM) { ASSERT(false, "widgAddSlider: Could not find parent form from formID"); return false; } } /* Create the slider structure */ psSlider = sliderCreate(psInit); if (psSlider == NULL /* Add it to the form */ || !formAddWidget(psForm, (WIDGET *)psSlider, (W_INIT *)psInit)) { return false; } return true; }
/* Add a button to the widget screen */ bool widgAddButton(W_SCREEN *psScreen, const W_BUTINIT* psInit) { W_BUTTON *psButton; W_FORM *psForm; ASSERT( psScreen != NULL, "widgAddButton: Invalid screen pointer" ); if (widgCheckIDForm((W_FORM *)psScreen->psForm,psInit->id)) { ASSERT( false, "widgAddButton: ID number has already been used(%d)", psInit->id ); return false; } /* Find the form to put the button on */ if (psInit->formID == 0) { psForm = (W_FORM *)psScreen->psForm; } else { psForm = (W_FORM *)widgGetFromID(psScreen, psInit->formID); if (psForm == NULL || psForm->type != WIDG_FORM) { ASSERT( false, "widgAddButton: Could not find parent form from formID" ); return false; } } /* Create the button structure */ psButton = buttonCreate(psInit); if (psButton == NULL /* Add it to the form */ || !formAddWidget(psForm, (WIDGET *)psButton, (W_INIT *)psInit)) { return false; } return true; }
/* Add a form to the widget screen */ bool widgAddForm(W_SCREEN *psScreen, const W_FORMINIT* psInit) { W_FORM *psParent, *psForm; ASSERT( psScreen != NULL, "widgAddForm: Invalid screen pointer" ); if (widgCheckIDForm((W_FORM *)psScreen->psForm,psInit->id)) { ASSERT( false, "widgAddForm: ID number has already been used (%d)", psInit->id ); return false; } /* Find the form to add the widget to */ if (psInit->formID == 0) { /* Add to the base form */ psParent = (W_FORM *)psScreen->psForm; } else { psParent = (W_FORM *)widgGetFromID(psScreen, psInit->formID); if (!psParent || psParent->type != WIDG_FORM) { ASSERT( false, "widgAddForm: Could not find parent form from formID" ); return false; } } /* Create the form structure */ psForm = formCreate(psInit); if (psForm == NULL /* Add it to the screen */ || !formAddWidget(psParent, (WIDGET *)psForm, (W_INIT *)psInit)) { return false; } return true; }
/* Add a bar graph to the widget screen */ BOOL widgAddBarGraph(W_SCREEN *psScreen, const W_BARINIT* psInit) { W_BARGRAPH *psBarGraph; W_FORM *psForm; ASSERT( psScreen != NULL, "widgAddEditBox: Invalid screen pointer" ); if (widgCheckIDForm((W_FORM *)psScreen->psForm,psInit->id)) { ASSERT( false, "widgAddBarGraph: ID number has already been used (%d)", psInit->id ); return false; } /* Find the form to put the bar graph on */ if (psInit->formID == 0) { psForm = (W_FORM *)psScreen->psForm; } else { psForm = (W_FORM *)widgGetFromID(psScreen, psInit->formID); if (!psForm || psForm->type != WIDG_FORM) { ASSERT( false, "widgAddBarGraph: Could not find parent form from formID" ); return false; } } /* Create the bar graph structure */ psBarGraph = barGraphCreate(psInit); if (psBarGraph == NULL /* Add it to the form */ || !formAddWidget(psForm, (WIDGET *)psBarGraph, (W_INIT *)psInit)) { return false; } return true; }