home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
OMEGA2
/
PCO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-25
|
14KB
|
573 lines
//
// *************************************************************************
// * *
// * PC Office for DOS using: *
// * *
// * OMEGA C++ Windowing Class Library *
// * ================================= *
// * *
// * Copyright 1991,92 Tom Clancy *
// * Submitted to the public domain, April 1992 *
// * *
// *************************************************************************
// * *
// * Incomplete program showing some of the uses of OMEGA C++ *
// * *
// *************************************************************************
//
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include "fastwrit.hpp"
#include "omscreen.hpp"
oScreen s;
// Interface routines
void makescreen();
void gomain();
void gofolders();
void finish();
void draw_cabinets(int set);
void draw_slider();
void draw_fslider();
void draw_books();
void draw_folders();
void update_slider(int set);
void checkxy(int x, int y);
int checkkey();
int onsliderup(int x, int y);
int onsliderdown(int x, int y);
void slideup();
void slidedown();
int onslide(int x, int y);
void slideabsolute(int y);
void updateclock();
void open_drawer(int d);
int onadrawer();
int whichdrawer(int x, int y);
// Database routines
void initcabinets();
void readcabinet(int c);
void writecabinet(int c);
int current;
int curdrawer;
int cabs[12][2] = {
2,11,21,11,40,11,59,11,
2,16,21,16,40,16,59,16,
2,21,21,21,40,21,59,21,
};
int fold[12][2] = {
1, 1,26, 3,51, 5,
1, 7,26, 9,51,11,
1,13,26,15,51,17,
1,19,26,21,51,23,
};
struct folder {
char title[21];
char password[11];
char locked;
char prog[9];
char path[65];
};
struct drawer {
struct folder folders[12];
char title[18];
char password[10];
char locked;
};
struct drawer cabinet[12];
main() {
current=1;
curdrawer=1;
OMEGA_SETUP();
initmouse();
initcabinets();
readcabinet(current);
s.setfgcolor(WHITE);
s.setbkcolor(BLACK);
s.clrscr();
makescreen();
gomain();
finish();
return 0;
}
void makescreen() {
s.cursoroff();
s.clrscr();
s.clearline(1,WHITE,BLUE);
s.writeat(1,1,WHITE,BLUE,"PC Office - Copyright 1991 HCS Software");
draw_cabinets(current);
draw_slider();
draw_books();
}
void gomain() {
int done=0;
int x,y,b;
x=y=b=0;
s.setmouse(1,1);
while(!done) {
s.showmouse();
s.getmouse(x,y,b);
if(b==1) {
checkxy(x,y);
while(b==1) {
s.getmouse(x,y,b);
s.showmouse();
}
}
if(s.keypressed()) {
done=checkkey();
}
updateclock();
s.showmouse();
}
}
void gofolders() {
draw_folders();
while(getch()!=27);
}
void updateclock() {
time_t timer;
struct tm *tblock;
timer = time(NULL);
tblock = localtime(&timer);
char str[30];
char ampm[5];
if(tblock->tm_hour>=12)
strcpy(ampm,"pm");
else
strcpy(ampm,"am");
if(tblock->tm_hour>12)
tblock->tm_hour=tblock->tm_hour-12;
sprintf(str,"%d:%#02d %s ",tblock->tm_hour,tblock->tm_min,ampm);
fastwritestr(70,1,WHITE,BLUE,(char far *)str,s.getvvseg(),s.getvvofs());
}
int onslide(int x, int y) {
return x==79 && y>=10 && y<=18;
}
int onsliderup(int x, int y) {
return x==79 && y==10;
}
int onsliderdown(int x, int y) {
return x==79 && y==18;
}
void slideup() {
current--;
if(current<1) current=1;
else {
readcabinet(current);
draw_cabinets(current);
draw_slider();
}
}
void slidedown() {
current++;
if(current>7) current=7;
else {
readcabinet(current);
draw_cabinets(current);
draw_slider();
}
}
void slideabsolute(int y) {
current=y-10;
readcabinet(current);
draw_cabinets(current);
draw_slider();
}
void open_drawer(int d) {
int nx, ny;
char num[4];
nx=cabs[d-1][0]-1;
ny=cabs[d-1][1]-1;
s.drawbox(nx+1,ny+1,nx+1+19,ny+1+5,WHITE,BLACK,0);
s.drawbox(nx+2,ny+2,nx+2+19,ny+2+5,WHITE,BLACK,0);
s.fillarea(nx+3,ny+3,nx+3+17,ny+3+3,WHITE,current,32);
s.drawhollowbox(nx+3+5,ny+3+2,nx+3+5+7,
ny+3+3,YELLOW,current,0);
if(cabinet[d-1].locked)
s.chwriteat(nx+3+16,ny+3,WHITE,current,7);
else
s.chwriteat(nx+3+16,ny+3,WHITE,current,9);
sprintf(num,"%#02d",d);
s.writeat(nx+3+8,ny+3+3,YELLOW,current,num);
if(strlen(cabinet[d-1].title))
s.writebetween(ny+3+1,nx+3,nx+3+17,WHITE,BLACK,cabinet[d-1].title);
curdrawer=d;
delay(100);
gofolders();
makescreen();
}
int onadrawer(int x, int y) {
return x>=2 && x<=76 && y>=11 && y<=24;
}
int whichdrawer(int x, int y) {
x-=2;
y-=11;
return (y/5) * 4 + (x/19+1);
}
void checkxy(int x, int y) {
if(onslide(x,y)) {
if(onsliderup(x,y)) {
slideup();
} else
if(onsliderdown(x,y)) {
slidedown();
} else
slideabsolute(y);
}
if(onadrawer(x,y)) {
open_drawer(whichdrawer(x,y));
}
}
int checkkey() {
int k=s.readkey();
switch(k) {
case AltX :
return 1;
case UpArrow :
slideup();
break;
case DownArrow :
slidedown();
break;
case Home :
current=1;
readcabinet(current);
draw_cabinets(current);
draw_slider();
break;
case End :
current=7;
readcabinet(current);
draw_cabinets(current);
draw_slider();
break;
case F1 :
open_drawer(1);
break;
case F2 :
open_drawer(2);
break;
case F3 :
open_drawer(3);
break;
case F4 :
open_drawer(4);
break;
case F5 :
open_drawer(5);
break;
case F6 :
open_drawer(6);
break;
case F7 :
open_drawer(7);
break;
case F8 :
open_drawer(8);
break;
case F9 :
open_drawer(9);
break;
case F10 :
open_drawer(10);
break;
case ShF1 :
open_drawer(11);
break;
case ShF2 :
open_drawer(12);
break;
case F11 :
open_drawer(11);
break;
case F12 :
open_drawer(12);
break;
}
return 0;
}
void finish() {
s.clrscr();
s.cursoron();
}
void draw_cabinets(int set) {
s.activate_virtual();
s.fillarea(2,11,76,24,WHITE,set,32);
s.drawhollowbox(1,10,77,25,WHITE,BLACK,0);
s.drawline(15,2,76,WHITE,BLACK,0);
s.drawline(20,2,76,WHITE,BLACK,0);
s.fillarea(20,11,20,24,WHITE,BLACK,186); //179
s.fillarea(39,11,39,24,WHITE,BLACK,186);
s.fillarea(58,11,58,24,WHITE,BLACK,186);
s.chwriteat(20,10,WHITE,BLACK,210); //194
s.chwriteat(39,10,WHITE,BLACK,210);
s.chwriteat(58,10,WHITE,BLACK,210);
s.chwriteat(20,25,WHITE,BLACK,208); //193
s.chwriteat(39,25,WHITE,BLACK,208);
s.chwriteat(58,25,WHITE,BLACK,208);
s.chwriteat(1,15,WHITE,BLACK,195);
s.chwriteat(1,20,WHITE,BLACK,195);
s.chwriteat(77,15,WHITE,BLACK,180);
s.chwriteat(77,20,WHITE,BLACK,180);
s.chwriteat(20,15,WHITE,BLACK,215); //197
s.chwriteat(39,15,WHITE,BLACK,215);
s.chwriteat(58,15,WHITE,BLACK,215);
s.chwriteat(20,20,WHITE,BLACK,215);
s.chwriteat(39,20,WHITE,BLACK,215);
s.chwriteat(58,20,WHITE,BLACK,215);
s.fillarea(1,8,80,9,WHITE,BLACK,32);
//s.chwriteat(2,9,WHITE,BLACK,47);
s.chwriteat(76,9,WHITE,BLACK,92);
s.fillarea(1,8,74,8,WHITE,BLACK,196);
//readcabinet(current);
int i;
char num[3];
for(i=0; i<12; i++) {
s.drawhollowbox(cabs[i][0]+5,cabs[i][1]+2,cabs[i][0]+5+7,
cabs[i][1]+3,YELLOW,set,0);
if(cabinet[i].locked)
s.chwriteat(cabs[i][0]+16,cabs[i][1],WHITE,set,7);
else
s.chwriteat(cabs[i][0]+16,cabs[i][1],WHITE,set,9);
sprintf(num,"%#02d",i+1);
s.writeat(cabs[i][0]+8,cabs[i][1]+3,YELLOW,set,num);
if(strlen(cabinet[i].title))
s.writebetween(cabs[i][1]+1,cabs[i][0],cabs[i][0]+17,WHITE,BLACK,cabinet[i].title);
}
s.deactivate_virtual();
}
void draw_slider() {
int i;
s.chwriteat(79,10,WHITE,BLACK,24);
for(i=1; i<8; i++)
s.chwriteat(79,10+i,LIGHTGRAY,BLACK,176);
s.chwriteat(79,18,WHITE,BLACK,25);
update_slider(current);
}
void draw_books() {
}
void draw_fslider() {
int i;
s.chwriteat(79,3,WHITE,BLACK,24);
for(i=1; i<22; i++)
s.chwriteat(79,3+i,LIGHTGRAY,BLACK,176);
s.chwriteat(79,25,WHITE,BLACK,25);
}
void draw_folders() {
int i,j;
s.activate_virtual();
s.clrscr();
for(i=0,j=0; i<=12; i++, j+=2)
s.drawbox(1,j+3,75,25,WHITE,current,0);
s.fillarea(1,25,75,25,WHITE,current,196);
s.chwriteat(1,25,WHITE,current,218);
s.chwriteat(75,25,WHITE,current,191);
s.drawbox( 1, 1,25, 3,WHITE,current,0);
s.drawbox(26, 3,50, 5,WHITE,current,0);
s.drawbox(51, 5,75, 7,WHITE,current,0);
s.chwriteat( 1, 3,WHITE,current,179);
s.chwriteat(25, 3,WHITE,current,192);
s.chwriteat(26, 5,WHITE,current,217);
s.chwriteat(50, 5,WHITE,current,192);
s.chwriteat(51, 7,WHITE,current,217);
s.chwriteat(75, 7,WHITE,current,179);
s.fillarea( 2, 3,24, 3,WHITE,current,32);
s.fillarea(27, 5,49, 5,WHITE,current,32);
s.fillarea(52, 7,74, 7,WHITE,current,32);
s.drawbox( 1, 7,25, 9,WHITE,current,0);
s.drawbox(26, 9,50,11,WHITE,current,0);
s.drawbox(51,11,75,13,WHITE,current,0);
s.chwriteat( 1, 9,WHITE,current,179);
s.chwriteat(25, 9,WHITE,current,192);
s.chwriteat(26,11,WHITE,current,217);
s.chwriteat(50,11,WHITE,current,192);
s.chwriteat(51,13,WHITE,current,217);
s.chwriteat(75,13,WHITE,current,179);
s.fillarea( 2, 9,24, 9,WHITE,current,32);
s.fillarea(27,11,49,11,WHITE,current,32);
s.fillarea(52,13,74,13,WHITE,current,32);
s.drawbox( 1,13,25,15,WHITE,current,0);
s.drawbox(26,15,50,17,WHITE,current,0);
s.drawbox(51,17,75,19,WHITE,current,0);
s.chwriteat( 1,15,WHITE,current,179);
s.chwriteat(25,15,WHITE,current,192);
s.chwriteat(26,17,WHITE,current,217);
s.chwriteat(50,17,WHITE,current,192);
s.chwriteat(51,19,WHITE,current,217);
s.chwriteat(75,19,WHITE,current,179);
s.fillarea( 2,15,24,15,WHITE,current,32);
s.fillarea(27,17,49,17,WHITE,current,32);
s.fillarea(52,19,74,19,WHITE,current,32);
s.drawbox( 1,19,25,21,WHITE,current,0);
s.drawbox(26,21,50,23,WHITE,current,0);
s.drawbox(51,23,75,25,WHITE,current,0);
s.chwriteat( 1,21,WHITE,current,179);
s.chwriteat(25,21,WHITE,current,192);
s.chwriteat(26,23,WHITE,current,217);
s.chwriteat(50,23,WHITE,current,192);
s.chwriteat(51,25,WHITE,current,217);
s.chwriteat(75,25,WHITE,current,179);
s.fillarea( 2,21,24,21,WHITE,current,32);
s.fillarea(27,23,49,23,WHITE,current,32);
s.fillarea(52,25,74,25,WHITE,current,32);
char num[3];
for(i=0; i<12; i++) {
if(cabinet[curdrawer-1].folders[i].locked)
s.chwriteat(fold[i][0]+23,fold[i][1],YELLOW,current,7);
else
s.chwriteat(fold[i][0]+23,fold[i][1],YELLOW,current,9);
sprintf(num,"%#02d",i+1);
s.writeat(fold[i][0]+1,fold[i][1]+1,YELLOW,current,num);
if(strlen(cabinet[curdrawer-1].folders[i].title))
s.writeat(fold[i][0]+4,fold[i][1]+1,WHITE,BLACK,cabinet[curdrawer-1].folders[i].title);
}
s.writeat(35,1,YELLOW,BLACK,"Cabinet: Drawer:");
sprintf(num,"%d",current);
s.writeat(44,1,WHITE,BLACK,num);
if(strlen(cabinet[curdrawer-1].title))
s.writeat(56,1,WHITE,BLACK,cabinet[curdrawer-1].title);
else
s.writeat(56,1,WHITE,BLACK,"(UNTITLED)");
draw_fslider();
s.deactivate_virtual();
}
void update_slider(int set) {
s.chwriteat(79,10+set,WHITE,BLACK,177);
}
void initcabinets() {
FILE *out;
int i,j;
memset(cabinet,0,sizeof(cabinet));
if((out=fopen("PCO.DAT","rb"))==NULL) {
if((out=fopen("PCO.DAT","wb"))==NULL) {
printf("Cannot open output file. . .\n");
exit(2);
}
else {
strcpy(cabinet[0].title," System ");
strcpy(cabinet[0].folders[0].title,"PCO Setup");
strcpy(cabinet[0].folders[1].title,"DOS Shell");
strcpy(cabinet[0].folders[2].title,"EXIT PC Office");
strcpy(cabinet[1].title," Utilities ");
for(i=0; i<7; i++) {
fwrite(&cabinet,sizeof(cabinet),1,out);
memset(cabinet,0,sizeof(cabinet));
}
fclose(out);
}
}
else {
fclose(out);
}
}
void readcabinet(int c) {
FILE *in;
if((in=fopen("PCO.DAT","rb"))==NULL) {
}
else {
fseek(in,(c-1)*sizeof(cabinet),SEEK_SET);
fread(cabinet,sizeof(cabinet),1,in);
fclose(in);
}
}
void writecabinet(int c) {
FILE *out;
if((out=fopen("PCO.DAT","wb+"))==NULL) {
}
else {
fseek(out,(c-1)*sizeof(cabinet),SEEK_SET);
fwrite(cabinet,sizeof(cabinet),1,out);
fclose(out);
}
}