home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / c / intuitionpp / examples / littlemore.cc next >
Encoding:
C/C++ Source or Header  |  1993-04-08  |  2.1 KB  |  95 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //
  4. //    Little test program implementing a simple 'more' to illustrate
  5. //    how objects are easy to use, and easy to handle.
  6. //
  7. //    For all comment email 'brulhart@cuilima.unige.ch'
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. ///////////////////////////////////////////////////////////////////////////////
  11.  
  12.  
  13. #include <stream.h>
  14. #include <stdlib.h>
  15.  
  16.  
  17. #include <ipp/mgwindow.h>
  18.  
  19.  
  20. MGWindow window;
  21. FILE *file;
  22.  
  23.  
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. //    Callbacks
  27. //
  28.  
  29. void moveon(IMessage& message)
  30. {
  31. IMessage mess;
  32. char buf[255];
  33.     while (!(window.getImsg(mess)->iclass & (RAWKEY+MOUSEBUTTONS)))
  34.     {
  35.         if (fgets(buf,255,file)==NULL) exit(0);
  36.         window.scrollraster(0,12,0,0,window.width(),window.height());
  37.         window.writetext(0,window.height()-22,buf);
  38.     }
  39. }
  40.  
  41.  
  42. void quit(IMessage& message)
  43. {
  44.     fclose(file);
  45.     exit(0);
  46. }
  47.  
  48.  
  49.  
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. //
  53. //    Main
  54. //
  55.  
  56. main(int argc,char **argv)
  57. {
  58.     if (argc!=2)
  59.     {
  60.         cout << "Usage : more <file>\n";
  61.         exit(1);
  62.     } 
  63.     if ((file=fopen(argv[1],"r"))==NULL)
  64.     {
  65.         cout << "Can't open file\n";
  66.         exit(1);
  67.     }
  68.  
  69.     window.setflags(GIMMEZEROZERO+WINDOWCLOSE+WINDOWDEPTH+WINDOWDRAG+WINDOWSIZING);
  70.     window.setIDCMPflags(RAWKEY+MOUSEBUTTONS+CLOSEWINDOW);
  71.  
  72.     window.linkIevent(CLOSEWINDOW,0,0,NULL,quit);
  73.     window.linkIevent(MOUSEBUTTONS,SELECTDOWN,0,NULL,moveon);
  74.     window.linkIevent(RAWKEY,0x45,IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,NULL,quit);
  75.     window.linkIevent(RAWKEY,0x40,0,NULL,moveon);
  76.  
  77.     window.resize(500,300);
  78.     window.setlimit(100,100,1000,1000);
  79.     window.setpos(50,50);
  80.     window.setfont((STRPTR)"Helvetica.font",11,0,0);
  81.  
  82.     window.open();
  83.  
  84.     window.setapen(1);
  85.     window.activate();
  86.     window.writetext(100,80,argv[1]);
  87.     window.writetext(100,110,"Press Left Mouse Button");
  88.     window.writetext(100,130," or Space Bar to read");
  89.     window.writetext(100,170,"Click Upper Left Corner");
  90.     window.writetext(100,190,"or Press Shift ESC to quit");
  91.  
  92.     window.hardcontrol();
  93. }
  94.     
  95.