static int do_undo (CB_PARAMS) { int result = FALSE; if (undoSize > 0) { CDKFSELECT *widget = (CDKFSELECT *)clientdata; int size; int n; char **oldlist = getCDKFselectContents (widget, &size); char **newlist = (char **)malloc ((size_t) (++size + 1) * sizeof (char *)); --undoSize; newlist[size] = 0; for (n = size - 1; n > myUndoList[undoSize].deleted; --n) { newlist[n] = copyChar (oldlist[n - 1]); } newlist[n--] = copyChar (myUserList[myUndoList[undoSize].original]); while (n >= 0) { newlist[n] = copyChar (oldlist[n]); --n; } setCDKFselectContents (widget, (CDK_CSTRING2)newlist, size); setCDKScrollCurrentTop (widget->scrollField, myUndoList[undoSize].topline); setCDKFselectCurrentItem (widget, myUndoList[undoSize].position); drawCDKFselect (widget, BorderOf (widget)); free (newlist); result = TRUE; } return result; }
static int do_delete1 (CB_PARAMS) { CDKFSELECT *widget = (CDKFSELECT *)clientdata; int size; char **list = getCDKFselectContents (widget, &size); int result = FALSE; if (size) { int save = getCDKScrollCurrentTop (widget->scrollField); int first = getCDKFselectCurrentItem (widget); if (first-- > 0) { int n; fill_undo (widget, first, list[first]); for (n = first; n < size; ++n) list[n] = list[n + 1]; setCDKFselectContents (widget, (CDK_CSTRING2)list, size - 1); setCDKScrollCurrentTop (widget->scrollField, save); setCDKFselectCurrentItem (widget, first); drawCDKFselect (widget, BorderOf (widget)); result = TRUE; } } return result; }
static int do_reload (CB_PARAMS) { int result = FALSE; if (userSize) { CDKFSELECT *widget = (CDKFSELECT *)clientdata; setCDKFselectContents (widget, (CDK_CSTRING2)myUserList, userSize); setCDKFselectCurrentItem (widget, 0); drawCDKFselect (widget, BorderOf (widget)); result = TRUE; } return result; }
/* * This moves the fselect field to the given location. */ static void _moveCDKFselect (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag) { CDKFSELECT *fselect = (CDKFSELECT *)object; /* Declare local variables. */ int currentX = getbegx(fselect->win); int currentY = getbegy(fselect->win); int xpos = xplace; int ypos = yplace; int xdiff = 0; int ydiff = 0; /* * If this is a relative move, then we will adjust where we want * to move to. */ if (relative) { xpos = getbegx(fselect->win) + xplace; ypos = getbegy(fselect->win) + yplace; } /* Adjust the window if we need to. */ alignxy (WindowOf(fselect), &xpos, &ypos, fselect->boxWidth, fselect->boxHeight); /* Get the difference. */ xdiff = currentX - xpos; ydiff = currentY - ypos; /* Move the window to the new location. */ moveCursesWindow(fselect->win, -xdiff, -ydiff); /* If there is a shadow box we have to move it too. */ if (fselect->shadow) { moveCursesWindow(fselect->shadowWin, -xdiff, -ydiff); } /* Move the sub-widgets. */ moveCDKEntry (fselect->entryField, xplace, yplace, relative, FALSE); moveCDKScroll (fselect->scrollField, xplace, yplace, relative, FALSE); touchwin (fselect->entryField->win); touchwin (fselect->scrollField->win); /* Redraw the window, if they asked for it. */ if (refresh_flag) { drawCDKFselect (fselect, ObjOf(fselect)->box); } }
/* * This means you want to use the given file selector. It takes input * from the keyboard, and when it's done, it fills the entry info * element of the structure with what was typed. */ char *activateCDKFselect (CDKFSELECT *fselect, chtype *actions) { /* Declare local variables. */ chtype input = 0; char *ret = 0; /* Draw the widget. */ drawCDKFselect (fselect, ObjOf(fselect)->box); /* Check if 'actions' is null. */ if (actions == 0) { for (;;) { /* Get the input. */ input = wgetch (fselect->entryField->fieldWin); /* Inject the character into the widget. */ ret = injectCDKFselect (fselect, input); if (fselect->exitType != vEARLY_EXIT) { return ret; } } } else { int length = chlen (actions); int x =0; /* Inject each character one at a time. */ for (x=0; x < length; x++) { ret = injectCDKFselect (fselect, actions[x]); if (fselect->exitType != vEARLY_EXIT) { return ret; } } } /* Set the exit type and exit. */ fselect->exitType = vEARLY_EXIT; return 0; }
/* * This is a callback to the scrolling list which displays information * about the current file. (and the whole directory as well) */ static int displayFileInfoCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { /* Declare local variables. */ CDKENTRY *entry = (CDKENTRY *)object; CDKFSELECT *fselect = (CDKFSELECT *)clientData; CDKLABEL *infoLabel; struct stat fileStat; struct passwd *pwEnt; struct group *grEnt; char *filename; char *filetype; char *mesg[10]; char temp[100]; char stringMode[15]; int len; int intMode; /* Get the file name. */ filename = fselect->entryField->info; /* Get specific information about the files. */ lstat (filename, &fileStat); /* Determine the file type. */ switch (mode2Filetype(fileStat.st_mode)) { case 'l': filetype = "Symbolic Link"; break; case '@': filetype = "Socket"; break; case '-': filetype = "Regular File"; break; case 'd': filetype = "Directory"; break; case 'c': filetype = "Character Device"; break; case 'b': filetype = "Block Device"; break; case '&': filetype = "FIFO Device"; break; default: filetype = "Unknown"; break; } /* Get the user name and group name. */ pwEnt = getpwuid (fileStat.st_uid); grEnt = getgrgid (fileStat.st_gid); /* Convert the mode_t type to both string and int. */ intMode = mode2Char (stringMode, fileStat.st_mode); /* Create the message. */ sprintf (temp, "Directory : </U>%s", fselect->pwd); mesg[0] = copyChar (temp); sprintf (temp, "Filename : </U>%s", filename); mesg[1] = copyChar (temp); sprintf (temp, "Owner : </U>%s<!U> (%d)", pwEnt->pw_name, (int)fileStat.st_uid); mesg[2] = copyChar (temp); sprintf (temp, "Group : </U>%s<!U> (%d)", grEnt->gr_name, (int)fileStat.st_gid); mesg[3] = copyChar (temp); sprintf (temp, "Permissions: </U>%s<!U> (%o)", stringMode, intMode); mesg[4] = copyChar (temp); sprintf (temp, "Size : </U>%ld<!U> bytes", (long) fileStat.st_size); mesg[5] = copyChar (temp); sprintf (temp, "Last Access: </U>%s", ctime (&fileStat.st_atime)); len = (int)strlen (temp); temp[len] = '\0'; temp[len-1] = '\0'; mesg[6] = copyChar (temp); sprintf (temp, "Last Change: </U>%s", ctime (&fileStat.st_ctime)); len = (int)strlen (temp); temp[len] = '\0'; temp[len-1] = '\0'; mesg[7] = copyChar (temp); sprintf (temp, "File Type : </U>%s", filetype); mesg[8] = copyChar (temp); /* Create the pop up label. */ infoLabel = newCDKLabel (entry->obj.screen, CENTER, CENTER, mesg, 9, TRUE, FALSE); drawCDKLabel (infoLabel, TRUE); wgetch (infoLabel->win); /* Clean up some memory. */ destroyCDKLabel (infoLabel); freeCharList (mesg, 9); /* Redraw the file selector. */ drawCDKFselect (fselect, ObjOf(fselect)->box); return (TRUE); }
/* * This function sets the information inside the file selector. */ void setCDKFselect (CDKFSELECT *fselect, char *directory, chtype fieldAttrib, chtype filler, chtype highlight, char *dirAttribute, char *fileAttribute, char *linkAttribute, char *sockAttribute, boolean Box GCC_UNUSED) { /* Declare local variables. */ CDKSCROLL *fscroll = fselect->scrollField; CDKENTRY *fentry = fselect->entryField; char *tempDir = 0; char *mesg[10], newDirectory[2000], temp[100]; int ret; /* Keep the info sent to us. */ fselect->fieldAttribute = fieldAttrib; fselect->fillerCharacter = filler; fselect->highlight = highlight; strcpy (newDirectory, directory); /* Set the attributes of the entry field/scrolling list. */ setCDKEntryFillerChar (fentry, filler); setCDKScrollHighlight (fscroll, highlight); /* Only do the directory stuff if the directory is not null. */ if (directory != 0) { /* Try to expand the directory if it starts with a ~ */ if (directory[0] == '~') { tempDir = expandFilename (directory); if (tempDir != 0) { strcpy (newDirectory, tempDir); freeChar (tempDir); } } /* Change directories. */ ret = chdir (newDirectory); if (ret != 0) { /* Beep at them. */ Beep(); /* Couldn't get into the directory, pop up a little message. */ sprintf (temp, "<C>Could not change into %s", newDirectory); mesg[0] = copyChar (temp); #ifdef HAVE_STRERROR sprintf (temp, "<C></U>%s", strerror(errno)); mesg[1] = copyChar (temp); #else sprintf (temp, "<C></U>Unknown reason."); mesg[1] = copyChar (temp); #endif mesg[2] = " "; mesg[3] = "<C>Press Any Key To Continue."; /* Pop Up a message. */ popupLabel (ScreenOf(fselect), mesg, 4); /* Clean up some memory. */ freeCharList (mesg, 4); /* Get out of here. */ eraseCDKFselect (fselect); drawCDKFselect (fselect, ObjOf(fselect)->box); return; } } /* * If the information coming in is the same as the information * that is already there, there is no need to destroy it. */ if (fselect->pwd != directory) { setPWD(fselect); } if (fselect->fileAttribute != fileAttribute) { /* Remove the old pointer and set the new value. */ freeChar (fselect->fileAttribute); fselect->fileAttribute = copyChar (fileAttribute); } if (fselect->dirAttribute != dirAttribute) { /* Remove the old pointer and set the new value. */ freeChar (fselect->dirAttribute); fselect->dirAttribute = copyChar (dirAttribute); } if (fselect->linkAttribute != linkAttribute) { /* Remove the old pointer and set the new value. */ freeChar (fselect->linkAttribute); fselect->linkAttribute = copyChar (linkAttribute); } if (fselect->sockAttribute != sockAttribute) { /* Remove the old pointer and set the new value. */ freeChar (fselect->sockAttribute); fselect->sockAttribute = copyChar (sockAttribute); } /* Set the contents of the entry field. */ setCDKEntryValue (fentry, fselect->pwd); drawCDKEntry (fentry, ObjOf(fentry)->box); /* Get the directory contents. */ if (setCDKFselectDirContents (fselect) == 0) { Beep(); return; } /* Set the values in the scrolling list. */ setCDKScrollItems (fscroll, fselect->dirContents, fselect->fileCounter, FALSE); }
void __drawCDKFselect (CDKFSELECT * fselect, int box) { drawCDKFselect(fselect, box); }
void CDKFselect::draw(void) { drawCDKFselect (fselect, box); }