home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / csnb.zip / NB.CPP < prev    next >
C/C++ Source or Header  |  1994-05-12  |  5KB  |  155 lines

  1. //---------------------------------------------------------------------------
  2. // Module name   :  nb.cpp - notebook example program
  3. //---------------------------------------------------------------------------
  4. // Author        :  Robert Ferguson 
  5. //---------------------------------------------------------------------------
  6. // Date          :  1 April, 1994
  7. //---------------------------------------------------------------------------
  8. // Description   :  This example program is a C++ - CS/ARCHITECT version of
  9. //                  Rick Fishmans' nbbase.c
  10. //---------------------------------------------------------------------------
  11. // $HEADER$
  12. // $Log$
  13. //---------------------------------------------------------------------------
  14.  
  15. #define INCL_CSAWINSTDBOOK             // notebook controls
  16.  
  17. #include <csa.h>                       // include CS/ARCHITECT
  18.  
  19. #include "nbdefs.h"                    // application defines
  20. #include "nb.h"                        // application declarations
  21.  
  22. // frame window constructor 
  23. // window has a tasklist and an icon
  24.  
  25. MyFrameWindow::MyFrameWindow( PXWINDOW AParent, const CHAR* ATitle, 
  26.                               PXWINDOW AClient ) 
  27.    : xFrameWindow( AParent, ATitle, AClient )
  28. {
  29.    FRAMECDATA fcdata ;
  30.  
  31.    QueryControlData( fcdata )    ;
  32.    fcdata.flCreateFlags|= FCF_TASKLIST | FCF_ICON ;
  33.    SetControlData( fcdata )    ;
  34. }
  35.  
  36. // client window constructor 
  37. // constuct notebook control as child of client window
  38.  
  39. MyClientWindow::MyClientWindow() : xClientWindow() 
  40. {
  41.    Notebook= new xNotebook( this ) ;
  42. }
  43.  
  44. // client setup window processing
  45. // insert notebook pages - default is load on page select
  46. // set major and minor tab dimensions
  47. // set tab and status line text
  48. // etc...
  49.  
  50. VOID MyClientWindow::SetupWindow()
  51. {
  52.    PXNOTEBOOKPAGE  ANotebookPage= 0 ;
  53.    PXSEPARATORPAGE ASeparatorPage= 0 ;
  54.    xPoint          point ;
  55.    xRect           rect ;
  56.  
  57.    xClientWindow::SetupWindow() ;
  58.  
  59.    Notebook->SetTabDimensions( NBPage[ 0 ].TabText, BKA_MAJORTAB ) ;
  60.    Notebook->SetTabDimensions( NBPage[ 2 ].TabText, BKA_MINORTAB ) ;
  61.  
  62.    for( INT i= 0 ; i < NUM_PAGES ; i++ )
  63.    {
  64.       if ( i == 1 )
  65.       {
  66.          ASeparatorPage= new xSeparatorPage( Notebook ) ;
  67.          Notebook->InsertPage( ASeparatorPage ) ;
  68.          ASeparatorPage->SetTabText( NBPage[ 1 ].TabText ) ;
  69.          continue ;
  70.       }
  71.  
  72.       ANotebookPage= new xNotebookPage( Notebook,
  73.                                         NBPage[ i ].Id,
  74.                                         NBPage[ i ].PageStyle ) ;
  75.       Notebook->InsertPage( ANotebookPage ) ;
  76.       ANotebookPage->SetTabText( NBPage[ i ].TabText ) ;
  77.       ANotebookPage->SetStatusLineText( NBPage[ i ].StatusLineText ) ;
  78.       
  79.       // calculate the size of the largest notebook page
  80.       rect= ANotebookPage->QueryWindowRect() ;
  81.       
  82.       if ( rect.xRight > point.x )
  83.          point.x= rect.xRight ;
  84.       
  85.       if ( rect.yTop > point.y )
  86.          point.y= rect.yTop ;
  87.    }
  88.  
  89.    rect.xRight= point.x ;
  90.    rect.yTop= point.y ;
  91.  
  92.    // map dialog units to window coordinates
  93.    WinMapDlgPoints( HWND_DESKTOP, (PPOINTL) &rect, 2, TRUE ) ;
  94.  
  95.    // the notebook is sized to fill the client area
  96.    Notebook->CalcPageRect( rect, FALSE ) ;
  97.  
  98.    // calculate the size of the frame from the size of the client
  99.    Frame->CalcFrameRect( rect, FALSE ) ;
  100.  
  101.    rect.xRight = rect.xRight - rect.xLeft ;
  102.    rect.yTop   = rect.yTop - rect.yBottom ;
  103.    rect.xLeft  = 10 ;
  104.    rect.yBottom= 20 ;
  105.  
  106.    // map dialog units to window coordinates
  107.    WinMapDlgPoints( HWND_DESKTOP, (PPOINTL) &rect, 1, TRUE ) ;
  108.  
  109.    rect.xRight+= ( rect.xLeft - 1 ) ;
  110.    rect.yTop  += ( rect.yBottom - 1 ) ;
  111.    rect.xRight= ( rect.xRight - rect.xLeft ) + 1 ;
  112.    rect.yTop= ( rect.yTop - rect.yBottom ) + 1 ;
  113.  
  114.    // size and activate frame window 
  115.    Frame->SetWindowPos( HWND_TOP, rect, 
  116.                         SWP_SIZE | SWP_MOVE | 
  117.                         SWP_SHOW | SWP_ACTIVATE ) ;
  118. }
  119.  
  120. // size of client == size of notebook
  121.  
  122. VOID MyClientWindow::WMSize( RXMESSAGE msg )
  123. {
  124.    xRect rect ;
  125.  
  126.    xClientWindow::WMSize( msg ) ;
  127.  
  128.    QueryWindowRect( rect ) ;
  129.  
  130.    if ( Notebook )         
  131.       Notebook->SetWindowPos( HWND_TOP, rect,
  132.                               SWP_SIZE | SWP_MOVE | 
  133.                               SWP_SHOW | SWP_ACTIVATE ) ;
  134. }
  135.  
  136. // construct main frame and client windows
  137.  
  138. VOID MyApp::InitMainWindow()
  139. {
  140.    MainWindow= new MyFrameWindow( 0,
  141.                                   Name, 
  142.                                   new MyClientWindow() ) ; 
  143. }
  144.  
  145. main()
  146. {
  147.    MyApp App( "Notebook Sample Program", FALSE ) ;    
  148.    return App.Run() ;        
  149. }
  150.  
  151. // eof nb.cpp
  152.  
  153.  
  154.  
  155.