void movecolright(void) /* Moves right one column */ { int col, oldleftcol, oldrightcol; unsigned char oldcolstart[SCREENCOLS]; movmem(colstart, oldcolstart, sizeof(colstart)); oldleftcol = leftcol; oldrightcol = rightcol; displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE); if (curcol < rightcol) curcol++; else if (rightcol < (MAXCOLS - 1)) { curcol++; rightcol++; setleftcol(); setrightcol(); if (oldrightcol >= leftcol) scroll(LEFT, oldcolstart[leftcol - oldleftcol] - LEFTMARGIN, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE); clearlastcol(); for (col = oldrightcol + 1; col <= rightcol; col++) displaycol(col, NOUPDATE); } } /* movecolright */
void movecolleft(void) /* Moves left one column */ { int col, oldleftcol; unsigned char oldcolstart[SCREENCOLS]; oldleftcol = leftcol; movmem(colstart, oldcolstart, sizeof(colstart)); displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE); if (curcol > leftcol) curcol--; else if (leftcol != 0) { curcol--; leftcol--; setrightcol(); setleftcol(); if (oldleftcol <= rightcol) scroll(RIGHT, colstart[oldleftcol - leftcol] - LEFTMARGIN, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE); clearlastcol(); for (col = leftcol; col <= oldleftcol - 1; col++) displaycol(col, NOUPDATE); } } /* movecolleft */
void displayrow(int row, int updating) /* Displays a row on the screen */ { int col; for (col = leftcol; col <= rightcol; col++) displaycell(col, row, NOHIGHLIGHT, updating); } /* displayrow */
void displaycol(int col, int updating) /* Displays a column on the screen */ { int row; for (row = toprow; row <= bottomrow; row++) displaycell(col, row, NOHIGHLIGHT, updating); } /* displaycol */
void clearoflags(int col, int row, int display) /* Clears the overwrite flag on cells starting at (col, row) */ { while ((format[col][row] >= OVERWRITE) && (col < MAXCOLS) && (cell[col][row] == NULL)) { format[col][row] &= ~OVERWRITE; if (display && (col >= leftcol) && (col <= rightcol)) displaycell(col, row, NOHIGHLIGHT, NOUPDATE); col++; } } /* clearoflags */
void formatcells(void) /* Prompts the user for a selected format and range of cells */ { int col, row, col1, col2, row1, row2, temp, newformat = 0; writeprompt(MSGCELL1); if (!getcell(&col1, &row1)) return; writeprompt(MSGCELL2); if (!getcell(&col2, &row2)) return; if ((col1 != col2) && (row1 != row2)) errormsg(MSGDIFFCOLROW); else { if (col1 > col2) swap(&col1, &col2); if (row1 > row2) swap(&row1, &row2); if (!getyesno(&temp, MSGRIGHTJUST)) return; newformat += (temp == 'Y') * RJUSTIFY; if (!getyesno(&temp, MSGDOLLAR)) return; newformat += (temp == 'Y') * DOLLAR; if (!getyesno(&temp, MSGCOMMAS)) return; newformat += (temp == 'Y') * COMMAS; if (newformat & DOLLAR) newformat += 2; else { writeprompt(MSGPLACES); if (!getint(&temp, 0, MAXPLACES)) return; newformat += temp; } for (col = col1; col <= col2; col++) { for (row = row1; row <= row2; row++) { format[col][row] = (format[col][row] & OVERWRITE) | newformat; if ((col >= leftcol) && (col <= rightcol) && (row >= toprow) && (row <= bottomrow)) displaycell(col, row, NOHIGHLIGHT, NOUPDATE); } } } changed = TRUE; } /* formatcells */
void moverowup(void) /* Moves up 1 row */ { displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE); if (currow > toprow) currow--; else if (toprow != 0) { scroll(DOWN, 1, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE); displayrow(--toprow, NOUPDATE); currow--; setbottomrow(); } } /* moverowup */
void moverowdown(void) /* Moves down one row */ { displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE); if (currow < bottomrow) currow++; else if (bottomrow < (MAXROWS - 1)) { scroll(UP, 1, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE); toprow++; currow++; setbottomrow(); displayrow(bottomrow, NOUPDATE); } } /* moverowdown */
int setoflags(int col, int row, int display) /* Sets the overwrite flag on cells starting at (col + 1, row) - returns the number of the column after the last column set. */ { int len; len = strlen(cell[col][row]->v.text) - colwidth[col]; while ((++col < MAXCOLS) && (len > 0) && (cell[col][row] == NULL)) { format[col][row] |= OVERWRITE; len -= colwidth[col]; if (display && (col >= leftcol) && (col <= rightcol)) displaycell(col, row, NOHIGHLIGHT, NOUPDATE); } return(col); } /* setoflags */
void act(char *s) /* Acts on a particular input */ { int attrib, allocated; double value; deletecell(curcol, currow, UPDATE); value = parse(s, &attrib); switch(attrib) { case TEXT : allocated = alloctext(curcol, currow, s); if (allocated) displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE); break; case VALUE : allocated = allocvalue(curcol, currow, value); break; case FORMULA : allocated = allocformula(curcol, currow, s, value); break; } /* switch */ if (allocated) { format[curcol][currow] &= ~OVERWRITE; clearoflags(curcol + 1, currow, UPDATE); if (attrib == TEXT) setoflags(curcol, currow, UPDATE); if (curcol > lastcol) lastcol = curcol; if (currow > lastrow) lastrow = currow; if (autocalc) recalc(); } else errormsg(MSGLOMEM); printfreemem(); } /* act */