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 >
C/C++ Source or Header  |  1992-04-25  |  14KB  |  573 lines

  1. //
  2. // *************************************************************************
  3. // *                                                                       *
  4. // *    PC Office for DOS using:                                           *
  5. // *                                                                       *
  6. // *    OMEGA C++ Windowing Class Library                                  *
  7. // *    =================================                                  *
  8. // *                                                                       *
  9. // *    Copyright 1991,92 Tom Clancy                                       *
  10. // *    Submitted to the public domain, April 1992                         *
  11. // *                                                                       *
  12. // *************************************************************************
  13. // *                                                                       *
  14. // *    Incomplete program showing some of the uses of OMEGA C++           *
  15. // *                                                                       *
  16. // *************************************************************************
  17. //
  18.  
  19. #include <time.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <conio.h>
  23. #include <string.h>
  24. #include <dos.h>
  25. #include "fastwrit.hpp"
  26. #include "omscreen.hpp"
  27.  
  28. oScreen s;
  29.  
  30. // Interface routines
  31.  
  32. void makescreen();
  33. void gomain();
  34. void gofolders();
  35. void finish();
  36. void draw_cabinets(int set);
  37. void draw_slider();
  38. void draw_fslider();
  39. void draw_books();
  40. void draw_folders();
  41. void update_slider(int set);
  42. void checkxy(int x, int y);
  43. int  checkkey();
  44. int  onsliderup(int x, int y);
  45. int  onsliderdown(int x, int y);
  46. void slideup();
  47. void slidedown();
  48. int  onslide(int x, int y);
  49. void slideabsolute(int y);
  50. void updateclock();
  51. void open_drawer(int d);
  52. int  onadrawer();
  53. int  whichdrawer(int x, int y);
  54.  
  55. // Database routines
  56.  
  57. void initcabinets();
  58. void readcabinet(int c);
  59. void writecabinet(int c);
  60.  
  61. int current;
  62. int curdrawer;
  63.  
  64. int cabs[12][2] = {
  65.    2,11,21,11,40,11,59,11,
  66.    2,16,21,16,40,16,59,16,
  67.    2,21,21,21,40,21,59,21,
  68. };
  69.  
  70. int fold[12][2] = {
  71.   1, 1,26, 3,51, 5,
  72.   1, 7,26, 9,51,11,
  73.   1,13,26,15,51,17,
  74.   1,19,26,21,51,23,
  75. };
  76.  
  77. struct folder {
  78.   char title[21];
  79.   char password[11];
  80.   char locked;
  81.   char prog[9];
  82.   char path[65];
  83. };
  84.  
  85. struct drawer {
  86.   struct folder folders[12];
  87.   char title[18];
  88.   char password[10];
  89.   char locked;
  90. };
  91.  
  92. struct drawer cabinet[12];
  93.  
  94.  
  95. main() {
  96.   current=1;
  97.   curdrawer=1;
  98.   OMEGA_SETUP();
  99.   initmouse();
  100.   initcabinets();
  101.   readcabinet(current);
  102.   s.setfgcolor(WHITE);
  103.   s.setbkcolor(BLACK);
  104.   s.clrscr();
  105.   makescreen();
  106.   gomain();
  107.   finish();
  108.   return 0;
  109. }
  110.  
  111. void makescreen() {
  112.   s.cursoroff();
  113.   s.clrscr();
  114.   s.clearline(1,WHITE,BLUE);
  115.   s.writeat(1,1,WHITE,BLUE,"PC Office - Copyright 1991 HCS Software");
  116.   draw_cabinets(current);
  117.   draw_slider();
  118.   draw_books();
  119.  
  120. }
  121.  
  122. void gomain() {
  123.   int done=0;
  124.   int x,y,b;
  125.  
  126.   x=y=b=0;
  127.  
  128.   s.setmouse(1,1);
  129.   while(!done) {
  130.     s.showmouse();
  131.     s.getmouse(x,y,b);
  132.     if(b==1) {
  133.       checkxy(x,y);
  134.       while(b==1) {
  135.     s.getmouse(x,y,b);
  136.     s.showmouse();
  137.       }
  138.     }
  139.     if(s.keypressed()) {
  140.       done=checkkey();
  141.     }
  142.     updateclock();
  143.     s.showmouse();
  144.   }
  145. }
  146.  
  147. void gofolders() {
  148.   draw_folders();
  149.   while(getch()!=27);
  150. }
  151.  
  152. void updateclock() {
  153.  
  154.   time_t timer;
  155.   struct tm *tblock;
  156.  
  157.   timer = time(NULL);
  158.   tblock = localtime(&timer);
  159.  
  160.   char str[30];
  161.   char ampm[5];
  162.  
  163.   if(tblock->tm_hour>=12)
  164.     strcpy(ampm,"pm");
  165.   else
  166.     strcpy(ampm,"am");
  167.   if(tblock->tm_hour>12)
  168.     tblock->tm_hour=tblock->tm_hour-12;
  169.   sprintf(str,"%d:%#02d %s   ",tblock->tm_hour,tblock->tm_min,ampm);
  170.   fastwritestr(70,1,WHITE,BLUE,(char far *)str,s.getvvseg(),s.getvvofs());
  171. }
  172.  
  173.  
  174. int onslide(int x, int y) {
  175.   return x==79 && y>=10 && y<=18;
  176. }
  177.  
  178. int onsliderup(int x, int y) {
  179.   return x==79 && y==10;
  180. }
  181.  
  182. int onsliderdown(int x, int y) {
  183.   return x==79 && y==18;
  184. }
  185.  
  186. void slideup() {
  187.   current--;
  188.   if(current<1) current=1;
  189.   else {
  190.     readcabinet(current);
  191.     draw_cabinets(current);
  192.     draw_slider();
  193.   }
  194. }
  195.  
  196. void slidedown() {
  197.   current++;
  198.   if(current>7) current=7;
  199.   else {
  200.     readcabinet(current);
  201.     draw_cabinets(current);
  202.     draw_slider();
  203.   }
  204. }
  205.  
  206. void slideabsolute(int y) {
  207.   current=y-10;
  208.   readcabinet(current);
  209.   draw_cabinets(current);
  210.   draw_slider();
  211. }
  212.  
  213. void open_drawer(int d) {
  214.   int nx, ny;
  215.   char num[4];
  216.  
  217.   nx=cabs[d-1][0]-1;
  218.   ny=cabs[d-1][1]-1;
  219.   s.drawbox(nx+1,ny+1,nx+1+19,ny+1+5,WHITE,BLACK,0);
  220.   s.drawbox(nx+2,ny+2,nx+2+19,ny+2+5,WHITE,BLACK,0);
  221.   s.fillarea(nx+3,ny+3,nx+3+17,ny+3+3,WHITE,current,32);
  222.   s.drawhollowbox(nx+3+5,ny+3+2,nx+3+5+7,
  223.           ny+3+3,YELLOW,current,0);
  224.  
  225.   if(cabinet[d-1].locked)
  226.     s.chwriteat(nx+3+16,ny+3,WHITE,current,7);
  227.   else
  228.     s.chwriteat(nx+3+16,ny+3,WHITE,current,9);
  229.  
  230.   sprintf(num,"%#02d",d);
  231.   s.writeat(nx+3+8,ny+3+3,YELLOW,current,num);
  232.  
  233.   if(strlen(cabinet[d-1].title))
  234.     s.writebetween(ny+3+1,nx+3,nx+3+17,WHITE,BLACK,cabinet[d-1].title);
  235.  
  236.   curdrawer=d;
  237.   delay(100);
  238.   gofolders();
  239.   makescreen();
  240.  
  241. }
  242.  
  243. int onadrawer(int x, int y) {
  244.   return x>=2 && x<=76 && y>=11 && y<=24;
  245. }
  246.  
  247. int whichdrawer(int x, int y) {
  248.   x-=2;
  249.   y-=11;
  250.   return (y/5) * 4 + (x/19+1);
  251. }
  252.  
  253. void checkxy(int x, int y) {
  254.   if(onslide(x,y)) {
  255.     if(onsliderup(x,y)) {
  256.       slideup();
  257.     } else
  258.     if(onsliderdown(x,y)) {
  259.       slidedown();
  260.     } else
  261.       slideabsolute(y);
  262.   }
  263.   if(onadrawer(x,y)) {
  264.     open_drawer(whichdrawer(x,y));
  265.   }
  266.  
  267. }
  268.  
  269. int checkkey() {
  270.   int k=s.readkey();
  271.   switch(k) {
  272.     case AltX :
  273.       return 1;
  274.     case UpArrow :
  275.       slideup();
  276.       break;
  277.     case DownArrow :
  278.       slidedown();
  279.       break;
  280.     case Home :
  281.       current=1;
  282.       readcabinet(current);
  283.       draw_cabinets(current);
  284.       draw_slider();
  285.       break;
  286.     case End :
  287.       current=7;
  288.       readcabinet(current);
  289.       draw_cabinets(current);
  290.       draw_slider();
  291.       break;
  292.     case F1 :
  293.       open_drawer(1);
  294.       break;
  295.     case F2 :
  296.       open_drawer(2);
  297.       break;
  298.     case F3 :
  299.       open_drawer(3);
  300.       break;
  301.     case F4 :
  302.       open_drawer(4);
  303.       break;
  304.     case F5 :
  305.       open_drawer(5);
  306.       break;
  307.     case F6 :
  308.       open_drawer(6);
  309.       break;
  310.     case F7 :
  311.       open_drawer(7);
  312.       break;
  313.     case F8 :
  314.       open_drawer(8);
  315.       break;
  316.     case F9 :
  317.       open_drawer(9);
  318.       break;
  319.     case F10 :
  320.       open_drawer(10);
  321.       break;
  322.     case ShF1 :
  323.       open_drawer(11);
  324.       break;
  325.     case ShF2 :
  326.       open_drawer(12);
  327.       break;
  328.     case F11 :
  329.       open_drawer(11);
  330.       break;
  331.     case F12 :
  332.       open_drawer(12);
  333.       break;
  334.   }
  335.   return 0;
  336. }
  337.  
  338. void finish() {
  339.   s.clrscr();
  340.   s.cursoron();
  341. }
  342.  
  343.  
  344. void draw_cabinets(int set) {
  345.   s.activate_virtual();
  346.   s.fillarea(2,11,76,24,WHITE,set,32);
  347.   s.drawhollowbox(1,10,77,25,WHITE,BLACK,0);
  348.   s.drawline(15,2,76,WHITE,BLACK,0);
  349.   s.drawline(20,2,76,WHITE,BLACK,0);
  350.   s.fillarea(20,11,20,24,WHITE,BLACK,186); //179
  351.   s.fillarea(39,11,39,24,WHITE,BLACK,186);
  352.   s.fillarea(58,11,58,24,WHITE,BLACK,186);
  353.  
  354.   s.chwriteat(20,10,WHITE,BLACK,210); //194
  355.   s.chwriteat(39,10,WHITE,BLACK,210);
  356.   s.chwriteat(58,10,WHITE,BLACK,210);
  357.  
  358.   s.chwriteat(20,25,WHITE,BLACK,208); //193
  359.   s.chwriteat(39,25,WHITE,BLACK,208);
  360.   s.chwriteat(58,25,WHITE,BLACK,208);
  361.  
  362.   s.chwriteat(1,15,WHITE,BLACK,195);
  363.   s.chwriteat(1,20,WHITE,BLACK,195);
  364.  
  365.   s.chwriteat(77,15,WHITE,BLACK,180);
  366.   s.chwriteat(77,20,WHITE,BLACK,180);
  367.  
  368.   s.chwriteat(20,15,WHITE,BLACK,215); //197
  369.   s.chwriteat(39,15,WHITE,BLACK,215);
  370.   s.chwriteat(58,15,WHITE,BLACK,215);
  371.  
  372.   s.chwriteat(20,20,WHITE,BLACK,215);
  373.   s.chwriteat(39,20,WHITE,BLACK,215);
  374.   s.chwriteat(58,20,WHITE,BLACK,215);
  375.  
  376.   s.fillarea(1,8,80,9,WHITE,BLACK,32);
  377.  
  378.   //s.chwriteat(2,9,WHITE,BLACK,47);
  379.  
  380.   s.chwriteat(76,9,WHITE,BLACK,92);
  381.  
  382.   s.fillarea(1,8,74,8,WHITE,BLACK,196);
  383.  
  384.   //readcabinet(current);
  385.  
  386.   int i;
  387.   char num[3];
  388.   for(i=0; i<12; i++) {
  389.     s.drawhollowbox(cabs[i][0]+5,cabs[i][1]+2,cabs[i][0]+5+7,
  390.             cabs[i][1]+3,YELLOW,set,0);
  391.     if(cabinet[i].locked)
  392.       s.chwriteat(cabs[i][0]+16,cabs[i][1],WHITE,set,7);
  393.     else
  394.       s.chwriteat(cabs[i][0]+16,cabs[i][1],WHITE,set,9);
  395.     sprintf(num,"%#02d",i+1);
  396.     s.writeat(cabs[i][0]+8,cabs[i][1]+3,YELLOW,set,num);
  397.     if(strlen(cabinet[i].title))
  398.       s.writebetween(cabs[i][1]+1,cabs[i][0],cabs[i][0]+17,WHITE,BLACK,cabinet[i].title);
  399.   }
  400.   s.deactivate_virtual();
  401. }
  402.  
  403. void draw_slider() {
  404.   int i;
  405.   s.chwriteat(79,10,WHITE,BLACK,24);
  406.   for(i=1; i<8; i++)
  407.     s.chwriteat(79,10+i,LIGHTGRAY,BLACK,176);
  408.   s.chwriteat(79,18,WHITE,BLACK,25);
  409.   update_slider(current);
  410. }
  411.  
  412.  
  413. void draw_books() {
  414. }
  415.  
  416. void draw_fslider() {
  417.   int i;
  418.   s.chwriteat(79,3,WHITE,BLACK,24);
  419.   for(i=1; i<22; i++)
  420.     s.chwriteat(79,3+i,LIGHTGRAY,BLACK,176);
  421.   s.chwriteat(79,25,WHITE,BLACK,25);
  422. }
  423.  
  424.  
  425. void draw_folders() {
  426.   int i,j;
  427.   s.activate_virtual();
  428.   s.clrscr();
  429.   for(i=0,j=0; i<=12; i++, j+=2)
  430.     s.drawbox(1,j+3,75,25,WHITE,current,0);
  431.  
  432.   s.fillarea(1,25,75,25,WHITE,current,196);
  433.   s.chwriteat(1,25,WHITE,current,218);
  434.   s.chwriteat(75,25,WHITE,current,191);
  435.  
  436.   s.drawbox( 1, 1,25, 3,WHITE,current,0);
  437.   s.drawbox(26, 3,50, 5,WHITE,current,0);
  438.   s.drawbox(51, 5,75, 7,WHITE,current,0);
  439.   s.chwriteat( 1, 3,WHITE,current,179);
  440.   s.chwriteat(25, 3,WHITE,current,192);
  441.   s.chwriteat(26, 5,WHITE,current,217);
  442.   s.chwriteat(50, 5,WHITE,current,192);
  443.   s.chwriteat(51, 7,WHITE,current,217);
  444.   s.chwriteat(75, 7,WHITE,current,179);
  445.   s.fillarea( 2, 3,24, 3,WHITE,current,32);
  446.   s.fillarea(27, 5,49, 5,WHITE,current,32);
  447.   s.fillarea(52, 7,74, 7,WHITE,current,32);
  448.  
  449.  
  450.   s.drawbox( 1, 7,25, 9,WHITE,current,0);
  451.   s.drawbox(26, 9,50,11,WHITE,current,0);
  452.   s.drawbox(51,11,75,13,WHITE,current,0);
  453.   s.chwriteat( 1, 9,WHITE,current,179);
  454.   s.chwriteat(25, 9,WHITE,current,192);
  455.   s.chwriteat(26,11,WHITE,current,217);
  456.   s.chwriteat(50,11,WHITE,current,192);
  457.   s.chwriteat(51,13,WHITE,current,217);
  458.   s.chwriteat(75,13,WHITE,current,179);
  459.   s.fillarea( 2, 9,24, 9,WHITE,current,32);
  460.   s.fillarea(27,11,49,11,WHITE,current,32);
  461.   s.fillarea(52,13,74,13,WHITE,current,32);
  462.  
  463.  
  464.   s.drawbox( 1,13,25,15,WHITE,current,0);
  465.   s.drawbox(26,15,50,17,WHITE,current,0);
  466.   s.drawbox(51,17,75,19,WHITE,current,0);
  467.   s.chwriteat( 1,15,WHITE,current,179);
  468.   s.chwriteat(25,15,WHITE,current,192);
  469.   s.chwriteat(26,17,WHITE,current,217);
  470.   s.chwriteat(50,17,WHITE,current,192);
  471.   s.chwriteat(51,19,WHITE,current,217);
  472.   s.chwriteat(75,19,WHITE,current,179);
  473.   s.fillarea( 2,15,24,15,WHITE,current,32);
  474.   s.fillarea(27,17,49,17,WHITE,current,32);
  475.   s.fillarea(52,19,74,19,WHITE,current,32);
  476.  
  477.  
  478.   s.drawbox( 1,19,25,21,WHITE,current,0);
  479.   s.drawbox(26,21,50,23,WHITE,current,0);
  480.   s.drawbox(51,23,75,25,WHITE,current,0);
  481.   s.chwriteat( 1,21,WHITE,current,179);
  482.   s.chwriteat(25,21,WHITE,current,192);
  483.   s.chwriteat(26,23,WHITE,current,217);
  484.   s.chwriteat(50,23,WHITE,current,192);
  485.   s.chwriteat(51,25,WHITE,current,217);
  486.   s.chwriteat(75,25,WHITE,current,179);
  487.   s.fillarea( 2,21,24,21,WHITE,current,32);
  488.   s.fillarea(27,23,49,23,WHITE,current,32);
  489.   s.fillarea(52,25,74,25,WHITE,current,32);
  490.  
  491.  
  492.   char num[3];
  493.   for(i=0; i<12; i++) {
  494.     if(cabinet[curdrawer-1].folders[i].locked)
  495.       s.chwriteat(fold[i][0]+23,fold[i][1],YELLOW,current,7);
  496.     else
  497.       s.chwriteat(fold[i][0]+23,fold[i][1],YELLOW,current,9);
  498.     sprintf(num,"%#02d",i+1);
  499.     s.writeat(fold[i][0]+1,fold[i][1]+1,YELLOW,current,num);
  500.     if(strlen(cabinet[curdrawer-1].folders[i].title))
  501.       s.writeat(fold[i][0]+4,fold[i][1]+1,WHITE,BLACK,cabinet[curdrawer-1].folders[i].title);
  502.   }
  503.   s.writeat(35,1,YELLOW,BLACK,"Cabinet:     Drawer:");
  504.   sprintf(num,"%d",current);
  505.   s.writeat(44,1,WHITE,BLACK,num);
  506.   if(strlen(cabinet[curdrawer-1].title))
  507.     s.writeat(56,1,WHITE,BLACK,cabinet[curdrawer-1].title);
  508.   else
  509.     s.writeat(56,1,WHITE,BLACK,"(UNTITLED)");
  510.  
  511.  
  512.   draw_fslider();
  513.   s.deactivate_virtual();
  514.  
  515. }
  516.  
  517.  
  518. void update_slider(int set) {
  519.   s.chwriteat(79,10+set,WHITE,BLACK,177);
  520. }
  521.  
  522. void initcabinets() {
  523.  
  524.   FILE *out;
  525.  
  526.   int i,j;
  527.   memset(cabinet,0,sizeof(cabinet));
  528.  
  529.   if((out=fopen("PCO.DAT","rb"))==NULL) {
  530.     if((out=fopen("PCO.DAT","wb"))==NULL) {
  531.       printf("Cannot open output file. . .\n");
  532.       exit(2);
  533.     }
  534.     else {
  535.       strcpy(cabinet[0].title," System ");
  536.       strcpy(cabinet[0].folders[0].title,"PCO Setup");
  537.       strcpy(cabinet[0].folders[1].title,"DOS Shell");
  538.       strcpy(cabinet[0].folders[2].title,"EXIT PC Office");
  539.       strcpy(cabinet[1].title," Utilities ");
  540.       for(i=0; i<7; i++) {
  541.     fwrite(&cabinet,sizeof(cabinet),1,out);
  542.     memset(cabinet,0,sizeof(cabinet));
  543.       }
  544.       fclose(out);
  545.     }
  546.   }
  547.   else {
  548.     fclose(out);
  549.   }
  550. }
  551.  
  552. void readcabinet(int c) {
  553.   FILE *in;
  554.   if((in=fopen("PCO.DAT","rb"))==NULL) {
  555.   }
  556.   else {
  557.     fseek(in,(c-1)*sizeof(cabinet),SEEK_SET);
  558.     fread(cabinet,sizeof(cabinet),1,in);
  559.     fclose(in);
  560.   }
  561. }
  562.  
  563. void writecabinet(int c) {
  564.   FILE *out;
  565.   if((out=fopen("PCO.DAT","wb+"))==NULL) {
  566.   }
  567.   else {
  568.     fseek(out,(c-1)*sizeof(cabinet),SEEK_SET);
  569.     fwrite(cabinet,sizeof(cabinet),1,out);
  570.     fclose(out);
  571.   }
  572. }
  573.