home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / CMNVUE.ZIP / DEMO.CXX < prev    next >
Text File  |  1988-11-30  |  8KB  |  241 lines

  1. #include "Demo.hxx"
  2.  
  3. void App::far Start() {
  4.     DemoWind Demo( this );    // the main window
  5.     MessBox Mb ( "Warning",
  6.                 "What you are about to witness may seriously amaze you.",
  7.                 &Demo );
  8.     Mb.SetType ( OkayButton | ExclamationIcon );
  9.     Mb.Show ();
  10.     Exec();
  11. }
  12.  
  13. DemoWind::far DemoWind( App *pa ) {
  14.     parent = pa;
  15.     EnableSysMenu ();
  16.     EnableBorder ();
  17.     SetCaption ( "A CommonView Demonstration" );
  18.     SetIcon ( new Icon( "DemoIcon" ) );
  19.     ChangeMenu ( new Menu( "DemoMenu" ) );
  20.     Show();
  21. }
  22.  
  23. long DemoWind::far MenuCommand ( MenuCommandEvt mCE ) {
  24.     int    Item = mCE.GetItemID ();
  25.     switch( Item )     {
  26.     case IDM_EXIT:
  27.         parent->Quit();
  28.         break;
  29.     case IDM_ABOUT: 
  30.         AboutDialog( this, "AboutBox" );
  31.         break;
  32.     case IDM_DETAILS:
  33.         DetailsDialog( this, "COMMONVIEWDETAILS" );
  34.         break;
  35.     case    IDM_HELLO:
  36.         HelloDialog( this, "HELLO_DIALOG" );
  37.         break;
  38.     case    IDM_MEMMANAGEMENT:
  39.         InfoBox( this, "Container classes in CommonView allow multiple shared local heaps.\n\nContainers do all their own memory locking and unlocking automatically.");
  40.         break;
  41.     case    IDM_SYSCALLREDUCTION:
  42.         InfoBox( this, "CommonView reduces the number of system calls needed dramatically, from as many as 700 in Presentation Manager, or 400 in MS-Windows to about 30 easy-to-use classes.");
  43.         break;
  44.     case    IDM_DYNALINKS:
  45.         InfoBox( this, "CommonView simplifies programming Dynalinks. In fact CommonView itself is a Dynalink.");
  46.         break;
  47.     case    IDM_EFFICIENCY:
  48.         InfoBox( this, "CommonView is written entirely in C++ which is just as efficient as C.");
  49.         break;
  50.     case    IDM_PORTABILITY:
  51.         InfoBox( this, "Applications you develop with CommonView are 100% portable between Presentation Manager and MS-Windows. CommonView improves portability to both X11 and NeWS without interfering with the `look and feel' of the different environments.");
  52.         break;
  53.     case    IDM_OBJECTORIENTEDDESIGN:
  54.         InfoBox( this, "CommonView's Object-Oriented design uses such concepts as Encapsulation and Inheritance to reduce development time for Windows applications.");
  55.         break;
  56.     case    IDM_MESSAGEHANDLING:
  57.         InfoBox( this, "CommonView's generic events map in a portable way onto other Windows systems such as X11, Presentation Manager and NeWS.");
  58.         break;
  59.     default: 
  60.         return FALSE;
  61.     }
  62. }
  63.  
  64. long AboutDialog::far WindowInit ( Event )
  65. {
  66.     return TRUE;
  67. }
  68.  
  69.  
  70. long AboutDialog::far ButtonClick ( ControlEvt )
  71. {
  72.     EndDlg ( FALSE );
  73.     return TRUE;
  74. }
  75.  
  76.  
  77. long DetailsDialog::far ButtonClick ( ControlEvt )
  78. {
  79.     EndDlg ( FALSE );
  80.     return TRUE;
  81. }
  82.  
  83.  
  84. long DetailsDialog::far HorizScroll ( ScrollEvt s ) {
  85.     HorizScrollBar    *b = ( HorizScrollBar * ) s.GetScrollBar ();
  86.     int pos = s.GetPos();
  87.     char StringBuf[16];
  88.     if ( s.GetScrollType () == EndScroll ) 
  89.         if ( b == CompatScroll ) {
  90.             MsgBox ( DetailsParent,
  91.                     "CommonView is always 100% compatible with both PM and MS-Windows." );
  92.             pos = 100;
  93.            } else if ( b == ExeScroll ) {
  94.             if ( pos < 50 ) MsgBox ( DetailsParent,
  95.                     "CommonView gives you a 50% reduction in .EXE file size. Bad programming increases the size." );
  96.             else MsgBox ( DetailsParent,
  97.                     "CommonView makes it easy to dynalink so dynalinking more of your code reduces .EXE size." );
  98.             pos = 50;
  99.         } else {
  100.             if ( pos < 75 ) MsgBox ( DetailsParent,
  101.                     "If you add lots of comments and redundant code you can avoid a 75% reduction in code size." );
  102.             else MsgBox ( DetailsParent,
  103.                     "CommonView gives 75% code reduction over MS-Windows. If you are very clever, you can reduce this further." );
  104.             pos = 75;
  105.         }
  106.  
  107.     if ( pos > 100 ) pos = 100;
  108.     if ( pos <   0 ) pos =   0;
  109.     b -> SetThumbPos ( pos );
  110.     sprintf ( StringBuf, "%3d%%", pos );
  111.     if ( b == CompatScroll ) TextPrint ( StringBuf, Point ( 228, 182 ) );
  112.     else if ( b == ExeScroll ) TextPrint ( StringBuf, Point ( 228, 240 ) );
  113.     else TextPrint ( StringBuf, Point ( 228, 210 ) );
  114.     return TRUE;
  115. }
  116.  
  117.  
  118. InfoBox::InfoBox ( pWindow p, pchar Text )
  119.     : ( "CommonView Features", Text, p )
  120. {
  121.     SetType ( OkayButton | HandIcon );
  122.     Show ();
  123. }
  124.  
  125. MsgBox::MsgBox ( pWindow p, pchar Text )
  126.     : ( "Concept Error!", Text, p )
  127. {
  128.     SetType ( MB_SYSTEMMODAL | OkayButton | ExclamationIcon );
  129.     Show ();
  130. }
  131.  
  132. long DetailsDialog::far WindowInit ( Event )
  133. {
  134.     Range r ( 0, 100 );
  135.     CompatScroll = new HorizScrollBar ( this, IDS_COMPAT );
  136.     CompatScroll->SetRange ( r );
  137.     CompatScroll->SetThumbPos ( 100 );
  138.     CompatScroll->SetBlock ( 5 );
  139.     CompatScroll->SetUnit ( 1 );
  140.     CodeReductScroll = new HorizScrollBar ( this, IDS_CODEREDUCTION );
  141.     CodeReductScroll->SetRange ( r );
  142.     CodeReductScroll->SetThumbPos ( 75 );
  143.     CodeReductScroll->SetBlock ( 5 );
  144.     CodeReductScroll->SetUnit ( 1 );
  145.     ExeScroll = new HorizScrollBar ( this, IDS_EXE );
  146.     ExeScroll->SetRange ( r );
  147.     ExeScroll->SetThumbPos ( 50 );
  148.     ExeScroll->SetBlock ( 5 );
  149.     ExeScroll->SetUnit ( 1 );
  150.     return TRUE;
  151. }
  152.  
  153. DetailsDialog::~DetailsDialog ()
  154. {
  155.     delete CompatScroll;
  156.     delete CodeReductScroll;
  157.     delete ExeScroll;
  158. }
  159.  
  160. long DetailsDialog::far Expose ( ExposeEvt ) {
  161.     char    StringBuf[16];
  162.     sprintf ( StringBuf, "%3d%%", CompatScroll->GetThumbPos () );
  163.     TextPrint ( StringBuf, Point ( 228, 182 ) );
  164.     sprintf ( StringBuf, "%3d%%", CodeReductScroll->GetThumbPos () );
  165.     TextPrint ( StringBuf, Point ( 228, 210 ) );
  166.     sprintf ( StringBuf, "%3d%%", ExeScroll->GetThumbPos () );
  167.     TextPrint ( StringBuf, Point ( 228, 240 ) );
  168.     return TRUE;
  169. }
  170.  
  171. long    HelloDialog::far ButtonClick ( ControlEvt )
  172. {
  173.     EndDlg ( FALSE );
  174.     return TRUE;
  175. }
  176.  
  177. long    HelloDialog::far WindowInit    ( Event ) {
  178.     int fp;
  179.     int len;
  180.     npchar Buffer;
  181.     int open ( const char*, int );
  182.     int close ( int );
  183.     long lseek ( int, long, int );
  184.     int read ( int, npchar, int );
  185.     CFile = new MultiLineEdit ( this, IDS_HELLO_C );
  186.     CxxFile = new MultiLineEdit ( this, IDS_HELLO_CXX );
  187.     if ( ( fp = open ( "hello.cxx", 0x8000 ) ) == -1 )
  188.         CxxFile->SetText ( "Cannot open hello.cxx" );
  189.     else {
  190.         len = ( int ) lseek ( fp, 0, 2 );
  191.         lseek ( fp, 0L, 0 );            /* Find length of file */
  192.         Buffer = new char [ len + 1 ];
  193.         if ( Buffer ) {
  194.             len = read ( fp, Buffer, len );
  195.             * ( Buffer + len ) = '\0';
  196.             CxxFile->SetTextLimit ( len );
  197.             CxxFile->SetText ( Buffer );
  198.             delete Buffer;
  199.         }
  200.         else CFile->SetText("Out of memory!");
  201.         close ( fp );
  202.     }
  203.     if ( ( fp = open ( "hello.c", 0x8000 ) ) == -1 )    // binary mode
  204.         CFile->SetText ( "Cannot open hello.c" );
  205.     else {
  206.         len = ( int ) lseek ( fp, 0, 2 );
  207.         lseek ( fp, 0, 0 );
  208.         Buffer = new char [ len + 1 ];
  209.         if ( Buffer ) {
  210.             len = read ( fp, Buffer, len );
  211.             * ( Buffer + len ) = '\0';
  212.             CFile->SetTextLimit ( len );
  213.             CFile->SetText ( Buffer );
  214.             delete Buffer;
  215.         }
  216.         else CFile->SetText ( "Out of memory!" );
  217.         close ( fp );
  218.     }
  219.     MessBox    M ( "The Hello Program",
  220.         "This window contains the listings of two programs. Each creates a window and prints 'Hello World' on it. One is written in C, the other in C++ with CommonView. Scroll around the code and see how the CommonView application is much smaller and much clearer in it's function.", 0 );
  221.     M.SetType ( AsteriskIcon | OkayButton );
  222.     M.Show ();
  223.     return TRUE;
  224. }
  225.  
  226. long    HelloDialog::far Expose ( ExposeEvt ) {
  227.     char Buf[16];
  228.     CFile->Show ();
  229.     CxxFile->Show ();
  230.     sprintf ( Buf, "%4d Lines", CFile->GetNumLines () );
  231.     TextPrint ( Buf, Point ( 114, 273 ) );
  232.     sprintf ( Buf, "%4d Lines", CxxFile->GetNumLines () );
  233.     TextPrint ( Buf, Point ( 444, 273 ) );
  234.     return TRUE;
  235. }
  236.  
  237. HelloDialog::~HelloDialog () {
  238.     delete CFile;
  239.     delete CxxFile;
  240. }
  241.