/* * This sets all the bindings for the given objects. */ void cleanCDKObjectBindings (EObjectType cdktype, void *object) { /* * Since dereferencing a void pointer is a no-no, we have to cast * our pointer correctly. */ if (cdktype == vFSELECT) { cleanCDKObjectBindings (vENTRY, ((CDKFSELECT *)object)->entryField); cleanCDKObjectBindings (vSCROLL, ((CDKFSELECT *)object)->scrollField); } else if (cdktype == vALPHALIST) { cleanCDKObjectBindings (vENTRY, ((CDKALPHALIST *)object)->entryField); cleanCDKObjectBindings (vSCROLL, ((CDKALPHALIST *)object)->scrollField); } else { int x; CDKOBJS *obj = (CDKOBJS *)object; for (x=0; x < obj->bindingCount; x++) { (obj)->bindingList[x].bindFunction = 0; (obj)->bindingList[x].bindData = 0; } } }
/* * This destroys the widget. */ static void _destroyCDKMarquee (CDKOBJS *object) { if (object != 0) { CDKMARQUEE *widget = (CDKMARQUEE *)object; /* Clean up the windows. */ deleteCursesWindow (widget->shadowWin); deleteCursesWindow (widget->win); /* Clean the key bindings. */ cleanCDKObjectBindings (vMARQUEE, widget); /* Unregister this object. */ unregisterCDKObject (vMARQUEE, widget); } }
/* * This destroys the button object pointer. */ static void _destroyCDKButton (CDKOBJS *object) { if (object != 0) { CDKBUTTON *button = (CDKBUTTON *)object; /* Free up the character pointers. */ freeChtype (button->info); /* Free up the window pointers. */ deleteCursesWindow (button->shadowWin); deleteCursesWindow (button->win); /* Clean the key bindings. */ cleanCDKObjectBindings (vBUTTON, button); /* Unregister the object. */ unregisterCDKObject (vBUTTON, button); } }
/* * This destroys the file selector. */ static void _destroyCDKAlphalist (CDKOBJS *object) { if (object != 0) { CDKALPHALIST *alphalist = (CDKALPHALIST *)object; destroyInfo (alphalist); /* Clean the key bindings. */ cleanCDKObjectBindings (vALPHALIST, alphalist); destroyCDKEntry (alphalist->entryField); destroyCDKScroll (alphalist->scrollField); /* Free up the window pointers. */ deleteCursesWindow (alphalist->shadowWin); deleteCursesWindow (alphalist->win); /* Unregister the object. */ unregisterCDKObject (vALPHALIST, alphalist); } }
/* * This function destroys the widget. */ static void _destroyCDKUScale (CDKOBJS *object) { if (object != 0) { CDKUSCALE *widget = (CDKUSCALE *)object; cleanCdkTitle (object); freeChtype (widget->label); /* Clean up the windows. */ deleteCursesWindow (widget->fieldWin); deleteCursesWindow (widget->labelWin); deleteCursesWindow (widget->shadowWin); deleteCursesWindow (widget->win); /* Clean the key bindings. */ cleanCDKObjectBindings (vUSCALE, widget); /* Unregister this object. */ unregisterCDKObject (vUSCALE, widget); } }
/* * This function destroys */ static void _destroyCDKScroll (CDKOBJS *object) { if (object != 0) { CDKSCROLL *scrollp = (CDKSCROLL *)object; cleanCdkTitle (object); CDKfreeChtypes (scrollp->item); freeChecked (scrollp->itemPos); freeChecked (scrollp->itemLen); /* Clean up the windows. */ deleteCursesWindow (scrollp->scrollbarWin); deleteCursesWindow (scrollp->shadowWin); deleteCursesWindow (scrollp->listWin); deleteCursesWindow (scrollp->win); /* Clean the key bindings. */ cleanCDKObjectBindings (vSCROLL, scrollp); /* Unregister this object. */ unregisterCDKObject (vSCROLL, scrollp); } }
/* * This function creates a scale widget. */ CDKFSCALE *newCDKFScale (CDKSCREEN *cdkscreen, int xplace, int yplace, char *title, char *label, chtype fieldAttr, int fieldWidth, float start, float low, float high, float inc, float fastinc, int digits, boolean Box, boolean shadow) { /* Declare local variables. */ CDKFSCALE *scale = newCDKObject(CDKFSCALE, &my_funcs); chtype *holder = 0; int parentWidth = getmaxx(cdkscreen->window) - 1; int parentHeight = getmaxy(cdkscreen->window) - 1; int boxHeight = 3; int boxWidth = fieldWidth + 2; int maxWidth = INT_MIN; int horizontalAdjust = 0; int xpos = xplace; int ypos = yplace; char **temp = 0; int x, len, junk, junk2; /* Set some basic values of the scale field. */ scale->label = 0; scale->labelLen = 0; scale->labelWin = 0; scale->titleLines = 0; /* * If the fieldWidth is a negative value, the fieldWidth will * be COLS-fieldWidth, otherwise, the fieldWidth will be the * given width. */ fieldWidth = setWidgetDimension (parentWidth, fieldWidth, 0); boxWidth = fieldWidth + 2; /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { scale->label = char2Chtype (label, &scale->labelLen, &junk); boxWidth = scale->labelLen + fieldWidth + 2; } /* Translate the char * items to chtype * */ if (title != 0) { temp = CDKsplitString (title, '\n'); scale->titleLines = CDKcountStrings (temp); /* We need to determine the widest title line. */ for (x=0; x < scale->titleLines; x++) { holder = char2Chtype (temp[x], &len, &junk2); maxWidth = MAXIMUM (maxWidth, len); freeChtype (holder); } /* * If one of the title lines is wider than the field and the label, * the box width will expand to accomodate. */ if (maxWidth > boxWidth) { horizontalAdjust = (int)((maxWidth - boxWidth) / 2) + 1; boxWidth = maxWidth + 2; } /* For each line in the title, convert from char * to chtype * */ for (x=0; x < scale->titleLines; x++) { scale->title[x] = char2Chtype (temp[x], &scale->titleLen[x], &scale->titlePos[x]); scale->titlePos[x] = justifyString (boxWidth, scale->titleLen[x], scale->titlePos[x]); } CDKfreeStrings(temp); } else { /* No title? Set the required variables. */ scale->titleLines = 0; } boxHeight += scale->titleLines; /* * Make sure we didn't extend beyond the dimensions of the window. */ boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth); boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight); fieldWidth = (fieldWidth > (boxWidth - scale->labelLen - 2) ? (boxWidth - scale->labelLen - 2) : fieldWidth); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the scale window. */ scale->win = newwin (boxHeight, boxWidth, ypos, xpos); /* Is the main window null??? */ if (scale->win == 0) { freeChtype (scale->label); free (scale); /* Return a null pointer. */ return (0); } /* Create the scale label window. */ if (scale->label != 0) { scale->labelWin = subwin (scale->win, 1, scale->labelLen + 2, ypos + scale->titleLines + 1, xpos + horizontalAdjust + 1); } /* Create the scale field window. */ scale->fieldWin = subwin (scale->win, 1, fieldWidth, ypos + scale->titleLines + 1, xpos + scale->labelLen + horizontalAdjust + 1); keypad (scale->fieldWin, TRUE); keypad (scale->win, TRUE); /* Create the scale field. */ ScreenOf(scale) = cdkscreen; ObjOf(scale)->box = Box; scale->parent = cdkscreen->window; scale->shadowWin = 0; scale->boxWidth = boxWidth; scale->boxHeight = boxHeight; scale->fieldWidth = fieldWidth; scale->fieldAttr = (chtype)fieldAttr; scale->current = low; scale->low = low; scale->high = high; scale->current = start; scale->inc = inc; scale->fastinc = fastinc; scale->digits = digits; scale->exitType = vNEVER_ACTIVATED; scale->shadow = shadow; scale->preProcessFunction = 0; scale->preProcessData = 0; scale->postProcessFunction = 0; scale->postProcessData = 0; scale->ULChar = ACS_ULCORNER; scale->URChar = ACS_URCORNER; scale->LLChar = ACS_LLCORNER; scale->LRChar = ACS_LRCORNER; scale->HChar = ACS_HLINE; scale->VChar = ACS_VLINE; scale->BoxAttrib = A_NORMAL; /* Do we want a shadow??? */ if (shadow) { scale->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Clean the key bindings. */ cleanCDKObjectBindings (vFSCALE, scale); /* Register this baby. */ registerCDKObject (cdkscreen, vFSCALE, scale); /* Return the pointer. */ return (scale); }
/* * This function creates a dialog widget. */ CDKDIALOG *newCDKDialog (CDKSCREEN *cdkscreen, int xplace, int yplace, char **mesg, int rows, char **buttonLabel, int buttonCount, chtype highlight, boolean separator, boolean Box, boolean shadow) { /* Declare local variables. */ CDKDIALOG *dialog = newCDKObject(CDKDIALOG, &my_funcs); int boxWidth = MIN_DIALOG_WIDTH; int boxHeight = rows + 3 + separator; int maxmessagewidth = -1; int buttonwidth = 0; int xpos = xplace; int ypos = yplace; int temp = 0; int buttonadj = 0; int x = 0; /* Translate the char * message to a chtype * */ for (x=0; x < rows; x++) { dialog->info[x] = char2Chtype (mesg[x], &dialog->infoLen[x], &dialog->infoPos[x]); maxmessagewidth = MAXIMUM(maxmessagewidth, dialog->infoLen[x]); } /* Translate the button label char * to a chtype * */ for (x = 0; x < buttonCount; x++) { dialog->buttonLabel[x] = char2Chtype (buttonLabel[x], &dialog->buttonLen[x], &temp); buttonwidth += dialog->buttonLen[x] + 1; } buttonwidth--; /* Determine the final dimensions of the box. */ boxWidth = MAXIMUM(boxWidth, maxmessagewidth); boxWidth = MAXIMUM(boxWidth, buttonwidth); boxWidth = boxWidth + 4; /* Now we have to readjust the x and y positions. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Set up the dialog box attributes. */ ScreenOf(dialog) = cdkscreen; dialog->parent = cdkscreen->window; dialog->win = newwin (boxHeight, boxWidth, ypos, xpos); dialog->shadowWin = 0; dialog->buttonCount = buttonCount; dialog->currentButton = 0; dialog->messageRows = rows; dialog->boxHeight = boxHeight; dialog->boxWidth = boxWidth; dialog->highlight = highlight; dialog->separator = separator; dialog->exitType = vNEVER_ACTIVATED; ObjOf(dialog)->box = Box; dialog->shadow = shadow; dialog->ULChar = ACS_ULCORNER; dialog->URChar = ACS_URCORNER; dialog->LLChar = ACS_LLCORNER; dialog->LRChar = ACS_LRCORNER; dialog->HChar = ACS_HLINE; dialog->VChar = ACS_VLINE; dialog->BoxAttrib = A_NORMAL; dialog->preProcessFunction = 0; dialog->preProcessData = 0; dialog->postProcessFunction = 0; dialog->postProcessData = 0; /* If we couldn't create the window, we should return a null value. */ if (dialog->win == 0) { /* Couldn't create the window. Clean up used memory. */ for (x=0; x < dialog->messageRows ; x++) { freeChtype (dialog->info[x]); } for (x=0; x < dialog->buttonCount; x++) { freeChtype (dialog->buttonLabel[x]); } /* Remove the memory used by the dialog pointer. */ free (dialog); /* Return a null dialog box. */ return (0); } keypad (dialog->win, TRUE); /* Find the button positions. */ buttonadj = ((int)((boxWidth-buttonwidth)/2)); for (x = 0; x < buttonCount; x++) { dialog->buttonPos[x] = buttonadj; buttonadj = buttonadj + dialog->buttonLen[x] + 1; } /* Create the string alignments. */ for (x=0; x < rows; x++) { dialog->infoPos[x] = justifyString (boxWidth, dialog->infoLen[x], dialog->infoPos[x]); } /* Was there a shadow? */ if (shadow) { dialog->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* Empty the key bindings. */ cleanCDKObjectBindings (vDIALOG, dialog); /* Register this baby. */ registerCDKObject (cdkscreen, vDIALOG, dialog); /* Return the dialog box pointer. */ return (dialog); }