home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / BENCH / TSCROLL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  8.4 KB  |  393 lines

  1. /* ===( tscroll.c )=== */
  2.  
  3. /*
  4.  * Contains scrolling window function(s) for 'generic' trees
  5. */
  6. #include <stdio.h>
  7. #include <bench.h>
  8. #include <tree.h>
  9. #include <dirw.h>
  10.  
  11. #ifdef ANSI
  12. static void branch_dsp(int, int, int, TREE *, struct tree_entry *, int, int, int, int);
  13. #else
  14. static void branch_dsp();
  15. #endif
  16.  
  17. extern struct window_rec *winptr;
  18.  
  19. static void branch_dsp(row, coloff, width, tp, t_ent, attr, awrow, awcol, mouseid)
  20. int row;
  21. int coloff;
  22. int width;
  23. TREE *tp;
  24. struct tree_entry *t_ent;
  25. int attr;
  26. int awrow;
  27. int awcol;
  28. int mouseid;
  29. {
  30.     struct tree_entry *t_parent;
  31.     int tmpcol;
  32.     char *nameptr;
  33. #ifdef MOUSE
  34.     int startcol = 0;
  35.     int stopcol;
  36. #endif
  37.  
  38.     if (t_ent != NULL)
  39.     {
  40.         tmpcol = t_ent->t_col - coloff + 1;
  41.         if (tmpcol < width)
  42.         {
  43.             for(nameptr = t_ent->t_name; *nameptr != '\0';nameptr++)
  44.             {
  45.                 if (tmpcol > 1)
  46.                 {
  47. #ifdef MOUSE
  48.                     if (startcol == 0)
  49.                         startcol = tmpcol;
  50.                     stopcol = tmpcol;
  51. #endif
  52.                     poke_w(row, tmpcol, attr, *nameptr);
  53.                 }
  54.     
  55.                 if (++tmpcol >= width)
  56.                     break;
  57.             }
  58.         }
  59. #ifdef MOUSE
  60.         mouse_add_object((unsigned char)(awrow + row - 1),
  61.                               (unsigned char)(awcol + startcol - 1),
  62.                               (unsigned char)(awrow + row - 1),
  63.                               (unsigned char)(awcol + stopcol -1),
  64.                               0, mouseid, NULL);
  65. #endif
  66.         while (tmpcol < width)
  67.         {
  68.             if (tmpcol > 1)
  69.                 poke_w(row, tmpcol, NORMAL, ' ');
  70.             tmpcol++;
  71.         }
  72.     
  73.         tmpcol = t_ent->t_col - coloff - 1;
  74.         if (t_ent->t_parent != -1)
  75.         {
  76.             if (tmpcol > 1 && tmpcol < width)
  77.                 poke_w(row, tmpcol, GRAPHIC | NORMAL, (t_ent->t_next == -1) ? LLEFT : LEFTT);
  78.             if (tmpcol + 1 > 1 && tmpcol + 1 < width)
  79.                 poke_w(row, tmpcol + 1, GRAPHIC | NORMAL, HORIZ);
  80.             t_parent = t_ent;
  81.             do
  82.             {
  83.                 t_parent = t_idxfind(tp, t_parent->t_parent);
  84.                 tmpcol = t_parent->t_col - coloff - 1;
  85.                 if (tmpcol > 1 && tmpcol < width)
  86.                 {
  87.                     if (t_parent->t_next != -1)
  88.                         poke_w(row, tmpcol, GRAPHIC | NORMAL, VERT);
  89.                     else
  90.                         poke_w(row, tmpcol, NORMAL, ' ');
  91.                 }
  92.                 if (tmpcol + 1 > 1 && tmpcol + 1 < width)
  93.                     poke_w(row, tmpcol + 1, NORMAL, ' ');
  94.             }
  95.             while(t_parent->t_parent != -1);
  96.         }
  97.     }
  98.     else
  99.     {
  100.         for (tmpcol = 0; tmpcol < width - 2; tmpcol++)
  101.             poke_w(row, tmpcol + 2, NORMAL, ' ');
  102.     }
  103. }
  104.  
  105. #ifdef UNIX
  106. int t_scroll(winhd, tp, nameptr, helpnum, va_alist)
  107. int *winhd;
  108. TREE *tp;
  109. char *nameptr;
  110. int helpnum;
  111. va_dcl
  112. #else
  113. int t_scroll(int *winhd, TREE *tp, char *nameptr, int helpnum, int va_alist, ...)
  114. #endif
  115. {
  116.     int row, col, height, width;
  117.     int rowoff = 0;
  118.     int coloff = 0;
  119.     int ctr;
  120.     struct tree_entry *t_ent;
  121.     int kk;
  122.     int maxrowoff;
  123.     int selrow = 1;
  124.     int find;
  125.     int tmpcol;
  126.     char *tmpbuf;
  127.     va_list ap;
  128.     int spkey;
  129.     int mouse_sel;
  130.  
  131.     sel_w(winhd);
  132.     abs_w(&row, &col, &width, &height);
  133.     row++;
  134.     col++;
  135.  
  136.     maxrowoff = tp->num_members - (height - 2);
  137.     if (maxrowoff < 0)
  138.         maxrowoff = 0;
  139.     if (tp->uniq == NOUNIQ)
  140.         tmpbuf = alloc(MAXPATHLEN + 1);
  141.  
  142.     if ((t_ent = t_namefind(tp, nameptr)) != NULL)
  143.     {
  144.         if (t_ent->t_row > rowoff + height - 2)
  145.         {
  146.             rowoff = t_ent->t_row - height + 2;
  147.             selrow = height - 2;
  148.         }
  149.         else
  150.             selrow = t_ent->t_row - rowoff;
  151.     }
  152.  
  153.     do
  154.     {
  155.         if (rowoff > maxrowoff)
  156.             rowoff = maxrowoff;
  157.         if (rowoff < 0)
  158.             rowoff = 0;
  159.         if (selrow + rowoff > tp->num_members)
  160.             selrow = tp->num_members - rowoff;
  161.  
  162.         t_ent = t_rowfind(tp, selrow + rowoff);
  163.  
  164.         if ((t_ent->t_col + strlen(t_ent->t_name)) > (width - 1))
  165.             coloff = t_ent->t_col + strlen(t_ent->t_name) - (width - 1);
  166.         else
  167.             coloff = 0;
  168.  
  169.         strcpy(nameptr, t_ent->t_name);
  170.         if (tp->uniq == NOUNIQ)
  171.         {
  172.             while(t_ent->t_parent != -1)
  173.             {
  174.                 t_ent = t_idxfind(tp, t_ent->t_parent);
  175.                 strcpy(tmpbuf, t_ent->t_name);
  176.                 addslash(tmpbuf);
  177.                 strcat(tmpbuf, nameptr);
  178.                 strcpy(nameptr, tmpbuf);
  179.             }
  180.         }
  181.  
  182.         ndisp_w(1, 2, REVVID, width - 2, nameptr);
  183.  
  184. #ifdef MOUSE
  185.         mouse_add_object((unsigned char)row, (unsigned char)col + 1,
  186.                     (unsigned char)row, (unsigned char)col + width - 2,
  187.                     K_UP, 1, NULL);
  188.         mouse_add_object((unsigned char)row + 1, (unsigned char)col,
  189.                     (unsigned char)row + height - 2, (unsigned char)col,
  190.                     K_LEFT, 2, NULL);
  191.         mouse_add_object((unsigned char)row + 1, (unsigned char)col + width - 1,
  192.                     (unsigned char)row + height - 2, (unsigned char)col + width - 1,
  193.                     K_RIGHT, 3, NULL);
  194.         mouse_add_object((unsigned char)row + height - 1, (unsigned char)col + 1,
  195.                     (unsigned char)row + height - 1, (unsigned char)col + width - 2,
  196.                     K_DOWN, 4, NULL);
  197. #endif
  198.  
  199.         for (ctr = 1; ctr < height - 1; ctr++)
  200.         {
  201.             t_ent = t_rowfind(tp, ctr + rowoff);
  202.             branch_dsp(ctr + 1, coloff, width, tp, t_ent, (selrow == ctr) ? REVVID : NORMAL, row, col, ctr + 4);
  203.         }
  204.  
  205.         kk = inchar();
  206.         ichar = kk;
  207.  
  208. # ifdef UNIX
  209.         va_start(ap);
  210.         spkey = va_arg(ap, int);
  211. # else
  212.         va_start(ap, va_alist);
  213.         spkey = va_alist;
  214. # endif
  215.  
  216.         while (spkey != 0)
  217.         {
  218.             if (kk == spkey)
  219.             {
  220.                 kk = K_CR;
  221.                 break;
  222.             }
  223.             spkey = va_arg(ap, int);
  224.         }
  225.         va_end(ap);
  226.  
  227.         switch(kk)
  228.         {
  229. #ifdef MOUSE
  230.             case M_PRESS:
  231.                 if (!mouse_check_bounds())
  232.                     break;
  233.             case M_RELEASE:
  234.                 if (mouse_click(&mouse_sel, kk))
  235.                     if (mouse_sel >= 5)
  236.                         selrow = mouse_sel - 4;
  237.                 break;
  238. #endif
  239.             case '?':
  240.             case K_HELP:
  241.                 help_msg(helpnum);
  242.                 break;
  243.             case K_UP:
  244.                 t_ent = t_rowfind(tp, selrow + rowoff);
  245.                 tmpcol = t_ent->t_col;
  246.                 find = selrow + rowoff - 1;
  247.                 while (find > 0)
  248.                 {
  249.                     t_ent = t_rowfind(tp, find--);
  250.                     if (t_ent->t_col == tmpcol)
  251.                         break;
  252.                 }
  253.                 if (t_ent->t_col == tmpcol)
  254.                 {
  255.                     if (t_ent->t_row < rowoff + 1)
  256.                     {
  257.                         rowoff = t_ent->t_row - 1;
  258.                         selrow = 1;
  259.                     }
  260.                     else
  261.                         selrow = t_ent->t_row - rowoff;
  262.                     break;
  263.                 }
  264.             case K_LEFT:
  265.                 t_ent = t_rowfind(tp, selrow + rowoff);
  266.                 if (t_ent->t_parent != -1)
  267.                 {
  268.                     t_ent = t_idxfind(tp, t_ent->t_parent);
  269.                     if (t_ent->t_row < rowoff + 1)
  270.                     {
  271.                         rowoff = t_ent->t_row - 1;
  272.                         selrow = 1;
  273.                     }
  274.                     else
  275.                         selrow = t_ent->t_row - rowoff;
  276.                 }
  277.                 break;
  278.             case K_DOWN:
  279.                 t_ent = t_rowfind(tp, selrow + rowoff);
  280.                 tmpcol = t_ent->t_col;
  281.                 find = selrow + rowoff + 1;
  282.                 while(find <= tp->num_members)
  283.                 {
  284.                     t_ent = t_rowfind(tp, find++);
  285.                     if (t_ent->t_col == tmpcol)
  286.                         break;
  287.                 }
  288.                 if (t_ent->t_col == tmpcol)
  289.                 {
  290.                     if (t_ent->t_row > rowoff + height - 2)
  291.                     {
  292.                         rowoff = t_ent->t_row - height + 2;
  293.                         selrow = height - 2;
  294.                     }
  295.                     else
  296.                         selrow = t_ent->t_row - rowoff;
  297.                     break;
  298.                 }
  299.             case K_RIGHT:
  300.                 if (selrow < (height - 2))
  301.                     selrow++;
  302.                 else
  303.                     rowoff++;
  304.                 break;
  305.             case K_HOME:
  306.                 selrow = 1;
  307.                 rowoff = 0;
  308.                 break;
  309.             case K_END:
  310.                 selrow = height - 2;
  311.                 rowoff = maxrowoff;
  312.                 break;
  313.             case K_PGDN:
  314.                 if (selrow < (height - 2))
  315.                     selrow = height - 2;
  316.                 else
  317.                     rowoff += (height - 3);
  318.                 break;
  319.             case K_PGUP:
  320.                 if (selrow > 1)
  321.                     selrow = 1;
  322.                 else
  323.                     rowoff -= (height - 3);
  324.                 break;
  325.             case K_CR:
  326.             case K_ESC:
  327.                 break;
  328.             default:
  329.                 if (isalpha(kk))
  330.                 {
  331. #ifdef MSDOS
  332.                     if (islower(kk))
  333.                         kk = toupper(kk);
  334. #endif
  335.                     for(find = selrow + rowoff + 1; find <= tp->num_members; find++)
  336.                     {
  337.                         t_ent = t_rowfind(tp, find);
  338.                         if ((int)t_ent->t_name[0] == kk)
  339.                             break;
  340.                     }
  341.                     if (find > tp->num_members)
  342.                     {
  343.                         for(find = 1; find < selrow + rowoff + 1; find++)
  344.                         {
  345.                             t_ent = t_rowfind(tp, find);
  346.                             if ((int)t_ent->t_name[0] == kk)
  347.                                 break;
  348.                         }
  349.                     }
  350.                     if ((int)t_ent->t_name[0] == kk)
  351.                     {
  352.                         if (find > selrow + rowoff)
  353.                         {
  354.                             if (t_ent->t_row > rowoff + height - 2)
  355.                             {
  356.                                 rowoff = t_ent->t_row - height + 2;
  357.                                 selrow = height - 2;
  358.                             }
  359.                             else
  360.                                 selrow = t_ent->t_row - rowoff;
  361.                         }
  362.                         else if (find < selrow + rowoff)
  363.                         {
  364.                             if (t_ent->t_row < rowoff + 1)
  365.                             {
  366.                                 rowoff = t_ent->t_row - 1;
  367.                                 selrow = 1;
  368.                             }
  369.                             else
  370.                                 selrow = t_ent->t_row - rowoff;
  371.                         }
  372.                     }
  373.                 }
  374.                 break;
  375.         }
  376. #ifdef MOUSE
  377.         mouse_delete_notkeys();
  378. #endif
  379.     }
  380.     while (kk != K_ESC && kk != K_CR);
  381.  
  382.     t_ent = t_rowfind(tp, selrow + rowoff);
  383.     branch_dsp(selrow + 1, coloff, width, tp, t_ent, BOLD, row, col, selrow + 4);
  384.  
  385.     if (tp->uniq == NOUNIQ)
  386.         free(tmpbuf);
  387.  
  388.     if (kk == K_ESC)
  389.         return(-1);
  390.  
  391.     return(0);
  392. }
  393.