home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*
- | TEGL Windows ToolKit II |
- | Copyright (C) 1990, TEGL Systems Corporation |
- | All Rights Reserved. |
- *---------------------------------------------------------------------------*/
-
- /* #include "teglsys.h" */
- #include <teglcond.h>
- #include <tgraph.h>
- #include <fastgrph.h>
- #include <teglintr.h>
- #include <fontsys.h>
- #include <virtmem.h>
- #include <ipstacks.h>
- #include <teglunit.h>
- #include <teglmain.h>
- #include <errorlog.h>
- #include <teglmenu.h>
- #include <selectfl.h>
- #include <sensems.h>
- #include <videochk.h>
- #include <iconsys.h>
- #include <teglspec.h>
- #include <teglfsio.h>
-
- #ifndef MSDOS
- #include <dir.h>
- #include <alloc.h>
- #endif
-
- #include <dos.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define maxlstrarr 16382 /* -- MaxInt DIV 2 */
-
- typedef char *lstr; /* -- pointer to char string */
-
- typedef lstr lstrarr[maxlstrarr];
-
- typedef struct fileviewrec *fileviewptr;
- typedef struct fileviewrec {
- fileviewptr nextfileview;
- imagestkptr fs;
- lstrarr *data;
- int lastline;
- int offset;
- int coloff;
- unsigned maxrow;
- unsigned maxbitlen;
- unsigned divisons;
- char filename[71];
- fontptr fonttable;
- } fileviewrec;
-
- #define arraymax 2000
-
- fileviewptr anchorfileview = NULL;
- optionmptr om1, om2, om3;
- char path[80];
-
- unsigned exitoption(imagestkptr frame, msclickptr mouseclickpos)
- {
- logmessage("Thank you for using our TEGL View Program...");
- abortexit("The source code for this program is included with the TEGL Windows Toolkit II");
- return 0;
- }
-
- unsigned infooption(imagestkptr frame, msclickptr mouseclickpos)
- {
- unsigned x, y, x1, y1;
-
- if (visualbuttonpress(frame, mouseclickpos)) {
- resetframeactive(frame->lstptr, FALSE);
-
- x = 160;
- y = 120;
- x1 = x + 360;
- y1 = y + 170;
-
- explodefrommsclick(frame,mouseclickpos,x,y,x1,y1);
-
- prepareforupdate(stackptr);
-
- setshadowcolor(WHITE);
- shadowbox(x,y,x1,y1);
- setcolor(BLACK);
- rectangle(x+3,y+3,x+355,y+165);
- rectangle(x+5,y+5,x+353,y+163);
-
- settextjustify(CENTER_TEXT,TOP_TEXT);
-
- setshadowtexttype(wndwx19); /* 5 */
- shadowtext(x+190,y+10,GREEN,"TEGLVIEW");
- setshadowtexttype(NULL);
-
- setteglfont(font14);
- extendtextxy(x+190,y+65,"Copyright (c) 1990,");
- extendtextxy(x+190,y+79,"TEGL Systems Corporation");
- extendtextxy(x+190,y+93,"All Rights Reserved");
- extendtextxy(x+190,y+120,"Written and Designed by Richard Tom");
-
- settextjustify(LEFT_TEXT,TOP_TEXT);
-
- commitupdate();
-
- definebuttonclick(stackptr,x+300,y+143,imageOK,collapsetomsclick);
-
- setmouseposition(x+310,y+153);
- }
- return 0;
- }
-
- fileviewptr findfileview(imagestkptr frame)
- {
- fileviewptr fvptr;
-
- fvptr = anchorfileview;
- while ((fvptr != NULL) && (fvptr->fs != frame))
- fvptr = fvptr->nextfileview;
-
- return fvptr;
- }
-
- void pageslideposition(fileviewptr fvptr)
- {
- unsigned x, y;
-
- x = fvptr->fs->x1 - 23;
- y = fvptr->fs->y+((fvptr->offset/fvptr->maxrow)*fvptr->divisons)+
- ((((fvptr->offset%fvptr->maxrow)*fvptr->divisons)+
- (fvptr->maxrow/2))/fvptr->maxrow)+16+23;
-
- setslideposition(fvptr->fs, x, y);
- }
-
- char *fittext(char far * mystr, fileviewptr fvptr, unsigned linenum, lstrarr mydata)
- {
- unsigned mysize;
- unsigned mylen;
-
- setteglfont(fvptr->fonttable);
- strcpy(mystr,&mydata[linenum][fvptr->coloff]);
- mysize = tegltextwidth(mystr);
- mylen = strlen(mystr);
- while (mysize > fvptr->maxbitlen) {
- mysize -= teglcharwidth(mystr[mylen - 1]);
- mystr[mylen-1] = '\0';
- mylen--;
- }
-
- while (strchr(mystr,'\t') != NULL)
- *strchr(mystr,'\t') = ' ';
-
- return mystr;
- }
-
- void display(fileviewptr fvptr)
- {
- int i;
- unsigned x, y, x1, y1;
- imagestkptr fs;
- char mystr[255];
-
- setteglfont(fvptr->fonttable);
-
- fs = fvptr->fs;
- getmargins(fs,&x,&y,&x1,&y1);
-
- gotofsxy(fs, x, y);
- prepareforupdate(fs);
- bar(fs->x+x,fs->y+y,fs->x+x1,fs->y+y1);
- for (i=1; (i<=fvptr->maxrow && fvptr->offset+i<= fvptr->lastline); i++)
- outtegltextxy(fs->x+x,fs->y+y+(i-1)*(teglcharheight()-2),
- fittext(mystr,fvptr,fvptr->offset+i,*fvptr->data));
- commitupdate();
- }
-
- unsigned pagedown(imagestkptr fs, msclickptr mouseclickpos)
- {
- int tempoff;
- fileviewptr fvptr;
-
- fvptr = findfileview(fs);
-
- tempoff = fvptr->offset;
- tempoff += fvptr->maxrow-1;
- if (tempoff>fvptr->lastline-fvptr->maxrow)
- tempoff=fvptr->lastline-fvptr->maxrow;
-
- if (tempoff != fvptr->offset) {
- fvptr->offset = tempoff;
- display(fvptr);
- pageslideposition(fvptr);
- } else {
- beep(200,1,10);
- while (mouse_buttons) {}
- }
-
- return 1;
- }
-
- unsigned pageup(imagestkptr fs, msclickptr mouseclickpos)
- {
- int tempoff;
- fileviewptr fvptr;
-
- fvptr = findfileview(fs);
-
- tempoff = fvptr->offset;
- tempoff -= fvptr->maxrow - 1;
- if (tempoff < 0)
- tempoff = 0;
-
- if (tempoff != fvptr->offset) {
- fvptr->offset = tempoff;
- display(fvptr);
- pageslideposition(fvptr);
- } else {
- beep(800,1,10);
- while (mouse_buttons) {}
- }
-
- return 1;
- }
-
- unsigned curup(imagestkptr fs, msclickptr mouseclickpos)
- {
- fileviewptr fvptr;
- unsigned x, y, x1, y1;
- char mystr[255];
-
- fvptr = findfileview(fs);
- setteglfont(fvptr->fonttable);
- getmargins(fs,&x,&y,&x1,&y1);
-
- fvptr->offset--;
- if (fvptr->offset < 0)
- fvptr->offset = 0;
- else {
- scrolldown(fs);
- prepareforpartialupdate(fs,fs->x+x,fs->y+y,fs->x+x1,fs->y+y+teglcharheight());
- outtegltextxy(fs->x+x,fs->y+y,fittext(mystr,fvptr,fvptr->offset+1,*fvptr->data));
- commitupdate();
- pageslideposition(fvptr);
- }
- return 1;
- }
-
- unsigned curdown(imagestkptr fs, msclickptr mouseclickpos)
- {
- fileviewptr fvptr;
- unsigned x, y, x1, y1;
- char mystr[255];
-
- fvptr = findfileview(fs);
- setteglfont(fvptr->fonttable);
- getmargins(fs,&x,&y,&x1,&y1);
-
- fvptr->offset++;
- if (fvptr->offset>fvptr->lastline-fvptr->maxrow)
- fvptr->offset = fvptr->lastline-fvptr->maxrow;
- else {
- scrollup(fs);
- prepareforpartialupdate(fs,fs->x+x,fs->y+y1-(teglcharheight()-2),fs->x+x1,fs->y+y1);
- outtegltextxy(fs->x+x,fs->y+y1-(teglcharheight()-2),fittext(mystr,fvptr,fvptr->offset+fvptr->maxrow,*fvptr->data));
- commitupdate();
- pageslideposition(fvptr);
- }
- return 1;
- }
-
- unsigned curleft(imagestkptr fs, msclickptr mouseclickpos)
- {
- fileviewptr fvptr;
-
- fvptr = findfileview(fs);
- setteglfont(fvptr->fonttable);
-
- fvptr->coloff++;
- if (fvptr->coloff > 100)
- fvptr->coloff = 100;
- display(fvptr);
- return 1;
- }
-
- unsigned curright(imagestkptr fs, msclickptr mouseclickpos)
- {
- fileviewptr fvptr;
-
- fvptr = findfileview(fs);
- setteglfont(fvptr->fonttable);
-
- fvptr->coloff--;
- if (fvptr->coloff < 0)
- fvptr->coloff = 0;
- display(fvptr);
- return 1;
- }
-
- void freelstr(lstr * s)
- {
- if (*s != NULL)
- cfreemem(*s,(unsigned long) strlen(*s)+1);
- *s = NULL;
- }
-
- void allocatelstrarr(lstrarr **data,unsigned limit)
- {
- *data = (lstrarr *) cgetmem((unsigned long) (limit+1)*4); /* -- array is 0 .. limit */
- memset(*data,0,(limit+1)*4); /* clear array */
- }
-
- void disposelstrarr(lstrarr data,unsigned limit)
- {
- unsigned count;
-
- for (count = 0; count <= limit; count++) /* -- send off pointers to free */
- freelstr(&data[count]); /* -- up memory */
-
- cfreemem(data,(unsigned long) (limit+1)*4);
- *data = NULL;
- }
-
- void store(lstr * s, char * s2)
- {
- freelstr(s); /* -- free up memory already used */
- *s = (lstr) cgetmem((unsigned long) strlen(s2)+1); /* -- get memory to store new string */
- strcpy(*s,s2);
- }
-
- char readfilelstr(char * filename, int * lastline, int limit, lstrarr data)
- {
- FILE *inputfile;
- char inputline[255];
- char readok;
-
- readok = TRUE;
- *lastline = 0;
-
- if ((inputfile=fopen(filename,"rt")) != NULL) {
-
- fgets(inputline,255,inputfile);
- do {
- if (strstr(inputline,"\n") != NULL)
- *strstr(inputline,"\n")='\0';
-
- if (strstr(inputline,"\r") != NULL)
- *strstr(inputline,"\r")='\0';
-
- (*lastline)++; /* -- inc line counter */
-
- store(&data[*lastline],inputline); /* -- allocate mem and store the string */
-
- fgets(inputline,255,inputfile);
- } while (!feof(inputfile) && (*lastline != limit));
- }
-
- if (*lastline == limit || inputfile==NULL) /* -- out of line space */
- {
- readok = FALSE;
- disposelstrarr(data,limit); /* -- free up heap */
- *lastline = 0; /* -- reset upper bound */
- }
-
- fclose(inputfile);
- return readok;
- }
-
- void dropfileview(imagestkptr fs)
- {
- fileviewptr nfvptr, lfvptr;
-
- lfvptr = (fileviewptr) NULL;
- nfvptr = anchorfileview;
- while ((nfvptr != NULL) && (nfvptr->fs != fs)) {
- lfvptr = nfvptr;
- nfvptr = nfvptr->nextfileview;
- }
-
- if (nfvptr != NULL) {
- if (lfvptr == NULL)
- anchorfileview = nfvptr->nextfileview;
- else
- lfvptr->nextfileview = nfvptr->nextfileview;
-
- cfreemem(nfvptr,(unsigned long) sizeof(*nfvptr));
- }
- }
-
- unsigned docquit(imagestkptr fs, msclickptr mouseclickpos)
- {
- fileviewptr fvptr;
-
- fvptr = findfileview(fs);
- disposelstrarr(*(fvptr->data), arraymax);
- closefsio(fs);
- dropfileview(fs);
- dropsliders(fs);
- dropstackimage(fs);
- return 1;
- }
-
- unsigned slidedoc(imagestkptr fs, msclickptr mouseclickpos)
- {
- fileviewptr fvptr;
- sliderptr slptr;
- unsigned diff;
- int tempoff;
-
- fvptr = findfileview(fs);
- slptr = findsliderfs(fs, mouseclickpos);
- if (slptr == NULL)
- aborterror("Unable to located Slider Information.",240);
-
- diff = (int) ((mouseclickpos->ms.y - slptr->miny));
- tempoff = ((diff/fvptr->divisons)*fvptr->maxrow)+(diff%fvptr->divisons);
-
- if (tempoff > fvptr->lastline - fvptr->maxrow)
- tempoff = fvptr->lastline - fvptr->maxrow;
-
- if (tempoff != fvptr->offset) {
- fvptr->offset = tempoff;
- display(fvptr);
- } else {
- beep(800, 1, 10);
- while (mouse_buttons) {}
- }
-
- return 1;
- }
-
- unsigned docwindow(imagestkptr fs, msclickptr mouseclickpos)
- {
- unsigned x, y, x1, y1;
- unsigned pages;
- unsigned barlength;
- fileviewptr fvptr;
-
- resetmouseclicks(fs, NULL);
- closefsio(fs);
- dropsliders(fs);
- fvptr = findfileview(fs);
-
- x = fs->x;
- y = fs->y;
- x1 = fs->x1;
- y1 = fs->y1;
-
- prepareforupdate(fs);
- setshadowcolor(WHITE);
- shadowbox(x, y, x1, y1);
-
- setteglfont(fvptr->fonttable);
-
- fvptr->maxbitlen=x1-x-40;
- fvptr->maxrow=((y1-y-55)/(teglcharheight()-2));
-
- /* Top area of window */
- setshadowcolor(LIGHTGRAY);
- shadowbox(x,y,x+20,y+18);
- teglwrtchar(28,x+5,y+3,BLACK,WHITE);
- definemouseclickarea(fs,0,0,20,18,TRUE,docquit,MSCLICK);
-
- shadowbox(x+18,y,x1-22,y+18);
- definemouseclickarea(fs,18,0,x1-x-22,18,TRUE,selectandmoveframe,MSCLICK);
-
- shadowbox(x1-24,y,x1,y+18);
- defineresizeclickarea(fs,x1-x-24,0,x1-x,18,docwindow);
-
- /* right area of window */
- /* Curup */
- shadowbox(x1-24,y+16,x1,y+16+24);
- definemouseclickarea(fs,x1-x-24,16,x1-x,20,TRUE,curup,MSCLICK);
- definemouseclickarea(fs,x1-x-24,20,x1-x,20+20,TRUE,pageup,MSCLICK);
- putpict(x1-22,y+18,imageUP,BLACK);
-
- setshadowfillstyle(CLOSE_DOT_FILL);
- shadowbox(x1-24,y+16+22,x1,y1-16-22);
- setshadowfillstyle(SOLID_FILL);
-
- /* Curdown */
- shadowbox(x1-24,y1-16-24,x1,y1-16);
- definemouseclickarea(fs,x1-x-24,y1-y-16-24,x1-x,y1-y-20,TRUE,pagedown,MSCLICK);
- definemouseclickarea(fs,x1-x-24,y1-y-20,x1-x,y1-y-16,TRUE,curdown,MSCLICK);
- putpict(x1-22,y1-16-22,imageDOWN,BLACK);
-
- /* bottom area of window */
- shadowbox(x,y1-18,x+20,y1);
- defineresizeclickarea(fs,0,y1-y-18,20,y1-y,docwindow);
-
- setshadowfillstyle(CLOSE_DOT_FILL);
- shadowbox(x+18,y1-18,x1-22,y1);
- setshadowfillstyle(SOLID_FILL);
- /* DefineMouseClickArea(FS,18,y1-y-18,x1-x-22,y1-y,TRUE,NULL,MSCLICK); */
-
- shadowbox(x1-24,y1-18,x1,y1);
- defineresizeclickarea(fs,x1-x-24,y1-y-18,x1-x,y1-y,docwindow);
- commitupdate();
-
-
- /* Scroll Slider */
- pages = arraymax / fvptr->maxrow;
- barlength=((y1-16-25)-(y+16+23));
- fvptr->divisons = barlength/pages;
- barlength = barlength-(((fvptr->lastline+fvptr->maxrow-1)/fvptr->maxrow)*fvptr->divisons);
-
- definesliderarea(fs,x1-x-24,16+23,x1-x,16+23+barlength,x1-x-24,16+23,x1-x,y1-y-16-25,slidedoc);
- prepareforupdate(fs);
- setshadowcolor(WHITE);
- setfillstyle(SOLID_FILL, WHITE);
- bar(x1-24,y+16+23,x1-3,y+16+23+barlength);
- setcolor(BLACK);
- rectangle(x1-24,y+16+23,x1-3,y+16+23+barlength);
- commitupdate();
-
- defineresizeminmax(fs,90,90,639,349);
-
- openfsio(fs,10,30,x1-x-30,30+(fvptr->maxrow*(teglcharheight()-2)));
-
- display(fvptr);
- return 1;
- }
-
- void createviewfile(char *s)
- {
- unsigned x, y, x1, y1;
- fileviewptr fvptr;
-
- fvptr = (fileviewptr) cgetmem((unsigned long) sizeof(*fvptr));
-
- strcpy(fvptr->filename, s);
- fvptr->fonttable = light14;
- fvptr->offset = 0;
- fvptr->coloff = 0;
-
- allocatelstrarr(&fvptr->data, arraymax);
- if (readfilelstr(s, &fvptr->lastline, arraymax,*fvptr->data)) {
- x = 15;
- y = 25;
- x1 = 624;
- y1 = 334;
- pushimage(x,y,x1,y1);
- fvptr->fs = stackptr;
- fvptr->nextfileview = anchorfileview;
- anchorfileview = fvptr;
-
- docwindow(fvptr->fs, NULL);
- } else
- cfreemem(fvptr,(unsigned long) sizeof(*fvptr));
-
- }
-
- unsigned fileselectandview(imagestkptr frame, msclickptr mouseclickpos)
- {
- char selected;
- char selectedfile[80];
- unsigned x, y;
-
- x = 100;
- y = 100;
- if (frame != NULL) {
- x = frame->x;
- y = frame->y;
- }
- selected = selectafile(x, y, path, selectedfile);
-
- if (selected)
- createviewfile(selectedfile);
-
- return 1;
- }
-
- void main(int argc, char **argv)
- {
- easytegl();
-
- setautorotate(TRUE);
-
- getcwd(path, sizeof(path));
- strcat(path, "\\*.*");
-
- om1 = createoptionmenu(font14);
- defineoptions(om1, "TEGLView ~I~nfo...", TRUE, infooption);
-
- om2 = createoptionmenu(font14);
- defineoptions(om2, "~O~pen ", TRUE, fileselectandview);
- defineoptions(om2, "--", FALSE, NULL);
- defineoptions(om2, "~Q~uit", TRUE, exitoption);
-
- setteglfont(font14);
- createbarmenu(0, 0, getmaxx());
- setbarmenumargin(24);
- outbaroption(" ~D~esk ", om1);
- outbaroption(" ~F~ile ", om2);
-
- putpict(5, 1, imageTINYTEGL, BLACK);
-
- setctrlbreakfs(exitoption);
-
- teglsupervisor();
- }