home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / TCALC.ZIP / TCDISPLY.C < prev    next >
Text File  |  1990-09-26  |  7KB  |  286 lines

  1. /* Turbo C++ - (C) Copyright 1987,1988,1990 by Borland International */
  2.  
  3. #include <dos.h>
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include <string.h>
  7. #include <mem.h>
  8. #include <conio.h>
  9. #include "tcalc.h"
  10.  
  11. static unsigned char colortable[256];
  12.  
  13. void setcolor(int color)
  14. /* Sets the current color using the color table */
  15. {
  16.   textattr(colortable[color]);
  17. } /* setcolor */
  18.  
  19. void writef(int col, int row, int color, int width, char *format, ...)
  20. /* Prints a string in video memory at a selected location in a color */
  21. {
  22.  va_list arg_ptr;
  23.  char output[81];
  24.  int len;
  25.  
  26.  va_start(arg_ptr, format);
  27.  vsprintf(output, format, arg_ptr);
  28.  output[width] = 0;
  29.  if ((len = strlen(output)) < width)
  30.   setmem(&output[len], width - len, ' ');
  31.  setcolor(color);
  32.  gotoxy(col, row);
  33.  cputs(output);
  34. } /* writef */
  35.  
  36. void scroll(int direction, int lines, int x1, int y1, int x2, int y2,
  37.             int attrib)
  38. /* Scrolls an area of the screen */
  39. {
  40.   if (lines == 0)
  41.     window(x1, y1, x2, y2);
  42.   else switch(direction)
  43.   {
  44.     case UP :
  45.       movetext(x1, y1 + lines, x2, y2, x1, y1);
  46.       window(x1, y2 - lines + 1, x2, y2);
  47.       break;
  48.     case DOWN :
  49.       movetext(x1, y1, x2, y2 - lines, x1, y1 + lines);
  50.       window(x1, y1, x2, y1 + lines - 1);
  51.       break;
  52.     case LEFT :
  53.       movetext(x1 + lines, y1, x2, y2, x1, y1);
  54.       window(x2 - lines + 1, y1, x2, y2);
  55.       break;
  56.     case RIGHT :
  57.       movetext(x1, y1, x2 - lines, y2, x1 + lines, y1);
  58.       window(x1, y1, x1 + lines - 1, y2);
  59.       break;
  60.   } /* switch */
  61.   setcolor(attrib);
  62.   clrscr();
  63.   window(1, 1, 80, 25);
  64. } /* scroll */
  65.  
  66. void setcursor(unsigned int shape)
  67. /* Sets the shape of the cursor */
  68. {
  69.  union REGS reg;
  70.  
  71.  reg.h.ah = 1;
  72.  reg.x.cx = shape;
  73.  int86(0X10, ®, ®);
  74. } /* setcursor */
  75.  
  76. unsigned int getcursor(void)
  77. /* Returns the shape of the current cursor */
  78. {
  79.  union REGS reg;
  80.  
  81.  reg.h.ah = 3;
  82.  reg.h.bh = 0;
  83.  int86(0X10, ®, ®);
  84.  return(reg.x.cx);
  85. } /* getcursor */
  86.  
  87. void changecursor(insmode)
  88. /* Changes the cursor shape based on the current insert mode */
  89. {
  90.  if (insmode)
  91.   setcursor(tallcursor);
  92.  else
  93.   setcursor(shortcursor);
  94. } /* changecursor */
  95.  
  96. void printcol(void)
  97. /* Prints the column headings */
  98. {
  99.  int col;
  100.  char colstr[MAXCOLWIDTH + 1];
  101.  
  102.  scroll(UP, 0, 1, 2, 80, 2, HEADERCOLOR);
  103.  for (col = leftcol; col <= rightcol; col++)
  104.  {
  105.   centercolstring(col, colstr);
  106.   writef(colstart[col - leftcol] + 1, 2, HEADERCOLOR, colwidth[col], colstr);
  107.  }
  108. } /* printcol */
  109.  
  110. void clearlastcol()
  111. /* Clears any data left in the last column */
  112. {
  113.  int col;
  114.  
  115.  if ((col = colstart[rightcol - leftcol] + colwidth[rightcol]) < 80)
  116.   scroll(UP, 0, col + 1, 3, 80, SCREENROWS + 2, WHITE);
  117. } /* clearlastcol */
  118.  
  119. void printrow(void)
  120. /* Prints the row headings */
  121. {
  122.  int row;
  123.  
  124.  for (row = 0; row < SCREENROWS; row++)
  125.   writef(1, row + 3, HEADERCOLOR, LEFTMARGIN, "%-d", row + toprow + 1);
  126. } /* printrow */
  127.  
  128. void displaycell(int col, int row, int highlighting, int updating)
  129. /* Displays the contents of a cell */
  130. {
  131.  int color;
  132.  char *s;
  133.  
  134.  if ((updating) &&
  135.      ((cell[col][row] == NULL) || (cell[col][row]->attrib != FORMULA)))
  136.   return;
  137.  s = cellstring(col, row, &color, FORMAT);
  138.  if (highlighting)
  139.  {
  140.   if (color == ERRORCOLOR)
  141.    color = HIGHLIGHTERRORCOLOR;
  142.   else
  143.    color = HIGHLIGHTCOLOR;
  144.  }
  145.  writef(colstart[col - leftcol] + 1, row - toprow + 3, color, colwidth[col],
  146.         "%s", s);
  147. } /* displaycell */
  148.  
  149. void displaycol(int col, int updating)
  150. /* Displays a column on the screen */
  151. {
  152.  int row;
  153.  
  154.  for (row = toprow; row <= bottomrow; row++)
  155.   displaycell(col, row, NOHIGHLIGHT, updating);
  156. } /* displaycol */
  157.  
  158. void displayrow(int row, int updating)
  159. /* Displays a row on the screen */
  160. {
  161.  int col;
  162.  
  163.  for (col = leftcol; col <= rightcol; col++)
  164.   displaycell(col, row, NOHIGHLIGHT, updating);
  165. } /* displayrow */
  166.  
  167. void displayscreen(int updating)
  168. /* Displays the current screen of the spreadsheet */
  169. {
  170.  int row;
  171.  
  172.  for (row = toprow; row <= bottomrow; row++)
  173.   displayrow(row, updating);
  174.  clearlastcol();
  175. } /* displayscreen */
  176.  
  177. void clearinput(void)
  178. /* Clears the input line */
  179. {
  180.  scroll(UP, 0, 1, 25, 80, 25, WHITE);
  181.  gotoxy(1, 25);
  182. } /* clearinput */
  183.  
  184. void showcelltype(void)
  185. /* Prints the type of cell and what is in it */
  186. {
  187.  char colstr[3], *s;
  188.  int color;
  189.  
  190.  formdisplay = !formdisplay;
  191.  s = cellstring(curcol, currow, &color, NOFORMAT);
  192.  colstring(curcol, colstr);
  193.  if (curcell == NULL)
  194.   writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGEMPTY);
  195.  else switch(curcell->attrib)
  196.  {
  197.   case TEXT :
  198.    writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1,
  199.           MSGTEXT);
  200.    break;
  201.   case VALUE :
  202.    writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1,
  203.           MSGVALUE);
  204.    break;
  205.   case FORMULA :
  206.    writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1,
  207.           MSGFORMULA);
  208.    break;
  209.  } /* switch */
  210.  writef(1, 24, CELLCONTENTSCOLOR, 80, "%s", s);
  211.  formdisplay = !formdisplay;
  212. } /* showcelltype */
  213.  
  214. void redrawscreen(void)
  215. /* Displays the entire screen */
  216. {
  217.  setrightcol();
  218.  setbottomrow();
  219.  writef(1, 1, MSGMEMORYCOLOR, strlen(MSGMEMORY), MSGMEMORY);
  220.  writef(29, 1, PROMPTCOLOR, strlen(MSGCOMMAND), MSGCOMMAND);
  221.  changeautocalc(autocalc);
  222.  changeformdisplay(formdisplay);
  223.  printfreemem();
  224.  displayscreen(NOUPDATE);
  225. } /* redrawscreen */
  226.  
  227. void initcursor(void)
  228. /* Initializes the different cursor types */
  229. {
  230.  struct text_info ti;
  231.  
  232.  gettextinfo(&ti);
  233.  oldcursor = getcursor();
  234.  if (ti.currmode == MONO)
  235.  {
  236.   shortcursor = 0x0A0C;
  237.   tallcursor = 0x090C;
  238.  }
  239.  else
  240.  {
  241.   shortcursor = 0x0607;
  242.   tallcursor = 0x0507;
  243.  }
  244. } /* initcursor */
  245.  
  246. void initcolortable(void)
  247. /* Sets up the color table */
  248. {
  249.   int color, fg, bg, fcolor, bcolor;
  250.   struct text_info ti;
  251.  
  252.   gettextinfo(&ti);
  253.   if (ti.currmode == C80)
  254.   {
  255.     for (color = 0; color <= 255; color++)
  256.       colortable[color] = color;
  257.   }
  258.   else
  259.   {
  260.     for (fg = BLACK; fg <= WHITE; fg++)
  261.     {
  262.       if (fg == BLACK)
  263.         fcolor = BLACK;
  264.       else if (fg <= LIGHTGRAY)
  265.         fcolor = LIGHTGRAY;
  266.       else
  267.         fcolor = WHITE;
  268.       for (bg = BLACK; bg <= LIGHTGRAY; bg++)
  269.       {
  270.         if (bg == BLACK)
  271.           bcolor = BLACK;
  272.         else
  273.   {
  274.           if (fcolor == WHITE)
  275.             fcolor = BLACK;
  276.           bcolor = LIGHTGRAY;
  277.         }
  278.         colortable[fg + (bg << 4)] = fcolor + (bcolor << 4);
  279.       }
  280.     }
  281.     for (fg = 128; fg <= 255; fg++)
  282.       colortable[fg] = colortable[fg - 128] | 0x80;
  283.   }
  284. } /* initcolortable */
  285. 
  286.