home *** CD-ROM | disk | FTP | other *** search
- /*
- * AREAS.C - Message area display
- *
- * Msged/Q message editor for QuickBBS Copyright 1990 by P.J. Muller
- *
- * Message area adapted from Johan Zwiekhorst's modifications to Msged
- *
- */
-
- /* #define SPEEDUP */ /* (not significant) */
-
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- #include "msged.h"
- #include "screen.h"
- #include "qmsgbase.h"
-
- static BOOLEAN showdesc = TRUE; /* tag/description flag */
-
- #define MENUWIDTH 23
-
- static int aROWS, aCOLS, aMAX; /* per page */
-
- #define INDIC '\20' /* Triangle pointing to the right */
-
- #define NormalVideo 0
- #define ReverseVideo 1
-
- #ifdef SPEEDUP
- static int *keeplastmsg=NULL; /* array for speedup */
- static void initspeedup(void);
- static void donespeedup(void);
- static int LASTMSG(BYTE b);
- #else /* disable everything */
- # define LASTMSG(b) lastmsg(b)
- # define initspeedup();
- # define donespeedup();
- #endif
-
- void display_area(int anum, int textcolor);
- void display_page(int pnum, int pmax);
- static void dop(char *title);
-
- #ifdef SPEEDUP
- /*
- * Initialise mechanism for speeding up Alt-T
- */
-
- static void initspeedup(void)
- {
- int c;
-
- if (keeplastmsg == NULL)
- if ((keeplastmsg = malloc(sizeof(int)*BLIM)) == NULL)
- return;
-
- for (c=0; c < BLIM; c++)
- keeplastmsg[c] = -1;
- } /* initspeedup */
-
- static void donespeedup(void)
- {
- if (keeplastmsg == NULL)
- return;
-
- ptrfree(keeplastmsg);
- keeplastmsg = NULL;
- } /* donespeedup */
-
- static int LASTMSG(BYTE b)
- {
- if (keeplastmsg == NULL) {
- return lastmsg(b);
- } else {
- if (keeplastmsg[b-1] == -1)
- return keeplastmsg[b-1] = lastmsg(b);
- else
- return keeplastmsg[b-1];
- } /* else */
- } /* LASTMSG */
- #endif /* SPEEDUP */
-
- /*
- * Draw the surroundings
- */
-
- static void dop(char *title)
- {
- int x,y;
-
- set_color(co_normal);
- cls();
-
- /* Draw frame */
-
- #ifdef NOIBM
- for (x = 2; x < maxx; x++) {
- gotoxy(x, 1); bputc('-');
- gotoxy(x, 6); bputc('-');
- gotoxy(x,maxy+1); bputc('-');
- }
- for (y = 2; y < maxy; y++) {
- gotoxy( 1,y); bputc('|');
- gotoxy(maxx,y); bputc('|');
- }
- gotoxy( 1, 1); bputc('/'); gotoxy(maxx, 1); bputc('\\');
- gotoxy( 1,maxy); bputc('\\'); gotoxy(maxx,maxy); bputc('/');
- #else
- for (x = 2; x < maxx; x++) {
- gotoxy(x, 1); bputc('─');
- gotoxy(x, 6); bputc('─');
- gotoxy(x,maxy+1); bputc('─');
- }
- for (y = 2; y < maxy; y++) {
- gotoxy( 1,y); bputc('│');
- gotoxy(maxx,y); bputc('│');
- }
- gotoxy( 1, 1); bputc('┌'); gotoxy(maxx, 1); bputc('┐');
- gotoxy( 1, 6); bputc('├'); gotoxy(maxx, 6); bputc('┤');
- gotoxy( 1,maxy); bputc('└'); gotoxy(maxx,maxy); bputc('┘');
- #endif
-
- gotoxy((maxx-57)/2, 2);
- bputs("Position cursor on desired area with the arrow keys, then");
- gotoxy((maxx-57)/2, 3);
- bputs("press <Enter> to select. <Alt-H> for Help Page.");
-
- set_color(co_info);
- if (title == NULL)
- title = "SELECT A MESSAGE AREA";
- gotoxy((maxx-strlen(title))/2, 1);
- bprintf(" %s ", title);
- set_color(co_normal);
-
- gotoxy(1,maxy);
- video_update();
- } /* dop */
-
- /* selectarea() returns -1 when aborted */
-
- int selectarea(char *title)
- {
- int y, ch=0, a=area, p=0, b;
- int pagenum=1, pagemax;
- char maybe[MENUWIDTH+1];
- char *adesc;
-
- if (areas <= 0) return -1;
-
- memset(maybe, 0, sizeof(maybe));
-
- aROWS = maxy-9;
- aCOLS = (maxx-4)/(MENUWIDTH+2);
- aMAX = (aROWS*aCOLS);
- dop(title);
-
- initspeedup();
-
- /* Display area descriptions */
-
- pagenum = a/aMAX + 1;
- pagemax = (areas-1)/aMAX + 1;
- display_page(pagenum, pagemax);
-
- /* get keys until ENTER or ESC pressed */
-
- while ((ch != ENTER) && (ch != ABORT)) {
- display_area(a, ReverseVideo);
-
- gotoxy((maxx-52), 5);
- set_color(co_info);
- y = countmsg(arealist[a].board);
- if (y == 0)
- bputs(" no");
- else
- bprintf("%4d",y);
- y -= boardmsg(arealist[a].board,lastreadmsg(arealist[a].board));
- bputs(" messages in current area,");
- if (y == 0)
- bputs(" none unread. ");
- else
- bprintf("%5d unread. ",y);
- set_color(co_normal);
-
- ch = getkey();
-
- display_area(a, NormalVideo);
-
- switch (ch) {
-
- case TOGGLE: /* toggle */
- showdesc = !showdesc;
- memset(maybe, 0, sizeof(maybe));
- p = 0;
- display_page(pagenum, pagemax);
- break;
-
- case LEFT:
- p=0; memset(maybe, 0, sizeof(maybe));
- if ((a % aMAX) >= aROWS)
- a -= aROWS;
- break;
-
- case RIGHT:
- p=0; memset(maybe, 0, sizeof(maybe));
- if ((a + aROWS) < min(areas,aMAX*pagenum))
- a += aROWS;
- break;
-
- case UP:
- p=0; memset(maybe, 0, sizeof(maybe));
- if (a > 0) {
- a--;
- if ((a+1) == (aMAX*(pagenum-1))) {
- pagenum--;
- display_page(pagenum,pagemax);
- }
- }
- break;
-
- case DOWN:
- p=0; memset(maybe, 0, sizeof(maybe));
- if (a < (areas-1)) {
- a++;
- if (a == (aMAX*pagenum)) {
- pagenum++;
- display_page(pagenum,pagemax);
- }
- }
- break;
-
- case '+': {
- int look = a; /* look for next board with mail */
- while ((++look >= areas ? look = 0 : look) != a)
- if (lastreadmsg(arealist[look].board) < LASTMSG(arealist[look].board))
- break;
- if (look != a) {
- p=0; memset(maybe, 0, sizeof(maybe));
- a = look;
- }
- b = a/aMAX + 1;
- if (pagenum != b) {
- pagenum = b;
- display_page(pagenum,pagemax);
- }
- break;
- }
-
- case '-': {
- int look = a; /* look for next board with mail */
- while ((--look < 0 ? look = areas-1 : look) != a)
- if (lastreadmsg(arealist[look].board) < LASTMSG(arealist[look].board))
- break;
- if (look != a) {
- p=0; memset(maybe, 0, sizeof(maybe));
- a = look;
- }
- b = a/aMAX + 1;
- if (pagenum != b) {
- pagenum = b;
- display_page(pagenum,pagemax);
- }
- break;
- }
-
- case GOBOL:
- p=0; memset(maybe, 0, sizeof(maybe));
- /* a = aMAX * (pagenum - 1); */
- a = 0;
- if (pagenum != 1) {
- pagenum = 1;
- display_page(pagenum,pagemax);
- }
- break;
-
- case GOEOL:
- p=0; memset(maybe, 0, sizeof(maybe));
- /* a = aMAX * pagenum - 1;
- if (a >= areas) */
- a = areas-1;
- if (pagenum != pagemax) {
- pagenum = pagemax;
- display_page(pagenum,pagemax);
- }
- break;
-
- case PGUP:
- p=0; memset(maybe, 0, sizeof(maybe));
- if (a % aROWS != 0) {
- a -= a % aROWS;
- } else if (pagenum > 1) {
- pagenum--;
- a = aMAX * (pagenum - 1);
- display_page(pagenum, pagemax);
- }
- break;
-
- case PGDN:
- p=0; memset(maybe, 0, sizeof(maybe));
- if (a % aROWS != aROWS-1) {
- a += aROWS - (a % aROWS) - 1;
- if (a >= areas)
- a = areas-1;
- } else if (pagenum < pagemax) {
- pagenum++;
- a = aMAX * (pagenum - 1);
- display_page(pagenum, pagemax);
- }
- break;
-
- case ENTER:
- donespeedup();
- return(a);
-
- case ABORT:
- donespeedup();
- return(-1);
-
- case HELP:
- helparea();
- dop(title);
- display_page(pagenum, pagemax);
- break;
-
- case DONE2:
- cleanup();
- break;
-
- default:
- if ((ch & 0xff) == 0) break;
- maybe[p++] = (unsigned char)(ch & 0xff);
- for (b = 0; b < areas; b++) {
- adesc = strlwr(strdup(arealist[b].description));
- if (strncmp(strlwr(maybe), adesc, strlen(maybe)) == 0)
- a = b;
- ptrfree(adesc);
- }
- b = a/aMAX + 1;
- if (pagenum != b) {
- pagenum = b;
- display_page(pagenum,pagemax);
- }
- }
- } /* while */
- donespeedup();
- return(area);
- } /* selectarea */
-
- void display_page(int pnum, int pmax)
- {
- int anum, count;
-
- gotoxy( 3, 5);
- set_color(co_quote);
- bprintf("Page %d of %d",pnum,pmax);
- set_color(co_normal);
- clrwnd(3,8,maxx-2,maxy-2);
- anum = aMAX * (pnum - 1);
- count = 1;
- while ((anum < areas) && (count++ <= aMAX))
- display_area(anum++, NormalVideo);
- } /* display_page */
-
- void display_area(int anum, int reversecolor)
- {
- int a, x, y;
- char desc[MENUWIDTH+1];
-
- a = anum % aMAX;
- x = (MENUWIDTH+2) * (a / aROWS) + 3;
- y = 8 + (a % aROWS);
- gotoxy(x+1, y);
-
- set_color(co_info);
- if (lastreadmsg(arealist[anum].board) < LASTMSG(arealist[anum].board))
- bputc(INDIC);
- else
- bputc(' ');
-
- if (reversecolor)
- set_color(co_hilite);
- else
- set_color(co_normal);
- if (!showdesc) {
- char buf[80];
- sprintf(buf,"%3d %1.70s", arealist[anum].board, arealist[anum].tag);
- strncpy(desc, buf, MENUWIDTH);
- } else {
- strncpy(desc, arealist[anum].description, MENUWIDTH);
- } /* else */
- desc[MENUWIDTH] = '\0';
- bputs(desc);
- set_color(co_normal);
- } /* display_area */