home *** CD-ROM | disk | FTP | other *** search
- /* ===( tscroll.c )=== */
-
- /*
- * Contains scrolling window function(s) for 'generic' trees
- */
- #include <stdio.h>
- #include <bench.h>
- #include <tree.h>
- #include <dirw.h>
-
- #ifdef ANSI
- static void branch_dsp(int, int, int, TREE *, struct tree_entry *, int, int, int, int);
- #else
- static void branch_dsp();
- #endif
-
- extern struct window_rec *winptr;
-
- static void branch_dsp(row, coloff, width, tp, t_ent, attr, awrow, awcol, mouseid)
- int row;
- int coloff;
- int width;
- TREE *tp;
- struct tree_entry *t_ent;
- int attr;
- int awrow;
- int awcol;
- int mouseid;
- {
- struct tree_entry *t_parent;
- int tmpcol;
- char *nameptr;
- #ifdef MOUSE
- int startcol = 0;
- int stopcol;
- #endif
-
- if (t_ent != NULL)
- {
- tmpcol = t_ent->t_col - coloff + 1;
- if (tmpcol < width)
- {
- for(nameptr = t_ent->t_name; *nameptr != '\0';nameptr++)
- {
- if (tmpcol > 1)
- {
- #ifdef MOUSE
- if (startcol == 0)
- startcol = tmpcol;
- stopcol = tmpcol;
- #endif
- poke_w(row, tmpcol, attr, *nameptr);
- }
-
- if (++tmpcol >= width)
- break;
- }
- }
- #ifdef MOUSE
- mouse_add_object((unsigned char)(awrow + row - 1),
- (unsigned char)(awcol + startcol - 1),
- (unsigned char)(awrow + row - 1),
- (unsigned char)(awcol + stopcol -1),
- 0, mouseid, NULL);
- #endif
- while (tmpcol < width)
- {
- if (tmpcol > 1)
- poke_w(row, tmpcol, NORMAL, ' ');
- tmpcol++;
- }
-
- tmpcol = t_ent->t_col - coloff - 1;
- if (t_ent->t_parent != -1)
- {
- if (tmpcol > 1 && tmpcol < width)
- poke_w(row, tmpcol, GRAPHIC | NORMAL, (t_ent->t_next == -1) ? LLEFT : LEFTT);
- if (tmpcol + 1 > 1 && tmpcol + 1 < width)
- poke_w(row, tmpcol + 1, GRAPHIC | NORMAL, HORIZ);
- t_parent = t_ent;
- do
- {
- t_parent = t_idxfind(tp, t_parent->t_parent);
- tmpcol = t_parent->t_col - coloff - 1;
- if (tmpcol > 1 && tmpcol < width)
- {
- if (t_parent->t_next != -1)
- poke_w(row, tmpcol, GRAPHIC | NORMAL, VERT);
- else
- poke_w(row, tmpcol, NORMAL, ' ');
- }
- if (tmpcol + 1 > 1 && tmpcol + 1 < width)
- poke_w(row, tmpcol + 1, NORMAL, ' ');
- }
- while(t_parent->t_parent != -1);
- }
- }
- else
- {
- for (tmpcol = 0; tmpcol < width - 2; tmpcol++)
- poke_w(row, tmpcol + 2, NORMAL, ' ');
- }
- }
-
- #ifdef UNIX
- int t_scroll(winhd, tp, nameptr, helpnum, va_alist)
- int *winhd;
- TREE *tp;
- char *nameptr;
- int helpnum;
- va_dcl
- #else
- int t_scroll(int *winhd, TREE *tp, char *nameptr, int helpnum, int va_alist, ...)
- #endif
- {
- int row, col, height, width;
- int rowoff = 0;
- int coloff = 0;
- int ctr;
- struct tree_entry *t_ent;
- int kk;
- int maxrowoff;
- int selrow = 1;
- int find;
- int tmpcol;
- char *tmpbuf;
- va_list ap;
- int spkey;
- int mouse_sel;
-
- sel_w(winhd);
- abs_w(&row, &col, &width, &height);
- row++;
- col++;
-
- maxrowoff = tp->num_members - (height - 2);
- if (maxrowoff < 0)
- maxrowoff = 0;
- if (tp->uniq == NOUNIQ)
- tmpbuf = alloc(MAXPATHLEN + 1);
-
- if ((t_ent = t_namefind(tp, nameptr)) != NULL)
- {
- if (t_ent->t_row > rowoff + height - 2)
- {
- rowoff = t_ent->t_row - height + 2;
- selrow = height - 2;
- }
- else
- selrow = t_ent->t_row - rowoff;
- }
-
- do
- {
- if (rowoff > maxrowoff)
- rowoff = maxrowoff;
- if (rowoff < 0)
- rowoff = 0;
- if (selrow + rowoff > tp->num_members)
- selrow = tp->num_members - rowoff;
-
- t_ent = t_rowfind(tp, selrow + rowoff);
-
- if ((t_ent->t_col + strlen(t_ent->t_name)) > (width - 1))
- coloff = t_ent->t_col + strlen(t_ent->t_name) - (width - 1);
- else
- coloff = 0;
-
- strcpy(nameptr, t_ent->t_name);
- if (tp->uniq == NOUNIQ)
- {
- while(t_ent->t_parent != -1)
- {
- t_ent = t_idxfind(tp, t_ent->t_parent);
- strcpy(tmpbuf, t_ent->t_name);
- addslash(tmpbuf);
- strcat(tmpbuf, nameptr);
- strcpy(nameptr, tmpbuf);
- }
- }
-
- ndisp_w(1, 2, REVVID, width - 2, nameptr);
-
- #ifdef MOUSE
- mouse_add_object((unsigned char)row, (unsigned char)col + 1,
- (unsigned char)row, (unsigned char)col + width - 2,
- K_UP, 1, NULL);
- mouse_add_object((unsigned char)row + 1, (unsigned char)col,
- (unsigned char)row + height - 2, (unsigned char)col,
- K_LEFT, 2, NULL);
- mouse_add_object((unsigned char)row + 1, (unsigned char)col + width - 1,
- (unsigned char)row + height - 2, (unsigned char)col + width - 1,
- K_RIGHT, 3, NULL);
- mouse_add_object((unsigned char)row + height - 1, (unsigned char)col + 1,
- (unsigned char)row + height - 1, (unsigned char)col + width - 2,
- K_DOWN, 4, NULL);
- #endif
-
- for (ctr = 1; ctr < height - 1; ctr++)
- {
- t_ent = t_rowfind(tp, ctr + rowoff);
- branch_dsp(ctr + 1, coloff, width, tp, t_ent, (selrow == ctr) ? REVVID : NORMAL, row, col, ctr + 4);
- }
-
- kk = inchar();
- ichar = kk;
-
- # ifdef UNIX
- va_start(ap);
- spkey = va_arg(ap, int);
- # else
- va_start(ap, va_alist);
- spkey = va_alist;
- # endif
-
- while (spkey != 0)
- {
- if (kk == spkey)
- {
- kk = K_CR;
- break;
- }
- spkey = va_arg(ap, int);
- }
- va_end(ap);
-
- switch(kk)
- {
- #ifdef MOUSE
- case M_PRESS:
- if (!mouse_check_bounds())
- break;
- case M_RELEASE:
- if (mouse_click(&mouse_sel, kk))
- if (mouse_sel >= 5)
- selrow = mouse_sel - 4;
- break;
- #endif
- case '?':
- case K_HELP:
- help_msg(helpnum);
- break;
- case K_UP:
- t_ent = t_rowfind(tp, selrow + rowoff);
- tmpcol = t_ent->t_col;
- find = selrow + rowoff - 1;
- while (find > 0)
- {
- t_ent = t_rowfind(tp, find--);
- if (t_ent->t_col == tmpcol)
- break;
- }
- if (t_ent->t_col == tmpcol)
- {
- if (t_ent->t_row < rowoff + 1)
- {
- rowoff = t_ent->t_row - 1;
- selrow = 1;
- }
- else
- selrow = t_ent->t_row - rowoff;
- break;
- }
- case K_LEFT:
- t_ent = t_rowfind(tp, selrow + rowoff);
- if (t_ent->t_parent != -1)
- {
- t_ent = t_idxfind(tp, t_ent->t_parent);
- if (t_ent->t_row < rowoff + 1)
- {
- rowoff = t_ent->t_row - 1;
- selrow = 1;
- }
- else
- selrow = t_ent->t_row - rowoff;
- }
- break;
- case K_DOWN:
- t_ent = t_rowfind(tp, selrow + rowoff);
- tmpcol = t_ent->t_col;
- find = selrow + rowoff + 1;
- while(find <= tp->num_members)
- {
- t_ent = t_rowfind(tp, find++);
- if (t_ent->t_col == tmpcol)
- break;
- }
- if (t_ent->t_col == tmpcol)
- {
- if (t_ent->t_row > rowoff + height - 2)
- {
- rowoff = t_ent->t_row - height + 2;
- selrow = height - 2;
- }
- else
- selrow = t_ent->t_row - rowoff;
- break;
- }
- case K_RIGHT:
- if (selrow < (height - 2))
- selrow++;
- else
- rowoff++;
- break;
- case K_HOME:
- selrow = 1;
- rowoff = 0;
- break;
- case K_END:
- selrow = height - 2;
- rowoff = maxrowoff;
- break;
- case K_PGDN:
- if (selrow < (height - 2))
- selrow = height - 2;
- else
- rowoff += (height - 3);
- break;
- case K_PGUP:
- if (selrow > 1)
- selrow = 1;
- else
- rowoff -= (height - 3);
- break;
- case K_CR:
- case K_ESC:
- break;
- default:
- if (isalpha(kk))
- {
- #ifdef MSDOS
- if (islower(kk))
- kk = toupper(kk);
- #endif
- for(find = selrow + rowoff + 1; find <= tp->num_members; find++)
- {
- t_ent = t_rowfind(tp, find);
- if ((int)t_ent->t_name[0] == kk)
- break;
- }
- if (find > tp->num_members)
- {
- for(find = 1; find < selrow + rowoff + 1; find++)
- {
- t_ent = t_rowfind(tp, find);
- if ((int)t_ent->t_name[0] == kk)
- break;
- }
- }
- if ((int)t_ent->t_name[0] == kk)
- {
- if (find > selrow + rowoff)
- {
- if (t_ent->t_row > rowoff + height - 2)
- {
- rowoff = t_ent->t_row - height + 2;
- selrow = height - 2;
- }
- else
- selrow = t_ent->t_row - rowoff;
- }
- else if (find < selrow + rowoff)
- {
- if (t_ent->t_row < rowoff + 1)
- {
- rowoff = t_ent->t_row - 1;
- selrow = 1;
- }
- else
- selrow = t_ent->t_row - rowoff;
- }
- }
- }
- break;
- }
- #ifdef MOUSE
- mouse_delete_notkeys();
- #endif
- }
- while (kk != K_ESC && kk != K_CR);
-
- t_ent = t_rowfind(tp, selrow + rowoff);
- branch_dsp(selrow + 1, coloff, width, tp, t_ent, BOLD, row, col, selrow + 4);
-
- if (tp->uniq == NOUNIQ)
- free(tmpbuf);
-
- if (kk == K_ESC)
- return(-1);
-
- return(0);
- }
-